ethclient, internal/ethapi: add support for EIP-695 (eth_chainId) (#19694)

EIP-695 was written in 2017. Parity and Infura have support for this
method and we should, too.
This commit is contained in:
Felix Lange
2019-06-11 13:12:33 +02:00
committed by Péter Szilágyi
parent c420dcb39c
commit 2b54666018
3 changed files with 31 additions and 0 deletions

View File

@ -529,6 +529,11 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI {
return &PublicBlockChainAPI{b}
}
// ChainId returns the chainID value for transaction replay protection.
func (s *PublicBlockChainAPI) ChainId() *hexutil.Big {
return (*hexutil.Big)(s.b.ChainConfig().ChainID)
}
// BlockNumber returns the block number of the chain head.
func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 {
header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available