diff --git a/demo/api/src/lib.rs b/demo/api/src/lib.rs index f83a6d228d3c9..848c0530464b5 100644 --- a/demo/api/src/lib.rs +++ b/demo/api/src/lib.rs @@ -108,19 +108,19 @@ where } fn validators(&self, at: &BlockId) -> Result> { - self.call_api(at, "validators", &()) + self.call_api_at(at, "validators", &()) } fn random_seed(&self, at: &BlockId) -> Result { - self.call_api(at, "random_seed", &()) + self.call_api_at(at, "random_seed", &()) } fn timestamp(&self, at: &BlockId) -> Result { - self.call_api(at, "timestamp", &()) + self.call_api_at(at, "timestamp", &()) } fn evaluate_block(&self, at: &BlockId, block: Block) -> Result { - let res: Result<()> = self.call_api(at, "execute_block", &block); + let res: Result<()> = self.call_api_at(at, "execute_block", &block); match res { Ok(()) => Ok(true), Err(err) => match err.kind() { @@ -131,11 +131,11 @@ where } fn index(&self, at: &BlockId, account: AccountId) -> Result { - self.call_api(at, "account_nonce", &account) + self.call_api_at(at, "account_nonce", &account) } fn lookup(&self, at: &BlockId, address: Address) -> Result> { - self.call_api(at, "lookup_address", &address) + self.call_api_at(at, "lookup_address", &address) } fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result { @@ -149,7 +149,7 @@ where fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result> { let runtime_version = self.runtime_version_at(at)?; - self.call_api(at, "inherent_extrinsics", &(inherent_data, runtime_version.spec_version)) + self.call_api_at(at, "inherent_extrinsics", &(inherent_data, runtime_version.spec_version)) } } diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm index 0561462684fe8..392a6759728e1 100644 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm differ diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm index d0cf943ec482f..b0912cf63bf2e 100755 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm differ diff --git a/substrate/client/src/client.rs b/substrate/client/src/client.rs index 9246e61ec85d9..9b82413c6a670 100644 --- a/substrate/client/src/client.rs +++ b/substrate/client/src/client.rs @@ -28,7 +28,7 @@ use primitives::{Blake2Hasher, RlpCodec}; use primitives::storage::{StorageKey, StorageData}; use codec::{Encode, Decode}; use state_machine::{ - Ext, OverlayedChanges, Backend as StateBackend, CodeExecutor, + Backend as StateBackend, CodeExecutor, ExecutionStrategy, ExecutionManager, prove_read }; @@ -37,7 +37,7 @@ use blockchain::{self, Info as ChainInfo, Backend as ChainBackend, HeaderBackend use call_executor::{CallExecutor, LocalCallExecutor}; use executor::{RuntimeVersion, RuntimeInfo}; use notifications::{StorageNotifications, StorageEventStream}; -use {cht, error, in_mem, block_builder, runtime_io, bft, genesis}; +use {cht, error, in_mem, block_builder, bft, genesis}; /// Type that implements `futures::Stream` of block import events. pub type BlockchainEventStream = mpsc::UnboundedReceiver>; @@ -308,23 +308,6 @@ impl Client where Ok((header, proof)) } - /// Set up the native execution environment to call into a native runtime code. - pub fn using_environment T, T>( - &self, f: F - ) -> error::Result { - self.using_environment_at(&BlockId::Number(self.info()?.chain.best_number), &mut Default::default(), f) - } - - /// Set up the native execution environment to call into a native runtime code. - pub fn using_environment_at T, T>( - &self, - id: &BlockId, - overlay: &mut OverlayedChanges, - f: F - ) -> error::Result { - Ok(runtime_io::with_externalities(&mut Ext::new(overlay, &self.state_at(id)?), f)) - } - /// Create a new block, built on the head of the chain. pub fn new_block(&self) -> error::Result> where E: Clone @@ -339,11 +322,16 @@ impl Client where block_builder::BlockBuilder::at_block(parent, &self) } + /// Set up the native execution environment to call into a native runtime code. + pub fn call_api(&self, function: &'static str, args: &A) -> error::Result + where A: Encode, R: Decode + { + self.call_api_at(&BlockId::Number(self.info()?.chain.best_number), function, args) + } + /// Call a runtime function at given block. - pub fn call_api(&self, at: &BlockId, function: &'static str, args: &A) -> error::Result - where - A: Encode, - R: Decode, + pub fn call_api_at(&self, at: &BlockId, function: &'static str, args: &A) -> error::Result + where A: Encode, R: Decode { let parent = at; let header = <::Header as HeaderT>::new( @@ -686,15 +674,15 @@ mod tests { use test_client::{self, TestClient}; use test_client::client::BlockOrigin; use test_client::client::backend::Backend as TestBackend; - use test_client::{runtime as test_runtime, BlockBuilderExt}; + use test_client::BlockBuilderExt; use test_client::runtime::Transfer; #[test] fn client_initialises_from_genesis_ok() { let client = test_client::new(); - assert_eq!(client.using_environment(|| test_runtime::system::balance_of(Keyring::Alice.to_raw_public().into())).unwrap(), 1000); - assert_eq!(client.using_environment(|| test_runtime::system::balance_of(Keyring::Ferdie.to_raw_public().into())).unwrap(), 0); + assert_eq!(client.call_api::<_, u64>("balance_of", &Keyring::Alice.to_raw_public()).unwrap(), 1000); + assert_eq!(client.call_api::<_, u64>("balance_of", &Keyring::Ferdie.to_raw_public()).unwrap(), 0); } #[test] @@ -737,8 +725,8 @@ mod tests { assert_eq!(client.info().unwrap().chain.best_number, 1); assert!(client.state_at(&BlockId::Number(1)).unwrap() != client.state_at(&BlockId::Number(0)).unwrap()); - assert_eq!(client.using_environment(|| test_runtime::system::balance_of(Keyring::Alice.to_raw_public().into())).unwrap(), 958); - assert_eq!(client.using_environment(|| test_runtime::system::balance_of(Keyring::Ferdie.to_raw_public().into())).unwrap(), 42); + assert_eq!(client.call_api::<_, u64>("balance_of", &Keyring::Alice.to_raw_public()).unwrap(), 958); + assert_eq!(client.call_api::<_, u64>("balance_of", &Keyring::Ferdie.to_raw_public()).unwrap(), 42); } #[test] diff --git a/substrate/test-runtime/src/lib.rs b/substrate/test-runtime/src/lib.rs index 5f9712aa7167b..eb1deca741c3f 100644 --- a/substrate/test-runtime/src/lib.rs +++ b/substrate/test-runtime/src/lib.rs @@ -153,6 +153,7 @@ pub mod api { initialise_block => |header| system::initialise_block(header), execute_block => |block| system::execute_block(block), apply_extrinsic => |utx| system::execute_transaction(utx), - finalise_block => |()| system::finalise_block() + finalise_block => |()| system::finalise_block(), + balance_of => |a| system::balance_of(a) ); } diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index c917584c7f3d8..dc0c4e46cea88 100644 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm index 89a0e6127e8be..5b61818cf57b2 100755 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm differ