Skip to main content

OrderAccount

Struct OrderAccount 

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

Source

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.

Source

pub fn bump(&self) -> u8

Canonical bump of the PDA this account lives at.

Source

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.

Source

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.

Source

pub fn filled_amounts(&self) -> FillAmounts

The order’s cumulative fill so far: the sell token withdrawn and the buy token received across settlements.

Source

pub fn created_by(&self) -> Pubkey

Account that funded the rent for this PDA; the rent is refunded here when the order is cleared.

Source

pub fn intent_bytes(&self) -> &[u8; 213]

The verbatim EncodedOrderIntent bytes stored in the account.

Source

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.

Source

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

Source

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

Source

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>

Source

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.

Source

pub fn set_amounts(&mut self, amounts: FillAmounts)

Overwrite the two cumulative fill amounts in place.

Source

pub fn set_cancelled(&mut self)

Mark the order cancelled. Idempotent: setting it on an already-cancelled order writes back the same value.

Auto Trait Implementations§

§

impl<T> Freeze for OrderAccount<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for OrderAccount<T>
where T: RefUnwindSafe,

§

impl<T> Send for OrderAccount<T>
where T: Send,

§

impl<T> Sync for OrderAccount<T>
where T: Sync,

§

impl<T> Unpin for OrderAccount<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for OrderAccount<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for OrderAccount<T>
where T: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.