From 8687d0d097547869a97a404c544bf7458e64c9ac Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 17 Dec 2015 12:32:35 +0100 Subject: [PATCH] Slightly better mutation semantics. --- src/account.rs | 2 +- src/state.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/account.rs b/src/account.rs index e342333ec..33d9406ca 100644 --- a/src/account.rs +++ b/src/account.rs @@ -97,7 +97,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 r = H256::from_slice(t.at(key.bytes()).unwrap_or(&[0u8;32][..])); + let r = H256::from_slice(t.get(key.bytes()).unwrap_or(&[0u8;32][..])); self.storage_overlay.insert(key, r.clone()); r } diff --git a/src/state.rs b/src/state.rs index 05615e0c0..dc9da6d65 100644 --- a/src/state.rs +++ b/src/state.rs @@ -6,6 +6,8 @@ use util::trie::*; use util::rlp::*; use util::uint::*; use std::mem; +//use std::cell::*; +//use std::ops::*; use account::Account; /* enum ValueOrRef<'self, 'db: 'self> { @@ -159,11 +161,11 @@ impl State { /// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too. /// `force_create` creates a new, empty basic account if there is not currently an active account. // TODO: make immutable. - fn get(&mut self, a: &Address, require_code: bool) -> Option<&mut Account> { + 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); - self.cache.insert(a.clone(), t.at(&a).map(|rlp| { println!("RLP: {:?}", rlp); Account::from_rlp(rlp) })); + self.cache.insert(a.clone(), t.get(&a).map(|rlp| { println!("RLP: {:?}", rlp); Account::from_rlp(rlp) })); } let db = &self.db; @@ -171,7 +173,7 @@ impl State { if require_code { account.cache_code(db); } - account + account as &Account }) } @@ -180,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).at(&a).map(|rlp| Account::from_rlp(rlp))); + self.cache.insert(a.clone(), TrieDB::new(&mut self.db, &mut self.root).get(&a).map(|rlp| Account::from_rlp(rlp))); } if self.cache.get(a).unwrap().is_none() {