Skip to content

Commit

Permalink
Adding support for setMint IX for backfilling.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Jan 18, 2024
1 parent 25f3fdf commit b637a9f
Show file tree
Hide file tree
Showing 15 changed files with 813 additions and 6 deletions.
9 changes: 7 additions & 2 deletions clients/js/src/generated/accounts/inscriptionMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type InscriptionMetadataAccountData = {
inscriptionBump: Option<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscription>;
mint: Option<PublicKey>;
padding: Array<number>;
};

Expand All @@ -66,6 +67,7 @@ export type InscriptionMetadataAccountDataArgs = {
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscriptionArgs>;
mint: OptionOrNullable<PublicKey>;
padding: Array<number>;
};

Expand All @@ -83,7 +85,8 @@ export function getInscriptionMetadataAccountDataSerializer(): Serializer<
['inscriptionBump', option(u8())],
['updateAuthorities', array(publicKeySerializer())],
['associatedInscriptions', array(getAssociatedInscriptionSerializer())],
['padding', array(u8(), { size: 8 })],
['mint', option(publicKeySerializer())],
['padding', array(u8(), { size: 7 })],
],
{ description: 'InscriptionMetadataAccountData' }
) as Serializer<
Expand Down Expand Up @@ -176,6 +179,7 @@ export function getInscriptionMetadataGpaBuilder(
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscriptionArgs>;
mint: OptionOrNullable<PublicKey>;
padding: Array<number>;
}>({
key: [0, getKeySerializer()],
Expand All @@ -189,7 +193,8 @@ export function getInscriptionMetadataGpaBuilder(
null,
array(getAssociatedInscriptionSerializer()),
],
padding: [null, array(u8(), { size: 8 })],
mint: [null, option(publicKeySerializer())],
padding: [null, array(u8(), { size: 7 })],
})
.deserializeUsing<InscriptionMetadata>((account) =>
deserializeInscriptionMetadata(account)
Expand Down
36 changes: 36 additions & 0 deletions clients/js/src/generated/errors/mplInscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,42 @@ export class AuthorityAlreadyExistsError extends ProgramError {
codeToErrorMap.set(0x10, AuthorityAlreadyExistsError);
nameToErrorMap.set('AuthorityAlreadyExists', AuthorityAlreadyExistsError);

/** RemainingAssociatedInscriptionAccounts: Cannot close Inscription accounts until all Associated Inscriptions are closed. */
export class RemainingAssociatedInscriptionAccountsError extends ProgramError {
readonly name: string = 'RemainingAssociatedInscriptionAccounts';

readonly code: number = 0x11; // 17

constructor(program: Program, cause?: Error) {
super(
'Cannot close Inscription accounts until all Associated Inscriptions are closed.',
program,
cause
);
}
}
codeToErrorMap.set(0x11, RemainingAssociatedInscriptionAccountsError);
nameToErrorMap.set(
'RemainingAssociatedInscriptionAccounts',
RemainingAssociatedInscriptionAccountsError
);

/** InvalidInscriptionMetadataAccount: The inscription metadata account is invalid. */
export class InvalidInscriptionMetadataAccountError extends ProgramError {
readonly name: string = 'InvalidInscriptionMetadataAccount';

readonly code: number = 0x12; // 18

constructor(program: Program, cause?: Error) {
super('The inscription metadata account is invalid.', program, cause);
}
}
codeToErrorMap.set(0x12, InvalidInscriptionMetadataAccountError);
nameToErrorMap.set(
'InvalidInscriptionMetadataAccount',
InvalidInscriptionMetadataAccountError
);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export * from './close';
export * from './createShard';
export * from './initializeAssociatedInscription';
export * from './removeAuthority';
export * from './setMint';
export * from './writeData';
129 changes: 129 additions & 0 deletions clients/js/src/generated/instructions/setMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
Context,
Pda,
PublicKey,
Signer,
TransactionBuilder,
transactionBuilder,
} from '@metaplex-foundation/umi';
import {
Serializer,
mapSerializer,
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
getAccountMetasAndSigners,
} from '../shared';

// Accounts.
export type SetMintInstructionAccounts = {
/** The account where data is stored. */
mintInscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
/** The mint that will be used to derive the PDA. */
mintAccount: PublicKey | Pda;
/** The account that will pay for the transaction and rent. */
payer?: Signer;
/** System program */
systemProgram?: PublicKey | Pda;
};

// Data.
export type SetMintInstructionData = { discriminator: number };

export type SetMintInstructionDataArgs = {};

export function getSetMintInstructionDataSerializer(): Serializer<
SetMintInstructionDataArgs,
SetMintInstructionData
> {
return mapSerializer<SetMintInstructionDataArgs, any, SetMintInstructionData>(
struct<SetMintInstructionData>([['discriminator', u8()]], {
description: 'SetMintInstructionData',
}),
(value) => ({ ...value, discriminator: 10 })
) as Serializer<SetMintInstructionDataArgs, SetMintInstructionData>;
}

// Instruction.
export function setMint(
context: Pick<Context, 'payer' | 'programs'>,
input: SetMintInstructionAccounts
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
'mplInscription',
'1NSCRfGeyo7wPUazGbaPBUsTM49e1k2aXewHGARfzSo'
);

// Accounts.
const resolvedAccounts: ResolvedAccountsWithIndices = {
mintInscriptionAccount: {
index: 0,
isWritable: false,
value: input.mintInscriptionAccount ?? null,
},
inscriptionMetadataAccount: {
index: 1,
isWritable: true,
value: input.inscriptionMetadataAccount ?? null,
},
mintAccount: {
index: 2,
isWritable: false,
value: input.mintAccount ?? null,
},
payer: { index: 3, isWritable: true, value: input.payer ?? null },
systemProgram: {
index: 4,
isWritable: false,
value: input.systemProgram ?? null,
},
};

// Default values.
if (!resolvedAccounts.payer.value) {
resolvedAccounts.payer.value = context.payer;
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
'splSystem',
'11111111111111111111111111111111'
);
resolvedAccounts.systemProgram.isWritable = false;
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
resolvedAccounts
).sort((a, b) => a.index - b.index);

