Skip to content

Commit

Permalink
Merge branch 'main' of github.com:metaplex-foundation/mpl-json into main
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Jan 10, 2024
2 parents 2d89490 + f773fc2 commit fa86853
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 4 deletions.
18 changes: 14 additions & 4 deletions clients/js/src/generated/accounts/inscriptionMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,26 @@ export type InscriptionMetadata = Account<InscriptionMetadataAccountData>;

export type InscriptionMetadataAccountData = {
key: Key;
inscriptionAccount: PublicKey;
bump: number;
dataType: DataType;
inscriptionRank: bigint;
inscriptionBump: Option<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscription>;
padding: Array<number>;
};

export type InscriptionMetadataAccountDataArgs = {
key: KeyArgs;
inscriptionAccount: PublicKey;
bump: number;
dataType: DataTypeArgs;
inscriptionRank: number | bigint;
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscriptionArgs>;
padding: Array<number>;
};

export function getInscriptionMetadataAccountDataSerializer(): Serializer<
Expand All @@ -72,12 +76,14 @@ export function getInscriptionMetadataAccountDataSerializer(): Serializer<
return struct<InscriptionMetadataAccountData>(
[
['key', getKeySerializer()],
['inscriptionAccount', publicKeySerializer()],
['bump', u8()],
['dataType', getDataTypeSerializer()],
['inscriptionRank', u64()],
['inscriptionBump', option(u8())],
['updateAuthorities', array(publicKeySerializer())],
['associatedInscriptions', array(getAssociatedInscriptionSerializer())],
['padding', array(u8(), { size: 8 })],
],
{ description: 'InscriptionMetadataAccountData' }
) as Serializer<
Expand Down Expand Up @@ -163,23 +169,27 @@ export function getInscriptionMetadataGpaBuilder(
return gpaBuilder(context, programId)
.registerFields<{
key: KeyArgs;
inscriptionAccount: PublicKey;
bump: number;
dataType: DataTypeArgs;
inscriptionRank: number | bigint;
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
associatedInscriptions: Array<AssociatedInscriptionArgs>;
padding: Array<number>;
}>({
key: [0, getKeySerializer()],
bump: [1, u8()],
dataType: [2, getDataTypeSerializer()],
inscriptionRank: [3, u64()],
inscriptionBump: [11, option(u8())],
inscriptionAccount: [1, publicKeySerializer()],
bump: [33, u8()],
dataType: [34, getDataTypeSerializer()],
inscriptionRank: [35, u64()],
inscriptionBump: [43, option(u8())],
updateAuthorities: [null, array(publicKeySerializer())],
associatedInscriptions: [
null,
array(getAssociatedInscriptionSerializer()),
],
padding: [null, array(u8(), { size: 8 })],
})
.deserializeUsing<InscriptionMetadata>((account) =>
deserializeInscriptionMetadata(account)
Expand Down
3 changes: 3 additions & 0 deletions clients/js/test/initialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test('it can initialize an Inscription account', async (t) => {

t.like(inscriptionMetadata, <InscriptionMetadata>{
key: Key.InscriptionMetadataAccount,
inscriptionAccount: inscriptionAccount.publicKey,
bump: inscriptionMetadataAccount[1],
dataType: DataType.Uninitialized,
inscriptionRank:
Expand Down Expand Up @@ -111,6 +112,7 @@ test('it can initialize multiple Inscription accounts', async (t) => {

t.like(inscriptionMetadata, <InscriptionMetadata>{
key: Key.InscriptionMetadataAccount,
inscriptionAccount: inscriptionAccount[i].publicKey,
bump: inscriptionMetadataAccount[1],
dataType: DataType.Uninitialized,
inscriptionRank:
Expand Down Expand Up @@ -169,6 +171,7 @@ test('it can initialize an Inscription account with separate authority', async (

t.like(inscriptionMetadata, <InscriptionMetadata>{
key: Key.InscriptionMetadataAccount,
inscriptionAccount: inscriptionAccount.publicKey,
bump: inscriptionMetadataAccount[1],
dataType: DataType.Uninitialized,
inscriptionRank:
Expand Down
2 changes: 2 additions & 0 deletions clients/js/test/initializeFromMint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test('it can initialize a Mint Inscription account', async (t) => {

t.like(inscriptionMetadata, <InscriptionMetadata>{
key: Key.MintInscriptionMetadataAccount,
inscriptionAccount: inscriptionAccount[0],
bump: inscriptionMetadataAccount[1],
dataType: DataType.Uninitialized,
inscriptionRank:
Expand Down Expand Up @@ -200,6 +201,7 @@ test('it can initialize a Mint Inscription account with separate authority', asy

t.like(inscriptionMetadata, <InscriptionMetadata>{
key: Key.MintInscriptionMetadataAccount,
inscriptionAccount: inscriptionAccount[0],
bump: inscriptionMetadataAccount[1],
dataType: DataType.Uninitialized,
inscriptionRank:
Expand Down
6 changes: 6 additions & 0 deletions clients/rust/src/generated/accounts/inscription_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ use solana_program::pubkey::Pubkey;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InscriptionMetadata {
pub key: Key,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub inscription_account: Pubkey,
pub bump: u8,
pub data_type: DataType,
pub inscription_rank: u64,
pub inscription_bump: Option<u8>,
pub update_authorities: Vec<Pubkey>,
pub associated_inscriptions: Vec<AssociatedInscription>,
pub padding: [u8; 8],
}

impl InscriptionMetadata {
Expand Down
13 changes: 13 additions & 0 deletions idls/mpl_inscription.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@
"defined": "Key"
}
},
{
"name": "inscriptionAccount",
"type": "publicKey"
},
{
"name": "bump",
"type": "u8"
Expand Down Expand Up @@ -606,6 +610,15 @@
"defined": "AssociatedInscription"
}
}
},
{
"name": "padding",
"type": {
"array": [
"u8",
8
]
}
}
]
}
Expand Down
1 change: 1 addition & 0 deletions programs/mpl-inscription/src/processor/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub(crate) fn process_initialize<'a>(accounts: &'a [AccountInfo<'a>]) -> Program

// Initialize the inscription metadata.
let mut inscription_metadata = InscriptionMetadata {
inscription_account: *ctx.accounts.inscription_account.key,
bump,
update_authorities: vec![*authority.key],
..InscriptionMetadata::default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ pub(crate) fn process_initialize_associated_inscription<'a>(
&ctx.accounts.inscription_metadata_account.data.borrow(),
)?;

let _metadata_bump = assert_derivation(
&crate::ID,
ctx.accounts.inscription_metadata_account,
&[
PREFIX.as_bytes(),
crate::ID.as_ref(),
inscription_metadata.inscription_account.as_ref(),
],
MplInscriptionError::DerivedKeyInvalid,
)?;

// Verify that the derived address is correct for the metadata account.
let inscription_bump = assert_derivation(
&crate::ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub(crate) fn process_initialize_from_mint<'a>(accounts: &'a [AccountInfo<'a>])
// Initialize the inscription metadata.
let mut inscription_metadata = InscriptionMetadata {
key: Key::MintInscriptionMetadataAccount,
inscription_account: *ctx.accounts.mint_inscription_account.key,
bump,
inscription_bump: Some(inscription_bump),
update_authorities: vec![token_metadata.update_authority],
Expand Down
4 changes: 4 additions & 0 deletions programs/mpl-inscription/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ pub struct AssociatedInscription {
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct InscriptionMetadata {
pub key: Key,
pub inscription_account: Pubkey,
pub bump: u8,
pub data_type: DataType,
pub inscription_rank: u64,
pub inscription_bump: Option<u8>,
pub update_authorities: Vec<Pubkey>,
pub associated_inscriptions: Vec<AssociatedInscription>,
pub _padding: [u8; 8],
}

impl Default for InscriptionMetadata {
fn default() -> Self {
Self {
key: Key::InscriptionMetadataAccount,
inscription_account: Pubkey::default(),
bump: 0,
data_type: DataType::Uninitialized,
inscription_rank: u64::MAX,
inscription_bump: None,
update_authorities: vec![],
associated_inscriptions: vec![],
_padding: [0; 8],
}
}
}
Expand Down

0 comments on commit fa86853

Please sign in to comment.