hooks_rs::transaction

Struct TransactionBuffer

Source
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>

Source

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);
Source

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());
Source

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());
Source

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);
Source

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);
Source

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);
Source

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();
Source

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);

Auto Trait Implementations§

§

impl<'a, const TXN_LEN: usize> Freeze for TransactionBuffer<'a, TXN_LEN>

§

impl<'a, const TXN_LEN: usize> RefUnwindSafe for TransactionBuffer<'a, TXN_LEN>

§

impl<'a, const TXN_LEN: usize> Send for TransactionBuffer<'a, TXN_LEN>

§

impl<'a, const TXN_LEN: usize> Sync for TransactionBuffer<'a, TXN_LEN>

§

impl<'a, const TXN_LEN: usize> Unpin for TransactionBuffer<'a, TXN_LEN>

§

impl<'a, const TXN_LEN: usize> !UnwindSafe for TransactionBuffer<'a, TXN_LEN>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.