2023-07-06 09:08:09 -07:00
|
|
|
use {
|
|
|
|
crate::{
|
|
|
|
account_storage::meta::StoredMetaWriteVersion, tiered_storage::meta::TieredAccountMeta,
|
|
|
|
},
|
|
|
|
solana_sdk::{account::ReadableAccount, hash::Hash, pubkey::Pubkey, stake_history::Epoch},
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The struct that offers read APIs for accessing a TieredAccount.
|
|
|
|
#[derive(PartialEq, Eq, Debug)]
|
2023-07-13 23:35:05 -07:00
|
|
|
pub struct TieredReadableAccount<'accounts_file, M: TieredAccountMeta> {
|
2023-07-06 09:08:09 -07:00
|
|
|
/// TieredAccountMeta
|
2023-07-13 23:35:05 -07:00
|
|
|
pub(crate) meta: &'accounts_file M,
|
2023-07-06 09:08:09 -07:00
|
|
|
/// The address of the account
|
2023-07-13 23:35:05 -07:00
|
|
|
pub(crate) address: &'accounts_file Pubkey,
|
2023-07-06 09:08:09 -07:00
|
|
|
/// The address of the account owner
|
2023-07-13 23:35:05 -07:00
|
|
|
pub(crate) owner: &'accounts_file Pubkey,
|
2023-07-06 09:08:09 -07:00
|
|
|
/// The index for accessing the account inside its belonging AccountsFile
|
|
|
|
pub(crate) index: usize,
|
|
|
|
/// The account block that contains this account. Note that this account
|
|
|
|
/// block may be shared with other accounts.
|
2023-07-13 23:35:05 -07:00
|
|
|
pub(crate) account_block: &'accounts_file [u8],
|
2023-07-06 09:08:09 -07:00
|
|
|
}
|
|
|
|
|
2023-07-13 23:35:05 -07:00
|
|
|
impl<'accounts_file, M: TieredAccountMeta> TieredReadableAccount<'accounts_file, M> {
|
2023-07-06 09:08:09 -07:00
|
|
|
/// Returns the address of this account.
|
2023-07-13 23:35:05 -07:00
|
|
|
pub fn address(&self) -> &'accounts_file Pubkey {
|
2023-07-06 09:08:09 -07:00
|
|
|
self.address
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the hash of this account.
|
2023-07-13 23:35:05 -07:00
|
|
|
pub fn hash(&self) -> Option<&'accounts_file Hash> {
|
2023-07-06 09:08:09 -07:00
|
|
|
self.meta.account_hash(self.account_block)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the index to this account in its AccountsFile.
|
|
|
|
pub fn index(&self) -> usize {
|
|
|
|
self.index
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the write version of the account.
|
|
|
|
pub fn write_version(&self) -> Option<StoredMetaWriteVersion> {
|
|
|
|
self.meta.write_version(self.account_block)
|
|
|
|
}
|
2023-07-10 09:33:36 -07:00
|
|
|
|
|
|
|
/// Returns the data associated to this account.
|
2023-07-13 23:35:05 -07:00
|
|
|
pub fn data(&self) -> &'accounts_file [u8] {
|
2023-07-10 09:33:36 -07:00
|
|
|
self.meta.account_data(self.account_block)
|
|
|
|
}
|
2023-07-06 09:08:09 -07:00
|
|
|
}
|
|
|
|
|
2023-07-13 23:35:05 -07:00
|
|
|
impl<'accounts_file, M: TieredAccountMeta> ReadableAccount
|
|
|
|
for TieredReadableAccount<'accounts_file, M>
|
|
|
|
{
|
2023-07-06 09:08:09 -07:00
|
|
|
/// Returns the balance of the lamports of this account.
|
|
|
|
fn lamports(&self) -> u64 {
|
|
|
|
self.meta.lamports()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the address of the owner of this account.
|
2023-07-13 23:35:05 -07:00
|
|
|
fn owner(&self) -> &'accounts_file Pubkey {
|
2023-07-06 09:08:09 -07:00
|
|
|
self.owner
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the data associated to this account is executable.
|
|
|
|
///
|
|
|
|
/// Temporarily unimplemented!() as program runtime v2 will use
|
|
|
|
/// a different API for executable.
|
|
|
|
fn executable(&self) -> bool {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the epoch that this account will next owe rent by parsing
|
|
|
|
/// the specified account block. Epoch::MAX will be returned if the account
|
|
|
|
/// is rent-exempt.
|
|
|
|
fn rent_epoch(&self) -> Epoch {
|
|
|
|
self.meta
|
|
|
|
.rent_epoch(self.account_block)
|
|
|
|
.unwrap_or(Epoch::MAX)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the data associated to this account.
|
2023-07-13 23:35:05 -07:00
|
|
|
fn data(&self) -> &'accounts_file [u8] {
|
2023-07-10 09:33:36 -07:00
|
|
|
self.data()
|
2023-07-06 09:08:09 -07:00
|
|
|
}
|
|
|
|
}
|