// Keys and Signers.
const [keys, signers] = getAccountMetasAndSigners(
orderedAccounts,
'programId',
programId
);

// Data.
const data = getSetMintInstructionDataSerializer().serialize({});

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;

return transactionBuilder([
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
]);
}
3 changes: 2 additions & 1 deletion clients/rust/src/generated/accounts/inscription_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub struct InscriptionMetadata {
pub inscription_bump: Option<u8>,
pub update_authorities: Vec<Pubkey>,
pub associated_inscriptions: Vec<AssociatedInscription>,
pub padding: [u8; 8],
pub mint: Option<Pubkey>,
pub padding: [u8; 7],
}

impl InscriptionMetadata {
Expand Down
6 changes: 6 additions & 0 deletions clients/rust/src/generated/errors/mpl_inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ pub enum MplInscriptionError {
/// 16 (0x10) - The authority already exists.
#[error("The authority already exists.")]
AuthorityAlreadyExists,
/// 17 (0x11) - Cannot close Inscription accounts until all Associated Inscriptions are closed.
#[error("Cannot close Inscription accounts until all Associated Inscriptions are closed.")]
RemainingAssociatedInscriptionAccounts,
/// 18 (0x12) - The inscription metadata account is invalid.
#[error("The inscription metadata account is invalid.")]
InvalidInscriptionMetadataAccount,
}

impl solana_program::program_error::PrintProgramError for MplInscriptionError {
Expand Down
2 changes: 2 additions & 0 deletions clients/rust/src/generated/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub(crate) mod initialize;
pub(crate) mod initialize_associated_inscription;
pub(crate) mod initialize_from_mint;
pub(crate) mod remove_authority;
pub(crate) mod set_mint;
pub(crate) mod write_data;

pub use self::add_authority::*;
Expand All @@ -25,4 +26,5 @@ pub use self::initialize::*;
pub use self::initialize_associated_inscription::*;
pub use self::initialize_from_mint::*;
pub use self::remove_authority::*;
pub use self::set_mint::*;
pub use self::write_data::*;
Loading

0 comments on commit b637a9f

Please sign in to comment.