From 8ea2c287fe971d439f70ad4a03d8c1dc321097cd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 17 Aug 2024 11:17:58 +0800 Subject: [PATCH] 1 --- server/marketserver/mt/Currency.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/server/marketserver/mt/Currency.go b/server/marketserver/mt/Currency.go index 2ec2866d..875e7918 100644 --- a/server/marketserver/mt/Currency.go +++ b/server/marketserver/mt/Currency.go @@ -4,6 +4,7 @@ import ( "q5" "f5" "fmt" + "strings" "main/constant" ) @@ -69,7 +70,21 @@ func (this *CurrencyTable) GetByNetId(netId int32) *q5.ConcurrentMap[string, *Cu } func (this *CurrencyTable) GetByNetIdAddress(netId int32, currencyAddress string) *Currency { - return nil + currencysMeta := this.GetByNetId(netId) + if currencysMeta == nil { + return nil + } + var result *Currency + currencyAddress = strings.ToLower(currencyAddress) + currencysMeta.Range( + func (key string, meta *Currency) bool { + if meta.GetContract().GetAddress() == currencyAddress { + result = meta + return false + } + return true + }) + return result } func (this *CurrencyTable) Load() { @@ -101,7 +116,12 @@ func (this *CurrencyTable) Load() { p := new(Currency) p.init(currencyCfg.CurrencyName, currencyCfg.ExchangeRate, currencyCfg.CurrencyDecimal) p.check() - //this.netIdHash.Store(netId, p) + currencysMeta := this.GetByNetId(netId) + if currencysMeta == nil { + currencysMeta := new(q5.ConcurrentMap[string, *Currency]) + this.netIdHash.Store(netId, currencysMeta) + } + currencysMeta.Store(p.GetCurrencyName(), p) } } }