use super::{ExecutableTransaction, Interpreter, RuntimeBalances};
use crate::context::Context;
use crate::interpreter::PanicContext;
use crate::state::Debugger;
use crate::storage::MemoryStorage;
use crate::{consts::*, gas::GasCosts};
#[cfg(feature = "profile-any")]
use crate::profiler::{ProfileReceiver, Profiler};
use fuel_tx::ConsensusParameters;
impl<S, Tx> Interpreter<S, Tx>
where
Tx: Default,
{
pub fn with_storage(storage: S, params: ConsensusParameters, gas_costs: GasCosts) -> Self {
Self {
registers: [0; VM_REGISTER_COUNT],
memory: vec![0; VM_MAX_RAM as usize],
frames: vec![],
receipts: vec![],
tx: Default::default(),
initial_balances: Default::default(),
storage,
debugger: Debugger::default(),
context: Context::default(),
balances: RuntimeBalances::default(),
gas_costs,
#[cfg(feature = "profile-any")]
profiler: Profiler::default(),
params,
panic_context: PanicContext::None,
}
}
pub fn with_params(&mut self, params: ConsensusParameters) -> &mut Self {
self.params = params;
self
}
#[cfg(feature = "profile-any")]
pub fn with_profiler<P>(&mut self, receiver: P) -> &mut Self
where
P: ProfileReceiver + Send + Sync + 'static,
{
self.profiler.set_receiver(Box::new(receiver));
self
}
}
impl<S, Tx> Interpreter<S, Tx>
where
S: Clone,
Tx: ExecutableTransaction,
{
pub fn build(&mut self) -> Self {
self.clone()
}
}
impl<S, Tx> Default for Interpreter<S, Tx>
where
S: Default,
Tx: ExecutableTransaction,
{
fn default() -> Self {
Self::with_storage(Default::default(), Default::default(), Default::default())
}
}
impl<Tx> Interpreter<(), Tx>
where
Tx: ExecutableTransaction,
{
pub fn without_storage() -> Self {
Self::default()
}
}
impl<Tx> Interpreter<MemoryStorage, Tx>
where
Tx: ExecutableTransaction,
{
pub fn with_memory_storage() -> Self {
Self::default()
}
}