revm_context_interface/
context.rs1pub use crate::journaled_state::StateLoad;
2use crate::{Block, Cfg, Database, JournalTr, LocalContextTr, Transaction};
3use auto_impl::auto_impl;
4use primitives::U256;
5use std::string::String;
6
7#[auto_impl(&mut, Box)]
13pub trait ContextTr {
14 type Block: Block;
16 type Tx: Transaction;
18 type Cfg: Cfg;
20 type Db: Database;
22 type Journal: JournalTr<Database = Self::Db>;
24 type Chain;
26 type Local: LocalContextTr;
28
29 fn tx(&self) -> &Self::Tx;
31 fn block(&self) -> &Self::Block;
33 fn cfg(&self) -> &Self::Cfg;
35 fn journal(&mut self) -> &mut Self::Journal;
37 fn journal_ref(&self) -> &Self::Journal;
39 fn db(&mut self) -> &mut Self::Db;
41 fn db_ref(&self) -> &Self::Db;
43 fn chain(&mut self) -> &mut Self::Chain;
45 fn chain_ref(&self) -> &Self::Chain;
47 fn local(&mut self) -> &mut Self::Local;
49 fn error(&mut self) -> &mut Result<(), ContextError<<Self::Db as Database>::Error>>;
51 fn tx_journal(&mut self) -> (&Self::Tx, &mut Self::Journal);
54 fn tx_local(&mut self) -> (&Self::Tx, &mut Self::Local);
57}
58
59#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
61#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
62pub enum ContextError<DbError> {
63 Db(DbError),
65 Custom(String),
67}
68
69impl<DbError> From<DbError> for ContextError<DbError> {
70 fn from(value: DbError) -> Self {
71 Self::Db(value)
72 }
73}
74
75#[derive(Clone, Debug, Default, PartialEq, Eq)]
77#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
78pub struct SStoreResult {
79 pub original_value: U256,
81 pub present_value: U256,
83 pub new_value: U256,
85}
86
87impl SStoreResult {
88 #[inline]
90 pub fn is_new_eq_present(&self) -> bool {
91 self.new_value == self.present_value
92 }
93
94 #[inline]
96 pub fn is_original_eq_present(&self) -> bool {
97 self.original_value == self.present_value
98 }
99
100 #[inline]
102 pub fn is_original_eq_new(&self) -> bool {
103 self.original_value == self.new_value
104 }
105
106 #[inline]
108 pub fn is_original_zero(&self) -> bool {
109 self.original_value.is_zero()
110 }
111
112 #[inline]
114 pub fn is_present_zero(&self) -> bool {
115 self.present_value.is_zero()
116 }
117
118 #[inline]
120 pub fn is_new_zero(&self) -> bool {
121 self.new_value.is_zero()
122 }
123}
124
125#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
129#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
130pub struct SelfDestructResult {
131 pub had_value: bool,
132 pub target_exists: bool,
133 pub previously_destroyed: bool,
134}
135
136pub trait ContextSetters: ContextTr {
137 fn set_tx(&mut self, tx: Self::Tx);
138 fn set_block(&mut self, block: Self::Block);
139}