Skip to content

Commit

Permalink
Adding sharded inscription counters.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Dec 11, 2023
1 parent fe3d141 commit b180cfb
Show file tree
Hide file tree
Showing 27 changed files with 1,105 additions and 43 deletions.
1 change: 1 addition & 0 deletions clients/js/src/generated/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export * from './inscriptionMetadata';
export * from './inscriptionShard';
10 changes: 5 additions & 5 deletions clients/js/src/generated/accounts/inscriptionMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type InscriptionMetadataAccountData = {
key: Key;
bump: number;
state: InscriptionState;
inscriptionNumber: Option<bigint>;
inscriptionRank: Option<bigint>;
inscriptionBump: Option<number>;
updateAuthorities: Array<PublicKey>;
};
Expand All @@ -55,7 +55,7 @@ export type InscriptionMetadataAccountDataArgs = {
key: KeyArgs;
bump: number;
state: InscriptionStateArgs;
inscriptionNumber: OptionOrNullable<number | bigint>;
inscriptionRank: OptionOrNullable<number | bigint>;
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
};
Expand All @@ -69,7 +69,7 @@ export function getInscriptionMetadataAccountDataSerializer(): Serializer<
['key', getKeySerializer()],
['bump', u8()],
['state', getInscriptionStateSerializer()],
['inscriptionNumber', option(u64())],
['inscriptionRank', option(u64())],
['inscriptionBump', option(u8())],
['updateAuthorities', array(publicKeySerializer())],
],
Expand Down Expand Up @@ -159,14 +159,14 @@ export function getInscriptionMetadataGpaBuilder(
key: KeyArgs;
bump: number;
state: InscriptionStateArgs;
inscriptionNumber: OptionOrNullable<number | bigint>;
inscriptionRank: OptionOrNullable<number | bigint>;
inscriptionBump: OptionOrNullable<number>;
updateAuthorities: Array<PublicKey>;
}>({
key: [0, getKeySerializer()],
bump: [1, u8()],
state: [2, getInscriptionStateSerializer()],
inscriptionNumber: [3, option(u64())],
inscriptionRank: [3, option(u64())],
inscriptionBump: [null, option(u8())],
updateAuthorities: [null, array(publicKeySerializer())],
})
Expand Down
152 changes: 152 additions & 0 deletions clients/js/src/generated/accounts/inscriptionShard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* 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,
struct,
u64,
u8,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '../types';

export type InscriptionShard = Account<InscriptionShardAccountData>;

export type InscriptionShardAccountData = {
key: Key;
bump: number;
shardNumber: number;
count: bigint;
};

export type InscriptionShardAccountDataArgs = {
key: KeyArgs;
bump: number;
shardNumber: number;
count: number | bigint;
};

export function getInscriptionShardAccountDataSerializer(): Serializer<
InscriptionShardAccountDataArgs,
InscriptionShardAccountData
> {
return struct<InscriptionShardAccountData>(
[
['key', getKeySerializer()],
['bump', u8()],
['shardNumber', u8()],
['count', u64()],
],
{ description: 'InscriptionShardAccountData' }
) as Serializer<InscriptionShardAccountDataArgs, InscriptionShardAccountData>;
}

export function deserializeInscriptionShard(
rawAccount: RpcAccount
): InscriptionShard {
return deserializeAccount(
rawAccount,
getInscriptionShardAccountDataSerializer()
);
}

export async function fetchInscriptionShard(
context: Pick<Context, 'rpc'>,
publicKey: PublicKey | Pda,
options?: RpcGetAccountOptions
): Promise<InscriptionShard> {
const maybeAccount = await context.rpc.getAccount(
toPublicKey(publicKey, false),
options
);
assertAccountExists(maybeAccount, 'InscriptionShard');
return deserializeInscriptionShard(maybeAccount);
}

export async function safeFetchInscriptionShard(
context: Pick<Context, 'rpc'>,
publicKey: PublicKey | Pda,
options?: RpcGetAccountOptions
): Promise<InscriptionShard | null> {
const maybeAccount = await context.rpc.getAccount(
toPublicKey(publicKey, false),
options
);
return maybeAccount.exists ? deserializeInscriptionShard(maybeAccount) : null;
}

export async function fetchAllInscriptionShard(
context: Pick<Context, 'rpc'>,
publicKeys: Array<PublicKey | Pda>,
options?: RpcGetAccountsOptions
): Promise<InscriptionShard[]> {
const maybeAccounts = await context.rpc.getAccounts(
publicKeys.map((key) => toPublicKey(key, false)),
options
);
return maybeAccounts.map((maybeAccount) => {
assertAccountExists(maybeAccount, 'InscriptionShard');
return deserializeInscriptionShard(maybeAccount);
});
}

