pub struct BorrowedAccount<'a> { /* private fields */ }
Expand description
Shared account borrowed from the TransactionContext and an InstructionContext.
Implementations§
Source§impl BorrowedAccount<'_>
impl BorrowedAccount<'_>
Sourcepub fn transaction_context(&self) -> &TransactionContext
pub fn transaction_context(&self) -> &TransactionContext
Returns the transaction context
Sourcepub fn get_index_in_transaction(&self) -> IndexOfAccount
pub fn get_index_in_transaction(&self) -> IndexOfAccount
Returns the index of this account (transaction wide)
Sourcepub fn set_owner(&mut self, pubkey: &[u8]) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn set_owner(&mut self, pubkey: &[u8]) -> Result<(), InstructionError>
target_os="solana"
only.Assignes the owner of this account (transaction wide)
Sourcepub fn get_lamports(&self) -> u64
pub fn get_lamports(&self) -> u64
Returns the number of lamports of this account (transaction wide)
Sourcepub fn set_lamports(&mut self, lamports: u64) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn set_lamports(&mut self, lamports: u64) -> Result<(), InstructionError>
target_os="solana"
only.Overwrites the number of lamports of this account (transaction wide)
Sourcepub fn checked_add_lamports(
&mut self,
lamports: u64,
) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn checked_add_lamports( &mut self, lamports: u64, ) -> Result<(), InstructionError>
target_os="solana"
only.Adds lamports to this account (transaction wide)
Sourcepub fn checked_sub_lamports(
&mut self,
lamports: u64,
) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn checked_sub_lamports( &mut self, lamports: u64, ) -> Result<(), InstructionError>
target_os="solana"
only.Subtracts lamports from this account (transaction wide)
Sourcepub fn get_data(&self) -> &[u8] ⓘ
pub fn get_data(&self) -> &[u8] ⓘ
Returns a read-only slice of the account data (transaction wide)
Sourcepub fn get_data_mut(&mut self) -> Result<&mut [u8], InstructionError>
Available on non-target_os="solana"
only.
pub fn get_data_mut(&mut self) -> Result<&mut [u8], InstructionError>
target_os="solana"
only.Returns a writable slice of the account data (transaction wide)
Sourcepub fn spare_data_capacity_mut(
&mut self,
) -> Result<&mut [MaybeUninit<u8>], InstructionError>
Available on non-target_os="solana"
only.
pub fn spare_data_capacity_mut( &mut self, ) -> Result<&mut [MaybeUninit<u8>], InstructionError>
target_os="solana"
only.Returns the spare capacity of the vector backing the account data.
This method should only ever be used during CPI, where after a shrinking realloc we want to zero the spare capacity.
Sourcepub fn set_data(&mut self, data: Vec<u8>) -> Result<(), InstructionError>
Available on non-target_os="solana"
and crate feature dev-context-only-utils
only.
pub fn set_data(&mut self, data: Vec<u8>) -> Result<(), InstructionError>
target_os="solana"
and crate feature dev-context-only-utils
only.Overwrites the account data and size (transaction wide).
You should always prefer set_data_from_slice(). Calling this method is currently safe but requires some special casing during CPI when direct account mapping is enabled.
Sourcepub fn set_data_from_slice(
&mut self,
data: &[u8],
) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn set_data_from_slice( &mut self, data: &[u8], ) -> Result<(), InstructionError>
target_os="solana"
only.Overwrites the account data and size (transaction wide).
Call this when you have a slice of data you do not own and want to replace the account data with it.
Sourcepub fn set_data_length(
&mut self,
new_length: usize,
) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn set_data_length( &mut self, new_length: usize, ) -> Result<(), InstructionError>
target_os="solana"
only.Resizes the account data (transaction wide)
Fills it with zeros at the end if is extended or truncates at the end otherwise.
Sourcepub fn extend_from_slice(&mut self, data: &[u8]) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn extend_from_slice(&mut self, data: &[u8]) -> Result<(), InstructionError>
target_os="solana"
only.Appends all elements in a slice to the account
Sourcepub fn reserve(&mut self, additional: usize) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn reserve(&mut self, additional: usize) -> Result<(), InstructionError>
target_os="solana"
only.Reserves capacity for at least additional more elements to be inserted in the given account. Does nothing if capacity is already sufficient.
Sourcepub fn capacity(&self) -> usize
Available on non-target_os="solana"
only.
pub fn capacity(&self) -> usize
target_os="solana"
only.Returns the number of bytes the account can hold without reallocating.
Available on non-target_os="solana"
only.
target_os="solana"
only.Returns whether the underlying AccountSharedData is shared.
The data is shared if the account has been loaded from the accounts database and has never been written to. Writing to an account unshares it.
During account serialization, if an account is shared it’ll get mapped as CoW, else it’ll get mapped directly as writable.
Sourcepub fn get_state<T: DeserializeOwned>(&self) -> Result<T, InstructionError>
Available on non-target_os="solana"
and crate feature bincode
only.
pub fn get_state<T: DeserializeOwned>(&self) -> Result<T, InstructionError>
target_os="solana"
and crate feature bincode
only.Deserializes the account data into a state
Sourcepub fn set_state<T: Serialize>(
&mut self,
state: &T,
) -> Result<(), InstructionError>
Available on non-target_os="solana"
and crate feature bincode
only.
pub fn set_state<T: Serialize>( &mut self, state: &T, ) -> Result<(), InstructionError>
target_os="solana"
and crate feature bincode
only.Serializes a state into the account data
pub fn is_rent_exempt_at_data_length(&self, data_length: usize) -> bool
target_os="solana"
only.Sourcepub fn is_executable(&self) -> bool
👎Deprecated since 2.1.0: Use get_owner
instead
pub fn is_executable(&self) -> bool
get_owner
insteadReturns whether this account is executable (transaction wide)
Sourcepub fn set_executable(
&mut self,
is_executable: bool,
) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn set_executable( &mut self, is_executable: bool, ) -> Result<(), InstructionError>
target_os="solana"
only.Configures whether this account is executable (transaction wide)
Sourcepub fn get_rent_epoch(&self) -> u64
Available on non-target_os="solana"
only.
pub fn get_rent_epoch(&self) -> u64
target_os="solana"
only.Returns the rent epoch of this account (transaction wide)
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Returns whether this account is writable (instruction wide)
Sourcepub fn is_owned_by_current_program(&self) -> bool
pub fn is_owned_by_current_program(&self) -> bool
Returns true if the owner of this account is the current InstructionContext
s last program (instruction wide)
Sourcepub fn can_data_be_changed(&self) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn can_data_be_changed(&self) -> Result<(), InstructionError>
target_os="solana"
only.Returns an error if the account data can not be mutated by the current program
Sourcepub fn can_data_be_resized(
&self,
new_length: usize,
) -> Result<(), InstructionError>
Available on non-target_os="solana"
only.
pub fn can_data_be_resized( &self, new_length: usize, ) -> Result<(), InstructionError>
target_os="solana"
only.Returns an error if the account data can not be resized to the given length