This commit is contained in:
aozhiwei 2024-06-27 15:41:24 +08:00
parent 79aaf80f84
commit 1c936329ff
3 changed files with 19 additions and 17 deletions

View File

@ -94,8 +94,7 @@ type Language struct {
}
type BcCurrency struct {
id string
symbol string
name string
contract_address string
current_price float64
@ -451,22 +450,14 @@ func (this *Language) HasEn() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *BcCurrency) GetId() string {
return this.id
func (this *BcCurrency) GetName() string {
return this.name
}
func (this *BcCurrency) HasId() bool {
func (this *BcCurrency) HasName() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *BcCurrency) GetSymbol() string {
return this.symbol
}
func (this *BcCurrency) HasSymbol() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *BcCurrency) GetContractAddress() string {
return this.contract_address
}
@ -614,8 +605,7 @@ func (this *Language) LoadFromKv(kv map[string]interface{}) {
}
func (this *BcCurrency) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.id, "id", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.symbol, "symbol", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.name, "name", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.contract_address, "contract_address", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.current_price, "current_price", &this._flags1_, 4, kv)
}

View File

@ -6,8 +6,11 @@ import (
"time"
"jccommon"
"math/big"
"mt"
)
const DECIMALS = 10000
type vsCurrency struct {
Name string `json:"name"`
CurrentPrice float64 `json:"current_price"`
@ -19,6 +22,14 @@ type bcCurrency struct {
}
func (this *bcCurrency) init() () {
mt.Table.BcCurrency.Traverse(
func (e *mt.BcCurrency) bool {
this.nameHash.Store(e.GetName(), int64(e.GetCurrentPrice() * DECIMALS))
if e.GetContractAddress() != "" {
this.addressHash.Store(e.GetContractAddress(), int64(e.GetCurrentPrice() * DECIMALS))
}
return true
})
go this.refreshExchangeRate()
}
@ -67,10 +78,10 @@ func (this *bcCurrency) refreshExchangeRate() () {
func (this *bcCurrency) updatePrice(l []vsCurrency) {
for _, val := range l {
this.nameHash.Store(val.Name, int64(val.CurrentPrice * 10000))
this.nameHash.Store(val.Name, int64(val.CurrentPrice * DECIMALS))
address := this.getAddressByName(val.Name)
if address != "" {
this.addressHash.Store(address, int64(val.CurrentPrice * 10000))
this.addressHash.Store(address, int64(val.CurrentPrice * DECIMALS))
}
}
f5.GetSysLog().Info("bcCurrency updatePrice %s", q5.EncodeJson(l))

View File

@ -25,6 +25,7 @@ func (this* webHook) unInit() {
}
func (this* webHook) loadWebHookEvent(eventName string, cb func(ds *f5.DataSet) bool) {
time.Sleep(time.Second * 3)
lastOutTick := q5.GetTickCount()
var lastSyncIdx = this.getLastIdx(eventName)
for true {