From 58d8f13913aebb7c1c3155a750600a0a8c095c0d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 17 Dec 2015 12:43:01 +0100 Subject: [PATCH] TrieDBMut rather than TrieDB in preparation for immutable Trie type. --- src/account.rs | 4 ++-- src/state.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/account.rs b/src/account.rs index 33d9406ca..95f58ed3b 100644 --- a/src/account.rs +++ b/src/account.rs @@ -96,7 +96,7 @@ impl Account { _ => {} } // fetch - cannot be done in match because of the borrow rules. - let t = TrieDB::new_existing(db, &mut self.storage_root); + let t = TrieDBMut::new_existing(db, &mut self.storage_root); let r = H256::from_slice(t.get(key.bytes()).unwrap_or(&[0u8;32][..])); self.storage_overlay.insert(key, r.clone()); r @@ -177,7 +177,7 @@ impl Account { /// Commit the `storage_overlay` to the backing DB and update `storage_root`. pub fn commit_storage(&mut self, db: &mut HashDB) { - let mut t = TrieDB::new(db, &mut self.storage_root); + let mut t = TrieDBMut::new(db, &mut self.storage_root); for (k, v) in self.storage_overlay.iter() { // cast key and value to trait type, // so we can call overloaded `to_bytes` method diff --git a/src/state.rs b/src/state.rs index dc9da6d65..978b55fbf 100644 --- a/src/state.rs +++ b/src/state.rs @@ -46,7 +46,7 @@ impl State { let mut root = H256::new(); { // init trie and reset root too null - let _ = TrieDB::new(&mut db, &mut root); + let _ = TrieDBMut::new(&mut db, &mut root); } State { @@ -61,7 +61,7 @@ impl State { pub fn new_existing(mut db: OverlayDB, mut root: H256, account_start_nonce: U256) -> State { { // trie should panic! if root does not exist - let _ = TrieDB::new_existing(&mut db, &mut root); + let _ = TrieDBMut::new_existing(&mut db, &mut root); } State { @@ -125,7 +125,7 @@ impl State { self.require(a, false).inc_nonce() } - /// Commit accounts to TrieDB. This is similar to cpp-ethereum's dev::eth::commit. + /// Commit accounts to TrieDBMut. This is similar to cpp-ethereum's dev::eth::commit. /// `accounts` is mutable because we may need to commit the code or storage and record that. pub fn commit_into(db: &mut HashDB, mut root: H256, accounts: &mut HashMap>) -> H256 { // first, commit the sub trees. @@ -141,7 +141,7 @@ impl State { } { - let mut trie = TrieDB::new_existing(db, &mut root); + let mut trie = TrieDBMut::new_existing(db, &mut root); for (address, ref a) in accounts.iter() { match a { &&Some(ref account) => trie.insert(address, &account.rlp()), @@ -164,7 +164,7 @@ impl State { fn get(&mut self, a: &Address, require_code: bool) -> Option<&Account> { if self.cache.get(a).is_none() { // load from trie. - let t = TrieDB::new_existing(&mut self.db, &mut self.root); + let t = TrieDBMut::new_existing(&mut self.db, &mut self.root); self.cache.insert(a.clone(), t.get(&a).map(|rlp| { println!("RLP: {:?}", rlp); Account::from_rlp(rlp) })); } @@ -182,7 +182,7 @@ impl State { fn require(&mut self, a: &Address, require_code: bool) -> &mut Account { if self.cache.get(a).is_none() { // load from trie. - self.cache.insert(a.clone(), TrieDB::new(&mut self.db, &mut self.root).get(&a).map(|rlp| Account::from_rlp(rlp))); + self.cache.insert(a.clone(), TrieDBMut::new(&mut self.db, &mut self.root).get(&a).map(|rlp| Account::from_rlp(rlp))); } if self.cache.get(a).unwrap().is_none() {