Skip to main content

gmsol_sdk/utils/
decode.rs

1use gmsol_decode::{AccountAccess, DecodeError};
2use gmsol_solana_utils::utils::WithSlot;
3use solana_sdk::{account::Account, pubkey::Pubkey};
4
5/// Account with pubkey.
6pub struct KeyedAccount {
7    /// The pubkey of the account.
8    pub pubkey: Pubkey,
9    /// The account data.
10    pub account: WithSlot<Account>,
11}
12
13impl AccountAccess for KeyedAccount {
14    fn owner(&self) -> Result<Pubkey, DecodeError> {
15        Ok(self.account.value().owner)
16    }
17
18    fn pubkey(&self) -> Result<Pubkey, DecodeError> {
19        Ok(self.pubkey)
20    }
21
22    fn lamports(&self) -> Result<u64, DecodeError> {
23        Ok(self.account.value().lamports)
24    }
25
26    fn data(&self) -> Result<&[u8], DecodeError> {
27        Ok(&self.account.value().data)
28    }
29
30    fn slot(&self) -> Result<u64, DecodeError> {
31        Ok(self.account.slot())
32    }
33}