internal/ethapi: fix eth_chainId method (#22243)

This removes the duplicated definition of eth_chainID
in package eth and updates the definition in internal/ethapi
to treat chain ID as a bigint.

Co-authored-by: Felix Lange <fjl@twurst.com>
revert-23120-drop-eth-65
piersy 4 years ago committed by GitHub
parent c79fc209cd
commit 706683ea72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      eth/api.go
  2. 10
      internal/ethapi/api.go

@ -61,15 +61,6 @@ func (api *PublicEthereumAPI) Coinbase() (common.Address, error) {
return api.Etherbase()
}
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
func (api *PublicEthereumAPI) ChainId() (hexutil.Uint64, error) {
// if current block is at or past the EIP-155 replay-protection fork block, return chainID from config
if config := api.e.blockchain.Config(); config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
return (hexutil.Uint64)(config.ChainID.Uint64()), nil
}
return hexutil.Uint64(0), fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block")
}
// PublicMinerAPI provides an API to control the miner.
// It offers only methods that operate on data that pose no security risk when it is publicly accessible.
type PublicMinerAPI struct {

@ -529,9 +529,13 @@ 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)
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
func (api *PublicBlockChainAPI) ChainId() (*hexutil.Big, error) {
// if current block is at or past the EIP-155 replay-protection fork block, return chainID from config
if config := api.b.ChainConfig(); config.IsEIP155(api.b.CurrentBlock().Number()) {
return (*hexutil.Big)(config.ChainID), nil
}
return nil, fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block")
}
// BlockNumber returns the block number of the chain head.

Loading…
Cancel
Save