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