Skip to content

Commit

Permalink
Merge pull request #102 from sunjiangjun/hotfix/release-0.6.0
Browse files Browse the repository at this point in the history
feat: Hotfix/release 0.6.0
  • Loading branch information
sunjiangjun authored Mar 1, 2024
2 parents fa2a20e + 8111be8 commit aa736d6
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 54 deletions.
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,26 @@ Allow all developers to use on-chain services without deploying nodes or knowing

## Blockchain for table

| 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 |
| 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*

## Getting Started

Expand Down
29 changes: 20 additions & 9 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@

## 公链表

| 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 |
| 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 可以有用户自定义*

## 入门指引

Expand Down
32 changes: 21 additions & 11 deletions blockchain/service/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ type HttpHandler struct {

func (h *HttpHandler) StartKafka(ctx context.Context) {
go func(ctx context.Context) {
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)
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)
}
}(ctx)
}

func NewHttpHandler(cluster map[int64][]*config.NodeCluster, kafkaCfg *config.Kafka, xlog *xlog.XLog) *HttpHandler {
x := xlog.WithField("model", "httpSrv")
kafkaClient := easyKafka.NewEasyKafka2(x)

var kafkaClient *easyKafka.EasyKafka
sendCh := make(chan []*kafka.Message)
if kafkaCfg != nil {
kafkaClient = easyKafka.NewEasyKafka2(x)
}
return &HttpHandler{
log: x,
nodeCluster: cluster,
Expand Down Expand Up @@ -545,9 +551,11 @@ func (h *HttpHandler) SendRawTx(ctx *gin.Context) {
}

defer func(backup map[string]any, chainCode int64) {
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}
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}
}
}(backup, blockChainCode)

res, err := h.blockChainClients[blockChainCode].SendRawTransaction(blockChainCode, signedTx)
Expand Down Expand Up @@ -610,9 +618,11 @@ func (h *HttpHandler) SendRawTx1(ctx *gin.Context) {
}

defer func(backup map[string]any, chainCode int64) {
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}
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}
}
}(backup, blockChainCode)

res, err := h.blockChainClients[blockChainCode].SendRawTransaction(blockChainCode, signedTx)
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ curl -X POST \
-H 'Postman-Token: 709ff247-53e9-4c90-bccc-3e1c3a6f241a' \
-H 'cache-control: no-cache' \
-d '{
"chain": 200
"chain": 1
}'
response:
Expand Down
2 changes: 1 addition & 1 deletion cmd/blockchain/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func main() {
var configPath string
flag.StringVar(&configPath, "blockchain", "./cmd/blockchain/config_ether.json", "The system file of config")
flag.StringVar(&configPath, "blockchain", "./cmd/blockchain/config_pro.json", "The system file of config")
flag.Parse()
if len(configPath) < 1 {
panic("can not find config file")
Expand Down
81 changes: 81 additions & 0 deletions cmd/blockchain/config_pro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"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": ""
}
]
}
49 changes: 26 additions & 23 deletions common/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,37 @@ import (
)

// dev
//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},
//}
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},
}

/**
arb:63
op:64
aval:65
base:66
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
*/

// main
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},
}
//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},
//}

func LoadConfig(path string) (string, error) {
f, err := os.OpenFile(path, os.O_RDONLY, os.ModeAppend)
Expand Down

0 comments on commit aa736d6

Please sign in to comment.