Skip to content

Commit 3d8e19a

Browse files
authored
Bump Codama to 1.2.8 and use @solana/kit (#38)
1 parent bf7002f commit 3d8e19a

File tree

13 files changed

+790
-409
lines changed

13 files changed

+790
-409
lines changed

clients/js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
"homepage": "https://github.com/solana-program/config#readme",
4343
"license": "MIT",
4444
"peerDependencies": {
45-
"@solana/web3.js": "^2.0.0"
45+
"@solana/kit": "^2.1.0"
4646
},
4747
"devDependencies": {
4848
"@ava/typescript": "^4.1.0",
4949
"@solana/eslint-config-solana": "^3.0.3",
50-
"@solana/web3.js": "^2.0.0",
50+
"@solana/kit": "^2.1.0",
5151
"@types/node": "^20",
5252
"@typescript-eslint/eslint-plugin": "^7.16.1",
5353
"@typescript-eslint/parser": "^7.16.1",

clients/js/pnpm-lock.yaml

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

clients/js/src/generated/accounts/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
type MaybeAccount,
2929
type MaybeEncodedAccount,
3030
type ReadonlyUint8Array,
31-
} from '@solana/web3.js';
31+
} from '@solana/kit';
3232
import {
3333
getConfigKeysDecoder,
3434
getConfigKeysEncoder,

clients/js/src/generated/instructions/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
type TransactionSigner,
2727
type WritableAccount,
2828
type WritableSignerAccount,
29-
} from '@solana/web3.js';
29+
} from '@solana/kit';
3030
import { SOLANA_CONFIG_PROGRAM_ADDRESS } from '../programs';
3131
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
3232
import {

clients/js/src/generated/programs/solanaConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @see https://github.com/codama-idl/codama
77
*/
88

9-
import { type Address } from '@solana/web3.js';
9+
import { type Address } from '@solana/kit';
1010
import { type ParsedStoreInstruction } from '../instructions';
1111

1212
export const SOLANA_CONFIG_PROGRAM_ADDRESS =

clients/js/src/generated/shared/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import {
1010
AccountRole,
1111
isProgramDerivedAddress,
12-
isTransactionSigner as web3JsIsTransactionSigner,
12+
isTransactionSigner as kitIsTransactionSigner,
1313
type Address,
1414
type IAccountMeta,
1515
type IAccountSignerMeta,
1616
type ProgramDerivedAddress,
1717
type TransactionSigner,
1818
upgradeRoleToSigner,
19-
} from '@solana/web3.js';
19+
} from '@solana/kit';
2020

2121
/**
2222
* Asserts that the given value is not null or undefined.
@@ -159,6 +159,6 @@ export function isTransactionSigner<TAddress extends string = string>(
159159
!!value &&
160160
typeof value === 'object' &&
161161
'address' in value &&
162-
web3JsIsTransactionSigner(value)
162+
kitIsTransactionSigner(value)
163163
);
164164
}

clients/js/src/generated/types/configKeys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
type Codec,
2323
type Decoder,
2424
type Encoder,
25-
} from '@solana/web3.js';
25+
} from '@solana/kit';
2626

2727
/**
2828
* A collection of keys to be stored in Config account data.

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

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

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use {
1111
};
1212

1313
/// Accounts.
14+
#[derive(Debug)]
1415
pub struct Store {
1516
/// The config account to be modified.
1617
/// Must sign during the first call to `store` to initialize the account,
@@ -37,8 +38,8 @@ impl Store {
3738
self.config_account.1,
3839
));
3940
accounts.extend_from_slice(remaining_accounts);
40-
let mut data = StoreInstructionData::new().try_to_vec().unwrap();
41-
let mut args = args.try_to_vec().unwrap();
41+
let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
42+
let mut args = borsh::to_vec(&args).unwrap();
4243
data.append(&mut args);
4344

4445
solana_program::instruction::Instruction {
@@ -49,7 +50,8 @@ impl Store {
4950
}
5051
}
5152

52-
#[derive(BorshDeserialize, BorshSerialize)]
53+
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
54+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5355
pub struct StoreInstructionData {}
5456

5557
impl StoreInstructionData {
@@ -219,8 +221,8 @@ impl<'a, 'b> StoreCpi<'a, 'b> {
219221
is_writable: remaining_account.2,
220222
})
221223
});
222-
let mut data = StoreInstructionData::new().try_to_vec().unwrap();
223-
let mut args = self.__args.try_to_vec().unwrap();
224+
let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
225+
let mut args = borsh::to_vec(&self.__args).unwrap();
224226
data.append(&mut args);
225227

226228
let instruction = solana_program::instruction::Instruction {

clients/rust/src/generated/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ pub mod accounts;
88
pub mod errors;
99
pub mod instructions;
1010
pub mod programs;
11+
pub mod shared;
1112

1213
pub(crate) use programs::*;

0 commit comments

Comments
 (0)