pub struct OrderAccount<T>(/* private fields */);Expand description
A zero-copy accessor over an order account’s canonical byte representation.
T is the borrow backing it, anything that dereferences to the account’s
bytes: &[u8] grants read access; &mut [u8] grants write access.
Implementations§
Source§impl<T: Deref<Target = [u8]>> OrderAccount<T>
impl<T: Deref<Target = [u8]>> OrderAccount<T>
Sourcepub fn attach(bytes: T) -> Result<Self, ProgramError>
pub fn attach(bytes: T) -> Result<Self, ProgramError>
Wrap an account’s bytes, checking they are exactly one order body long
and begin with the order discriminator. Every accessor relies on that
guarantee not to panic.
No further byte validation is performed: the intent may be invalid, or
the intent fail to decode, and attach would still return Ok.
Sourcepub fn bump_slice(&self) -> &[u8; 1]
pub fn bump_slice(&self) -> &[u8; 1]
The canonical bump as a one-byte slice borrowed in place, ready to feed
the PDA seeds. Makes it a bit more efficient to write the PDA seeds
compared to using bump() and recreating the slice.
Sourcepub fn cancelled(&self) -> Result<bool, ProgramError>
pub fn cancelled(&self) -> Result<bool, ProgramError>
Whether the order has been cancelled by its owner. Fails with
ProgramError::InvalidAccountData if the stored byte is out of range.
Sourcepub fn filled_amounts(&self) -> FillAmounts
pub fn filled_amounts(&self) -> FillAmounts
The order’s cumulative fill so far: the sell token withdrawn and the buy token received across settlements.
Sourcepub fn created_by(&self) -> Pubkey
pub fn created_by(&self) -> Pubkey
Account that funded the rent for this PDA; the rent is refunded here when the order is cleared.
Sourcepub fn intent_bytes(&self) -> &[u8; 213]
pub fn intent_bytes(&self) -> &[u8; 213]
The verbatim EncodedOrderIntent bytes stored in the account.
Sourcepub fn intent_uid(&self) -> Hash
pub fn intent_uid(&self) -> Hash
The order UID: the hash of the intent’s canonical bytes. Computed over the stored bytes directly, so no intent decoding is required. It doesn’t check that the underlying intent is valid, though this does not happen for accounts created by the program.
Sourcepub fn check_pda(
&self,
address: &Address,
program_id: &Address,
) -> Result<(), ProgramError>
pub fn check_pda( &self, address: &Address, program_id: &Address, ) -> Result<(), ProgramError>
Confirm the account lives at its own canonical order PDA: both the UID
and the bump feeding the derivation come from the stored body, so an
account planted at the wrong address is rejected. address is the
account this accessor is attached to.
Source§impl<'a> OrderAccount<Ref<'a, [u8]>>
impl<'a> OrderAccount<Ref<'a, [u8]>>
Sourcepub fn load_from_pda(
order_pda: &'a AccountView,
program_id: &Address,
) -> Result<Self, ProgramError>
pub fn load_from_pda( order_pda: &'a AccountView, program_id: &Address, ) -> Result<Self, ProgramError>
Attach to the order at the given PDA and confirm the PDA is derivable from its own data: both the UID and the bump feeding the derivation come from the stored body.
Source§impl<'a> OrderAccount<RefMut<'a, [u8]>>
impl<'a> OrderAccount<RefMut<'a, [u8]>>
Sourcepub fn load_from_pda_mut(
order_pda: &'a mut AccountView,
program_id: &Address,
) -> Result<Self, ProgramError>
pub fn load_from_pda_mut( order_pda: &'a mut AccountView, program_id: &Address, ) -> Result<Self, ProgramError>
Mutable counterpart of OrderAccount::load_from_pda: borrow the order
mutably and confirm it lives at its own canonical PDA before a caller
writes to it.
Source§impl<T: DerefMut<Target = [u8]>> OrderAccount<T>
impl<T: DerefMut<Target = [u8]>> OrderAccount<T>
Sourcepub fn initialize(
bytes: T,
bump: u8,
cancelled: bool,
amount_withdrawn: u64,
amount_received: u64,
created_by: &Pubkey,
encoded_intent: &[u8; 213],
) -> Result<Self, ProgramError>
pub fn initialize( bytes: T, bump: u8, cancelled: bool, amount_withdrawn: u64, amount_received: u64, created_by: &Pubkey, encoded_intent: &[u8; 213], ) -> Result<Self, ProgramError>
Writes a full order body into bytes and return the accessor over it.
encoded_intent is stored verbatim and unvalidated: an order’s PDA is
derived from the hash of these exact bytes, so their canonicality is the
caller’s responsibility.
Fails with ProgramError::AccountDataTooSmall if the buffer isn’t
exactly one order body long.
Sourcepub fn set_amounts(&mut self, amounts: FillAmounts)
pub fn set_amounts(&mut self, amounts: FillAmounts)
Overwrite the two cumulative fill amounts in place.
Sourcepub fn set_cancelled(&mut self)
pub fn set_cancelled(&mut self)
Mark the order cancelled. Idempotent: setting it on an already-cancelled order writes back the same value.