Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"homepage": "https://github.com/solana-program/config#readme",
"license": "MIT",
"peerDependencies": {
"@solana/web3.js": "^2.0.0"
"@solana/kit": "^2.1.0"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@solana/eslint-config-solana": "^3.0.3",
"@solana/web3.js": "^2.0.0",
"@solana/kit": "^2.1.0",
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
Expand Down
569 changes: 285 additions & 284 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clients/js/src/generated/accounts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
type MaybeAccount,
type MaybeEncodedAccount,
type ReadonlyUint8Array,
} from '@solana/web3.js';
} from '@solana/kit';
import {
getConfigKeysDecoder,
getConfigKeysEncoder,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
type TransactionSigner,
type WritableAccount,
type WritableSignerAccount,
} from '@solana/web3.js';
} from '@solana/kit';
import { SOLANA_CONFIG_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
import {
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/programs/solanaConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @see https://github.com/codama-idl/codama
*/

import { type Address } from '@solana/web3.js';
import { type Address } from '@solana/kit';
import { type ParsedStoreInstruction } from '../instructions';

export const SOLANA_CONFIG_PROGRAM_ADDRESS =
Expand Down
6 changes: 3 additions & 3 deletions clients/js/src/generated/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import {
AccountRole,
isProgramDerivedAddress,
isTransactionSigner as web3JsIsTransactionSigner,
isTransactionSigner as kitIsTransactionSigner,
type Address,
type IAccountMeta,
type IAccountSignerMeta,
type ProgramDerivedAddress,
type TransactionSigner,
upgradeRoleToSigner,
} from '@solana/web3.js';
} from '@solana/kit';

/**
* Asserts that the given value is not null or undefined.
Expand Down Expand Up @@ -159,6 +159,6 @@ export function isTransactionSigner<TAddress extends string = string>(
!!value &&
typeof value === 'object' &&
'address' in value &&
web3JsIsTransactionSigner(value)
kitIsTransactionSigner(value)
);
}
2 changes: 1 addition & 1 deletion clients/js/src/generated/types/configKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
type Codec,
type Decoder,
type Encoder,
} from '@solana/web3.js';
} from '@solana/kit';

/**
* A collection of keys to be stored in Config account data.
Expand Down
70 changes: 70 additions & 0 deletions clients/rust/src/generated/accounts/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,73 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Config {
Self::deserialize(&mut data)
}
}

#[cfg(feature = "fetch")]
pub fn fetch_config(
rpc: &solana_client::rpc_client::RpcClient,
address: &Pubkey,
) -> Result<crate::shared::DecodedAccount<Config>, std::io::Error> {
let accounts = fetch_all_config(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_config(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<Config>>, 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<Config>> = 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 = Config::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_config(
rpc: &solana_client::rpc_client::RpcClient,
address: &Pubkey,
) -> Result<crate::shared::MaybeAccount<Config>, std::io::Error> {
let accounts = fetch_all_maybe_config(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_config(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[Pubkey],
) -> Result<Vec<crate::shared::MaybeAccount<Config>>, 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<Config>> = Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
if let Some(account) = accounts[i].as_ref() {
let data = Config::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)
}
12 changes: 7 additions & 5 deletions clients/rust/src/generated/instructions/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
};

/// Accounts.
#[derive(Debug)]
pub struct Store {
/// The config account to be modified.
/// Must sign during the first call to `store` to initialize the account,
Expand All @@ -37,8 +38,8 @@ impl Store {
self.config_account.1,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = StoreInstructionData::new().try_to_vec().unwrap();
let mut args = args.try_to_vec().unwrap();
let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);

solana_program::instruction::Instruction {
Expand All @@ -49,7 +50,8 @@ impl Store {
}
}

#[derive(BorshDeserialize, BorshSerialize)]
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StoreInstructionData {}

impl StoreInstructionData {
Expand Down Expand Up @@ -219,8 +221,8 @@ impl<'a, 'b> StoreCpi<'a, 'b> {
is_writable: remaining_account.2,
})
});
let mut data = StoreInstructionData::new().try_to_vec().unwrap();
let mut args = self.__args.try_to_vec().unwrap();
let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);

let instruction = solana_program::instruction::Instruction {
Expand Down
1 change: 1 addition & 0 deletions clients/rust/src/generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub mod accounts;
pub mod errors;
pub mod instructions;
pub mod programs;
pub mod shared;

pub(crate) use programs::*;
20 changes: 20 additions & 0 deletions clients/rust/src/generated/shared.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! 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),
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"template:upgrade": "zx ./scripts/upgrade-template.mjs"
},
"devDependencies": {
"@codama/renderers-js": "^1.0.0",
"@codama/renderers-rust": "^1.0.3",
"@codama/renderers-js": "^1.2.7",
"@codama/renderers-rust": "^1.0.16",
"@iarna/toml": "^2.2.5",
"codama": "^1.0.0",
"codama": "^1.2.8",
"typescript": "^5.5.2",
"zx": "^7.2.3"
},
Expand Down
Loading
Loading