Skip to content

Commit

Permalink
Merge pull request #91 from 0xcregis/release-0.5.2
Browse files Browse the repository at this point in the history
fix: Release 0.5.2
  • Loading branch information
sunjiangjun authored Jan 3, 2024
2 parents 9949cca + 10b12d6 commit 226baf6
Show file tree
Hide file tree
Showing 45 changed files with 1,536 additions and 407 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ go.work
.idea/*
/clickhouse_data/
/redis_data/
/build/config/

/kafka_data/
/zookeeper_data/
Expand Down
7 changes: 7 additions & 0 deletions blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ type API interface {
StartWDT()
MonitorCluster() any
}

type ExApi interface {
GasPrice(chainCode int64) (string, error)
EstimateGas(chainCode int64, from, to, data string) (string, error)
EstimateGasForTron(chainCode int64, from, to, functionSelector, parameter string) (string, error)
GetAccountResourceForTron(chainCode int64, address string) (string, error)
}
61 changes: 61 additions & 0 deletions blockchain/service/bnb/bnb.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ func NewBnb(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) bl
return e
}

func NewBnb2(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) blockchain.ExApi {
blockChainClient := chain.NewChain(blockchain, xlog)
if blockChainClient == nil {
return nil
}
e := &Bnb{
log: xlog,
nodeCluster: cluster,
blockChainClient: blockChainClient,
}
e.StartWDT()
return e
}

func (e *Bnb) StartWDT() {
go func() {
t := time.NewTicker(10 * time.Minute)
Expand Down Expand Up @@ -398,6 +412,53 @@ func (e *Bnb) LatestBlock(chainCode int64) (string, error) {
return e.SendReq(chainCode, req)
}

func (e *Bnb) GetAccountResourceForTron(chainCode int64, address string) (string, error) {
return "", nil
}

func (e *Bnb) EstimateGasForTron(chainCode int64, from, to, functionSelector, parameter string) (string, error) {
return "", nil
}

func (e *Bnb) EstimateGas(chainCode int64, from, to, data string) (string, error) {
req := `
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"from":"%v",
"to": "%v",
"data": "%v"
}
]
}`
req = fmt.Sprintf(req, from, to, data)
res, err := e.SendJsonRpc(chainCode, req)
if err != nil {
return "", err
}
return res, nil
}

func (e *Bnb) GasPrice(chainCode int64) (string, error) {
req := `
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_gasPrice"
}
`

//req = fmt.Sprintf(req, from, to, functionSelector, parameter)
res, err := e.SendJsonRpc(chainCode, req)
if err != nil {
return "", err
}
return res, nil
}

func (e *Bnb) SendRawTransaction(chainCode int64, signedTx string) (string, error) {
req := `{
"id": 1,
Expand Down
6 changes: 3 additions & 3 deletions blockchain/service/bnb/bnb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

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

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

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

if err != nil {
t.Error(err)
Expand Down
61 changes: 61 additions & 0 deletions blockchain/service/ether/ether.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ func NewEth(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) bl
return e
}

func NewEth2(cluster []*config.NodeCluster, blockchain int64, xlog *xlog.XLog) blockchain.ExApi {
blockChainClient := chain.NewChain(blockchain, xlog)
if blockChainClient == nil {
return nil
}
e := &Ether{
log: xlog,
nodeCluster: cluster,
blockChainClient: blockChainClient,
}
e.StartWDT()
return e
}

func (e *Ether) StartWDT() {
go func() {
t := time.NewTicker(10 * time.Minute)
Expand Down Expand Up @@ -431,6 +445,53 @@ func (e *Ether) SendRawTransaction(chainCode int64, signedTx string) (string, er
return e.SendReq(chainCode, req)
}

func (e *Ether) GetAccountResourceForTron(chainCode int64, address string) (string, error) {
return "", nil
}

func (e *Ether) EstimateGasForTron(chainCode int64, from, to, functionSelector, parameter string) (string, error) {
return "", nil
}

func (e *Ether) EstimateGas(chainCode int64, from, to, data string) (string, error) {
req := `
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"from":"%v",
"to": "%v",
"data": "%v"
}
]
}`
req = fmt.Sprintf(req, from, to, data)
res, err := e.SendJsonRpc(chainCode, req)
if err != nil {
return "", err
}
return res, nil
}

func (e *Ether) GasPrice(chainCode int64) (string, error) {
req := `
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_gasPrice"
}
`

//req = fmt.Sprintf(req, from, to, functionSelector, parameter)
res, err := e.SendJsonRpc(chainCode, req)
if err != nil {
return "", err
}
return res, nil
}

func (e *Ether) SendReqByWs(blockChain int64, receiverCh chan string, sendCh chan string) (string, error) {
cluster := e.BalanceCluster()
if cluster == nil {
Expand Down
23 changes: 23 additions & 0 deletions blockchain/service/gw.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,26 @@ func NewNftApis(clusters map[int64][]*config.NodeCluster, xlog *xlog.XLog) map[i
}
return blockChainClients
}

func NewExApi(clusters map[int64][]*config.NodeCluster, xlog *xlog.XLog) map[int64]blockchain.ExApi {
blockChainClients := make(map[int64]blockchain.ExApi, 0)
for chainCode, cluster := range clusters {
if chain.GetChainCode(chainCode, "TRON", xlog) {
blockChainClients[chainCode] = tron.NewTron2(cluster, chainCode, xlog)
}

if chain.GetChainCode(chainCode, "ETH", xlog) {
blockChainClients[chainCode] = ether.NewEth2(cluster, chainCode, xlog)
}

if chain.GetChainCode(chainCode, "POLYGON", xlog) {
blockChainClients[chainCode] = polygon.NewPolygonPos2(cluster, chainCode, xlog)
}

if chain.GetChainCode(chainCode, "BSC", xlog) {
blockChainClients[chainCode] = bnb.NewBnb2(cluster, chainCode, xlog)
}

}
return blockChainClients
}
Loading

0 comments on commit 226baf6

Please sign in to comment.