Skip to main content

satrush_client/generated/accounts/
public_automation.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use solana_address::Address;
9use crate::generated::types::AutomationStrategy;
10use borsh::BorshSerialize;
11use borsh::BorshDeserialize;
12
13
14#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
15pub struct PublicAutomation {
16pub discriminator: [u8; 8],
17/// Struct version.
18pub version: u16,
19/// PDA bump seed.
20pub bump: u8,
21/// The user the automation plays for; also the `PublicDeployment.authority`
22/// of every deployment it creates.
23pub authority: Address,
24/// Tile-selection strategy.
25pub strategy: AutomationStrategy,
26/// Static: the mask used every round. Random: the initial mask whose
27/// `count_ones()` fixes the generated tile count. Discretionary: 0.
28pub selection_mask: u32,
29/// Whether settled USD winnings reload `remaining_usd_amount`.
30pub reload: bool,
31/// Gross deploy size per round; all fee legs are deducted from it, so it is
32/// exactly what the balance parts with, matching manual deploy semantics.
33pub per_round_usd_amount: u64,
34/// Escrowed funds still available; mirrors the automation's USD ATA.
35pub remaining_usd_amount: u64,
36/// Lifetime gross USD debited by executes. Only executes move it, and each
37/// debits exactly `per_round_usd_amount` (immutable), so rounds played =
38/// `total_spent_usd_amount / per_round_usd_amount` without indexing.
39/// Carved out of `reserved`, so pre-existing accounts read 0.
40pub total_spent_usd_amount: u64,
41/// Reserved.
42pub reserved: [u8; 56],
43}
44
45
46pub const PUBLIC_AUTOMATION_DISCRIMINATOR: [u8; 8] = [16, 128, 211, 70, 213, 109, 108, 216];
47
48impl PublicAutomation {
49      pub const LEN: usize = 129;
50  
51  
52  
53  #[inline(always)]
54  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
55    let mut data = data;
56    Self::deserialize(&mut data)
57  }
58}
59
60impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for PublicAutomation {
61  type Error = std::io::Error;
62
63  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
64      let mut data: &[u8] = &(*account_info.data).borrow();
65      Self::deserialize(&mut data)
66  }
67}
68
69#[cfg(feature = "fetch")]
70pub fn fetch_public_automation(
71  rpc: &solana_rpc_client::rpc_client::RpcClient,
72  address: &solana_address::Address,
73) -> Result<crate::shared::DecodedAccount<PublicAutomation>, std::io::Error> {
74  let accounts = fetch_all_public_automation(rpc, &[*address])?;
75  Ok(accounts[0].clone())
76}
77
78#[cfg(feature = "fetch")]
79pub fn fetch_all_public_automation(
80  rpc: &solana_rpc_client::rpc_client::RpcClient,
81  addresses: &[solana_address::Address],
82) -> Result<Vec<crate::shared::DecodedAccount<PublicAutomation>>, std::io::Error> {
83    let accounts = rpc.get_multiple_accounts(addresses)
84      .map_err(|e| std::io::Error::other(e.to_string()))?;
85    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<PublicAutomation>> = Vec::new();
86    for i in 0..addresses.len() {
87      let address = addresses[i];
88      let account = accounts[i].as_ref()
89        .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
90      let data = PublicAutomation::from_bytes(&account.data)?;
91      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
92    }
93    Ok(decoded_accounts)
94}
95
96#[cfg(feature = "fetch")]
97pub fn fetch_maybe_public_automation(
98  rpc: &solana_rpc_client::rpc_client::RpcClient,
99  address: &solana_address::Address,
100) -> Result<crate::shared::MaybeAccount<PublicAutomation>, std::io::Error> {
101    let accounts = fetch_all_maybe_public_automation(rpc, &[*address])?;
102    Ok(accounts[0].clone())
103}
104
105#[cfg(feature = "fetch")]
106pub fn fetch_all_maybe_public_automation(
107  rpc: &solana_rpc_client::rpc_client::RpcClient,
108  addresses: &[solana_address::Address],
109) -> Result<Vec<crate::shared::MaybeAccount<PublicAutomation>>, std::io::Error> {
110    let accounts = rpc.get_multiple_accounts(addresses)
111      .map_err(|e| std::io::Error::other(e.to_string()))?;
112    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<PublicAutomation>> = Vec::new();
113    for i in 0..addresses.len() {
114      let address = addresses[i];
115      if let Some(account) = accounts[i].as_ref() {
116        let data = PublicAutomation::from_bytes(&account.data)?;
117        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
118      } else {
119        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
120      }
121    }
122  Ok(decoded_accounts)
123}
124
125  #[cfg(feature = "anchor")]
126  impl anchor_lang::AccountDeserialize for PublicAutomation {
127      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
128        Ok(Self::deserialize(buf)?)
129      }
130  }
131
132  #[cfg(feature = "anchor")]
133  impl anchor_lang::AccountSerialize for PublicAutomation {}
134
135  #[cfg(feature = "anchor")]
136  impl anchor_lang::Owner for PublicAutomation {
137      fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
138        anchor_lang::solana_program::pubkey::Pubkey::from(
139          crate::SATRUSH_ID.to_bytes()
140        )
141      }
142  }
143
144  #[cfg(feature = "anchor-idl-build")]
145  impl anchor_lang::IdlBuild for PublicAutomation {}
146
147  
148  #[cfg(feature = "anchor-idl-build")]
149  impl anchor_lang::Discriminator for PublicAutomation {
150    const DISCRIMINATOR: &[u8] = &[0; 8];
151  }
152