use crate::{
vm::{
evm::{interpreter::Halt, EVMGas, Interpreter, DIFFICULTY},
Ext,
},
Error, RuntimeCosts,
};
use core::ops::ControlFlow;
use revm::interpreter::gas::BASE;
use sp_core::U256;
pub fn chainid<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(BASE))?;
interpreter.stack.push(interpreter.ext.chain_id())?;
ControlFlow::Continue(())
}
pub fn coinbase<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(RuntimeCosts::BlockAuthor)?;
let coinbase = interpreter.ext.block_author();
interpreter.stack.push(coinbase)?;
ControlFlow::Continue(())
}
pub fn timestamp<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(RuntimeCosts::Now)?;
let timestamp = interpreter.ext.now();
interpreter.stack.push(timestamp)?;
ControlFlow::Continue(())
}
pub fn block_number<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(RuntimeCosts::BlockNumber)?;
let block_number = interpreter.ext.block_number();
interpreter.stack.push(block_number)?;
ControlFlow::Continue(())
}
pub fn difficulty<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(BASE))?;
interpreter.stack.push(U256::from(DIFFICULTY))?;
ControlFlow::Continue(())
}
pub fn gaslimit<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(RuntimeCosts::GasLimit)?;
let gas_limit = interpreter.ext.gas_limit();
interpreter.stack.push(U256::from(gas_limit))?;
ControlFlow::Continue(())
}
pub fn basefee<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(RuntimeCosts::BaseFee)?;
interpreter.stack.push(crate::Pallet::<E::T>::evm_base_fee())?;
ControlFlow::Continue(())
}
pub fn blob_basefee<'ext, E: Ext>(_interpreter: &mut Interpreter<'ext, E>) -> ControlFlow<Halt> {
ControlFlow::Break(Error::<E::T>::InvalidInstruction.into())
}