This commit is contained in:
aozhiwei 2024-08-17 17:03:06 +08:00
parent 0c6f21e211
commit 9fcc66005a
2 changed files with 18 additions and 14 deletions

View File

@ -1,4 +1,6 @@
{
"currency_name": "TestToken",
"currency_decimal": 6
}
[
{
"currency_name": "TestToken",
"currency_decimal": 6
}
]

View File

@ -105,23 +105,25 @@ func (this *CurrencyTable) Load() {
fileName := fmt.Sprintf("../config/currencys/%d/currency.json", netId)
if jsonStr, err := f5.ReadJsonFile(fileName); err == nil {
f5.GetSysLog().Info("load currency %s", fileName)
currencyCfg := struct {
currencysCfg := []struct {
CurrencyName string `json:"currency_name"`
ExchangeRate int64 `json:"exchange_rate"`
CurrencyDecimal int64 `json:"currency_decimal"`
}{}
if err := q5.DecodeJson(jsonStr, &currencyCfg); err != nil {
if err := q5.DecodeJson(jsonStr, &currencysCfg); err != nil {
panic(fmt.Sprintf("load metafile json decode error %s %s", "currency.json", err))
}
p := new(Currency)
p.init(currencyCfg.CurrencyName, currencyCfg.ExchangeRate, currencyCfg.CurrencyDecimal)
p.check()
currencysMeta := this.GetByNetId(netId)
if currencysMeta == nil {
currencysMeta = new(q5.ConcurrentMap[string, *Currency])
this.netIdHash.Store(netId, currencysMeta)
for _, currencyCfg := range currencysCfg {
p := new(Currency)
p.init(currencyCfg.CurrencyName, currencyCfg.ExchangeRate, currencyCfg.CurrencyDecimal)
p.check()
currencysMeta := this.GetByNetId(netId)
if currencysMeta == nil {
currencysMeta = new(q5.ConcurrentMap[string, *Currency])
this.netIdHash.Store(netId, currencysMeta)
}
currencysMeta.Store(p.GetCurrencyName(), p)
}
currencysMeta.Store(p.GetCurrencyName(), p)
}
}
}