Skip to content

Commit c755dfa

Browse files
authored
Update Codama to 1.2.4 and use Codama CLI (#34)
1 parent 6185b40 commit c755dfa

23 files changed

+5167
-1135
lines changed

Cargo.lock

Lines changed: 4517 additions & 884 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/rust/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ readme = "README.md"
88
license-file = "../../LICENSE"
99

1010
[features]
11+
fetch = ["dep:solana-client", "dep:solana-sdk"]
1112
test-sbf = []
1213
serde = ["dep:serde", "dep:serde_with", "kaigan/serde"]
1314

@@ -18,5 +19,7 @@ num-derive = "^0.3"
1819
num-traits = "^0.2"
1920
serde = { version = "^1.0", features = ["derive"], optional = true }
2021
serde_with = { version = "^3.0", optional = true }
22+
solana-client = { version = "^2.1", optional = true }
23+
solana-sdk = { version = "^2.1", optional = true }
2124
solana-program = "^2.1"
2225
thiserror = "^1.0"

clients/rust/src/generated/accounts/nonce.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,73 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Nonce {
4949
Self::deserialize(&mut data)
5050
}
5151
}
52+
53+
#[cfg(feature = "fetch")]
54+
pub fn fetch_nonce(
55+
rpc: &solana_client::rpc_client::RpcClient,
56+
address: &Pubkey,
57+
) -> Result<crate::shared::DecodedAccount<Nonce>, std::io::Error> {
58+
let accounts = fetch_all_nonce(rpc, &[*address])?;
59+
Ok(accounts[0].clone())
60+
}
61+
62+
#[cfg(feature = "fetch")]
63+
pub fn fetch_all_nonce(
64+
rpc: &solana_client::rpc_client::RpcClient,
65+
addresses: &[Pubkey],
66+
) -> Result<Vec<crate::shared::DecodedAccount<Nonce>>, std::io::Error> {
67+
let accounts = rpc
68+
.get_multiple_accounts(&addresses)
69+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
70+
let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Nonce>> = Vec::new();
71+
for i in 0..addresses.len() {
72+
let address = addresses[i];
73+
let account = accounts[i].as_ref().ok_or(std::io::Error::new(
74+
std::io::ErrorKind::Other,
75+
format!("Account not found: {}", address),
76+
))?;
77+
let data = Nonce::from_bytes(&account.data)?;
78+
decoded_accounts.push(crate::shared::DecodedAccount {
79+
address,
80+
account: account.clone(),
81+
data,
82+
});
83+
}
84+
Ok(decoded_accounts)
85+
}
86+
87+
#[cfg(feature = "fetch")]
88+
pub fn fetch_maybe_nonce(
89+
rpc: &solana_client::rpc_client::RpcClient,
90+
address: &Pubkey,
91+
) -> Result<crate::shared::MaybeAccount<Nonce>, std::io::Error> {
92+
let accounts = fetch_all_maybe_nonce(rpc, &[*address])?;
93+
Ok(accounts[0].clone())
94+
}
95+
96+
#[cfg(feature = "fetch")]
97+
pub fn fetch_all_maybe_nonce(
98+
rpc: &solana_client::rpc_client::RpcClient,
99+
addresses: &[Pubkey],
100+
) -> Result<Vec<crate::shared::MaybeAccount<Nonce>>, std::io::Error> {
101+
let accounts = rpc
102+
.get_multiple_accounts(&addresses)
103+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
104+
let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Nonce>> = Vec::new();
105+
for i in 0..addresses.len() {
106+
let address = addresses[i];
107+
if let Some(account) = accounts[i].as_ref() {
108+
let data = Nonce::from_bytes(&account.data)?;
109+
decoded_accounts.push(crate::shared::MaybeAccount::Exists(
110+
crate::shared::DecodedAccount {
111+
address,
112+
account: account.clone(),
113+
data,
114+
},
115+
));
116+
} else {
117+
decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
118+
}
119+
}
120+
Ok(decoded_accounts)
121+
}

