revm/handler/handle_types/
post_execution.rs
1use crate::{
3 handler::mainnet,
4 interpreter::Gas,
5 primitives::{db::Database, EVMError, EVMResultGeneric, ResultAndState, Spec},
6 Context, FrameResult,
7};
8use std::sync::Arc;
9
10pub type ReimburseCallerHandle<'a, EXT, DB> =
12 Arc<dyn Fn(&mut Context<EXT, DB>, &Gas) -> EVMResultGeneric<(), <DB as Database>::Error> + 'a>;
13
14pub type RewardBeneficiaryHandle<'a, EXT, DB> = ReimburseCallerHandle<'a, EXT, DB>;
16
17pub type OutputHandle<'a, EXT, DB> = Arc<
19 dyn Fn(
20 &mut Context<EXT, DB>,
21 FrameResult,
22 ) -> Result<ResultAndState, EVMError<<DB as Database>::Error>>
23 + 'a,
24>;
25
26pub type EndHandle<'a, EXT, DB> = Arc<
31 dyn Fn(
32 &mut Context<EXT, DB>,
33 Result<ResultAndState, EVMError<<DB as Database>::Error>>,
34 ) -> Result<ResultAndState, EVMError<<DB as Database>::Error>>
35 + 'a,
36>;
37
38pub type ClearHandle<'a, EXT, DB> = Arc<dyn Fn(&mut Context<EXT, DB>) + 'a>;
41
42pub type RefundHandle<'a, EXT, DB> = Arc<dyn Fn(&mut Context<EXT, DB>, &mut Gas, i64) + 'a>;
44pub struct PostExecutionHandler<'a, EXT, DB: Database> {
46 pub refund: RefundHandle<'a, EXT, DB>,
48 pub reimburse_caller: ReimburseCallerHandle<'a, EXT, DB>,
50 pub reward_beneficiary: RewardBeneficiaryHandle<'a, EXT, DB>,
52 pub output: OutputHandle<'a, EXT, DB>,
54 pub end: EndHandle<'a, EXT, DB>,
58 pub clear: ClearHandle<'a, EXT, DB>,
61}
62
63impl<'a, EXT: 'a, DB: Database + 'a> PostExecutionHandler<'a, EXT, DB> {
64 pub fn new<SPEC: Spec + 'a>() -> Self {
66 Self {
67 refund: Arc::new(mainnet::refund::<SPEC, EXT, DB>),
68 reimburse_caller: Arc::new(mainnet::reimburse_caller::<SPEC, EXT, DB>),
69 reward_beneficiary: Arc::new(mainnet::reward_beneficiary::<SPEC, EXT, DB>),
70 output: Arc::new(mainnet::output::<EXT, DB>),
71 end: Arc::new(mainnet::end::<EXT, DB>),
72 clear: Arc::new(mainnet::clear::<EXT, DB>),
73 }
74 }
75}
76
77impl<EXT, DB: Database> PostExecutionHandler<'_, EXT, DB> {
78 pub fn refund(&self, context: &mut Context<EXT, DB>, gas: &mut Gas, eip7702_refund: i64) {
80 (self.refund)(context, gas, eip7702_refund)
81 }
82
83 pub fn reimburse_caller(
85 &self,
86 context: &mut Context<EXT, DB>,
87 gas: &Gas,
88 ) -> Result<(), EVMError<DB::Error>> {
89 (self.reimburse_caller)(context, gas)
90 }
91 pub fn reward_beneficiary(
93 &self,
94 context: &mut Context<EXT, DB>,
95 gas: &Gas,
96 ) -> Result<(), EVMError<DB::Error>> {
97 (self.reward_beneficiary)(context, gas)
98 }
99
100 pub fn output(
102 &self,
103 context: &mut Context<EXT, DB>,
104 result: FrameResult,
105 ) -> Result<ResultAndState, EVMError<DB::Error>> {
106 (self.output)(context, result)
107 }
108
109 pub fn end(
111 &self,
112 context: &mut Context<EXT, DB>,
113 end_output: Result<ResultAndState, EVMError<DB::Error>>,
114 ) -> Result<ResultAndState, EVMError<DB::Error>> {
115 (self.end)(context, end_output)
116 }
117
118 pub fn clear(&self, context: &mut Context<EXT, DB>) {
120 (self.clear)(context)
121 }
122}