rpc: implement eth_chainId (#379)

* add eth_chainId

* add nolint

* use clientCtx chainID

* rpc: eth_chainId test

Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
This commit is contained in:
noot
2020-07-08 03:57:19 -04:00
committed by GitHub
co-authored by Federico Kunze
parent c4cf33a9bb
commit 1d8c997585
2 changed files with 21 additions and 0 deletions
+12
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"math/big"
"strconv"
"strings"
"sync"
@@ -67,6 +68,17 @@ func (e *PublicEthAPI) ProtocolVersion() hexutil.Uint {
return hexutil.Uint(version.ProtocolVersion)
}
// ChainId returns the chain's identifier in hex format
func (e *PublicEthAPI) ChainId() (hexutil.Uint, error) { // nolint
// parse the chainID from a integer string
intChainID, err := strconv.ParseUint(e.cliCtx.ChainID, 0, 64)
if err != nil {
return 0, fmt.Errorf("invalid chainID: %s, must be integer format", e.cliCtx.ChainID)
}
return hexutil.Uint(intChainID), nil
}
// Syncing returns whether or not the current node is syncing with other peers. Returns false if not, or a struct
// outlining the state of the sync if it is.
func (e *PublicEthAPI) Syncing() (interface{}, error) {