pub trait SVMRentCollector {
// Required methods
fn collect_rent(
&self,
address: &Pubkey,
account: &mut AccountSharedData,
) -> CollectedInfo;
fn get_rent(&self) -> &Rent;
fn get_rent_due(
&self,
lamports: u64,
data_len: usize,
account_rent_epoch: Epoch,
) -> RentDue;
// Provided methods
fn check_rent_state(
&self,
pre_rent_state: Option<&RentState>,
post_rent_state: Option<&RentState>,
transaction_context: &TransactionContext,
index: IndexOfAccount,
) -> Result<()> { ... }
fn check_rent_state_with_account(
&self,
pre_rent_state: &RentState,
post_rent_state: &RentState,
address: &Pubkey,
_account_state: &AccountSharedData,
account_index: IndexOfAccount,
) -> Result<()> { ... }
fn get_account_rent_state(&self, account: &AccountSharedData) -> RentState { ... }
fn transition_allowed(
&self,
pre_rent_state: &RentState,
post_rent_state: &RentState,
) -> bool { ... }
}
Expand description
Rent collector trait. Represents an entity that can evaluate the rent state of an account, determine rent due, and collect rent.
Implementors are responsible for evaluating rent due and collecting rent from accounts, if required. Methods for evaluating account rent state have default implementations, which can be overridden for customized rent management.
Required Methods§
Sourcefn collect_rent(
&self,
address: &Pubkey,
account: &mut AccountSharedData,
) -> CollectedInfo
fn collect_rent( &self, address: &Pubkey, account: &mut AccountSharedData, ) -> CollectedInfo
Collect rent from an account.
Provided Methods§
Sourcefn check_rent_state(
&self,
pre_rent_state: Option<&RentState>,
post_rent_state: Option<&RentState>,
transaction_context: &TransactionContext,
index: IndexOfAccount,
) -> Result<()>
fn check_rent_state( &self, pre_rent_state: Option<&RentState>, post_rent_state: Option<&RentState>, transaction_context: &TransactionContext, index: IndexOfAccount, ) -> Result<()>
Check rent state transition for an account in a transaction.
This method has a default implementation that calls into
check_rent_state_with_account
.
Sourcefn check_rent_state_with_account(
&self,
pre_rent_state: &RentState,
post_rent_state: &RentState,
address: &Pubkey,
_account_state: &AccountSharedData,
account_index: IndexOfAccount,
) -> Result<()>
fn check_rent_state_with_account( &self, pre_rent_state: &RentState, post_rent_state: &RentState, address: &Pubkey, _account_state: &AccountSharedData, account_index: IndexOfAccount, ) -> Result<()>
Check rent state transition for an account directly.
This method has a default implementation that checks whether the transition is allowed and returns an error if it is not. It also verifies that the account is not the incinerator.
Sourcefn get_account_rent_state(&self, account: &AccountSharedData) -> RentState
fn get_account_rent_state(&self, account: &AccountSharedData) -> RentState
Determine the rent state of an account.
This method has a default implementation that treats accounts with zero
lamports as uninitialized and uses the implemented get_rent
to
determine whether an account is rent-exempt.
Sourcefn transition_allowed(
&self,
pre_rent_state: &RentState,
post_rent_state: &RentState,
) -> bool
fn transition_allowed( &self, pre_rent_state: &RentState, post_rent_state: &RentState, ) -> bool
Check whether a transition from the pre_rent_state to the post_rent_state is valid.
This method has a default implementation that allows transitions from
any state to RentState::Uninitialized
or RentState::RentExempt
.
Pre-state RentState::RentPaying
can only transition to
RentState::RentPaying
if the data size remains the same and the
account is not credited.