Skip to content

Commit

Permalink
feat: add support for some json rpc queries (#341)
Browse files Browse the repository at this point in the history
* feat: add support for some json rpc queries

* fix comment
  • Loading branch information
yutianwu authored Nov 1, 2023
1 parent 771bd5d commit a3c24a5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
18 changes: 12 additions & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ const (

// Supported EVM json-rpc requests
const (
EthBlockNumber = "eth_blockNumber"
EthGetBlockByNumber = "eth_getBlockByNumber"
EthGetBalance = "eth_getBalance"
EthChainID = "eth_chainId"
NetVersion = "net_version"
EthNetworkID = "eth_networkId"
EthBlockNumber = "eth_blockNumber"
EthGetBlockByNumber = "eth_getBlockByNumber"
EthGetBalance = "eth_getBalance"
EthChainID = "eth_chainId"
NetVersion = "net_version"
EthNetworkID = "eth_networkId"
EthGasPrice = "eth_gasPrice"
EthGetCode = "eth_getCode"
EthEstimateGas = "eth_estimateGas"
EthCall = "eth_call"
EthGetTransactionCount = "eth_getTransactionCount"
EthSendRawTransaction = "eth_sendRawTransaction"
)

// InitChain implements the ABCI interface. It runs the initialization logic
Expand Down
24 changes: 24 additions & 0 deletions baseapp/ethrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func (e *EthQueryRouter) RegisterConstHandler() {
e.AddRoute(EthNetworkID, chainIdHandler)
e.AddRoute(EthChainID, chainIdHandler)
e.AddRoute(NetVersion, chainIdHandler)
e.AddRoute(EthGasPrice, gasPriceHandler)
e.AddRoute(EthGetCode, chainIdHandler) // return dummy result
e.AddRoute(EthEstimateGas, estimateGasHandler) // return dummy result
e.AddRoute(EthCall, chainIdHandler) // return dummy result
e.AddRoute(EthGetTransactionCount, getTransactionCountHandler) // return dummy result
e.AddRoute(EthSendRawTransaction, chainIdHandler) // return dummy result
}

func blockNumberHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
Expand All @@ -72,6 +78,24 @@ func blockNumberHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.Respo
return res, nil
}

func gasPriceHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
res.Response = big.NewInt(5e9).Bytes()
return res, nil
}

func estimateGasHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
res.Response = big.NewInt(21000).Bytes()
return res, nil
}

func getTransactionCountHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
res.Response = big.NewInt(1).Bytes()
return res, nil
}

func chainIdHandler(ctx sdk.Context, req cmtrpctypes.RPCRequest) (abci.ResponseEthQuery, error) {
var res abci.ResponseEthQuery
eip155ChainID, err := sdk.ParseChainID(ctx.ChainID())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.0

github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.3
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsy
github.com/bkielbasa/cyclop v1.2.0/go.mod h1:qOI0yy6A7dYC4Zgsa72Ppm9kONl0RoIlPbzot9mhmeI=
github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield-cometbft v0.0.3 h1:tv8NMy3bzX/1urqXGQIIAZSLy83loiI+dG0VKeyh1CY=
github.com/bnb-chain/greenfield-cometbft v0.0.3/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62 h1:pakuREXV/XfWNwgsTXUQwYirem12Tt+2LGGHIar0z8o=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62/go.mod h1:43yICrTxu90VjEUpQN23bsqi9mua5m5sFQq/ekHwN9s=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-iavl v0.20.1 h1:y3L64GU99otNp27/xLVBTDbv4eroR6CzoYz0rbaVotM=
Expand Down

0 comments on commit a3c24a5

Please sign in to comment.