mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
Make it compilable (still bunch to fix!)
This commit is contained in:
107
src/evm/api/exec.rs
Normal file
107
src/evm/api/exec.rs
Normal file
@ -0,0 +1,107 @@
|
||||
use super::HlEvmInner;
|
||||
use crate::evm::{handler::HlHandler, spec::HlSpecId, transaction::HlTxTr};
|
||||
use revm::{
|
||||
context::{ContextSetters, JournalOutput},
|
||||
context_interface::{
|
||||
result::{EVMError, ExecutionResult, ResultAndState},
|
||||
Cfg, ContextTr, Database, JournalTr,
|
||||
},
|
||||
handler::{instructions::EthInstructions, EthFrame, EvmTr, Handler, PrecompileProvider},
|
||||
inspector::{InspectCommitEvm, InspectEvm, Inspector, InspectorHandler, JournalExt},
|
||||
interpreter::{interpreter::EthInterpreter, InterpreterResult},
|
||||
DatabaseCommit, ExecuteCommitEvm, ExecuteEvm,
|
||||
};
|
||||
|
||||
// Type alias for HL context
|
||||
pub trait HlContextTr:
|
||||
ContextTr<Journal: JournalTr<FinalOutput = JournalOutput>, Tx: HlTxTr, Cfg: Cfg<Spec = HlSpecId>>
|
||||
{
|
||||
}
|
||||
|
||||
impl<T> HlContextTr for T where
|
||||
T: ContextTr<
|
||||
Journal: JournalTr<FinalOutput = JournalOutput>,
|
||||
Tx: HlTxTr,
|
||||
Cfg: Cfg<Spec = HlSpecId>,
|
||||
>
|
||||
{
|
||||
}
|
||||
|
||||
/// Type alias for the error type of the HlEvm.
|
||||
type HlError<CTX> = EVMError<<<CTX as ContextTr>::Db as Database>::Error>;
|
||||
|
||||
impl<CTX, INSP, PRECOMPILE> ExecuteEvm
|
||||
for HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE>
|
||||
where
|
||||
CTX: HlContextTr + ContextSetters,
|
||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||
{
|
||||
type Output = Result<ResultAndState, HlError<CTX>>;
|
||||
|
||||
type Tx = <CTX as ContextTr>::Tx;
|
||||
|
||||
type Block = <CTX as ContextTr>::Block;
|
||||
|
||||
fn set_tx(&mut self, tx: Self::Tx) {
|
||||
self.0.ctx.set_tx(tx);
|
||||
}
|
||||
|
||||
fn set_block(&mut self, block: Self::Block) {
|
||||
self.0.ctx.set_block(block);
|
||||
}
|
||||
|
||||
fn replay(&mut self) -> Self::Output {
|
||||
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
|
||||
h.run(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX, INSP, PRECOMPILE> ExecuteCommitEvm
|
||||
for HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE>
|
||||
where
|
||||
CTX: HlContextTr<Db: DatabaseCommit> + ContextSetters,
|
||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||
{
|
||||
type CommitOutput = Result<ExecutionResult, HlError<CTX>>;
|
||||
|
||||
fn replay_commit(&mut self) -> Self::CommitOutput {
|
||||
self.replay().map(|r| {
|
||||
self.ctx().db().commit(r.state);
|
||||
r.result
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX, INSP, PRECOMPILE> InspectEvm
|
||||
for HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE>
|
||||
where
|
||||
CTX: HlContextTr<Journal: JournalExt> + ContextSetters,
|
||||
INSP: Inspector<CTX, EthInterpreter>,
|
||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||
{
|
||||
type Inspector = INSP;
|
||||
|
||||
fn set_inspector(&mut self, inspector: Self::Inspector) {
|
||||
self.0.inspector = inspector;
|
||||
}
|
||||
|
||||
fn inspect_replay(&mut self) -> Self::Output {
|
||||
let mut h = HlHandler::<_, _, EthFrame<_, _, _>>::new();
|
||||
h.inspect_run(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX, INSP, PRECOMPILE> InspectCommitEvm
|
||||
for HlEvmInner<CTX, INSP, EthInstructions<EthInterpreter, CTX>, PRECOMPILE>
|
||||
where
|
||||
CTX: HlContextTr<Journal: JournalExt, Db: DatabaseCommit> + ContextSetters,
|
||||
INSP: Inspector<CTX, EthInterpreter>,
|
||||
PRECOMPILE: PrecompileProvider<CTX, Output = InterpreterResult>,
|
||||
{
|
||||
fn inspect_replay_commit(&mut self) -> Self::CommitOutput {
|
||||
self.inspect_replay().map(|r| {
|
||||
self.ctx().db().commit(r.state);
|
||||
r.result
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user