satrush_client/generated/accounts/
public_automation.rs1use 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],
17pub version: u16,
19pub bump: u8,
21pub authority: Address,
24pub strategy: AutomationStrategy,
26pub selection_mask: u32,
29pub reload: bool,
31pub per_round_usd_amount: u64,
34pub remaining_usd_amount: u64,
36pub total_spent_usd_amount: u64,
41pub 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