cfx_executor/stack/
resources.rs

1use crate::{
2    executive_observer::TracerTrait, stack::CallStackInfo, state::State,
3};
4
5/// The global resources and utilities shared across all frames.
6pub struct RuntimeRes<'a> {
7    /// The ledger state including information such as the balance of each
8    /// account.
9    pub state: &'a mut State,
10
11    /// Metadata about the frame call stack.
12    pub callstack: &'a mut CallStackInfo,
13
14    /// A tool for recording information about the execution as it proceeds.
15    /// The data captured by the tracer is not used for consensus-critical
16    /// operations.
17    pub tracer: &'a mut dyn TracerTrait,
18}
19
20#[cfg(test)]
21pub mod runtime_res_test {
22    use super::RuntimeRes;
23    use crate::stack::CallStackInfo;
24
25    use super::State;
26
27    pub struct OwnedRuntimeRes<'a> {
28        state: &'a mut State,
29        callstack: CallStackInfo,
30        tracer: (),
31    }
32
33    impl<'a> From<&'a mut State> for OwnedRuntimeRes<'a> {
34        fn from(state: &'a mut State) -> Self {
35            OwnedRuntimeRes {
36                state,
37                callstack: CallStackInfo::new(),
38                tracer: (),
39            }
40        }
41    }
42
43    impl<'a> OwnedRuntimeRes<'a> {
44        pub fn as_res<'b>(&'b mut self) -> RuntimeRes<'b> {
45            RuntimeRes {
46                state: &mut self.state,
47                callstack: &mut self.callstack,
48                tracer: &mut self.tracer,
49            }
50        }
51    }
52}