Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions crates/context/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ impl<
CFG: Cfg,
JOURNAL: JournalTr<Database = DB>,
CHAIN,
> ContextSetters for Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>
LOCAL: LocalContextTr,
> ContextSetters for Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN, LOCAL>
{
fn set_tx(&mut self, tx: Self::Tx) {
self.tx = tx;
Expand All @@ -153,7 +154,8 @@ impl<
DB: Database,
JOURNAL: JournalTr<Database = DB>,
CHAIN: Default,
> Context<BLOCK, TX, CfgEnv, DB, JOURNAL, CHAIN>
LOCAL: LocalContextTr + Default,
> Context<BLOCK, TX, CfgEnv, DB, JOURNAL, CHAIN, LOCAL>
{
/// Creates a new context with a new database type.
///
Expand All @@ -168,27 +170,28 @@ impl<
spec,
..Default::default()
},
local: LocalContext::default(),
local: LOCAL::default(),
journaled_state,
chain: Default::default(),
error: Ok(()),
}
}
}

impl<BLOCK, TX, CFG, DB, JOURNAL, CHAIN> Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN>
impl<BLOCK, TX, CFG, DB, JOURNAL, CHAIN, LOCAL> Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN, LOCAL>
where
BLOCK: Block,
TX: Transaction,
CFG: Cfg,
DB: Database,
JOURNAL: JournalTr<Database = DB>,
LOCAL: LocalContextTr,
{
/// Creates a new context with a new journal type. New journal needs to have the same database type.
pub fn with_new_journal<OJOURNAL: JournalTr<Database = DB>>(
self,
mut journal: OJOURNAL,
) -> Context<BLOCK, TX, CFG, DB, OJOURNAL, CHAIN> {
) -> Context<BLOCK, TX, CFG, DB, OJOURNAL, CHAIN, LOCAL> {
journal.set_spec_id(self.cfg.spec().into());
Context {
tx: self.tx,
Expand All @@ -207,7 +210,7 @@ where
pub fn with_db<ODB: Database>(
self,
db: ODB,
) -> Context<BLOCK, TX, CFG, ODB, Journal<ODB>, CHAIN> {
) -> Context<BLOCK, TX, CFG, ODB, Journal<ODB>, CHAIN, LOCAL> {
let spec = self.cfg.spec().into();
let mut journaled_state = Journal::new(db);
journaled_state.set_spec_id(spec);
Expand All @@ -226,7 +229,8 @@ where
pub fn with_ref_db<ODB: DatabaseRef>(
self,
db: ODB,
) -> Context<BLOCK, TX, CFG, WrapDatabaseRef<ODB>, Journal<WrapDatabaseRef<ODB>>, CHAIN> {
) -> Context<BLOCK, TX, CFG, WrapDatabaseRef<ODB>, Journal<WrapDatabaseRef<ODB>>, CHAIN, LOCAL>
{
let spec = self.cfg.spec().into();
let mut journaled_state = Journal::new(WrapDatabaseRef(db));
journaled_state.set_spec_id(spec);
Expand All @@ -242,7 +246,10 @@ where
}

/// Creates a new context with a new block type.
pub fn with_block<OB: Block>(self, block: OB) -> Context<OB, TX, CFG, DB, JOURNAL, CHAIN> {
pub fn with_block<OB: Block>(
self,
block: OB,
) -> Context<OB, TX, CFG, DB, JOURNAL, CHAIN, LOCAL> {
Context {
tx: self.tx,
block,
Expand All @@ -257,7 +264,7 @@ where
pub fn with_tx<OTX: Transaction>(
self,
tx: OTX,
) -> Context<BLOCK, OTX, CFG, DB, JOURNAL, CHAIN> {
) -> Context<BLOCK, OTX, CFG, DB, JOURNAL, CHAIN, LOCAL> {
Context {
tx,
block: self.block,
Expand All @@ -270,7 +277,7 @@ where
}

/// Creates a new context with a new chain type.
pub fn with_chain<OC>(self, chain: OC) -> Context<BLOCK, TX, CFG, DB, JOURNAL, OC> {
pub fn with_chain<OC>(self, chain: OC) -> Context<BLOCK, TX, CFG, DB, JOURNAL, OC, LOCAL> {
Context {
tx: self.tx,
block: self.block,
Expand All @@ -286,7 +293,7 @@ where
pub fn with_cfg<OCFG: Cfg>(
mut self,
cfg: OCFG,
) -> Context<BLOCK, TX, OCFG, DB, JOURNAL, CHAIN> {
) -> Context<BLOCK, TX, OCFG, DB, JOURNAL, CHAIN, LOCAL> {
self.journaled_state.set_spec_id(cfg.spec().into());
Context {
tx: self.tx,
Expand All @@ -299,6 +306,22 @@ where
}
}

/// Creates a new context with a new local context type.
pub fn with_local<OL: LocalContextTr>(
self,
local: OL,
) -> Context<BLOCK, TX, CFG, DB, JOURNAL, CHAIN, OL> {
Context {
tx: self.tx,
block: self.block,
cfg: self.cfg,
journaled_state: self.journaled_state,
local,
chain: self.chain,
error: Ok(()),
}
}

/// Modifies the context configuration.
#[must_use]
pub fn modify_cfg_chained<F>(mut self, f: F) -> Self
Expand Down Expand Up @@ -408,4 +431,12 @@ where
{
f(&mut self.journaled_state);
}

/// Modifies the local context.
pub fn modify_local<F>(&mut self, f: F)
where
F: FnOnce(&mut LOCAL),
{
f(&mut self.local);
}
}
Loading