cfx_executor/stack/frame_local.rs
1use super::{
2 super::context::{Context, OriginInfo},
3 RuntimeRes,
4};
5use crate::{machine::Machine, substate::Substate};
6
7use cfx_types::{Address, Space};
8use cfx_vm_types::{Env, Spec};
9
10/// `FrameLocal` represents the local data associated with a specific call frame
11/// during the execution of the Ethereum Virtual Machine (EVM). This data is
12/// local to the frame and is not visible to other frames in the execution
13/// stack.
14pub struct FrameLocal<'a> {
15 /// The space the current frame belongs.
16 pub space: Space,
17
18 /// A reference to environmental information relevant to the
19 /// current execution, such as the block number and block author.
20 pub env: &'a Env,
21
22 /// The depth of the current frame in the call stack.
23 pub depth: usize,
24
25 /// The address of the newly deployed contract, if the current frame is for
26 /// contract creation.
27 pub create_address: Option<Address>,
28
29 /// The caller information for the current frame, including the caller, the
30 /// original sender, etc.
31 pub origin: OriginInfo,
32
33 /// Collects changes produced during execution for post-execution logic
34 /// such as collecting storage fees, and generating receipts.
35 pub substate: Substate,
36
37 /// All the necessities for executing EVM bytecode.
38 pub machine: &'a Machine,
39
40 /// Activated hardfork features and the parameters that may be modified in
41 /// hardfork
42 pub spec: &'a Spec,
43
44 /// Enforce the static context of a call, as defined by EIP-214
45 /// (STATICCALL), ensuring that certain operations do not alter the
46 /// state.
47 pub static_flag: bool,
48}
49
50impl<'a> FrameLocal<'a> {
51 pub fn new(
52 space: Space, env: &'a Env, machine: &'a Machine, spec: &'a Spec,
53 depth: usize, origin: OriginInfo, substate: Substate,
54 create_address: Option<Address>, static_flag: bool,
55 ) -> Self {
56 FrameLocal {
57 space,
58 env,
59 depth,
60 origin,
61 substate,
62 machine,
63 spec,
64 create_address,
65 static_flag,
66 }
67 }
68
69 /// Creates a `Context` for the current frame, which includes two distinct
70 /// parts:
71 /// 1. Local frame information - Specific to the current frame and not
72 /// visible to others.
73 /// 2. Runtime resources - Contains global information like the ledger
74 /// state, accessible across frames.
75 pub fn make_vm_context<'b, 'c>(
76 &'b mut self, resources: &'b mut RuntimeRes<'c>,
77 ) -> Context<'b> {
78 Context::new(self, resources)
79 }
80}