From fc79ea1d5f9e74951bfc505b1d7439fc722df496 Mon Sep 17 00:00:00 2001 From: sunjiangjun Date: Fri, 1 Mar 2024 18:33:26 +0800 Subject: [PATCH] Revert "feat: Hotfix/release 0.6.0" --- README.md | 29 ++++------- README_zh.md | 29 ++++------- blockchain/service/http_handler.go | 32 ++++-------- cmd/blockchain/README.md | 2 +- cmd/blockchain/app.go | 2 +- cmd/blockchain/config_pro.json | 81 ------------------------------ common/chain/chain.go | 49 +++++++++--------- 7 files changed, 54 insertions(+), 170 deletions(-) delete mode 100644 cmd/blockchain/config_pro.json diff --git a/README.md b/README.md index 519f5ff..921c76d 100644 --- a/README.md +++ b/README.md @@ -34,26 +34,15 @@ Allow all developers to use on-chain services without deploying nodes or knowing ## Blockchain for table - | blockchain | chaincode | desc | - |:----------------|:---------:|:-------:| - | ethereum | 200 | ETH | - | ethereum.Goerli | 20001 | ETH | - | tron | 205 | TRX | - | tron.shasta | 2051 | TRX | - | polygon-pos | 201 | POLYGON | - | arbitrum | 42161 | ARB | - | optimism | 42162 | OP | - | base | 8453 | BASE | - | avalanche-C | 43114 | AVAX | - | bitcoin | 300 | BTC | - | filecoin | 301 | FIL | - | ripple | 310 | XRP | - | bsc | 202 | BNB | - | bsc.testnet | 2021 | BNB | - -tips: - - *chaincode can set by clients* + | blockchain | chaincode | desc | + |:------------|:---------:|:-------:| + | ethereum | 200 | ETH | + | tron | 205 | TRX | + | polygon-pos | 201 | POLYGON | + | bitcoin | 300 | BTC | + | filecoin | 301 | FIL | + | ripple | 310 | XRP | + | bnb | 202 | BNB | ## Getting Started diff --git a/README_zh.md b/README_zh.md index 89a7105..f0472d7 100644 --- a/README_zh.md +++ b/README_zh.md @@ -32,26 +32,15 @@ ## 公链表 -| blockchain | chaincode | desc | - |:----------------|:---------:|:-------:| -| ethereum | 200 | ETH | -| ethereum.Goerli | 20001 | ETH | -| tron | 205 | TRX | -| tron.shasta | 2051 | TRX | -| polygon-pos | 201 | POLYGON | -| arbitrum | 42161 | ARB | -| optimism | 42162 | OP | -| base | 8453 | BASE | -| avalanche-C | 43114 | AVAX | -| bitcoin | 300 | BTC | -| filecoin | 301 | FIL | -| ripple | 310 | XRP | -| bsc | 202 | BNB | -| bsc.testnet | 2021 | BNB | - -提示: - -*chaincode 可以有用户自定义* +| blockchain | chaincode | desc | +|:------------|:---------:|:-------:| +| ethereum | 200 | ETH | +| tron | 205 | TRX | +| polygon-pos | 201 | POLYGON | +| bitcoin | 300 | BTC | +| filecoin | 301 | FIL | +| ripple | 310 | XRP | +| bnb | 202 | BNB | ## 入门指引 diff --git a/blockchain/service/http_handler.go b/blockchain/service/http_handler.go index 76173c0..dbfdac5 100644 --- a/blockchain/service/http_handler.go +++ b/blockchain/service/http_handler.go @@ -35,23 +35,17 @@ type HttpHandler struct { func (h *HttpHandler) StartKafka(ctx context.Context) { go func(ctx context.Context) { - if h.kafkaCfg != nil { - broker := fmt.Sprintf("%v:%v", h.kafkaCfg.Host, h.kafkaCfg.Port) - kafkaCtx, cancel := context.WithCancel(ctx) - defer cancel() - h.kafkaClient.Write(easyKafka.Config{Brokers: []string{broker}}, h.sendCh, nil, kafkaCtx) - } + broker := fmt.Sprintf("%v:%v", h.kafkaCfg.Host, h.kafkaCfg.Port) + kafkaCtx, cancel := context.WithCancel(ctx) + defer cancel() + h.kafkaClient.Write(easyKafka.Config{Brokers: []string{broker}}, h.sendCh, nil, kafkaCtx) }(ctx) } func NewHttpHandler(cluster map[int64][]*config.NodeCluster, kafkaCfg *config.Kafka, xlog *xlog.XLog) *HttpHandler { x := xlog.WithField("model", "httpSrv") - - var kafkaClient *easyKafka.EasyKafka + kafkaClient := easyKafka.NewEasyKafka2(x) sendCh := make(chan []*kafka.Message) - if kafkaCfg != nil { - kafkaClient = easyKafka.NewEasyKafka2(x) - } return &HttpHandler{ log: x, nodeCluster: cluster, @@ -551,11 +545,9 @@ func (h *HttpHandler) SendRawTx(ctx *gin.Context) { } defer func(backup map[string]any, chainCode int64) { - if h.kafkaClient != nil { - bs, _ := json.Marshal(backup) - msg := &kafka.Message{Topic: fmt.Sprintf("%v-%v", h.kafkaCfg.Topic, chainCode), Partition: h.kafkaCfg.Partition, Key: []byte(fmt.Sprintf("%v", time.Now().UnixNano())), Value: bs} - h.sendCh <- []*kafka.Message{msg} - } + bs, _ := json.Marshal(backup) + msg := &kafka.Message{Topic: fmt.Sprintf("%v-%v", h.kafkaCfg.Topic, chainCode), Partition: h.kafkaCfg.Partition, Key: []byte(fmt.Sprintf("%v", time.Now().UnixNano())), Value: bs} + h.sendCh <- []*kafka.Message{msg} }(backup, blockChainCode) res, err := h.blockChainClients[blockChainCode].SendRawTransaction(blockChainCode, signedTx) @@ -618,11 +610,9 @@ func (h *HttpHandler) SendRawTx1(ctx *gin.Context) { } defer func(backup map[string]any, chainCode int64) { - if h.kafkaClient != nil { - bs, _ := json.Marshal(backup) - msg := &kafka.Message{Topic: fmt.Sprintf("%v-%v", h.kafkaCfg.Topic, chainCode), Partition: h.kafkaCfg.Partition, Key: []byte(fmt.Sprintf("%v", time.Now().UnixNano())), Value: bs} - h.sendCh <- []*kafka.Message{msg} - } + bs, _ := json.Marshal(backup) + msg := &kafka.Message{Topic: fmt.Sprintf("%v-%v", h.kafkaCfg.Topic, chainCode), Partition: h.kafkaCfg.Partition, Key: []byte(fmt.Sprintf("%v", time.Now().UnixNano())), Value: bs} + h.sendCh <- []*kafka.Message{msg} }(backup, blockChainCode) res, err := h.blockChainClients[blockChainCode].SendRawTransaction(blockChainCode, signedTx) diff --git a/cmd/blockchain/README.md b/cmd/blockchain/README.md index 16d916c..95496c9 100644 --- a/cmd/blockchain/README.md +++ b/cmd/blockchain/README.md @@ -551,7 +551,7 @@ curl -X POST \ -H 'Postman-Token: 709ff247-53e9-4c90-bccc-3e1c3a6f241a' \ -H 'cache-control: no-cache' \ -d '{ - "chain": 1 + "chain": 200 }' response: diff --git a/cmd/blockchain/app.go b/cmd/blockchain/app.go index 4cc9fbb..13290dc 100644 --- a/cmd/blockchain/app.go +++ b/cmd/blockchain/app.go @@ -15,7 +15,7 @@ import ( func main() { var configPath string - flag.StringVar(&configPath, "blockchain", "./cmd/blockchain/config_pro.json", "The system file of config") + flag.StringVar(&configPath, "blockchain", "./cmd/blockchain/config_ether.json", "The system file of config") flag.Parse() if len(configPath) < 1 { panic("can not find config file") diff --git a/cmd/blockchain/config_pro.json b/cmd/blockchain/config_pro.json deleted file mode 100644 index a241fd9..0000000 --- a/cmd/blockchain/config_pro.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "RootPath": "/api/chain", - "Port": 9002, - "Nodes": [ - { - "BlockChain": 200, - "NodeUrl": "https://eth.llamarpc.com", - "NodeToken": "" - }, - { - "BlockChain": 200, - "NodeUrl": "https://rpc.ankr.com/eth", - "NodeToken": "" - }, - { - "BlockChain": 2001, - "NodeUrl": "https://eth-goerli.public.blastapi.io", - "NodeToken": "" - }, - { - "BlockChain": 42161, - "NodeUrl": "https://arbitrum.blockpi.network/v1/rpc/public", - "NodeToken": "" - }, - { - "BlockChain": 42161, - "NodeUrl": "https://arbitrum-one.publicnode.com", - "NodeToken": "" - }, - { - "BlockChain": 42162, - "NodeUrl": "https://optimism.meowrpc.com", - "NodeToken": "" - }, - { - "BlockChain": 42162, - "NodeUrl": "https://optimism-rpc.publicnode.com", - "NodeToken": "" - }, - { - "BlockChain": 8453, - "NodeUrl": "https://base-rpc.publicnode.com", - "NodeToken": "" - }, - { - "BlockChain": 8453, - "NodeUrl": "https://base.llamarpc.com", - "NodeToken": "" - }, - { - "BlockChain": 43114, - "NodeUrl": "https://avalanche.public-rpc.com", - "NodeToken": "" - }, - { - "BlockChain": 43114, - "NodeUrl": "https://endpoints.omniatech.io/v1/avax/mainnet/public", - "NodeToken": "" - }, - { - "BlockChain": 202, - "NodeUrl": "https://binance.llamarpc.com", - "NodeToken": "" - }, - { - "BlockChain": 202, - "NodeUrl": "https://bsc-dataseed1.defibit.io", - "NodeToken": "" - }, - { - "BlockChain": 2021, - "NodeUrl": "https://data-seed-prebsc-2-s2.bnbchain.org:8545", - "NodeToken": "" - }, - { - "BlockChain": 2021, - "NodeUrl": "https://endpoints.omniatech.io/v1/bsc/testnet/public", - "NodeToken": "" - } - ] -} \ No newline at end of file diff --git a/common/chain/chain.go b/common/chain/chain.go index 6cddd7b..19b8a7c 100644 --- a/common/chain/chain.go +++ b/common/chain/chain.go @@ -9,37 +9,34 @@ import ( ) // dev -var defaultChainCode = map[string]map[int64]int8{ - "ETH": {200: 1, 2001: 1}, - "POLYGON": {201: 1, 42161: 1, 42162: 1, 8453: 1, 43114: 1}, - "BSC": {202: 1, 2021: 1}, - "TRON": {205: 1, 2051: 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}, +//} /** - eth: 1: main,5:Goerli - L2: 42161:arb.main,10:op.main,8453:base.main 43114:aval.main - polygon: 137:main, - bsc: 56:main,97:test - tron: 115:main,118:test - btc:198:main - fil: 314:main - xrp: 144:main + + arb:63 + op:64 + aval:65 + base:66 */ // main -//var defaultChainCode = map[string]map[int64]int8{ -// "ETH": {1: 1, 5: 1}, -// "POLYGON": {137: 1, 42161: 1, 10: 1, 8453: 1, 43114: 1}, -// "BSC": {56: 1, 97: 1}, -// "TRON": {115: 1, 118: 1}, -// "BTC": {198: 1, 199: 1}, -// "FIL": {314: 1}, -// "XRP": {144: 1}, -//} +var defaultChainCode = map[string]map[int64]int8{ + "ETH": {60: 1, 6001: 1}, + "POLYGON": {62: 1, 6201: 1, 63: 1, 64: 1, 65: 1, 66: 1}, + "BSC": {2510: 1, 2610: 1}, + "TRON": {195: 1, 198: 1}, + "BTC": {0: 1, 1: 1}, + "FIL": {2307: 1}, + "XRP": {144: 1}, +} func LoadConfig(path string) (string, error) { f, err := os.OpenFile(path, os.O_RDONLY, os.ModeAppend)