pub use crate::journaled_state::StateLoad;
use crate::{Block, Cfg, Database, JournalTr, LocalContextTr, Transaction};
use auto_impl::auto_impl;
use primitives::StorageValue;
use std::string::String;
#[auto_impl(&mut, Box)]
pub trait ContextTr {
type Block: Block;
type Tx: Transaction;
type Cfg: Cfg;
type Db: Database;
type Journal: JournalTr<Database = Self::Db>;
type Chain;
type Local: LocalContextTr;
fn tx(&self) -> &Self::Tx;
fn block(&self) -> &Self::Block;
fn cfg(&self) -> &Self::Cfg;
fn journal(&self) -> &Self::Journal;
fn journal_mut(&mut self) -> &mut Self::Journal;
fn journal_ref(&self) -> &Self::Journal {
self.journal()
}
fn db(&self) -> &Self::Db;
fn db_mut(&mut self) -> &mut Self::Db;
fn db_ref(&self) -> &Self::Db {
self.db()
}
fn chain(&self) -> &Self::Chain;
fn chain_mut(&mut self) -> &mut Self::Chain;
fn chain_ref(&self) -> &Self::Chain {
self.chain()
}
fn local(&self) -> &Self::Local;
fn local_mut(&mut self) -> &mut Self::Local;
fn local_ref(&self) -> &Self::Local {
self.local()
}
fn error(&mut self) -> &mut Result<(), ContextError<<Self::Db as Database>::Error>>;
fn tx_journal_mut(&mut self) -> (&Self::Tx, &mut Self::Journal);
fn tx_local_mut(&mut self) -> (&Self::Tx, &mut Self::Local);
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ContextError<DbError> {
Db(DbError),
Custom(String),
}
impl<DbError> From<DbError> for ContextError<DbError> {
fn from(value: DbError) -> Self {
Self::Db(value)
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SStoreResult {
pub original_value: StorageValue,
pub present_value: StorageValue,
pub new_value: StorageValue,
}
impl SStoreResult {
#[inline]
pub fn is_new_eq_present(&self) -> bool {
self.new_value == self.present_value
}
#[inline]
pub fn is_original_eq_present(&self) -> bool {
self.original_value == self.present_value
}
#[inline]
pub fn is_original_eq_new(&self) -> bool {
self.original_value == self.new_value
}
#[inline]
pub fn is_original_zero(&self) -> bool {
self.original_value.is_zero()
}
#[inline]
pub fn is_present_zero(&self) -> bool {
self.present_value.is_zero()
}
#[inline]
pub fn is_new_zero(&self) -> bool {
self.new_value.is_zero()
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SelfDestructResult {
pub had_value: bool,
pub target_exists: bool,
pub previously_destroyed: bool,
}
pub trait ContextSetters: ContextTr {
fn set_tx(&mut self, tx: Self::Tx);
fn set_block(&mut self, block: Self::Block);
}