use crate::{
interpreter_types::{InterpreterTypes, RuntimeFlag, StackTr},
Host,
};
use primitives::hardfork::SpecId::*;
use crate::InstructionContext;
pub fn chainid<WIRE: InterpreterTypes, H: Host + ?Sized>(context: InstructionContext<'_, H, WIRE>) {
check!(context.interpreter, ISTANBUL);
push!(context.interpreter, context.host.chain_id());
}
pub fn coinbase<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
push!(
context.interpreter,
context.host.beneficiary().into_word().into()
);
}
pub fn timestamp<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
push!(context.interpreter, context.host.timestamp());
}
pub fn block_number<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
push!(context.interpreter, context.host.block_number());
}
pub fn difficulty<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
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());
}
}
pub fn gaslimit<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
push!(context.interpreter, context.host.gas_limit());
}
pub fn basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(context: InstructionContext<'_, H, WIRE>) {
check!(context.interpreter, LONDON);
push!(context.interpreter, context.host.basefee());
}
pub fn blob_basefee<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
check!(context.interpreter, CANCUN);
push!(context.interpreter, context.host.blob_gasprice());
}
pub fn slot_num<WIRE: InterpreterTypes, H: Host + ?Sized>(
context: InstructionContext<'_, H, WIRE>,
) {
check!(context.interpreter, AMSTERDAM);
push!(context.interpreter, context.host.slot_num());
}