pub struct TransactionBuffer<'a, const TXN_LEN: usize> { /* private fields */ }
Expand description
A generic buffer for building a transaction. You can use this struct to build your custom transaction.
Implementations§
Source§impl<'a, const TXN_LEN: usize> TransactionBuffer<'a, TXN_LEN>
impl<'a, const TXN_LEN: usize> TransactionBuffer<'a, TXN_LEN>
Sourcepub fn encode_txn_type(&mut self, tt: TxnType)
pub fn encode_txn_type(&mut self, tt: TxnType)
Encodes a transaction type.
§Example
let mut txn_buffer = ...
txn_buffer.encode_txn_type(TxnType::Payment);
Sourcepub fn encode_u32(&mut self, data: u32, field: u8)
pub fn encode_u32(&mut self, data: u32, field: u8)
Encodes a serialized field value for the first byte, and encodes the u32 data on the rest of the 4 bytes.
Check serialization format to see which field codes are available to be encoded using this method.
§Example
let mut txn_buffer = ...
txn_buffer.encode_u32(c::tfCANONICAL, FieldCode::Flags.into());
Sourcepub fn encode_u32_with_field_id(&mut self, data: u32, field: u8)
pub fn encode_u32_with_field_id(&mut self, data: u32, field: u8)
Encodes a u32 value with a field id. Note that
the firsrt byte is always encoded as 0x20
and the second byte
is always encoded as the field id. The rest of the 4 bytes are encoded
with the u32 data.
Check serialization format to see which field codes are available to be encoded using this method.
§Example
let mut txn_buffer = ...
txn_buffer.encode_u32_with_field_id(1000, FieldCode::Sequence.into());
Sourcepub fn encode_drops(&mut self, drops: u64, amount_type: AmountType)
pub fn encode_drops(&mut self, drops: u64, amount_type: AmountType)
Encodes amount in drops.
§Example
let mut txn_buffer = ...
txn_buffer.encode_drops(12, AmountType::Fee);
Sourcepub fn encode_drops_at(
&mut self,
pos: usize,
drops: u64,
amount_type: AmountType,
)
pub fn encode_drops_at( &mut self, pos: usize, drops: u64, amount_type: AmountType, )
Encodes amount in drops at a specific position.
§Example
let mut txn_buffer = ...
let fee = etxn_fee_base(&txn_buffer);
txn_buffer.encode_drops_at(45, fee, AmountType::Fee);
Sourcepub unsafe fn encode_drops_at_buf_ptr(
uninitialized_buf: *mut MaybeUninit<u8>,
pos: usize,
drops: u64,
amount_type: AmountType,
)
pub unsafe fn encode_drops_at_buf_ptr( uninitialized_buf: *mut MaybeUninit<u8>, pos: usize, drops: u64, amount_type: AmountType, )
Encodes an amount in drops at a specific position of the buffer.
§Safety
pos
must be a valid position in the buffer where the fee should be encoded at.
and the buffer must be initialized up to pos + 9
.
only call this function when you get the fee from etxn_fee_base_from_ptr or etxn_fee_base and want to encode the fee.
§Example
let mut txn_buffer = ...
...
let fee = etxn_fee_base(&txn_buffer);
txn_buffer.encode_drops_at_buf_ptr(unsafe { txn_buffer.as_mut_ptr() }, 45, fee, AmountType::Fee);
Sourcepub fn encode_signing_pubkey_as_null(&mut self)
pub fn encode_signing_pubkey_as_null(&mut self)
Encodes a signing public key as null. For transactions emitted from hooks, the signing public key is always null.
§Example
let mut txn_buffer = ...
txn_buffer.encode_signing_pubkey_as_null();
Sourcepub fn encode_account(
&mut self,
account_id: &AccountId,
account_type: AccountType,
)
pub fn encode_account( &mut self, account_id: &AccountId, account_type: AccountType, )
Encodes an account.
§Example
let mut txn_buffer = ...
txn_buffer.encode_account(&otxn_account, AccountType::Account);