diff --git a/blockchain/chain/gw.go b/blockchain/chain/gw.go index e27a738..97130e3 100644 --- a/blockchain/chain/gw.go +++ b/blockchain/chain/gw.go @@ -14,25 +14,25 @@ import ( ) func NewChain(blockchain int64, log *xlog.XLog) blockchain.ChainConn { - if blockchain == chain.GetChainCode("ETH", log) { + if chain.GetChainCode(blockchain, "ETH", log) { //eth return ether.NewChainClient() - } else if blockchain == chain.GetChainCode("TRON", log) { + } else if chain.GetChainCode(blockchain, "TRON", log) { //tron return tron.NewChainClient() - } else if blockchain == chain.GetChainCode("POLYGON", log) { + } else if chain.GetChainCode(blockchain, "POLYGON", log) { //polygon-pos return polygonpos.NewChainClient() - } else if blockchain == chain.GetChainCode("BSC", log) { + } else if chain.GetChainCode(blockchain, "BSC", log) { //bnb return bnb.NewChainClient() - } else if blockchain == chain.GetChainCode("FIL", log) { + } else if chain.GetChainCode(blockchain, "FIL", log) { //file-coin return filecoin.NewChainClient() - } else if blockchain == chain.GetChainCode("BTC", log) { + } else if chain.GetChainCode(blockchain, "BTC", log) { //btc return btc.NewChainClient() - } else if blockchain == chain.GetChainCode("XRP", log) { + } else if chain.GetChainCode(blockchain, "XRP", log) { //xrp return xrp.NewChainClient() } else { @@ -41,12 +41,12 @@ func NewChain(blockchain int64, log *xlog.XLog) blockchain.ChainConn { } func NewNFT(blockchain int64, log *xlog.XLog) blockchain.NFT { - if blockchain == chain.GetChainCode("ETH", log) { + if chain.GetChainCode(blockchain, "ETH", log) { //eth return ether.NewNFTClient() - } else if blockchain == chain.GetChainCode("POLYGON", log) { + } else if chain.GetChainCode(blockchain, "POLYGON", log) { return polygonpos.NewNFTClient() - } else if blockchain == chain.GetChainCode("BSC", log) { + } else if chain.GetChainCode(blockchain, "BSC", log) { return bnb.NewNFTClient() } else { return nil diff --git a/blockchain/service/gw.go b/blockchain/service/gw.go index 9539648..b419204 100644 --- a/blockchain/service/gw.go +++ b/blockchain/service/gw.go @@ -15,30 +15,30 @@ import ( ) func NewApi(blockchain int64, cluster []*config.NodeCluster, xlog *xlog.XLog) blockchain.API { - if blockchain == chain.GetChainCode("ETH", xlog) { + if chain.GetChainCode(blockchain, "ETH", xlog) { return ether.NewEth(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("TRON", xlog) { + } else if chain.GetChainCode(blockchain, "TRON", xlog) { return tron.NewTron(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("POLYGON", xlog) { + } else if chain.GetChainCode(blockchain, "POLYGON", xlog) { return polygon.NewPolygonPos(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("BSC", xlog) { + } else if chain.GetChainCode(blockchain, "BSC", xlog) { return bnb.NewBnb(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("BTC", xlog) { + } else if chain.GetChainCode(blockchain, "BTC", xlog) { return btc.NewBtc(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("FIL", xlog) { + } else if chain.GetChainCode(blockchain, "FIL", xlog) { return filecoin.NewFileCoin(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("XRP", xlog) { + } else if chain.GetChainCode(blockchain, "XRP", xlog) { return xrp.NewXRP(cluster, blockchain, xlog) } return nil } func NewNftApi(blockchain int64, cluster []*config.NodeCluster, xlog *xlog.XLog) blockchain.NftApi { - if blockchain == chain.GetChainCode("ETH", xlog) { + if chain.GetChainCode(blockchain, "ETH", xlog) { return ether.NewNftEth(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("POLYGON", xlog) { + } else if chain.GetChainCode(blockchain, "POLYGON", xlog) { return polygon.NewNftPolygonPos(cluster, blockchain, xlog) - } else if blockchain == chain.GetChainCode("BSC", xlog) { + } else if chain.GetChainCode(blockchain, "BSC", xlog) { return bnb.NewNftBnb(cluster, blockchain, xlog) } return nil diff --git a/collect/service/cmd/chain/gw.go b/collect/service/cmd/chain/gw.go index 15987bf..910397a 100644 --- a/collect/service/cmd/chain/gw.go +++ b/collect/service/cmd/chain/gw.go @@ -25,19 +25,19 @@ func GetBlockchain(blockchain int, c *config.Chain, store collect.StoreTaskInter code := int64(blockchain) x := xlog.NewXLogger().BuildOutType(xlog.FILE).BuildFormatter(xlog.FORMAT_JSON).BuildLevel(xlog.Level(logConfig.LogLevel)).BuildFile(fmt.Sprintf("%v/chain_info", logConfig.Path), 24*time.Hour) var srv collect.BlockChainInterface - if code == chainCode.GetChainCode("ETH", x) { + if chainCode.GetChainCode(code, "ETH", x) { srv = ether.NewService(c, x, store, nodeId, collect.EthTopic, collect.EthNftTransferSingleTopic) - } else if code == chainCode.GetChainCode("TRON", x) { + } else if chainCode.GetChainCode(code, "TRON", x) { srv = tron2.NewService(c, x, store, nodeId, collect.TronTopic) - } else if code == chainCode.GetChainCode("POLYGON", x) { + } else if chainCode.GetChainCode(code, "POLYGON", x) { srv = polygonpos.NewService(c, x, store, nodeId, collect.PolygonTopic, collect.EthNftTransferSingleTopic) - } else if code == chainCode.GetChainCode("BSC", x) { + } else if chainCode.GetChainCode(code, "BSC", x) { srv = bnb.NewService(c, x, store, nodeId, collect.EthTopic, collect.EthNftTransferSingleTopic) - } else if code == chainCode.GetChainCode("FIL", x) { + } else if chainCode.GetChainCode(code, "FIL", x) { srv = filecoin.NewService(c, x, store, nodeId, "") - } else if code == chainCode.GetChainCode("XRP", x) { + } else if chainCode.GetChainCode(code, "XRP", x) { srv = xrp.NewService(c, x, store, nodeId, "") - } else if code == chainCode.GetChainCode("BTC", x) { + } else if chainCode.GetChainCode(code, "BTC", x) { srv = btc.NewService(c, x, store, nodeId) } @@ -48,18 +48,18 @@ func GetTxHashFromKafka(blockchain int, txMsg []byte) string { code := int64(blockchain) r := gjson.ParseBytes(txMsg) var txHash string - if code == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(code, "ETH", nil) { txHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(code, "TRON", nil) { tx := r.Get("tx").String() txHash = gjson.Parse(tx).Get("txID").String() - } else if code == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(code, "POLYGON", nil) { txHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(code, "BSC", nil) { txHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(code, "FIL", nil) { txHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(code, "XRP", nil) { txHash = r.Get("hash").String() } @@ -70,17 +70,17 @@ func GetBlockHashFromKafka(blockchain int, blockMsg []byte) string { code := int64(blockchain) r := gjson.ParseBytes(blockMsg) var blockHash string - if code == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(code, "ETH", nil) { blockHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(code, "TRON", nil) { blockHash = r.Get("blockID").String() - } else if code == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(code, "POLYGON", nil) { blockHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(code, "BSC", nil) { blockHash = r.Get("hash").String() - } else if code == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(code, "FIL", nil) { blockHash = r.Get("blockHash").String() - } else if code == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(code, "XRP", nil) { blockHash = r.Get("ledger_hash").String() } return blockHash @@ -90,17 +90,17 @@ func GetReceiptHashFromKafka(blockchain int, receiptMsg []byte) string { code := int64(blockchain) r := gjson.ParseBytes(receiptMsg) var txHash string - if code == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(code, "ETH", nil) { txHash = r.Get("transactionHash").String() - } else if code == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(code, "TRON", nil) { txHash = r.Get("id").String() - } else if code == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(code, "POLYGON", nil) { txHash = r.Get("transactionHash").String() - } else if code == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(code, "BSC", nil) { txHash = r.Get("transactionHash").String() - } else if code == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(code, "FIL", nil) { txHash = r.Get("transactionHash").String() - } else if code == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(code, "XRP", nil) { txHash = r.Get("hash").String() } return txHash diff --git a/common/chain/chain.go b/common/chain/chain.go index e231575..457f3e3 100644 --- a/common/chain/chain.go +++ b/common/chain/chain.go @@ -1,24 +1,47 @@ package chain import ( - "encoding/json" "io" "os" "github.com/sunjiangjun/xlog" + "github.com/tidwall/gjson" ) -var defaultChain = ` - { - "ETH": 200, - "POLYGON": 201, - "BSC": 202, - "TRON": 205, - "BTC": 300, - "FIL": 301, - "XRP": 310 -} -` +//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}} func LoadConfig(path string) (string, error) { f, err := os.OpenFile(path, os.O_RDONLY, os.ModeAppend) @@ -35,44 +58,56 @@ func LoadConfig(path string) (string, error) { return string(b), nil } -func LoadChainCodeFile(file string) map[string]int64 { - //default - body := defaultChain +func LoadChainCodeFile(file string) map[string]map[int64]int { + + mp := make(map[string]map[int64]int) //set customer config if len(file) > 1 { - f, _ := LoadConfig(file) - if len(f) > 1 { - body = f + 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) + for _, v := range list { + code := v.Int() + m[code] = 1 + } + mp[k] = m + return true + }) } - } - if len(body) < 1 { - return nil } - mp := make(map[string]int64) - err := json.Unmarshal([]byte(body), &mp) - if err != nil { - return nil + if len(mp) < 1 { + // default + mp = defaultChainCode } + return mp } -func GetChainCode(chainName string, log *xlog.XLog) int64 { +func GetChainCode(chainCode int64, chainName string, log *xlog.XLog) bool { if log == nil { log = xlog.NewXLogger() } mp := LoadChainCodeFile("./chain.json") if mp == nil { log.Errorf("unknown all chainCode,this is a fatal error") - return 0 + return false } - if code, ok := mp[chainName]; ok { - return code + if m, ok := mp[chainName]; ok { + if _, ok := m[chainCode]; ok { + return true + } else { + log.Errorf("unknown chainCode:%v,please check whether the system supports this chain", chainCode) + return false + } } else { - log.Errorf("unknown chainCode:%v,please check whether the system supports this chain", code) - return 0 + log.Errorf("unknown chainCode:%v,please check whether the system supports this chain", chainCode) + return false } } diff --git a/common/chain/chain.json b/common/chain/chain.json index 9329398..0c24507 100644 --- a/common/chain/chain.json +++ b/common/chain/chain.json @@ -1,9 +1,30 @@ { - "ETH": 200, - "POLYGON": 201, - "BSC": 202, - "TRON": 205, - "BTC": 300, - "FIL": 301, - "XRP": 310 + "ETH": [ + 200, + 2001 + ], + "POLYGON": [ + 201, + 2011 + ], + "BSC": [ + 202, + 2021 + ], + "TRON": [ + 205, + 2051 + ], + "BTC": [ + 300, + 3001 + ], + "FIL": [ + 301, + 3011 + ], + "XRP": [ + 310, + 3101 + ] } \ No newline at end of file diff --git a/common/chain/chain_test.go b/common/chain/chain_test.go index e28ecb3..fd14fe9 100644 --- a/common/chain/chain_test.go +++ b/common/chain/chain_test.go @@ -8,6 +8,6 @@ import ( ) func TestGetChainCode(t *testing.T) { - code := GetChainCode("ETH", xlog.NewXLogger()) + code := GetChainCode(200, "ETH", xlog.NewXLogger()) log.Println(code) } diff --git a/store/chain/gw.go b/store/chain/gw.go index d087701..1652ee0 100644 --- a/store/chain/gw.go +++ b/store/chain/gw.go @@ -16,19 +16,19 @@ import ( ) func GetReceiptFromKafka(value []byte, blockChain int64) (*store.Receipt, error) { - if blockChain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockChain, "ETH", nil) { return ether.GetReceiptFromKafka(value) - } else if blockChain == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(blockChain, "TRON", nil) { return tron.GetReceiptFromKafka(value) - } else if blockChain == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(blockChain, "POLYGON", nil) { return polygonpos.GetReceiptFromKafka(value) - } else if blockChain == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(blockChain, "BSC", nil) { return bnb.GetReceiptFromKafka(value) - } else if blockChain == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(blockChain, "FIL", nil) { return filecoin.GetReceiptFromKafka(value) - } else if blockChain == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(blockChain, "XRP", nil) { return xrp.GetReceiptFromKafka(value) - } else if blockChain == chainCode.GetChainCode("BTC", nil) { + } else if chainCode.GetChainCode(blockChain, "BTC", nil) { return btc.GetReceiptFromKafka(value) } else { return nil, fmt.Errorf("blockchain:%v does not support", blockChain) @@ -36,19 +36,19 @@ func GetReceiptFromKafka(value []byte, blockChain int64) (*store.Receipt, error) } func GetBlockFromKafka(value []byte, blockChain int64) (*store.Block, error) { - if blockChain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockChain, "ETH", nil) { return ether.GetBlockFromKafka(value) - } else if blockChain == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(blockChain, "TRON", nil) { return tron.GetBlockFromKafka(value) - } else if blockChain == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(blockChain, "POLYGON", nil) { return polygonpos.GetBlockFromKafka(value) - } else if blockChain == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(blockChain, "BSC", nil) { return bnb.GetBlockFromKafka(value) - } else if blockChain == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(blockChain, "FIL", nil) { return filecoin.GetBlockFromKafka(value) - } else if blockChain == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(blockChain, "XRP", nil) { return xrp.GetBlockFromKafka(value) - } else if blockChain == chainCode.GetChainCode("BTC", nil) { + } else if chainCode.GetChainCode(blockChain, "BTC", nil) { return btc.GetBlockFromKafka(value) } else { return nil, fmt.Errorf("blockchain:%v does not support", blockChain) @@ -56,19 +56,19 @@ func GetBlockFromKafka(value []byte, blockChain int64) (*store.Block, error) { } func GetTxFromKafka(value []byte, blockChain int64) (*store.Tx, error) { - if blockChain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockChain, "ETH", nil) { return ether.GetTxFromKafka(value) - } else if blockChain == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(blockChain, "TRON", nil) { return tron.GetTxFromKafka(value) - } else if blockChain == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(blockChain, "POLYGON", nil) { return polygonpos.GetTxFromKafka(value) - } else if blockChain == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(blockChain, "BSC", nil) { return bnb.GetTxFromKafka(value) - } else if blockChain == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(blockChain, "FIL", nil) { return filecoin.GetTxFromKafka(value) - } else if blockChain == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(blockChain, "XRP", nil) { return xrp.GetTxFromKafka(value) - } else if blockChain == chainCode.GetChainCode("BTC", nil) { + } else if chainCode.GetChainCode(blockChain, "BTC", nil) { return btc.GetTxFromKafka(value) } else { return nil, fmt.Errorf("blockchain:%v does not support", blockChain) @@ -76,69 +76,69 @@ func GetTxFromKafka(value []byte, blockChain int64) (*store.Tx, error) { } func ParseTx(blockchain int64, msg *kafka.Message) (*store.SubTx, error) { - if blockchain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockchain, "ETH", nil) { return ether.ParseTx(msg.Value, store.EthTopic, store.EthTransferSingleTopic, blockchain) } - if blockchain == chainCode.GetChainCode("TRON", nil) { + if chainCode.GetChainCode(blockchain, "TRON", nil) { return tron.ParseTx(msg.Value, store.TronTopic, blockchain) } - if blockchain == chainCode.GetChainCode("POLYGON", nil) { + if chainCode.GetChainCode(blockchain, "POLYGON", nil) { return polygonpos.ParseTx(msg.Value, store.PolygonTopic, store.EthTransferSingleTopic, blockchain) } - if blockchain == chainCode.GetChainCode("BSC", nil) { + if chainCode.GetChainCode(blockchain, "BSC", nil) { return bnb.ParseTx(msg.Value, store.EthTopic, store.EthTransferSingleTopic, blockchain) } - if blockchain == chainCode.GetChainCode("FIL", nil) { + if chainCode.GetChainCode(blockchain, "FIL", nil) { return filecoin.ParseTx(msg.Value, store.PolygonTopic, blockchain) } - if blockchain == chainCode.GetChainCode("XRP", nil) { + if chainCode.GetChainCode(blockchain, "XRP", nil) { return xrp.ParseTx(msg.Value, "", blockchain) } - if blockchain == chainCode.GetChainCode("BTC", nil) { + if chainCode.GetChainCode(blockchain, "BTC", nil) { return btc.ParseTx(msg.Value, blockchain) } return nil, nil } func GetTxType(blockchain int64, msg *kafka.Message) (uint64, error) { - if blockchain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockchain, "ETH", nil) { return ether.GetTxType(msg.Value) } - if blockchain == chainCode.GetChainCode("BSC", nil) { + if chainCode.GetChainCode(blockchain, "BSC", nil) { return bnb.GetTxType(msg.Value) } - if blockchain == chainCode.GetChainCode("TRON", nil) { + if chainCode.GetChainCode(blockchain, "TRON", nil) { return tron.GetTxType(msg.Value) } - if blockchain == chainCode.GetChainCode("POLYGON", nil) { + if chainCode.GetChainCode(blockchain, "POLYGON", nil) { return polygonpos.GetTxType(msg.Value) } - if blockchain == chainCode.GetChainCode("FIL", nil) { + if chainCode.GetChainCode(blockchain, "FIL", nil) { return filecoin.GetTxType(msg.Value) } - if blockchain == chainCode.GetChainCode("XRP", nil) { + if chainCode.GetChainCode(blockchain, "XRP", nil) { return xrp.GetTxType(msg.Value) } - if blockchain == chainCode.GetChainCode("BTC", nil) { + if chainCode.GetChainCode(blockchain, "BTC", nil) { return btc.GetTxType(msg.Value) } return 0, nil } func GetCoreAddress(blockChain int64, address string) string { - if blockChain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockChain, "ETH", nil) { return ether.GetCoreAddr(address) - } else if blockChain == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(blockChain, "TRON", nil) { return tron.GetCoreAddr(address) - } else if blockChain == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(blockChain, "POLYGON", nil) { return polygonpos.GetCoreAddr(address) - } else if blockChain == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(blockChain, "BSC", nil) { return bnb.GetCoreAddr(address) - } else if blockChain == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(blockChain, "FIL", nil) { return filecoin.GetCoreAddr(address) - } else if blockChain == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(blockChain, "XRP", nil) { return xrp.GetCoreAddr(address) - } else if blockChain == chainCode.GetChainCode("BTC", nil) { + } else if chainCode.GetChainCode(blockChain, "BTC", nil) { return btc.GetCoreAddr(address) } else { return address @@ -149,19 +149,19 @@ func CheckAddress(blockChain int64, msg *kafka.Message, list map[string]*store.M if len(list) < 1 { return false } - if blockChain == chainCode.GetChainCode("ETH", nil) { + if chainCode.GetChainCode(blockChain, "ETH", nil) { return ether.CheckAddress(msg.Value, list, store.EthTopic, store.EthTransferSingleTopic) - } else if blockChain == chainCode.GetChainCode("TRON", nil) { + } else if chainCode.GetChainCode(blockChain, "TRON", nil) { return tron.CheckAddress(msg.Value, list, store.TronTopic) - } else if blockChain == chainCode.GetChainCode("POLYGON", nil) { + } else if chainCode.GetChainCode(blockChain, "POLYGON", nil) { return polygonpos.CheckAddress(msg.Value, list, store.PolygonTopic, store.EthTransferSingleTopic) - } else if blockChain == chainCode.GetChainCode("BSC", nil) { + } else if chainCode.GetChainCode(blockChain, "BSC", nil) { return bnb.CheckAddress(msg.Value, list, store.EthTopic, store.EthTransferSingleTopic) - } else if blockChain == chainCode.GetChainCode("FIL", nil) { + } else if chainCode.GetChainCode(blockChain, "FIL", nil) { return filecoin.CheckAddress(msg.Value, list, store.PolygonTopic) - } else if blockChain == chainCode.GetChainCode("XRP", nil) { + } else if chainCode.GetChainCode(blockChain, "XRP", nil) { return xrp.CheckAddress(msg.Value, list, "") - } else if blockChain == chainCode.GetChainCode("BTC", nil) { + } else if chainCode.GetChainCode(blockChain, "BTC", nil) { return btc.CheckAddress(msg.Value, list) } else { return false diff --git a/store/chain/gw_test.go b/store/chain/gw_test.go new file mode 100644 index 0000000..170925c --- /dev/null +++ b/store/chain/gw_test.go @@ -0,0 +1,8 @@ +package chain + +import "testing" + +func TestGetCoreAddress(t *testing.T) { + addr := GetCoreAddress(200, "0xb6e268b6675846104feef5582d22f40723164d05") + t.Log(addr) +} diff --git a/task/service/taskcreate/gw.go b/task/service/taskcreate/gw.go index a3b0f28..31e32c0 100644 --- a/task/service/taskcreate/gw.go +++ b/task/service/taskcreate/gw.go @@ -15,19 +15,19 @@ import ( ) func NewApi(blockchain int64, log *xlog.XLog, v *config.BlockConfig) task.BlockChainInterface { - if blockchain == chain.GetChainCode("ETH", log) { + if chain.GetChainCode(blockchain, "ETH", log) { return ether.NewEther(log, v) - } else if blockchain == chain.GetChainCode("TRON", log) { + } else if chain.GetChainCode(blockchain, "TRON", log) { return tron.NewTron(log, v) - } else if blockchain == chain.GetChainCode("POLYGON", log) { + } else if chain.GetChainCode(blockchain, "POLYGON", log) { return polygonpos.NewPolygonPos(log, v) - } else if blockchain == chain.GetChainCode("BSC", log) { + } else if chain.GetChainCode(blockchain, "BSC", log) { return bnb.NewBnb(log, v) - } else if blockchain == chain.GetChainCode("FIL", log) { + } else if chain.GetChainCode(blockchain, "FIL", log) { return filecoin.NewFileCoin(log, v) - } else if blockchain == chain.GetChainCode("XRP", log) { + } else if chain.GetChainCode(blockchain, "XRP", log) { return xrp.NewXRP(log, v) - } else if blockchain == chain.GetChainCode("BTC", log) { + } else if chain.GetChainCode(blockchain, "BTC", log) { return btc.NewBtc(log, v) } return nil