Skip to content

Commit 226baf6

Browse files
authored
Merge pull request #91 from 0xcregis/release-0.5.2
fix: Release 0.5.2
2 parents 9949cca + 10b12d6 commit 226baf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1536
-407
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ go.work
2626
.idea/*
2727
/clickhouse_data/
2828
/redis_data/
29-
/build/config/
3029

3130
/kafka_data/
3231
/zookeeper_data/

blockchain/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ type API interface {
3737
StartWDT()
3838
MonitorCluster() any
3939
}
40+
41+
type ExApi interface {
42+
GasPrice(chainCode int64) (string, error)
43+
EstimateGas(chainCode int64, from, to, data string) (string, error)
44+
EstimateGasForTron(chainCode int64, from, to, functionSelector, parameter string) (string, error)
45+
GetAccountResourceForTron(chainCode int64, address string) (string, error)
46+
}

blockchain/service/bnb/bnb.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ func NewBnb(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) bl
315315
return e
316316
}
317317

318+
func NewBnb2(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) blockchain.ExApi {
319+
blockChainClient := chain.NewChain(blockchain, xlog)
320+
if blockChainClient == nil {
321+
return nil
322+
}
323+
e := &Bnb{
324+
log: xlog,
325+
nodeCluster: cluster,
326+
blockChainClient: blockChainClient,
327+
}
328+
e.StartWDT()
329+
return e
330+
}
331+
318332
func (e *Bnb) StartWDT() {
319333
go func() {
320334
t := time.NewTicker(10 * time.Minute)
@@ -398,6 +412,53 @@ func (e *Bnb) LatestBlock(chainCode int64) (string, error) {
398412
return e.SendReq(chainCode, req)
399413
}
400414

415+
func (e *Bnb) GetAccountResourceForTron(chainCode int64, address string) (string, error) {
416+
return "", nil
417+
}
418+
419+
func (e *Bnb) EstimateGasForTron(chainCode int64, from, to, functionSelector, parameter string) (string, error) {
420+
return "", nil
421+
}
422+
423+
func (e *Bnb) EstimateGas(chainCode int64, from, to, data string) (string, error) {
424+
req := `
425+
{
426+
"id": 1,
427+
"jsonrpc": "2.0",
428+
"method": "eth_estimateGas",
429+
"params": [
430+
{
431+
"from":"%v",
432+
"to": "%v",
433+
"data": "%v"
434+
}
435+
]
436+
}`
437+
req = fmt.Sprintf(req, from, to, data)
438+
res, err := e.SendJsonRpc(chainCode, req)
439+
if err != nil {
440+
return "", err
441+
}
442+
return res, nil
443+
}
444+
445+
func (e *Bnb) GasPrice(chainCode int64) (string, error) {
446+
req := `
447+
{
448+
"id": 1,
449+
"jsonrpc": "2.0",
450+
"method": "eth_gasPrice"
451+
}
452+
`
453+
454+
//req = fmt.Sprintf(req, from, to, functionSelector, parameter)
455+
res, err := e.SendJsonRpc(chainCode, req)
456+
if err != nil {
457+
return "", err
458+
}
459+
return res, nil
460+
}
461+
401462
func (e *Bnb) SendRawTransaction(chainCode int64, signedTx string) (string, error) {
402463
req := `{
403464
"id": 1,

blockchain/service/bnb/bnb_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
)
1111

1212
func Init() blockchain.API {
13-
cfg := config.LoadConfig("./../../../cmd/blockchain/config_bnb.json")
14-
return NewBnb(cfg.Cluster[202], 202, xlog.NewXLogger())
13+
cfg := config.LoadConfig("./../../../cmd/blockchain/blockchain_config.json")
14+
return NewBnb(cfg.Cluster[2610], 2610, xlog.NewXLogger())
1515
}
1616

1717
func TestBnb_Token(t *testing.T) {
@@ -26,7 +26,7 @@ func TestBnb_Token(t *testing.T) {
2626

2727
func TestBnb_TokenBalance(t *testing.T) {
2828
s := Init()
29-
resp, err := s.TokenBalance(202, "0x403f9D1EA51D55d0341ce3c2fBF33E09846F2C74", "0x55d398326f99059fF775485246999027B3197955", "")
29+
resp, err := s.TokenBalance(2610, "0xf0e4939183a76746e602a12c389ab183be4290b1", "0x337610d27c682e347c9cd60bd4b3b107c9d34ddd", "")
3030

3131
if err != nil {
3232
t.Error(err)

blockchain/service/ether/ether.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,20 @@ func NewEth(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) bl
335335
return e
336336
}
337337

338+
func NewEth2(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) blockchain.ExApi {
339+
blockChainClient := chain.NewChain(blockchain, xlog)
340+
if blockChainClient == nil {
341+
return nil
342+
}
343+
e := &Ether{
344+
log: xlog,
345+
nodeCluster: cluster,
346+
blockChainClient: blockChainClient,
347+
}
348+
e.StartWDT()
349+
return e
350+
}
351+
338352
func (e *Ether) StartWDT() {
339353
go func() {
340354
t := time.NewTicker(10 * time.Minute)
@@ -431,6 +445,53 @@ func (e *Ether) SendRawTransaction(chainCode int64, signedTx string) (string, er
431445
return e.SendReq(chainCode, req)
432446
}
433447

448+
func (e *Ether) GetAccountResourceForTron(chainCode int64, address string) (string, error) {
449+
return "", nil
450+
}
451+
452+
func (e *Ether) EstimateGasForTron(chainCode int64, from, to, functionSelector, parameter string) (string, error) {
453+
return "", nil
454+
}
455+
456+
func (e *Ether) EstimateGas(chainCode int64, from, to, data string) (string, error) {
457+
req := `
458+
{
459+
"id": 1,
460+
"jsonrpc": "2.0",
461+
"method": "eth_estimateGas",
462+
"params": [
463+
{
464+
"from":"%v",
465+
"to": "%v",
466+
"data": "%v"
467+
}
468+
]
469+
}`
470+
req = fmt.Sprintf(req, from, to, data)
471+
res, err := e.SendJsonRpc(chainCode, req)
472+
if err != nil {
473+
return "", err
474+
}
475+
return res, nil
476+
}
477+
478+
func (e *Ether) GasPrice(chainCode int64) (string, error) {
479+
req := `
480+
{
481+
"id": 1,
482+
"jsonrpc": "2.0",
483+
"method": "eth_gasPrice"
484+
}
485+
`
486+
487+
//req = fmt.Sprintf(req, from, to, functionSelector, parameter)
488+
res, err := e.SendJsonRpc(chainCode, req)
489+
if err != nil {
490+
return "", err
491+
}
492+
return res, nil
493+
}
494+
434495
func (e *Ether) SendReqByWs(blockChain int64, receiverCh chan string, sendCh chan string) (string, error) {
435496
cluster := e.BalanceCluster()
436497
if cluster == nil {

blockchain/service/gw.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,26 @@ func NewNftApis(clusters map[int64][]*config.NodeCluster, xlog *xlog.XLog) map[i
5959
}
6060
return blockChainClients
6161
}
62+
63+
func NewExApi(clusters map[int64][]*config.NodeCluster, xlog *xlog.XLog) map[int64]blockchain.ExApi {
64+
blockChainClients := make(map[int64]blockchain.ExApi, 0)
65+
for chainCode, cluster := range clusters {
66+
if chain.GetChainCode(chainCode, "TRON", xlog) {
67+
blockChainClients[chainCode] = tron.NewTron2(cluster, chainCode, xlog)
68+
}
69+
70+
if chain.GetChainCode(chainCode, "ETH", xlog) {
71+
blockChainClients[chainCode] = ether.NewEth2(cluster, chainCode, xlog)
72+
}
73+
74+
if chain.GetChainCode(chainCode, "POLYGON", xlog) {
75+
blockChainClients[chainCode] = polygon.NewPolygonPos2(cluster, chainCode, xlog)
76+
}
77+
78+
if chain.GetChainCode(chainCode, "BSC", xlog) {
79+
blockChainClients[chainCode] = bnb.NewBnb2(cluster, chainCode, xlog)
80+
}
81+
82+
}
83+
return blockChainClients
84+
}

0 commit comments

Comments
 (0)