revm_context_interface/
context.rs1pub use crate::journaled_state::StateLoad;
3use crate::{Block, Cfg, Database, JournalTr, LocalContextTr, Transaction};
4use auto_impl::auto_impl;
5use primitives::StorageValue;
6use std::string::String;
7
8#[auto_impl(&mut, Box)]
16pub trait ContextTr {
17 type Block: Block;
19 type Tx: Transaction;
21 type Cfg: Cfg;
23 type Db: Database;
25 type Journal: JournalTr<Database = Self::Db>;
27 type Chain;
29 type Local: LocalContextTr;
31
32 fn tx(&self) -> &Self::Tx;
34 fn block(&self) -> &Self::Block;
36 fn cfg(&self) -> &Self::Cfg;
38 fn journal(&self) -> &Self::Journal;
40 fn journal_mut(&mut self) -> &mut Self::Journal;
42 fn journal_ref(&self) -> &Self::Journal {
44 self.journal()
45 }
46 fn db(&self) -> &Self::Db;
48 fn db_mut(&mut self) -> &mut Self::Db;
50 fn db_ref(&self) -> &Self::Db {
52 self.db()
53 }
54 fn chain(&self) -> &Self::Chain;
56 fn chain_mut(&mut self) -> &mut Self::Chain;
58 fn chain_ref(&self) -> &Self::Chain {
60 self.chain()
61 }
62 fn local(&self) -> &Self::Local;
64 fn local_mut(&mut self) -> &mut Self::Local;
66 fn local_ref(&self) -> &Self::Local {
68 self.local()
69 }
70 fn error(&mut self) -> &mut Result<(), ContextError<<Self::Db as Database>::Error>>;
72 fn tx_journal_mut(&mut self) -> (&Self::Tx, &mut Self::Journal);
75 fn tx_local_mut(&mut self) -> (&Self::Tx, &mut Self::Local);
78}
79
80#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
82#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
83pub enum ContextError<DbError> {
84 Db(DbError),
86 Custom(String),
88}
89
90impl<DbError> From<DbError> for ContextError<DbError> {
91 fn from(value: DbError) -> Self {
92 Self::Db(value)
93 }
94}
95
96#[derive(Clone, Debug, Default, PartialEq, Eq)]
98#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99pub struct SStoreResult {
100 pub original_value: StorageValue,
102 pub present_value: StorageValue,
104 pub new_value: StorageValue,
106}
107
108impl SStoreResult {
109 #[inline]
111 pub fn is_new_eq_present(&self) -> bool {
112 self.new_value == self.present_value
113 }
114
115 #[inline]
117 pub fn is_original_eq_present(&self) -> bool {
118 self.original_value == self.present_value
119 }
120
121 #[inline]
123 pub fn is_original_eq_new(&self) -> bool {
124 self.original_value == self.new_value
125 }
126
127 #[inline]
129 pub fn is_original_zero(&self) -> bool {
130 self.original_value.is_zero()
131 }
132
133 #[inline]
135 pub fn is_present_zero(&self) -> bool {
136 self.present_value.is_zero()
137 }
138
139 #[inline]
141 pub fn is_new_zero(&self) -> bool {
142 self.new_value.is_zero()
143 }
144}
145
146#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
150#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
151pub struct SelfDestructResult {
152 pub had_value: bool,
154 pub target_exists: bool,
156 pub previously_destroyed: bool,
158}
159
160pub trait ContextSetters: ContextTr {
162 fn set_tx(&mut self, tx: Self::Tx);
164 fn set_block(&mut self, block: Self::Block);
166}