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<[u8; 32], HashError>
pub fn tx_rid(&self) -> Result<[u8; 32], 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
A fixed-size 32 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 multi_sign_from_raw_priv_keys(
&mut self,
private_keys: &[&str],
) -> Result<(), Error>
pub fn multi_sign_from_raw_priv_keys( &mut self, private_keys: &[&str], ) -> Result<(), Error>
Signs the transaction with multiple raw private key strings.
This method iteratively signs the transaction with each provided private key string, enabling multi-signature transactions.
§Arguments
private_keys- Slice of raw private key strings
§Returns
Result indicating success or a secp256k1 error
§Errors
Returns an error if any private key is invalid or signing fails
Sourcepub fn sign(&mut self, private_key: &[u8; 32]) -> Result<(), Error>
pub fn sign(&mut self, private_key: &[u8; 32]) -> 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- 32-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; 32]]) -> Result<(), Error>
pub fn multi_sign(&mut self, private_keys: &[&[u8; 32]]) -> 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 32-byte private keys
§Returns
Result indicating success or a secp256k1 error
§Errors
Returns an error if any private key is invalid or signing fails