Skip to main content

orca_sol/accounts/
lock_config.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 crate::types::LockTypeLabel;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11use solana_pubkey::Pubkey;
12
13#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct LockConfig {
16    pub discriminator: [u8; 8],
17    #[cfg_attr(
18        feature = "serde",
19        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
20    )]
21    pub position: Pubkey,
22    #[cfg_attr(
23        feature = "serde",
24        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
25    )]
26    pub position_owner: Pubkey,
27    #[cfg_attr(
28        feature = "serde",
29        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
30    )]
31    pub whirlpool: Pubkey,
32    pub locked_timestamp: u64,
33    pub lock_type: LockTypeLabel,
34}
35
36impl LockConfig {
37    pub const LEN: usize = 113;
38
39    #[inline(always)]
40    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
41        let mut data = data;
42        Self::deserialize(&mut data)
43    }
44}
45
46impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for LockConfig {
47    type Error = std::io::Error;
48
49    fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
50        let mut data: &[u8] = &(*account_info.data).borrow();
51        Self::deserialize(&mut data)
52    }
53}
54
55#[cfg(feature = "fetch")]
56pub fn fetch_lock_config(
57    rpc: &solana_client::rpc_client::RpcClient,
58    address: &solana_pubkey::Pubkey,
59) -> Result<crate::shared::DecodedAccount<LockConfig>, std::io::Error> {
60    let accounts = fetch_all_lock_config(rpc, &[*address])?;
61    Ok(accounts[0].clone())
62}
63
64#[cfg(feature = "fetch")]
65pub fn fetch_all_lock_config(
66    rpc: &solana_client::rpc_client::RpcClient,
67    addresses: &[solana_pubkey::Pubkey],
68) -> Result<Vec<crate::shared::DecodedAccount<LockConfig>>, std::io::Error> {
69    let accounts = rpc
70        .get_multiple_accounts(addresses)
71        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
72    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<LockConfig>> = Vec::new();
73    for i in 0..addresses.len() {
74        let address = addresses[i];
75        let account = accounts[i].as_ref().ok_or(std::io::Error::new(
76            std::io::ErrorKind::Other,
77            format!("Account not found: {}", address),
78        ))?;
79        let data = LockConfig::from_bytes(&account.data)?;
80        decoded_accounts.push(crate::shared::DecodedAccount {
81            address,
82            account: account.clone(),
83            data,
84        });
85    }
86    Ok(decoded_accounts)
87}
88
89#[cfg(feature = "fetch")]
90pub fn fetch_maybe_lock_config(
91    rpc: &solana_client::rpc_client::RpcClient,
92    address: &solana_pubkey::Pubkey,
93) -> Result<crate::shared::MaybeAccount<LockConfig>, std::io::Error> {
94    let accounts = fetch_all_maybe_lock_config(rpc, &[*address])?;
95    Ok(accounts[0].clone())
96}
97
98#[cfg(feature = "fetch")]
99pub fn fetch_all_maybe_lock_config(
100    rpc: &solana_client::rpc_client::RpcClient,
101    addresses: &[solana_pubkey::Pubkey],
102) -> Result<Vec<crate::shared::MaybeAccount<LockConfig>>, std::io::Error> {
103    let accounts = rpc
104        .get_multiple_accounts(addresses)
105        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
106    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<LockConfig>> = Vec::new();
107    for i in 0..addresses.len() {
108        let address = addresses[i];
109        if let Some(account) = accounts[i].as_ref() {
110            let data = LockConfig::from_bytes(&account.data)?;
111            decoded_accounts.push(crate::shared::MaybeAccount::Exists(
112                crate::shared::DecodedAccount {
113                    address,
114                    account: account.clone(),
115                    data,
116                },
117            ));
118        } else {
119            decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
120        }
121    }
122    Ok(decoded_accounts)
123}
124
125#[cfg(feature = "anchor")]
126impl anchor_lang::AccountDeserialize for LockConfig {
127    fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
128        Ok(Self::deserialize(buf)?)
129    }
130}
131
132#[cfg(feature = "anchor")]
133impl anchor_lang::AccountSerialize for LockConfig {}
134
135#[cfg(feature = "anchor")]
136impl anchor_lang::Owner for LockConfig {
137    fn owner() -> Pubkey {
138        crate::WHIRLPOOL_ID
139    }
140}
141
142#[cfg(feature = "anchor-idl-build")]
143impl anchor_lang::IdlBuild for LockConfig {}
144
145#[cfg(feature = "anchor-idl-build")]
146impl anchor_lang::Discriminator for LockConfig {
147    const DISCRIMINATOR: [u8; 8] = [0; 8];
148}