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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
mod memory;
pub use self::memory::{MemoryBackend, MemoryVicinity, MemoryAccount};
use alloc::vec::Vec;
use primitive_types::{H160, H256, U256};
#[derive(Clone, Eq, PartialEq, Debug, Default)]
pub struct Basic {
pub balance: U256,
pub nonce: U256,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Log {
pub address: H160,
pub topics: Vec<H256>,
pub data: Vec<u8>,
}
#[derive(Clone, Debug)]
pub enum Apply<I> {
Modify {
address: H160,
basic: Basic,
code: Option<Vec<u8>>,
storage: I,
reset_storage: bool,
},
Delete {
address: H160,
},
}
pub trait Backend {
fn gas_price(&self) -> U256;
fn origin(&self) -> H160;
fn block_hash(&self, number: U256) -> H256;
fn block_number(&self) -> U256;
fn block_coinbase(&self) -> H160;
fn block_timestamp(&self) -> U256;
fn block_difficulty(&self) -> U256;
fn block_gas_limit(&self) -> U256;
fn chain_id(&self) -> U256;
fn exists(&self, address: H160) -> bool;
fn basic(&self, address: H160) -> Basic;
fn code_hash(&self, address: H160) -> H256;
fn code_size(&self, address: H160) -> usize;
fn code(&self, address: H160) -> Vec<u8>;
fn storage(&self, address: H160, index: H256) -> H256;
}
pub trait ApplyBackend {
fn apply<A, I, L>(
&mut self,
values: A,
logs: L,
delete_empty: bool,
) where
A: IntoIterator<Item=Apply<I>>,
I: IntoIterator<Item=(H256, H256)>,
L: IntoIterator<Item=Log>;
}