-
Notifications
You must be signed in to change notification settings - Fork 17
Update Codama to 1.2.4 and use Codama CLI #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c7b4940
f7bde49
2773394
80d2c40
e0421c1
f5a599c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,3 +49,73 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Nonce { | |
| 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()))?; | ||
|
Comment on lines
+67
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some RPCs meter the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah good to know. This is something that would needs updating on the Rust renderer (was introduced in this PR). I made an issue for it.
This comment was marked as spam.
Sorry, something went wrong. |
||
| 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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //! This code was AUTOGENERATED using the codama library. | ||
| //! Please DO NOT EDIT THIS FILE, instead use visitors | ||
| //! to add features, then rerun codama to update it. | ||
| //! | ||
| //! <https://github.com/codama-idl/codama> | ||
| //! | ||
|
|
||
| #[cfg(feature = "fetch")] | ||
| #[derive(Debug, Clone)] | ||
| pub struct DecodedAccount<T> { | ||
| pub address: solana_program::pubkey::Pubkey, | ||
| pub account: solana_sdk::account::Account, | ||
| pub data: T, | ||
| } | ||
|
|
||
| #[cfg(feature = "fetch")] | ||
| #[derive(Debug, Clone)] | ||
| pub enum MaybeAccount<T> { | ||
| Exists(DecodedAccount<T>), | ||
| NotFound(solana_program::pubkey::Pubkey), | ||
| } |
lorisleiva marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import path from 'node:path'; | ||
|
|
||
| const { default: prettierOptions } = await import( | ||
| path.resolve('clients', 'js', '.prettierrc.json'), | ||
| { with: { type: 'json' } } | ||
| ); | ||
|
|
||
| export default { | ||
| idl: 'program/idl.json', | ||
| before: [], | ||
| scripts: { | ||
| js: { | ||
| from: '@codama/renderers-js', | ||
| args: ['clients/js/src/generated', { prettierOptions }], | ||
| }, | ||
| rust: { | ||
| from: '@codama/renderers-rust', | ||
| args: [ | ||
| 'clients/rust/src/generated', | ||
| { | ||
| anchorTraits: false, | ||
| crateFolder: 'clients/rust', | ||
| formatCode: true, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we are currently having to use these crates instead of the more granular ones to stay compatible with clients using Solana below 2.1.
We have documented a way forward on the Codama Rust renderer here.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.