revm_context_interface/
context.rs1pub use crate::journaled_state::StateLoad;
2use crate::{Block, Cfg, Database, JournalTr, Transaction};
3use auto_impl::auto_impl;
4use core::cell::RefCell;
5use primitives::U256;
6use std::{rc::Rc, string::String, vec::Vec};
7
8#[auto_impl(&mut, Box)]
14pub trait ContextTr {
15 type Block: Block;
17 type Tx: Transaction;
19 type Cfg: Cfg;
21 type Db: Database;
23 type Journal: JournalTr<Database = Self::Db>;
25 type Chain;
27
28 fn tx(&self) -> &Self::Tx;
30 fn block(&self) -> &Self::Block;
32 fn cfg(&self) -> &Self::Cfg;
34 fn journal(&mut self) -> &mut Self::Journal;
36 fn journal_ref(&self) -> &Self::Journal;
38 fn db(&mut self) -> &mut Self::Db;
40 fn db_ref(&self) -> &Self::Db;
42 fn chain(&mut self) -> &mut Self::Chain;
44 fn memory_buffer(&mut self) -> &Rc<RefCell<Vec<u8>>>;
46 fn error(&mut self) -> &mut Result<(), ContextError<<Self::Db as Database>::Error>>;
48 fn tx_journal(&mut self) -> (&mut Self::Tx, &mut Self::Journal);
51}
52
53#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
55#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56pub enum ContextError<DbError> {
57 Db(DbError),
59 Custom(String),
61}
62
63impl<DbError> From<DbError> for ContextError<DbError> {
64 fn from(value: DbError) -> Self {
65 Self::Db(value)
66 }
67}
68
69#[derive(Clone, Debug, Default, PartialEq, Eq)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72pub struct SStoreResult {
73 pub original_value: U256,
75 pub present_value: U256,
77 pub new_value: U256,
79}
80
81impl SStoreResult {
82 #[inline]
84 pub fn is_new_eq_present(&self) -> bool {
85 self.new_value == self.present_value
86 }
87
88 #[inline]
90 pub fn is_original_eq_present(&self) -> bool {
91 self.original_value == self.present_value
92 }
93
94 #[inline]
96 pub fn is_original_eq_new(&self) -> bool {
97 self.original_value == self.new_value
98 }
99
100 #[inline]
102 pub fn is_original_zero(&self) -> bool {
103 self.original_value.is_zero()
104 }
105
106 #[inline]
108 pub fn is_present_zero(&self) -> bool {
109 self.present_value.is_zero()
110 }
111
112 #[inline]
114 pub fn is_new_zero(&self) -> bool {
115 self.new_value.is_zero()
116 }
117}
118
119#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
123#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
124pub struct SelfDestructResult {
125 pub had_value: bool,
126 pub target_exists: bool,
127 pub previously_destroyed: bool,
128}
129
130pub trait ContextSetters: ContextTr {
131 fn set_tx(&mut self, tx: Self::Tx);
132 fn set_block(&mut self, block: Self::Block);
133}