diff --git a/common/chain/chain.go b/common/chain/chain.go index 457f3e3..e32033b 100644 --- a/common/chain/chain.go +++ b/common/chain/chain.go @@ -8,40 +8,15 @@ import ( "github.com/tidwall/gjson" ) -//var defaultChain = ` -//{ -// "ETH": [ -// 200, -// 2001 -// ], -// "POLYGON": [ -// 201, -// 2011 -// ], -// "BSC": [ -// 202, -// 2021 -// ], -// "TRON": [ -// 205, -// 2051 -// ], -// "BTC": [ -// 300, -// 3001 -// ], -// "FIL": [ -// 301, -// 3011 -// ], -// "XRP": [ -// 310, -// 3101 -// ] -//} -//` - -var defaultChainCode = map[string]map[int64]int{"ETH": {200: 1, 2001: 1}, "POLYGON": {201: 1, 2011: 1}, "BSC": {202: 1}, "TRON": {205: 1}, "BTC": {300: 1}, "FIL": {301: 1}, "XRP": {310: 1}} +var defaultChainCode = map[string]map[int64]int8{ + "ETH": {200: 1, 2001: 1}, + "POLYGON": {201: 1, 2011: 1}, + "BSC": {202: 1}, + "TRON": {205: 1}, + "BTC": {300: 1}, + "FIL": {301: 1}, + "XRP": {310: 1}, +} func LoadConfig(path string) (string, error) { f, err := os.OpenFile(path, os.O_RDONLY, os.ModeAppend) @@ -58,18 +33,16 @@ func LoadConfig(path string) (string, error) { return string(b), nil } -func LoadChainCodeFile(file string) map[string]map[int64]int { - - mp := make(map[string]map[int64]int) - +func LoadChainCodeFile(file string) map[string]map[int64]int8 { //set customer config + mp := make(map[string]map[int64]int8) if len(file) > 1 { body, _ := LoadConfig(file) if len(body) > 1 { gjson.Parse(body).ForEach(func(key, v gjson.Result) bool { k := key.String() list := v.Array() - m := make(map[int64]int) + m := make(map[int64]int8) for _, v := range list { code := v.Int() m[code] = 1 @@ -81,11 +54,6 @@ func LoadChainCodeFile(file string) map[string]map[int64]int { } - if len(mp) < 1 { - // default - mp = defaultChainCode - } - return mp } @@ -93,7 +61,11 @@ func GetChainCode(chainCode int64, chainName string, log *xlog.XLog) bool { if log == nil { log = xlog.NewXLogger() } - mp := LoadChainCodeFile("./chain.json") + mp := defaultChainCode + + //todo load chainCode if it is necessary, but it is not efficient because It loads configuration files very frequently + //mp = LoadChainCodeFile("./chain.json") + if mp == nil { log.Errorf("unknown all chainCodeļ¼Œthis is a fatal error") return false