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: u8
Chain tag
block_ref: u64
Previous block reference
First 4 bytes (BE) are block height, the rest is part of referred block ID.
expiration: u32
Expiration (in blocks)
clauses: Vec<Clause>
Vector of clauses
gas_price_coef: u8
Coefficient to calculate the gas price.
gas: u64
Maximal 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: u64
Transaction 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 or equal to 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 const fn is_delegated(&self) -> bool
pub const 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.
Sourcepub fn build(node: ThorNode) -> TransactionBuilder
pub fn build(node: ThorNode) -> TransactionBuilder
Create a transaction builder.
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§impl Serialize for Transaction
impl Serialize for Transaction
impl Eq for Transaction
impl StructuralPartialEq for Transaction
Auto Trait Implementations§
impl !Freeze for Transaction
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more