revm_context/
local.rs

1//! Local context that is filled by execution.
2use context_interface::LocalContextTr;
3use core::cell::RefCell;
4use std::{rc::Rc, vec::Vec};
5
6/// Local context that is filled by execution.
7#[derive(Clone, Debug)]
8pub struct LocalContext {
9    /// Interpreter shared memory buffer. A reused memory buffer for calls.
10    pub shared_memory_buffer: Rc<RefCell<Vec<u8>>>,
11}
12
13impl Default for LocalContext {
14    fn default() -> Self {
15        Self {
16            shared_memory_buffer: Rc::new(RefCell::new(Vec::with_capacity(1024 * 4))),
17        }
18    }
19}
20
21impl LocalContextTr for LocalContext {
22    fn clear(&mut self) {
23        // Sets len to 0 but it will not shrink to drop the capacity.
24        unsafe { self.shared_memory_buffer.borrow_mut().set_len(0) };
25    }
26
27    fn shared_memory_buffer(&self) -> &Rc<RefCell<Vec<u8>>> {
28        &self.shared_memory_buffer
29    }
30}
31
32impl LocalContext {
33    /// Creates a new local context, initcodes are hashes and added to the mapping.
34    pub fn new() -> Self {
35        Self::default()
36    }
37}