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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use alloc::vec::Vec;
use primitive_types::{H160, H256, U256};
use crate::{Capture, Stack, ExitError, Opcode,
CreateScheme, Context, Machine, ExitReason};
#[derive(Clone, Debug)]
pub struct Transfer {
pub source: H160,
pub target: H160,
pub value: U256,
}
pub trait Handler {
type CreateInterrupt;
type CreateFeedback;
type CallInterrupt;
type CallFeedback;
fn balance(&self, address: H160) -> U256;
fn code_size(&self, address: H160) -> U256;
fn code_hash(&self, address: H160) -> H256;
fn code(&self, address: H160) -> Vec<u8>;
fn storage(&self, address: H160, index: H256) -> H256;
fn original_storage(&self, address: H160, index: H256) -> H256;
fn gas_left(&self) -> U256;
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 deleted(&self, address: H160) -> bool;
fn set_storage(&mut self, address: H160, index: H256, value: H256) -> Result<(), ExitError>;
fn log(&mut self, address: H160, topcis: Vec<H256>, data: Vec<u8>) -> Result<(), ExitError>;
fn mark_delete(&mut self, address: H160, target: H160) -> Result<(), ExitError>;
fn create(
&mut self,
caller: H160,
scheme: CreateScheme,
value: U256,
init_code: Vec<u8>,
target_gas: Option<u64>,
) -> Capture<(ExitReason, Option<H160>, Vec<u8>), Self::CreateInterrupt>;
fn create_feedback(
&mut self,
_feedback: Self::CreateFeedback
) -> Result<(), ExitError> {
Ok(())
}
fn call(
&mut self,
code_address: H160,
transfer: Option<Transfer>,
input: Vec<u8>,
target_gas: Option<u64>,
is_static: bool,
context: Context,
) -> Capture<(ExitReason, Vec<u8>), Self::CallInterrupt>;
fn call_feedback(
&mut self,
_feedback: Self::CallFeedback
) -> Result<(), ExitError> {
Ok(())
}
fn pre_validate(
&mut self,
context: &Context,
opcode: Opcode,
stack: &Stack
) -> Result<(), ExitError>;
fn other(
&mut self,
_opcode: Opcode,
_stack: &mut Machine
) -> Result<(), ExitError> {
Err(ExitError::OutOfGas)
}
}