generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding sharded inscription counters.
- Loading branch information
1 parent
fe3d141
commit b180cfb
Showing
27 changed files
with
1,105 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
*/ | ||
|
||
export * from './inscriptionMetadata'; | ||
export * from './inscriptionShard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.