satrush_client/generated/accounts/
round.rs1use crate::generated::types::RoundState;
9use crate::generated::types::TileStake;
10use borsh::BorshSerialize;
11use borsh::BorshDeserialize;
12
13
14#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
15pub struct Round {
16pub discriminator: [u8; 8],
17pub version: u16,
19pub bump: u8,
21pub id: u32,
23pub state: RoundState,
25pub blockhash_entropy: [u8; 32],
27pub winning_tile: Option<u8>,
29pub deployed_pending_usd_amount: u64,
31pub deployed_usd_amount: u64,
33pub deployed_btc_amount: u64,
35pub deployed_usd_on_winning_tile_amount: u64,
37pub miners_count: u32,
39pub revealed_miners_count: u32,
41pub winners_count: u32,
43pub settled_miners_count: u32,
45pub strike_bonus_usd: u64,
47pub strike_bonus_btc: u64,
49pub public_tile_stakes: [TileStake; 21],
53pub deploy_entropy_acc: [u8; 32],
55pub settled_at_slot: u64,
57pub pending_epoch_fee_usd_amount: u64,
60pub pending_one_btc_fee_usd_amount: u64,
62pub pending_protocol_fee_usd_amount: u64,
64pub reserved: [u8; 40],
66}
67
68
69pub const ROUND_DISCRIMINATOR: [u8; 8] = [87, 127, 165, 51, 73, 78, 116, 174];
70
71impl Round {
72
73
74
75 #[inline(always)]
76 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
77 let mut data = data;
78 Self::deserialize(&mut data)
79 }
80}
81
82impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Round {
83 type Error = std::io::Error;
84
85 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
86 let mut data: &[u8] = &(*account_info.data).borrow();
87 Self::deserialize(&mut data)
88 }
89}
90
91#[cfg(feature = "fetch")]
92pub fn fetch_round(
93 rpc: &solana_rpc_client::rpc_client::RpcClient,
94 address: &solana_address::Address,
95) -> Result<crate::shared::DecodedAccount<Round>, std::io::Error> {
96 let accounts = fetch_all_round(rpc, &[*address])?;
97 Ok(accounts[0].clone())
98}
99
100#[cfg(feature = "fetch")]
101pub fn fetch_all_round(
102 rpc: &solana_rpc_client::rpc_client::RpcClient,
103 addresses: &[solana_address::Address],
104) -> Result<Vec<crate::shared::DecodedAccount<Round>>, std::io::Error> {
105 let accounts = rpc.get_multiple_accounts(addresses)
106 .map_err(|e| std::io::Error::other(e.to_string()))?;
107 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Round>> = Vec::new();
108 for i in 0..addresses.len() {
109 let address = addresses[i];
110 let account = accounts[i].as_ref()
111 .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
112 let data = Round::from_bytes(&account.data)?;
113 decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
114 }
115 Ok(decoded_accounts)
116}
117
118#[cfg(feature = "fetch")]
119pub fn fetch_maybe_round(
120 rpc: &solana_rpc_client::rpc_client::RpcClient,
121 address: &solana_address::Address,
122) -> Result<crate::shared::MaybeAccount<Round>, std::io::Error> {
123 let accounts = fetch_all_maybe_round(rpc, &[*address])?;
124 Ok(accounts[0].clone())
125}
126
127#[cfg(feature = "fetch")]
128pub fn fetch_all_maybe_round(
129 rpc: &solana_rpc_client::rpc_client::RpcClient,
130 addresses: &[solana_address::Address],
131) -> Result<Vec<crate::shared::MaybeAccount<Round>>, std::io::Error> {
132 let accounts = rpc.get_multiple_accounts(addresses)
133 .map_err(|e| std::io::Error::other(e.to_string()))?;
134 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Round>> = Vec::new();
135 for i in 0..addresses.len() {
136 let address = addresses[i];
137 if let Some(account) = accounts[i].as_ref() {
138 let data = Round::from_bytes(&account.data)?;
139 decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
140 } else {
141 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
142 }
143 }
144 Ok(decoded_accounts)
145}
146
147 #[cfg(feature = "anchor")]
148 impl anchor_lang::AccountDeserialize for Round {
149 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
150 Ok(Self::deserialize(buf)?)
151 }
152 }
153
154 #[cfg(feature = "anchor")]
155 impl anchor_lang::AccountSerialize for Round {}
156
157 #[cfg(feature = "anchor")]
158 impl anchor_lang::Owner for Round {
159 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
160 anchor_lang::solana_program::pubkey::Pubkey::from(
161 crate::SATRUSH_ID.to_bytes()
162 )
163 }
164 }
165
166 #[cfg(feature = "anchor-idl-build")]
167 impl anchor_lang::IdlBuild for Round {}
168
169
170 #[cfg(feature = "anchor-idl-build")]
171 impl anchor_lang::Discriminator for Round {
172 const DISCRIMINATOR: &[u8] = &[0; 8];
173 }
174