Skip to main content

HookState

Struct HookState 

Source
pub struct HookState {
    pub accounts: BTreeMap<Address, Option<FetchedAccount>>,
}
Expand description

A snapshot of the accounts that the hook lists of its mints read. A builder resolves the hook accounts from the snapshot of each mint.

Fill the snapshot with missing: fetch the accounts it returns, insert each one and call it again, until it returns none. A builder reads no account outside the snapshot. An account that the snapshot does not have, such as a PDA of the trader, fails with HookError::NotLoaded, which names the accounts.

A hook armed or changed after the fill makes the transaction fail in simulation. Fill the snapshot again.

Fields§

§accounts: BTreeMap<Address, Option<FetchedAccount>>

Each fetched account: Some where it exists, None where it does not. An address it does not hold was not fetched.

Implementations§

Source§

impl HookState

Source

pub fn insert(&mut self, address: Address, account: Option<FetchedAccount>)

Records what a fetch of address returned: None for no account.

Source

pub fn fetched(&self, address: &Address) -> Fetched<'_>

What the snapshot knows of address.

Source

pub fn missing(&self, mints: &[Address]) -> Result<Vec<Address>, HookError>

The accounts to fetch next for a snapshot of mints: the mints, then each hook’s list, then each account a list reads at a fixed address. Empty when the snapshot holds them all.

An address is fixed when no trade sets it: a fixed key, or a PDA or data key whose inputs are literal seeds, the first 8 bytes of the Execute data (the discriminator), the mint, the validation account and earlier fixed extras. It names no extra that reads the source, the destination or the authority.

A missing mint runs no hook. For a missing list, or a list that no resolver can resolve, it returns no more accounts, and a build fails.

§Errors

HookError::MalformedMint for a mint that does not decode.

Trait Implementations§

Source§

impl Clone for HookState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HookState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HookState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for HookState

Source§

impl PartialEq for HookState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HookState

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.