1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::Account;
use hashbrown::HashMap as Map;
use primitive_types::{H160, H256, U256};
use crate::AccountInfo;
use auto_impl::auto_impl;
use bytes::Bytes;
#[auto_impl(& mut, Box)]
pub trait Database {
fn basic(&mut self, address: H160) -> AccountInfo;
fn code_by_hash(&mut self, code_hash: H256) -> Bytes;
fn storage(&mut self, address: H160, index: U256) -> U256;
fn block_hash(&mut self, number: U256) -> H256;
}
#[auto_impl(& mut, Box)]
pub trait DatabaseCommit {
fn commit(&mut self, changes: Map<H160, Account>);
}
#[auto_impl(&, Box)]
pub trait DatabaseRef {
fn basic(&self, address: H160) -> AccountInfo;
fn code_by_hash(&self, code_hash: H256) -> Bytes;
fn storage(&self, address: H160, index: U256) -> U256;
fn block_hash(&self, number: U256) -> H256;
}
pub struct RefDBWrapper<'a> {
pub db: &'a dyn DatabaseRef,
}
impl<'a> RefDBWrapper<'a> {
pub fn new(db: &'a dyn DatabaseRef) -> Self {
Self { db }
}
}
impl<'a> Database for RefDBWrapper<'a> {
fn basic(&mut self, address: H160) -> AccountInfo {
self.db.basic(address)
}
fn code_by_hash(&mut self, code_hash: H256) -> Bytes {
self.db.code_by_hash(code_hash)
}
fn storage(&mut self, address: H160, index: U256) -> U256 {
self.db.storage(address, index)
}
fn block_hash(&mut self, number: U256) -> H256 {
self.db.block_hash(number)
}
}