export async function safeFetchAllInscriptionShard(
context: Pick<Context, 'rpc'>,
publicKeys: Array<PublicKey | Pda>,
options?: RpcGetAccountsOptions
): Promise<InscriptionShard[]> {
const maybeAccounts = await context.rpc.getAccounts(
publicKeys.map((key) => toPublicKey(key, false)),
options
);
return maybeAccounts
.filter((maybeAccount) => maybeAccount.exists)
.map((maybeAccount) =>
deserializeInscriptionShard(maybeAccount as RpcAccount)
);
}

export function getInscriptionShardGpaBuilder(
context: Pick<Context, 'rpc' | 'programs'>
) {
const programId = context.programs.getPublicKey(
'mplInscription',
'1NSCRfGeyo7wPUazGbaPBUsTM49e1k2aXewHGARfzSo'
);
return gpaBuilder(context, programId)
.registerFields<{
key: KeyArgs;
bump: number;
shardNumber: number;
count: number | bigint;
}>({
key: [0, getKeySerializer()],
bump: [1, u8()],
shardNumber: [2, u8()],
count: [3, u64()],
})
.deserializeUsing<InscriptionShard>((account) =>
deserializeInscriptionShard(account)
);
}

export function getInscriptionShardSize(): number {
return 11;
}
25 changes: 19 additions & 6 deletions clients/js/src/generated/errors/mplInscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ export class NotInitializedError extends ProgramError {
codeToErrorMap.set(0x1, NotInitializedError);
nameToErrorMap.set('NotInitialized', NotInitializedError);

/** MetadataDerivedKeyInvalid: The key for the JSON metadata account is invalid. */
export class MetadataDerivedKeyInvalidError extends ProgramError {
readonly name: string = 'MetadataDerivedKeyInvalid';
/** DerivedKeyInvalid: The key for the account is invalid. */
export class DerivedKeyInvalidError extends ProgramError {
readonly name: string = 'DerivedKeyInvalid';

readonly code: number = 0x2; // 2

constructor(program: Program, cause?: Error) {
super('The key for the JSON metadata account is invalid.', program, cause);
super('The key for the account is invalid.', program, cause);
}
}
codeToErrorMap.set(0x2, MetadataDerivedKeyInvalidError);
nameToErrorMap.set('MetadataDerivedKeyInvalid', MetadataDerivedKeyInvalidError);
codeToErrorMap.set(0x2, DerivedKeyInvalidError);
nameToErrorMap.set('DerivedKeyInvalid', DerivedKeyInvalidError);

/** InvalidSystemProgram: The system program account is invalid. */
export class InvalidSystemProgramError extends ProgramError {
Expand Down Expand Up @@ -188,6 +188,19 @@ export class NotEnoughTokensError extends ProgramError {
codeToErrorMap.set(0xc, NotEnoughTokensError);
nameToErrorMap.set('NotEnoughTokens', NotEnoughTokensError);

/** InvalidShardAccount: The shard account is invalid. */
export class InvalidShardAccountError extends ProgramError {
readonly name: string = 'InvalidShardAccount';

readonly code: number = 0xd; // 13

constructor(program: Program, cause?: Error) {
super('The shard account is invalid.', program, cause);
}
}
codeToErrorMap.set(0xd, InvalidShardAccountError);
nameToErrorMap.set('InvalidShardAccount', InvalidShardAccountError);

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

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

// Accounts.
export type CreateShardInstructionAccounts = {
/** The account to store the shard data in. */
shardAccount: PublicKey | Pda;
/** The account that will pay for the transaction and rent. */
payer?: Signer;
/** System program */
systemProgram?: PublicKey | Pda;
};

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

export type CreateShardInstructionDataArgs = { shardNumber: number };

export function getCreateShardInstructionDataSerializer(): Serializer<
CreateShardInstructionDataArgs,
CreateShardInstructionData
> {
return mapSerializer<
CreateShardInstructionDataArgs,
any,
CreateShardInstructionData
>(
struct<CreateShardInstructionData>(
[
['discriminator', u8()],
['shardNumber', u8()],
],
{ description: 'CreateShardInstructionData' }
),
(value) => ({ ...value, discriminator: 7 })
) as Serializer<CreateShardInstructionDataArgs, CreateShardInstructionData>;
}

// Args.
export type CreateShardInstructionArgs = CreateShardInstructionDataArgs;

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

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

// Arguments.
const resolvedArgs: CreateShardInstructionArgs = { ...input };

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

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

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

// Data.
const data = getCreateShardInstructionDataSerializer().serialize(
resolvedArgs as CreateShardInstructionDataArgs
);

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

return transactionBuilder([
{ instruction: { keys, programId, data }, signers, bytesCreatedOnChain },
]);
}
1 change: 1 addition & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export * from './addAuthority';
export * from './clearData';
export * from './close';
export * from './createShard';
export * from './initialize';
export * from './initializeFromMint';
export * from './removeAuthority';
Expand Down
Loading

0 comments on commit b180cfb

Please sign in to comment.