Struct thor_devkit::transactions::Transaction
source · pub struct Transaction {
pub chain_tag: u8,
pub block_ref: u64,
pub expiration: u32,
pub clauses: Vec<Clause>,
pub gas_price_coef: u8,
pub gas: u64,
pub depends_on: Option<U256>,
pub nonce: u64,
pub reserved: Option<Reserved>,
pub signature: Option<Bytes>,
}Expand description
Represents a single VeChain transaction.
Fields§
§chain_tag: u8Chain tag
block_ref: u64Previous block reference
First 4 bytes (BE) are block height, the rest is part of referred block ID.
expiration: u32Expiration (in blocks)
clauses: Vec<Clause>Vector of clauses
gas_price_coef: u8Coefficient to calculate the gas price.
gas: u64Maximal amount of gas to spend for transaction.
depends_on: Option<U256>Hash of transaction on which current transaction depends.
May be left unspecified if this functionality is not necessary.
nonce: u64Transaction nonce
reserved: Option<Reserved>Reserved fields.
signature: Option<Bytes>Signature. 65 bytes for regular transactions, 130 - for VIP-191.
Ignored when making a signing hash.
For VIP-191 transactions, this would be a simple concatenation of two signatures.
Implementations§
source§impl Transaction
impl Transaction
sourcepub const TRANSACTION_GAS: u64 = 5_000u64
pub const TRANSACTION_GAS: u64 = 5_000u64
Gas cost for whole transaction execution.
sourcepub fn get_signing_hash(&self) -> [u8; 32]
pub fn get_signing_hash(&self) -> [u8; 32]
Get a signing hash for this transaction.
sourcepub fn get_delegate_signing_hash(&self, delegate_for: &Address) -> [u8; 32]
pub fn get_delegate_signing_hash(&self, delegate_for: &Address) -> [u8; 32]
Get a signing hash for this transaction with fee delegation.
VIP-191 <https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md>
sourcepub fn sign(self, private_key: &PrivateKey) -> Self
pub fn sign(self, private_key: &PrivateKey) -> Self
Create a copy of transaction with a signature emplaced.
You can call .encode() on the result to get bytes ready to be sent
over wire.
sourcepub fn with_signature(self, signature: Bytes) -> Result<Self, Error>
pub fn with_signature(self, signature: Bytes) -> Result<Self, Error>
Set a signature for this transaction.
sourcepub fn sign_hash(hash: [u8; 32], private_key: &PrivateKey) -> [u8; 65]
pub fn sign_hash(hash: [u8; 32], private_key: &PrivateKey) -> [u8; 65]
Sign a hash obtained from Transaction::get_signing_hash.
sourcepub fn intrinsic_gas(&self) -> u64
pub fn intrinsic_gas(&self) -> u64
Calculate the intrinsic gas amount required for this transaction.
This amount is always less than actual amount of gas necessary.
More info <https://docs.vechain.org/core-concepts/transactions/transaction-calculation>
sourcepub fn origin(&self) -> Result<Option<PublicKey>, Error>
pub fn origin(&self) -> Result<Option<PublicKey>, Error>
Recover origin public key using the signature.
Returns Ok(None) if signature is unset.
sourcepub fn delegator(&self) -> Result<Option<PublicKey>, Error>
pub fn delegator(&self) -> Result<Option<PublicKey>, Error>
Recover delegator public key using the signature.
Returns Ok(None) if signature is unset or transaction is not delegated.
sourcepub fn is_delegated(&self) -> bool
pub fn is_delegated(&self) -> bool
Check if transaction is VIP-191 delegated.
sourcepub fn id(&self) -> Result<Option<[u8; 32]>, Error>
pub fn id(&self) -> Result<Option<[u8; 32]>, Error>
Calculate transaction ID using the signature.
Returns Ok(None) if signature is unset.
sourcepub fn has_valid_signature(&self) -> bool
pub fn has_valid_signature(&self) -> bool
Check wheter the signature is valid.
sourcepub fn to_broadcastable_bytes(&self) -> Result<Bytes, Error>
pub fn to_broadcastable_bytes(&self) -> Result<Bytes, Error>
Create a binary representation.
Returns Err(secp256k1::Error::IncorrectSignature) if signature is not set.
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<'de> Deserialize<'de> for Transaction
impl<'de> Deserialize<'de> for Transaction
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Encodable for Transaction
impl Encodable 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 ==.source§impl Serialize for Transaction
impl Serialize for Transaction
impl Eq for Transaction
impl StructuralEq for Transaction
impl StructuralPartialEq for Transaction
Auto Trait Implementations§
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.