pub struct Transaction<'a> {
pub blockchain_rid: Vec<u8>,
pub operations: Option<Vec<Operation<'a>>>,
pub signers: Option<Vec<Vec<u8>>>,
pub signatures: Option<Vec<Vec<u8>>>,
}Expand description
Represents a blockchain transaction with operations and signatures.
A transaction contains a list of operations to be executed, along with the necessary signatures to authorize these operations. It supports both single and multi-signature scenarios.
Fields§
§blockchain_rid: Vec<u8>Unique identifier of the blockchain this transaction belongs to
operations: Option<Vec<Operation<'a>>>List of operations to be executed in this transaction
signers: Option<Vec<Vec<u8>>>List of public keys of the signers
signatures: Option<Vec<Vec<u8>>>List of signatures corresponding to the signers
Implementations§
Source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
Sourcepub fn new(
blockchain_rid: Vec<u8>,
operations: Option<Vec<Operation<'a>>>,
signers: Option<Vec<Vec<u8>>>,
signatures: Option<Vec<Vec<u8>>>,
) -> Self
pub fn new( blockchain_rid: Vec<u8>, operations: Option<Vec<Operation<'a>>>, signers: Option<Vec<Vec<u8>>>, signatures: Option<Vec<Vec<u8>>>, ) -> Self
Creates a new transaction with the specified parameters.
§Arguments
blockchain_rid- Unique identifier of the blockchainoperations- Optional list of operations to be executedsigners- Optional list of public keys of the signerssignatures- Optional list of signatures
§Returns
A new Transaction instance
Sourcepub fn gvt_hex_encoded(&self) -> String
pub fn gvt_hex_encoded(&self) -> String
Returns the hex-encoded GTV (Generic Tree Value) representation of the transaction.
This method encodes the transaction into GTV format and returns it as a hexadecimal string.
§Returns
Hex-encoded string of the GTV-encoded transaction
Sourcepub fn tx_rid(&self) -> Result<Vec<u8>, HashError>
pub fn tx_rid(&self) -> Result<Vec<u8>, HashError>
Computes the unique identifier (RID) of this transaction.
The transaction RID is computed by hashing the GTV representation of the transaction using the GTX hash function.
§Returns
Vector of bytes containing the transaction RID
Sourcepub fn tx_rid_hex(&self) -> Result<String, HashError>
pub fn tx_rid_hex(&self) -> Result<String, HashError>
Returns the hex-encoded transaction RID.
This is a convenience method that returns the transaction RID as a hexadecimal string.
§Returns
Hex-encoded string of the transaction RID
Sourcepub fn sign(&mut self, private_key: &[u8; 64]) -> Result<(), Error>
pub fn sign(&mut self, private_key: &[u8; 64]) -> Result<(), Error>
Signs the transaction using a private key.
This method:
- Derives the public key from the private key
- Adds the public key to the signers list
- Signs the transaction RID
- Adds the signature to the signatures list
§Arguments
private_key- 64-byte private key
§Returns
Result indicating success or a secp256k1 error
§Errors
Returns an error if the private key is invalid or signing fails
Sourcepub fn multi_sign(&mut self, private_keys: &[&[u8; 64]]) -> Result<(), Error>
pub fn multi_sign(&mut self, private_keys: &[&[u8; 64]]) -> Result<(), Error>
Signs the transaction with multiple private keys.
This method iteratively signs the transaction with each provided private key, enabling multi-signature transactions.
§Arguments
private_keys- Slice of 64-byte private keys
§Returns
Result indicating success or a secp256k1 error
§Errors
Returns an error if any private key is invalid or signing fails