From 1c936329ffebc7198b91c6515102c2bc998c0ebd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 27 Jun 2024 15:41:24 +0800 Subject: [PATCH] 1 --- server/backtask/mtb/mtb.auto_gen.go | 20 +++++--------------- server/backtask/service/bc_currency.go | 15 +++++++++++++-- server/backtask/task/webhook.go | 1 + 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/server/backtask/mtb/mtb.auto_gen.go b/server/backtask/mtb/mtb.auto_gen.go index 927c0ad3..bca2b8bb 100644 --- a/server/backtask/mtb/mtb.auto_gen.go +++ b/server/backtask/mtb/mtb.auto_gen.go @@ -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) } diff --git a/server/backtask/service/bc_currency.go b/server/backtask/service/bc_currency.go index f656e9c7..fd788eca 100644 --- a/server/backtask/service/bc_currency.go +++ b/server/backtask/service/bc_currency.go @@ -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)) diff --git a/server/backtask/task/webhook.go b/server/backtask/task/webhook.go index b0733024..5b623b92 100644 --- a/server/backtask/task/webhook.go +++ b/server/backtask/task/webhook.go @@ -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 {