clients/rust/src/generated/errors/system.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ impl solana_program::program_error::PrintProgramError for SystemError {
4444
solana_program::msg!(&self.to_string());
4545
}
4646
}
47+
48+
impl<T> solana_program::decode_error::DecodeError<T> for SystemError {
49+
fn type_of() -> &'static str {
50+
"SystemError"
51+
}
52+
}

clients/rust/src/generated/instructions/advance_nonce_account.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use borsh::BorshDeserialize;
99
use borsh::BorshSerialize;
1010

1111
/// Accounts.
12+
#[derive(Debug)]
1213
pub struct AdvanceNonceAccount {
1314
pub nonce_account: solana_program::pubkey::Pubkey,
1415

@@ -52,7 +53,8 @@ impl AdvanceNonceAccount {
5253
}
5354
}
5455

55-
#[derive(BorshDeserialize, BorshSerialize)]
56+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
57+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5658
pub struct AdvanceNonceAccountInstructionData {
5759
discriminator: u32,
5860
}

clients/rust/src/generated/instructions/allocate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use borsh::BorshDeserialize;
99
use borsh::BorshSerialize;
1010

1111
/// Accounts.
12+
#[derive(Debug)]
1213
pub struct Allocate {
1314
pub new_account: solana_program::pubkey::Pubkey,
1415
}
@@ -44,7 +45,8 @@ impl Allocate {
4445
}
4546
}
4647

47-
#[derive(BorshDeserialize, BorshSerialize)]
48+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
49+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4850
pub struct AllocateInstructionData {
4951
discriminator: u32,
5052
}

clients/rust/src/generated/instructions/allocate_with_seed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kaigan::types::U64PrefixString;
1111
use solana_program::pubkey::Pubkey;
1212

1313
/// Accounts.
14+
#[derive(Debug)]
1415
pub struct AllocateWithSeed {
1516
pub new_account: solana_program::pubkey::Pubkey,
1617

@@ -52,7 +53,8 @@ impl AllocateWithSeed {
5253
}
5354
}
5455

55-
#[derive(BorshDeserialize, BorshSerialize)]
56+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
57+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5658
pub struct AllocateWithSeedInstructionData {
5759
discriminator: u32,
5860
}

clients/rust/src/generated/instructions/assign.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use borsh::BorshSerialize;
1010
use solana_program::pubkey::Pubkey;
1111

1212
/// Accounts.
13+
#[derive(Debug)]
1314
pub struct Assign {
1415
pub account: solana_program::pubkey::Pubkey,
1516
}
@@ -45,7 +46,8 @@ impl Assign {
4546
}
4647
}
4748

48-
#[derive(BorshDeserialize, BorshSerialize)]
49+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
50+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4951
pub struct AssignInstructionData {
5052
discriminator: u32,
5153
}

clients/rust/src/generated/instructions/assign_with_seed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kaigan::types::U64PrefixString;
1111
use solana_program::pubkey::Pubkey;
1212

1313
/// Accounts.
14+
#[derive(Debug)]
1415
pub struct AssignWithSeed {
1516
pub account: solana_program::pubkey::Pubkey,
1617

@@ -52,7 +53,8 @@ impl AssignWithSeed {
5253
}
5354
}
5455

55-
#[derive(BorshDeserialize, BorshSerialize)]
56+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
57+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5658
pub struct AssignWithSeedInstructionData {
5759
discriminator: u32,
5860
}

clients/rust/src/generated/instructions/authorize_nonce_account.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use borsh::BorshSerialize;
1010
use solana_program::pubkey::Pubkey;
1111

1212
/// Accounts.
13+
#[derive(Debug)]
1314
pub struct AuthorizeNonceAccount {
1415
pub nonce_account: solana_program::pubkey::Pubkey,
1516

@@ -53,7 +54,8 @@ impl AuthorizeNonceAccount {
5354
}
5455
}
5556

56-
#[derive(BorshDeserialize, BorshSerialize)]
57+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
58+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5759
pub struct AuthorizeNonceAccountInstructionData {
5860
discriminator: u32,
5961
}

0 commit comments

Comments
 (0)