@1upmonster/duel 0.1.8 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -59
- package/dist/admin.d.ts +25 -40
- package/dist/admin.js +93 -114
- package/dist/encryption.js +1 -2
- package/dist/generated/duel/accounts/index.d.ts +10 -0
- package/dist/generated/duel/accounts/index.js +11 -0
- package/dist/generated/duel/accounts/matchTicket.d.ts +38 -0
- package/dist/generated/duel/accounts/matchTicket.js +45 -0
- package/dist/generated/duel/accounts/queue.d.ts +42 -0
- package/dist/generated/duel/accounts/queue.js +45 -0
- package/dist/generated/duel/accounts/tenant.d.ts +41 -0
- package/dist/generated/duel/accounts/tenant.js +44 -0
- package/dist/generated/duel/errors/duel.d.ts +31 -0
- package/dist/generated/duel/errors/duel.js +35 -0
- package/dist/generated/duel/errors/index.d.ts +8 -0
- package/dist/generated/duel/errors/index.js +9 -0
- package/dist/generated/duel/index.d.ts +12 -0
- package/dist/generated/duel/index.js +13 -0
- package/dist/generated/duel/instructions/cancelTicket.d.ts +45 -0
- package/dist/generated/duel/instructions/cancelTicket.js +56 -0
- package/dist/generated/duel/instructions/closeTicket.d.ts +45 -0
- package/dist/generated/duel/instructions/closeTicket.js +56 -0
- package/dist/generated/duel/instructions/commitTickets.d.ts +39 -0
- package/dist/generated/duel/instructions/commitTickets.js +50 -0
- package/dist/generated/duel/instructions/createTicket.d.ts +48 -0
- package/dist/generated/duel/instructions/createTicket.js +63 -0
- package/dist/generated/duel/instructions/delegateQueue.d.ts +69 -0
- package/dist/generated/duel/instructions/delegateQueue.js +90 -0
- package/dist/generated/duel/instructions/delegateTicket.d.ts +69 -0
- package/dist/generated/duel/instructions/delegateTicket.js +90 -0
- package/dist/generated/duel/instructions/flushMatches.d.ts +37 -0
- package/dist/generated/duel/instructions/flushMatches.js +43 -0
- package/dist/generated/duel/instructions/index.d.ts +19 -0
- package/dist/generated/duel/instructions/index.js +20 -0
- package/dist/generated/duel/instructions/initializeQueue.d.ts +48 -0
- package/dist/generated/duel/instructions/initializeQueue.js +63 -0
- package/dist/generated/duel/instructions/initializeTenant.d.ts +70 -0
- package/dist/generated/duel/instructions/initializeTenant.js +67 -0
- package/dist/generated/duel/instructions/joinQueue.d.ts +51 -0
- package/dist/generated/duel/instructions/joinQueue.js +56 -0
- package/dist/generated/duel/instructions/processUndelegation.d.ts +43 -0
- package/dist/generated/duel/instructions/processUndelegation.js +49 -0
- package/dist/generated/duel/instructions/setupTicketPermission.d.ts +54 -0
- package/dist/generated/duel/instructions/setupTicketPermission.js +63 -0
- package/dist/generated/duel/programs/duel.d.ts +92 -0
- package/dist/generated/duel/programs/duel.js +146 -0
- package/dist/generated/duel/programs/index.d.ts +8 -0
- package/dist/generated/duel/programs/index.js +9 -0
- package/dist/generated/duel/types/accountType.d.ts +25 -0
- package/dist/generated/duel/types/accountType.js +25 -0
- package/dist/generated/duel/types/index.d.ts +13 -0
- package/dist/generated/duel/types/index.js +14 -0
- package/dist/generated/duel/types/matchEntry.d.ts +23 -0
- package/dist/generated/duel/types/matchEntry.js +18 -0
- package/dist/generated/duel/types/matchFound.d.ts +23 -0
- package/dist/generated/duel/types/matchFound.js +18 -0
- package/dist/generated/duel/types/pendingMatch.d.ts +21 -0
- package/dist/generated/duel/types/pendingMatch.js +18 -0
- package/dist/generated/duel/types/queueEntry.d.ts +19 -0
- package/dist/generated/duel/types/queueEntry.js +18 -0
- package/dist/generated/duel/types/ticketStatus.d.ts +40 -0
- package/dist/generated/duel/types/ticketStatus.js +25 -0
- package/dist/generated/rps-game/accounts/gameSession.d.ts +40 -0
- package/dist/generated/rps-game/accounts/gameSession.js +45 -0
- package/dist/generated/rps-game/accounts/index.d.ts +9 -0
- package/dist/generated/rps-game/accounts/index.js +10 -0
- package/dist/generated/rps-game/accounts/playerProfile.d.ts +36 -0
- package/dist/generated/rps-game/accounts/playerProfile.js +47 -0
- package/dist/generated/rps-game/errors/index.d.ts +8 -0
- package/dist/generated/rps-game/errors/index.js +9 -0
- package/dist/generated/rps-game/errors/rpsGame.d.ts +25 -0
- package/dist/generated/rps-game/errors/rpsGame.js +29 -0
- package/dist/generated/rps-game/index.d.ts +12 -0
- package/dist/generated/rps-game/index.js +13 -0
- package/dist/generated/rps-game/instructions/closePlayer.d.ts +45 -0
- package/dist/generated/rps-game/instructions/closePlayer.js +56 -0
- package/dist/generated/rps-game/instructions/delegatePda.d.ts +69 -0
- package/dist/generated/rps-game/instructions/delegatePda.js +90 -0
- package/dist/generated/rps-game/instructions/index.d.ts +16 -0
- package/dist/generated/rps-game/instructions/index.js +17 -0
- package/dist/generated/rps-game/instructions/initializePlayer.d.ts +48 -0
- package/dist/generated/rps-game/instructions/initializePlayer.js +63 -0
- package/dist/generated/rps-game/instructions/makeChoice.d.ts +44 -0
- package/dist/generated/rps-game/instructions/makeChoice.js +46 -0
- package/dist/generated/rps-game/instructions/onMatchFound.d.ts +43 -0
- package/dist/generated/rps-game/instructions/onMatchFound.js +45 -0
- package/dist/generated/rps-game/instructions/persistResults.d.ts +43 -0
- package/dist/generated/rps-game/instructions/persistResults.js +50 -0
- package/dist/generated/rps-game/instructions/processUndelegation.d.ts +43 -0
- package/dist/generated/rps-game/instructions/processUndelegation.js +49 -0
- package/dist/generated/rps-game/instructions/startGame.d.ts +54 -0
- package/dist/generated/rps-game/instructions/startGame.js +67 -0
- package/dist/generated/rps-game/instructions/startGameWithTicket.d.ts +57 -0
- package/dist/generated/rps-game/instructions/startGameWithTicket.js +67 -0
- package/dist/generated/rps-game/programs/index.d.ts +8 -0
- package/dist/generated/rps-game/programs/index.js +9 -0
- package/dist/generated/rps-game/programs/rpsGame.d.ts +78 -0
- package/dist/generated/rps-game/programs/rpsGame.js +118 -0
- package/dist/generated/rps-game/types/accountType.d.ts +34 -0
- package/dist/generated/rps-game/types/accountType.js +25 -0
- package/dist/generated/rps-game/types/choice.d.ts +17 -0
- package/dist/generated/rps-game/types/choice.js +25 -0
- package/dist/generated/rps-game/types/gameResult.d.ts +26 -0
- package/dist/generated/rps-game/types/gameResult.js +25 -0
- package/dist/generated/rps-game/types/index.d.ts +10 -0
- package/dist/generated/rps-game/types/index.js +11 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/player.d.ts +25 -46
- package/dist/player.js +81 -140
- package/dist/tee.d.ts +14 -0
- package/dist/tee.js +62 -0
- package/dist/transaction.d.ts +11 -0
- package/dist/transaction.js +50 -0
- package/dist/utils.d.ts +4 -4
- package/dist/utils.js +23 -8
- package/package.json +3 -6
- package/src/admin.ts +151 -161
- package/src/duel.json +66 -7
- package/src/encryption.ts +0 -3
- package/src/generated/duel/accounts/index.ts +11 -0
- package/src/generated/duel/accounts/matchTicket.ts +77 -0
- package/src/generated/duel/accounts/queue.ts +77 -0
- package/src/generated/duel/accounts/tenant.ts +76 -0
- package/src/generated/duel/errors/duel.ts +46 -0
- package/src/generated/duel/errors/index.ts +9 -0
- package/src/generated/duel/index.ts +13 -0
- package/src/generated/duel/instructions/cancelTicket.ts +100 -0
- package/src/generated/duel/instructions/closeTicket.ts +100 -0
- package/src/generated/duel/instructions/commitTickets.ts +84 -0
- package/src/generated/duel/instructions/createTicket.ts +109 -0
- package/src/generated/duel/instructions/delegateQueue.ts +157 -0
- package/src/generated/duel/instructions/delegateTicket.ts +157 -0
- package/src/generated/duel/instructions/flushMatches.ts +76 -0
- package/src/generated/duel/instructions/index.ts +20 -0
- package/src/generated/duel/instructions/initializeQueue.ts +109 -0
- package/src/generated/duel/instructions/initializeTenant.ts +126 -0
- package/src/generated/duel/instructions/joinQueue.ts +106 -0
- package/src/generated/duel/instructions/processUndelegation.ts +86 -0
- package/src/generated/duel/instructions/setupTicketPermission.ts +115 -0
- package/src/generated/duel/programs/duel.ts +108 -0
- package/src/generated/duel/programs/index.ts +9 -0
- package/src/generated/duel/types/accountType.ts +36 -0
- package/src/generated/duel/types/index.ts +14 -0
- package/src/generated/duel/types/matchEntry.ts +25 -0
- package/src/generated/duel/types/matchFound.ts +25 -0
- package/src/generated/duel/types/pendingMatch.ts +25 -0
- package/src/generated/duel/types/queueEntry.ts +25 -0
- package/src/generated/duel/types/ticketStatus.ts +38 -0
- package/src/generated/rps-game/accounts/gameSession.ts +77 -0
- package/src/generated/rps-game/accounts/index.ts +10 -0
- package/src/generated/rps-game/accounts/playerProfile.ts +80 -0
- package/src/generated/rps-game/errors/index.ts +9 -0
- package/src/generated/rps-game/errors/rpsGame.ts +40 -0
- package/src/generated/rps-game/index.ts +13 -0
- package/src/generated/rps-game/instructions/closePlayer.ts +100 -0
- package/src/generated/rps-game/instructions/delegatePda.ts +157 -0
- package/src/generated/rps-game/instructions/index.ts +17 -0
- package/src/generated/rps-game/instructions/initializePlayer.ts +109 -0
- package/src/generated/rps-game/instructions/makeChoice.ts +84 -0
- package/src/generated/rps-game/instructions/onMatchFound.ts +79 -0
- package/src/generated/rps-game/instructions/persistResults.ts +88 -0
- package/src/generated/rps-game/instructions/processUndelegation.ts +86 -0
- package/src/generated/rps-game/instructions/startGame.ts +118 -0
- package/src/generated/rps-game/instructions/startGameWithTicket.ts +121 -0
- package/src/generated/rps-game/programs/index.ts +9 -0
- package/src/generated/rps-game/programs/rpsGame.ts +95 -0
- package/src/generated/rps-game/types/accountType.ts +36 -0
- package/src/generated/rps-game/types/choice.ts +25 -0
- package/src/generated/rps-game/types/gameResult.ts +37 -0
- package/src/generated/rps-game/types/index.ts +11 -0
- package/src/index.ts +2 -1
- package/src/player.ts +129 -192
- package/src/{idl/private_matchmaking.json → rps_game.json} +547 -583
- package/src/tee.ts +79 -0
- package/src/transaction.ts +90 -0
- package/src/utils.ts +35 -20
- package/tsconfig.json +2 -2
- package/dist/client.d.ts +0 -54
- package/dist/client.js +0 -265
- package/dist/duel.json +0 -1207
- package/dist/private_matchmaking.json +0 -534
- package/dist/types.d.ts +0 -635
- package/dist/types.js +0 -2
- package/src/idl/private_matchmaking.ts +0 -1033
- package/src/types.ts +0 -300
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
|
|
10
|
+
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core';
|
|
11
|
+
import { RPS_GAME_PROGRAM_ADDRESS } from '../programs';
|
|
12
|
+
|
|
13
|
+
export const PERSIST_RESULTS_DISCRIMINATOR = new Uint8Array([9, 175, 42, 217, 2, 48, 80, 81]);
|
|
14
|
+
|
|
15
|
+
export function getPersistResultsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PERSIST_RESULTS_DISCRIMINATOR); }
|
|
16
|
+
|
|
17
|
+
export type PersistResultsInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountGameSession extends string | AccountMeta<string> = string, TAccountPlayer1Profile extends string | AccountMeta<string> = string, TAccountPlayer2Profile extends string | AccountMeta<string> = string, TAccountPayer extends string | AccountMeta<string> = string, TAccountMagicProgram extends string | AccountMeta<string> = "Magic11111111111111111111111111111111111111", TAccountMagicContext extends string | AccountMeta<string> = "MagicContext1111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
18
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountGameSession extends string ? WritableAccount<TAccountGameSession> : TAccountGameSession, TAccountPlayer1Profile extends string ? WritableAccount<TAccountPlayer1Profile> : TAccountPlayer1Profile, TAccountPlayer2Profile extends string ? WritableAccount<TAccountPlayer2Profile> : TAccountPlayer2Profile, TAccountPayer extends string ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer> : TAccountPayer, TAccountMagicProgram extends string ? ReadonlyAccount<TAccountMagicProgram> : TAccountMagicProgram, TAccountMagicContext extends string ? WritableAccount<TAccountMagicContext> : TAccountMagicContext, ...TRemainingAccounts]>;
|
|
19
|
+
|
|
20
|
+
export type PersistResultsInstructionData = { discriminator: ReadonlyUint8Array; };
|
|
21
|
+
|
|
22
|
+
export type PersistResultsInstructionDataArgs = { };
|
|
23
|
+
|
|
24
|
+
export function getPersistResultsInstructionDataEncoder(): FixedSizeEncoder<PersistResultsInstructionDataArgs> {
|
|
25
|
+
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: PERSIST_RESULTS_DISCRIMINATOR }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getPersistResultsInstructionDataDecoder(): FixedSizeDecoder<PersistResultsInstructionData> {
|
|
29
|
+
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getPersistResultsInstructionDataCodec(): FixedSizeCodec<PersistResultsInstructionDataArgs, PersistResultsInstructionData> {
|
|
33
|
+
return combineCodec(getPersistResultsInstructionDataEncoder(), getPersistResultsInstructionDataDecoder());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type PersistResultsInput<TAccountGameSession extends string = string, TAccountPlayer1Profile extends string = string, TAccountPlayer2Profile extends string = string, TAccountPayer extends string = string, TAccountMagicProgram extends string = string, TAccountMagicContext extends string = string> = {
|
|
37
|
+
gameSession: Address<TAccountGameSession>;
|
|
38
|
+
player1Profile: Address<TAccountPlayer1Profile>;
|
|
39
|
+
player2Profile: Address<TAccountPlayer2Profile>;
|
|
40
|
+
payer: TransactionSigner<TAccountPayer>;
|
|
41
|
+
magicProgram?: Address<TAccountMagicProgram>;
|
|
42
|
+
magicContext?: Address<TAccountMagicContext>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getPersistResultsInstruction<TAccountGameSession extends string, TAccountPlayer1Profile extends string, TAccountPlayer2Profile extends string, TAccountPayer extends string, TAccountMagicProgram extends string, TAccountMagicContext extends string, TProgramAddress extends Address = typeof RPS_GAME_PROGRAM_ADDRESS>(input: PersistResultsInput<TAccountGameSession, TAccountPlayer1Profile, TAccountPlayer2Profile, TAccountPayer, TAccountMagicProgram, TAccountMagicContext>, config?: { programAddress?: TProgramAddress } ): PersistResultsInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer1Profile, TAccountPlayer2Profile, TAccountPayer, TAccountMagicProgram, TAccountMagicContext> {
|
|
46
|
+
// Program address.
|
|
47
|
+
const programAddress = config?.programAddress ?? RPS_GAME_PROGRAM_ADDRESS;
|
|
48
|
+
|
|
49
|
+
// Original accounts.
|
|
50
|
+
const originalAccounts = { gameSession: { value: input.gameSession ?? null, isWritable: true }, player1Profile: { value: input.player1Profile ?? null, isWritable: true }, player2Profile: { value: input.player2Profile ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, magicProgram: { value: input.magicProgram ?? null, isWritable: false }, magicContext: { value: input.magicContext ?? null, isWritable: true } }
|
|
51
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// Resolve default values.
|
|
55
|
+
if (!accounts.magicProgram.value) {
|
|
56
|
+
accounts.magicProgram.value = 'Magic11111111111111111111111111111111111111' as Address<'Magic11111111111111111111111111111111111111'>;
|
|
57
|
+
}
|
|
58
|
+
if (!accounts.magicContext.value) {
|
|
59
|
+
accounts.magicContext.value = 'MagicContext1111111111111111111111111111111' as Address<'MagicContext1111111111111111111111111111111'>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
63
|
+
return Object.freeze({ accounts: [getAccountMeta("gameSession", accounts.gameSession), getAccountMeta("player1Profile", accounts.player1Profile), getAccountMeta("player2Profile", accounts.player2Profile), getAccountMeta("payer", accounts.payer), getAccountMeta("magicProgram", accounts.magicProgram), getAccountMeta("magicContext", accounts.magicContext)], data: getPersistResultsInstructionDataEncoder().encode({}), programAddress } as PersistResultsInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer1Profile, TAccountPlayer2Profile, TAccountPayer, TAccountMagicProgram, TAccountMagicContext>);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type ParsedPersistResultsInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
67
|
+
accounts: {
|
|
68
|
+
gameSession: TAccountMetas[0];
|
|
69
|
+
player1Profile: TAccountMetas[1];
|
|
70
|
+
player2Profile: TAccountMetas[2];
|
|
71
|
+
payer: TAccountMetas[3];
|
|
72
|
+
magicProgram: TAccountMetas[4];
|
|
73
|
+
magicContext: TAccountMetas[5];
|
|
74
|
+
};
|
|
75
|
+
data: PersistResultsInstructionData; };
|
|
76
|
+
|
|
77
|
+
export function parsePersistResultsInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedPersistResultsInstruction<TProgram, TAccountMetas> {
|
|
78
|
+
if (instruction.accounts.length < 6) {
|
|
79
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 6 });
|
|
80
|
+
}
|
|
81
|
+
let accountIndex = 0;
|
|
82
|
+
const getNextAccount = () => {
|
|
83
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
84
|
+
accountIndex += 1;
|
|
85
|
+
return accountMeta;
|
|
86
|
+
}
|
|
87
|
+
return { programAddress: instruction.programAddress, accounts: { gameSession: getNextAccount(), player1Profile: getNextAccount(), player2Profile: getNextAccount(), payer: getNextAccount(), magicProgram: getNextAccount(), magicContext: getNextAccount() }, data: getPersistResultsInstructionDataDecoder().decode(instruction.data) };
|
|
88
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount } from '@solana/kit';
|
|
10
|
+
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core';
|
|
11
|
+
import { RPS_GAME_PROGRAM_ADDRESS } from '../programs';
|
|
12
|
+
|
|
13
|
+
export const PROCESS_UNDELEGATION_DISCRIMINATOR = new Uint8Array([196, 28, 41, 206, 48, 37, 51, 167]);
|
|
14
|
+
|
|
15
|
+
export function getProcessUndelegationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PROCESS_UNDELEGATION_DISCRIMINATOR); }
|
|
16
|
+
|
|
17
|
+
export type ProcessUndelegationInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountBaseAccount extends string | AccountMeta<string> = string, TAccountBuffer extends string | AccountMeta<string> = string, TAccountPayer extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
18
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountBaseAccount extends string ? WritableAccount<TAccountBaseAccount> : TAccountBaseAccount, TAccountBuffer extends string ? ReadonlyAccount<TAccountBuffer> : TAccountBuffer, TAccountPayer extends string ? WritableAccount<TAccountPayer> : TAccountPayer, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, ...TRemainingAccounts]>;
|
|
19
|
+
|
|
20
|
+
export type ProcessUndelegationInstructionData = { discriminator: ReadonlyUint8Array; accountSeeds: Array<ReadonlyUint8Array>; };
|
|
21
|
+
|
|
22
|
+
export type ProcessUndelegationInstructionDataArgs = { accountSeeds: Array<ReadonlyUint8Array>; };
|
|
23
|
+
|
|
24
|
+
export function getProcessUndelegationInstructionDataEncoder(): Encoder<ProcessUndelegationInstructionDataArgs> {
|
|
25
|
+
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['accountSeeds', getArrayEncoder(addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()))]]), (value) => ({ ...value, discriminator: PROCESS_UNDELEGATION_DISCRIMINATOR }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getProcessUndelegationInstructionDataDecoder(): Decoder<ProcessUndelegationInstructionData> {
|
|
29
|
+
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['accountSeeds', getArrayDecoder(addDecoderSizePrefix(getBytesDecoder(), getU32Decoder()))]]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getProcessUndelegationInstructionDataCodec(): Codec<ProcessUndelegationInstructionDataArgs, ProcessUndelegationInstructionData> {
|
|
33
|
+
return combineCodec(getProcessUndelegationInstructionDataEncoder(), getProcessUndelegationInstructionDataDecoder());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ProcessUndelegationInput<TAccountBaseAccount extends string = string, TAccountBuffer extends string = string, TAccountPayer extends string = string, TAccountSystemProgram extends string = string> = {
|
|
37
|
+
baseAccount: Address<TAccountBaseAccount>;
|
|
38
|
+
buffer: Address<TAccountBuffer>;
|
|
39
|
+
payer: Address<TAccountPayer>;
|
|
40
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
41
|
+
accountSeeds: ProcessUndelegationInstructionDataArgs["accountSeeds"];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getProcessUndelegationInstruction<TAccountBaseAccount extends string, TAccountBuffer extends string, TAccountPayer extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof RPS_GAME_PROGRAM_ADDRESS>(input: ProcessUndelegationInput<TAccountBaseAccount, TAccountBuffer, TAccountPayer, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): ProcessUndelegationInstruction<TProgramAddress, TAccountBaseAccount, TAccountBuffer, TAccountPayer, TAccountSystemProgram> {
|
|
45
|
+
// Program address.
|
|
46
|
+
const programAddress = config?.programAddress ?? RPS_GAME_PROGRAM_ADDRESS;
|
|
47
|
+
|
|
48
|
+
// Original accounts.
|
|
49
|
+
const originalAccounts = { baseAccount: { value: input.baseAccount ?? null, isWritable: true }, buffer: { value: input.buffer ?? null, isWritable: false }, payer: { value: input.payer ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false } }
|
|
50
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Original args.
|
|
54
|
+
const args = { ...input, };
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// Resolve default values.
|
|
58
|
+
if (!accounts.systemProgram.value) {
|
|
59
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
63
|
+
return Object.freeze({ accounts: [getAccountMeta("baseAccount", accounts.baseAccount), getAccountMeta("buffer", accounts.buffer), getAccountMeta("payer", accounts.payer), getAccountMeta("systemProgram", accounts.systemProgram)], data: getProcessUndelegationInstructionDataEncoder().encode(args as ProcessUndelegationInstructionDataArgs), programAddress } as ProcessUndelegationInstruction<TProgramAddress, TAccountBaseAccount, TAccountBuffer, TAccountPayer, TAccountSystemProgram>);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type ParsedProcessUndelegationInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
67
|
+
accounts: {
|
|
68
|
+
baseAccount: TAccountMetas[0];
|
|
69
|
+
buffer: TAccountMetas[1];
|
|
70
|
+
payer: TAccountMetas[2];
|
|
71
|
+
systemProgram: TAccountMetas[3];
|
|
72
|
+
};
|
|
73
|
+
data: ProcessUndelegationInstructionData; };
|
|
74
|
+
|
|
75
|
+
export function parseProcessUndelegationInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedProcessUndelegationInstruction<TProgram, TAccountMetas> {
|
|
76
|
+
if (instruction.accounts.length < 4) {
|
|
77
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4 });
|
|
78
|
+
}
|
|
79
|
+
let accountIndex = 0;
|
|
80
|
+
const getNextAccount = () => {
|
|
81
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
82
|
+
accountIndex += 1;
|
|
83
|
+
return accountMeta;
|
|
84
|
+
}
|
|
85
|
+
return { programAddress: instruction.programAddress, accounts: { baseAccount: getNextAccount(), buffer: getNextAccount(), payer: getNextAccount(), systemProgram: getNextAccount() }, data: getProcessUndelegationInstructionDataDecoder().decode(instruction.data) };
|
|
86
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
|
|
10
|
+
import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, getNonNullResolvedInstructionInput, type ResolvedInstructionAccount } from '@solana/program-client-core';
|
|
11
|
+
import { RPS_GAME_PROGRAM_ADDRESS } from '../programs';
|
|
12
|
+
|
|
13
|
+
export const START_GAME_DISCRIMINATOR = new Uint8Array([249, 47, 252, 172, 184, 162, 245, 14]);
|
|
14
|
+
|
|
15
|
+
export function getStartGameDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(START_GAME_DISCRIMINATOR); }
|
|
16
|
+
|
|
17
|
+
export type StartGameInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountGameSession extends string | AccountMeta<string> = string, TAccountPlayer extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
18
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountGameSession extends string ? WritableAccount<TAccountGameSession> : TAccountGameSession, TAccountPlayer extends string ? WritableSignerAccount<TAccountPlayer> & AccountSignerMeta<TAccountPlayer> : TAccountPlayer, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, ...TRemainingAccounts]>;
|
|
19
|
+
|
|
20
|
+
export type StartGameInstructionData = { discriminator: ReadonlyUint8Array; gameId: bigint; opponent: Address; };
|
|
21
|
+
|
|
22
|
+
export type StartGameInstructionDataArgs = { gameId: number | bigint; opponent: Address; };
|
|
23
|
+
|
|
24
|
+
export function getStartGameInstructionDataEncoder(): FixedSizeEncoder<StartGameInstructionDataArgs> {
|
|
25
|
+
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['gameId', getU64Encoder()], ['opponent', getAddressEncoder()]]), (value) => ({ ...value, discriminator: START_GAME_DISCRIMINATOR }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getStartGameInstructionDataDecoder(): FixedSizeDecoder<StartGameInstructionData> {
|
|
29
|
+
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['gameId', getU64Decoder()], ['opponent', getAddressDecoder()]]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getStartGameInstructionDataCodec(): FixedSizeCodec<StartGameInstructionDataArgs, StartGameInstructionData> {
|
|
33
|
+
return combineCodec(getStartGameInstructionDataEncoder(), getStartGameInstructionDataDecoder());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type StartGameAsyncInput<TAccountGameSession extends string = string, TAccountPlayer extends string = string, TAccountSystemProgram extends string = string> = {
|
|
37
|
+
gameSession?: Address<TAccountGameSession>;
|
|
38
|
+
player: TransactionSigner<TAccountPlayer>;
|
|
39
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
40
|
+
gameId: StartGameInstructionDataArgs["gameId"];
|
|
41
|
+
opponent: StartGameInstructionDataArgs["opponent"];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function getStartGameInstructionAsync<TAccountGameSession extends string, TAccountPlayer extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof RPS_GAME_PROGRAM_ADDRESS>(input: StartGameAsyncInput<TAccountGameSession, TAccountPlayer, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): Promise<StartGameInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountSystemProgram>> {
|
|
45
|
+
// Program address.
|
|
46
|
+
const programAddress = config?.programAddress ?? RPS_GAME_PROGRAM_ADDRESS;
|
|
47
|
+
|
|
48
|
+
// Original accounts.
|
|
49
|
+
const originalAccounts = { gameSession: { value: input.gameSession ?? null, isWritable: true }, player: { value: input.player ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false } }
|
|
50
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Original args.
|
|
54
|
+
const args = { ...input, };
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// Resolve default values.
|
|
58
|
+
if (!accounts.gameSession.value) {
|
|
59
|
+
accounts.gameSession.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([103, 97, 109, 101, 95, 115, 101, 115, 115, 105, 111, 110, 95, 118, 49])), getAddressEncoder().encode(getAddressFromResolvedInstructionAccount("player", accounts.player.value)), getAddressEncoder().encode(getNonNullResolvedInstructionInput("opponent", args.opponent)), getU64Encoder().encode(getNonNullResolvedInstructionInput("gameId", args.gameId))] });
|
|
60
|
+
}
|
|
61
|
+
if (!accounts.systemProgram.value) {
|
|
62
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
66
|
+
return Object.freeze({ accounts: [getAccountMeta("gameSession", accounts.gameSession), getAccountMeta("player", accounts.player), getAccountMeta("systemProgram", accounts.systemProgram)], data: getStartGameInstructionDataEncoder().encode(args as StartGameInstructionDataArgs), programAddress } as StartGameInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountSystemProgram>);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type StartGameInput<TAccountGameSession extends string = string, TAccountPlayer extends string = string, TAccountSystemProgram extends string = string> = {
|
|
70
|
+
gameSession: Address<TAccountGameSession>;
|
|
71
|
+
player: TransactionSigner<TAccountPlayer>;
|
|
72
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
73
|
+
gameId: StartGameInstructionDataArgs["gameId"];
|
|
74
|
+
opponent: StartGameInstructionDataArgs["opponent"];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getStartGameInstruction<TAccountGameSession extends string, TAccountPlayer extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof RPS_GAME_PROGRAM_ADDRESS>(input: StartGameInput<TAccountGameSession, TAccountPlayer, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): StartGameInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountSystemProgram> {
|
|
78
|
+
// Program address.
|
|
79
|
+
const programAddress = config?.programAddress ?? RPS_GAME_PROGRAM_ADDRESS;
|
|
80
|
+
|
|
81
|
+
// Original accounts.
|
|
82
|
+
const originalAccounts = { gameSession: { value: input.gameSession ?? null, isWritable: true }, player: { value: input.player ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false } }
|
|
83
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
// Original args.
|
|
87
|
+
const args = { ...input, };
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
// Resolve default values.
|
|
91
|
+
if (!accounts.systemProgram.value) {
|
|
92
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
96
|
+
return Object.freeze({ accounts: [getAccountMeta("gameSession", accounts.gameSession), getAccountMeta("player", accounts.player), getAccountMeta("systemProgram", accounts.systemProgram)], data: getStartGameInstructionDataEncoder().encode(args as StartGameInstructionDataArgs), programAddress } as StartGameInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountSystemProgram>);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type ParsedStartGameInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
100
|
+
accounts: {
|
|
101
|
+
gameSession: TAccountMetas[0];
|
|
102
|
+
player: TAccountMetas[1];
|
|
103
|
+
systemProgram: TAccountMetas[2];
|
|
104
|
+
};
|
|
105
|
+
data: StartGameInstructionData; };
|
|
106
|
+
|
|
107
|
+
export function parseStartGameInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedStartGameInstruction<TProgram, TAccountMetas> {
|
|
108
|
+
if (instruction.accounts.length < 3) {
|
|
109
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 3 });
|
|
110
|
+
}
|
|
111
|
+
let accountIndex = 0;
|
|
112
|
+
const getNextAccount = () => {
|
|
113
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
114
|
+
accountIndex += 1;
|
|
115
|
+
return accountMeta;
|
|
116
|
+
}
|
|
117
|
+
return { programAddress: instruction.programAddress, accounts: { gameSession: getNextAccount(), player: getNextAccount(), systemProgram: getNextAccount() }, data: getStartGameInstructionDataDecoder().decode(instruction.data) };
|
|
118
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
|
|
10
|
+
import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, getNonNullResolvedInstructionInput, type ResolvedInstructionAccount } from '@solana/program-client-core';
|
|
11
|
+
import { RPS_GAME_PROGRAM_ADDRESS } from '../programs';
|
|
12
|
+
|
|
13
|
+
export const START_GAME_WITH_TICKET_DISCRIMINATOR = new Uint8Array([2, 250, 253, 202, 51, 138, 80, 20]);
|
|
14
|
+
|
|
15
|
+
export function getStartGameWithTicketDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(START_GAME_WITH_TICKET_DISCRIMINATOR); }
|
|
16
|
+
|
|
17
|
+
export type StartGameWithTicketInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountGameSession extends string | AccountMeta<string> = string, TAccountPlayer extends string | AccountMeta<string> = string, TAccountMatchTicket extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
|
|
18
|
+
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountGameSession extends string ? WritableAccount<TAccountGameSession> : TAccountGameSession, TAccountPlayer extends string ? WritableSignerAccount<TAccountPlayer> & AccountSignerMeta<TAccountPlayer> : TAccountPlayer, TAccountMatchTicket extends string ? ReadonlyAccount<TAccountMatchTicket> : TAccountMatchTicket, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, ...TRemainingAccounts]>;
|
|
19
|
+
|
|
20
|
+
export type StartGameWithTicketInstructionData = { discriminator: ReadonlyUint8Array; gameId: bigint; opponent: Address; };
|
|
21
|
+
|
|
22
|
+
export type StartGameWithTicketInstructionDataArgs = { gameId: number | bigint; opponent: Address; };
|
|
23
|
+
|
|
24
|
+
export function getStartGameWithTicketInstructionDataEncoder(): FixedSizeEncoder<StartGameWithTicketInstructionDataArgs> {
|
|
25
|
+
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['gameId', getU64Encoder()], ['opponent', getAddressEncoder()]]), (value) => ({ ...value, discriminator: START_GAME_WITH_TICKET_DISCRIMINATOR }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getStartGameWithTicketInstructionDataDecoder(): FixedSizeDecoder<StartGameWithTicketInstructionData> {
|
|
29
|
+
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['gameId', getU64Decoder()], ['opponent', getAddressDecoder()]]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getStartGameWithTicketInstructionDataCodec(): FixedSizeCodec<StartGameWithTicketInstructionDataArgs, StartGameWithTicketInstructionData> {
|
|
33
|
+
return combineCodec(getStartGameWithTicketInstructionDataEncoder(), getStartGameWithTicketInstructionDataDecoder());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type StartGameWithTicketAsyncInput<TAccountGameSession extends string = string, TAccountPlayer extends string = string, TAccountMatchTicket extends string = string, TAccountSystemProgram extends string = string> = {
|
|
37
|
+
gameSession?: Address<TAccountGameSession>;
|
|
38
|
+
player: TransactionSigner<TAccountPlayer>;
|
|
39
|
+
matchTicket: Address<TAccountMatchTicket>;
|
|
40
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
41
|
+
gameId: StartGameWithTicketInstructionDataArgs["gameId"];
|
|
42
|
+
opponent: StartGameWithTicketInstructionDataArgs["opponent"];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function getStartGameWithTicketInstructionAsync<TAccountGameSession extends string, TAccountPlayer extends string, TAccountMatchTicket extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof RPS_GAME_PROGRAM_ADDRESS>(input: StartGameWithTicketAsyncInput<TAccountGameSession, TAccountPlayer, TAccountMatchTicket, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): Promise<StartGameWithTicketInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountMatchTicket, TAccountSystemProgram>> {
|
|
46
|
+
// Program address.
|
|
47
|
+
const programAddress = config?.programAddress ?? RPS_GAME_PROGRAM_ADDRESS;
|
|
48
|
+
|
|
49
|
+
// Original accounts.
|
|
50
|
+
const originalAccounts = { gameSession: { value: input.gameSession ?? null, isWritable: true }, player: { value: input.player ?? null, isWritable: true }, matchTicket: { value: input.matchTicket ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false } }
|
|
51
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// Original args.
|
|
55
|
+
const args = { ...input, };
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Resolve default values.
|
|
59
|
+
if (!accounts.gameSession.value) {
|
|
60
|
+
accounts.gameSession.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([103, 97, 109, 101, 95, 115, 101, 115, 115, 105, 111, 110, 95, 118, 49])), getAddressEncoder().encode(getAddressFromResolvedInstructionAccount("player", accounts.player.value)), getAddressEncoder().encode(getNonNullResolvedInstructionInput("opponent", args.opponent)), getU64Encoder().encode(getNonNullResolvedInstructionInput("gameId", args.gameId))] });
|
|
61
|
+
}
|
|
62
|
+
if (!accounts.systemProgram.value) {
|
|
63
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
67
|
+
return Object.freeze({ accounts: [getAccountMeta("gameSession", accounts.gameSession), getAccountMeta("player", accounts.player), getAccountMeta("matchTicket", accounts.matchTicket), getAccountMeta("systemProgram", accounts.systemProgram)], data: getStartGameWithTicketInstructionDataEncoder().encode(args as StartGameWithTicketInstructionDataArgs), programAddress } as StartGameWithTicketInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountMatchTicket, TAccountSystemProgram>);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type StartGameWithTicketInput<TAccountGameSession extends string = string, TAccountPlayer extends string = string, TAccountMatchTicket extends string = string, TAccountSystemProgram extends string = string> = {
|
|
71
|
+
gameSession: Address<TAccountGameSession>;
|
|
72
|
+
player: TransactionSigner<TAccountPlayer>;
|
|
73
|
+
matchTicket: Address<TAccountMatchTicket>;
|
|
74
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
75
|
+
gameId: StartGameWithTicketInstructionDataArgs["gameId"];
|
|
76
|
+
opponent: StartGameWithTicketInstructionDataArgs["opponent"];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getStartGameWithTicketInstruction<TAccountGameSession extends string, TAccountPlayer extends string, TAccountMatchTicket extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof RPS_GAME_PROGRAM_ADDRESS>(input: StartGameWithTicketInput<TAccountGameSession, TAccountPlayer, TAccountMatchTicket, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): StartGameWithTicketInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountMatchTicket, TAccountSystemProgram> {
|
|
80
|
+
// Program address.
|
|
81
|
+
const programAddress = config?.programAddress ?? RPS_GAME_PROGRAM_ADDRESS;
|
|
82
|
+
|
|
83
|
+
// Original accounts.
|
|
84
|
+
const originalAccounts = { gameSession: { value: input.gameSession ?? null, isWritable: true }, player: { value: input.player ?? null, isWritable: true }, matchTicket: { value: input.matchTicket ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false } }
|
|
85
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
// Original args.
|
|
89
|
+
const args = { ...input, };
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Resolve default values.
|
|
93
|
+
if (!accounts.systemProgram.value) {
|
|
94
|
+
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
|
|
98
|
+
return Object.freeze({ accounts: [getAccountMeta("gameSession", accounts.gameSession), getAccountMeta("player", accounts.player), getAccountMeta("matchTicket", accounts.matchTicket), getAccountMeta("systemProgram", accounts.systemProgram)], data: getStartGameWithTicketInstructionDataEncoder().encode(args as StartGameWithTicketInstructionDataArgs), programAddress } as StartGameWithTicketInstruction<TProgramAddress, TAccountGameSession, TAccountPlayer, TAccountMatchTicket, TAccountSystemProgram>);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type ParsedStartGameWithTicketInstruction<TProgram extends string = typeof RPS_GAME_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
|
|
102
|
+
accounts: {
|
|
103
|
+
gameSession: TAccountMetas[0];
|
|
104
|
+
player: TAccountMetas[1];
|
|
105
|
+
matchTicket: TAccountMetas[2];
|
|
106
|
+
systemProgram: TAccountMetas[3];
|
|
107
|
+
};
|
|
108
|
+
data: StartGameWithTicketInstructionData; };
|
|
109
|
+
|
|
110
|
+
export function parseStartGameWithTicketInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedStartGameWithTicketInstruction<TProgram, TAccountMetas> {
|
|
111
|
+
if (instruction.accounts.length < 4) {
|
|
112
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4 });
|
|
113
|
+
}
|
|
114
|
+
let accountIndex = 0;
|
|
115
|
+
const getNextAccount = () => {
|
|
116
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
117
|
+
accountIndex += 1;
|
|
118
|
+
return accountMeta;
|
|
119
|
+
}
|
|
120
|
+
return { programAddress: instruction.programAddress, accounts: { gameSession: getNextAccount(), player: getNextAccount(), matchTicket: getNextAccount(), systemProgram: getNextAccount() }, data: getStartGameWithTicketInstructionDataDecoder().decode(instruction.data) };
|
|
121
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { assertIsInstructionWithAccounts, containsBytes, fixEncoderSize, getBytesEncoder, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, SolanaError, type Address, type ClientWithPayer, type ClientWithRpc, type ClientWithTransactionPlanning, type ClientWithTransactionSending, type GetAccountInfoApi, type GetMultipleAccountsApi, type Instruction, type InstructionWithData, type ReadonlyUint8Array } from '@solana/kit';
|
|
10
|
+
import { addSelfFetchFunctions, addSelfPlanAndSendFunctions, type SelfFetchFunctions, type SelfPlanAndSendFunctions } from '@solana/program-client-core';
|
|
11
|
+
import { getGameSessionCodec, getPlayerProfileCodec, type GameSession, type GameSessionArgs, type PlayerProfile, type PlayerProfileArgs } from '../accounts';
|
|
12
|
+
import { getClosePlayerInstructionAsync, getDelegatePdaInstructionAsync, getInitializePlayerInstructionAsync, getMakeChoiceInstruction, getOnMatchFoundInstruction, getPersistResultsInstruction, getProcessUndelegationInstruction, getStartGameInstructionAsync, getStartGameWithTicketInstructionAsync, parseClosePlayerInstruction, parseDelegatePdaInstruction, parseInitializePlayerInstruction, parseMakeChoiceInstruction, parseOnMatchFoundInstruction, parsePersistResultsInstruction, parseProcessUndelegationInstruction, parseStartGameInstruction, parseStartGameWithTicketInstruction, type ClosePlayerAsyncInput, type DelegatePdaAsyncInput, type InitializePlayerAsyncInput, type MakeChoiceInput, type OnMatchFoundInput, type ParsedClosePlayerInstruction, type ParsedDelegatePdaInstruction, type ParsedInitializePlayerInstruction, type ParsedMakeChoiceInstruction, type ParsedOnMatchFoundInstruction, type ParsedPersistResultsInstruction, type ParsedProcessUndelegationInstruction, type ParsedStartGameInstruction, type ParsedStartGameWithTicketInstruction, type PersistResultsInput, type ProcessUndelegationInput, type StartGameAsyncInput, type StartGameWithTicketAsyncInput } from '../instructions';
|
|
13
|
+
|
|
14
|
+
export const RPS_GAME_PROGRAM_ADDRESS = '8ohu3RobXyZ2DebyJjbs2co9YCG275FUsVckEcmDbCos' as Address<'8ohu3RobXyZ2DebyJjbs2co9YCG275FUsVckEcmDbCos'>;
|
|
15
|
+
|
|
16
|
+
export enum RpsGameAccount { GameSession, PlayerProfile }
|
|
17
|
+
|
|
18
|
+
export function identifyRpsGameAccount(account: { data: ReadonlyUint8Array } | ReadonlyUint8Array): RpsGameAccount {
|
|
19
|
+
const data = 'data' in account ? account.data : account;
|
|
20
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([150, 116, 20, 197, 205, 121, 220, 240])), 0)) { return RpsGameAccount.GameSession; }
|
|
21
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([82, 226, 99, 87, 164, 130, 181, 80])), 0)) { return RpsGameAccount.PlayerProfile; }
|
|
22
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, { accountData: data, programName: "rpsGame" });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum RpsGameInstruction { ClosePlayer, DelegatePda, InitializePlayer, MakeChoice, OnMatchFound, PersistResults, ProcessUndelegation, StartGame, StartGameWithTicket }
|
|
26
|
+
|
|
27
|
+
export function identifyRpsGameInstruction(instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array): RpsGameInstruction {
|
|
28
|
+
const data = 'data' in instruction ? instruction.data : instruction;
|
|
29
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([225, 227, 204, 63, 32, 122, 58, 227])), 0)) { return RpsGameInstruction.ClosePlayer; }
|
|
30
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([248, 217, 193, 46, 124, 191, 64, 135])), 0)) { return RpsGameInstruction.DelegatePda; }
|
|
31
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([79, 249, 88, 177, 220, 62, 56, 128])), 0)) { return RpsGameInstruction.InitializePlayer; }
|
|
32
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([207, 18, 251, 32, 135, 122, 160, 77])), 0)) { return RpsGameInstruction.MakeChoice; }
|
|
33
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([66, 209, 170, 159, 10, 195, 34, 214])), 0)) { return RpsGameInstruction.OnMatchFound; }
|
|
34
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([9, 175, 42, 217, 2, 48, 80, 81])), 0)) { return RpsGameInstruction.PersistResults; }
|
|
35
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([196, 28, 41, 206, 48, 37, 51, 167])), 0)) { return RpsGameInstruction.ProcessUndelegation; }
|
|
36
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([249, 47, 252, 172, 184, 162, 245, 14])), 0)) { return RpsGameInstruction.StartGame; }
|
|
37
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([2, 250, 253, 202, 51, 138, 80, 20])), 0)) { return RpsGameInstruction.StartGameWithTicket; }
|
|
38
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "rpsGame" });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ParsedRpsGameInstruction<TProgram extends string = '8ohu3RobXyZ2DebyJjbs2co9YCG275FUsVckEcmDbCos'> =
|
|
42
|
+
| { instructionType: RpsGameInstruction.ClosePlayer } & ParsedClosePlayerInstruction<TProgram>
|
|
43
|
+
| { instructionType: RpsGameInstruction.DelegatePda } & ParsedDelegatePdaInstruction<TProgram>
|
|
44
|
+
| { instructionType: RpsGameInstruction.InitializePlayer } & ParsedInitializePlayerInstruction<TProgram>
|
|
45
|
+
| { instructionType: RpsGameInstruction.MakeChoice } & ParsedMakeChoiceInstruction<TProgram>
|
|
46
|
+
| { instructionType: RpsGameInstruction.OnMatchFound } & ParsedOnMatchFoundInstruction<TProgram>
|
|
47
|
+
| { instructionType: RpsGameInstruction.PersistResults } & ParsedPersistResultsInstruction<TProgram>
|
|
48
|
+
| { instructionType: RpsGameInstruction.ProcessUndelegation } & ParsedProcessUndelegationInstruction<TProgram>
|
|
49
|
+
| { instructionType: RpsGameInstruction.StartGame } & ParsedStartGameInstruction<TProgram>
|
|
50
|
+
| { instructionType: RpsGameInstruction.StartGameWithTicket } & ParsedStartGameWithTicketInstruction<TProgram>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export function parseRpsGameInstruction<TProgram extends string>(
|
|
54
|
+
instruction: Instruction<TProgram>
|
|
55
|
+
& InstructionWithData<ReadonlyUint8Array>
|
|
56
|
+
): ParsedRpsGameInstruction<TProgram> {
|
|
57
|
+
const instructionType = identifyRpsGameInstruction(instruction);
|
|
58
|
+
switch (instructionType) {
|
|
59
|
+
case RpsGameInstruction.ClosePlayer: { assertIsInstructionWithAccounts(instruction);
|
|
60
|
+
return { instructionType: RpsGameInstruction.ClosePlayer, ...parseClosePlayerInstruction(instruction) }; }
|
|
61
|
+
case RpsGameInstruction.DelegatePda: { assertIsInstructionWithAccounts(instruction);
|
|
62
|
+
return { instructionType: RpsGameInstruction.DelegatePda, ...parseDelegatePdaInstruction(instruction) }; }
|
|
63
|
+
case RpsGameInstruction.InitializePlayer: { assertIsInstructionWithAccounts(instruction);
|
|
64
|
+
return { instructionType: RpsGameInstruction.InitializePlayer, ...parseInitializePlayerInstruction(instruction) }; }
|
|
65
|
+
case RpsGameInstruction.MakeChoice: { assertIsInstructionWithAccounts(instruction);
|
|
66
|
+
return { instructionType: RpsGameInstruction.MakeChoice, ...parseMakeChoiceInstruction(instruction) }; }
|
|
67
|
+
case RpsGameInstruction.OnMatchFound: { assertIsInstructionWithAccounts(instruction);
|
|
68
|
+
return { instructionType: RpsGameInstruction.OnMatchFound, ...parseOnMatchFoundInstruction(instruction) }; }
|
|
69
|
+
case RpsGameInstruction.PersistResults: { assertIsInstructionWithAccounts(instruction);
|
|
70
|
+
return { instructionType: RpsGameInstruction.PersistResults, ...parsePersistResultsInstruction(instruction) }; }
|
|
71
|
+
case RpsGameInstruction.ProcessUndelegation: { assertIsInstructionWithAccounts(instruction);
|
|
72
|
+
return { instructionType: RpsGameInstruction.ProcessUndelegation, ...parseProcessUndelegationInstruction(instruction) }; }
|
|
73
|
+
case RpsGameInstruction.StartGame: { assertIsInstructionWithAccounts(instruction);
|
|
74
|
+
return { instructionType: RpsGameInstruction.StartGame, ...parseStartGameInstruction(instruction) }; }
|
|
75
|
+
case RpsGameInstruction.StartGameWithTicket: { assertIsInstructionWithAccounts(instruction);
|
|
76
|
+
return { instructionType: RpsGameInstruction.StartGameWithTicket, ...parseStartGameWithTicketInstruction(instruction) }; }
|
|
77
|
+
default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: "rpsGame" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type RpsGamePlugin = { accounts: RpsGamePluginAccounts; instructions: RpsGamePluginInstructions; }
|
|
82
|
+
|
|
83
|
+
export type RpsGamePluginAccounts = { gameSession: ReturnType<typeof getGameSessionCodec> & SelfFetchFunctions<GameSessionArgs, GameSession>; playerProfile: ReturnType<typeof getPlayerProfileCodec> & SelfFetchFunctions<PlayerProfileArgs, PlayerProfile>; }
|
|
84
|
+
|
|
85
|
+
export type RpsGamePluginInstructions = { closePlayer: (input: MakeOptional<ClosePlayerAsyncInput, "payer">) => ReturnType<typeof getClosePlayerInstructionAsync> & SelfPlanAndSendFunctions; delegatePda: (input: MakeOptional<DelegatePdaAsyncInput, "payer">) => ReturnType<typeof getDelegatePdaInstructionAsync> & SelfPlanAndSendFunctions; initializePlayer: (input: MakeOptional<InitializePlayerAsyncInput, "payer">) => ReturnType<typeof getInitializePlayerInstructionAsync> & SelfPlanAndSendFunctions; makeChoice: (input: MakeChoiceInput) => ReturnType<typeof getMakeChoiceInstruction> & SelfPlanAndSendFunctions; onMatchFound: (input: OnMatchFoundInput) => ReturnType<typeof getOnMatchFoundInstruction> & SelfPlanAndSendFunctions; persistResults: (input: MakeOptional<PersistResultsInput, "payer">) => ReturnType<typeof getPersistResultsInstruction> & SelfPlanAndSendFunctions; processUndelegation: (input: MakeOptional<ProcessUndelegationInput, "payer">) => ReturnType<typeof getProcessUndelegationInstruction> & SelfPlanAndSendFunctions; startGame: (input: StartGameAsyncInput) => ReturnType<typeof getStartGameInstructionAsync> & SelfPlanAndSendFunctions; startGameWithTicket: (input: StartGameWithTicketAsyncInput) => ReturnType<typeof getStartGameWithTicketInstructionAsync> & SelfPlanAndSendFunctions; }
|
|
86
|
+
|
|
87
|
+
export type RpsGamePluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> & ClientWithPayer & ClientWithTransactionPlanning & ClientWithTransactionSending
|
|
88
|
+
|
|
89
|
+
export function rpsGameProgram() {
|
|
90
|
+
return <T extends RpsGamePluginRequirements>(client: T) => {
|
|
91
|
+
return { ...client, rpsGame: <RpsGamePlugin>{ accounts: { gameSession: addSelfFetchFunctions(client, getGameSessionCodec()), playerProfile: addSelfFetchFunctions(client, getPlayerProfileCodec()) }, instructions: { closePlayer: input => addSelfPlanAndSendFunctions(client, getClosePlayerInstructionAsync({ ...input, payer: input.payer ?? client.payer.address })), delegatePda: input => addSelfPlanAndSendFunctions(client, getDelegatePdaInstructionAsync({ ...input, payer: input.payer ?? client.payer })), initializePlayer: input => addSelfPlanAndSendFunctions(client, getInitializePlayerInstructionAsync({ ...input, payer: input.payer ?? client.payer })), makeChoice: input => addSelfPlanAndSendFunctions(client, getMakeChoiceInstruction(input)), onMatchFound: input => addSelfPlanAndSendFunctions(client, getOnMatchFoundInstruction(input)), persistResults: input => addSelfPlanAndSendFunctions(client, getPersistResultsInstruction({ ...input, payer: input.payer ?? client.payer })), processUndelegation: input => addSelfPlanAndSendFunctions(client, getProcessUndelegationInstruction({ ...input, payer: input.payer ?? client.payer.address })), startGame: input => addSelfPlanAndSendFunctions(client, getStartGameInstructionAsync(input)), startGameWithTicket: input => addSelfPlanAndSendFunctions(client, getStartGameWithTicketInstructionAsync(input)) } } };
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { combineCodec, getAddressDecoder, getAddressEncoder, getDiscriminatedUnionDecoder, getDiscriminatedUnionEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, type Address, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type AccountType = { __kind: "PlayerProfile", player: Address; } | { __kind: "GameSession", p1: Address; p2: Address; id: bigint; };
|
|
12
|
+
|
|
13
|
+
export type AccountTypeArgs = { __kind: "PlayerProfile", player: Address; } | { __kind: "GameSession", p1: Address; p2: Address; id: number | bigint; };
|
|
14
|
+
|
|
15
|
+
export function getAccountTypeEncoder(): Encoder<AccountTypeArgs> {
|
|
16
|
+
return getDiscriminatedUnionEncoder([['PlayerProfile', getStructEncoder([['player', getAddressEncoder()]])], ['GameSession', getStructEncoder([['p1', getAddressEncoder()], ['p2', getAddressEncoder()], ['id', getU64Encoder()]])]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getAccountTypeDecoder(): Decoder<AccountType> {
|
|
20
|
+
return getDiscriminatedUnionDecoder([['PlayerProfile', getStructDecoder([['player', getAddressDecoder()]])], ['GameSession', getStructDecoder([['p1', getAddressDecoder()], ['p2', getAddressDecoder()], ['id', getU64Decoder()]])]]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getAccountTypeCodec(): Codec<AccountTypeArgs, AccountType> {
|
|
24
|
+
return combineCodec(getAccountTypeEncoder(), getAccountTypeDecoder());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Data Enum Helpers.
|
|
28
|
+
export function accountType(kind: 'PlayerProfile', data: GetDiscriminatedUnionVariantContent<AccountTypeArgs, '__kind', 'PlayerProfile'>): GetDiscriminatedUnionVariant<AccountTypeArgs, '__kind', 'PlayerProfile'>;
|
|
29
|
+
export function accountType(kind: 'GameSession', data: GetDiscriminatedUnionVariantContent<AccountTypeArgs, '__kind', 'GameSession'>): GetDiscriminatedUnionVariant<AccountTypeArgs, '__kind', 'GameSession'>;
|
|
30
|
+
export function accountType<K extends AccountTypeArgs['__kind'], Data>(kind: K, data?: Data) {
|
|
31
|
+
return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isAccountType<K extends AccountType['__kind']>(kind: K, value: AccountType): value is AccountType & { __kind: K } {
|
|
35
|
+
return value.__kind === kind;
|
|
36
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { combineCodec, getEnumDecoder, getEnumEncoder, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export enum Choice { Rock, Paper, Scissors };
|
|
12
|
+
|
|
13
|
+
export type ChoiceArgs = Choice;
|
|
14
|
+
|
|
15
|
+
export function getChoiceEncoder(): FixedSizeEncoder<ChoiceArgs> {
|
|
16
|
+
return getEnumEncoder(Choice);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getChoiceDecoder(): FixedSizeDecoder<Choice> {
|
|
20
|
+
return getEnumDecoder(Choice);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getChoiceCodec(): FixedSizeCodec<ChoiceArgs, Choice> {
|
|
24
|
+
return combineCodec(getChoiceEncoder(), getChoiceDecoder());
|
|
25
|
+
}
|