Skip to content

Commit

Permalink
Merge pull request #103 from 0xcregis/revert-102-hotfix/release-0.6.0
Browse files Browse the repository at this point in the history
Revert "feat: Hotfix/release 0.6.0"
  • Loading branch information
sunjiangjun authored Mar 1, 2024
2 parents aa736d6 + fc79ea1 commit a8f41d8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 170 deletions.
29 changes: 9 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 9 additions & 20 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

## 入门指引

Expand Down
32 changes: 11 additions & 21 deletions blockchain/service/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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": 1
"chain": 200
}'
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_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")
Expand Down
81 changes: 0 additions & 81 deletions cmd/blockchain/config_pro.json

This file was deleted.

49 changes: 23 additions & 26 deletions common/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8f41d8

Please sign in to comment.