Skip to main content

light_client/indexer/types/
token.rs

1use solana_pubkey::Pubkey;
2
3use super::super::{base58::decode_base58_to_fixed_array, IndexerError};
4
5#[derive(Clone, Default, Debug, PartialEq)]
6pub struct TokenBalance {
7    pub balance: u64,
8    pub mint: Pubkey,
9}
10
11impl TryFrom<&photon_api::types::TokenBalance> for TokenBalance {
12    type Error = IndexerError;
13
14    fn try_from(token_balance: &photon_api::types::TokenBalance) -> Result<Self, Self::Error> {
15        Ok(TokenBalance {
16            balance: *token_balance.balance,
17            mint: Pubkey::new_from_array(decode_base58_to_fixed_array(&token_balance.mint)?),
18        })
19    }
20}
21
22#[derive(Debug, Clone, PartialEq, Default)]
23pub struct OwnerBalance {
24    pub balance: u64,
25    pub owner: Pubkey,
26}
27
28impl TryFrom<&photon_api::types::OwnerBalance> for OwnerBalance {
29    type Error = IndexerError;
30
31    fn try_from(owner_balance: &photon_api::types::OwnerBalance) -> Result<Self, Self::Error> {
32        Ok(OwnerBalance {
33            balance: *owner_balance.balance,
34            owner: Pubkey::new_from_array(decode_base58_to_fixed_array(&owner_balance.owner)?),
35        })
36    }
37}