use bigint::{Address, Gas, U256};
use smallvec::SmallVec;
use crate::patch::{AccountPatch, Patch, Precompiled};
#[derive(Copy, Clone)]
pub struct DynamicAccountPatch {
pub initial_nonce: U256,
pub initial_create_nonce: U256,
pub empty_considered_exists: bool,
pub allow_partial_change: bool,
}
impl AccountPatch for DynamicAccountPatch {
fn initial_nonce(&self) -> U256 {
self.initial_nonce
}
fn initial_create_nonce(&self) -> U256 {
self.initial_create_nonce
}
fn empty_considered_exists(&self) -> bool {
self.empty_considered_exists
}
fn allow_partial_change(&self) -> bool {
self.allow_partial_change
}
}
#[derive(Clone)]
pub struct DynamicPatch {
pub account_patch: DynamicAccountPatch,
pub code_deposit_limit: Option<usize>,
pub callstack_limit: usize,
pub gas_extcode: Gas,
pub gas_balance: Gas,
pub gas_sload: Gas,
pub gas_suicide: Gas,
pub gas_suicide_new_account: Gas,
pub gas_call: Gas,
pub gas_expbyte: Gas,
pub gas_transaction_create: Gas,
pub force_code_deposit: bool,
pub has_delegate_call: bool,
pub has_static_call: bool,
pub has_revert: bool,
pub has_return_data: bool,
pub has_bitwise_shift: bool,
pub has_extcodehash: bool,
pub has_create2: bool,
pub has_reduced_sstore_gas_metering: bool,
pub err_on_call_with_more_gas: bool,
pub call_create_l64_after_gas: bool,
pub memory_limit: usize,
pub enabled_precompileds: SmallVec<[Address; 8]>,
pub precompileds: &'static [(Address, Option<&'static [u8]>, &'static dyn Precompiled)],
}
#[rustfmt::skip]
impl Patch for DynamicPatch {
type Account = DynamicAccountPatch;
fn account_patch(&self) -> &Self::Account { &self.account_patch }
fn code_deposit_limit(&self) -> Option<usize> { self.code_deposit_limit }
fn callstack_limit(&self) -> usize { self.callstack_limit }
fn gas_extcode(&self) -> Gas { self.gas_extcode }
fn gas_balance(&self) -> Gas { self.gas_balance }
fn gas_sload(&self) -> Gas { self.gas_sload }
fn gas_suicide(&self) -> Gas { self.gas_suicide }
fn gas_suicide_new_account(&self) -> Gas { self.gas_suicide_new_account }
fn gas_call(&self) -> Gas { self.gas_call }
fn gas_expbyte(&self) -> Gas { self.gas_expbyte }
fn gas_transaction_create(&self) -> Gas { self.gas_transaction_create }
fn force_code_deposit(&self) -> bool { self.force_code_deposit }
fn has_delegate_call(&self) -> bool { self.has_delegate_call }
fn has_static_call(&self) -> bool { self.has_static_call }
fn has_revert(&self) -> bool { self.has_revert }
fn has_return_data(&self) -> bool { self.has_return_data }
fn has_bitwise_shift(&self) -> bool { self.has_bitwise_shift }
fn has_create2(&self) -> bool { self.has_create2 }
fn has_extcodehash(&self) -> bool { self.has_extcodehash }
fn has_reduced_sstore_gas_metering(&self) -> bool { self.has_reduced_sstore_gas_metering }
fn err_on_call_with_more_gas(&self) -> bool { self.err_on_call_with_more_gas }
fn call_create_l64_after_gas(&self) -> bool { self.call_create_l64_after_gas }
fn memory_limit(&self) -> usize { self.memory_limit }
fn is_precompiled_contract_enabled(&self, address: &Address) -> bool {
self.enabled_precompileds.iter().find(|&a| a == address).is_some()
}
fn precompileds(&self) -> &[(Address, Option<&'static [u8]>, &'static dyn Precompiled)] {
&self.precompileds
}
}