use crate::{
interpreter_types::{InterpreterTypes as ITy, RuntimeFlag, StackTr},
Host, InstructionExecResult as Result,
};
use primitives::hardfork::SpecId::*;
use crate::InstructionContext as Ictx;
pub fn chainid<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
check!(context.interpreter, ISTANBUL);
push!(context.interpreter, context.host.chain_id());
Ok(())
}
pub fn coinbase<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
push!(
context.interpreter,
context.host.beneficiary().into_word().into()
);
Ok(())
}
pub fn timestamp<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
push!(context.interpreter, context.host.timestamp());
Ok(())
}
pub fn block_number<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
push!(context.interpreter, context.host.block_number());
Ok(())
}
pub fn difficulty<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
if context
.interpreter
.runtime_flag
.spec_id()
.is_enabled_in(MERGE)
{
push!(context.interpreter, context.host.prevrandao().unwrap());
} else {
push!(context.interpreter, context.host.difficulty());
}
Ok(())
}
pub fn gaslimit<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
push!(context.interpreter, context.host.gas_limit());
Ok(())
}
pub fn basefee<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
check!(context.interpreter, LONDON);
push!(context.interpreter, context.host.basefee());
Ok(())
}
pub fn blob_basefee<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
check!(context.interpreter, CANCUN);
push!(context.interpreter, context.host.blob_gasprice());
Ok(())
}
pub fn slot_num<IT: ITy, H: Host + ?Sized>(context: Ictx<'_, H, IT>) -> Result {
check!(context.interpreter, AMSTERDAM);
push!(context.interpreter, context.host.slot_num());
Ok(())
}