Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function getAdvanceNonceAccountInstruction<
'SysvarRecentB1ockHashes11111111111111111111' as Address<'SysvarRecentB1ockHashes11111111111111111111'>;
}

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.nonceAccount),
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/allocate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function getAllocateInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [getAccountMeta(accounts.newAccount)],
programAddress,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/allocateWithSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function getAllocateWithSeedInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.newAccount),
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function getAssignInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [getAccountMeta(accounts.account)],
programAddress,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/assignWithSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function getAssignWithSeedInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.account),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function getAuthorizeNonceAccountInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.nonceAccount),
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function getCreateAccountInstruction<
0
);

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.payer),
Expand Down
35 changes: 24 additions & 11 deletions clients/js/src/generated/instructions/createAccountWithSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export type CreateAccountWithSeedInstruction<
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
TAccountPayer extends string | AccountMeta<string> = string,
TAccountNewAccount extends string | AccountMeta<string> = string,
TAccountBaseAccount extends string | AccountMeta<string> = string,
TAccountBaseAccount extends
| string
| AccountMeta<string>
| undefined = undefined,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
Expand All @@ -62,10 +65,14 @@ export type CreateAccountWithSeedInstruction<
TAccountNewAccount extends string
? WritableAccount<TAccountNewAccount>
: TAccountNewAccount,
TAccountBaseAccount extends string
? ReadonlySignerAccount<TAccountBaseAccount> &
AccountSignerMeta<TAccountBaseAccount>
: TAccountBaseAccount,
...(TAccountBaseAccount extends undefined
? []
: [
TAccountBaseAccount extends string
? ReadonlySignerAccount<TAccountBaseAccount> &
AccountSignerMeta<TAccountBaseAccount>
: TAccountBaseAccount,
]),
...TRemainingAccounts,
]
>;
Expand Down Expand Up @@ -132,7 +139,7 @@ export type CreateAccountWithSeedInput<
> = {
payer: TransactionSigner<TAccountPayer>;
newAccount: Address<TAccountNewAccount>;
baseAccount: TransactionSigner<TAccountBaseAccount>;
baseAccount?: TransactionSigner<TAccountBaseAccount>;
base: CreateAccountWithSeedInstructionDataArgs['base'];
seed: CreateAccountWithSeedInstructionDataArgs['seed'];
amount: CreateAccountWithSeedInstructionDataArgs['amount'];
Expand Down Expand Up @@ -175,13 +182,13 @@ export function getCreateAccountWithSeedInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.payer),
getAccountMeta(accounts.newAccount),
getAccountMeta(accounts.baseAccount),
],
].filter(<T,>(x: T | undefined): x is T => x !== undefined),
programAddress,
data: getCreateAccountWithSeedInstructionDataEncoder().encode(
args as CreateAccountWithSeedInstructionDataArgs
Expand All @@ -204,7 +211,7 @@ export type ParsedCreateAccountWithSeedInstruction<
accounts: {
payer: TAccountMetas[0];
newAccount: TAccountMetas[1];
baseAccount: TAccountMetas[2];
baseAccount?: TAccountMetas[2] | undefined;
};
data: CreateAccountWithSeedInstructionData;
};
Expand All @@ -217,7 +224,7 @@ export function parseCreateAccountWithSeedInstruction<
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>
): ParsedCreateAccountWithSeedInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 3) {
if (instruction.accounts.length < 2) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -227,12 +234,18 @@ export function parseCreateAccountWithSeedInstruction<
accountIndex += 1;
return accountMeta;
};
let optionalAccountsRemaining = instruction.accounts.length - 2;
const getNextOptionalAccount = () => {
if (optionalAccountsRemaining === 0) return undefined;
optionalAccountsRemaining -= 1;
return getNextAccount();
};
return {
programAddress: instruction.programAddress,
accounts: {
payer: getNextAccount(),
newAccount: getNextAccount(),
baseAccount: getNextAccount(),
baseAccount: getNextOptionalAccount(),
},
data: getCreateAccountWithSeedInstructionDataDecoder().decode(
instruction.data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function getInitializeNonceAccountInstruction<
'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;
}

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.nonceAccount),
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/transferSol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function getTransferSolInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.source),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function getTransferSolWithSeedInstruction<
// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.source),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function getUpgradeNonceAccountInstruction<
ResolvedAccount
>;

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [getAccountMeta(accounts.nonceAccount)],
programAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function getWithdrawNonceAccountInstruction<
'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>;
}

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
const instruction = {
accounts: [
getAccountMeta(accounts.nonceAccount),
Expand Down
54 changes: 31 additions & 23 deletions clients/rust/src/generated/instructions/create_account_with_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct CreateAccountWithSeed {

pub new_account: solana_program::pubkey::Pubkey,

pub base_account: solana_program::pubkey::Pubkey,
pub base_account: Option<solana_program::pubkey::Pubkey>,
}

impl CreateAccountWithSeed {
Expand All @@ -42,10 +42,12 @@ impl CreateAccountWithSeed {
self.new_account,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.base_account,
true,
));
if let Some(base_account) = self.base_account {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
base_account,
true,
));
}
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&CreateAccountWithSeedInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
Expand Down Expand Up @@ -93,7 +95,7 @@ pub struct CreateAccountWithSeedInstructionArgs {
///
/// 0. `[writable, signer]` payer
/// 1. `[writable]` new_account
/// 2. `[signer]` base_account
/// 2. `[signer, optional]` base_account
#[derive(Clone, Debug, Default)]
pub struct CreateAccountWithSeedBuilder {
payer: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -121,9 +123,13 @@ impl CreateAccountWithSeedBuilder {
self.new_account = Some(new_account);
self
}
/// `[optional account]`
#[inline(always)]
pub fn base_account(&mut self, base_account: solana_program::pubkey::Pubkey) -> &mut Self {
self.base_account = Some(base_account);
pub fn base_account(
&mut self,
base_account: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.base_account = base_account;
self
}
#[inline(always)]
Expand Down Expand Up @@ -174,7 +180,7 @@ impl CreateAccountWithSeedBuilder {
let accounts = CreateAccountWithSeed {
payer: self.payer.expect("payer is not set"),
new_account: self.new_account.expect("new_account is not set"),
base_account: self.base_account.expect("base_account is not set"),
base_account: self.base_account,
};
let args = CreateAccountWithSeedInstructionArgs {
base: self.base.clone().expect("base is not set"),
Expand All @@ -197,7 +203,7 @@ pub struct CreateAccountWithSeedCpiAccounts<'a, 'b> {

pub new_account: &'b solana_program::account_info::AccountInfo<'a>,

pub base_account: &'b solana_program::account_info::AccountInfo<'a>,
pub base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
}

/// `create_account_with_seed` CPI instruction.
Expand All @@ -209,7 +215,7 @@ pub struct CreateAccountWithSeedCpi<'a, 'b> {

pub new_account: &'b solana_program::account_info::AccountInfo<'a>,

pub base_account: &'b solana_program::account_info::AccountInfo<'a>,
pub base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
/// The arguments for the instruction.
pub __args: CreateAccountWithSeedInstructionArgs,
}
Expand Down Expand Up @@ -271,10 +277,12 @@ impl<'a, 'b> CreateAccountWithSeedCpi<'a, 'b> {
*self.new_account.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.base_account.key,
true,
));
if let Some(base_account) = self.base_account {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*base_account.key,
true,
));
}
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
Expand All @@ -295,7 +303,9 @@ impl<'a, 'b> CreateAccountWithSeedCpi<'a, 'b> {
account_infos.push(self.__program.clone());
account_infos.push(self.payer.clone());
account_infos.push(self.new_account.clone());
account_infos.push(self.base_account.clone());
if let Some(base_account) = self.base_account {
account_infos.push(base_account.clone());
}
remaining_accounts
.iter()
.for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
Expand All @@ -314,7 +324,7 @@ impl<'a, 'b> CreateAccountWithSeedCpi<'a, 'b> {
///
/// 0. `[writable, signer]` payer
/// 1. `[writable]` new_account
/// 2. `[signer]` base_account
/// 2. `[signer, optional]` base_account
#[derive(Clone, Debug)]
pub struct CreateAccountWithSeedCpiBuilder<'a, 'b> {
instruction: Box<CreateAccountWithSeedCpiBuilderInstruction<'a, 'b>>,
Expand Down Expand Up @@ -349,12 +359,13 @@ impl<'a, 'b> CreateAccountWithSeedCpiBuilder<'a, 'b> {
self.instruction.new_account = Some(new_account);
self
}
/// `[optional account]`
#[inline(always)]
pub fn base_account(
&mut self,
base_account: &'b solana_program::account_info::AccountInfo<'a>,
base_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.base_account = Some(base_account);
self.instruction.base_account = base_account;
self
}
#[inline(always)]
Expand Down Expand Up @@ -444,10 +455,7 @@ impl<'a, 'b> CreateAccountWithSeedCpiBuilder<'a, 'b> {
.new_account
.expect("new_account is not set"),

base_account: self
.instruction
.base_account
.expect("base_account is not set"),
base_account: self.instruction.base_account,
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
Expand Down
Loading
Loading