use crate::Tx;
use alloy::primitives::{address, Address, Bytes, U256};
use revm::context::{TransactionType, TxEnv};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SystemTx {
pub target: Address,
pub input: Bytes,
pub caller: Address,
}
pub const DEFAULT_SYSTEM_CALLER: Address = address!("fffffffffffffffffffffffffffffffffffffffe");
impl SystemTx {
pub const fn new(target: Address, input: Bytes) -> Self {
Self { caller: DEFAULT_SYSTEM_CALLER, target, input }
}
pub const fn new_with_caller(target: Address, input: Bytes, caller: Address) -> Self {
Self { caller, target, input }
}
}
impl Tx for SystemTx {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
let TxEnv {
tx_type,
caller,
gas_limit,
gas_price,
kind,
value,
data,
nonce,
chain_id,
access_list,
gas_priority_fee,
blob_hashes,
max_fee_per_blob_gas,
authorization_list,
} = tx_env;
*tx_type = TransactionType::Custom as u8;
*caller = self.caller;
*gas_limit = 30_000_000;
*gas_price = 0;
*kind = self.target.into();
*value = U256::ZERO;
*data = self.input.clone();
*nonce = 0;
chain_id.take();
gas_priority_fee.take();
access_list.0.clear();
blob_hashes.clear();
*max_fee_per_blob_gas = 0;
authorization_list.clear();
}
}