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 reserved_entropy: [u8; 32],
57pub settled_at_slot: u64,
59pub pending_epoch_fee_usd_amount: u64,
62pub pending_one_btc_fee_usd_amount: u64,
64pub pending_protocol_fee_usd_amount: u64,
66pub is_hashrate_boosted: bool,
72pub pending_affiliate_fee_usd_amount: u64,
78pub pending_buybacks_fee_usd_amount: u64,
82pub reserved: [u8; 23],
84}
85
86
87pub const ROUND_DISCRIMINATOR: [u8; 8] = [87, 127, 165, 51, 73, 78, 116, 174];
88
89impl Round {
90
91
92
93 #[inline(always)]
94 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
95 let mut data = data;
96 Self::deserialize(&mut data)
97 }
98}
99
100impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Round {
101 type Error = std::io::Error;
102
103 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
104 let mut data: &[u8] = &(*account_info.data).borrow();
105 Self::deserialize(&mut data)
106 }
107}
108
109#[cfg(feature = "fetch")]
110pub fn fetch_round(
111 rpc: &solana_rpc_client::rpc_client::RpcClient,
112 address: &solana_address::Address,
113) -> Result<crate::shared::DecodedAccount<Round>, std::io::Error> {
114 let accounts = fetch_all_round(rpc, &[*address])?;
115 Ok(accounts[0].clone())
116}
117
118#[cfg(feature = "fetch")]
119pub fn fetch_all_round(
120 rpc: &solana_rpc_client::rpc_client::RpcClient,
121 addresses: &[solana_address::Address],
122) -> Result<Vec<crate::shared::DecodedAccount<Round>>, std::io::Error> {
123 let accounts = rpc.get_multiple_accounts(addresses)
124 .map_err(|e| std::io::Error::other(e.to_string()))?;
125 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Round>> = Vec::new();
126 for i in 0..addresses.len() {
127 let address = addresses[i];
128 let account = accounts[i].as_ref()
129 .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
130 let data = Round::from_bytes(&account.data)?;
131 decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
132 }
133 Ok(decoded_accounts)
134}
135
136#[cfg(feature = "fetch")]
137pub fn fetch_maybe_round(
138 rpc: &solana_rpc_client::rpc_client::RpcClient,
139 address: &solana_address::Address,
140) -> Result<crate::shared::MaybeAccount<Round>, std::io::Error> {
141 let accounts = fetch_all_maybe_round(rpc, &[*address])?;
142 Ok(accounts[0].clone())
143}
144
145#[cfg(feature = "fetch")]
146pub fn fetch_all_maybe_round(
147 rpc: &solana_rpc_client::rpc_client::RpcClient,
148 addresses: &[solana_address::Address],
149) -> Result<Vec<crate::shared::MaybeAccount<Round>>, std::io::Error> {
150 let accounts = rpc.get_multiple_accounts(addresses)
151 .map_err(|e| std::io::Error::other(e.to_string()))?;
152 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Round>> = Vec::new();
153 for i in 0..addresses.len() {
154 let address = addresses[i];
155 if let Some(account) = accounts[i].as_ref() {
156 let data = Round::from_bytes(&account.data)?;
157 decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
158 } else {
159 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
160 }
161 }
162 Ok(decoded_accounts)
163}
164
165 #[cfg(feature = "anchor")]
166 impl anchor_lang::AccountDeserialize for Round {
167 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
168 Ok(Self::deserialize(buf)?)
169 }
170 }
171
172 #[cfg(feature = "anchor")]
173 impl anchor_lang::AccountSerialize for Round {}
174
175 #[cfg(feature = "anchor")]
176 impl anchor_lang::Owner for Round {
177 fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
178 anchor_lang::solana_program::pubkey::Pubkey::from(
179 crate::SATRUSH_ID.to_bytes()
180 )
181 }
182 }
183
184 #[cfg(feature = "anchor-idl-build")]
185 impl anchor_lang::IdlBuild for Round {}
186
187
188 #[cfg(feature = "anchor-idl-build")]
189 impl anchor_lang::Discriminator for Round {
190 const DISCRIMINATOR: &[u8] = &[0; 8];
191 }
192