Overview
TheTransaction struct represents a transaction that can be sent to the Tashi Vertex consensus network. Transactions must be allocated using Transaction::allocate(), populated with data, and then sent via an Engine.
The
Transaction struct is marked with #[must_use], which means the compiler will warn you if you allocate a transaction but don’t send it. This helps prevent resource leaks.Methods
allocate
Allocates a buffer for a transaction of the specified size.The size in bytes of the transaction buffer to allocate
Transaction with an allocated buffer of the specified size.
The transaction buffer is allocated by the Tashi Vertex library and optimized for efficient transmission to the network.
Populating transaction data
TheTransaction struct implements Deref<Target = [u8]> and DerefMut, which means you can treat it as a mutable byte slice:
Sending transactions
Transactions are sent to the network using theEngine::send_transaction() method:
The
Transaction::send() method is internal and not exposed in the public API. Use Engine::send_transaction() instead to send transactions.Complete example
Here’s a complete example showing how to serialize data, allocate a transaction, and send it:Memory management
Transactions use special memory management:
- When allocated, the buffer is managed by the Tashi Vertex library
- When sent via
send_transaction(), ownership is transferred and the buffer is automatically freed - If a transaction is allocated but not sent, it should be freed (note: the current implementation has a TODO to add a
Dropimplementation for this)
Size considerations
When allocating transactions, consider:- Network efficiency: Smaller transactions propagate faster through the network
- Event capacity: Multiple transactions are batched into events
- Serialization overhead: Account for serialization format overhead when calculating size