From 542444a860324e6f84a0fe6b0435816291dc3f73 Mon Sep 17 00:00:00 2001 From: blockiosaurus Date: Fri, 8 Dec 2023 20:33:35 -0500 Subject: [PATCH] Renaming and switching to straight bytes. --- .github/.env | 2 +- .github/file-filters.yml | 6 +- .github/workflows/build-rust-client.yml | 2 +- .vscode/settings.json | 2 +- CONTRIBUTING.md | 4 +- README.md | 6 +- clients/js/CONTRIBUTING.md | 4 +- clients/js/README.md | 10 +- clients/js/package.json | 4 +- clients/js/src/generated/accounts/index.ts | 2 +- .../generated/accounts/inscriptionMetadata.ts | 201 ++++++++++++++++++ .../js/src/generated/accounts/jsonMetadata.ts | 186 ---------------- clients/js/src/generated/errors/index.ts | 2 +- .../errors/{mplJson.ts => mplInscription.ts} | 17 +- .../generated/instructions/addAuthority.ts | 8 +- .../{appendValue.ts => clearData.ts} | 62 ++---- .../js/src/generated/instructions/close.ts | 16 +- .../js/src/generated/instructions/index.ts | 4 +- .../src/generated/instructions/initialize.ts | 16 +- .../generated/instructions/removeAuthority.ts | 50 ++--- .../{setValue.ts => writeData.ts} | 58 ++--- clients/js/src/generated/programs/index.ts | 2 +- .../{mplJson.ts => mplInscription.ts} | 27 +-- clients/js/src/generated/types/key.ts | 2 +- clients/js/src/plugin.ts | 6 +- clients/js/test/_setup.ts | 4 +- clients/js/test/append_value.test.ts | 42 ---- clients/js/test/getProgram.test.ts | 6 +- clients/js/test/initialize.test.ts | 26 +-- .../{set_value.test.ts => writeData.test.ts} | 22 +- clients/rust/CONTRIBUTING.md | 2 +- clients/rust/Cargo.lock | 2 +- clients/rust/Cargo.toml | 2 +- clients/rust/README.md | 4 +- ...on_metadata.rs => inscription_metadata.rs} | 30 +-- clients/rust/src/generated/accounts/mod.rs | 4 +- clients/rust/src/generated/errors/mod.rs | 4 +- .../{mpl_json.rs => mpl_inscription.rs} | 7 +- .../generated/instructions/add_authority.rs | 46 ++-- .../{append_value.rs => clear_data.rs} | 187 +++++++--------- .../rust/src/generated/instructions/close.rs | 99 ++++----- .../src/generated/instructions/initialize.rs | 99 ++++----- .../rust/src/generated/instructions/mod.rs | 8 +- .../instructions/remove_authority.rs | 145 +++++-------- .../{set_value.rs => write_data.rs} | 167 ++++++++------- clients/rust/src/generated/programs.rs | 4 +- clients/rust/src/generated/types/key.rs | 2 +- clients/rust/src/lib.rs | 2 +- clients/rust/tests/create.rs | 4 +- configs/kinobi.cjs | 12 +- configs/shank.cjs | 4 +- configs/validator.cjs | 2 +- idls/{mpl_json.json => mpl_inscription.json} | 105 ++++----- .../{mpl-json => mpl-inscription}/Cargo.lock | 2 +- .../{mpl-json => mpl-inscription}/Cargo.toml | 2 +- .../{mpl-json => mpl-inscription}/README.md | 0 .../rustfmt.toml | 0 .../src/entrypoint.rs | 4 +- .../src/error.rs | 14 +- .../mpl-inscription/src/instruction/mod.rs | 59 +++++ .../{mpl-json => mpl-inscription}/src/lib.rs | 0 .../src/processor/add_authority.rs | 37 ++-- .../src/processor/clear_data.rs | 75 +++++++ .../mpl-inscription/src/processor/close.rs | 63 ++++++ .../src/processor/initialize.rs | 100 +++++++++ .../src/processor/mod.rs | 35 +-- .../src/processor/remove_authority.rs | 65 ++++++ .../src/processor/write_data.rs | 82 +++++++ .../src/state.rs | 10 +- programs/mpl-json/src/instruction/mod.rs | 72 ------- .../mpl-json/src/processor/append_value.rs | 124 ----------- programs/mpl-json/src/processor/close.rs | 59 ----- programs/mpl-json/src/processor/initialize.rs | 110 ---------- .../src/processor/remove_authority.rs | 66 ------ programs/mpl-json/src/processor/set_value.rs | 110 ---------- 75 files changed, 1303 insertions(+), 1526 deletions(-) create mode 100644 clients/js/src/generated/accounts/inscriptionMetadata.ts delete mode 100644 clients/js/src/generated/accounts/jsonMetadata.ts rename clients/js/src/generated/errors/{mplJson.ts => mplInscription.ts} (89%) rename clients/js/src/generated/instructions/{appendValue.ts => clearData.ts} (63%) rename clients/js/src/generated/instructions/{setValue.ts => writeData.ts} (65%) rename clients/js/src/generated/programs/{mplJson.ts => mplInscription.ts} (57%) delete mode 100644 clients/js/test/append_value.test.ts rename clients/js/test/{set_value.test.ts => writeData.test.ts} (55%) rename clients/rust/src/generated/accounts/{json_metadata.rs => inscription_metadata.rs} (68%) rename clients/rust/src/generated/errors/{mpl_json.rs => mpl_inscription.rs} (87%) rename clients/rust/src/generated/instructions/{append_value.rs => clear_data.rs} (66%) rename clients/rust/src/generated/instructions/{set_value.rs => write_data.rs} (72%) rename idls/{mpl_json.json => mpl_inscription.json} (78%) rename programs/{mpl-json => mpl-inscription}/Cargo.lock (99%) rename programs/{mpl-json => mpl-inscription}/Cargo.toml (93%) rename programs/{mpl-json => mpl-inscription}/README.md (100%) rename programs/{mpl-json => mpl-inscription}/rustfmt.toml (100%) rename programs/{mpl-json => mpl-inscription}/src/entrypoint.rs (84%) rename programs/{mpl-json => mpl-inscription}/src/error.rs (81%) create mode 100644 programs/mpl-inscription/src/instruction/mod.rs rename programs/{mpl-json => mpl-inscription}/src/lib.rs (100%) rename programs/{mpl-json => mpl-inscription}/src/processor/add_authority.rs (51%) create mode 100644 programs/mpl-inscription/src/processor/clear_data.rs create mode 100644 programs/mpl-inscription/src/processor/close.rs create mode 100644 programs/mpl-inscription/src/processor/initialize.rs rename programs/{mpl-json => mpl-inscription}/src/processor/mod.rs (53%) create mode 100644 programs/mpl-inscription/src/processor/remove_authority.rs create mode 100644 programs/mpl-inscription/src/processor/write_data.rs rename programs/{mpl-json => mpl-inscription}/src/state.rs (66%) delete mode 100644 programs/mpl-json/src/instruction/mod.rs delete mode 100644 programs/mpl-json/src/processor/append_value.rs delete mode 100644 programs/mpl-json/src/processor/close.rs delete mode 100644 programs/mpl-json/src/processor/initialize.rs delete mode 100644 programs/mpl-json/src/processor/remove_authority.rs delete mode 100644 programs/mpl-json/src/processor/set_value.rs diff --git a/.github/.env b/.github/.env index a5ff789..9b84e46 100644 --- a/.github/.env +++ b/.github/.env @@ -1,5 +1,5 @@ CARGO_TERM_COLOR=always NODE_VERSION=16.x -PROGRAMS=["mpl-json"] +PROGRAMS=["mpl-inscription"] RUST_VERSION=1.70.0 SOLANA_VERSION=1.16.18 diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 6910926..21c1202 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -11,12 +11,12 @@ program_common: &program_common - ".github/file-filters.yml" - ".github/.env" -mpl_json: &mpl_json +mpl_inscription: &mpl_inscription - *program_common - - "programs/mpl-json/**" + - "programs/mpl-inscription/**" programs: &programs - - *mpl_json + - *mpl_inscription # Clients. diff --git a/.github/workflows/build-rust-client.yml b/.github/workflows/build-rust-client.yml index c8ea99b..b401a50 100644 --- a/.github/workflows/build-rust-client.yml +++ b/.github/workflows/build-rust-client.yml @@ -61,5 +61,5 @@ jobs: with: name: rust-client-builds # First wildcard ensures exported paths are consistently under the clients folder. - path: ./client*/rust/target/release/*mpl_json* + path: ./client*/rust/target/release/*mpl_inscription* if-no-files-found: error \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b67c651..993d630 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { "rust-analyzer.linkedProjects": [ - "./programs/mpl-json/Cargo.toml", + "./programs/mpl-inscription/Cargo.toml", ] } \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 05bd21e..8a64cf1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# Contributing to Mpl Json +# Contributing to Mpl Inscription -This is a quick guide to help you contribute to Mpl Json. +This is a quick guide to help you contribute to Mpl Inscription. ## Getting started diff --git a/README.md b/README.md index 4e84790..1765021 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# Mpl Json +# Mpl Inscription -A simple program for writing JSON bytes on chain. +A simple program for inscribing bytes on chain. ## Programs This project contains the following programs: -- [Mpl Json](./programs/mpl-json/README.md) `JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa` +- [Mpl Inscription](./programs/mpl-inscription/README.md) `JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa` You will need a Rust version compatible with BPF to compile the program, currently we recommend using Rust 1.68.0. diff --git a/clients/js/CONTRIBUTING.md b/clients/js/CONTRIBUTING.md index b684033..c9d4184 100644 --- a/clients/js/CONTRIBUTING.md +++ b/clients/js/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to the JavaScript client -This is a quick guide to help you contribute to the JavaScript client of Mpl Json. +This is a quick guide to help you contribute to the JavaScript client of Mpl Inscription. ## Getting started @@ -49,7 +49,7 @@ To publish JavaScript clients using GitHub actions, we first need the following Then, we'll need to create a new GitHub environment called `js-client-documentation` for the generated documentation of the JavaScript client. We can then select the `main` branch only and add the following secret variable to this specific environment. - `VERCEL_PROJECT_ID` — The ID of the Vercel project you want to deploy to. - The convention for Metaplex is to create a new Vercel project named `mpl-json-js-docs` with the following deployment settings: + The convention for Metaplex is to create a new Vercel project named `mpl-inscription-js-docs` with the following deployment settings: - Build Command: `pnpm run build:docs` - Output Directory: `docs` diff --git a/clients/js/README.md b/clients/js/README.md index b3b47aa..e08b774 100644 --- a/clients/js/README.md +++ b/clients/js/README.md @@ -1,4 +1,4 @@ -# JavaScript client for Mpl Json +# JavaScript client for Mpl Inscription A Umi-compatible JavaScript library for the project. @@ -7,15 +7,15 @@ A Umi-compatible JavaScript library for the project. 1. First, if you're not already using Umi, [follow these instructions to install the Umi framework](https://github.com/metaplex-foundation/umi/blob/main/docs/installation.md). 2. Next, install this library using the package manager of your choice. ```sh - npm install @metaplex-foundation/mpl-json + npm install @metaplex-foundation/mpl-inscription ``` 2. Finally, register the library with your Umi instance like so. ```ts - import { mplJson } from '@metaplex-foundation/mpl-json'; - umi.use(mplJson()); + import { MplInscription } from '@metaplex-foundation/mpl-inscription'; + umi.use(MplInscription()); ``` -You can learn more about this library's API by reading its generated [TypeDoc documentation](https://mpl-json-js-docs.vercel.app). +You can learn more about this library's API by reading its generated [TypeDoc documentation](https://mpl-inscription-js-docs.vercel.app). ## Contributing diff --git a/clients/js/package.json b/clients/js/package.json index f5683d3..a72a2f8 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -1,7 +1,7 @@ { - "name": "@metaplex-foundation/mpl-json", + "name": "@metaplex-foundation/mpl-inscription", "version": "0.1.0", - "description": "A simple program for writing JSON bytes on chain.", + "description": "A simple program for inscribing bytes on chain.", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", "scripts": { diff --git a/clients/js/src/generated/accounts/index.ts b/clients/js/src/generated/accounts/index.ts index e87fcc3..2e340b9 100644 --- a/clients/js/src/generated/accounts/index.ts +++ b/clients/js/src/generated/accounts/index.ts @@ -6,4 +6,4 @@ * @see https://github.com/metaplex-foundation/kinobi */ -export * from './jsonMetadata'; +export * from './inscriptionMetadata'; diff --git a/clients/js/src/generated/accounts/inscriptionMetadata.ts b/clients/js/src/generated/accounts/inscriptionMetadata.ts new file mode 100644 index 0000000..862d1f5 --- /dev/null +++ b/clients/js/src/generated/accounts/inscriptionMetadata.ts @@ -0,0 +1,201 @@ +/** + * 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 { + Account, + Context, + Option, + OptionOrNullable, + Pda, + PublicKey, + RpcAccount, + RpcGetAccountOptions, + RpcGetAccountsOptions, + assertAccountExists, + deserializeAccount, + gpaBuilder, + publicKey as toPublicKey, +} from '@metaplex-foundation/umi'; +import { + Serializer, + array, + option, + publicKey as publicKeySerializer, + string, + struct, + u64, + u8, +} from '@metaplex-foundation/umi/serializers'; +import { Key, KeyArgs, getKeySerializer } from '../types'; + +export type InscriptionMetadata = Account; + +export type InscriptionMetadataAccountData = { + key: Key; + bump: number; + inscriptionNumber: Option; + updateAuthorities: Array; +}; + +export type InscriptionMetadataAccountDataArgs = { + key: KeyArgs; + bump: number; + inscriptionNumber: OptionOrNullable; + updateAuthorities: Array; +}; + +export function getInscriptionMetadataAccountDataSerializer(): Serializer< + InscriptionMetadataAccountDataArgs, + InscriptionMetadataAccountData +> { + return struct( + [ + ['key', getKeySerializer()], + ['bump', u8()], + ['inscriptionNumber', option(u64())], + ['updateAuthorities', array(publicKeySerializer())], + ], + { description: 'InscriptionMetadataAccountData' } + ) as Serializer< + InscriptionMetadataAccountDataArgs, + InscriptionMetadataAccountData + >; +} + +export function deserializeInscriptionMetadata( + rawAccount: RpcAccount +): InscriptionMetadata { + return deserializeAccount( + rawAccount, + getInscriptionMetadataAccountDataSerializer() + ); +} + +export async function fetchInscriptionMetadata( + context: Pick, + publicKey: PublicKey | Pda, + options?: RpcGetAccountOptions +): Promise { + const maybeAccount = await context.rpc.getAccount( + toPublicKey(publicKey, false), + options + ); + assertAccountExists(maybeAccount, 'InscriptionMetadata'); + return deserializeInscriptionMetadata(maybeAccount); +} + +export async function safeFetchInscriptionMetadata( + context: Pick, + publicKey: PublicKey | Pda, + options?: RpcGetAccountOptions +): Promise { + const maybeAccount = await context.rpc.getAccount( + toPublicKey(publicKey, false), + options + ); + return maybeAccount.exists + ? deserializeInscriptionMetadata(maybeAccount) + : null; +} + +export async function fetchAllInscriptionMetadata( + context: Pick, + publicKeys: Array, + options?: RpcGetAccountsOptions +): Promise { + const maybeAccounts = await context.rpc.getAccounts( + publicKeys.map((key) => toPublicKey(key, false)), + options + ); + return maybeAccounts.map((maybeAccount) => { + assertAccountExists(maybeAccount, 'InscriptionMetadata'); + return deserializeInscriptionMetadata(maybeAccount); + }); +} + +export async function safeFetchAllInscriptionMetadata( + context: Pick, + publicKeys: Array, + options?: RpcGetAccountsOptions +): Promise { + const maybeAccounts = await context.rpc.getAccounts( + publicKeys.map((key) => toPublicKey(key, false)), + options + ); + return maybeAccounts + .filter((maybeAccount) => maybeAccount.exists) + .map((maybeAccount) => + deserializeInscriptionMetadata(maybeAccount as RpcAccount) + ); +} + +export function getInscriptionMetadataGpaBuilder( + context: Pick +) { + const programId = context.programs.getPublicKey( + 'mplInscription', + 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' + ); + return gpaBuilder(context, programId) + .registerFields<{ + key: KeyArgs; + bump: number; + inscriptionNumber: OptionOrNullable; + updateAuthorities: Array; + }>({ + key: [0, getKeySerializer()], + bump: [1, u8()], + inscriptionNumber: [2, option(u64())], + updateAuthorities: [null, array(publicKeySerializer())], + }) + .deserializeUsing((account) => + deserializeInscriptionMetadata(account) + ); +} + +export function findInscriptionMetadataPda( + context: Pick, + seeds: { + /** The address of the Inscription Account */ + inscriptionAccount: PublicKey; + } +): Pda { + const programId = context.programs.getPublicKey( + 'mplInscription', + 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' + ); + return context.eddsa.findPda(programId, [ + string({ size: 'variable' }).serialize('Inscription'), + publicKeySerializer().serialize(programId), + publicKeySerializer().serialize(seeds.inscriptionAccount), + ]); +} + +export async function fetchInscriptionMetadataFromSeeds( + context: Pick, + seeds: Parameters[1], + options?: RpcGetAccountOptions +): Promise { + return fetchInscriptionMetadata( + context, + findInscriptionMetadataPda(context, seeds), + options + ); +} + +export async function safeFetchInscriptionMetadataFromSeeds( + context: Pick, + seeds: Parameters[1], + options?: RpcGetAccountOptions +): Promise { + return safeFetchInscriptionMetadata( + context, + findInscriptionMetadataPda(context, seeds), + options + ); +} diff --git a/clients/js/src/generated/accounts/jsonMetadata.ts b/clients/js/src/generated/accounts/jsonMetadata.ts deleted file mode 100644 index 71e0799..0000000 --- a/clients/js/src/generated/accounts/jsonMetadata.ts +++ /dev/null @@ -1,186 +0,0 @@ -/** - * 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 { - Account, - Context, - Pda, - PublicKey, - RpcAccount, - RpcGetAccountOptions, - RpcGetAccountsOptions, - assertAccountExists, - deserializeAccount, - gpaBuilder, - publicKey as toPublicKey, -} from '@metaplex-foundation/umi'; -import { - Serializer, - array, - bool, - publicKey as publicKeySerializer, - string, - struct, - u8, -} from '@metaplex-foundation/umi/serializers'; -import { Key, KeyArgs, getKeySerializer } from '../types'; - -export type JsonMetadata = Account; - -export type JsonMetadataAccountData = { - key: Key; - bump: number; - mutable: boolean; - authorities: Array; -}; - -export type JsonMetadataAccountDataArgs = { - key: KeyArgs; - bump: number; - mutable: boolean; - authorities: Array; -}; - -export function getJsonMetadataAccountDataSerializer(): Serializer< - JsonMetadataAccountDataArgs, - JsonMetadataAccountData -> { - return struct( - [ - ['key', getKeySerializer()], - ['bump', u8()], - ['mutable', bool()], - ['authorities', array(publicKeySerializer())], - ], - { description: 'JsonMetadataAccountData' } - ) as Serializer; -} - -export function deserializeJsonMetadata(rawAccount: RpcAccount): JsonMetadata { - return deserializeAccount(rawAccount, getJsonMetadataAccountDataSerializer()); -} - -export async function fetchJsonMetadata( - context: Pick, - publicKey: PublicKey | Pda, - options?: RpcGetAccountOptions -): Promise { - const maybeAccount = await context.rpc.getAccount( - toPublicKey(publicKey, false), - options - ); - assertAccountExists(maybeAccount, 'JsonMetadata'); - return deserializeJsonMetadata(maybeAccount); -} - -export async function safeFetchJsonMetadata( - context: Pick, - publicKey: PublicKey | Pda, - options?: RpcGetAccountOptions -): Promise { - const maybeAccount = await context.rpc.getAccount( - toPublicKey(publicKey, false), - options - ); - return maybeAccount.exists ? deserializeJsonMetadata(maybeAccount) : null; -} - -export async function fetchAllJsonMetadata( - context: Pick, - publicKeys: Array, - options?: RpcGetAccountsOptions -): Promise { - const maybeAccounts = await context.rpc.getAccounts( - publicKeys.map((key) => toPublicKey(key, false)), - options - ); - return maybeAccounts.map((maybeAccount) => { - assertAccountExists(maybeAccount, 'JsonMetadata'); - return deserializeJsonMetadata(maybeAccount); - }); -} - -export async function safeFetchAllJsonMetadata( - context: Pick, - publicKeys: Array, - options?: RpcGetAccountsOptions -): Promise { - const maybeAccounts = await context.rpc.getAccounts( - publicKeys.map((key) => toPublicKey(key, false)), - options - ); - return maybeAccounts - .filter((maybeAccount) => maybeAccount.exists) - .map((maybeAccount) => deserializeJsonMetadata(maybeAccount as RpcAccount)); -} - -export function getJsonMetadataGpaBuilder( - context: Pick -) { - const programId = context.programs.getPublicKey( - 'mplJson', - 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' - ); - return gpaBuilder(context, programId) - .registerFields<{ - key: KeyArgs; - bump: number; - mutable: boolean; - authorities: Array; - }>({ - key: [0, getKeySerializer()], - bump: [1, u8()], - mutable: [2, bool()], - authorities: [3, array(publicKeySerializer())], - }) - .deserializeUsing((account) => - deserializeJsonMetadata(account) - ); -} - -export function findJsonMetadataPda( - context: Pick, - seeds: { - /** The address of the JSON Account */ - jsonAccount: PublicKey; - } -): Pda { - const programId = context.programs.getPublicKey( - 'mplJson', - 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' - ); - return context.eddsa.findPda(programId, [ - string({ size: 'variable' }).serialize('JSON'), - publicKeySerializer().serialize(programId), - publicKeySerializer().serialize(seeds.jsonAccount), - ]); -} - -export async function fetchJsonMetadataFromSeeds( - context: Pick, - seeds: Parameters[1], - options?: RpcGetAccountOptions -): Promise { - return fetchJsonMetadata( - context, - findJsonMetadataPda(context, seeds), - options - ); -} - -export async function safeFetchJsonMetadataFromSeeds( - context: Pick, - seeds: Parameters[1], - options?: RpcGetAccountOptions -): Promise { - return safeFetchJsonMetadata( - context, - findJsonMetadataPda(context, seeds), - options - ); -} diff --git a/clients/js/src/generated/errors/index.ts b/clients/js/src/generated/errors/index.ts index 7d23894..91623a8 100644 --- a/clients/js/src/generated/errors/index.ts +++ b/clients/js/src/generated/errors/index.ts @@ -6,4 +6,4 @@ * @see https://github.com/metaplex-foundation/kinobi */ -export * from './mplJson'; +export * from './mplInscription'; diff --git a/clients/js/src/generated/errors/mplJson.ts b/clients/js/src/generated/errors/mplInscription.ts similarity index 89% rename from clients/js/src/generated/errors/mplJson.ts rename to clients/js/src/generated/errors/mplInscription.ts index 54bb97a..79ae97b 100644 --- a/clients/js/src/generated/errors/mplJson.ts +++ b/clients/js/src/generated/errors/mplInscription.ts @@ -110,11 +110,24 @@ export class InvalidAuthorityError extends ProgramError { codeToErrorMap.set(0x6, InvalidAuthorityError); nameToErrorMap.set('InvalidAuthority', InvalidAuthorityError); +/** NumericalOverflow: Numerical Overflow */ +export class NumericalOverflowError extends ProgramError { + readonly name: string = 'NumericalOverflow'; + + readonly code: number = 0x7; // 7 + + constructor(program: Program, cause?: Error) { + super('Numerical Overflow', program, cause); + } +} +codeToErrorMap.set(0x7, NumericalOverflowError); +nameToErrorMap.set('NumericalOverflow', NumericalOverflowError); + /** * Attempts to resolve a custom program error from the provided error code. * @category Errors */ -export function getMplJsonErrorFromCode( +export function getMplInscriptionErrorFromCode( code: number, program: Program, cause?: Error @@ -127,7 +140,7 @@ export function getMplJsonErrorFromCode( * Attempts to resolve a custom program error from the provided error name, i.e. 'Unauthorized'. * @category Errors */ -export function getMplJsonErrorFromName( +export function getMplInscriptionErrorFromName( name: string, program: Program, cause?: Error diff --git a/clients/js/src/generated/instructions/addAuthority.ts b/clients/js/src/generated/instructions/addAuthority.ts index bf58bfe..b77ba70 100644 --- a/clients/js/src/generated/instructions/addAuthority.ts +++ b/clients/js/src/generated/instructions/addAuthority.ts @@ -30,7 +30,7 @@ import { // Accounts. export type AddAuthorityInstructionAccounts = { /** The account to store the metadata's metadata in. */ - jsonMetadataAccount: PublicKey | Pda; + metadataAccount: PublicKey | Pda; /** The account that will pay for the transaction and rent. */ payer?: Signer; /** System program */ @@ -75,16 +75,16 @@ export function addAuthority( ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( - 'mplJson', + 'mplInscription', 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' ); // Accounts. const resolvedAccounts: ResolvedAccountsWithIndices = { - jsonMetadataAccount: { + metadataAccount: { index: 0, isWritable: true, - value: input.jsonMetadataAccount ?? null, + value: input.metadataAccount ?? null, }, payer: { index: 1, isWritable: true, value: input.payer ?? null }, systemProgram: { diff --git a/clients/js/src/generated/instructions/appendValue.ts b/clients/js/src/generated/instructions/clearData.ts similarity index 63% rename from clients/js/src/generated/instructions/appendValue.ts rename to clients/js/src/generated/instructions/clearData.ts index b5480a6..fbba7e1 100644 --- a/clients/js/src/generated/instructions/appendValue.ts +++ b/clients/js/src/generated/instructions/clearData.ts @@ -17,7 +17,6 @@ import { import { Serializer, mapSerializer, - string, struct, u8, } from '@metaplex-foundation/umi/serializers'; @@ -28,11 +27,11 @@ import { } from '../shared'; // Accounts. -export type AppendValueInstructionAccounts = { +export type ClearDataInstructionAccounts = { /** The account to store the metadata in. */ - jsonAccount: PublicKey | Pda; - /** The account to store the json account's metadata in. */ - jsonMetadataAccount: PublicKey | Pda; + inscriptionAccount: PublicKey | Pda; + /** The account to store the inscription account's metadata in. */ + metadataAccount: PublicKey | Pda; /** The account that will pay for the transaction and rent. */ payer?: Signer; /** System program */ @@ -40,58 +39,48 @@ export type AppendValueInstructionAccounts = { }; // Data. -export type AppendValueInstructionData = { - discriminator: number; - value: string; -}; +export type ClearDataInstructionData = { discriminator: number }; -export type AppendValueInstructionDataArgs = { value: string }; +export type ClearDataInstructionDataArgs = {}; -export function getAppendValueInstructionDataSerializer(): Serializer< - AppendValueInstructionDataArgs, - AppendValueInstructionData +export function getClearDataInstructionDataSerializer(): Serializer< + ClearDataInstructionDataArgs, + ClearDataInstructionData > { return mapSerializer< - AppendValueInstructionDataArgs, + ClearDataInstructionDataArgs, any, - AppendValueInstructionData + ClearDataInstructionData >( - struct( - [ - ['discriminator', u8()], - ['value', string()], - ], - { description: 'AppendValueInstructionData' } - ), + struct([['discriminator', u8()]], { + description: 'ClearDataInstructionData', + }), (value) => ({ ...value, discriminator: 3 }) - ) as Serializer; + ) as Serializer; } -// Args. -export type AppendValueInstructionArgs = AppendValueInstructionDataArgs; - // Instruction. -export function appendValue( +export function clearData( context: Pick, - input: AppendValueInstructionAccounts & AppendValueInstructionArgs + input: ClearDataInstructionAccounts ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( - 'mplJson', + 'mplInscription', 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' ); // Accounts. const resolvedAccounts: ResolvedAccountsWithIndices = { - jsonAccount: { + inscriptionAccount: { index: 0, isWritable: true, - value: input.jsonAccount ?? null, + value: input.inscriptionAccount ?? null, }, - jsonMetadataAccount: { + metadataAccount: { index: 1, isWritable: true, - value: input.jsonMetadataAccount ?? null, + value: input.metadataAccount ?? null, }, payer: { index: 2, isWritable: true, value: input.payer ?? null }, systemProgram: { @@ -101,9 +90,6 @@ export function appendValue( }, }; - // Arguments. - const resolvedArgs: AppendValueInstructionArgs = { ...input }; - // Default values. if (!resolvedAccounts.payer.value) { resolvedAccounts.payer.value = context.payer; @@ -129,9 +115,7 @@ export function appendValue( ); // Data. - const data = getAppendValueInstructionDataSerializer().serialize( - resolvedArgs as AppendValueInstructionDataArgs - ); + const data = getClearDataInstructionDataSerializer().serialize({}); // Bytes Created On Chain. const bytesCreatedOnChain = 0; diff --git a/clients/js/src/generated/instructions/close.ts b/clients/js/src/generated/instructions/close.ts index 981765f..cd770a2 100644 --- a/clients/js/src/generated/instructions/close.ts +++ b/clients/js/src/generated/instructions/close.ts @@ -29,9 +29,9 @@ import { // Accounts. export type CloseInstructionAccounts = { /** The account to store the metadata in. */ - jsonAccount: PublicKey | Pda; - /** The account to store the json account's metadata in. */ - jsonMetadataAccount: PublicKey | Pda; + inscriptionAccount: PublicKey | Pda; + /** The account to store the inscription account's metadata in. */ + metadataAccount: PublicKey | Pda; /** The account that will pay for the transaction and rent. */ payer?: Signer; /** System program */ @@ -62,21 +62,21 @@ export function close( ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( - 'mplJson', + 'mplInscription', 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' ); // Accounts. const resolvedAccounts: ResolvedAccountsWithIndices = { - jsonAccount: { + inscriptionAccount: { index: 0, isWritable: true, - value: input.jsonAccount ?? null, + value: input.inscriptionAccount ?? null, }, - jsonMetadataAccount: { + metadataAccount: { index: 1, isWritable: true, - value: input.jsonMetadataAccount ?? null, + value: input.metadataAccount ?? null, }, payer: { index: 2, isWritable: true, value: input.payer ?? null }, systemProgram: { diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index b926dc8..3ebb36b 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -7,8 +7,8 @@ */ export * from './addAuthority'; -export * from './appendValue'; +export * from './clearData'; export * from './close'; export * from './initialize'; export * from './removeAuthority'; -export * from './setValue'; +export * from './writeData'; diff --git a/clients/js/src/generated/instructions/initialize.ts b/clients/js/src/generated/instructions/initialize.ts index b1096d0..fcc99a0 100644 --- a/clients/js/src/generated/instructions/initialize.ts +++ b/clients/js/src/generated/instructions/initialize.ts @@ -29,9 +29,9 @@ import { // Accounts. export type InitializeInstructionAccounts = { /** The account to store the metadata in. */ - jsonAccount: Signer; - /** The account to store the json account's metadata in. */ - jsonMetadataAccount: PublicKey | Pda; + inscriptionAccount: Signer; + /** The account to store the inscription account's metadata in. */ + metadataAccount: PublicKey | Pda; /** The account that will pay for the transaction and rent. */ payer?: Signer; /** System program */ @@ -66,21 +66,21 @@ export function initialize( ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( - 'mplJson', + 'mplInscription', 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' ); // Accounts. const resolvedAccounts: ResolvedAccountsWithIndices = { - jsonAccount: { + inscriptionAccount: { index: 0, isWritable: true, - value: input.jsonAccount ?? null, + value: input.inscriptionAccount ?? null, }, - jsonMetadataAccount: { + metadataAccount: { index: 1, isWritable: true, - value: input.jsonMetadataAccount ?? null, + value: input.metadataAccount ?? null, }, payer: { index: 2, isWritable: true, value: input.payer ?? null }, systemProgram: { diff --git a/clients/js/src/generated/instructions/removeAuthority.ts b/clients/js/src/generated/instructions/removeAuthority.ts index e2131eb..e78a6f5 100644 --- a/clients/js/src/generated/instructions/removeAuthority.ts +++ b/clients/js/src/generated/instructions/removeAuthority.ts @@ -17,7 +17,6 @@ import { import { Serializer, mapSerializer, - publicKey as publicKeySerializer, struct, u8, } from '@metaplex-foundation/umi/serializers'; @@ -30,20 +29,17 @@ import { // Accounts. export type RemoveAuthorityInstructionAccounts = { /** The account to store the metadata's metadata in. */ - jsonMetadataAccount: PublicKey | Pda; - /** The account that will pay for the transaction and rent. */ - payer?: Signer; + metadataAccount: PublicKey | Pda; + /** The authority paying and being removed. */ + authority?: Signer; /** System program */ systemProgram?: PublicKey | Pda; }; // Data. -export type RemoveAuthorityInstructionData = { - discriminator: number; - authority: PublicKey; -}; +export type RemoveAuthorityInstructionData = { discriminator: number }; -export type RemoveAuthorityInstructionDataArgs = { authority: PublicKey }; +export type RemoveAuthorityInstructionDataArgs = {}; export function getRemoveAuthorityInstructionDataSerializer(): Serializer< RemoveAuthorityInstructionDataArgs, @@ -54,13 +50,9 @@ export function getRemoveAuthorityInstructionDataSerializer(): Serializer< any, RemoveAuthorityInstructionData >( - struct( - [ - ['discriminator', u8()], - ['authority', publicKeySerializer()], - ], - { description: 'RemoveAuthorityInstructionData' } - ), + struct([['discriminator', u8()]], { + description: 'RemoveAuthorityInstructionData', + }), (value) => ({ ...value, discriminator: 5 }) ) as Serializer< RemoveAuthorityInstructionDataArgs, @@ -68,28 +60,25 @@ export function getRemoveAuthorityInstructionDataSerializer(): Serializer< >; } -// Args. -export type RemoveAuthorityInstructionArgs = RemoveAuthorityInstructionDataArgs; - // Instruction. export function removeAuthority( - context: Pick, - input: RemoveAuthorityInstructionAccounts & RemoveAuthorityInstructionArgs + context: Pick, + input: RemoveAuthorityInstructionAccounts ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( - 'mplJson', + 'mplInscription', 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' ); // Accounts. const resolvedAccounts: ResolvedAccountsWithIndices = { - jsonMetadataAccount: { + metadataAccount: { index: 0, isWritable: true, - value: input.jsonMetadataAccount ?? null, + value: input.metadataAccount ?? null, }, - payer: { index: 1, isWritable: true, value: input.payer ?? null }, + authority: { index: 1, isWritable: true, value: input.authority ?? null }, systemProgram: { index: 2, isWritable: false, @@ -97,12 +86,9 @@ export function removeAuthority( }, }; - // Arguments. - const resolvedArgs: RemoveAuthorityInstructionArgs = { ...input }; - // Default values. - if (!resolvedAccounts.payer.value) { - resolvedAccounts.payer.value = context.payer; + if (!resolvedAccounts.authority.value) { + resolvedAccounts.authority.value = context.identity; } if (!resolvedAccounts.systemProgram.value) { resolvedAccounts.systemProgram.value = context.programs.getPublicKey( @@ -125,9 +111,7 @@ export function removeAuthority( ); // Data. - const data = getRemoveAuthorityInstructionDataSerializer().serialize( - resolvedArgs as RemoveAuthorityInstructionDataArgs - ); + const data = getRemoveAuthorityInstructionDataSerializer().serialize({}); // Bytes Created On Chain. const bytesCreatedOnChain = 0; diff --git a/clients/js/src/generated/instructions/setValue.ts b/clients/js/src/generated/instructions/writeData.ts similarity index 65% rename from clients/js/src/generated/instructions/setValue.ts rename to clients/js/src/generated/instructions/writeData.ts index ca37454..1914257 100644 --- a/clients/js/src/generated/instructions/setValue.ts +++ b/clients/js/src/generated/instructions/writeData.ts @@ -16,9 +16,10 @@ import { } from '@metaplex-foundation/umi'; import { Serializer, + bytes, mapSerializer, - string, struct, + u32, u8, } from '@metaplex-foundation/umi/serializers'; import { @@ -28,11 +29,11 @@ import { } from '../shared'; // Accounts. -export type SetValueInstructionAccounts = { +export type WriteDataInstructionAccounts = { /** The account to store the metadata in. */ - jsonAccount: PublicKey | Pda; - /** The account to store the json account's metadata in. */ - jsonMetadataAccount: PublicKey | Pda; + inscriptionAccount: PublicKey | Pda; + /** The account to store the inscription account's metadata in. */ + metadataAccount: PublicKey | Pda; /** The account that will pay for the transaction and rent. */ payer?: Signer; /** System program */ @@ -40,55 +41,58 @@ export type SetValueInstructionAccounts = { }; // Data. -export type SetValueInstructionData = { discriminator: number; value: string }; +export type WriteDataInstructionData = { + discriminator: number; + value: Uint8Array; +}; -export type SetValueInstructionDataArgs = { value: string }; +export type WriteDataInstructionDataArgs = { value: Uint8Array }; -export function getSetValueInstructionDataSerializer(): Serializer< - SetValueInstructionDataArgs, - SetValueInstructionData +export function getWriteDataInstructionDataSerializer(): Serializer< + WriteDataInstructionDataArgs, + WriteDataInstructionData > { return mapSerializer< - SetValueInstructionDataArgs, + WriteDataInstructionDataArgs, any, - SetValueInstructionData + WriteDataInstructionData >( - struct( + struct( [ ['discriminator', u8()], - ['value', string()], + ['value', bytes({ size: u32() })], ], - { description: 'SetValueInstructionData' } + { description: 'WriteDataInstructionData' } ), (value) => ({ ...value, discriminator: 2 }) - ) as Serializer; + ) as Serializer; } // Args. -export type SetValueInstructionArgs = SetValueInstructionDataArgs; +export type WriteDataInstructionArgs = WriteDataInstructionDataArgs; // Instruction. -export function setValue( +export function writeData( context: Pick, - input: SetValueInstructionAccounts & SetValueInstructionArgs + input: WriteDataInstructionAccounts & WriteDataInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( - 'mplJson', + 'mplInscription', 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' ); // Accounts. const resolvedAccounts: ResolvedAccountsWithIndices = { - jsonAccount: { + inscriptionAccount: { index: 0, isWritable: true, - value: input.jsonAccount ?? null, + value: input.inscriptionAccount ?? null, }, - jsonMetadataAccount: { + metadataAccount: { index: 1, isWritable: true, - value: input.jsonMetadataAccount ?? null, + value: input.metadataAccount ?? null, }, payer: { index: 2, isWritable: true, value: input.payer ?? null }, systemProgram: { @@ -99,7 +103,7 @@ export function setValue( }; // Arguments. - const resolvedArgs: SetValueInstructionArgs = { ...input }; + const resolvedArgs: WriteDataInstructionArgs = { ...input }; // Default values. if (!resolvedAccounts.payer.value) { @@ -126,8 +130,8 @@ export function setValue( ); // Data. - const data = getSetValueInstructionDataSerializer().serialize( - resolvedArgs as SetValueInstructionDataArgs + const data = getWriteDataInstructionDataSerializer().serialize( + resolvedArgs as WriteDataInstructionDataArgs ); // Bytes Created On Chain. diff --git a/clients/js/src/generated/programs/index.ts b/clients/js/src/generated/programs/index.ts index 7d23894..91623a8 100644 --- a/clients/js/src/generated/programs/index.ts +++ b/clients/js/src/generated/programs/index.ts @@ -6,4 +6,4 @@ * @see https://github.com/metaplex-foundation/kinobi */ -export * from './mplJson'; +export * from './mplInscription'; diff --git a/clients/js/src/generated/programs/mplJson.ts b/clients/js/src/generated/programs/mplInscription.ts similarity index 57% rename from clients/js/src/generated/programs/mplJson.ts rename to clients/js/src/generated/programs/mplInscription.ts index e25e6a1..21cc0ac 100644 --- a/clients/js/src/generated/programs/mplJson.ts +++ b/clients/js/src/generated/programs/mplInscription.ts @@ -12,20 +12,23 @@ import { Program, PublicKey, } from '@metaplex-foundation/umi'; -import { getMplJsonErrorFromCode, getMplJsonErrorFromName } from '../errors'; +import { + getMplInscriptionErrorFromCode, + getMplInscriptionErrorFromName, +} from '../errors'; -export const MPL_JSON_PROGRAM_ID = +export const MPL_INSCRIPTION_PROGRAM_ID = 'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' as PublicKey<'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa'>; -export function createMplJsonProgram(): Program { +export function createMplInscriptionProgram(): Program { return { - name: 'mplJson', - publicKey: MPL_JSON_PROGRAM_ID, + name: 'mplInscription', + publicKey: MPL_INSCRIPTION_PROGRAM_ID, getErrorFromCode(code: number, cause?: Error) { - return getMplJsonErrorFromCode(code, this, cause); + return getMplInscriptionErrorFromCode(code, this, cause); }, getErrorFromName(name: string, cause?: Error) { - return getMplJsonErrorFromName(name, this, cause); + return getMplInscriptionErrorFromName(name, this, cause); }, isOnCluster() { return true; @@ -33,20 +36,20 @@ export function createMplJsonProgram(): Program { }; } -export function getMplJsonProgram( +export function getMplInscriptionProgram( context: Pick, clusterFilter?: ClusterFilter ): T { - return context.programs.get('mplJson', clusterFilter); + return context.programs.get('mplInscription', clusterFilter); } -export function getMplJsonProgramId( +export function getMplInscriptionProgramId( context: Pick, clusterFilter?: ClusterFilter ): PublicKey { return context.programs.getPublicKey( - 'mplJson', - MPL_JSON_PROGRAM_ID, + 'mplInscription', + MPL_INSCRIPTION_PROGRAM_ID, clusterFilter ); } diff --git a/clients/js/src/generated/types/key.ts b/clients/js/src/generated/types/key.ts index 6579414..eb7b3cd 100644 --- a/clients/js/src/generated/types/key.ts +++ b/clients/js/src/generated/types/key.ts @@ -10,7 +10,7 @@ import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers'; export enum Key { Uninitialized, - JsonMetadataAccount, + InscriptionMetadataAccount, } export type KeyArgs = Key; diff --git a/clients/js/src/plugin.ts b/clients/js/src/plugin.ts index 9e5e0b9..3d50238 100644 --- a/clients/js/src/plugin.ts +++ b/clients/js/src/plugin.ts @@ -1,8 +1,8 @@ import { UmiPlugin } from '@metaplex-foundation/umi'; -import { createMplJsonProgram } from './generated'; +import { createMplInscriptionProgram } from './generated'; -export const mplJson = (): UmiPlugin => ({ +export const MplInscription = (): UmiPlugin => ({ install(umi) { - umi.programs.add(createMplJsonProgram(), false); + umi.programs.add(createMplInscriptionProgram(), false); }, }); diff --git a/clients/js/test/_setup.ts b/clients/js/test/_setup.ts index 3cd5802..4a37591 100644 --- a/clients/js/test/_setup.ts +++ b/clients/js/test/_setup.ts @@ -1,6 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies */ import { createUmi as basecreateUmi } from '@metaplex-foundation/umi-bundle-tests'; -import { mplJson } from '../src'; +import { MplInscription } from '../src'; export const createUmi = async () => - (await basecreateUmi()).use(mplJson()); + (await basecreateUmi()).use(MplInscription()); diff --git a/clients/js/test/append_value.test.ts b/clients/js/test/append_value.test.ts deleted file mode 100644 index 0f7c52f..0000000 --- a/clients/js/test/append_value.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { TransactionBuilder, generateSigner } from '@metaplex-foundation/umi'; -import test from 'ava'; -import { MPL_JSON_PROGRAM_ID, findJsonMetadataPda, initialize, setValue } from '../src'; -import { createUmi } from './_setup'; - -test('it can create initialize a JSON account', async (t) => { - // Given a Umi instance and a new signer. - const umi = await createUmi(); - const jsonAccount = generateSigner(umi); - - const jsonMetadataAccount = await findJsonMetadataPda(umi, { jsonAccount: jsonAccount.publicKey }); - - let builder = new TransactionBuilder(); - - // When we create a new account. - builder = builder.add(initialize(umi, { - jsonAccount, - jsonMetadataAccount, - })); - - // And set the value. - builder = builder.add(setValue(umi, { - jsonAccount: jsonAccount.publicKey, - jsonMetadataAccount, - value: '{"description": "A bread! But on-chain!", "external_url": "https://breadheads.io"}' - })); - - await builder.sendAndConfirm(umi, { confirm: { commitment: 'finalized' } }); - - // Then an account was created with the correct data. - const jsonData = await umi.rpc.getAccount(jsonAccount.publicKey); - console.log(jsonData); - if (jsonData.exists) { - const jsonString = Buffer.from(jsonData.data).toString('utf8') - const parsedData = JSON.parse(jsonString) - console.log(parsedData); - - t.like(jsonData, { - owner: MPL_JSON_PROGRAM_ID, - }); - } -}); diff --git a/clients/js/test/getProgram.test.ts b/clients/js/test/getProgram.test.ts index 0fe3b4a..6adaea1 100644 --- a/clients/js/test/getProgram.test.ts +++ b/clients/js/test/getProgram.test.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import { MPL_JSON_PROGRAM_ID } from '../src'; +import { MPL_INSCRIPTION_PROGRAM_ID } from '../src'; import { createUmi } from './_setup'; test('it registers the program', async (t) => { @@ -7,8 +7,8 @@ test('it registers the program', async (t) => { const umi = await createUmi(); // When we fetch the registered program. - const program = umi.programs.get('mplJson'); + const program = umi.programs.get('mplInscription'); // Then we expect it to be the same as the program ID constant. - t.true(program.publicKey === MPL_JSON_PROGRAM_ID); + t.true(program.publicKey === MPL_INSCRIPTION_PROGRAM_ID); }); diff --git a/clients/js/test/initialize.test.ts b/clients/js/test/initialize.test.ts index 143472a..c7614d0 100644 --- a/clients/js/test/initialize.test.ts +++ b/clients/js/test/initialize.test.ts @@ -1,36 +1,36 @@ import { generateSigner } from '@metaplex-foundation/umi'; import test from 'ava'; -import { JsonMetadata, Key, MPL_JSON_PROGRAM_ID, fetchJsonMetadata, findJsonMetadataPda, initialize } from '../src'; +import { InscriptionMetadata, Key, MPL_INSCRIPTION_PROGRAM_ID, fetchInscriptionMetadata, findInscriptionMetadataPda, initialize } from '../src'; import { createUmi } from './_setup'; test('it can create initialize a JSON account', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const jsonAccount = generateSigner(umi); + const inscriptionAccount = generateSigner(umi); - const jsonMetadataAccount = await findJsonMetadataPda(umi, {jsonAccount: jsonAccount.publicKey}); + const metadataAccount = await findInscriptionMetadataPda(umi, {inscriptionAccount: inscriptionAccount.publicKey}); // When we create a new account. await initialize(umi, { - jsonAccount, - jsonMetadataAccount, + inscriptionAccount, + metadataAccount, }).sendAndConfirm(umi); // Then an account was created with the correct data. - const jsonMetadata = await fetchJsonMetadata(umi, jsonMetadataAccount); + const jsonMetadata = await fetchInscriptionMetadata(umi, metadataAccount); console.log(jsonMetadata); - t.like(jsonMetadata, { - key: Key.JsonMetadataAccount, - bump: jsonMetadataAccount[1], - authorities: [umi.identity.publicKey], + t.like(jsonMetadata, { + key: Key.InscriptionMetadataAccount, + bump: metadataAccount[1], + updateAuthorities: [umi.identity.publicKey], }); - const jsonData = await umi.rpc.getAccount(jsonAccount.publicKey); + const jsonData = await umi.rpc.getAccount(inscriptionAccount.publicKey); if (jsonData.exists) { console.log(jsonData); t.like(jsonData, { - owner: MPL_JSON_PROGRAM_ID, - data: Uint8Array.from([0, 0, 0, 0]), + owner: MPL_INSCRIPTION_PROGRAM_ID, + data: Uint8Array.from([]), }); } }); diff --git a/clients/js/test/set_value.test.ts b/clients/js/test/writeData.test.ts similarity index 55% rename from clients/js/test/set_value.test.ts rename to clients/js/test/writeData.test.ts index f45712c..7a3a385 100644 --- a/clients/js/test/set_value.test.ts +++ b/clients/js/test/writeData.test.ts @@ -1,34 +1,34 @@ import { TransactionBuilder, generateSigner } from '@metaplex-foundation/umi'; import test from 'ava'; -import { MPL_JSON_PROGRAM_ID, findJsonMetadataPda, initialize, setValue } from '../src'; +import { MPL_INSCRIPTION_PROGRAM_ID, findInscriptionMetadataPda, initialize, writeData } from '../src'; import { createUmi } from './_setup'; test('it can set JSON data on an account', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const jsonAccount = generateSigner(umi); + const inscriptionAccount = generateSigner(umi); - const jsonMetadataAccount = await findJsonMetadataPda(umi, { jsonAccount: jsonAccount.publicKey }); + const metadataAccount = await findInscriptionMetadataPda(umi, { inscriptionAccount: inscriptionAccount.publicKey }); let builder = new TransactionBuilder(); // When we create a new account. builder = builder.add(initialize(umi, { - jsonAccount, - jsonMetadataAccount, + inscriptionAccount, + metadataAccount, })); // And set the value. - builder = builder.add(setValue(umi, { - jsonAccount: jsonAccount.publicKey, - jsonMetadataAccount, - value: '{"description": "A bread! But on-chain!", "external_url": "https://breadheads.io"}' + builder = builder.add(writeData(umi, { + inscriptionAccount: inscriptionAccount.publicKey, + metadataAccount, + value: Buffer.from('{"description": "A bread! But on-chain!", "external_url": "https://breadheads.io"}') })); await builder.sendAndConfirm(umi, { confirm: { commitment: 'finalized' } }); // Then an account was created with the correct data. - const jsonData = await umi.rpc.getAccount(jsonAccount.publicKey); + const jsonData = await umi.rpc.getAccount(inscriptionAccount.publicKey); console.log(jsonData); if (jsonData.exists) { const jsonString = Buffer.from(jsonData.data).toString('utf8') @@ -36,7 +36,7 @@ test('it can set JSON data on an account', async (t) => { console.log(parsedData); t.like(jsonData, { - owner: MPL_JSON_PROGRAM_ID, + owner: MPL_INSCRIPTION_PROGRAM_ID, }); } }); diff --git a/clients/rust/CONTRIBUTING.md b/clients/rust/CONTRIBUTING.md index d905ffe..56d3f20 100644 --- a/clients/rust/CONTRIBUTING.md +++ b/clients/rust/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to the Rust client -This is a quick guide to help you contribute to the Rust client of Mpl Json. +This is a quick guide to help you contribute to the Rust client of Mpl Inscription. ## Getting started diff --git a/clients/rust/Cargo.lock b/clients/rust/Cargo.lock index cd55ef8..e5f74e2 100644 --- a/clients/rust/Cargo.lock +++ b/clients/rust/Cargo.lock @@ -2081,7 +2081,7 @@ dependencies = [ ] [[package]] -name = "mpl-json" +name = "mpl-inscription" version = "0.1.0" dependencies = [ "assert_matches", diff --git a/clients/rust/Cargo.toml b/clients/rust/Cargo.toml index 7c9e34a..d168029 100644 --- a/clients/rust/Cargo.toml +++ b/clients/rust/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mpl-json" +name = "mpl-inscription" version = "0.1.0" edition = "2021" readme = "README.md" diff --git a/clients/rust/README.md b/clients/rust/README.md index b3571bb..6b81fe8 100644 --- a/clients/rust/README.md +++ b/clients/rust/README.md @@ -1,4 +1,4 @@ -# Rust client SDK for Mpl Json +# Rust client SDK for Mpl Inscription An autogenerated Rust client SDK for the project. @@ -7,7 +7,7 @@ An autogenerated Rust client SDK for the project. From your project folder: ```bash -cargo add mpl-json +cargo add mpl-inscription ``` ## Structure diff --git a/clients/rust/src/generated/accounts/json_metadata.rs b/clients/rust/src/generated/accounts/inscription_metadata.rs similarity index 68% rename from clients/rust/src/generated/accounts/json_metadata.rs rename to clients/rust/src/generated/accounts/inscription_metadata.rs index b371fa2..6989921 100644 --- a/clients/rust/src/generated/accounts/json_metadata.rs +++ b/clients/rust/src/generated/accounts/inscription_metadata.rs @@ -12,37 +12,37 @@ use solana_program::pubkey::Pubkey; #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct JsonMetadata { +pub struct InscriptionMetadata { pub key: Key, pub bump: u8, - pub mutable: bool, - pub authorities: Vec, + pub inscription_number: Option, + pub update_authorities: Vec, } -impl JsonMetadata { +impl InscriptionMetadata { pub fn create_pda( - json_account: Pubkey, + inscription_account: Pubkey, bump: u8, ) -> Result { solana_program::pubkey::Pubkey::create_program_address( &[ - "JSON".as_bytes(), - crate::MPL_JSON_ID.as_ref(), - json_account.as_ref(), + "Inscription".as_bytes(), + crate::MPL_INSCRIPTION_ID.as_ref(), + inscription_account.as_ref(), &[bump], ], - &crate::MPL_JSON_ID, + &crate::MPL_INSCRIPTION_ID, ) } - pub fn find_pda(json_account: &Pubkey) -> (solana_program::pubkey::Pubkey, u8) { + pub fn find_pda(inscription_account: &Pubkey) -> (solana_program::pubkey::Pubkey, u8) { solana_program::pubkey::Pubkey::find_program_address( &[ - "JSON".as_bytes(), - crate::MPL_JSON_ID.as_ref(), - json_account.as_ref(), + "Inscription".as_bytes(), + crate::MPL_INSCRIPTION_ID.as_ref(), + inscription_account.as_ref(), ], - &crate::MPL_JSON_ID, + &crate::MPL_INSCRIPTION_ID, ) } @@ -53,7 +53,7 @@ impl JsonMetadata { } } -impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for JsonMetadata { +impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for InscriptionMetadata { type Error = std::io::Error; fn try_from( diff --git a/clients/rust/src/generated/accounts/mod.rs b/clients/rust/src/generated/accounts/mod.rs index 43f58a5..35b7917 100644 --- a/clients/rust/src/generated/accounts/mod.rs +++ b/clients/rust/src/generated/accounts/mod.rs @@ -5,6 +5,6 @@ //! [https://github.com/metaplex-foundation/kinobi] //! -pub(crate) mod json_metadata; +pub(crate) mod inscription_metadata; -pub use self::json_metadata::*; +pub use self::inscription_metadata::*; diff --git a/clients/rust/src/generated/errors/mod.rs b/clients/rust/src/generated/errors/mod.rs index 02512dd..981a80d 100644 --- a/clients/rust/src/generated/errors/mod.rs +++ b/clients/rust/src/generated/errors/mod.rs @@ -5,6 +5,6 @@ //! [https://github.com/metaplex-foundation/kinobi] //! -pub(crate) mod mpl_json; +pub(crate) mod mpl_inscription; -pub use self::mpl_json::MplJsonError; +pub use self::mpl_inscription::MplInscriptionError; diff --git a/clients/rust/src/generated/errors/mpl_json.rs b/clients/rust/src/generated/errors/mpl_inscription.rs similarity index 87% rename from clients/rust/src/generated/errors/mpl_json.rs rename to clients/rust/src/generated/errors/mpl_inscription.rs index ca417ae..fd4256c 100644 --- a/clients/rust/src/generated/errors/mpl_json.rs +++ b/clients/rust/src/generated/errors/mpl_inscription.rs @@ -9,7 +9,7 @@ use num_derive::FromPrimitive; use thiserror::Error; #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] -pub enum MplJsonError { +pub enum MplInscriptionError { /// 0 (0x0) - The account has already been initialized #[error("The account has already been initialized")] AlreadyInitialized, @@ -31,9 +31,12 @@ pub enum MplJsonError { /// 6 (0x6) - The payer does not have authority to perform this action. #[error("The payer does not have authority to perform this action.")] InvalidAuthority, + /// 7 (0x7) - Numerical Overflow + #[error("Numerical Overflow")] + NumericalOverflow, } -impl solana_program::program_error::PrintProgramError for MplJsonError { +impl solana_program::program_error::PrintProgramError for MplInscriptionError { fn print(&self) { solana_program::msg!(&self.to_string()); } diff --git a/clients/rust/src/generated/instructions/add_authority.rs b/clients/rust/src/generated/instructions/add_authority.rs index d668e9f..e0466fa 100644 --- a/clients/rust/src/generated/instructions/add_authority.rs +++ b/clients/rust/src/generated/instructions/add_authority.rs @@ -12,7 +12,7 @@ use solana_program::pubkey::Pubkey; /// Accounts. pub struct AddAuthority { /// The account to store the metadata's metadata in. - pub json_metadata_account: solana_program::pubkey::Pubkey, + pub metadata_account: solana_program::pubkey::Pubkey, /// The account that will pay for the transaction and rent. pub payer: solana_program::pubkey::Pubkey, /// System program @@ -34,7 +34,7 @@ impl AddAuthority { ) -> solana_program::instruction::Instruction { let mut accounts = Vec::with_capacity(3 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_metadata_account, + self.metadata_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -50,7 +50,7 @@ impl AddAuthority { data.append(&mut args); solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, } @@ -77,7 +77,7 @@ pub struct AddAuthorityInstructionArgs { /// Instruction builder. #[derive(Default)] pub struct AddAuthorityBuilder { - json_metadata_account: Option, + metadata_account: Option, payer: Option, system_program: Option, new_authority: Option, @@ -90,11 +90,11 @@ impl AddAuthorityBuilder { } /// The account to store the metadata's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: solana_program::pubkey::Pubkey, + metadata_account: solana_program::pubkey::Pubkey, ) -> &mut Self { - self.json_metadata_account = Some(json_metadata_account); + self.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -136,9 +136,7 @@ impl AddAuthorityBuilder { #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { let accounts = AddAuthority { - json_metadata_account: self - .json_metadata_account - .expect("json_metadata_account is not set"), + metadata_account: self.metadata_account.expect("metadata_account is not set"), payer: self.payer.expect("payer is not set"), system_program: self .system_program @@ -158,7 +156,7 @@ impl AddAuthorityBuilder { /// `add_authority` CPI accounts. pub struct AddAuthorityCpiAccounts<'a, 'b> { /// The account to store the metadata's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program @@ -170,7 +168,7 @@ pub struct AddAuthorityCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, /// The account to store the metadata's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program @@ -187,7 +185,7 @@ impl<'a, 'b> AddAuthorityCpi<'a, 'b> { ) -> Self { Self { __program: program, - json_metadata_account: accounts.json_metadata_account, + metadata_account: accounts.metadata_account, payer: accounts.payer, system_program: accounts.system_program, __args: args, @@ -228,7 +226,7 @@ impl<'a, 'b> AddAuthorityCpi<'a, 'b> { ) -> solana_program::entrypoint::ProgramResult { let mut accounts = Vec::with_capacity(3 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_metadata_account.key, + *self.metadata_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -251,13 +249,13 @@ impl<'a, 'b> AddAuthorityCpi<'a, 'b> { data.append(&mut args); let instruction = solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, }; let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.json_metadata_account.clone()); + account_infos.push(self.metadata_account.clone()); account_infos.push(self.payer.clone()); account_infos.push(self.system_program.clone()); remaining_accounts @@ -281,7 +279,7 @@ impl<'a, 'b> AddAuthorityCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { let instruction = Box::new(AddAuthorityCpiBuilderInstruction { __program: program, - json_metadata_account: None, + metadata_account: None, payer: None, system_program: None, new_authority: None, @@ -291,11 +289,11 @@ impl<'a, 'b> AddAuthorityCpiBuilder<'a, 'b> { } /// The account to store the metadata's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + metadata_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_metadata_account = Some(json_metadata_account); + self.instruction.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -369,10 +367,10 @@ impl<'a, 'b> AddAuthorityCpiBuilder<'a, 'b> { let instruction = AddAuthorityCpi { __program: self.instruction.__program, - json_metadata_account: self + metadata_account: self .instruction - .json_metadata_account - .expect("json_metadata_account is not set"), + .metadata_account + .expect("metadata_account is not set"), payer: self.instruction.payer.expect("payer is not set"), @@ -391,7 +389,7 @@ impl<'a, 'b> AddAuthorityCpiBuilder<'a, 'b> { struct AddAuthorityCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - json_metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, new_authority: Option, diff --git a/clients/rust/src/generated/instructions/append_value.rs b/clients/rust/src/generated/instructions/clear_data.rs similarity index 66% rename from clients/rust/src/generated/instructions/append_value.rs rename to clients/rust/src/generated/instructions/clear_data.rs index 6d6b8b3..cc7d048 100644 --- a/clients/rust/src/generated/instructions/append_value.rs +++ b/clients/rust/src/generated/instructions/clear_data.rs @@ -9,37 +9,33 @@ use borsh::BorshDeserialize; use borsh::BorshSerialize; /// Accounts. -pub struct AppendValue { +pub struct ClearData { /// The account to store the metadata in. - pub json_account: solana_program::pubkey::Pubkey, - /// The account to store the json account's metadata in. - pub json_metadata_account: solana_program::pubkey::Pubkey, + pub inscription_account: solana_program::pubkey::Pubkey, + /// The account to store the inscription account's metadata in. + pub metadata_account: solana_program::pubkey::Pubkey, /// The account that will pay for the transaction and rent. pub payer: solana_program::pubkey::Pubkey, /// System program pub system_program: solana_program::pubkey::Pubkey, } -impl AppendValue { - pub fn instruction( - &self, - args: AppendValueInstructionArgs, - ) -> solana_program::instruction::Instruction { - self.instruction_with_remaining_accounts(args, &[]) +impl ClearData { + pub fn instruction(&self) -> solana_program::instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) } #[allow(clippy::vec_init_then_push)] pub fn instruction_with_remaining_accounts( &self, - args: AppendValueInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_account, + self.inscription_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_metadata_account, + self.metadata_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -50,12 +46,10 @@ impl AppendValue { false, )); accounts.extend_from_slice(remaining_accounts); - let mut data = AppendValueInstructionData::new().try_to_vec().unwrap(); - let mut args = args.try_to_vec().unwrap(); - data.append(&mut args); + let data = ClearDataInstructionData::new().try_to_vec().unwrap(); solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, } @@ -63,50 +57,46 @@ impl AppendValue { } #[derive(BorshDeserialize, BorshSerialize)] -struct AppendValueInstructionData { +struct ClearDataInstructionData { discriminator: u8, } -impl AppendValueInstructionData { +impl ClearDataInstructionData { fn new() -> Self { Self { discriminator: 3 } } } -#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct AppendValueInstructionArgs { - pub value: String, -} - /// Instruction builder. #[derive(Default)] -pub struct AppendValueBuilder { - json_account: Option, - json_metadata_account: Option, +pub struct ClearDataBuilder { + inscription_account: Option, + metadata_account: Option, payer: Option, system_program: Option, - value: Option, __remaining_accounts: Vec, } -impl AppendValueBuilder { +impl ClearDataBuilder { pub fn new() -> Self { Self::default() } /// The account to store the metadata in. #[inline(always)] - pub fn json_account(&mut self, json_account: solana_program::pubkey::Pubkey) -> &mut Self { - self.json_account = Some(json_account); + pub fn inscription_account( + &mut self, + inscription_account: solana_program::pubkey::Pubkey, + ) -> &mut Self { + self.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: solana_program::pubkey::Pubkey, + metadata_account: solana_program::pubkey::Pubkey, ) -> &mut Self { - self.json_metadata_account = Some(json_metadata_account); + self.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -122,11 +112,6 @@ impl AppendValueBuilder { self.system_program = Some(system_program); self } - #[inline(always)] - pub fn value(&mut self, value: String) -> &mut Self { - self.value = Some(value); - self - } /// Add an aditional account to the instruction. #[inline(always)] pub fn add_remaining_account( @@ -147,65 +132,58 @@ impl AppendValueBuilder { } #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { - let accounts = AppendValue { - json_account: self.json_account.expect("json_account is not set"), - json_metadata_account: self - .json_metadata_account - .expect("json_metadata_account is not set"), + let accounts = ClearData { + inscription_account: self + .inscription_account + .expect("inscription_account is not set"), + metadata_account: self.metadata_account.expect("metadata_account is not set"), payer: self.payer.expect("payer is not set"), system_program: self .system_program .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")), }; - let args = AppendValueInstructionArgs { - value: self.value.clone().expect("value is not set"), - }; - accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) } } -/// `append_value` CPI accounts. -pub struct AppendValueCpiAccounts<'a, 'b> { +/// `clear_data` CPI accounts. +pub struct ClearDataCpiAccounts<'a, 'b> { /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program pub system_program: &'b solana_program::account_info::AccountInfo<'a>, } -/// `append_value` CPI instruction. -pub struct AppendValueCpi<'a, 'b> { +/// `clear_data` CPI instruction. +pub struct ClearDataCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program pub system_program: &'b solana_program::account_info::AccountInfo<'a>, - /// The arguments for the instruction. - pub __args: AppendValueInstructionArgs, } -impl<'a, 'b> AppendValueCpi<'a, 'b> { +impl<'a, 'b> ClearDataCpi<'a, 'b> { pub fn new( program: &'b solana_program::account_info::AccountInfo<'a>, - accounts: AppendValueCpiAccounts<'a, 'b>, - args: AppendValueInstructionArgs, + accounts: ClearDataCpiAccounts<'a, 'b>, ) -> Self { Self { __program: program, - json_account: accounts.json_account, - json_metadata_account: accounts.json_metadata_account, + inscription_account: accounts.inscription_account, + metadata_account: accounts.metadata_account, payer: accounts.payer, system_program: accounts.system_program, - __args: args, } } #[inline(always)] @@ -243,11 +221,11 @@ impl<'a, 'b> AppendValueCpi<'a, 'b> { ) -> solana_program::entrypoint::ProgramResult { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_account.key, + *self.inscription_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_metadata_account.key, + *self.metadata_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -265,19 +243,17 @@ impl<'a, 'b> AppendValueCpi<'a, 'b> { is_writable: remaining_account.2, }) }); - let mut data = AppendValueInstructionData::new().try_to_vec().unwrap(); - let mut args = self.__args.try_to_vec().unwrap(); - data.append(&mut args); + let data = ClearDataInstructionData::new().try_to_vec().unwrap(); let instruction = solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, }; let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.json_account.clone()); - account_infos.push(self.json_metadata_account.clone()); + account_infos.push(self.inscription_account.clone()); + account_infos.push(self.metadata_account.clone()); account_infos.push(self.payer.clone()); account_infos.push(self.system_program.clone()); remaining_accounts @@ -292,40 +268,39 @@ impl<'a, 'b> AppendValueCpi<'a, 'b> { } } -/// `append_value` CPI instruction builder. -pub struct AppendValueCpiBuilder<'a, 'b> { - instruction: Box>, +/// `clear_data` CPI instruction builder. +pub struct ClearDataCpiBuilder<'a, 'b> { + instruction: Box>, } -impl<'a, 'b> AppendValueCpiBuilder<'a, 'b> { +impl<'a, 'b> ClearDataCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { - let instruction = Box::new(AppendValueCpiBuilderInstruction { + let instruction = Box::new(ClearDataCpiBuilderInstruction { __program: program, - json_account: None, - json_metadata_account: None, + inscription_account: None, + metadata_account: None, payer: None, system_program: None, - value: None, __remaining_accounts: Vec::new(), }); Self { instruction } } /// The account to store the metadata in. #[inline(always)] - pub fn json_account( + pub fn inscription_account( &mut self, - json_account: &'b solana_program::account_info::AccountInfo<'a>, + inscription_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_account = Some(json_account); + self.instruction.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + metadata_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_metadata_account = Some(json_metadata_account); + self.instruction.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -343,11 +318,6 @@ impl<'a, 'b> AppendValueCpiBuilder<'a, 'b> { self.instruction.system_program = Some(system_program); self } - #[inline(always)] - pub fn value(&mut self, value: String) -> &mut Self { - self.instruction.value = Some(value); - self - } /// Add an additional account to the instruction. #[inline(always)] pub fn add_remaining_account( @@ -389,21 +359,18 @@ impl<'a, 'b> AppendValueCpiBuilder<'a, 'b> { &self, signers_seeds: &[&[&[u8]]], ) -> solana_program::entrypoint::ProgramResult { - let args = AppendValueInstructionArgs { - value: self.instruction.value.clone().expect("value is not set"), - }; - let instruction = AppendValueCpi { + let instruction = ClearDataCpi { __program: self.instruction.__program, - json_account: self + inscription_account: self .instruction - .json_account - .expect("json_account is not set"), + .inscription_account + .expect("inscription_account is not set"), - json_metadata_account: self + metadata_account: self .instruction - .json_metadata_account - .expect("json_metadata_account is not set"), + .metadata_account + .expect("metadata_account is not set"), payer: self.instruction.payer.expect("payer is not set"), @@ -411,7 +378,6 @@ impl<'a, 'b> AppendValueCpiBuilder<'a, 'b> { .instruction .system_program .expect("system_program is not set"), - __args: args, }; instruction.invoke_signed_with_remaining_accounts( signers_seeds, @@ -420,13 +386,12 @@ impl<'a, 'b> AppendValueCpiBuilder<'a, 'b> { } } -struct AppendValueCpiBuilderInstruction<'a, 'b> { +struct ClearDataCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - json_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, - json_metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + inscription_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, - value: Option, /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. __remaining_accounts: Vec<( &'b solana_program::account_info::AccountInfo<'a>, diff --git a/clients/rust/src/generated/instructions/close.rs b/clients/rust/src/generated/instructions/close.rs index 9447a80..387faec 100644 --- a/clients/rust/src/generated/instructions/close.rs +++ b/clients/rust/src/generated/instructions/close.rs @@ -11,9 +11,9 @@ use borsh::BorshSerialize; /// Accounts. pub struct Close { /// The account to store the metadata in. - pub json_account: solana_program::pubkey::Pubkey, - /// The account to store the json account's metadata in. - pub json_metadata_account: solana_program::pubkey::Pubkey, + pub inscription_account: solana_program::pubkey::Pubkey, + /// The account to store the inscription account's metadata in. + pub metadata_account: solana_program::pubkey::Pubkey, /// The account that will pay for the transaction and rent. pub payer: solana_program::pubkey::Pubkey, /// System program @@ -31,11 +31,11 @@ impl Close { ) -> solana_program::instruction::Instruction { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_account, + self.inscription_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_metadata_account, + self.metadata_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -49,7 +49,7 @@ impl Close { let data = CloseInstructionData::new().try_to_vec().unwrap(); solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, } @@ -70,8 +70,8 @@ impl CloseInstructionData { /// Instruction builder. #[derive(Default)] pub struct CloseBuilder { - json_account: Option, - json_metadata_account: Option, + inscription_account: Option, + metadata_account: Option, payer: Option, system_program: Option, __remaining_accounts: Vec, @@ -83,17 +83,20 @@ impl CloseBuilder { } /// The account to store the metadata in. #[inline(always)] - pub fn json_account(&mut self, json_account: solana_program::pubkey::Pubkey) -> &mut Self { - self.json_account = Some(json_account); + pub fn inscription_account( + &mut self, + inscription_account: solana_program::pubkey::Pubkey, + ) -> &mut Self { + self.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: solana_program::pubkey::Pubkey, + metadata_account: solana_program::pubkey::Pubkey, ) -> &mut Self { - self.json_metadata_account = Some(json_metadata_account); + self.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -130,10 +133,10 @@ impl CloseBuilder { #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { let accounts = Close { - json_account: self.json_account.expect("json_account is not set"), - json_metadata_account: self - .json_metadata_account - .expect("json_metadata_account is not set"), + inscription_account: self + .inscription_account + .expect("inscription_account is not set"), + metadata_account: self.metadata_account.expect("metadata_account is not set"), payer: self.payer.expect("payer is not set"), system_program: self .system_program @@ -147,9 +150,9 @@ impl CloseBuilder { /// `close` CPI accounts. pub struct CloseCpiAccounts<'a, 'b> { /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program @@ -161,9 +164,9 @@ pub struct CloseCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program @@ -177,8 +180,8 @@ impl<'a, 'b> CloseCpi<'a, 'b> { ) -> Self { Self { __program: program, - json_account: accounts.json_account, - json_metadata_account: accounts.json_metadata_account, + inscription_account: accounts.inscription_account, + metadata_account: accounts.metadata_account, payer: accounts.payer, system_program: accounts.system_program, } @@ -218,11 +221,11 @@ impl<'a, 'b> CloseCpi<'a, 'b> { ) -> solana_program::entrypoint::ProgramResult { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_account.key, + *self.inscription_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_metadata_account.key, + *self.metadata_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -243,14 +246,14 @@ impl<'a, 'b> CloseCpi<'a, 'b> { let data = CloseInstructionData::new().try_to_vec().unwrap(); let instruction = solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, }; let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.json_account.clone()); - account_infos.push(self.json_metadata_account.clone()); + account_infos.push(self.inscription_account.clone()); + account_infos.push(self.metadata_account.clone()); account_infos.push(self.payer.clone()); account_infos.push(self.system_program.clone()); remaining_accounts @@ -274,8 +277,8 @@ impl<'a, 'b> CloseCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { let instruction = Box::new(CloseCpiBuilderInstruction { __program: program, - json_account: None, - json_metadata_account: None, + inscription_account: None, + metadata_account: None, payer: None, system_program: None, __remaining_accounts: Vec::new(), @@ -284,20 +287,20 @@ impl<'a, 'b> CloseCpiBuilder<'a, 'b> { } /// The account to store the metadata in. #[inline(always)] - pub fn json_account( + pub fn inscription_account( &mut self, - json_account: &'b solana_program::account_info::AccountInfo<'a>, + inscription_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_account = Some(json_account); + self.instruction.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + metadata_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_metadata_account = Some(json_metadata_account); + self.instruction.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -359,15 +362,15 @@ impl<'a, 'b> CloseCpiBuilder<'a, 'b> { let instruction = CloseCpi { __program: self.instruction.__program, - json_account: self + inscription_account: self .instruction - .json_account - .expect("json_account is not set"), + .inscription_account + .expect("inscription_account is not set"), - json_metadata_account: self + metadata_account: self .instruction - .json_metadata_account - .expect("json_metadata_account is not set"), + .metadata_account + .expect("metadata_account is not set"), payer: self.instruction.payer.expect("payer is not set"), @@ -385,8 +388,8 @@ impl<'a, 'b> CloseCpiBuilder<'a, 'b> { struct CloseCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - json_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, - json_metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + inscription_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. diff --git a/clients/rust/src/generated/instructions/initialize.rs b/clients/rust/src/generated/instructions/initialize.rs index 54d152e..01d3c43 100644 --- a/clients/rust/src/generated/instructions/initialize.rs +++ b/clients/rust/src/generated/instructions/initialize.rs @@ -11,9 +11,9 @@ use borsh::BorshSerialize; /// Accounts. pub struct Initialize { /// The account to store the metadata in. - pub json_account: solana_program::pubkey::Pubkey, - /// The account to store the json account's metadata in. - pub json_metadata_account: solana_program::pubkey::Pubkey, + pub inscription_account: solana_program::pubkey::Pubkey, + /// The account to store the inscription account's metadata in. + pub metadata_account: solana_program::pubkey::Pubkey, /// The account that will pay for the transaction and rent. pub payer: solana_program::pubkey::Pubkey, /// System program @@ -31,11 +31,11 @@ impl Initialize { ) -> solana_program::instruction::Instruction { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_account, + self.inscription_account, true, )); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_metadata_account, + self.metadata_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -49,7 +49,7 @@ impl Initialize { let data = InitializeInstructionData::new().try_to_vec().unwrap(); solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, } @@ -70,8 +70,8 @@ impl InitializeInstructionData { /// Instruction builder. #[derive(Default)] pub struct InitializeBuilder { - json_account: Option, - json_metadata_account: Option, + inscription_account: Option, + metadata_account: Option, payer: Option, system_program: Option, __remaining_accounts: Vec, @@ -83,17 +83,20 @@ impl InitializeBuilder { } /// The account to store the metadata in. #[inline(always)] - pub fn json_account(&mut self, json_account: solana_program::pubkey::Pubkey) -> &mut Self { - self.json_account = Some(json_account); + pub fn inscription_account( + &mut self, + inscription_account: solana_program::pubkey::Pubkey, + ) -> &mut Self { + self.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: solana_program::pubkey::Pubkey, + metadata_account: solana_program::pubkey::Pubkey, ) -> &mut Self { - self.json_metadata_account = Some(json_metadata_account); + self.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -130,10 +133,10 @@ impl InitializeBuilder { #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { let accounts = Initialize { - json_account: self.json_account.expect("json_account is not set"), - json_metadata_account: self - .json_metadata_account - .expect("json_metadata_account is not set"), + inscription_account: self + .inscription_account + .expect("inscription_account is not set"), + metadata_account: self.metadata_account.expect("metadata_account is not set"), payer: self.payer.expect("payer is not set"), system_program: self .system_program @@ -147,9 +150,9 @@ impl InitializeBuilder { /// `initialize` CPI accounts. pub struct InitializeCpiAccounts<'a, 'b> { /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program @@ -161,9 +164,9 @@ pub struct InitializeCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program @@ -177,8 +180,8 @@ impl<'a, 'b> InitializeCpi<'a, 'b> { ) -> Self { Self { __program: program, - json_account: accounts.json_account, - json_metadata_account: accounts.json_metadata_account, + inscription_account: accounts.inscription_account, + metadata_account: accounts.metadata_account, payer: accounts.payer, system_program: accounts.system_program, } @@ -218,11 +221,11 @@ impl<'a, 'b> InitializeCpi<'a, 'b> { ) -> solana_program::entrypoint::ProgramResult { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_account.key, + *self.inscription_account.key, true, )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_metadata_account.key, + *self.metadata_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -243,14 +246,14 @@ impl<'a, 'b> InitializeCpi<'a, 'b> { let data = InitializeInstructionData::new().try_to_vec().unwrap(); let instruction = solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, }; let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.json_account.clone()); - account_infos.push(self.json_metadata_account.clone()); + account_infos.push(self.inscription_account.clone()); + account_infos.push(self.metadata_account.clone()); account_infos.push(self.payer.clone()); account_infos.push(self.system_program.clone()); remaining_accounts @@ -274,8 +277,8 @@ impl<'a, 'b> InitializeCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { let instruction = Box::new(InitializeCpiBuilderInstruction { __program: program, - json_account: None, - json_metadata_account: None, + inscription_account: None, + metadata_account: None, payer: None, system_program: None, __remaining_accounts: Vec::new(), @@ -284,20 +287,20 @@ impl<'a, 'b> InitializeCpiBuilder<'a, 'b> { } /// The account to store the metadata in. #[inline(always)] - pub fn json_account( + pub fn inscription_account( &mut self, - json_account: &'b solana_program::account_info::AccountInfo<'a>, + inscription_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_account = Some(json_account); + self.instruction.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + metadata_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_metadata_account = Some(json_metadata_account); + self.instruction.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -359,15 +362,15 @@ impl<'a, 'b> InitializeCpiBuilder<'a, 'b> { let instruction = InitializeCpi { __program: self.instruction.__program, - json_account: self + inscription_account: self .instruction - .json_account - .expect("json_account is not set"), + .inscription_account + .expect("inscription_account is not set"), - json_metadata_account: self + metadata_account: self .instruction - .json_metadata_account - .expect("json_metadata_account is not set"), + .metadata_account + .expect("metadata_account is not set"), payer: self.instruction.payer.expect("payer is not set"), @@ -385,8 +388,8 @@ impl<'a, 'b> InitializeCpiBuilder<'a, 'b> { struct InitializeCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - json_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, - json_metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + inscription_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. diff --git a/clients/rust/src/generated/instructions/mod.rs b/clients/rust/src/generated/instructions/mod.rs index d4348b0..875fd1e 100644 --- a/clients/rust/src/generated/instructions/mod.rs +++ b/clients/rust/src/generated/instructions/mod.rs @@ -6,15 +6,15 @@ //! pub(crate) mod add_authority; -pub(crate) mod append_value; +pub(crate) mod clear_data; pub(crate) mod close; pub(crate) mod initialize; pub(crate) mod remove_authority; -pub(crate) mod set_value; +pub(crate) mod write_data; pub use self::add_authority::*; -pub use self::append_value::*; +pub use self::clear_data::*; pub use self::close::*; pub use self::initialize::*; pub use self::remove_authority::*; -pub use self::set_value::*; +pub use self::write_data::*; diff --git a/clients/rust/src/generated/instructions/remove_authority.rs b/clients/rust/src/generated/instructions/remove_authority.rs index a22d83e..99b4367 100644 --- a/clients/rust/src/generated/instructions/remove_authority.rs +++ b/clients/rust/src/generated/instructions/remove_authority.rs @@ -7,50 +7,44 @@ use borsh::BorshDeserialize; use borsh::BorshSerialize; -use solana_program::pubkey::Pubkey; /// Accounts. pub struct RemoveAuthority { /// The account to store the metadata's metadata in. - pub json_metadata_account: solana_program::pubkey::Pubkey, - /// The account that will pay for the transaction and rent. - pub payer: solana_program::pubkey::Pubkey, + pub metadata_account: solana_program::pubkey::Pubkey, + /// The authority paying and being removed. + pub authority: solana_program::pubkey::Pubkey, /// System program pub system_program: solana_program::pubkey::Pubkey, } impl RemoveAuthority { - pub fn instruction( - &self, - args: RemoveAuthorityInstructionArgs, - ) -> solana_program::instruction::Instruction { - self.instruction_with_remaining_accounts(args, &[]) + pub fn instruction(&self) -> solana_program::instruction::Instruction { + self.instruction_with_remaining_accounts(&[]) } #[allow(clippy::vec_init_then_push)] pub fn instruction_with_remaining_accounts( &self, - args: RemoveAuthorityInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { let mut accounts = Vec::with_capacity(3 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_metadata_account, + self.metadata_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - self.payer, true, + self.authority, + true, )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( self.system_program, false, )); accounts.extend_from_slice(remaining_accounts); - let mut data = RemoveAuthorityInstructionData::new().try_to_vec().unwrap(); - let mut args = args.try_to_vec().unwrap(); - data.append(&mut args); + let data = RemoveAuthorityInstructionData::new().try_to_vec().unwrap(); solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, } @@ -68,19 +62,12 @@ impl RemoveAuthorityInstructionData { } } -#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct RemoveAuthorityInstructionArgs { - pub authority: Pubkey, -} - /// Instruction builder. #[derive(Default)] pub struct RemoveAuthorityBuilder { - json_metadata_account: Option, - payer: Option, + metadata_account: Option, + authority: Option, system_program: Option, - authority: Option, __remaining_accounts: Vec, } @@ -90,17 +77,17 @@ impl RemoveAuthorityBuilder { } /// The account to store the metadata's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: solana_program::pubkey::Pubkey, + metadata_account: solana_program::pubkey::Pubkey, ) -> &mut Self { - self.json_metadata_account = Some(json_metadata_account); + self.metadata_account = Some(metadata_account); self } - /// The account that will pay for the transaction and rent. + /// The authority paying and being removed. #[inline(always)] - pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self { - self.payer = Some(payer); + pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self { + self.authority = Some(authority); self } /// `[optional account, default to '11111111111111111111111111111111']` @@ -110,11 +97,6 @@ impl RemoveAuthorityBuilder { self.system_program = Some(system_program); self } - #[inline(always)] - pub fn authority(&mut self, authority: Pubkey) -> &mut Self { - self.authority = Some(authority); - self - } /// Add an aditional account to the instruction. #[inline(always)] pub fn add_remaining_account( @@ -136,28 +118,23 @@ impl RemoveAuthorityBuilder { #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { let accounts = RemoveAuthority { - json_metadata_account: self - .json_metadata_account - .expect("json_metadata_account is not set"), - payer: self.payer.expect("payer is not set"), + metadata_account: self.metadata_account.expect("metadata_account is not set"), + authority: self.authority.expect("authority is not set"), system_program: self .system_program .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")), }; - let args = RemoveAuthorityInstructionArgs { - authority: self.authority.clone().expect("authority is not set"), - }; - accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) + accounts.instruction_with_remaining_accounts(&self.__remaining_accounts) } } /// `remove_authority` CPI accounts. pub struct RemoveAuthorityCpiAccounts<'a, 'b> { /// The account to store the metadata's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account that will pay for the transaction and rent. - pub payer: &'b solana_program::account_info::AccountInfo<'a>, + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The authority paying and being removed. + pub authority: &'b solana_program::account_info::AccountInfo<'a>, /// System program pub system_program: &'b solana_program::account_info::AccountInfo<'a>, } @@ -167,27 +144,23 @@ pub struct RemoveAuthorityCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, /// The account to store the metadata's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account that will pay for the transaction and rent. - pub payer: &'b solana_program::account_info::AccountInfo<'a>, + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The authority paying and being removed. + pub authority: &'b solana_program::account_info::AccountInfo<'a>, /// System program pub system_program: &'b solana_program::account_info::AccountInfo<'a>, - /// The arguments for the instruction. - pub __args: RemoveAuthorityInstructionArgs, } impl<'a, 'b> RemoveAuthorityCpi<'a, 'b> { pub fn new( program: &'b solana_program::account_info::AccountInfo<'a>, accounts: RemoveAuthorityCpiAccounts<'a, 'b>, - args: RemoveAuthorityInstructionArgs, ) -> Self { Self { __program: program, - json_metadata_account: accounts.json_metadata_account, - payer: accounts.payer, + metadata_account: accounts.metadata_account, + authority: accounts.authority, system_program: accounts.system_program, - __args: args, } } #[inline(always)] @@ -225,11 +198,11 @@ impl<'a, 'b> RemoveAuthorityCpi<'a, 'b> { ) -> solana_program::entrypoint::ProgramResult { let mut accounts = Vec::with_capacity(3 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_metadata_account.key, + *self.metadata_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.payer.key, + *self.authority.key, true, )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( @@ -243,19 +216,17 @@ impl<'a, 'b> RemoveAuthorityCpi<'a, 'b> { is_writable: remaining_account.2, }) }); - let mut data = RemoveAuthorityInstructionData::new().try_to_vec().unwrap(); - let mut args = self.__args.try_to_vec().unwrap(); - data.append(&mut args); + let data = RemoveAuthorityInstructionData::new().try_to_vec().unwrap(); let instruction = solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, }; let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.json_metadata_account.clone()); - account_infos.push(self.payer.clone()); + account_infos.push(self.metadata_account.clone()); + account_infos.push(self.authority.clone()); account_infos.push(self.system_program.clone()); remaining_accounts .iter() @@ -278,27 +249,29 @@ impl<'a, 'b> RemoveAuthorityCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { let instruction = Box::new(RemoveAuthorityCpiBuilderInstruction { __program: program, - json_metadata_account: None, - payer: None, - system_program: None, + metadata_account: None, authority: None, + system_program: None, __remaining_accounts: Vec::new(), }); Self { instruction } } /// The account to store the metadata's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + metadata_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_metadata_account = Some(json_metadata_account); + self.instruction.metadata_account = Some(metadata_account); self } - /// The account that will pay for the transaction and rent. + /// The authority paying and being removed. #[inline(always)] - pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { - self.instruction.payer = Some(payer); + pub fn authority( + &mut self, + authority: &'b solana_program::account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.authority = Some(authority); self } /// System program @@ -310,11 +283,6 @@ impl<'a, 'b> RemoveAuthorityCpiBuilder<'a, 'b> { self.instruction.system_program = Some(system_program); self } - #[inline(always)] - pub fn authority(&mut self, authority: Pubkey) -> &mut Self { - self.instruction.authority = Some(authority); - self - } /// Add an additional account to the instruction. #[inline(always)] pub fn add_remaining_account( @@ -356,28 +324,20 @@ impl<'a, 'b> RemoveAuthorityCpiBuilder<'a, 'b> { &self, signers_seeds: &[&[&[u8]]], ) -> solana_program::entrypoint::ProgramResult { - let args = RemoveAuthorityInstructionArgs { - authority: self - .instruction - .authority - .clone() - .expect("authority is not set"), - }; let instruction = RemoveAuthorityCpi { __program: self.instruction.__program, - json_metadata_account: self + metadata_account: self .instruction - .json_metadata_account - .expect("json_metadata_account is not set"), + .metadata_account + .expect("metadata_account is not set"), - payer: self.instruction.payer.expect("payer is not set"), + authority: self.instruction.authority.expect("authority is not set"), system_program: self .instruction .system_program .expect("system_program is not set"), - __args: args, }; instruction.invoke_signed_with_remaining_accounts( signers_seeds, @@ -388,10 +348,9 @@ impl<'a, 'b> RemoveAuthorityCpiBuilder<'a, 'b> { struct RemoveAuthorityCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - json_metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, - payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, + metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + authority: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, - authority: Option, /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. __remaining_accounts: Vec<( &'b solana_program::account_info::AccountInfo<'a>, diff --git a/clients/rust/src/generated/instructions/set_value.rs b/clients/rust/src/generated/instructions/write_data.rs similarity index 72% rename from clients/rust/src/generated/instructions/set_value.rs rename to clients/rust/src/generated/instructions/write_data.rs index 5cba543..edbe54f 100644 --- a/clients/rust/src/generated/instructions/set_value.rs +++ b/clients/rust/src/generated/instructions/write_data.rs @@ -9,37 +9,37 @@ use borsh::BorshDeserialize; use borsh::BorshSerialize; /// Accounts. -pub struct SetValue { +pub struct WriteData { /// The account to store the metadata in. - pub json_account: solana_program::pubkey::Pubkey, - /// The account to store the json account's metadata in. - pub json_metadata_account: solana_program::pubkey::Pubkey, + pub inscription_account: solana_program::pubkey::Pubkey, + /// The account to store the inscription account's metadata in. + pub metadata_account: solana_program::pubkey::Pubkey, /// The account that will pay for the transaction and rent. pub payer: solana_program::pubkey::Pubkey, /// System program pub system_program: solana_program::pubkey::Pubkey, } -impl SetValue { +impl WriteData { pub fn instruction( &self, - args: SetValueInstructionArgs, + args: WriteDataInstructionArgs, ) -> solana_program::instruction::Instruction { self.instruction_with_remaining_accounts(args, &[]) } #[allow(clippy::vec_init_then_push)] pub fn instruction_with_remaining_accounts( &self, - args: SetValueInstructionArgs, + args: WriteDataInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_account, + self.inscription_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - self.json_metadata_account, + self.metadata_account, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -50,12 +50,12 @@ impl SetValue { false, )); accounts.extend_from_slice(remaining_accounts); - let mut data = SetValueInstructionData::new().try_to_vec().unwrap(); + let mut data = WriteDataInstructionData::new().try_to_vec().unwrap(); let mut args = args.try_to_vec().unwrap(); data.append(&mut args); solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, } @@ -63,11 +63,11 @@ impl SetValue { } #[derive(BorshDeserialize, BorshSerialize)] -struct SetValueInstructionData { +struct WriteDataInstructionData { discriminator: u8, } -impl SetValueInstructionData { +impl WriteDataInstructionData { fn new() -> Self { Self { discriminator: 2 } } @@ -75,38 +75,41 @@ impl SetValueInstructionData { #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct SetValueInstructionArgs { - pub value: String, +pub struct WriteDataInstructionArgs { + pub value: Vec, } /// Instruction builder. #[derive(Default)] -pub struct SetValueBuilder { - json_account: Option, - json_metadata_account: Option, +pub struct WriteDataBuilder { + inscription_account: Option, + metadata_account: Option, payer: Option, system_program: Option, - value: Option, + value: Option>, __remaining_accounts: Vec, } -impl SetValueBuilder { +impl WriteDataBuilder { pub fn new() -> Self { Self::default() } /// The account to store the metadata in. #[inline(always)] - pub fn json_account(&mut self, json_account: solana_program::pubkey::Pubkey) -> &mut Self { - self.json_account = Some(json_account); + pub fn inscription_account( + &mut self, + inscription_account: solana_program::pubkey::Pubkey, + ) -> &mut Self { + self.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: solana_program::pubkey::Pubkey, + metadata_account: solana_program::pubkey::Pubkey, ) -> &mut Self { - self.json_metadata_account = Some(json_metadata_account); + self.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -123,7 +126,7 @@ impl SetValueBuilder { self } #[inline(always)] - pub fn value(&mut self, value: String) -> &mut Self { + pub fn value(&mut self, value: Vec) -> &mut Self { self.value = Some(value); self } @@ -147,17 +150,17 @@ impl SetValueBuilder { } #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { - let accounts = SetValue { - json_account: self.json_account.expect("json_account is not set"), - json_metadata_account: self - .json_metadata_account - .expect("json_metadata_account is not set"), + let accounts = WriteData { + inscription_account: self + .inscription_account + .expect("inscription_account is not set"), + metadata_account: self.metadata_account.expect("metadata_account is not set"), payer: self.payer.expect("payer is not set"), system_program: self .system_program .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")), }; - let args = SetValueInstructionArgs { + let args = WriteDataInstructionArgs { value: self.value.clone().expect("value is not set"), }; @@ -165,44 +168,44 @@ impl SetValueBuilder { } } -/// `set_value` CPI accounts. -pub struct SetValueCpiAccounts<'a, 'b> { +/// `write_data` CPI accounts. +pub struct WriteDataCpiAccounts<'a, 'b> { /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program pub system_program: &'b solana_program::account_info::AccountInfo<'a>, } -/// `set_value` CPI instruction. -pub struct SetValueCpi<'a, 'b> { +/// `write_data` CPI instruction. +pub struct WriteDataCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, /// The account to store the metadata in. - pub json_account: &'b solana_program::account_info::AccountInfo<'a>, - /// The account to store the json account's metadata in. - pub json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + pub inscription_account: &'b solana_program::account_info::AccountInfo<'a>, + /// The account to store the inscription account's metadata in. + pub metadata_account: &'b solana_program::account_info::AccountInfo<'a>, /// The account that will pay for the transaction and rent. pub payer: &'b solana_program::account_info::AccountInfo<'a>, /// System program pub system_program: &'b solana_program::account_info::AccountInfo<'a>, /// The arguments for the instruction. - pub __args: SetValueInstructionArgs, + pub __args: WriteDataInstructionArgs, } -impl<'a, 'b> SetValueCpi<'a, 'b> { +impl<'a, 'b> WriteDataCpi<'a, 'b> { pub fn new( program: &'b solana_program::account_info::AccountInfo<'a>, - accounts: SetValueCpiAccounts<'a, 'b>, - args: SetValueInstructionArgs, + accounts: WriteDataCpiAccounts<'a, 'b>, + args: WriteDataInstructionArgs, ) -> Self { Self { __program: program, - json_account: accounts.json_account, - json_metadata_account: accounts.json_metadata_account, + inscription_account: accounts.inscription_account, + metadata_account: accounts.metadata_account, payer: accounts.payer, system_program: accounts.system_program, __args: args, @@ -243,11 +246,11 @@ impl<'a, 'b> SetValueCpi<'a, 'b> { ) -> solana_program::entrypoint::ProgramResult { let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_account.key, + *self.inscription_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.json_metadata_account.key, + *self.metadata_account.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( @@ -265,19 +268,19 @@ impl<'a, 'b> SetValueCpi<'a, 'b> { is_writable: remaining_account.2, }) }); - let mut data = SetValueInstructionData::new().try_to_vec().unwrap(); + let mut data = WriteDataInstructionData::new().try_to_vec().unwrap(); let mut args = self.__args.try_to_vec().unwrap(); data.append(&mut args); let instruction = solana_program::instruction::Instruction { - program_id: crate::MPL_JSON_ID, + program_id: crate::MPL_INSCRIPTION_ID, accounts, data, }; let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.json_account.clone()); - account_infos.push(self.json_metadata_account.clone()); + account_infos.push(self.inscription_account.clone()); + account_infos.push(self.metadata_account.clone()); account_infos.push(self.payer.clone()); account_infos.push(self.system_program.clone()); remaining_accounts @@ -292,17 +295,17 @@ impl<'a, 'b> SetValueCpi<'a, 'b> { } } -/// `set_value` CPI instruction builder. -pub struct SetValueCpiBuilder<'a, 'b> { - instruction: Box>, +/// `write_data` CPI instruction builder. +pub struct WriteDataCpiBuilder<'a, 'b> { + instruction: Box>, } -impl<'a, 'b> SetValueCpiBuilder<'a, 'b> { +impl<'a, 'b> WriteDataCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { - let instruction = Box::new(SetValueCpiBuilderInstruction { + let instruction = Box::new(WriteDataCpiBuilderInstruction { __program: program, - json_account: None, - json_metadata_account: None, + inscription_account: None, + metadata_account: None, payer: None, system_program: None, value: None, @@ -312,20 +315,20 @@ impl<'a, 'b> SetValueCpiBuilder<'a, 'b> { } /// The account to store the metadata in. #[inline(always)] - pub fn json_account( + pub fn inscription_account( &mut self, - json_account: &'b solana_program::account_info::AccountInfo<'a>, + inscription_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_account = Some(json_account); + self.instruction.inscription_account = Some(inscription_account); self } - /// The account to store the json account's metadata in. + /// The account to store the inscription account's metadata in. #[inline(always)] - pub fn json_metadata_account( + pub fn metadata_account( &mut self, - json_metadata_account: &'b solana_program::account_info::AccountInfo<'a>, + metadata_account: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.json_metadata_account = Some(json_metadata_account); + self.instruction.metadata_account = Some(metadata_account); self } /// The account that will pay for the transaction and rent. @@ -344,7 +347,7 @@ impl<'a, 'b> SetValueCpiBuilder<'a, 'b> { self } #[inline(always)] - pub fn value(&mut self, value: String) -> &mut Self { + pub fn value(&mut self, value: Vec) -> &mut Self { self.instruction.value = Some(value); self } @@ -389,21 +392,21 @@ impl<'a, 'b> SetValueCpiBuilder<'a, 'b> { &self, signers_seeds: &[&[&[u8]]], ) -> solana_program::entrypoint::ProgramResult { - let args = SetValueInstructionArgs { + let args = WriteDataInstructionArgs { value: self.instruction.value.clone().expect("value is not set"), }; - let instruction = SetValueCpi { + let instruction = WriteDataCpi { __program: self.instruction.__program, - json_account: self + inscription_account: self .instruction - .json_account - .expect("json_account is not set"), + .inscription_account + .expect("inscription_account is not set"), - json_metadata_account: self + metadata_account: self .instruction - .json_metadata_account - .expect("json_metadata_account is not set"), + .metadata_account + .expect("metadata_account is not set"), payer: self.instruction.payer.expect("payer is not set"), @@ -420,13 +423,13 @@ impl<'a, 'b> SetValueCpiBuilder<'a, 'b> { } } -struct SetValueCpiBuilderInstruction<'a, 'b> { +struct WriteDataCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - json_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, - json_metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + inscription_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, + metadata_account: Option<&'b solana_program::account_info::AccountInfo<'a>>, payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, - value: Option, + value: Option>, /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. __remaining_accounts: Vec<( &'b solana_program::account_info::AccountInfo<'a>, diff --git a/clients/rust/src/generated/programs.rs b/clients/rust/src/generated/programs.rs index 70593dc..eaf252f 100644 --- a/clients/rust/src/generated/programs.rs +++ b/clients/rust/src/generated/programs.rs @@ -7,5 +7,5 @@ use solana_program::{pubkey, pubkey::Pubkey}; -/// `mpl_json` program ID. -pub const MPL_JSON_ID: Pubkey = pubkey!("JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa"); +/// `mpl_inscription` program ID. +pub const MPL_INSCRIPTION_ID: Pubkey = pubkey!("JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa"); diff --git a/clients/rust/src/generated/types/key.rs b/clients/rust/src/generated/types/key.rs index ef310f4..5f07f1f 100644 --- a/clients/rust/src/generated/types/key.rs +++ b/clients/rust/src/generated/types/key.rs @@ -12,5 +12,5 @@ use borsh::BorshSerialize; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Key { Uninitialized, - JsonMetadataAccount, + InscriptionMetadataAccount, } diff --git a/clients/rust/src/lib.rs b/clients/rust/src/lib.rs index 653086e..038e0b7 100644 --- a/clients/rust/src/lib.rs +++ b/clients/rust/src/lib.rs @@ -1,4 +1,4 @@ mod generated; -pub use generated::programs::MPL_JSON_ID as ID; +pub use generated::programs::mpl_inscription_ID as ID; pub use generated::*; diff --git a/clients/rust/tests/create.rs b/clients/rust/tests/create.rs index 7c86199..94e65d7 100644 --- a/clients/rust/tests/create.rs +++ b/clients/rust/tests/create.rs @@ -1,7 +1,7 @@ #![cfg(feature = "test-sbf")] use borsh::BorshDeserialize; -use mpl_json::{accounts::MyAccount, instructions::CreateBuilder}; +use mpl_inscription::{accounts::MyAccount, instructions::CreateBuilder}; use solana_program_test::{tokio, ProgramTest}; use solana_sdk::{ signature::{Keypair, Signer}, @@ -10,7 +10,7 @@ use solana_sdk::{ #[tokio::test] async fn create() { - let mut context = ProgramTest::new("mpl_json", mpl_json::ID, None) + let mut context = ProgramTest::new("mpl_inscription", mpl_inscription::ID, None) .start_with_context() .await; diff --git a/configs/kinobi.cjs b/configs/kinobi.cjs index 6c6ffc8..a38ad4f 100755 --- a/configs/kinobi.cjs +++ b/configs/kinobi.cjs @@ -6,23 +6,23 @@ const clientDir = path.join(__dirname, "..", "clients"); const idlDir = path.join(__dirname, "..", "idls"); // Instanciate Kinobi. -const kinobi = k.createFromIdls([path.join(idlDir, "mpl_json.json")]); +const kinobi = k.createFromIdls([path.join(idlDir, "mpl_inscription.json")]); // Update programs. kinobi.update( new k.UpdateProgramsVisitor({ - mplJsonProgram: { name: "mplJson" }, + MplInscriptionProgram: { name: "MplInscription" }, }) ); // Update accounts. kinobi.update( new k.UpdateAccountsVisitor({ - jsonMetadata: { + inscriptionMetadata: { seeds: [ - k.stringConstantSeed("JSON"), + k.stringConstantSeed("Inscription"), k.programSeed(), - k.publicKeySeed("jsonAccount", "The address of the JSON Account"), + k.publicKeySeed("inscriptionAccount", "The address of the Inscription Account"), ], }, }) @@ -42,7 +42,7 @@ const key = (name) => ({ field: "key", value: k.vEnum("Key", name) }); kinobi.update( new k.SetAccountDiscriminatorFromFieldVisitor({ // myAccount: key("MyAccount"), - jsonMetadataAccount: key("JsonMetadataAccount"), + inscriptionMetadataAccount: key("InscriptionMetadataAccount"), }) ); diff --git a/configs/shank.cjs b/configs/shank.cjs index 2c8efb9..8d483de 100644 --- a/configs/shank.cjs +++ b/configs/shank.cjs @@ -7,9 +7,9 @@ const programDir = path.join(__dirname, "..", "programs"); generateIdl({ generator: "shank", - programName: "mpl_json", + programName: "mpl_inscription", programId: "JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa", idlDir, binaryInstallDir, - programDir: path.join(programDir, "mpl-json"), + programDir: path.join(programDir, "mpl-inscription"), }); diff --git a/configs/validator.cjs b/configs/validator.cjs index 78f73d1..473d0f1 100755 --- a/configs/validator.cjs +++ b/configs/validator.cjs @@ -13,7 +13,7 @@ module.exports = { { label: "Mpl Json", programId: "JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa", - deployPath: getProgram("mpl_json.so"), + deployPath: getProgram("mpl_inscription.so"), }, // Below are external programs that should be included in the local validator. // You may configure which ones to fetch from the cluster when building diff --git a/idls/mpl_json.json b/idls/mpl_inscription.json similarity index 78% rename from idls/mpl_json.json rename to idls/mpl_inscription.json index 6b726f7..86d3370 100644 --- a/idls/mpl_json.json +++ b/idls/mpl_inscription.json @@ -1,12 +1,12 @@ { "version": "0.1.0", - "name": "mpl_json", + "name": "mpl_inscription", "instructions": [ { "name": "Initialize", "accounts": [ { - "name": "jsonAccount", + "name": "inscriptionAccount", "isMut": true, "isSigner": true, "docs": [ @@ -14,11 +14,11 @@ ] }, { - "name": "jsonMetadataAccount", + "name": "metadataAccount", "isMut": true, "isSigner": false, "docs": [ - "The account to store the json account's metadata in." + "The account to store the inscription account's metadata in." ] }, { @@ -48,7 +48,7 @@ "name": "Close", "accounts": [ { - "name": "jsonAccount", + "name": "inscriptionAccount", "isMut": true, "isSigner": false, "docs": [ @@ -56,11 +56,11 @@ ] }, { - "name": "jsonMetadataAccount", + "name": "metadataAccount", "isMut": true, "isSigner": false, "docs": [ - "The account to store the json account's metadata in." + "The account to store the inscription account's metadata in." ] }, { @@ -87,10 +87,10 @@ } }, { - "name": "SetValue", + "name": "WriteData", "accounts": [ { - "name": "jsonAccount", + "name": "inscriptionAccount", "isMut": true, "isSigner": false, "docs": [ @@ -98,11 +98,11 @@ ] }, { - "name": "jsonMetadataAccount", + "name": "metadataAccount", "isMut": true, "isSigner": false, "docs": [ - "The account to store the json account's metadata in." + "The account to store the inscription account's metadata in." ] }, { @@ -124,9 +124,9 @@ ], "args": [ { - "name": "setValueArgs", + "name": "writeDataArgs", "type": { - "defined": "SetValueArgs" + "defined": "WriteDataArgs" } } ], @@ -136,10 +136,10 @@ } }, { - "name": "AppendValue", + "name": "ClearData", "accounts": [ { - "name": "jsonAccount", + "name": "inscriptionAccount", "isMut": true, "isSigner": false, "docs": [ @@ -147,11 +147,11 @@ ] }, { - "name": "jsonMetadataAccount", + "name": "metadataAccount", "isMut": true, "isSigner": false, "docs": [ - "The account to store the json account's metadata in." + "The account to store the inscription account's metadata in." ] }, { @@ -171,14 +171,7 @@ ] } ], - "args": [ - { - "name": "appendValueArgs", - "type": { - "defined": "AppendValueArgs" - } - } - ], + "args": [], "discriminant": { "type": "u8", "value": 3 @@ -188,7 +181,7 @@ "name": "AddAuthority", "accounts": [ { - "name": "jsonMetadataAccount", + "name": "metadataAccount", "isMut": true, "isSigner": false, "docs": [ @@ -229,7 +222,7 @@ "name": "RemoveAuthority", "accounts": [ { - "name": "jsonMetadataAccount", + "name": "metadataAccount", "isMut": true, "isSigner": false, "docs": [ @@ -237,11 +230,11 @@ ] }, { - "name": "payer", + "name": "authority", "isMut": true, "isSigner": true, "docs": [ - "The account that will pay for the transaction and rent." + "The authority paying and being removed." ] }, { @@ -253,14 +246,7 @@ ] } ], - "args": [ - { - "name": "removeAuthorityArgs", - "type": { - "defined": "RemoveAuthorityArgs" - } - } - ], + "args": [], "discriminant": { "type": "u8", "value": 5 @@ -269,7 +255,7 @@ ], "accounts": [ { - "name": "JsonMetadata", + "name": "InscriptionMetadata", "type": { "kind": "struct", "fields": [ @@ -284,11 +270,13 @@ "type": "u8" }, { - "name": "mutable", - "type": "bool" + "name": "inscriptionNumber", + "type": { + "option": "u64" + } }, { - "name": "authorities", + "name": "updateAuthorities", "type": { "vec": "publicKey" } @@ -299,25 +287,13 @@ ], "types": [ { - "name": "SetValueArgs", - "type": { - "kind": "struct", - "fields": [ - { - "name": "value", - "type": "string" - } - ] - } - }, - { - "name": "AppendValueArgs", + "name": "WriteDataArgs", "type": { "kind": "struct", "fields": [ { "name": "value", - "type": "string" + "type": "bytes" } ] } @@ -334,18 +310,6 @@ ] } }, - { - "name": "RemoveAuthorityArgs", - "type": { - "kind": "struct", - "fields": [ - { - "name": "authority", - "type": "publicKey" - } - ] - } - }, { "name": "Key", "type": { @@ -355,7 +319,7 @@ "name": "Uninitialized" }, { - "name": "JsonMetadataAccount" + "name": "InscriptionMetadataAccount" } ] } @@ -396,6 +360,11 @@ "code": 6, "name": "InvalidAuthority", "msg": "The payer does not have authority to perform this action." + }, + { + "code": 7, + "name": "NumericalOverflow", + "msg": "Numerical Overflow" } ], "metadata": { diff --git a/programs/mpl-json/Cargo.lock b/programs/mpl-inscription/Cargo.lock similarity index 99% rename from programs/mpl-json/Cargo.lock rename to programs/mpl-inscription/Cargo.lock index fd7464d..efccf97 100644 --- a/programs/mpl-json/Cargo.lock +++ b/programs/mpl-inscription/Cargo.lock @@ -1035,7 +1035,7 @@ dependencies = [ ] [[package]] -name = "mpl-json" +name = "mpl-inscription" version = "0.1.0" dependencies = [ "borsh 0.10.3", diff --git a/programs/mpl-json/Cargo.toml b/programs/mpl-inscription/Cargo.toml similarity index 93% rename from programs/mpl-json/Cargo.toml rename to programs/mpl-inscription/Cargo.toml index 598d44d..09281be 100644 --- a/programs/mpl-json/Cargo.toml +++ b/programs/mpl-inscription/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mpl-json" +name = "mpl-inscription" version = "0.1.0" edition = "2021" readme = "./README.md" diff --git a/programs/mpl-json/README.md b/programs/mpl-inscription/README.md similarity index 100% rename from programs/mpl-json/README.md rename to programs/mpl-inscription/README.md diff --git a/programs/mpl-json/rustfmt.toml b/programs/mpl-inscription/rustfmt.toml similarity index 100% rename from programs/mpl-json/rustfmt.toml rename to programs/mpl-inscription/rustfmt.toml diff --git a/programs/mpl-json/src/entrypoint.rs b/programs/mpl-inscription/src/entrypoint.rs similarity index 84% rename from programs/mpl-json/src/entrypoint.rs rename to programs/mpl-inscription/src/entrypoint.rs index 875353a..96255a6 100644 --- a/programs/mpl-json/src/entrypoint.rs +++ b/programs/mpl-inscription/src/entrypoint.rs @@ -3,7 +3,7 @@ use solana_program::{ program_error::PrintProgramError, pubkey::Pubkey, }; -use crate::{error::MplJsonError, processor}; +use crate::{error::MplInscriptionError, processor}; entrypoint!(process_instruction); fn process_instruction<'a>( @@ -15,7 +15,7 @@ fn process_instruction<'a>( processor::Processor::process_instruction(program_id, accounts, instruction_data) { // catch the error so we can print it - error.print::(); + error.print::(); return Err(error); } Ok(()) diff --git a/programs/mpl-json/src/error.rs b/programs/mpl-inscription/src/error.rs similarity index 81% rename from programs/mpl-json/src/error.rs rename to programs/mpl-inscription/src/error.rs index 4c4856d..3e3f971 100644 --- a/programs/mpl-json/src/error.rs +++ b/programs/mpl-inscription/src/error.rs @@ -7,7 +7,7 @@ use solana_program::{ use thiserror::Error; #[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)] -pub enum MplJsonError { +pub enum MplInscriptionError { /// 0 - The account passed in was already initialized. #[error("The account has already been initialized")] AlreadyInitialized, @@ -35,21 +35,25 @@ pub enum MplJsonError { /// 6 - The payer does not have authority to perform this action. #[error("The payer does not have authority to perform this action.")] InvalidAuthority, + + /// 7 - Numerical Overflow + #[error("Numerical Overflow")] + NumericalOverflow, } -impl PrintProgramError for MplJsonError { +impl PrintProgramError for MplInscriptionError { fn print(&self) { msg!(&self.to_string()); } } -impl From for ProgramError { - fn from(e: MplJsonError) -> Self { +impl From for ProgramError { + fn from(e: MplInscriptionError) -> Self { ProgramError::Custom(e as u32) } } -impl DecodeError for MplJsonError { +impl DecodeError for MplInscriptionError { fn type_of() -> &'static str { "Mpl Json Error" } diff --git a/programs/mpl-inscription/src/instruction/mod.rs b/programs/mpl-inscription/src/instruction/mod.rs new file mode 100644 index 0000000..620f692 --- /dev/null +++ b/programs/mpl-inscription/src/instruction/mod.rs @@ -0,0 +1,59 @@ +use borsh::{BorshDeserialize, BorshSerialize}; +use shank::{ShankContext, ShankInstruction}; +use solana_program::pubkey::Pubkey; + +#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, ShankContext, ShankInstruction)] +#[rustfmt::skip] +pub enum MplInscriptionInstruction { + /// Initialize the Inscription and Metadata accounts + #[account(0, writable, signer, name="inscription_account", desc = "The account to store the metadata in.")] + #[account(1, writable, name="metadata_account", desc = "The account to store the inscription account's metadata in.")] + #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] + #[account(3, name="system_program", desc = "System program")] + Initialize, + + /// Close the Inscription and Metadata accounts + #[account(0, writable, name="inscription_account", desc = "The account to store the metadata in.")] + #[account(1, writable, name="metadata_account", desc = "The account to store the inscription account's metadata in.")] + #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] + #[account(3, name="system_program", desc = "System program")] + Close, + + /// Write data to the inscription account + #[account(0, writable, name="inscription_account", desc = "The account to store the metadata in.")] + #[account(1, writable, name="metadata_account", desc = "The account to store the inscription account's metadata in.")] + #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] + #[account(3, name="system_program", desc = "System program")] + WriteData(WriteDataArgs), + + /// Clear the inscription account + #[account(0, writable, name="inscription_account", desc = "The account to store the metadata in.")] + #[account(1, writable, name="metadata_account", desc = "The account to store the inscription account's metadata in.")] + #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] + #[account(3, name="system_program", desc = "System program")] + ClearData, + + /// Add an update authority to the Inscription + #[account(0, writable, name="metadata_account", desc = "The account to store the metadata's metadata in.")] + #[account(1, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] + #[account(2, name="system_program", desc = "System program")] + AddAuthority(AddAuthorityArgs), + + /// Remove an update authority from the Inscription account + #[account(0, writable, name="metadata_account", desc = "The account to store the metadata's metadata in.")] + #[account(1, writable, signer, name="authority", desc="The authority paying and being removed.")] + #[account(2, name="system_program", desc = "System program")] + RemoveAuthority, +} + +#[repr(C)] +#[derive(PartialEq, Eq, Debug, Clone, BorshSerialize, BorshDeserialize)] +pub struct WriteDataArgs { + pub value: Vec, +} + +#[repr(C)] +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] +pub struct AddAuthorityArgs { + pub new_authority: Pubkey, +} diff --git a/programs/mpl-json/src/lib.rs b/programs/mpl-inscription/src/lib.rs similarity index 100% rename from programs/mpl-json/src/lib.rs rename to programs/mpl-inscription/src/lib.rs diff --git a/programs/mpl-json/src/processor/add_authority.rs b/programs/mpl-inscription/src/processor/add_authority.rs similarity index 51% rename from programs/mpl-json/src/processor/add_authority.rs rename to programs/mpl-inscription/src/processor/add_authority.rs index 98dba79..cc16d7d 100644 --- a/programs/mpl-json/src/processor/add_authority.rs +++ b/programs/mpl-inscription/src/processor/add_authority.rs @@ -6,9 +6,9 @@ use solana_program::{ }; use crate::{ - error::MplJsonError, + error::MplInscriptionError, instruction::{accounts::AddAuthorityAccounts, AddAuthorityArgs}, - state::JsonMetadata, + state::InscriptionMetadata, }; pub(crate) fn process_add_authority<'a>( @@ -18,41 +18,46 @@ pub(crate) fn process_add_authority<'a>( let ctx = &AddAuthorityAccounts::context(accounts)?; // Check that the account isn't already initialized. - if (ctx.accounts.json_metadata_account.owner != &crate::ID) - || ctx.accounts.json_metadata_account.data_is_empty() + if (ctx.accounts.metadata_account.owner != &crate::ID) + || ctx.accounts.metadata_account.data_is_empty() { - return Err(MplJsonError::NotInitialized.into()); + return Err(MplInscriptionError::NotInitialized.into()); } - let mut json_metadata = - JsonMetadata::try_from_slice(&ctx.accounts.json_metadata_account.data.borrow())?; + let mut inscription_metadata = + InscriptionMetadata::try_from_slice(&ctx.accounts.metadata_account.data.borrow())?; // The payer and authority must sign. assert_signer(ctx.accounts.payer)?; - if !json_metadata.authorities.contains(ctx.accounts.payer.key) { - return Err(MplJsonError::InvalidAuthority.into()); + if !inscription_metadata + .update_authorities + .contains(ctx.accounts.payer.key) + { + return Err(MplInscriptionError::InvalidAuthority.into()); } if ctx.accounts.system_program.key != &system_program::ID { - return Err(MplJsonError::InvalidSystemProgram.into()); + return Err(MplInscriptionError::InvalidSystemProgram.into()); } // Add the new authority. - json_metadata.authorities.push(args.new_authority); + inscription_metadata + .update_authorities + .push(args.new_authority); - // Write the updated JSON metadata account back to the account. - let serialized_data = json_metadata.try_to_vec()?; + // Write the updated inscription metadata account back to the account. + let serialized_data = inscription_metadata.try_to_vec()?; // Resize the account to fit the new authority. resize_or_reallocate_account_raw( - ctx.accounts.json_metadata_account, + ctx.accounts.metadata_account, ctx.accounts.payer, ctx.accounts.system_program, serialized_data.len(), )?; - // Write the JSON metadata to the JSON metadata account. + // Write the inscription metadata to the metadata account. sol_memcpy( - &mut ctx.accounts.json_metadata_account.try_borrow_mut_data()?, + &mut ctx.accounts.metadata_account.try_borrow_mut_data()?, &serialized_data, serialized_data.len(), ); diff --git a/programs/mpl-inscription/src/processor/clear_data.rs b/programs/mpl-inscription/src/processor/clear_data.rs new file mode 100644 index 0000000..4311741 --- /dev/null +++ b/programs/mpl-inscription/src/processor/clear_data.rs @@ -0,0 +1,75 @@ +use borsh::BorshDeserialize; +use mpl_utils::{assert_derivation, assert_signer, resize_or_reallocate_account_raw}; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memset, + system_program, +}; + +use crate::{ + error::MplInscriptionError, + instruction::accounts::WriteDataAccounts, + state::{InscriptionMetadata, INITIAL_SIZE, PREFIX}, +}; + +pub(crate) fn process_clear_data<'a>(accounts: &'a [AccountInfo<'a>]) -> ProgramResult { + let ctx = &mut WriteDataAccounts::context(accounts)?; + + // Check that the inscription account is already initialized. + if (ctx.accounts.inscription_account.owner != &crate::ID) + || ctx.accounts.inscription_account.data_is_empty() + { + return Err(MplInscriptionError::NotInitialized.into()); + } + + // Check that the metadata account is already initialized. + if ctx.accounts.metadata_account.owner != &crate::ID { + return Err(MplInscriptionError::NotInitialized.into()); + } + let inscription_metadata = + InscriptionMetadata::try_from_slice(&ctx.accounts.metadata_account.data.borrow())?; + + // Verify that the derived address is correct for the metadata account. + let bump = assert_derivation( + &crate::ID, + ctx.accounts.metadata_account, + &[ + PREFIX.as_bytes(), + crate::ID.as_ref(), + ctx.accounts.inscription_account.key.as_ref(), + ], + MplInscriptionError::MetadataDerivedKeyInvalid, + )?; + if bump != inscription_metadata.bump { + return Err(MplInscriptionError::MetadataDerivedKeyInvalid.into()); + } + + // The payer and authority must sign. + assert_signer(ctx.accounts.payer)?; + if !inscription_metadata + .update_authorities + .contains(ctx.accounts.payer.key) + { + return Err(MplInscriptionError::InvalidAuthority.into()); + } + + if ctx.accounts.system_program.key != &system_program::ID { + return Err(MplInscriptionError::InvalidSystemProgram.into()); + } + + // Resize the account to fit the new authority. + resize_or_reallocate_account_raw( + ctx.accounts.inscription_account, + ctx.accounts.payer, + ctx.accounts.system_program, + INITIAL_SIZE, + )?; + + // Write the inscription metadata to the metadata account. + sol_memset( + &mut ctx.accounts.inscription_account.try_borrow_mut_data()?, + 0, + ctx.accounts.inscription_account.data_len(), + ); + + Ok(()) +} diff --git a/programs/mpl-inscription/src/processor/close.rs b/programs/mpl-inscription/src/processor/close.rs new file mode 100644 index 0000000..14a8807 --- /dev/null +++ b/programs/mpl-inscription/src/processor/close.rs @@ -0,0 +1,63 @@ +use borsh::BorshDeserialize; +use mpl_utils::{assert_derivation, assert_signer, close_account_raw}; +use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, system_program}; + +use crate::{ + error::MplInscriptionError, + instruction::accounts::CloseAccounts, + state::{InscriptionMetadata, PREFIX}, +}; + +pub(crate) fn process_close<'a>(accounts: &'a [AccountInfo<'a>]) -> ProgramResult { + let ctx = &CloseAccounts::context(accounts)?; + + // Check that the account isn't already initialized. + if (ctx.accounts.inscription_account.owner != &crate::ID) + || ctx.accounts.inscription_account.data_is_empty() + { + return Err(MplInscriptionError::NotInitialized.into()); + } + + // Check that the account isn't already initialized. + if (ctx.accounts.metadata_account.owner != &crate::ID) + || ctx.accounts.metadata_account.data_is_empty() + { + return Err(MplInscriptionError::NotInitialized.into()); + } + let inscription_metadata = + InscriptionMetadata::try_from_slice(&ctx.accounts.metadata_account.data.borrow())?; + + // Verify that the derived address is correct for the metadata account. + let bump = assert_derivation( + &crate::ID, + ctx.accounts.metadata_account, + &[ + PREFIX.as_bytes(), + crate::ID.as_ref(), + ctx.accounts.inscription_account.key.as_ref(), + ], + MplInscriptionError::MetadataDerivedKeyInvalid, + )?; + if bump != inscription_metadata.bump { + return Err(MplInscriptionError::MetadataDerivedKeyInvalid.into()); + } + + // The payer and authority must sign. + assert_signer(ctx.accounts.payer)?; + if !inscription_metadata + .update_authorities + .contains(ctx.accounts.payer.key) + { + return Err(MplInscriptionError::InvalidAuthority.into()); + } + + if ctx.accounts.system_program.key != &system_program::ID { + return Err(MplInscriptionError::InvalidSystemProgram.into()); + } + + // Close both accounts + close_account_raw(ctx.accounts.payer, ctx.accounts.inscription_account)?; + close_account_raw(ctx.accounts.payer, ctx.accounts.metadata_account)?; + + Ok(()) +} diff --git a/programs/mpl-inscription/src/processor/initialize.rs b/programs/mpl-inscription/src/processor/initialize.rs new file mode 100644 index 0000000..f350bfb --- /dev/null +++ b/programs/mpl-inscription/src/processor/initialize.rs @@ -0,0 +1,100 @@ +use borsh::BorshSerialize; +use mpl_utils::{assert_derivation, assert_signer, create_or_allocate_account_raw}; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program::invoke, + program_memory::sol_memcpy, rent::Rent, system_instruction, system_program, sysvar::Sysvar, +}; + +use crate::{ + error::MplInscriptionError, + instruction::accounts::InitializeAccounts, + state::{InscriptionMetadata, Key, INITIAL_SIZE, PREFIX}, +}; + +pub(crate) fn process_initialize<'a>(accounts: &'a [AccountInfo<'a>]) -> ProgramResult { + let ctx = &InitializeAccounts::context(accounts)?; + + // Check that the account isn't already initialized. + if (ctx.accounts.inscription_account.owner != &system_program::ID) + || !ctx.accounts.inscription_account.data_is_empty() + { + return Err(MplInscriptionError::AlreadyInitialized.into()); + } + + // Check that the account isn't already initialized. + if (ctx.accounts.metadata_account.owner != &system_program::ID) + || !ctx.accounts.metadata_account.data_is_empty() + { + return Err(MplInscriptionError::AlreadyInitialized.into()); + } + // Verify that the derived address is correct for the metadata account. + let bump = assert_derivation( + &crate::ID, + ctx.accounts.metadata_account, + &[ + PREFIX.as_bytes(), + crate::ID.as_ref(), + ctx.accounts.inscription_account.key.as_ref(), + ], + MplInscriptionError::MetadataDerivedKeyInvalid, + )?; + + // The payer and authority must sign. + assert_signer(ctx.accounts.payer)?; + + if ctx.accounts.system_program.key != &system_program::ID { + return Err(MplInscriptionError::InvalidSystemProgram.into()); + } + + // Initialize the inscription metadata account. + let rent = Rent::get()?; + let rent_amount = rent.minimum_balance(INITIAL_SIZE); + invoke( + &system_instruction::create_account( + ctx.accounts.payer.key, + ctx.accounts.inscription_account.key, + rent_amount, + 0, + &crate::ID, + ), + &[ + ctx.accounts.payer.clone(), + ctx.accounts.inscription_account.clone(), + ctx.accounts.system_program.clone(), + ], + )?; + + // Initialize the inscription metadata. + let inscription_metadata = InscriptionMetadata { + key: Key::InscriptionMetadataAccount, + bump, + update_authorities: vec![*ctx.accounts.payer.key], + inscription_number: None, + }; + + let serialized_metadata = &inscription_metadata.try_to_vec()?; + + // Initialize the inscription metadata account. + create_or_allocate_account_raw( + crate::ID, + ctx.accounts.metadata_account, + ctx.accounts.system_program, + ctx.accounts.payer, + serialized_metadata.len(), + &[ + PREFIX.as_bytes(), + crate::ID.as_ref(), + ctx.accounts.inscription_account.key.as_ref(), + &[bump], + ], + )?; + + // Write the inscription metadata to the metadata account. + sol_memcpy( + &mut ctx.accounts.metadata_account.try_borrow_mut_data()?, + serialized_metadata, + serialized_metadata.len(), + ); + + Ok(()) +} diff --git a/programs/mpl-json/src/processor/mod.rs b/programs/mpl-inscription/src/processor/mod.rs similarity index 53% rename from programs/mpl-json/src/processor/mod.rs rename to programs/mpl-inscription/src/processor/mod.rs index a5aa9b6..9959b17 100644 --- a/programs/mpl-json/src/processor/mod.rs +++ b/programs/mpl-inscription/src/processor/mod.rs @@ -1,20 +1,20 @@ -use crate::instruction::MplJsonInstruction; +use crate::instruction::MplInscriptionInstruction; use borsh::BorshDeserialize; use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey}; mod add_authority; -mod append_value; +mod clear_data; mod close; mod initialize; mod remove_authority; -mod set_value; +mod write_data; use add_authority::*; -use append_value::*; +use clear_data::*; use close::*; use initialize::*; use remove_authority::*; -use set_value::*; +use write_data::*; pub struct Processor; impl Processor { @@ -23,31 +23,32 @@ impl Processor { accounts: &'a [AccountInfo<'a>], instruction_data: &[u8], ) -> ProgramResult { - let instruction: MplJsonInstruction = MplJsonInstruction::try_from_slice(instruction_data)?; + let instruction: MplInscriptionInstruction = + MplInscriptionInstruction::try_from_slice(instruction_data)?; match instruction { - MplJsonInstruction::Initialize => { + MplInscriptionInstruction::Initialize => { msg!("Instruction: Initialize"); process_initialize(accounts) } - MplJsonInstruction::Close => { + MplInscriptionInstruction::Close => { msg!("Instruction: Close"); process_close(accounts) } - MplJsonInstruction::SetValue(args) => { - msg!("Instruction: SetValue"); - process_set_value(accounts, args) + MplInscriptionInstruction::WriteData(args) => { + msg!("Instruction: WriteData"); + process_write_data(accounts, args) } - MplJsonInstruction::AppendValue(args) => { - msg!("Instruction: AppendValue"); - process_append_value(accounts, args) + MplInscriptionInstruction::ClearData => { + msg!("Instruction: ClearData"); + process_clear_data(accounts) } - MplJsonInstruction::AddAuthority(args) => { + MplInscriptionInstruction::AddAuthority(args) => { msg!("Instruction: AddAuthority"); process_add_authority(accounts, args) } - MplJsonInstruction::RemoveAuthority(args) => { + MplInscriptionInstruction::RemoveAuthority => { msg!("Instruction: RemoveAuthority"); - process_remove_authority(accounts, args) + process_remove_authority(accounts) } } } diff --git a/programs/mpl-inscription/src/processor/remove_authority.rs b/programs/mpl-inscription/src/processor/remove_authority.rs new file mode 100644 index 0000000..669aa7e --- /dev/null +++ b/programs/mpl-inscription/src/processor/remove_authority.rs @@ -0,0 +1,65 @@ +use borsh::{BorshDeserialize, BorshSerialize}; +use mpl_utils::{assert_signer, resize_or_reallocate_account_raw}; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memcpy, + system_program, +}; + +use crate::{ + error::MplInscriptionError, instruction::accounts::RemoveAuthorityAccounts, + state::InscriptionMetadata, +}; + +pub(crate) fn process_remove_authority<'a>(accounts: &'a [AccountInfo<'a>]) -> ProgramResult { + let ctx = &RemoveAuthorityAccounts::context(accounts)?; + + // Check that the account isn't already initialized. + if (ctx.accounts.metadata_account.owner != &crate::ID) + || ctx.accounts.metadata_account.data_is_empty() + { + return Err(MplInscriptionError::NotInitialized.into()); + } + let mut inscription_metadata = + InscriptionMetadata::try_from_slice(&ctx.accounts.metadata_account.data.borrow())?; + + // The payer and authority must sign. + assert_signer(ctx.accounts.authority)?; + if !inscription_metadata + .update_authorities + .contains(ctx.accounts.authority.key) + { + return Err(MplInscriptionError::InvalidAuthority.into()); + } + + if ctx.accounts.system_program.key != &system_program::ID { + return Err(MplInscriptionError::InvalidSystemProgram.into()); + } + + // Remove the authority if they're the signer. + let index = inscription_metadata + .update_authorities + .iter() + .position(|x| x == ctx.accounts.authority.key) + .ok_or(MplInscriptionError::InvalidAuthority)?; + inscription_metadata.update_authorities.swap_remove(index); + + // Write the updated inscription metadata account back to the account. + let serialized_data = inscription_metadata.try_to_vec()?; + + // Resize the account to fit the new authority. + resize_or_reallocate_account_raw( + ctx.accounts.metadata_account, + ctx.accounts.authority, + ctx.accounts.system_program, + serialized_data.len(), + )?; + + // Write the inscription metadata to the metadata account. + sol_memcpy( + &mut ctx.accounts.metadata_account.try_borrow_mut_data()?, + &serialized_data, + serialized_data.len(), + ); + + Ok(()) +} diff --git a/programs/mpl-inscription/src/processor/write_data.rs b/programs/mpl-inscription/src/processor/write_data.rs new file mode 100644 index 0000000..b1d67af --- /dev/null +++ b/programs/mpl-inscription/src/processor/write_data.rs @@ -0,0 +1,82 @@ +use borsh::BorshDeserialize; +use mpl_utils::{assert_derivation, assert_signer, resize_or_reallocate_account_raw}; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memcpy, + system_program, +}; + +use crate::{ + error::MplInscriptionError, + instruction::{accounts::WriteDataAccounts, WriteDataArgs}, + state::{InscriptionMetadata, PREFIX}, +}; + +pub(crate) fn process_write_data<'a>( + accounts: &'a [AccountInfo<'a>], + args: WriteDataArgs, +) -> ProgramResult { + let ctx = &mut WriteDataAccounts::context(accounts)?; + + // Check that the inscription account is already initialized. + if ctx.accounts.inscription_account.owner != &crate::ID { + return Err(MplInscriptionError::NotInitialized.into()); + } + + // Check that the metadata account is already initialized. + if (ctx.accounts.metadata_account.owner != &crate::ID) + || ctx.accounts.metadata_account.data_is_empty() + { + return Err(MplInscriptionError::NotInitialized.into()); + } + let inscription_metadata = + InscriptionMetadata::try_from_slice(&ctx.accounts.metadata_account.data.borrow())?; + + // Verify that the derived address is correct for the metadata account. + let bump = assert_derivation( + &crate::ID, + ctx.accounts.metadata_account, + &[ + PREFIX.as_bytes(), + crate::ID.as_ref(), + ctx.accounts.inscription_account.key.as_ref(), + ], + MplInscriptionError::MetadataDerivedKeyInvalid, + )?; + if bump != inscription_metadata.bump { + return Err(MplInscriptionError::MetadataDerivedKeyInvalid.into()); + } + + // The payer and authority must sign. + assert_signer(ctx.accounts.payer)?; + if !inscription_metadata + .update_authorities + .contains(ctx.accounts.payer.key) + { + return Err(MplInscriptionError::InvalidAuthority.into()); + } + + if ctx.accounts.system_program.key != &system_program::ID { + return Err(MplInscriptionError::InvalidSystemProgram.into()); + } + + let old_size = ctx.accounts.inscription_account.data_len(); + let new_size = old_size + .checked_add(args.value.len()) + .ok_or(MplInscriptionError::NumericalOverflow)?; + // Resize the account to fit the new authority. + resize_or_reallocate_account_raw( + ctx.accounts.inscription_account, + ctx.accounts.payer, + ctx.accounts.system_program, + new_size, + )?; + + // Write the inscription metadata to the metadata account. + sol_memcpy( + &mut ctx.accounts.inscription_account.try_borrow_mut_data()?[old_size..], + &args.value, + args.value.len(), + ); + + Ok(()) +} diff --git a/programs/mpl-json/src/state.rs b/programs/mpl-inscription/src/state.rs similarity index 66% rename from programs/mpl-json/src/state.rs rename to programs/mpl-inscription/src/state.rs index 79c8296..24002b1 100644 --- a/programs/mpl-json/src/state.rs +++ b/programs/mpl-inscription/src/state.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use shank::ShankAccount; use solana_program::pubkey::Pubkey; -pub const PREFIX: &str = "JSON"; +pub const PREFIX: &str = "Inscription"; pub const INITIAL_SIZE: usize = 1024; @@ -10,14 +10,14 @@ pub const INITIAL_SIZE: usize = 1024; #[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] pub enum Key { Uninitialized, - JsonMetadataAccount, + InscriptionMetadataAccount, } #[repr(C)] #[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)] -pub struct JsonMetadata { +pub struct InscriptionMetadata { pub key: Key, pub bump: u8, - pub mutable: bool, - pub authorities: Vec, + pub inscription_number: Option, + pub update_authorities: Vec, } diff --git a/programs/mpl-json/src/instruction/mod.rs b/programs/mpl-json/src/instruction/mod.rs deleted file mode 100644 index 202cc91..0000000 --- a/programs/mpl-json/src/instruction/mod.rs +++ /dev/null @@ -1,72 +0,0 @@ -use borsh::{BorshDeserialize, BorshSerialize}; -use shank::{ShankContext, ShankInstruction}; -use solana_program::pubkey::Pubkey; - -#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, ShankContext, ShankInstruction)] -#[rustfmt::skip] -pub enum MplJsonInstruction { - /// Initialize the JSON account - #[account(0, writable, signer, name="json_account", desc = "The account to store the metadata in.")] - #[account(1, writable, name="json_metadata_account", desc = "The account to store the json account's metadata in.")] - #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] - #[account(3, name="system_program", desc = "System program")] - Initialize, - - /// Close the JSON account - #[account(0, writable, name="json_account", desc = "The account to store the metadata in.")] - #[account(1, writable, name="json_metadata_account", desc = "The account to store the json account's metadata in.")] - #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] - #[account(3, name="system_program", desc = "System program")] - Close, - - /// Set a value in the JSON account - #[account(0, writable, name="json_account", desc = "The account to store the metadata in.")] - #[account(1, writable, name="json_metadata_account", desc = "The account to store the json account's metadata in.")] - #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] - #[account(3, name="system_program", desc = "System program")] - SetValue(SetValueArgs), - - /// Append a value to the JSON account - #[account(0, writable, name="json_account", desc = "The account to store the metadata in.")] - #[account(1, writable, name="json_metadata_account", desc = "The account to store the json account's metadata in.")] - #[account(2, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] - #[account(3, name="system_program", desc = "System program")] - AppendValue(AppendValueArgs), - - /// Add an authority to the JSON account - #[account(0, writable, name="json_metadata_account", desc = "The account to store the metadata's metadata in.")] - #[account(1, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] - #[account(2, name="system_program", desc = "System program")] - AddAuthority(AddAuthorityArgs), - - /// Remove an authority from the JSON account - #[account(0, writable, name="json_metadata_account", desc = "The account to store the metadata's metadata in.")] - #[account(1, writable, signer, name="payer", desc="The account that will pay for the transaction and rent.")] - #[account(2, name="system_program", desc = "System program")] - RemoveAuthority(RemoveAuthorityArgs), -} - -#[repr(C)] -#[derive(PartialEq, Eq, Debug, Clone, BorshSerialize, BorshDeserialize)] -pub struct SetValueArgs { - pub value: String, -} - -#[repr(C)] -#[repr(C)] -#[derive(PartialEq, Eq, Debug, Clone, BorshSerialize, BorshDeserialize)] -pub struct AppendValueArgs { - pub value: String, -} - -#[repr(C)] -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] -pub struct AddAuthorityArgs { - pub new_authority: Pubkey, -} - -#[repr(C)] -#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] -pub struct RemoveAuthorityArgs { - pub authority: Pubkey, -} diff --git a/programs/mpl-json/src/processor/append_value.rs b/programs/mpl-json/src/processor/append_value.rs deleted file mode 100644 index 6ad8d10..0000000 --- a/programs/mpl-json/src/processor/append_value.rs +++ /dev/null @@ -1,124 +0,0 @@ -use borsh::BorshDeserialize; -use mpl_utils::{assert_derivation, assert_signer, resize_or_reallocate_account_raw}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memcpy, - system_program, -}; - -use crate::{ - error::MplJsonError, - instruction::{accounts::AppendValueAccounts, AppendValueArgs}, - state::{JsonMetadata, PREFIX}, -}; - -pub(crate) fn process_append_value<'a>( - accounts: &'a [AccountInfo<'a>], - args: AppendValueArgs, -) -> ProgramResult { - let ctx = &AppendValueAccounts::context(accounts)?; - // Check that the account is already initialized. - if (ctx.accounts.json_account.owner != &crate::ID) || ctx.accounts.json_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - - // Check that the account isn't already initialized. - if (ctx.accounts.json_metadata_account.owner != &crate::ID) - || ctx.accounts.json_metadata_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - let json_metadata = - JsonMetadata::try_from_slice(&ctx.accounts.json_metadata_account.data.borrow())?; - - // Verify that the derived address is correct for the JSON metadata account. - let bump = assert_derivation( - &crate::ID, - ctx.accounts.json_metadata_account, - &[ - PREFIX.as_bytes(), - crate::ID.as_ref(), - ctx.accounts.json_account.key.as_ref(), - ], - MplJsonError::MetadataDerivedKeyInvalid, - )?; - if bump != json_metadata.bump { - return Err(MplJsonError::MetadataDerivedKeyInvalid.into()); - } - - // The payer and authority must sign. - assert_signer(ctx.accounts.payer)?; - if !json_metadata.authorities.contains(ctx.accounts.payer.key) { - return Err(MplJsonError::InvalidAuthority.into()); - } - - if ctx.accounts.system_program.key != &system_program::ID { - return Err(MplJsonError::InvalidSystemProgram.into()); - } - - let mut json_data: serde_json::Value = - serde_json::from_slice(&ctx.accounts.json_account.data.borrow()) - .map_err(|_| MplJsonError::InvalidJson)?; - - let new_data: serde_json::Value = - serde_json::from_str(&args.value).map_err(|_| MplJsonError::InvalidJson)?; - - merge_append(&mut json_data, new_data)?; - - // Write the updated JSON metadata account back to the account. - let serialized_data = serde_json::to_vec(&json_data).map_err(|_| MplJsonError::InvalidJson)?; - - // Resize the account to fit the new authority. - resize_or_reallocate_account_raw( - ctx.accounts.json_account, - ctx.accounts.payer, - ctx.accounts.system_program, - serialized_data.len(), - )?; - - // Write the JSON metadata to the JSON metadata account. - sol_memcpy( - &mut ctx.accounts.json_account.try_borrow_mut_data()?, - &serialized_data, - serialized_data.len(), - ); - - let json_data: serde_json::Value = - serde_json::from_slice(&ctx.accounts.json_account.data.borrow()) - .map_err(|_| MplJsonError::InvalidJson)?; - solana_program::msg!("JSON account data: {:?}", json_data); - - Ok(()) -} - -fn merge_append(a: &mut serde_json::Value, b: serde_json::Value) -> ProgramResult { - if let serde_json::Value::Object(a) = a { - if let serde_json::Value::Object(b) = b { - for (k, v) in b { - merge_append(a.entry(k).or_insert(serde_json::Value::Null), v)?; - } - - return Ok(()); - } - } - - match a { - serde_json::Value::String(a) => { - if let serde_json::Value::String(b) = b { - a.push_str(&b); - Ok(()) - } else { - Err(MplJsonError::InvalidJson.into()) - } - } - serde_json::Value::Array(a) => { - if let serde_json::Value::Array(b) = b { - a.extend(b); - Ok(()) - } else { - Err(MplJsonError::InvalidJson.into()) - } - } - _ => Err(MplJsonError::InvalidJson.into()), - } -} diff --git a/programs/mpl-json/src/processor/close.rs b/programs/mpl-json/src/processor/close.rs deleted file mode 100644 index 2819f9a..0000000 --- a/programs/mpl-json/src/processor/close.rs +++ /dev/null @@ -1,59 +0,0 @@ -use borsh::BorshDeserialize; -use mpl_utils::{assert_derivation, assert_signer, close_account_raw}; -use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, system_program}; - -use crate::{ - error::MplJsonError, - instruction::accounts::CloseAccounts, - state::{JsonMetadata, PREFIX}, -}; - -pub(crate) fn process_close<'a>(accounts: &'a [AccountInfo<'a>]) -> ProgramResult { - let ctx = &CloseAccounts::context(accounts)?; - - // Check that the account isn't already initialized. - if (ctx.accounts.json_account.owner != &crate::ID) || ctx.accounts.json_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - - // Check that the account isn't already initialized. - if (ctx.accounts.json_metadata_account.owner != &crate::ID) - || ctx.accounts.json_metadata_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - let json_metadata = - JsonMetadata::try_from_slice(&ctx.accounts.json_metadata_account.data.borrow())?; - - // Verify that the derived address is correct for the JSON metadata account. - let bump = assert_derivation( - &crate::ID, - ctx.accounts.json_metadata_account, - &[ - PREFIX.as_bytes(), - crate::ID.as_ref(), - ctx.accounts.json_account.key.as_ref(), - ], - MplJsonError::MetadataDerivedKeyInvalid, - )?; - if bump != json_metadata.bump { - return Err(MplJsonError::MetadataDerivedKeyInvalid.into()); - } - - // The payer and authority must sign. - assert_signer(ctx.accounts.payer)?; - if !json_metadata.authorities.contains(ctx.accounts.payer.key) { - return Err(MplJsonError::InvalidAuthority.into()); - } - - if ctx.accounts.system_program.key != &system_program::ID { - return Err(MplJsonError::InvalidSystemProgram.into()); - } - - // Close both accounts - close_account_raw(ctx.accounts.payer, ctx.accounts.json_account)?; - close_account_raw(ctx.accounts.payer, ctx.accounts.json_metadata_account)?; - - Ok(()) -} diff --git a/programs/mpl-json/src/processor/initialize.rs b/programs/mpl-json/src/processor/initialize.rs deleted file mode 100644 index 0ab9b5f..0000000 --- a/programs/mpl-json/src/processor/initialize.rs +++ /dev/null @@ -1,110 +0,0 @@ -use borsh::BorshSerialize; -use mpl_utils::{assert_derivation, assert_signer, create_or_allocate_account_raw}; -use num_traits::ToPrimitive; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program::invoke, - program_memory::sol_memcpy, rent::Rent, system_instruction, system_program, sysvar::Sysvar, -}; - -use crate::{ - error::MplJsonError, - instruction::accounts::InitializeAccounts, - state::{JsonMetadata, Key, INITIAL_SIZE, PREFIX}, -}; - -pub(crate) fn process_initialize<'a>(accounts: &'a [AccountInfo<'a>]) -> ProgramResult { - let ctx = &InitializeAccounts::context(accounts)?; - - // Check that the account isn't already initialized. - if (ctx.accounts.json_account.owner != &system_program::ID) - || !ctx.accounts.json_account.data_is_empty() - { - return Err(MplJsonError::AlreadyInitialized.into()); - } - - // Check that the account isn't already initialized. - if (ctx.accounts.json_metadata_account.owner != &system_program::ID) - || !ctx.accounts.json_metadata_account.data_is_empty() - { - return Err(MplJsonError::AlreadyInitialized.into()); - } - // Verify that the derived address is correct for the JSON metadata account. - let bump = assert_derivation( - &crate::ID, - ctx.accounts.json_metadata_account, - &[ - PREFIX.as_bytes(), - crate::ID.as_ref(), - ctx.accounts.json_account.key.as_ref(), - ], - MplJsonError::MetadataDerivedKeyInvalid, - )?; - - // The payer and authority must sign. - assert_signer(ctx.accounts.payer)?; - - if ctx.accounts.system_program.key != &system_program::ID { - return Err(MplJsonError::InvalidSystemProgram.into()); - } - - // Initialize the JSON data with a null value. - let json_data = serde_json::Value::Null; - let serialized_data = match serde_json::to_vec(&json_data) { - Ok(data) => data, - Err(_) => return Err(MplJsonError::InvalidJson.into()), - }; - - // Initialize the JSON metadata account. - solana_program::msg!("Creating JSON account"); - let rent = Rent::get()?; - let rent_amount = rent.minimum_balance(INITIAL_SIZE); - invoke( - &system_instruction::create_account( - ctx.accounts.payer.key, - ctx.accounts.json_account.key, - rent_amount, - serialized_data.len().to_u64().unwrap_or(0), - &crate::ID, - ), - &[ - ctx.accounts.payer.clone(), - ctx.accounts.json_account.clone(), - ctx.accounts.system_program.clone(), - ], - )?; - - // Initialize the JSON metadata. - let json_metadata = JsonMetadata { - key: Key::JsonMetadataAccount, - bump, - mutable: true, - authorities: vec![*ctx.accounts.payer.key], - }; - - let serialized_metadata = &json_metadata.try_to_vec()?; - - // Initialize the JSON metadata account. - solana_program::msg!("Creating JSON Metadata account"); - create_or_allocate_account_raw( - crate::ID, - ctx.accounts.json_metadata_account, - ctx.accounts.system_program, - ctx.accounts.payer, - serialized_metadata.len(), - &[ - PREFIX.as_bytes(), - crate::ID.as_ref(), - ctx.accounts.json_account.key.as_ref(), - &[bump], - ], - )?; - - // Write the JSON metadata to the JSON metadata account. - sol_memcpy( - &mut ctx.accounts.json_metadata_account.try_borrow_mut_data()?, - serialized_metadata, - serialized_metadata.len(), - ); - - Ok(()) -} diff --git a/programs/mpl-json/src/processor/remove_authority.rs b/programs/mpl-json/src/processor/remove_authority.rs deleted file mode 100644 index e300185..0000000 --- a/programs/mpl-json/src/processor/remove_authority.rs +++ /dev/null @@ -1,66 +0,0 @@ -use borsh::{BorshDeserialize, BorshSerialize}; -use mpl_utils::{assert_signer, resize_or_reallocate_account_raw}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memcpy, - system_program, -}; - -use crate::{ - error::MplJsonError, - instruction::{accounts::RemoveAuthorityAccounts, RemoveAuthorityArgs}, - state::JsonMetadata, -}; - -pub(crate) fn process_remove_authority<'a>( - accounts: &'a [AccountInfo<'a>], - args: RemoveAuthorityArgs, -) -> ProgramResult { - let ctx = &RemoveAuthorityAccounts::context(accounts)?; - - // Check that the account isn't already initialized. - if (ctx.accounts.json_metadata_account.owner != &crate::ID) - || ctx.accounts.json_metadata_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - let mut json_metadata = - JsonMetadata::try_from_slice(&ctx.accounts.json_metadata_account.data.borrow())?; - - // The payer and authority must sign. - assert_signer(ctx.accounts.payer)?; - if !json_metadata.authorities.contains(ctx.accounts.payer.key) { - return Err(MplJsonError::InvalidAuthority.into()); - } - - if ctx.accounts.system_program.key != &system_program::ID { - return Err(MplJsonError::InvalidSystemProgram.into()); - } - - // Add the new authority. - let index = json_metadata - .authorities - .iter() - .position(|x| x == &args.authority) - .ok_or(MplJsonError::InvalidAuthority)?; - json_metadata.authorities.swap_remove(index); - - // Write the updated JSON metadata account back to the account. - let serialized_data = json_metadata.try_to_vec()?; - - // Resize the account to fit the new authority. - resize_or_reallocate_account_raw( - ctx.accounts.json_metadata_account, - ctx.accounts.payer, - ctx.accounts.system_program, - serialized_data.len(), - )?; - - // Write the JSON metadata to the JSON metadata account. - sol_memcpy( - &mut ctx.accounts.json_metadata_account.try_borrow_mut_data()?, - &serialized_data, - serialized_data.len(), - ); - - Ok(()) -} diff --git a/programs/mpl-json/src/processor/set_value.rs b/programs/mpl-json/src/processor/set_value.rs deleted file mode 100644 index 7f3d3b2..0000000 --- a/programs/mpl-json/src/processor/set_value.rs +++ /dev/null @@ -1,110 +0,0 @@ -use borsh::BorshDeserialize; -use mpl_utils::{assert_derivation, assert_signer, resize_or_reallocate_account_raw}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memcpy, - system_program, -}; - -use crate::{ - error::MplJsonError, - instruction::{accounts::SetValueAccounts, SetValueArgs}, - state::{JsonMetadata, PREFIX}, -}; - -pub(crate) fn process_set_value<'a>( - accounts: &'a [AccountInfo<'a>], - args: SetValueArgs, -) -> ProgramResult { - let ctx = &mut SetValueAccounts::context(accounts)?; - - // Check that the account is already initialized. - if (ctx.accounts.json_account.owner != &crate::ID) || ctx.accounts.json_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - - // Check that the account isn't already initialized. - if (ctx.accounts.json_metadata_account.owner != &crate::ID) - || ctx.accounts.json_metadata_account.data_is_empty() - { - return Err(MplJsonError::NotInitialized.into()); - } - let json_metadata = - JsonMetadata::try_from_slice(&ctx.accounts.json_metadata_account.data.borrow())?; - - // Verify that the derived address is correct for the JSON metadata account. - let bump = assert_derivation( - &crate::ID, - ctx.accounts.json_metadata_account, - &[ - PREFIX.as_bytes(), - crate::ID.as_ref(), - ctx.accounts.json_account.key.as_ref(), - ], - MplJsonError::MetadataDerivedKeyInvalid, - )?; - if bump != json_metadata.bump { - return Err(MplJsonError::MetadataDerivedKeyInvalid.into()); - } - - // The payer and authority must sign. - assert_signer(ctx.accounts.payer)?; - if !json_metadata.authorities.contains(ctx.accounts.payer.key) { - return Err(MplJsonError::InvalidAuthority.into()); - } - - if ctx.accounts.system_program.key != &system_program::ID { - return Err(MplJsonError::InvalidSystemProgram.into()); - } - - // solana_program::msg!("JSON account data: {:?}", ctx.accounts.json_account.data.borrow()); - let mut json_data: serde_json::Value = - serde_json::from_slice(&ctx.accounts.json_account.data.borrow()) - .unwrap_or(serde_json::Value::Null); - // .map_err(|_| MplJsonError::InvalidJson)?; - - // solana_program::msg!("New data: {:?}", args.value); - let new_data: serde_json::Value = - serde_json::from_str(&args.value).map_err(|_| MplJsonError::InvalidJson)?; - - merge(&mut json_data, new_data); - - // Write the updated JSON metadata account back to the account. - // solana_program::msg!("Updated JSON data: {:?}", json_data); - let serialized_data = serde_json::to_vec(&json_data).map_err(|_| MplJsonError::InvalidJson)?; - - // Resize the account to fit the new authority. - resize_or_reallocate_account_raw( - ctx.accounts.json_account, - ctx.accounts.payer, - ctx.accounts.system_program, - serialized_data.len(), - )?; - - // Write the JSON metadata to the JSON metadata account. - sol_memcpy( - &mut ctx.accounts.json_account.try_borrow_mut_data()?, - &serialized_data, - serialized_data.len(), - ); - - Ok(()) -} - -fn merge(a: &mut serde_json::Value, b: serde_json::Value) { - if let serde_json::Value::Object(a) = a { - if let serde_json::Value::Object(b) = b { - for (k, v) in b { - if v.is_null() { - a.remove(&k); - } else { - merge(a.entry(k).or_insert(serde_json::Value::Null), v); - } - } - - return; - } - } - - *a = b; -}