revm_context_interface/
context.rs1pub use crate::journaled_state::StateLoad;
2use crate::{Block, Cfg, Database, JournalTr, 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
27 fn tx(&self) -> &Self::Tx;
29 fn block(&self) -> &Self::Block;
31 fn cfg(&self) -> &Self::Cfg;
33 fn journal(&mut self) -> &mut Self::Journal;
35 fn journal_ref(&self) -> &Self::Journal;
37 fn db(&mut self) -> &mut Self::Db;
39 fn db_ref(&self) -> &Self::Db;
41 fn chain(&mut self) -> &mut Self::Chain;
43 fn error(&mut self) -> &mut Result<(), ContextError<<Self::Db as Database>::Error>>;
45 fn tx_journal(&mut self) -> (&mut Self::Tx, &mut Self::Journal);
48}
49
50#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
52#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
53pub enum ContextError<DbError> {
54 Db(DbError),
56 Custom(String),
58}
59
60impl<DbError> From<DbError> for ContextError<DbError> {
61 fn from(value: DbError) -> Self {
62 Self::Db(value)
63 }
64}
65
66#[derive(Clone, Debug, Default, PartialEq, Eq)]
68#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
69pub struct SStoreResult {
70 pub original_value: U256,
72 pub present_value: U256,
74 pub new_value: U256,
76}
77
78impl SStoreResult {
79 #[inline]
81 pub fn is_new_eq_present(&self) -> bool {
82 self.new_value == self.present_value
83 }
84
85 #[inline]
87 pub fn is_original_eq_present(&self) -> bool {
88 self.original_value == self.present_value
89 }
90
91 #[inline]
93 pub fn is_original_eq_new(&self) -> bool {
94 self.original_value == self.new_value
95 }
96
97 #[inline]
99 pub fn is_original_zero(&self) -> bool {
100 self.original_value.is_zero()
101 }
102
103 #[inline]
105 pub fn is_present_zero(&self) -> bool {
106 self.present_value.is_zero()
107 }
108
109 #[inline]
111 pub fn is_new_zero(&self) -> bool {
112 self.new_value.is_zero()
113 }
114}
115
116#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
120#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
121pub struct SelfDestructResult {
122 pub had_value: bool,
123 pub target_exists: bool,
124 pub previously_destroyed: bool,
125}
126
127pub trait ContextSetters: ContextTr {
128 fn set_tx(&mut self, tx: Self::Tx);
129 fn set_block(&mut self, block: Self::Block);
130}