From d70491f093098253866be3238113cbf728a9d28a Mon Sep 17 00:00:00 2001 From: Gav Date: Thu, 22 Feb 2018 18:38:33 +0100 Subject: [PATCH] More work on Ext & calls. --- substrate/demo/runtime/src/runtime/staking.rs | 40 +++++++++---------- substrate/substrate/runtime-std/with_std.rs | 4 +- .../substrate/runtime-std/without_std.rs | 4 +- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/substrate/demo/runtime/src/runtime/staking.rs b/substrate/demo/runtime/src/runtime/staking.rs index 867b5d8795..b843498f88 100644 --- a/substrate/demo/runtime/src/runtime/staking.rs +++ b/substrate/demo/runtime/src/runtime/staking.rs @@ -18,7 +18,7 @@ use rstd::prelude::*; use rstd::cell::RefCell; -use rstd::hash_map::{HashMap, Entry}; +use rstd::collections::hash_map::{HashMap, Entry}; use runtime_io::{print, blake2_256}; use codec::KeyedVec; use runtime_support::{storage, StorageVec}; @@ -220,24 +220,24 @@ pub mod public { let local: RefCell = RefCell::new(HashMap::new()); let should_commit = { - // Our local ext: Should be used for any transfers and creates that happen internally. - let ext = Ext { - do_get_account_storage: |account: &AccountId, location: &[u8]| - local.borrow().get(account) - .and_then(|a| a.2.get(location)) - .cloned() - .unwrap_or_else(|| ext.get_account_storage(account, location)), - do_get_account_code: |account: &AccountId| - local.borrow().get(account) - .and_then(|a| a.1.clone()) - .unwrap_or_else(|| ext.get_account_code(account)), - do_get_account_balance: |account: &AccountId| - local.borrow().get(account) - .and_then(|a| a.0) - .unwrap_or_else(|| ext.get_account_balance(account)), - }; - let mut transfer = |inner_dest: &AccountId, value: Balance| { + // Our local ext: Should be used for any transfers and creates that happen internally. + let ext = Ext { + do_get_account_storage: |account: &AccountId, location: &[u8]| + local.borrow().get(account) + .and_then(|a| a.2.get(location)) + .cloned() + .unwrap_or_else(|| ext.get_account_storage(account, location)), + do_get_account_code: |account: &AccountId| + local.borrow().get(account) + .and_then(|a| a.1.clone()) + .unwrap_or_else(|| ext.get_account_code(account)), + do_get_account_balance: |account: &AccountId| + local.borrow().get(account) + .and_then(|a| a.0) + .unwrap_or_else(|| ext.get_account_balance(account)), + }; + if let Some(commit_state) = effect_transfer(dest, inner_dest, value, ext) { let mut local = local.borrow_mut(); for (address, (maybe_balance, maybe_code, storage)) in commit_state.into_iter() { @@ -259,8 +259,8 @@ pub mod public { } } }; - - let mut create = |code: &[u8], value: Balance| unimplemented!(); + let mut create = |code: &[u8], value: Balance| unimplemented!(); // TODO: use `create` and place in `local` + let mut set_storage = |code: &[u8], value: Balance| unimplemented!(); // TODO: use `local` storage::put(CALL_DEPTH, &(call_depth + 1)); diff --git a/substrate/substrate/runtime-std/with_std.rs b/substrate/substrate/runtime-std/with_std.rs index 719f85f0ca..91d3de8751 100644 --- a/substrate/substrate/runtime-std/with_std.rs +++ b/substrate/substrate/runtime-std/with_std.rs @@ -25,4 +25,6 @@ pub use std::ptr; pub use std::rc; pub use std::slice; pub use std::vec; -pub use std::collections::hash_map; +pub mod collections { + pub use std::collections::hash_map; +} diff --git a/substrate/substrate/runtime-std/without_std.rs b/substrate/substrate/runtime-std/without_std.rs index b54d652323..dc4ce2d866 100644 --- a/substrate/substrate/runtime-std/without_std.rs +++ b/substrate/substrate/runtime-std/without_std.rs @@ -25,7 +25,9 @@ extern crate pwasm_alloc; pub use alloc::boxed; pub use alloc::rc; pub use alloc::vec; -pub use alloc::collections::hash_map; +pub mod collections { + pub use alloc::collections::hash_map; +} pub use core::cell; pub use core::cmp; pub use core::intrinsics;