diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index d912c13dd..548271f89 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -48,6 +48,7 @@ use v1::types::{ RichBlock, Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, Index, Filter, Log, Receipt, Work, H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256, block_number_to_id, + U64 as RpcU64, }; use v1::metadata::Metadata; @@ -513,6 +514,10 @@ impl Eth for EthClient< Ok(self.miner.is_currently_sealing()) } + fn chain_id(&self) -> Result> { + Ok(self.client.signing_chain_id().map(RpcU64::from)) + } + fn hashrate(&self) -> Result { Ok(RpcU256::from(self.external_miner.hashrate())) } diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index 34b89ac9f..2a2563016 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -49,6 +49,7 @@ use v1::types::{ RichBlock, Block, BlockTransactions, BlockNumber, LightBlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, Index, Filter, Log, Receipt, Work, H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256, + U64 as RpcU64, }; use v1::metadata::Metadata; @@ -246,6 +247,10 @@ impl Eth for EthClient { Ok(false) } + fn chain_id(&self) -> Result> { + Ok(self.client.signing_chain_id().map(RpcU64::from)) + } + fn hashrate(&self) -> Result { Ok(Default::default()) } diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 3f51826fc..18577926c 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -38,7 +38,7 @@ use v1::helpers::light_fetch::LightFetch; use v1::metadata::Metadata; use v1::traits::Parity; use v1::types::{ - Bytes, U256, U64, H64, H160, H256, H512, CallRequest, + Bytes, U256, H64, H160, H256, H512, CallRequest, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, BlockNumber, LightBlockNumber, ConsensusCapability, VersionInfo, @@ -328,10 +328,6 @@ impl Parity for ParityClient { Err(errors::light_unimplemented(None)) } - fn chain_id(&self) -> Result> { - Ok(self.client.signing_chain_id().map(U64::from)) - } - fn chain(&self) -> Result { Ok(self.settings.chain.clone()) } diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 3dce93ecd..a003b3c11 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -40,7 +40,7 @@ use v1::helpers::{self, errors, fake_sign, ipfs, SigningQueue, SignerService, Ne use v1::metadata::Metadata; use v1::traits::Parity; use v1::types::{ - Bytes, U256, U64, H64, H160, H256, H512, CallRequest, + Bytes, U256, H64, H160, H256, H512, CallRequest, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, @@ -173,10 +173,6 @@ impl Parity for ParityClient where Ok(self.settings.chain.clone()) } - fn chain_id(&self) -> Result> { - Ok(self.client.signing_chain_id().map(U64::from)) - } - fn chain(&self) -> Result { Ok(self.client.spec_name()) } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index ff364cf7f..040bf4be6 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -178,6 +178,15 @@ fn rpc_eth_syncing() { assert_eq!(tester.io.handle_request_sync(request), Some(false_res.to_owned())); } +#[test] +fn rpc_eth_chain_id() { + let tester = EthTester::default(); + let request = r#"{"jsonrpc": "2.0", "method": "eth_chainId", "params": [], "id": 1}"#; + let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#; + + assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); +} + #[test] fn rpc_eth_hashrate() { let tester = EthTester::default(); diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 8ac8e44eb..0b59e5beb 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -193,17 +193,6 @@ fn rpc_parity_extra_data() { assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); } -#[test] -fn rpc_parity_chain_id() { - let deps = Dependencies::new(); - let io = deps.default_client(); - - let request = r#"{"jsonrpc": "2.0", "method": "parity_chainId", "params": [], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#; - - assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); -} - #[test] fn rpc_parity_default_extra_data() { use version::version_data; diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index a11b86806..0c0041bb7 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -20,7 +20,7 @@ use jsonrpc_macros::Trailing; use v1::types::{RichBlock, BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index}; use v1::types::{Log, Receipt, SyncStatus, Transaction, Work}; -use v1::types::{H64, H160, H256, U256}; +use v1::types::{H64, H160, H256, U256, U64}; build_rpc_trait! { /// Eth rpc interface. @@ -47,6 +47,12 @@ build_rpc_trait! { #[rpc(name = "eth_mining")] fn is_mining(&self) -> Result; + /// Returns the chain ID used for transaction signing at the + /// current best block. None is returned if not + /// available. + #[rpc(name = "eth_chainId")] + fn chain_id(&self) -> Result>; + /// Returns current gas_price. #[rpc(name = "eth_gasPrice")] fn gas_price(&self) -> Result; diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index 0dc0f15dc..a14369581 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -22,7 +22,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_macros::Trailing; use v1::types::{ - H64, H160, H256, H512, U256, U64, Bytes, CallRequest, + H64, H160, H256, H512, U256, Bytes, CallRequest, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, @@ -172,12 +172,6 @@ build_rpc_trait! { #[rpc(name = "parity_mode")] fn mode(&self) -> Result; - /// Returns the chain ID used for transaction signing at the - /// current best block. None is returned if not - /// available. - #[rpc(name = "parity_chainId")] - fn chain_id(&self) -> Result>; - /// Get the chain name. Returns one of the pre-configured chain names or a filename. #[rpc(name = "parity_chain")] fn chain(&self) -> Result;