revm_context_interface/
context.rs1pub use crate::journaled_state::StateLoad;
3use crate::{
4 result::FromStringError, Block, Cfg, Database, JournalTr, LocalContextTr, Transaction,
5};
6use auto_impl::auto_impl;
7use primitives::StorageValue;
8use std::string::String;
9
10#[auto_impl(&mut, Box)]
18pub trait ContextTr {
19 type Block: Block;
21 type Tx: Transaction;
23 type Cfg: Cfg;
25 type Db: Database;
27 type Journal: JournalTr<Database = Self::Db>;
29 type Chain;
31 type Local: LocalContextTr;
33
34 fn tx(&self) -> &Self::Tx;
36 fn block(&self) -> &Self::Block;
38 fn cfg(&self) -> &Self::Cfg;
40 fn journal(&self) -> &Self::Journal;
42 fn journal_mut(&mut self) -> &mut Self::Journal;
44 fn journal_ref(&self) -> &Self::Journal {
46 self.journal()
47 }
48 fn db(&self) -> &Self::Db;
50 fn db_mut(&mut self) -> &mut Self::Db;
52 fn db_ref(&self) -> &Self::Db {
54 self.db()
55 }
56 fn chain(&self) -> &Self::Chain;
58 fn chain_mut(&mut self) -> &mut Self::Chain;
60 fn chain_ref(&self) -> &Self::Chain {
62 self.chain()
63 }
64 fn local(&self) -> &Self::Local;
66 fn local_mut(&mut self) -> &mut Self::Local;
68 fn local_ref(&self) -> &Self::Local {
70 self.local()
71 }
72 fn error(&mut self) -> &mut Result<(), ContextError<<Self::Db as Database>::Error>>;
74 fn tx_journal_mut(&mut self) -> (&Self::Tx, &mut Self::Journal);
77 fn tx_local_mut(&mut self) -> (&Self::Tx, &mut Self::Local);
80}
81
82#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
84#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
85pub enum ContextError<DbError> {
86 Db(DbError),
88 Custom(String),
90}
91
92impl<DbError> FromStringError for ContextError<DbError> {
93 fn from_string(value: String) -> Self {
94 Self::Custom(value)
95 }
96}
97
98impl<DbError> From<DbError> for ContextError<DbError> {
99 fn from(value: DbError) -> Self {
100 Self::Db(value)
101 }
102}
103
104#[derive(Clone, Debug, Default, PartialEq, Eq)]
106#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
107pub struct SStoreResult {
108 pub original_value: StorageValue,
110 pub present_value: StorageValue,
112 pub new_value: StorageValue,
114}
115
116impl SStoreResult {
117 #[inline]
119 pub fn is_new_eq_present(&self) -> bool {
120 self.new_value == self.present_value
121 }
122
123 #[inline]
125 pub fn is_original_eq_present(&self) -> bool {
126 self.original_value == self.present_value
127 }
128
129 #[inline]
131 pub fn is_original_eq_new(&self) -> bool {
132 self.original_value == self.new_value
133 }
134
135 #[inline]
137 pub fn is_original_zero(&self) -> bool {
138 self.original_value.is_zero()
139 }
140
141 #[inline]
143 pub fn is_present_zero(&self) -> bool {
144 self.present_value.is_zero()
145 }
146
147 #[inline]
149 pub fn is_new_zero(&self) -> bool {
150 self.new_value.is_zero()
151 }
152}
153
154#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
158#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
159pub struct SelfDestructResult {
160 pub had_value: bool,
162 pub target_exists: bool,
164 pub previously_destroyed: bool,
166}
167
168pub trait ContextSetters: ContextTr {
170 fn set_tx(&mut self, tx: Self::Tx);
172 fn set_block(&mut self, block: Self::Block);
174}