-
Notifications
You must be signed in to change notification settings - Fork 981
Expand file tree
/
Copy pathlib.rs
More file actions
137 lines (122 loc) · 3.81 KB
/
lib.rs
File metadata and controls
137 lines (122 loc) · 3.81 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Optimism-specific constants, types, and helpers.
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate alloc as std;
// Mainnet related handlers.
pub mod eth_handler;
mod execution;
mod frame;
mod frame_data;
mod post_execution;
mod pre_execution;
mod precompile_provider;
mod validation;
// Public exports
pub use execution::{EthExecution, EthExecutionContext, EthExecutionError};
pub use frame::{return_create, return_eofcreate, EthFrame, EthFrameContext, EthFrameError};
pub use frame_data::{FrameData, FrameResult};
pub use post_execution::{EthPostExecution, EthPostExecutionContext, EthPostExecutionError};
pub use pre_execution::{apply_eip7702_auth_list, EthPreExecution, EthPreExecutionContext};
use precompile::PrecompileErrors;
pub use precompile_provider::EthPrecompileProvider;
use primitives::Log;
use state::EvmState;
use std::vec::Vec;
pub use validation::{
validate_eip4844_tx, validate_initial_tx_gas, validate_priority_fee_tx,
validate_tx_against_account, validate_tx_env, EthValidation, EthValidationContext,
EthValidationError,
};
// Imports
use context_interface::{
journaled_state::Journal,
result::{HaltReason, InvalidHeader, InvalidTransaction},
};
use context_interface::{
BlockGetter, CfgGetter, ErrorGetter, JournalDBError, JournalGetter, TransactionGetter,
};
use handler_interface::{
ExecutionHandler, Handler, PostExecutionHandler, PreExecutionHandler, ValidationHandler,
};
use interpreter::Host;
#[derive(Default)]
pub struct EthHandler<
CTX,
ERROR,
VAL = EthValidation<CTX, ERROR>,
PREEXEC = EthPreExecution<CTX, ERROR>,
EXEC = EthExecution<CTX, ERROR>,
POSTEXEC = EthPostExecution<CTX, ERROR, HaltReason>,
> {
pub validation: VAL,
pub pre_execution: PREEXEC,
pub execution: EXEC,
pub post_execution: POSTEXEC,
_phantom: core::marker::PhantomData<fn() -> (CTX, ERROR)>,
}
impl<CTX, ERROR> Default for EthHandler<CTX, ERROR> {
fn default() -> Self {
Self {
validation: EthValidation::new(),
pre_execution: EthPreExecution::new(),
execution: EthExecution::new(),
post_execution: EthPostExecution::new(),
_phantom: core::marker::PhantomData,
}
}
}
impl<CTX, ERROR, VAL, PREEXEC, EXEC, POSTEXEC>
EthHandler<CTX, ERROR, VAL, PREEXEC, EXEC, POSTEXEC>
{
pub fn new(
validation: VAL,
pre_execution: PREEXEC,
execution: EXEC,
post_execution: POSTEXEC,
) -> Self {
Self {
validation,
pre_execution,
execution,
post_execution,
_phantom: core::marker::PhantomData,
}
}
}
impl<CTX, ERROR, VAL, PREEXEC, EXEC, POSTEXEC> Handler
for EthHandler<CTX, ERROR, VAL, PREEXEC, EXEC, POSTEXEC>
where
CTX: TransactionGetter
+ BlockGetter
+ JournalGetter
+ CfgGetter
+ ErrorGetter<Error = JournalDBError<CTX>>
+ JournalGetter<Journal: Journal<FinalOutput = (EvmState, Vec<Log>)>>
+ Host,
ERROR: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<JournalDBError<CTX>>
+ From<PrecompileErrors>,
VAL: ValidationHandler,
PREEXEC: PreExecutionHandler,
EXEC: ExecutionHandler,
POSTEXEC: PostExecutionHandler,
{
type Validation = VAL;
type PreExecution = PREEXEC;
type Execution = EXEC;
type PostExecution = POSTEXEC;
fn validation(&mut self) -> &mut Self::Validation {
&mut self.validation
}
fn pre_execution(&mut self) -> &mut Self::PreExecution {
&mut self.pre_execution
}
fn execution(&mut self) -> &mut Self::Execution {
&mut self.execution
}
fn post_execution(&mut self) -> &mut Self::PostExecution {
&mut self.post_execution
}
}