Slightly better mutation semantics.
This commit is contained in:
parent
e08958d502
commit
8687d0d097
@ -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
|
||||
}
|
||||
|
10
src/state.rs
10
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user