Skip to content
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

Add derive to instruction builders #189

Merged
merged 2 commits into from
Mar 28, 2024
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
5 changes: 5 additions & 0 deletions .changeset/dry-jokes-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@metaplex-foundation/kinobi": patch
---

Add derive to Rust instruction builders
2 changes: 2 additions & 0 deletions src/renderers/rust/templates/instructionsCpiPageBuilder.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{% endif %}
{{ '/// ' + loop.index0 + '. `[' + modifiers + ']` ' + account.name | snakeCase }}
{% endfor %}
#[derive(Clone, Debug)]
pub struct {{ instruction.name | pascalCase }}CpiBuilder<'a, 'b> {
instruction: Box<{{ instruction.name | pascalCase }}CpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -124,6 +125,7 @@ impl<'a, 'b> {{ instruction.name | pascalCase }}CpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct {{ instruction.name | pascalCase }}CpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
{% for account in instruction.accounts %}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/rust/templates/instructionsPageBuilder.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{ '/// ' + loop.index0 + '. `[' + modifiers + ']` ' + account.name | snakeCase }}
{{- " (default to `" + account.defaultValue.publicKey + "`)" if account.defaultValue.kind === 'publicKeyValueNode' }}
{% endfor %}
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct {{ instruction.name | pascalCase }}Builder {
{% for account in instruction.accounts %}
{% if account.isSigner === 'either' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct AddConfigLinesInstructionArgs {
///
/// 0. `[writable]` candy_machine
/// 1. `[signer]` authority
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct AddConfigLinesBuilder {
candy_machine: Option<solana_program::pubkey::Pubkey>,
authority: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -264,6 +264,7 @@ impl<'a, 'b> AddConfigLinesCpi<'a, 'b> {
///
/// 0. `[writable]` candy_machine
/// 1. `[signer]` authority
#[derive(Clone, Debug)]
pub struct AddConfigLinesCpiBuilder<'a, 'b> {
instruction: Box<AddConfigLinesCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -384,6 +385,7 @@ impl<'a, 'b> AddConfigLinesCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct AddConfigLinesCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
candy_machine: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
4 changes: 3 additions & 1 deletion test/packages/rust/src/generated/instructions/add_memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct AddMemoInstructionArgs {
///
/// ### Accounts:
///
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct AddMemoBuilder {
memo: Option<String>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
Expand Down Expand Up @@ -187,6 +187,7 @@ impl<'a, 'b> AddMemoCpi<'a, 'b> {
///
/// ### Accounts:
///
#[derive(Clone, Debug)]
pub struct AddMemoCpiBuilder<'a, 'b> {
instruction: Box<AddMemoCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -260,6 +261,7 @@ impl<'a, 'b> AddMemoCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct AddMemoCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
memo: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl ApproveCollectionAuthorityInstructionData {
/// 5. `[]` mint
/// 6. `[optional]` system_program (default to `11111111111111111111111111111111`)
/// 7. `[optional]` rent
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct ApproveCollectionAuthorityBuilder {
collection_authority_record: Option<solana_program::pubkey::Pubkey>,
new_collection_authority: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -410,6 +410,7 @@ impl<'a, 'b> ApproveCollectionAuthorityCpi<'a, 'b> {
/// 5. `[]` mint
/// 6. `[]` system_program
/// 7. `[optional]` rent
#[derive(Clone, Debug)]
pub struct ApproveCollectionAuthorityCpiBuilder<'a, 'b> {
instruction: Box<ApproveCollectionAuthorityCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -576,6 +577,7 @@ impl<'a, 'b> ApproveCollectionAuthorityCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct ApproveCollectionAuthorityCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
collection_authority_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct ApproveUseAuthorityInstructionArgs {
/// 8. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
/// 9. `[optional]` system_program (default to `11111111111111111111111111111111`)
/// 10. `[optional]` rent
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct ApproveUseAuthorityBuilder {
use_authority_record: Option<solana_program::pubkey::Pubkey>,
owner: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -516,6 +516,7 @@ impl<'a, 'b> ApproveUseAuthorityCpi<'a, 'b> {
/// 8. `[]` token_program
/// 9. `[]` system_program
/// 10. `[optional]` rent
#[derive(Clone, Debug)]
pub struct ApproveUseAuthorityCpiBuilder<'a, 'b> {
instruction: Box<ApproveUseAuthorityCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -726,6 +727,7 @@ impl<'a, 'b> ApproveUseAuthorityCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct ApproveUseAuthorityCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
use_authority_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct BubblegumSetCollectionSizeInstructionArgs {
/// 2. `[]` collection_mint
/// 3. `[signer]` bubblegum_signer
/// 4. `[optional]` collection_authority_record
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct BubblegumSetCollectionSizeBuilder {
collection_metadata: Option<solana_program::pubkey::Pubkey>,
collection_authority: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -373,6 +373,7 @@ impl<'a, 'b> BubblegumSetCollectionSizeCpi<'a, 'b> {
/// 2. `[]` collection_mint
/// 3. `[signer]` bubblegum_signer
/// 4. `[optional]` collection_authority_record
#[derive(Clone, Debug)]
pub struct BubblegumSetCollectionSizeCpiBuilder<'a, 'b> {
instruction: Box<BubblegumSetCollectionSizeCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -526,6 +527,7 @@ impl<'a, 'b> BubblegumSetCollectionSizeCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct BubblegumSetCollectionSizeCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
4 changes: 3 additions & 1 deletion test/packages/rust/src/generated/instructions/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub struct BurnInstructionArgs {
/// 6. `[writable, optional]` collection_metadata
/// 7. `[optional]` authorization_rules
/// 8. `[optional]` authorization_rules_program
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct BurnBuilder {
metadata: Option<solana_program::pubkey::Pubkey>,
owner: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -500,6 +500,7 @@ impl<'a, 'b> BurnCpi<'a, 'b> {
/// 6. `[writable, optional]` collection_metadata
/// 7. `[optional]` authorization_rules
/// 8. `[optional]` authorization_rules_program
#[derive(Clone, Debug)]
pub struct BurnCpiBuilder<'a, 'b> {
instruction: Box<BurnCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -691,6 +692,7 @@ impl<'a, 'b> BurnCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct BurnCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl BurnEditionNftInstructionData {
/// 7. `[writable]` print_edition_account
/// 8. `[writable]` edition_marker_account
/// 9. `[optional]` spl_token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct BurnEditionNftBuilder {
metadata: Option<solana_program::pubkey::Pubkey>,
owner: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -469,6 +469,7 @@ impl<'a, 'b> BurnEditionNftCpi<'a, 'b> {
/// 7. `[writable]` print_edition_account
/// 8. `[writable]` edition_marker_account
/// 9. `[]` spl_token_program
#[derive(Clone, Debug)]
pub struct BurnEditionNftCpiBuilder<'a, 'b> {
instruction: Box<BurnEditionNftCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -673,6 +674,7 @@ impl<'a, 'b> BurnEditionNftCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct BurnEditionNftCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
4 changes: 3 additions & 1 deletion test/packages/rust/src/generated/instructions/burn_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl BurnNftInstructionData {
/// 4. `[writable]` master_edition_account
/// 5. `[optional]` spl_token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
/// 6. `[writable, optional]` collection_metadata
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct BurnNftBuilder {
metadata: Option<solana_program::pubkey::Pubkey>,
owner: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -380,6 +380,7 @@ impl<'a, 'b> BurnNftCpi<'a, 'b> {
/// 4. `[writable]` master_edition_account
/// 5. `[]` spl_token_program
/// 6. `[writable, optional]` collection_metadata
#[derive(Clone, Debug)]
pub struct BurnNftCpiBuilder<'a, 'b> {
instruction: Box<BurnNftCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -531,6 +532,7 @@ impl<'a, 'b> BurnNftCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct BurnNftCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl CloseEscrowAccountInstructionData {
/// 5. `[writable, signer]` payer
/// 6. `[optional]` system_program (default to `11111111111111111111111111111111`)
/// 7. `[optional]` sysvar_instructions (default to `Sysvar1nstructions1111111111111111111111111`)
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct CloseEscrowAccountBuilder {
escrow: Option<solana_program::pubkey::Pubkey>,
metadata: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -388,6 +388,7 @@ impl<'a, 'b> CloseEscrowAccountCpi<'a, 'b> {
/// 5. `[writable, signer]` payer
/// 6. `[]` system_program
/// 7. `[]` sysvar_instructions
#[derive(Clone, Debug)]
pub struct CloseEscrowAccountCpiBuilder<'a, 'b> {
instruction: Box<CloseEscrowAccountCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -550,6 +551,7 @@ impl<'a, 'b> CloseEscrowAccountCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct CloseEscrowAccountCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ConvertMasterEditionV1ToV2InstructionData {
/// 0. `[writable]` master_edition
/// 1. `[writable]` one_time_auth
/// 2. `[writable]` printing_mint
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct ConvertMasterEditionV1ToV2Builder {
master_edition: Option<solana_program::pubkey::Pubkey>,
one_time_auth: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -251,6 +251,7 @@ impl<'a, 'b> ConvertMasterEditionV1ToV2Cpi<'a, 'b> {
/// 0. `[writable]` master_edition
/// 1. `[writable]` one_time_auth
/// 2. `[writable]` printing_mint
#[derive(Clone, Debug)]
pub struct ConvertMasterEditionV1ToV2CpiBuilder<'a, 'b> {
instruction: Box<ConvertMasterEditionV1ToV2CpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -359,6 +360,7 @@ impl<'a, 'b> ConvertMasterEditionV1ToV2CpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct ConvertMasterEditionV1ToV2CpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct CreateAccountInstructionArgs {
///
/// 0. `[writable, signer]` payer
/// 1. `[writable, signer]` new_account
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct CreateAccountBuilder {
payer: Option<solana_program::pubkey::Pubkey>,
new_account: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -260,6 +260,7 @@ impl<'a, 'b> CreateAccountCpi<'a, 'b> {
///
/// 0. `[writable, signer]` payer
/// 1. `[writable, signer]` new_account
#[derive(Clone, Debug)]
pub struct CreateAccountCpiBuilder<'a, 'b> {
instruction: Box<CreateAccountCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -377,6 +378,7 @@ impl<'a, 'b> CreateAccountCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct CreateAccountCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl CreateEscrowAccountInstructionData {
/// 6. `[optional]` system_program (default to `11111111111111111111111111111111`)
/// 7. `[optional]` sysvar_instructions (default to `Sysvar1nstructions1111111111111111111111111`)
/// 8. `[signer, optional]` authority
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct CreateEscrowAccountBuilder {
escrow: Option<solana_program::pubkey::Pubkey>,
metadata: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -430,6 +430,7 @@ impl<'a, 'b> CreateEscrowAccountCpi<'a, 'b> {
/// 6. `[]` system_program
/// 7. `[]` sysvar_instructions
/// 8. `[signer, optional]` authority
#[derive(Clone, Debug)]
pub struct CreateEscrowAccountCpiBuilder<'a, 'b> {
instruction: Box<CreateEscrowAccountCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -605,6 +606,7 @@ impl<'a, 'b> CreateEscrowAccountCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct CreateEscrowAccountCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct CreateFrequencyRuleInstructionArgs {
/// 0. `[writable, signer]` payer
/// 1. `[writable]` frequency_pda
/// 2. `[optional]` system_program (default to `11111111111111111111111111111111`)
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct CreateFrequencyRuleBuilder {
payer: Option<solana_program::pubkey::Pubkey>,
frequency_pda: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -310,6 +310,7 @@ impl<'a, 'b> CreateFrequencyRuleCpi<'a, 'b> {
/// 0. `[writable, signer]` payer
/// 1. `[writable]` frequency_pda
/// 2. `[]` system_program
#[derive(Clone, Debug)]
pub struct CreateFrequencyRuleCpiBuilder<'a, 'b> {
instruction: Box<CreateFrequencyRuleCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -455,6 +456,7 @@ impl<'a, 'b> CreateFrequencyRuleCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct CreateFrequencyRuleCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub struct CreateMasterEditionInstructionArgs {
/// 6. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
/// 7. `[optional]` system_program (default to `11111111111111111111111111111111`)
/// 8. `[optional]` rent (default to `SysvarRent111111111111111111111111111111111`)
#[derive(Default)]
#[derive(Clone, Debug, Default)]
pub struct CreateMasterEditionBuilder {
edition: Option<solana_program::pubkey::Pubkey>,
mint: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -450,6 +450,7 @@ impl<'a, 'b> CreateMasterEditionCpi<'a, 'b> {
/// 6. `[]` token_program
/// 7. `[]` system_program
/// 8. `[]` rent
#[derive(Clone, Debug)]
pub struct CreateMasterEditionCpiBuilder<'a, 'b> {
instruction: Box<CreateMasterEditionCpiBuilderInstruction<'a, 'b>>,
}
Expand Down Expand Up @@ -641,6 +642,7 @@ impl<'a, 'b> CreateMasterEditionCpiBuilder<'a, 'b> {
}
}

#[derive(Clone, Debug)]
struct CreateMasterEditionCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
Expand Down
Loading
Loading