security_token_client/generated/accounts/
proof.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Proof {
14 pub discriminator: u8,
15 pub bump: u8,
16 pub data: Vec<[u8; 32]>,
17}
18
19impl Proof {
20 #[inline(always)]
21 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
22 let mut data = data;
23 Self::deserialize(&mut data)
24 }
25}
26
27impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Proof {
28 type Error = std::io::Error;
29
30 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
31 let mut data: &[u8] = &(*account_info.data).borrow();
32 Self::deserialize(&mut data)
33 }
34}
35
36#[cfg(feature = "fetch")]
37pub fn fetch_proof(
38 rpc: &solana_client::rpc_client::RpcClient,
39 address: &solana_pubkey::Pubkey,
40) -> Result<crate::shared::DecodedAccount<Proof>, std::io::Error> {
41 let accounts = fetch_all_proof(rpc, &[*address])?;
42 Ok(accounts[0].clone())
43}
44
45#[cfg(feature = "fetch")]
46pub fn fetch_all_proof(
47 rpc: &solana_client::rpc_client::RpcClient,
48 addresses: &[solana_pubkey::Pubkey],
49) -> Result<Vec<crate::shared::DecodedAccount<Proof>>, std::io::Error> {
50 let accounts = rpc
51 .get_multiple_accounts(addresses)
52 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
53 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Proof>> = Vec::new();
54 for i in 0..addresses.len() {
55 let address = addresses[i];
56 let account = accounts[i].as_ref().ok_or(std::io::Error::new(
57 std::io::ErrorKind::Other,
58 format!("Account not found: {}", address),
59 ))?;
60 let data = Proof::from_bytes(&account.data)?;
61 decoded_accounts.push(crate::shared::DecodedAccount {
62 address,
63 account: account.clone(),
64 data,
65 });
66 }
67 Ok(decoded_accounts)
68}
69
70#[cfg(feature = "fetch")]
71pub fn fetch_maybe_proof(
72 rpc: &solana_client::rpc_client::RpcClient,
73 address: &solana_pubkey::Pubkey,
74) -> Result<crate::shared::MaybeAccount<Proof>, std::io::Error> {
75 let accounts = fetch_all_maybe_proof(rpc, &[*address])?;
76 Ok(accounts[0].clone())
77}
78
79#[cfg(feature = "fetch")]
80pub fn fetch_all_maybe_proof(
81 rpc: &solana_client::rpc_client::RpcClient,
82 addresses: &[solana_pubkey::Pubkey],
83) -> Result<Vec<crate::shared::MaybeAccount<Proof>>, std::io::Error> {
84 let accounts = rpc
85 .get_multiple_accounts(addresses)
86 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
87 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Proof>> = Vec::new();
88 for i in 0..addresses.len() {
89 let address = addresses[i];
90 if let Some(account) = accounts[i].as_ref() {
91 let data = Proof::from_bytes(&account.data)?;
92 decoded_accounts.push(crate::shared::MaybeAccount::Exists(
93 crate::shared::DecodedAccount {
94 address,
95 account: account.clone(),
96 data,
97 },
98 ));
99 } else {
100 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
101 }
102 }
103 Ok(decoded_accounts)
104}
105
106#[cfg(feature = "anchor")]
107impl anchor_lang::AccountDeserialize for Proof {
108 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
109 Ok(Self::deserialize(buf)?)
110 }
111}
112
113#[cfg(feature = "anchor")]
114impl anchor_lang::AccountSerialize for Proof {}
115
116#[cfg(feature = "anchor")]
117impl anchor_lang::Owner for Proof {
118 fn owner() -> Pubkey {
119 crate::SECURITY_TOKEN_PROGRAM_ID
120 }
121}
122
123#[cfg(feature = "anchor-idl-build")]
124impl anchor_lang::IdlBuild for Proof {}
125
126#[cfg(feature = "anchor-idl-build")]
127impl anchor_lang::Discriminator for Proof {
128 const DISCRIMINATOR: &[u8] = &[0; 8];
129}