|
@@ -49,3 +49,98 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Nonce {
|
|
|
Self::deserialize(&mut data)
|
|
Self::deserialize(&mut data)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "fetch")]
|
|
|
|
|
+pub fn fetch_nonce(
|
|
|
|
|
+ rpc: &solana_client::rpc_client::RpcClient,
|
|
|
|
|
+ address: &Pubkey,
|
|
|
|
|
+) -> Result<crate::shared::DecodedAccount<Nonce>, std::io::Error> {
|
|
|
|
|
+ let accounts = fetch_all_nonce(rpc, &[*address])?;
|
|
|
|
|
+ Ok(accounts[0].clone())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "fetch")]
|
|
|
|
|
+pub fn fetch_all_nonce(
|
|
|
|
|
+ rpc: &solana_client::rpc_client::RpcClient,
|
|
|
|
|
+ addresses: &[Pubkey],
|
|
|
|
|
+) -> Result<Vec<crate::shared::DecodedAccount<Nonce>>, std::io::Error> {
|
|
|
|
|
+ let accounts = rpc
|
|
|
|
|
+ .get_multiple_accounts(&addresses)
|
|
|
|
|
+ .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
|
|
|
|
+ let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Nonce>> = Vec::new();
|
|
|
|
|
+ for i in 0..addresses.len() {
|
|
|
|
|
+ let address = addresses[i];
|
|
|
|
|
+ let account = accounts[i].as_ref().ok_or(std::io::Error::new(
|
|
|
|
|
+ std::io::ErrorKind::Other,
|
|
|
|
|
+ format!("Account not found: {}", address),
|
|
|
|
|
+ ))?;
|
|
|
|
|
+ let data = Nonce::from_bytes(&account.data)?;
|
|
|
|
|
+ decoded_accounts.push(crate::shared::DecodedAccount {
|
|
|
|
|
+ address,
|
|
|
|
|
+ account: account.clone(),
|
|
|
|
|
+ data,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(decoded_accounts)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "fetch")]
|
|
|
|
|
+pub fn fetch_maybe_nonce(
|
|
|
|
|
+ rpc: &solana_client::rpc_client::RpcClient,
|
|
|
|
|
+ address: &Pubkey,
|
|
|
|
|
+) -> Result<crate::shared::MaybeAccount<Nonce>, std::io::Error> {
|
|
|
|
|
+ let accounts = fetch_all_maybe_nonce(rpc, &[*address])?;
|
|
|
|
|
+ Ok(accounts[0].clone())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "fetch")]
|
|
|
|
|
+pub fn fetch_all_maybe_nonce(
|
|
|
|
|
+ rpc: &solana_client::rpc_client::RpcClient,
|
|
|
|
|
+ addresses: &[Pubkey],
|
|
|
|
|
+) -> Result<Vec<crate::shared::MaybeAccount<Nonce>>, std::io::Error> {
|
|
|
|
|
+ let accounts = rpc
|
|
|
|
|
+ .get_multiple_accounts(&addresses)
|
|
|
|
|
+ .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
|
|
|
|
+ let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Nonce>> = Vec::new();
|
|
|
|
|
+ for i in 0..addresses.len() {
|
|
|
|
|
+ let address = addresses[i];
|
|
|
|
|
+ if let Some(account) = accounts[i].as_ref() {
|
|
|
|
|
+ let data = Nonce::from_bytes(&account.data)?;
|
|
|
|
|
+ decoded_accounts.push(crate::shared::MaybeAccount::Exists(
|
|
|
|
|
+ crate::shared::DecodedAccount {
|
|
|
|
|
+ address,
|
|
|
|
|
+ account: account.clone(),
|
|
|
|
|
+ data,
|
|
|
|
|
+ },
|
|
|
|
|
+ ));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(decoded_accounts)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "anchor")]
|
|
|
|
|
+impl anchor_lang::AccountDeserialize for Nonce {
|
|
|
|
|
+ fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
|
|
|
|
|
+ Ok(Self::deserialize(buf)?)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "anchor")]
|
|
|
|
|
+impl anchor_lang::AccountSerialize for Nonce {}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "anchor")]
|
|
|
|
|
+impl anchor_lang::Owner for Nonce {
|
|
|
|
|
+ fn owner() -> Pubkey {
|
|
|
|
|
+ crate::SYSTEM_ID
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "anchor-idl-build")]
|
|
|
|
|
+impl anchor_lang::IdlBuild for Nonce {}
|
|
|
|
|
+
|
|
|
|
|
+#[cfg(feature = "anchor-idl-build")]
|
|
|
|
|
+impl anchor_lang::Discriminator for Nonce {
|
|
|
|
|
+ const DISCRIMINATOR: [u8; 8] = [0; 8];
|
|
|
|
|
+}
|