44 "bytes"
55 "errors"
66 "fmt"
7- "log"
87 "math/big"
8+ "os"
99 "strconv"
1010 "sync"
1111
@@ -20,6 +20,7 @@ import (
2020
2121 abci "github.com/tendermint/tendermint/abci/types"
2222 "github.com/tendermint/tendermint/crypto/merkle"
23+ "github.com/tendermint/tendermint/libs/log"
2324 "github.com/tendermint/tendermint/rpc/client"
2425 tmtypes "github.com/tendermint/tendermint/types"
2526
@@ -42,6 +43,7 @@ import (
4243// PublicEthAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
4344type PublicEthAPI struct {
4445 cliCtx context.CLIContext
46+ logger log.Logger
4547 backend Backend
4648 keys []crypto.PrivKeySecp256k1
4749 nonceLock * AddrLocker
@@ -54,6 +56,7 @@ func NewPublicEthAPI(cliCtx context.CLIContext, backend Backend, nonceLock *Addr
5456
5557 return & PublicEthAPI {
5658 cliCtx : cliCtx ,
59+ logger : log .NewTMLogger (log .NewSyncWriter (os .Stdout )).With ("module" , "json-rpc" ),
5760 backend : backend ,
5861 keys : key ,
5962 nonceLock : nonceLock ,
@@ -62,11 +65,14 @@ func NewPublicEthAPI(cliCtx context.CLIContext, backend Backend, nonceLock *Addr
6265
6366// ProtocolVersion returns the supported Ethereum protocol version.
6467func (e * PublicEthAPI ) ProtocolVersion () hexutil.Uint {
68+ e .logger .Debug ("eth_protocolVersion" )
6569 return hexutil .Uint (version .ProtocolVersion )
6670}
6771
6872// ChainId returns the chain's identifier in hex format
6973func (e * PublicEthAPI ) ChainId () (hexutil.Uint , error ) { // nolint
74+ e .logger .Debug ("eth_chainId" )
75+
7076 // parse the chainID from a integer string
7177 intChainID , err := strconv .ParseUint (e .cliCtx .ChainID , 0 , 64 )
7278 if err != nil {
@@ -79,6 +85,8 @@ func (e *PublicEthAPI) ChainId() (hexutil.Uint, error) { // nolint
7985// Syncing returns whether or not the current node is syncing with other peers. Returns false if not, or a struct
8086// outlining the state of the sync if it is.
8187func (e * PublicEthAPI ) Syncing () (interface {}, error ) {
88+ e .logger .Debug ("eth_syncing" )
89+
8290 status , err := e .cliCtx .Client .Status ()
8391 if err != nil {
8492 return false , err
@@ -99,6 +107,8 @@ func (e *PublicEthAPI) Syncing() (interface{}, error) {
99107
100108// Coinbase is the address that staking rewards will be send to (alias for Etherbase).
101109func (e * PublicEthAPI ) Coinbase () (common.Address , error ) {
110+ e .logger .Debug ("eth_coinbase" )
111+
102112 node , err := e .cliCtx .GetNode ()
103113 if err != nil {
104114 return common.Address {}, err
@@ -114,22 +124,26 @@ func (e *PublicEthAPI) Coinbase() (common.Address, error) {
114124
115125// Mining returns whether or not this node is currently mining. Always false.
116126func (e * PublicEthAPI ) Mining () bool {
127+ e .logger .Debug ("eth_mining" )
117128 return false
118129}
119130
120131// Hashrate returns the current node's hashrate. Always 0.
121132func (e * PublicEthAPI ) Hashrate () hexutil.Uint64 {
133+ e .logger .Debug ("eth_hashrate" )
122134 return 0
123135}
124136
125137// GasPrice returns the current gas price based on Ethermint's gas price oracle.
126138func (e * PublicEthAPI ) GasPrice () * hexutil.Big {
139+ e .logger .Debug ("eth_gasPrice" )
127140 out := big .NewInt (0 )
128141 return (* hexutil .Big )(out )
129142}
130143
131144// Accounts returns the list of accounts available to this node.
132145func (e * PublicEthAPI ) Accounts () ([]common.Address , error ) {
146+ e .logger .Debug ("eth_accounts" )
133147 e .keybaseLock .Lock ()
134148
135149 addresses := make ([]common.Address , 0 ) // return [] instead of nil if empty
@@ -162,11 +176,13 @@ func (e *PublicEthAPI) Accounts() ([]common.Address, error) {
162176
163177// BlockNumber returns the current block number.
164178func (e * PublicEthAPI ) BlockNumber () (hexutil.Uint64 , error ) {
179+ e .logger .Debug ("eth_blockNumber" )
165180 return e .backend .BlockNumber ()
166181}
167182
168183// GetBalance returns the provided account's balance up to the provided block number.
169184func (e * PublicEthAPI ) GetBalance (address common.Address , blockNum BlockNumber ) (* hexutil.Big , error ) {
185+ e .logger .Debug ("eth_getBalance" , "address" , address , "block number" , blockNum )
170186 ctx := e .cliCtx .WithHeight (blockNum .Int64 ())
171187 res , _ , err := ctx .QueryWithData (fmt .Sprintf ("custom/%s/balance/%s" , evmtypes .ModuleName , address .Hex ()), nil )
172188 if err != nil {
@@ -185,6 +201,7 @@ func (e *PublicEthAPI) GetBalance(address common.Address, blockNum BlockNumber)
185201
186202// GetStorageAt returns the contract storage at the given address, block number, and key.
187203func (e * PublicEthAPI ) GetStorageAt (address common.Address , key string , blockNum BlockNumber ) (hexutil.Bytes , error ) {
204+ e .logger .Debug ("eth_getStorageAt" , "address" , address , "key" , key , "block number" , blockNum )
188205 ctx := e .cliCtx .WithHeight (blockNum .Int64 ())
189206 res , _ , err := ctx .QueryWithData (fmt .Sprintf ("custom/%s/storage/%s/%s" , evmtypes .ModuleName , address .Hex (), key ), nil )
190207 if err != nil {
@@ -198,6 +215,7 @@ func (e *PublicEthAPI) GetStorageAt(address common.Address, key string, blockNum
198215
199216// GetTransactionCount returns the number of transactions at the given address up to the given block number.
200217func (e * PublicEthAPI ) GetTransactionCount (address common.Address , blockNum BlockNumber ) (* hexutil.Uint64 , error ) {
218+ e .logger .Debug ("eth_getTransactionCount" , "address" , address , "block number" , blockNum )
201219 ctx := e .cliCtx .WithHeight (blockNum .Int64 ())
202220
203221 // Get nonce (sequence) from account
@@ -222,6 +240,7 @@ func (e *PublicEthAPI) GetTransactionCount(address common.Address, blockNum Bloc
222240
223241// GetBlockTransactionCountByHash returns the number of transactions in the block identified by hash.
224242func (e * PublicEthAPI ) GetBlockTransactionCountByHash (hash common.Hash ) * hexutil.Uint {
243+ e .logger .Debug ("eth_getBlockTransactionCountByHash" , "hash" , hash )
225244 res , _ , err := e .cliCtx .Query (fmt .Sprintf ("custom/%s/%s/%s" , evmtypes .ModuleName , evmtypes .QueryHashToHeight , hash .Hex ()))
226245 if err != nil {
227246 // Return nil if block does not exist
@@ -235,6 +254,7 @@ func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil
235254
236255// GetBlockTransactionCountByNumber returns the number of transactions in the block identified by number.
237256func (e * PublicEthAPI ) GetBlockTransactionCountByNumber (blockNum BlockNumber ) * hexutil.Uint {
257+ e .logger .Debug ("eth_getBlockTransactionCountByNumber" , "block number" , blockNum )
238258 height := blockNum .Int64 ()
239259 return e .getBlockTransactionCountByNumber (height )
240260}
@@ -262,6 +282,7 @@ func (e *PublicEthAPI) GetUncleCountByBlockNumber(blockNum BlockNumber) hexutil.
262282
263283// GetCode returns the contract code at the given address and block number.
264284func (e * PublicEthAPI ) GetCode (address common.Address , blockNumber BlockNumber ) (hexutil.Bytes , error ) {
285+ e .logger .Debug ("eth_getCode" , "address" , address , "block number" , blockNumber )
265286 ctx := e .cliCtx .WithHeight (blockNumber .Int64 ())
266287 res , _ , err := ctx .QueryWithData (fmt .Sprintf ("custom/%s/%s/%s" , evmtypes .ModuleName , evmtypes .QueryCode , address .Hex ()), nil )
267288 if err != nil {
@@ -275,12 +296,14 @@ func (e *PublicEthAPI) GetCode(address common.Address, blockNumber BlockNumber)
275296
276297// GetTransactionLogs returns the logs given a transaction hash.
277298func (e * PublicEthAPI ) GetTransactionLogs (txHash common.Hash ) ([]* ethtypes.Log , error ) {
299+ e .logger .Debug ("eth_getTransactionLogs" , "hash" , txHash )
278300 return e .backend .GetTransactionLogs (txHash )
279301}
280302
281303// ExportAccount exports an account's balance, code, and storage at the given block number
282304// TODO: deprecate this once the export genesis command works
283305func (e * PublicEthAPI ) ExportAccount (address common.Address , blockNumber BlockNumber ) (string , error ) {
306+ e .logger .Debug ("eth_exportAccount" , "address" , address , "block number" , blockNumber )
284307 ctx := e .cliCtx .WithHeight (blockNumber .Int64 ())
285308
286309 res , _ , err := ctx .QueryWithData (fmt .Sprintf ("custom/%s/%s/%s" , evmtypes .ModuleName , evmtypes .QueryExportAccount , address .Hex ()), nil )
@@ -304,6 +327,7 @@ func checkKeyInKeyring(keys []crypto.PrivKeySecp256k1, address common.Address) (
304327
305328// Sign signs the provided data using the private key of address via Geth's signature standard.
306329func (e * PublicEthAPI ) Sign (address common.Address , data hexutil.Bytes ) (hexutil.Bytes , error ) {
330+ e .logger .Debug ("eth_sign" , "address" , address , "data" , data )
307331 // TODO: Change this functionality to find an unlocked account by address
308332
309333 key , exist := checkKeyInKeyring (e .keys , address )
@@ -322,6 +346,7 @@ func (e *PublicEthAPI) Sign(address common.Address, data hexutil.Bytes) (hexutil
322346
323347// SendTransaction sends an Ethereum transaction.
324348func (e * PublicEthAPI ) SendTransaction (args params.SendTxArgs ) (common.Hash , error ) {
349+ e .logger .Debug ("eth_sendTransaction" , "args" , args )
325350 // TODO: Change this functionality to find an unlocked account by address
326351
327352 key , exist := checkKeyInKeyring (e .keys , args .From )
@@ -374,6 +399,7 @@ func (e *PublicEthAPI) SendTransaction(args params.SendTxArgs) (common.Hash, err
374399
375400// SendRawTransaction send a raw Ethereum transaction.
376401func (e * PublicEthAPI ) SendRawTransaction (data hexutil.Bytes ) (common.Hash , error ) {
402+ e .logger .Debug ("eth_sendRawTransaction" , "data" , data )
377403 tx := new (evmtypes.MsgEthereumTx )
378404
379405 // RLP decode raw transaction bytes
@@ -411,7 +437,8 @@ type CallArgs struct {
411437}
412438
413439// Call performs a raw contract call.
414- func (e * PublicEthAPI ) Call (args CallArgs , blockNr BlockNumber , overrides * map [common.Address ]account ) (hexutil.Bytes , error ) {
440+ func (e * PublicEthAPI ) Call (args CallArgs , blockNr BlockNumber , _ * map [common.Address ]account ) (hexutil.Bytes , error ) {
441+ e .logger .Debug ("eth_call" , "args" , args , "block number" , blockNr )
415442 simRes , err := e .doCall (args , blockNr , big .NewInt (emint .DefaultRPCGasLimit ))
416443 if err != nil {
417444 return []byte {}, err
@@ -471,7 +498,7 @@ func (e *PublicEthAPI) doCall(
471498 gas = uint64 (* args .Gas )
472499 }
473500 if globalGasCap != nil && globalGasCap .Uint64 () < gas {
474- log . Println ("Caller gas above allowance, capping" , "requested" , gas , "cap" , globalGasCap )
501+ e . logger . Debug ("Caller gas above allowance, capping" , "requested" , gas , "cap" , globalGasCap )
475502 gas = globalGasCap .Uint64 ()
476503 }
477504
@@ -531,6 +558,7 @@ func (e *PublicEthAPI) doCall(
531558// It adds 1,000 gas to the returned value instead of using the gas adjustment
532559// param from the SDK.
533560func (e * PublicEthAPI ) EstimateGas (args CallArgs ) (hexutil.Uint64 , error ) {
561+ e .logger .Debug ("eth_estimateGas" , "args" , args )
534562 simResponse , err := e .doCall (args , 0 , big .NewInt (emint .DefaultRPCGasLimit ))
535563 if err != nil {
536564 return 0 , err
@@ -545,11 +573,13 @@ func (e *PublicEthAPI) EstimateGas(args CallArgs) (hexutil.Uint64, error) {
545573
546574// GetBlockByHash returns the block identified by hash.
547575func (e * PublicEthAPI ) GetBlockByHash (hash common.Hash , fullTx bool ) (map [string ]interface {}, error ) {
576+ e .logger .Debug ("eth_getBlockByHash" , "hash" , hash , "full" , fullTx )
548577 return e .backend .GetBlockByHash (hash , fullTx )
549578}
550579
551580// GetBlockByNumber returns the block identified by number.
552581func (e * PublicEthAPI ) GetBlockByNumber (blockNum BlockNumber , fullTx bool ) (map [string ]interface {}, error ) {
582+ e .logger .Debug ("eth_getBlockByNumber" , "number" , blockNum , "full" , fullTx )
553583 return e .backend .GetBlockByNumber (blockNum , fullTx )
554584}
555585
@@ -668,6 +698,7 @@ func newRPCTransaction(tx evmtypes.MsgEthereumTx, txHash, blockHash common.Hash,
668698
669699// GetTransactionByHash returns the transaction identified by hash.
670700func (e * PublicEthAPI ) GetTransactionByHash (hash common.Hash ) (* Transaction , error ) {
701+ e .logger .Debug ("eth_getTransactionByHash" , "hash" , hash )
671702 tx , err := e .cliCtx .Client .Tx (hash .Bytes (), false )
672703 if err != nil {
673704 // Return nil for transaction when not found
@@ -692,6 +723,7 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*Transaction, err
692723
693724// GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index.
694725func (e * PublicEthAPI ) GetTransactionByBlockHashAndIndex (hash common.Hash , idx hexutil.Uint ) (* Transaction , error ) {
726+ e .logger .Debug ("eth_getTransactionByHashAndIndex" , "hash" , hash , "index" , idx )
695727 res , _ , err := e .cliCtx .Query (fmt .Sprintf ("custom/%s/%s/%s" , evmtypes .ModuleName , evmtypes .QueryHashToHeight , hash .Hex ()))
696728 if err != nil {
697729 return nil , err
@@ -704,6 +736,7 @@ func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx h
704736
705737// GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index.
706738func (e * PublicEthAPI ) GetTransactionByBlockNumberAndIndex (blockNum BlockNumber , idx hexutil.Uint ) (* Transaction , error ) {
739+ e .logger .Debug ("eth_getTransactionByBlockNumberAndIndex" , "number" , blockNum , "index" , idx )
707740 value := blockNum .Int64 ()
708741 return e .getTransactionByBlockNumberAndIndex (value , idx )
709742}
@@ -730,6 +763,7 @@ func (e *PublicEthAPI) getTransactionByBlockNumberAndIndex(number int64, idx hex
730763
731764// GetTransactionReceipt returns the transaction receipt identified by hash.
732765func (e * PublicEthAPI ) GetTransactionReceipt (hash common.Hash ) (map [string ]interface {}, error ) {
766+ e .logger .Debug ("eth_getTransactionReceipt" , "hash" , hash )
733767 tx , err := e .cliCtx .Client .Tx (hash .Bytes (), false )
734768 if err != nil {
735769 // Return nil for transaction when not found
@@ -803,6 +837,7 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter
803837// PendingTransactions returns the transactions that are in the transaction pool
804838// and have a from address that is one of the accounts this node manages.
805839func (e * PublicEthAPI ) PendingTransactions () ([]* Transaction , error ) {
840+ e .logger .Debug ("eth_getPendingTransactions" )
806841 return e .backend .PendingTransactions ()
807842}
808843
@@ -839,6 +874,7 @@ type StorageResult struct {
839874
840875// GetProof returns an account object with proof and any storage proofs
841876func (e * PublicEthAPI ) GetProof (address common.Address , storageKeys []string , block BlockNumber ) (* AccountResult , error ) {
877+ e .logger .Debug ("eth_getProof" , "address" , address , "keys" , storageKeys , "number" , block )
842878 e .cliCtx = e .cliCtx .WithHeight (int64 (block ))
843879 path := fmt .Sprintf ("custom/%s/%s/%s" , evmtypes .ModuleName , evmtypes .QueryAccount , address .Hex ())
844880
0 commit comments