From 51dd117a3423504c12c16e23834d97a45f1b5359 Mon Sep 17 00:00:00 2001 From: ia Date: Fri, 18 Aug 2017 07:45:43 -0500 Subject: [PATCH 1/3] eth,internal: add eth_chainId method to PublicEthereumApi JSONRPC --- eth/api.go | 5 +++++ internal/web3ext/web3ext.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/eth/api.go b/eth/api.go index 708f75a784ad..7bb6847b49ae 100644 --- a/eth/api.go +++ b/eth/api.go @@ -67,6 +67,11 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 { return hexutil.Uint64(api.e.Miner().HashRate()) } +// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config. +func (api *PublicEthereumAPI) ChainId() *big.Int { + return api.e.chainConfig.ChainId +} + // 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 { diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index f4eb47a12ac7..bf4b7808f7ff 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -433,6 +433,11 @@ const Eth_JS = ` web3._extend({ property: 'eth', methods: [ + new web3._extend.Method({ + name: 'chainId', + call: 'eth_chainId', + params: 0 + }), new web3._extend.Method({ name: 'sign', call: 'eth_sign', From df4f7c867e3035e2154b4408e5decd8af104e050 Mon Sep 17 00:00:00 2001 From: ia Date: Wed, 6 Sep 2017 11:08:06 -0500 Subject: [PATCH 2/3] eth: improve getting chainID with existence check and hexutil --- eth/api.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eth/api.go b/eth/api.go index 7bb6847b49ae..a433f8d26082 100644 --- a/eth/api.go +++ b/eth/api.go @@ -68,8 +68,12 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 { } // ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config. -func (api *PublicEthereumAPI) ChainId() *big.Int { - return api.e.chainConfig.ChainId +func (api *PublicEthereumAPI) ChainId() hexutil.Uint { + chainID := new(big.Int) + if config := api.e.chainConfig; config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) { + chainID = config.ChainId + } + return hexutil.Uint(chainID) } // PublicMinerAPI provides an API to control the miner. From a68236fb172db9ee4e9d79b832e74b8fc154a33e Mon Sep 17 00:00:00 2001 From: hackyminer Date: Sun, 9 Sep 2018 21:11:09 +0900 Subject: [PATCH 3/3] eth: small fix to make it work --- eth/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eth/api.go b/eth/api.go index a433f8d26082..3ec3afb81e14 100644 --- a/eth/api.go +++ b/eth/api.go @@ -68,12 +68,12 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 { } // ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config. -func (api *PublicEthereumAPI) ChainId() hexutil.Uint { +func (api *PublicEthereumAPI) ChainId() hexutil.Uint64 { chainID := new(big.Int) if config := api.e.chainConfig; config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) { - chainID = config.ChainId + chainID = config.ChainID } - return hexutil.Uint(chainID) + return (hexutil.Uint64)(chainID.Uint64()) } // PublicMinerAPI provides an API to control the miner.