mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: correct effective_gas_price (#2573)
This commit is contained in:
@ -369,7 +369,7 @@ impl Transaction {
|
||||
/// transactions is returned.
|
||||
///
|
||||
/// If the `max_fee_per_gas` is less than the base fee, `None` returned.
|
||||
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> Option<u128> {
|
||||
pub fn effective_gas_tip(&self, base_fee: Option<u64>) -> Option<u128> {
|
||||
if let Some(base_fee) = base_fee {
|
||||
let max_fee_per_gas = self.max_fee_per_gas();
|
||||
if max_fee_per_gas < base_fee as u128 {
|
||||
@ -400,6 +400,19 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the effective gas price for the given base fee.
|
||||
///
|
||||
/// If the transaction is a legacy or EIP2930 transaction, the gas price is returned.
|
||||
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
|
||||
let dynamic_tx = match self {
|
||||
Transaction::Legacy(tx) => return tx.gas_price,
|
||||
Transaction::Eip2930(tx) => return tx.gas_price,
|
||||
Transaction::Eip1559(dynamic_tx) => dynamic_tx,
|
||||
};
|
||||
|
||||
dynamic_tx.effective_gas_price(base_fee)
|
||||
}
|
||||
|
||||
/// Returns the effective miner gas tip cap (`gasTipCap`) for the given base fee.
|
||||
///
|
||||
/// Returns `None` if the basefee is higher than the [Transaction::max_fee_per_gas].
|
||||
@ -633,6 +646,26 @@ impl Encodable for Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl TxEip1559 {
|
||||
/// Returns the effective gas price for the given `base_fee`.
|
||||
pub fn effective_gas_price(&self, base_fee: Option<u64>) -> u128 {
|
||||
match base_fee {
|
||||
None => self.max_fee_per_gas,
|
||||
Some(base_fee) => {
|
||||
// if the tip is greater than the max priority fee per gas, set it to the max
|
||||
// priority fee per gas + base fee
|
||||
let tip = self.max_fee_per_gas - base_fee as u128;
|
||||
if tip > self.max_priority_fee_per_gas {
|
||||
self.max_priority_fee_per_gas + base_fee as u128
|
||||
} else {
|
||||
// otherwise return the max fee per gas
|
||||
self.max_fee_per_gas
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether or not the transaction is a contract creation.
|
||||
#[derive_arbitrary(compact, rlp)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user