Enum clarity::transaction::Transaction
source · pub enum Transaction {
Legacy {
nonce: Uint256,
gas_price: Uint256,
gas_limit: Uint256,
to: Address,
value: Uint256,
data: Vec<u8>,
signature: Option<Signature>,
},
Eip2930 {
access_list: Vec<(Address, Vec<Uint256>)>,
chain_id: Uint256,
signature: Option<Signature>,
nonce: Uint256,
gas_price: Uint256,
gas_limit: Uint256,
to: Address,
value: Uint256,
data: Vec<u8>,
},
Eip1559 {
chain_id: Uint256,
nonce: Uint256,
max_priority_fee_per_gas: Uint256,
max_fee_per_gas: Uint256,
gas_limit: Uint256,
to: Address,
value: Uint256,
data: Vec<u8>,
signature: Option<Signature>,
access_list: Vec<(Address, Vec<Uint256>)>,
},
}
Variants§
Legacy
The original Ethereum transaction format, will always start with a byte >=0xc0
Fields
nonce: Uint256
Replay prevention counter, this must be the last nonce successfully on the chain plus one, multiple tx with incrementing nonces can wait in the mempool but they must execute in order. If you have multiple tx in the pool, one with a lower nonce fails, and is then replaced the following tx will execute immediately
gas_price: Uint256
The price of gas for this transaction, total spend will be price * limit with no refund for actual utilization
gas_limit: Uint256
The maximum amount of gas that can be used by this transaction, total spend will be price * limit with no refund for if the actual utilization is below this value
to: Address
The destination address, this can be a contract or another account, in the contract case the data field will be populated with an encoded contract call
Eip2930
using an access list
Fields
access_list: Vec<(Address, Vec<Uint256>)>
A list of addresses mapped to storage keys access within this range is cheaper in terms of gas for this tx type as an incentive to assist with node optimization
signature: Option<Signature>
The signature, encoded such that the V value is a boolean and does not include an encoded chain id
nonce: Uint256
Replay prevention counter, this must be the last nonce successfully on the chain plus one, multiple tx with incrementing nonces can wait in the mempool but they must execute in order. If you have multiple tx in the pool, one with a lower nonce fails, and is then replaced the following tx will execute immediately
gas_price: Uint256
The price of gas for this transaction, total spend will be price * limit with no refund for actual utilization
gas_limit: Uint256
The maximum amount of gas that can be used by this transaction, total spend will be price * limit with no refund for if the actual utilization is below this value
to: Address
The destination address, this can be a contract or another account, in the contract case the data field will be populated with an encoded contract call
Eip1559
Fields
nonce: Uint256
Replay prevention counter, this must be the last nonce successfully on the chain plus one, multiple tx with incrementing nonces can wait in the mempool but they must execute in order. If you have multiple tx in the pool, one with a lower nonce fails, and is then replaced the following tx will execute immediately
to: Address
The destination address, this can be a contract or another account, in the contract case the data field will be populated with an encoded contract call
Implementations§
source§impl Transaction
impl Transaction
pub fn is_valid(&self) -> bool
pub fn get_signature(&self) -> Option<Signature>
pub fn get_nonce(&self) -> Uint256
pub fn get_data(&self) -> Vec<u8>
pub fn as_data(self) -> Vec<u8>
pub fn data_ref(&self) -> &[u8] ⓘ
pub fn get_to(&self) -> Address
pub fn get_value(&self) -> Uint256
pub fn get_gas_limit(&self) -> Uint256
pub fn set_gas_limit(&mut self, limit: Uint256)
pub fn set_max_fee_per_gas(&mut self, max_fee: Uint256)
pub fn set_max_priority_fee_per_gas(&mut self, max_fee: Uint256)
pub fn set_gas_price(&mut self, new_gas_price: Uint256)
pub fn intrinsic_gas_used(&self) -> Uint256
sourcepub fn sign(&self, key: &PrivateKey, network_id: Option<u64>) -> Transaction
pub fn sign(&self, key: &PrivateKey, network_id: Option<u64>) -> Transaction
Signs the provided transaction, with a legacy format signature if a network_id is provided
WARNING: network_id
MUST be provided for Legacy transactions, or else replay attacks are possible
sourcepub fn sender(&self) -> Result<Address, Error>
pub fn sender(&self) -> Result<Address, Error>
Get the sender’s Address
; derived from the signature
field, does not keep with convention
returns error if the signature is invalid. Traditional return would be constants::NULL_ADDRESS
you may need to insert that yourself after matching on errors
sourcepub fn hash(&self) -> Vec<u8>
pub fn hash(&self) -> Vec<u8>
Creates a hash of a transaction given all TX attributes including signature (VRS) whether it is present, or not.
sourcepub fn to_rlp_bytes(&self) -> Vec<u8>
pub fn to_rlp_bytes(&self) -> Vec<u8>
Generates rlp ethereum encoded byte format of this transaction
sourcepub fn decode_from_rlp(raw_rlp_bytes: &[u8]) -> Result<Self, Error>
pub fn decode_from_rlp(raw_rlp_bytes: &[u8]) -> Result<Self, Error>
Creates a transaction from raw RLP bytes, can not decode unsigned transactions
Trait Implementations§
source§impl Clone for Transaction
impl Clone for Transaction
source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Transaction
impl Debug for Transaction
source§impl Display for Transaction
impl Display for Transaction
source§impl Hash for Transaction
impl Hash for Transaction
source§impl LowerHex for Transaction
impl LowerHex for Transaction
source§impl PartialEq for Transaction
impl PartialEq for Transaction
source§fn eq(&self, other: &Transaction) -> bool
fn eq(&self, other: &Transaction) -> bool
self
and other
values to be equal, and is used
by ==
.