Skip to content

Commit

Permalink
Merge pull request #6 from metaplex-foundation/fix/assocationed-inscr…
Browse files Browse the repository at this point in the history
…iption

Adding inscription account to context
  • Loading branch information
blockiosaurus authored Jan 15, 2024
2 parents c3eb964 + 68ecd4d commit 92363fd
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 103 deletions.
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metaplex-foundation/mpl-inscription",
"version": "0.7.0",
"version": "0.8.0",
"description": "A simple program for inscribing bytes on chain.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
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 @@ -33,7 +33,7 @@ import {

// Accounts.
export type AllocateInstructionAccounts = {
/** The account to store the metadata in. */
/** The account where data is stored. */
inscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/clearData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {

// Accounts.
export type ClearDataInstructionAccounts = {
/** The account to store the metadata in. */
/** The account where data is stored. */
inscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {

// Accounts.
export type CloseInstructionAccounts = {
/** The account to store the metadata in. */
/** The account where data is stored. */
inscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

// Accounts.
export type InitializeInstructionAccounts = {
/** The account to store the metadata in. */
/** The account where data is stored. */
inscriptionAccount: Signer;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount?: PublicKey | Pda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import { findAssociatedInscriptionAccountPda } from '../accounts';
import {
findAssociatedInscriptionAccountPda,
findInscriptionMetadataPda,
} from '../accounts';
import {
ResolvedAccount,
ResolvedAccountsWithIndices,
Expand All @@ -32,8 +35,10 @@ import {

// Accounts.
export type InitializeAssociatedInscriptionInstructionAccounts = {
/** The account where data is stored. */
inscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
inscriptionMetadataAccount?: PublicKey | Pda;
/** The account to create and store the new associated data in. */
associatedInscriptionAccount?: PublicKey | Pda;
/** The account that will pay for the transaction and rent. */
Expand Down Expand Up @@ -95,20 +100,25 @@ export function initializeAssociatedInscription(

// Accounts.
const resolvedAccounts: ResolvedAccountsWithIndices = {
inscriptionMetadataAccount: {
inscriptionAccount: {
index: 0,
isWritable: false,
value: input.inscriptionAccount ?? null,
},
inscriptionMetadataAccount: {
index: 1,
isWritable: true,
value: input.inscriptionMetadataAccount ?? null,
},
associatedInscriptionAccount: {
index: 1,
index: 2,
isWritable: true,
value: input.associatedInscriptionAccount ?? null,
},
payer: { index: 2, isWritable: true, value: input.payer ?? null },
authority: { index: 3, isWritable: false, value: input.authority ?? null },
payer: { index: 3, isWritable: true, value: input.payer ?? null },
authority: { index: 4, isWritable: false, value: input.authority ?? null },
systemProgram: {
index: 4,
index: 5,
isWritable: false,
value: input.systemProgram ?? null,
},
Expand All @@ -120,6 +130,14 @@ export function initializeAssociatedInscription(
};

// Default values.
if (!resolvedAccounts.inscriptionMetadataAccount.value) {
resolvedAccounts.inscriptionMetadataAccount.value =
findInscriptionMetadataPda(context, {
inscriptionAccount: expectPublicKey(
resolvedAccounts.inscriptionAccount.value
),
});
}
if (!resolvedAccounts.associatedInscriptionAccount.value) {
resolvedAccounts.associatedInscriptionAccount.value =
findAssociatedInscriptionAccountPda(context, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

// Accounts.
export type InitializeFromMintInstructionAccounts = {
/** The account to store the metadata in. */
/** The account where data is stored. */
mintInscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/writeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {

// Accounts.
export type WriteDataInstructionAccounts = {
/** The account to store the metadata in. */
/** The account where data is stored. */
inscriptionAccount: PublicKey | Pda;
/** The account to store the inscription account's metadata in. */
inscriptionMetadataAccount: PublicKey | Pda;
Expand Down
22 changes: 11 additions & 11 deletions clients/js/test/clearData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,14 @@ test('it can write Image data to an associated inscription account', async (t) =
);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

builder = builder.add(
initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount.publicKey,
associationTag: 'image',
})
);

Expand All @@ -242,11 +241,12 @@ test('it can write Image data to an associated inscription account', async (t) =
const chunk = imageBytes.slice(i, i + chunkSize);
// eslint-disable-next-line no-await-in-loop
promises.push(
// eslint-disable-next-line no-await-in-loop
await writeData(umi, {
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
value: chunk,
associatedTag: 'image/png',
associatedTag: 'image',
offset: i,
}).sendAndConfirm(umi, { confirm: { commitment: 'finalized' } })
);
Expand All @@ -257,7 +257,7 @@ test('it can write Image data to an associated inscription account', async (t) =
await clearData(umi, {
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
associatedTag: 'image/png',
associatedTag: 'image',
}).sendAndConfirm(umi, { confirm: { commitment: 'finalized' } });

// Then an account was cleared with no remaining data.
Expand Down Expand Up @@ -308,15 +308,14 @@ test('it can write Image data to an associated mint inscription account', async
);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

builder = builder.add(
initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount[0],
associationTag: 'image',
})
);

Expand All @@ -332,11 +331,12 @@ test('it can write Image data to an associated mint inscription account', async
const chunk = imageBytes.slice(i, i + chunkSize);
// eslint-disable-next-line no-await-in-loop
promises.push(
// eslint-disable-next-line no-await-in-loop
await writeData(umi, {
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
value: chunk,
associatedTag: 'image/png',
associatedTag: 'image',
offset: i,
}).sendAndConfirm(umi)
);
Expand Down
18 changes: 8 additions & 10 deletions clients/js/test/initializeAssocatedInscription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ test('it can initialize an Associated Inscription account', async (t) => {
t.is(shardDataBefore.count + BigInt(1), shardDataAfter.count);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

// Create an Associated Inscription account.
await initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
// associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount.publicKey,
associationTag: 'image',
}).sendAndConfirm(umi);

const inscriptionMetadata = await fetchInscriptionMetadata(
Expand All @@ -78,7 +77,7 @@ test('it can initialize an Associated Inscription account', async (t) => {
updateAuthorities: [umi.identity.publicKey],
associatedInscriptions: [
{
tag: 'image/png',
tag: 'image',
bump: associatedInscriptionAccount[1],
dataType: DataType.Uninitialized,
},
Expand Down Expand Up @@ -149,15 +148,14 @@ test('it can initialize an Associated Inscription account on a Mint', async (t)
t.is(shardDataBefore.count + BigInt(1), shardDataAfter.count);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

// Create an Associated Inscription account.
await initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
// associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount[0],
associationTag: 'image',
}).sendAndConfirm(umi);

const inscriptionMetadata = await fetchInscriptionMetadata(
Expand All @@ -174,7 +172,7 @@ test('it can initialize an Associated Inscription account on a Mint', async (t)
updateAuthorities: [umi.identity.publicKey],
associatedInscriptions: [
{
tag: 'image/png',
tag: 'image',
bump: associatedInscriptionAccount[1],
dataType: DataType.Uninitialized,
},
Expand Down
29 changes: 13 additions & 16 deletions clients/js/test/writeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,14 @@ test('it can write Image data to an associated inscription account', async (t) =
);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

builder = builder.add(
initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount.publicKey,
associationTag: 'image',
})
);

Expand All @@ -311,7 +310,7 @@ test('it can write Image data to an associated inscription account', async (t) =
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
value: chunk,
associatedTag: 'image/png',
associatedTag: 'image',
offset: i,
}).sendAndConfirm(umi)
);
Expand Down Expand Up @@ -366,15 +365,14 @@ test('it can write Image data to an associated mint inscription account', async
);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

builder = builder.add(
initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount[0],
associationTag: 'image',
})
);

Expand All @@ -394,7 +392,7 @@ test('it can write Image data to an associated mint inscription account', async
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
value: chunk,
associatedTag: 'image/png',
associatedTag: 'image',
offset: i,
}).sendAndConfirm(umi)
);
Expand Down Expand Up @@ -432,15 +430,14 @@ test('it can write Image data to an associated inscription account, with preallo
);

const associatedInscriptionAccount = findAssociatedInscriptionPda(umi, {
associated_tag: 'image/png',
associated_tag: 'image',
inscriptionMetadataAccount,
});

builder = builder.add(
initializeAssociatedInscription(umi, {
inscriptionMetadataAccount,
associatedInscriptionAccount,
associationTag: 'image/png',
inscriptionAccount: inscriptionAccount.publicKey,
associationTag: 'image',
})
);

Expand All @@ -454,7 +451,7 @@ test('it can write Image data to an associated inscription account, with preallo
await allocate(umi, {
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
associatedTag: 'image/png',
associatedTag: 'image',
targetSize: imageBytes.length,
}).sendAndConfirm(umi);
}
Expand All @@ -477,7 +474,7 @@ test('it can write Image data to an associated inscription account, with preallo
inscriptionAccount: associatedInscriptionAccount,
inscriptionMetadataAccount,
value: chunk,
associatedTag: 'image/png',
associatedTag: 'image',
offset: i,
}).sendAndConfirm(umi)
);
Expand Down
Loading

0 comments on commit 92363fd

Please sign in to comment.