pub trait Transaction {
type AccessListItem<'a>: AccessListItemTr
where Self: 'a;
type Authorization<'a>: AuthorizationTr
where Self: 'a;
Show 23 methods
// Required methods
fn tx_type(&self) -> u8;
fn caller(&self) -> Address;
fn gas_limit(&self) -> u64;
fn value(&self) -> U256;
fn input(&self) -> &Bytes;
fn nonce(&self) -> u64;
fn kind(&self) -> TxKind;
fn chain_id(&self) -> Option<u64>;
fn gas_price(&self) -> u128;
fn access_list(
&self,
) -> Option<impl Iterator<Item = Self::AccessListItem<'_>>>;
fn blob_versioned_hashes(&self) -> &[B256] ⓘ;
fn max_fee_per_blob_gas(&self) -> u128;
fn authorization_list_len(&self) -> usize;
fn authorization_list(
&self,
) -> impl Iterator<Item = Self::Authorization<'_>>;
fn max_priority_fee_per_gas(&self) -> Option<u128>;
// Provided methods
fn total_blob_gas(&self) -> u64 { ... }
fn calc_max_data_fee(&self) -> U256 { ... }
fn max_fee_per_gas(&self) -> u128 { ... }
fn effective_gas_price(&self, base_fee: u128) -> u128 { ... }
fn max_balance_spending(&self) -> Result<U256, InvalidTransaction> { ... }
fn ensure_enough_balance(
&self,
balance: U256,
) -> Result<(), InvalidTransaction> { ... }
fn effective_balance_spending(
&self,
base_fee: u128,
blob_price: u128,
) -> Result<U256, InvalidTransaction> { ... }
fn gas_balance_spending(
&self,
base_fee: u128,
blob_price: u128,
) -> Result<U256, InvalidTransaction> { ... }
}
Expand description
Main Transaction trait that abstracts and specifies all transaction currently supported by Ethereum
Access to any associated type is gated behind tx_type
function.
It can be extended to support new transaction types and only transaction types can be deprecated by not returning tx_type.
Required Associated Types§
Sourcetype AccessListItem<'a>: AccessListItemTr
where
Self: 'a
type AccessListItem<'a>: AccessListItemTr where Self: 'a
EIP-2930 Access list item type.
Sourcetype Authorization<'a>: AuthorizationTr
where
Self: 'a
type Authorization<'a>: AuthorizationTr where Self: 'a
EIP-7702 Authorization type.
Required Methods§
Sourcefn tx_type(&self) -> u8
fn tx_type(&self) -> u8
Returns the transaction type.
Depending on this field other functions should be called.
Sourcefn caller(&self) -> Address
fn caller(&self) -> Address
Caller aka Author aka transaction signer.
Note : Common field for all transactions.
Sourcefn gas_limit(&self) -> u64
fn gas_limit(&self) -> u64
The maximum amount of gas the transaction can use.
Note : Common field for all transactions.
Sourcefn value(&self) -> U256
fn value(&self) -> U256
The value sent to the receiver of TxKind::Call
.
Note : Common field for all transactions.
Sourcefn input(&self) -> &Bytes
fn input(&self) -> &Bytes
Returns the input data of the transaction.
Note : Common field for all transactions.
Sourcefn kind(&self) -> TxKind
fn kind(&self) -> TxKind
Transaction kind. It can be Call or Create.
Kind is applicable for: Legacy, EIP-2930, EIP-1559 And is Call for EIP-4844 and EIP-7702 transactions.
Sourcefn chain_id(&self) -> Option<u64>
fn chain_id(&self) -> Option<u64>
Chain Id is optional for legacy transactions.
As it was introduced in EIP-155.
Sourcefn gas_price(&self) -> u128
fn gas_price(&self) -> u128
Gas price for the transaction. It is only applicable for Legacy and EIP-2930 transactions. For Eip1559 it is max_fee_per_gas.
Sourcefn access_list(&self) -> Option<impl Iterator<Item = Self::AccessListItem<'_>>>
fn access_list(&self) -> Option<impl Iterator<Item = Self::AccessListItem<'_>>>
Access list for the transaction.
Introduced in EIP-2930.
Sourcefn blob_versioned_hashes(&self) -> &[B256] ⓘ
fn blob_versioned_hashes(&self) -> &[B256] ⓘ
Returns vector of fixed size hash(32 bytes)
Note : EIP-4844 transaction field.
Sourcefn max_fee_per_blob_gas(&self) -> u128
fn max_fee_per_blob_gas(&self) -> u128
Max fee per data gas
Note : EIP-4844 transaction field.
List of authorizations, that contains the signature that authorizes this caller to place the code to signer account.
Set EOA account code for one transaction
Sourcefn max_priority_fee_per_gas(&self) -> Option<u128>
fn max_priority_fee_per_gas(&self) -> Option<u128>
Maximum priority fee per gas.
Provided Methods§
Sourcefn total_blob_gas(&self) -> u64
fn total_blob_gas(&self) -> u64
Total gas for all blobs. Max number of blocks is already checked so we dont need to check for overflow.
Sourcefn calc_max_data_fee(&self) -> U256
fn calc_max_data_fee(&self) -> U256
Calculates the maximum [EIP-4844] data_fee
of the transaction.
This is used for ensuring that the user has at least enough funds to pay the
max_fee_per_blob_gas * total_blob_gas
, on top of regular gas costs.
See EIP-4844: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md#execution-layer-validation
Sourcefn max_fee_per_gas(&self) -> u128
fn max_fee_per_gas(&self) -> u128
Returns maximum fee that can be paid for the transaction.
Sourcefn effective_gas_price(&self, base_fee: u128) -> u128
fn effective_gas_price(&self, base_fee: u128) -> u128
Returns effective gas price is gas price field for Legacy and Eip2930 transaction.
While for transactions after Eip1559 it is minimum of max_fee and base + max_priority_fee
.
Sourcefn max_balance_spending(&self) -> Result<U256, InvalidTransaction>
fn max_balance_spending(&self) -> Result<U256, InvalidTransaction>
Returns the maximum balance that can be spent by the transaction.
Return U256 or error if all values overflow U256 number.
Sourcefn ensure_enough_balance(&self, balance: U256) -> Result<(), InvalidTransaction>
fn ensure_enough_balance(&self, balance: U256) -> Result<(), InvalidTransaction>
Checks if the caller has enough balance to cover the maximum balance spending of this transaction.
Internally calls Self::max_balance_spending
and checks if the balance is enough.
Sourcefn effective_balance_spending(
&self,
base_fee: u128,
blob_price: u128,
) -> Result<U256, InvalidTransaction>
fn effective_balance_spending( &self, base_fee: u128, blob_price: u128, ) -> Result<U256, InvalidTransaction>
Returns the effective balance that is going to be spent that depends on base_fee Multiplication for gas are done in u128 type (saturated) and value is added as U256 type.
It is calculated as tx.effective_gas_price * tx.gas_limit + tx.value
. Additionally adding
blob_price * tx.total_blob_gas
blob fee if transaction is EIP-4844.
§Reason
This is done for performance reasons and it is known to be safe as there is no more that u128::MAX value of eth in existence.
This is always strictly less than Self::max_balance_spending
.
Return U256 or error if all values overflow U256 number.
Sourcefn gas_balance_spending(
&self,
base_fee: u128,
blob_price: u128,
) -> Result<U256, InvalidTransaction>
fn gas_balance_spending( &self, base_fee: u128, blob_price: u128, ) -> Result<U256, InvalidTransaction>
Returns the effective balance calculated with Self::effective_balance_spending
but without the value.
Effective balance is always strictly less than Self::max_balance_spending
.
This functions returns tx.effective_gas_price * tx.gas_limit + blob_price * tx.total_blob_gas
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.