revm_context_interface/
context.rs

1pub use crate::journaled_state::StateLoad;
2use crate::{Block, Cfg, Database, JournalTr, Transaction};
3use auto_impl::auto_impl;
4use primitives::U256;
5
6#[auto_impl(&mut, Box)]
7pub trait ContextTr {
8    type Block: Block;
9    type Tx: Transaction;
10    type Cfg: Cfg;
11    type Db: Database;
12    type Journal: JournalTr<Database = Self::Db>;
13    type Chain;
14
15    fn tx(&self) -> &Self::Tx;
16    fn block(&self) -> &Self::Block;
17    fn cfg(&self) -> &Self::Cfg;
18    fn journal(&mut self) -> &mut Self::Journal;
19    fn journal_ref(&self) -> &Self::Journal;
20    fn db(&mut self) -> &mut Self::Db;
21    fn db_ref(&self) -> &Self::Db;
22    fn chain(&mut self) -> &mut Self::Chain;
23    fn error(&mut self) -> &mut Result<(), <Self::Db as Database>::Error>;
24    fn tx_journal(&mut self) -> (&mut Self::Tx, &mut Self::Journal);
25}
26
27/// Represents the result of an `sstore` operation.
28#[derive(Clone, Debug, Default, PartialEq, Eq)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30pub struct SStoreResult {
31    /// Value of the storage when it is first read
32    pub original_value: U256,
33    /// Current value of the storage
34    pub present_value: U256,
35    /// New value that is set
36    pub new_value: U256,
37}
38
39impl SStoreResult {
40    /// Returns `true` if the new value is equal to the present value.
41    #[inline]
42    pub fn is_new_eq_present(&self) -> bool {
43        self.new_value == self.present_value
44    }
45
46    /// Returns `true` if the original value is equal to the present value.
47    #[inline]
48    pub fn is_original_eq_present(&self) -> bool {
49        self.original_value == self.present_value
50    }
51
52    /// Returns `true` if the original value is equal to the new value.
53    #[inline]
54    pub fn is_original_eq_new(&self) -> bool {
55        self.original_value == self.new_value
56    }
57
58    /// Returns `true` if the original value is zero.
59    #[inline]
60    pub fn is_original_zero(&self) -> bool {
61        self.original_value.is_zero()
62    }
63
64    /// Returns `true` if the present value is zero.
65    #[inline]
66    pub fn is_present_zero(&self) -> bool {
67        self.present_value.is_zero()
68    }
69
70    /// Returns `true` if the new value is zero.
71    #[inline]
72    pub fn is_new_zero(&self) -> bool {
73        self.new_value.is_zero()
74    }
75}
76
77/// Result of a selfdestruct action
78///
79/// Value returned are needed to calculate the gas spent.
80#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
81#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
82pub struct SelfDestructResult {
83    pub had_value: bool,
84    pub target_exists: bool,
85    pub previously_destroyed: bool,
86}