pub struct StateAccount<T>(/* private fields */);Expand description
A zero-copy accessor over a settlement state account’s canonical byte
representation: the discriminator byte followed by the current holder of
each Role.
T is the borrow backing it, anything that dereferences to the account’s
bytes: &[u8] grant read access; &mut [u8] grants write access.
Implementations§
Source§impl<T: Deref<Target = [u8]>> StateAccount<T>
impl<T: Deref<Target = [u8]>> StateAccount<T>
Sourcepub fn attach(bytes: T) -> Result<Self, ProgramError>
pub fn attach(bytes: T) -> Result<Self, ProgramError>
Wrap an account’s bytes, checking they begin with the settlement-state discriminator and are at least a full header long. Every accessor relies on that guarantee not to panic.
Current holder of role.
Sourcepub fn solver_search(&self, solver: &Pubkey) -> Result<usize, usize>
pub fn solver_search(&self, solver: &Pubkey) -> Result<usize, usize>
Locate solver in the sorted solver list, mirroring
slice::binary_search: Ok(index) if present, Err(index) with the
slot it would occupy otherwise. The list is sorted by address bytes.
Sourcepub fn solvers(&self) -> impl Iterator<Item = Pubkey> + '_
pub fn solvers(&self) -> impl Iterator<Item = Pubkey> + '_
The stored solvers, in order (sorted ascending by address).
Sourcepub fn grown_len(&self) -> Result<usize, ProgramError>
pub fn grown_len(&self) -> Result<usize, ProgramError>
The account’s data length after growing it by one solver slot: the size
it must be resized to before insert_solver can
fill that new slot.
Returns ProgramError::ArithmeticOverflow if that length overflows
usize, which a caller handling data from a real account can treat as
unreachable: the runtime caps account data at
MAX_PERMITTED_DATA_LENGTH.
Source§impl<'a> StateAccount<Ref<'a, [u8]>>
impl<'a> StateAccount<Ref<'a, [u8]>>
pub fn from_account(account: &'a AccountView) -> Result<Self, ProgramError>
Source§impl<T: DerefMut<Target = [u8]>> StateAccount<T>
impl<T: DerefMut<Target = [u8]>> StateAccount<T>
Sourcepub fn initialize(bytes: T, args: &StateInitArgs) -> Result<Self, ProgramError>
pub fn initialize(bytes: T, args: &StateInitArgs) -> Result<Self, ProgramError>
Stamp a fresh header (discriminator + role holders) into a zeroed account and return the accessor over it.
The generated data is a full header long, which is needed for the read accessors not to panic.
Set role’s holder to new in place.
Sourcepub fn insert_solver(&mut self, solver: &Pubkey) -> Result<(), ProgramError>
pub fn insert_solver(&mut self, solver: &Pubkey) -> Result<(), ProgramError>
Insert solver into the sorted solver list, or fail with
SettlementError::SolverAlreadyExists if it is already stored.
The account must already be grown by one solver slot
(grown_len): the trailing slot is spare capacity
for the new entry, so the live list is every entry but that last one.
The solver is placed in sorted order by shifting all entries and
inserting the new solver in the initial slot.
An error is returned if the solver is already included.