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

View File

@ -6,8 +6,11 @@ import (
"time" "time"
"jccommon" "jccommon"
"math/big" "math/big"
"mt"
) )
const DECIMALS = 10000
type vsCurrency struct { type vsCurrency struct {
Name string `json:"name"` Name string `json:"name"`
CurrentPrice float64 `json:"current_price"` CurrentPrice float64 `json:"current_price"`
@ -19,6 +22,14 @@ type bcCurrency struct {
} }
func (this *bcCurrency) init() () { 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() go this.refreshExchangeRate()
} }
@ -67,10 +78,10 @@ func (this *bcCurrency) refreshExchangeRate() () {
func (this *bcCurrency) updatePrice(l []vsCurrency) { func (this *bcCurrency) updatePrice(l []vsCurrency) {
for _, val := range l { 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) address := this.getAddressByName(val.Name)
if address != "" { 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)) 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) { func (this* webHook) loadWebHookEvent(eventName string, cb func(ds *f5.DataSet) bool) {
time.Sleep(time.Second * 3)
lastOutTick := q5.GetTickCount() lastOutTick := q5.GetTickCount()
var lastSyncIdx = this.getLastIdx(eventName) var lastSyncIdx = this.getLastIdx(eventName)
for true { for true {