Skip to main content

HopperAccount

Struct HopperAccount 

Source
pub struct HopperAccount<'a, T>{ /* private fields */ }
Expand description

A layout-bound, owner-validated account.

Wraps a hopper-native AccountView with layout type information. Access the typed data via read() for immutable or write() for mutable.

Validation is performed at construction time:

  • Owner matches program_id
  • Discriminator, version, layout_id match T’s constants
  • Account data size matches T’s expected layout size

Implementations§

Source§

impl<'a, T> HopperAccount<'a, T>

Source

pub fn from_account( account: &'a AccountView, program_id: &'a Address, ) -> Result<HopperAccount<'a, T>, ProgramError>

Construct from an AccountView with full header validation.

Validates: owner == program_id, discriminator, version, layout_id, size.

Source

pub fn from_account_mut( account: &'a AccountView, program_id: &'a Address, ) -> Result<HopperAccount<'a, T>, ProgramError>

Construct from an AccountView that must also be writable.

Source

pub fn read(&self) -> Result<VerifiedAccount<'a, T>, ProgramError>

Read the typed layout overlay (immutable).

Returns a reference to the typed layout struct overlaid on account data.

§Safety

The caller must ensure no conflicting mutable borrows exist on this account’s data. Frame-level borrow tracking handles this in normal usage.

Source

pub fn write(&self) -> Result<VerifiedAccountMut<'a, T>, ProgramError>

Write to the typed layout overlay (mutable).

Returns a mutable reference to the typed layout struct. The account must have been constructed via from_account_mut or the caller must ensure writability.

§Safety

The caller must ensure exclusive access to this account’s data.

Source

pub fn address(&self) -> &Address

The account’s address.

Source

pub unsafe fn owner(&self) -> &Address

The account’s owner.

§Safety

Caller must ensure no conflicting mutable borrows on the account.

Source

pub fn to_account_view(&self) -> &'a AccountView

The underlying AccountView.

Source

pub fn lamports(&self) -> u64

Current lamports on the account.

Auto Trait Implementations§

§

impl<'a, T> Freeze for HopperAccount<'a, T>

§

impl<'a, T> RefUnwindSafe for HopperAccount<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for HopperAccount<'a, T>
where T: Send,

§

impl<'a, T> Sync for HopperAccount<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for HopperAccount<'a, T>
where T: Unpin,

§

impl<'a, T> UnsafeUnpin for HopperAccount<'a, T>

§

impl<'a, T> UnwindSafe for HopperAccount<'a, 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, 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.