From 54d067ea53a0e22fb8414f9c01b4786e5bfbb1dd Mon Sep 17 00:00:00 2001 From: tgmichel Date: Thu, 28 May 2020 10:27:59 +0200 Subject: [PATCH 01/11] Implement gas_price runtime API --- rpc/core/src/eth.rs | 2 +- rpc/primitives/src/lib.rs | 3 ++- rpc/src/lib.rs | 14 ++++++++++++-- template/runtime/src/lib.rs | 4 ++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index afe485e829..f5afe5c3f6 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -57,7 +57,7 @@ pub trait EthApi { /// Returns current gas_price. #[rpc(name = "eth_gasPrice")] - fn gas_price(&self) -> BoxFuture; + fn gas_price(&self) -> Result>; /// Returns accounts list. #[rpc(name = "eth_accounts")] diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index ebf4af5abe..814412d217 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -16,7 +16,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use sp_core::{H160, H256}; +use sp_core::{H160, H256, U256}; use ethereum::Log; use ethereum_types::Bloom; use codec::{Encode, Decode}; @@ -39,6 +39,7 @@ sp_api::decl_runtime_apis! { fn chain_id() -> u64; fn account_basic(address: H160) -> pallet_evm::Account; fn transaction_status(hash: H256) -> Option; + fn gas_price() -> U256; } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 841cbb3e8b..a936e1cdfc 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -98,8 +98,18 @@ impl EthApiT for EthApi where .map_err(|_| internal_err("fetch runtime chain id failed"))?.into())) } - fn gas_price(&self) -> BoxFuture { - unimplemented!("gas_price"); + fn gas_price(&self) -> Result> { + let header = self + .select_chain + .best_chain() + .map_err(|_| internal_err("fetch header failed"))?; + Ok(Some( + self.client + .runtime_api() + .gas_price(&BlockId::Hash(header.hash())) + .map_err(|_| internal_err("fetch runtime chain id failed"))? + .into(), + )) } fn accounts(&self) -> Result> { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index b7eee8817a..0f20604997 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -448,6 +448,10 @@ impl_runtime_apis! { fn transaction_status(hash: H256) -> Option { ethereum::Module::::transaction_status(hash) } + + fn gas_price() -> U256 { + FixedGasPrice::min_gas_price() + } } impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< From 8b8db874df0d4b2aa141645e78e059b938e2911b Mon Sep 17 00:00:00 2001 From: tgmichel Date: Thu, 28 May 2020 10:43:02 +0200 Subject: [PATCH 02/11] Implement block_number runtime API --- rpc/core/src/eth.rs | 2 +- rpc/primitives/src/lib.rs | 1 + rpc/src/lib.rs | 14 ++++++++++++-- template/runtime/src/lib.rs | 6 ++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index f5afe5c3f6..10718ef728 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -65,7 +65,7 @@ pub trait EthApi { /// Returns highest block number. #[rpc(name = "eth_blockNumber")] - fn block_number(&self) -> Result; + fn block_number(&self) -> Result>; /// Returns balance of the given account. #[rpc(name = "eth_getBalance")] diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index 814412d217..0a8b08b101 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -40,6 +40,7 @@ sp_api::decl_runtime_apis! { fn account_basic(address: H160) -> pallet_evm::Account; fn transaction_status(hash: H256) -> Option; fn gas_price() -> U256; + fn block_number() -> U256; } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index a936e1cdfc..25d794ce68 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -116,8 +116,18 @@ impl EthApiT for EthApi where unimplemented!("accounts"); } - fn block_number(&self) -> Result { - unimplemented!("block_number"); + fn block_number(&self) -> Result> { + let header = self + .select_chain + .best_chain() + .map_err(|_| internal_err("fetch header failed"))?; + Ok(Some( + self.client + .runtime_api() + .block_number(&BlockId::Hash(header.hash())) + .map_err(|_| internal_err("fetch runtime chain id failed"))? + .into(), + )) } fn balance(&self, _: H160, _: Option) -> BoxFuture { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 0f20604997..d6123b2a72 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -33,6 +33,7 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, U256, H160, H256}; use sp_runtime::traits::{ BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, Saturating, Verify, + UniqueSaturatedInto }; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, @@ -452,6 +453,11 @@ impl_runtime_apis! { fn gas_price() -> U256 { FixedGasPrice::min_gas_price() } + + fn block_number() -> U256 { + let number: u128 = >::block_number().unique_saturated_into(); + U256::from(number) + } } impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< From a32a22169d35ad8b85b357517cb54639cf16f685 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Thu, 28 May 2020 11:08:54 +0200 Subject: [PATCH 03/11] Implement balances runtime API --- rpc/core/src/eth.rs | 2 +- rpc/primitives/src/lib.rs | 1 + rpc/src/lib.rs | 19 +++++++++++++++++-- template/runtime/src/lib.rs | 9 +++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index 10718ef728..0218e182b1 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -69,7 +69,7 @@ pub trait EthApi { /// Returns balance of the given account. #[rpc(name = "eth_getBalance")] - fn balance(&self, _: H160, _: Option) -> BoxFuture; + fn balance(&self, _: H160, _: Option) -> Result>; /// Returns the account- and storage-values of the specified account including the Merkle-proof #[rpc(name = "eth_getProof")] diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index 0a8b08b101..6cf030a248 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -41,6 +41,7 @@ sp_api::decl_runtime_apis! { fn transaction_status(hash: H256) -> Option; fn gas_price() -> U256; fn block_number() -> U256; + fn evm_balance(address: H160) -> U256; } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 25d794ce68..6278fb24b5 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -130,8 +130,23 @@ impl EthApiT for EthApi where )) } - fn balance(&self, _: H160, _: Option) -> BoxFuture { - unimplemented!("balance"); + fn balance(&self, address: H160, number: Option) -> Result> { + if let Some(number) = number { + if number != BlockNumber::Latest { + unimplemented!("fetch nonce for past blocks is not yet supported"); + } + } + let header = self + .select_chain + .best_chain() + .map_err(|_| internal_err("fetch header failed"))?; + Ok(Some( + self.client + .runtime_api() + .evm_balance(&BlockId::Hash(header.hash()), address) + .map_err(|_| internal_err("fetch runtime chain id failed"))? + .into(), + )) } fn proof(&self, _: H160, _: Vec, _: Option) -> BoxFuture { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index d6123b2a72..a687380904 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -458,6 +458,15 @@ impl_runtime_apis! { let number: u128 = >::block_number().unique_saturated_into(); U256::from(number) } + + fn evm_balance(address: H160) -> U256 { + if !evm::Module::::account_exists(&address) { + U256::zero() + } else { + let account: EVMAccount = evm::Module::::accounts(address); + account.balance + } + } } impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< From 971bf636703b434b4569bd05d6c1e1020c4d7f03 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Thu, 28 May 2020 12:54:08 +0200 Subject: [PATCH 04/11] Implement code_at runtime API --- rpc/core/src/eth.rs | 2 +- rpc/primitives/src/lib.rs | 1 + rpc/src/lib.rs | 19 +++++++++++++++++-- template/runtime/src/lib.rs | 8 ++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index 0218e182b1..a198463035 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -109,7 +109,7 @@ pub trait EthApi { /// Returns the code at given address at given time (block number). #[rpc(name = "eth_getCode")] - fn code_at(&self, _: H160, _: Option) -> BoxFuture; + fn code_at(&self, _: H160, _: Option) -> Result>; /// Sends signed transaction, returning its hash. #[rpc(name = "eth_sendRawTransaction")] diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index 6cf030a248..a47dcaa10d 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -42,6 +42,7 @@ sp_api::decl_runtime_apis! { fn gas_price() -> U256; fn block_number() -> U256; fn evm_balance(address: H160) -> U256; + fn code_at(address: H160) -> Vec; } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 6278fb24b5..0f51922cc6 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -194,8 +194,23 @@ impl EthApiT for EthApi where unimplemented!("block_uncles_count_by_number"); } - fn code_at(&self, _: H160, _: Option) -> BoxFuture { - unimplemented!("code_at"); + fn code_at(&self, address: H160, number: Option) -> Result> { + if let Some(number) = number { + if number != BlockNumber::Latest { + unimplemented!("fetch nonce for past blocks is not yet supported"); + } + } + let header = self + .select_chain + .best_chain() + .map_err(|_| internal_err("fetch header failed"))?; + Ok(Some( + self.client + .runtime_api() + .code_at(&BlockId::Hash(header.hash()), address) + .map_err(|_| internal_err("fetch runtime chain id failed"))? + .into(), + )) } fn send_raw_transaction(&self, bytes: Bytes) -> BoxFuture { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index a687380904..4e5b186d7a 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -467,6 +467,14 @@ impl_runtime_apis! { account.balance } } + + fn code_at(address: H160) -> Vec { + if !evm::Module::::account_exists(&address) { + vec![] + } else { + evm::Module::::account_codes(address) + } + } } impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi< From e8ad2c3842eeea5bfc4f4e1fe3e86603e359c30a Mon Sep 17 00:00:00 2001 From: tgmichel Date: Fri, 29 May 2020 17:48:36 +0200 Subject: [PATCH 05/11] Remove gas_price Option from Result --- rpc/core/src/eth.rs | 2 +- rpc/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index a198463035..c4e196d615 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -57,7 +57,7 @@ pub trait EthApi { /// Returns current gas_price. #[rpc(name = "eth_gasPrice")] - fn gas_price(&self) -> Result>; + fn gas_price(&self) -> Result; /// Returns accounts list. #[rpc(name = "eth_accounts")] diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 0f51922cc6..2350fdb8a4 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -98,18 +98,18 @@ impl EthApiT for EthApi where .map_err(|_| internal_err("fetch runtime chain id failed"))?.into())) } - fn gas_price(&self) -> Result> { + fn gas_price(&self) -> Result { let header = self .select_chain .best_chain() .map_err(|_| internal_err("fetch header failed"))?; - Ok(Some( + Ok( self.client .runtime_api() .gas_price(&BlockId::Hash(header.hash())) .map_err(|_| internal_err("fetch runtime chain id failed"))? .into(), - )) + ) } fn accounts(&self) -> Result> { From 8b30615bf7dc1782f987645dfdbb77239e71c18a Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 1 Jun 2020 09:30:17 +0200 Subject: [PATCH 06/11] Remove block_number Option from Result --- rpc/core/src/eth.rs | 2 +- rpc/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index c4e196d615..c8978b26d1 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -65,7 +65,7 @@ pub trait EthApi { /// Returns highest block number. #[rpc(name = "eth_blockNumber")] - fn block_number(&self) -> Result>; + fn block_number(&self) -> Result; /// Returns balance of the given account. #[rpc(name = "eth_getBalance")] diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 2350fdb8a4..73c4f4ac47 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -116,18 +116,18 @@ impl EthApiT for EthApi where unimplemented!("accounts"); } - fn block_number(&self) -> Result> { + fn block_number(&self) -> Result { let header = self .select_chain .best_chain() .map_err(|_| internal_err("fetch header failed"))?; - Ok(Some( + Ok( self.client .runtime_api() .block_number(&BlockId::Hash(header.hash())) .map_err(|_| internal_err("fetch runtime chain id failed"))? .into(), - )) + ) } fn balance(&self, address: H160, number: Option) -> Result> { From dfa59cd04106e63f0ca30f0b55e1ddd529775a85 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 1 Jun 2020 09:41:15 +0200 Subject: [PATCH 07/11] Remove balance Option from Result, evm handles Default --- rpc/core/src/eth.rs | 2 +- rpc/src/lib.rs | 6 +++--- template/runtime/src/lib.rs | 8 ++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index c8978b26d1..6441c3eb68 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -69,7 +69,7 @@ pub trait EthApi { /// Returns balance of the given account. #[rpc(name = "eth_getBalance")] - fn balance(&self, _: H160, _: Option) -> Result>; + fn balance(&self, _: H160, _: Option) -> Result; /// Returns the account- and storage-values of the specified account including the Merkle-proof #[rpc(name = "eth_getProof")] diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 73c4f4ac47..7136d736e3 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -130,7 +130,7 @@ impl EthApiT for EthApi where ) } - fn balance(&self, address: H160, number: Option) -> Result> { + fn balance(&self, address: H160, number: Option) -> Result { if let Some(number) = number { if number != BlockNumber::Latest { unimplemented!("fetch nonce for past blocks is not yet supported"); @@ -140,13 +140,13 @@ impl EthApiT for EthApi where .select_chain .best_chain() .map_err(|_| internal_err("fetch header failed"))?; - Ok(Some( + Ok( self.client .runtime_api() .evm_balance(&BlockId::Hash(header.hash()), address) .map_err(|_| internal_err("fetch runtime chain id failed"))? .into(), - )) + ) } fn proof(&self, _: H160, _: Vec, _: Option) -> BoxFuture { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 4e5b186d7a..d24504ef4e 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -460,12 +460,8 @@ impl_runtime_apis! { } fn evm_balance(address: H160) -> U256 { - if !evm::Module::::account_exists(&address) { - U256::zero() - } else { - let account: EVMAccount = evm::Module::::accounts(address); - account.balance - } + let account: EVMAccount = evm::Module::::accounts(address); + account.balance } fn code_at(address: H160) -> Vec { From e44a44c31a1ec065deee9e8d1676782cf86f4813 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 1 Jun 2020 09:46:33 +0200 Subject: [PATCH 08/11] Remove code_at Option from Result, evm handles Default --- rpc/core/src/eth.rs | 2 +- rpc/src/lib.rs | 6 +++--- template/runtime/src/lib.rs | 6 +----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/rpc/core/src/eth.rs b/rpc/core/src/eth.rs index 6441c3eb68..0aa2c1f0ec 100644 --- a/rpc/core/src/eth.rs +++ b/rpc/core/src/eth.rs @@ -109,7 +109,7 @@ pub trait EthApi { /// Returns the code at given address at given time (block number). #[rpc(name = "eth_getCode")] - fn code_at(&self, _: H160, _: Option) -> Result>; + fn code_at(&self, _: H160, _: Option) -> Result; /// Sends signed transaction, returning its hash. #[rpc(name = "eth_sendRawTransaction")] diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 7136d736e3..5c4221ce9c 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -194,7 +194,7 @@ impl EthApiT for EthApi where unimplemented!("block_uncles_count_by_number"); } - fn code_at(&self, address: H160, number: Option) -> Result> { + fn code_at(&self, address: H160, number: Option) -> Result { if let Some(number) = number { if number != BlockNumber::Latest { unimplemented!("fetch nonce for past blocks is not yet supported"); @@ -204,13 +204,13 @@ impl EthApiT for EthApi where .select_chain .best_chain() .map_err(|_| internal_err("fetch header failed"))?; - Ok(Some( + Ok( self.client .runtime_api() .code_at(&BlockId::Hash(header.hash()), address) .map_err(|_| internal_err("fetch runtime chain id failed"))? .into(), - )) + ) } fn send_raw_transaction(&self, bytes: Bytes) -> BoxFuture { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index d24504ef4e..c88e9039c0 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -465,11 +465,7 @@ impl_runtime_apis! { } fn code_at(address: H160) -> Vec { - if !evm::Module::::account_exists(&address) { - vec![] - } else { - evm::Module::::account_codes(address) - } + evm::Module::::account_codes(address) } } From aad3512d83f744adb0bd72531ce6350520aef911 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Mon, 1 Jun 2020 13:21:25 +0200 Subject: [PATCH 09/11] Remove block_number Runtime API implementation --- rpc/primitives/src/lib.rs | 1 - rpc/src/lib.rs | 10 ++-------- template/runtime/src/lib.rs | 5 ----- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index a47dcaa10d..1c9c0e429b 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -40,7 +40,6 @@ sp_api::decl_runtime_apis! { fn account_basic(address: H160) -> pallet_evm::Account; fn transaction_status(hash: H256) -> Option; fn gas_price() -> U256; - fn block_number() -> U256; fn evm_balance(address: H160) -> U256; fn code_at(address: H160) -> Vec; } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 5c4221ce9c..9189505bf4 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -18,7 +18,7 @@ use std::{marker::PhantomData, sync::Arc}; use ethereum_types::{H160, H256, H64, U256, U64}; use jsonrpc_core::{BoxFuture, Result, ErrorCode, Error, futures::future::{self, Future}}; use futures::future::TryFutureExt; -use sp_runtime::traits::{Block as BlockT, Header as _}; +use sp_runtime::traits::{Block as BlockT, Header as _, UniqueSaturatedInto}; use sp_runtime::transaction_validity::TransactionSource; use sp_api::{ProvideRuntimeApi, BlockId}; use sp_consensus::SelectChain; @@ -121,13 +121,7 @@ impl EthApiT for EthApi where .select_chain .best_chain() .map_err(|_| internal_err("fetch header failed"))?; - Ok( - self.client - .runtime_api() - .block_number(&BlockId::Hash(header.hash())) - .map_err(|_| internal_err("fetch runtime chain id failed"))? - .into(), - ) + Ok(U256::from(header.number().clone().unique_saturated_into())) } fn balance(&self, address: H160, number: Option) -> Result { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index c88e9039c0..d5889c7d7f 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -454,11 +454,6 @@ impl_runtime_apis! { FixedGasPrice::min_gas_price() } - fn block_number() -> U256 { - let number: u128 = >::block_number().unique_saturated_into(); - U256::from(number) - } - fn evm_balance(address: H160) -> U256 { let account: EVMAccount = evm::Module::::accounts(address); account.balance From 78dc8e9309cfc4168a467388e52e15341599b5d5 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Tue, 2 Jun 2020 09:33:46 +0200 Subject: [PATCH 10/11] Rename code_at > account_code_at --- rpc/primitives/src/lib.rs | 2 +- rpc/src/lib.rs | 2 +- template/runtime/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index 1c9c0e429b..ffdc5d3878 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -41,7 +41,7 @@ sp_api::decl_runtime_apis! { fn transaction_status(hash: H256) -> Option; fn gas_price() -> U256; fn evm_balance(address: H160) -> U256; - fn code_at(address: H160) -> Vec; + fn account_code_at(address: H160) -> Vec; } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 9189505bf4..84ce028c3b 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -201,7 +201,7 @@ impl EthApiT for EthApi where Ok( self.client .runtime_api() - .code_at(&BlockId::Hash(header.hash()), address) + .account_code_at(&BlockId::Hash(header.hash()), address) .map_err(|_| internal_err("fetch runtime chain id failed"))? .into(), ) diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index d5889c7d7f..3c34e9c81f 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -459,7 +459,7 @@ impl_runtime_apis! { account.balance } - fn code_at(address: H160) -> Vec { + fn account_code_at(address: H160) -> Vec { evm::Module::::account_codes(address) } } From 4c8fe879d7a12ba1c1ca030d2e03eefde9691743 Mon Sep 17 00:00:00 2001 From: tgmichel Date: Tue, 2 Jun 2020 09:39:47 +0200 Subject: [PATCH 11/11] Use account_basic Runtime API to retrieve account balance --- rpc/primitives/src/lib.rs | 1 - rpc/src/lib.rs | 4 ++-- template/runtime/src/lib.rs | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/rpc/primitives/src/lib.rs b/rpc/primitives/src/lib.rs index ffdc5d3878..f67964d481 100644 --- a/rpc/primitives/src/lib.rs +++ b/rpc/primitives/src/lib.rs @@ -40,7 +40,6 @@ sp_api::decl_runtime_apis! { fn account_basic(address: H160) -> pallet_evm::Account; fn transaction_status(hash: H256) -> Option; fn gas_price() -> U256; - fn evm_balance(address: H160) -> U256; fn account_code_at(address: H160) -> Vec; } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 84ce028c3b..2cb0730787 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -137,9 +137,9 @@ impl EthApiT for EthApi where Ok( self.client .runtime_api() - .evm_balance(&BlockId::Hash(header.hash()), address) + .account_basic(&BlockId::Hash(header.hash()), address) .map_err(|_| internal_err("fetch runtime chain id failed"))? - .into(), + .balance.into(), ) } diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 3c34e9c81f..1cb76290c2 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -454,11 +454,6 @@ impl_runtime_apis! { FixedGasPrice::min_gas_price() } - fn evm_balance(address: H160) -> U256 { - let account: EVMAccount = evm::Module::::accounts(address); - account.balance - } - fn account_code_at(address: H160) -> Vec { evm::Module::::account_codes(address) }