diff --git a/crates/context/src/context.rs b/crates/context/src/context.rs index f1194ffc5f..96c82152a9 100644 --- a/crates/context/src/context.rs +++ b/crates/context/src/context.rs @@ -136,7 +136,8 @@ impl< CFG: Cfg, JOURNAL: JournalTr, CHAIN, - > ContextSetters for Context + LOCAL: LocalContextTr, + > ContextSetters for Context { fn set_tx(&mut self, tx: Self::Tx) { self.tx = tx; @@ -153,7 +154,8 @@ impl< DB: Database, JOURNAL: JournalTr, CHAIN: Default, - > Context + LOCAL: LocalContextTr + Default, + > Context { /// Creates a new context with a new database type. /// @@ -168,7 +170,7 @@ impl< spec, ..Default::default() }, - local: LocalContext::default(), + local: LOCAL::default(), journaled_state, chain: Default::default(), error: Ok(()), @@ -176,19 +178,20 @@ impl< } } -impl Context +impl Context where BLOCK: Block, TX: Transaction, CFG: Cfg, DB: Database, JOURNAL: JournalTr, + 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>( self, mut journal: OJOURNAL, - ) -> Context { + ) -> Context { journal.set_spec_id(self.cfg.spec().into()); Context { tx: self.tx, @@ -207,7 +210,7 @@ where pub fn with_db( self, db: ODB, - ) -> Context, CHAIN> { + ) -> Context, CHAIN, LOCAL> { let spec = self.cfg.spec().into(); let mut journaled_state = Journal::new(db); journaled_state.set_spec_id(spec); @@ -226,7 +229,8 @@ where pub fn with_ref_db( self, db: ODB, - ) -> Context, Journal>, CHAIN> { + ) -> Context, Journal>, CHAIN, LOCAL> + { let spec = self.cfg.spec().into(); let mut journaled_state = Journal::new(WrapDatabaseRef(db)); journaled_state.set_spec_id(spec); @@ -242,7 +246,10 @@ where } /// Creates a new context with a new block type. - pub fn with_block(self, block: OB) -> Context { + pub fn with_block( + self, + block: OB, + ) -> Context { Context { tx: self.tx, block, @@ -257,7 +264,7 @@ where pub fn with_tx( self, tx: OTX, - ) -> Context { + ) -> Context { Context { tx, block: self.block, @@ -270,7 +277,7 @@ where } /// Creates a new context with a new chain type. - pub fn with_chain(self, chain: OC) -> Context { + pub fn with_chain(self, chain: OC) -> Context { Context { tx: self.tx, block: self.block, @@ -286,7 +293,7 @@ where pub fn with_cfg( mut self, cfg: OCFG, - ) -> Context { + ) -> Context { self.journaled_state.set_spec_id(cfg.spec().into()); Context { tx: self.tx, @@ -299,6 +306,22 @@ where } } + /// Creates a new context with a new local context type. + pub fn with_local( + self, + local: OL, + ) -> Context { + 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(mut self, f: F) -> Self @@ -408,4 +431,12 @@ where { f(&mut self.journaled_state); } + + /// Modifies the local context. + pub fn modify_local(&mut self, f: F) + where + F: FnOnce(&mut LOCAL), + { + f(&mut self.local); + } }