@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,108 @@
|
|
|
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 { getMatchTicketCodec, getQueueCodec, getTenantCodec, type MatchTicket, type MatchTicketArgs, type Queue, type QueueArgs, type Tenant, type TenantArgs } from '../accounts';
|
|
12
|
+
import { getCancelTicketInstructionAsync, getCloseTicketInstructionAsync, getCommitTicketsInstruction, getCreateTicketInstructionAsync, getDelegateQueueInstructionAsync, getDelegateTicketInstructionAsync, getFlushMatchesInstruction, getInitializeQueueInstructionAsync, getInitializeTenantInstructionAsync, getJoinQueueInstructionAsync, getProcessUndelegationInstruction, getSetupTicketPermissionInstructionAsync, parseCancelTicketInstruction, parseCloseTicketInstruction, parseCommitTicketsInstruction, parseCreateTicketInstruction, parseDelegateQueueInstruction, parseDelegateTicketInstruction, parseFlushMatchesInstruction, parseInitializeQueueInstruction, parseInitializeTenantInstruction, parseJoinQueueInstruction, parseProcessUndelegationInstruction, parseSetupTicketPermissionInstruction, type CancelTicketAsyncInput, type CloseTicketAsyncInput, type CommitTicketsInput, type CreateTicketAsyncInput, type DelegateQueueAsyncInput, type DelegateTicketAsyncInput, type FlushMatchesInput, type InitializeQueueAsyncInput, type InitializeTenantAsyncInput, type JoinQueueAsyncInput, type ParsedCancelTicketInstruction, type ParsedCloseTicketInstruction, type ParsedCommitTicketsInstruction, type ParsedCreateTicketInstruction, type ParsedDelegateQueueInstruction, type ParsedDelegateTicketInstruction, type ParsedFlushMatchesInstruction, type ParsedInitializeQueueInstruction, type ParsedInitializeTenantInstruction, type ParsedJoinQueueInstruction, type ParsedProcessUndelegationInstruction, type ParsedSetupTicketPermissionInstruction, type ProcessUndelegationInput, type SetupTicketPermissionAsyncInput } from '../instructions';
|
|
13
|
+
|
|
14
|
+
export const DUEL_PROGRAM_ADDRESS = 'EdZzUwKd1X2ZWjxLPpz1cpEzMF7RUZC43Pq64v1VcK5X' as Address<'EdZzUwKd1X2ZWjxLPpz1cpEzMF7RUZC43Pq64v1VcK5X'>;
|
|
15
|
+
|
|
16
|
+
export enum DuelAccount { MatchTicket, Queue, Tenant }
|
|
17
|
+
|
|
18
|
+
export function identifyDuelAccount(account: { data: ReadonlyUint8Array } | ReadonlyUint8Array): DuelAccount {
|
|
19
|
+
const data = 'data' in account ? account.data : account;
|
|
20
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([11, 131, 4, 157, 207, 79, 126, 5])), 0)) { return DuelAccount.MatchTicket; }
|
|
21
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([204, 167, 6, 247, 20, 33, 2, 188])), 0)) { return DuelAccount.Queue; }
|
|
22
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([61, 43, 215, 51, 232, 242, 209, 170])), 0)) { return DuelAccount.Tenant; }
|
|
23
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, { accountData: data, programName: "duel" });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum DuelInstruction { CancelTicket, CloseTicket, CommitTickets, CreateTicket, DelegateQueue, DelegateTicket, FlushMatches, InitializeQueue, InitializeTenant, JoinQueue, ProcessUndelegation, SetupTicketPermission }
|
|
27
|
+
|
|
28
|
+
export function identifyDuelInstruction(instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array): DuelInstruction {
|
|
29
|
+
const data = 'data' in instruction ? instruction.data : instruction;
|
|
30
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([216, 28, 247, 206, 195, 171, 100, 143])), 0)) { return DuelInstruction.CancelTicket; }
|
|
31
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([66, 209, 114, 197, 75, 27, 182, 117])), 0)) { return DuelInstruction.CloseTicket; }
|
|
32
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([245, 199, 81, 0, 62, 133, 18, 22])), 0)) { return DuelInstruction.CommitTickets; }
|
|
33
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([16, 178, 122, 25, 213, 85, 96, 129])), 0)) { return DuelInstruction.CreateTicket; }
|
|
34
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([31, 200, 139, 125, 93, 239, 83, 87])), 0)) { return DuelInstruction.DelegateQueue; }
|
|
35
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([195, 3, 78, 64, 128, 235, 209, 171])), 0)) { return DuelInstruction.DelegateTicket; }
|
|
36
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([49, 148, 163, 71, 77, 63, 197, 76])), 0)) { return DuelInstruction.FlushMatches; }
|
|
37
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([174, 102, 132, 232, 90, 202, 27, 20])), 0)) { return DuelInstruction.InitializeQueue; }
|
|
38
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([94, 120, 34, 186, 57, 167, 241, 206])), 0)) { return DuelInstruction.InitializeTenant; }
|
|
39
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([157, 115, 48, 109, 65, 86, 203, 238])), 0)) { return DuelInstruction.JoinQueue; }
|
|
40
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([196, 28, 41, 206, 48, 37, 51, 167])), 0)) { return DuelInstruction.ProcessUndelegation; }
|
|
41
|
+
if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([164, 29, 7, 235, 183, 223, 11, 85])), 0)) { return DuelInstruction.SetupTicketPermission; }
|
|
42
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "duel" });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type ParsedDuelInstruction<TProgram extends string = 'EdZzUwKd1X2ZWjxLPpz1cpEzMF7RUZC43Pq64v1VcK5X'> =
|
|
46
|
+
| { instructionType: DuelInstruction.CancelTicket } & ParsedCancelTicketInstruction<TProgram>
|
|
47
|
+
| { instructionType: DuelInstruction.CloseTicket } & ParsedCloseTicketInstruction<TProgram>
|
|
48
|
+
| { instructionType: DuelInstruction.CommitTickets } & ParsedCommitTicketsInstruction<TProgram>
|
|
49
|
+
| { instructionType: DuelInstruction.CreateTicket } & ParsedCreateTicketInstruction<TProgram>
|
|
50
|
+
| { instructionType: DuelInstruction.DelegateQueue } & ParsedDelegateQueueInstruction<TProgram>
|
|
51
|
+
| { instructionType: DuelInstruction.DelegateTicket } & ParsedDelegateTicketInstruction<TProgram>
|
|
52
|
+
| { instructionType: DuelInstruction.FlushMatches } & ParsedFlushMatchesInstruction<TProgram>
|
|
53
|
+
| { instructionType: DuelInstruction.InitializeQueue } & ParsedInitializeQueueInstruction<TProgram>
|
|
54
|
+
| { instructionType: DuelInstruction.InitializeTenant } & ParsedInitializeTenantInstruction<TProgram>
|
|
55
|
+
| { instructionType: DuelInstruction.JoinQueue } & ParsedJoinQueueInstruction<TProgram>
|
|
56
|
+
| { instructionType: DuelInstruction.ProcessUndelegation } & ParsedProcessUndelegationInstruction<TProgram>
|
|
57
|
+
| { instructionType: DuelInstruction.SetupTicketPermission } & ParsedSetupTicketPermissionInstruction<TProgram>
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export function parseDuelInstruction<TProgram extends string>(
|
|
61
|
+
instruction: Instruction<TProgram>
|
|
62
|
+
& InstructionWithData<ReadonlyUint8Array>
|
|
63
|
+
): ParsedDuelInstruction<TProgram> {
|
|
64
|
+
const instructionType = identifyDuelInstruction(instruction);
|
|
65
|
+
switch (instructionType) {
|
|
66
|
+
case DuelInstruction.CancelTicket: { assertIsInstructionWithAccounts(instruction);
|
|
67
|
+
return { instructionType: DuelInstruction.CancelTicket, ...parseCancelTicketInstruction(instruction) }; }
|
|
68
|
+
case DuelInstruction.CloseTicket: { assertIsInstructionWithAccounts(instruction);
|
|
69
|
+
return { instructionType: DuelInstruction.CloseTicket, ...parseCloseTicketInstruction(instruction) }; }
|
|
70
|
+
case DuelInstruction.CommitTickets: { assertIsInstructionWithAccounts(instruction);
|
|
71
|
+
return { instructionType: DuelInstruction.CommitTickets, ...parseCommitTicketsInstruction(instruction) }; }
|
|
72
|
+
case DuelInstruction.CreateTicket: { assertIsInstructionWithAccounts(instruction);
|
|
73
|
+
return { instructionType: DuelInstruction.CreateTicket, ...parseCreateTicketInstruction(instruction) }; }
|
|
74
|
+
case DuelInstruction.DelegateQueue: { assertIsInstructionWithAccounts(instruction);
|
|
75
|
+
return { instructionType: DuelInstruction.DelegateQueue, ...parseDelegateQueueInstruction(instruction) }; }
|
|
76
|
+
case DuelInstruction.DelegateTicket: { assertIsInstructionWithAccounts(instruction);
|
|
77
|
+
return { instructionType: DuelInstruction.DelegateTicket, ...parseDelegateTicketInstruction(instruction) }; }
|
|
78
|
+
case DuelInstruction.FlushMatches: { assertIsInstructionWithAccounts(instruction);
|
|
79
|
+
return { instructionType: DuelInstruction.FlushMatches, ...parseFlushMatchesInstruction(instruction) }; }
|
|
80
|
+
case DuelInstruction.InitializeQueue: { assertIsInstructionWithAccounts(instruction);
|
|
81
|
+
return { instructionType: DuelInstruction.InitializeQueue, ...parseInitializeQueueInstruction(instruction) }; }
|
|
82
|
+
case DuelInstruction.InitializeTenant: { assertIsInstructionWithAccounts(instruction);
|
|
83
|
+
return { instructionType: DuelInstruction.InitializeTenant, ...parseInitializeTenantInstruction(instruction) }; }
|
|
84
|
+
case DuelInstruction.JoinQueue: { assertIsInstructionWithAccounts(instruction);
|
|
85
|
+
return { instructionType: DuelInstruction.JoinQueue, ...parseJoinQueueInstruction(instruction) }; }
|
|
86
|
+
case DuelInstruction.ProcessUndelegation: { assertIsInstructionWithAccounts(instruction);
|
|
87
|
+
return { instructionType: DuelInstruction.ProcessUndelegation, ...parseProcessUndelegationInstruction(instruction) }; }
|
|
88
|
+
case DuelInstruction.SetupTicketPermission: { assertIsInstructionWithAccounts(instruction);
|
|
89
|
+
return { instructionType: DuelInstruction.SetupTicketPermission, ...parseSetupTicketPermissionInstruction(instruction) }; }
|
|
90
|
+
default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: "duel" });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type DuelPlugin = { accounts: DuelPluginAccounts; instructions: DuelPluginInstructions; }
|
|
95
|
+
|
|
96
|
+
export type DuelPluginAccounts = { matchTicket: ReturnType<typeof getMatchTicketCodec> & SelfFetchFunctions<MatchTicketArgs, MatchTicket>; queue: ReturnType<typeof getQueueCodec> & SelfFetchFunctions<QueueArgs, Queue>; tenant: ReturnType<typeof getTenantCodec> & SelfFetchFunctions<TenantArgs, Tenant>; }
|
|
97
|
+
|
|
98
|
+
export type DuelPluginInstructions = { cancelTicket: (input: CancelTicketAsyncInput) => ReturnType<typeof getCancelTicketInstructionAsync> & SelfPlanAndSendFunctions; closeTicket: (input: CloseTicketAsyncInput) => ReturnType<typeof getCloseTicketInstructionAsync> & SelfPlanAndSendFunctions; commitTickets: (input: MakeOptional<CommitTicketsInput, "payer">) => ReturnType<typeof getCommitTicketsInstruction> & SelfPlanAndSendFunctions; createTicket: (input: CreateTicketAsyncInput) => ReturnType<typeof getCreateTicketInstructionAsync> & SelfPlanAndSendFunctions; delegateQueue: (input: MakeOptional<DelegateQueueAsyncInput, "payer">) => ReturnType<typeof getDelegateQueueInstructionAsync> & SelfPlanAndSendFunctions; delegateTicket: (input: MakeOptional<DelegateTicketAsyncInput, "payer">) => ReturnType<typeof getDelegateTicketInstructionAsync> & SelfPlanAndSendFunctions; flushMatches: (input: FlushMatchesInput) => ReturnType<typeof getFlushMatchesInstruction> & SelfPlanAndSendFunctions; initializeQueue: (input: InitializeQueueAsyncInput) => ReturnType<typeof getInitializeQueueInstructionAsync> & SelfPlanAndSendFunctions; initializeTenant: (input: InitializeTenantAsyncInput) => ReturnType<typeof getInitializeTenantInstructionAsync> & SelfPlanAndSendFunctions; joinQueue: (input: JoinQueueAsyncInput) => ReturnType<typeof getJoinQueueInstructionAsync> & SelfPlanAndSendFunctions; processUndelegation: (input: MakeOptional<ProcessUndelegationInput, "payer">) => ReturnType<typeof getProcessUndelegationInstruction> & SelfPlanAndSendFunctions; setupTicketPermission: (input: SetupTicketPermissionAsyncInput) => ReturnType<typeof getSetupTicketPermissionInstructionAsync> & SelfPlanAndSendFunctions; }
|
|
99
|
+
|
|
100
|
+
export type DuelPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> & ClientWithPayer & ClientWithTransactionPlanning & ClientWithTransactionSending
|
|
101
|
+
|
|
102
|
+
export function duelProgram() {
|
|
103
|
+
return <T extends DuelPluginRequirements>(client: T) => {
|
|
104
|
+
return { ...client, duel: <DuelPlugin>{ accounts: { matchTicket: addSelfFetchFunctions(client, getMatchTicketCodec()), queue: addSelfFetchFunctions(client, getQueueCodec()), tenant: addSelfFetchFunctions(client, getTenantCodec()) }, instructions: { cancelTicket: input => addSelfPlanAndSendFunctions(client, getCancelTicketInstructionAsync(input)), closeTicket: input => addSelfPlanAndSendFunctions(client, getCloseTicketInstructionAsync(input)), commitTickets: input => addSelfPlanAndSendFunctions(client, getCommitTicketsInstruction({ ...input, payer: input.payer ?? client.payer })), createTicket: input => addSelfPlanAndSendFunctions(client, getCreateTicketInstructionAsync(input)), delegateQueue: input => addSelfPlanAndSendFunctions(client, getDelegateQueueInstructionAsync({ ...input, payer: input.payer ?? client.payer })), delegateTicket: input => addSelfPlanAndSendFunctions(client, getDelegateTicketInstructionAsync({ ...input, payer: input.payer ?? client.payer })), flushMatches: input => addSelfPlanAndSendFunctions(client, getFlushMatchesInstruction(input)), initializeQueue: input => addSelfPlanAndSendFunctions(client, getInitializeQueueInstructionAsync(input)), initializeTenant: input => addSelfPlanAndSendFunctions(client, getInitializeTenantInstructionAsync(input)), joinQueue: input => addSelfPlanAndSendFunctions(client, getJoinQueueInstructionAsync(input)), processUndelegation: input => addSelfPlanAndSendFunctions(client, getProcessUndelegationInstruction({ ...input, payer: input.payer ?? client.payer.address })), setupTicketPermission: input => addSelfPlanAndSendFunctions(client, getSetupTicketPermissionInstructionAsync(input)) } } };
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
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, type Address, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type AccountType = { __kind: "Queue", authority: Address; } | { __kind: "Ticket", player: Address; tenant: Address; };
|
|
12
|
+
|
|
13
|
+
export type AccountTypeArgs = AccountType;
|
|
14
|
+
|
|
15
|
+
export function getAccountTypeEncoder(): Encoder<AccountTypeArgs> {
|
|
16
|
+
return getDiscriminatedUnionEncoder([['Queue', getStructEncoder([['authority', getAddressEncoder()]])], ['Ticket', getStructEncoder([['player', getAddressEncoder()], ['tenant', getAddressEncoder()]])]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getAccountTypeDecoder(): Decoder<AccountType> {
|
|
20
|
+
return getDiscriminatedUnionDecoder([['Queue', getStructDecoder([['authority', getAddressDecoder()]])], ['Ticket', getStructDecoder([['player', getAddressDecoder()], ['tenant', getAddressDecoder()]])]]);
|
|
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: 'Queue', data: GetDiscriminatedUnionVariantContent<AccountTypeArgs, '__kind', 'Queue'>): GetDiscriminatedUnionVariant<AccountTypeArgs, '__kind', 'Queue'>;
|
|
29
|
+
export function accountType(kind: 'Ticket', data: GetDiscriminatedUnionVariantContent<AccountTypeArgs, '__kind', 'Ticket'>): GetDiscriminatedUnionVariant<AccountTypeArgs, '__kind', 'Ticket'>;
|
|
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,14 @@
|
|
|
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
|
+
export * from './accountType';
|
|
10
|
+
export * from './matchEntry';
|
|
11
|
+
export * from './matchFound';
|
|
12
|
+
export * from './pendingMatch';
|
|
13
|
+
export * from './queueEntry';
|
|
14
|
+
export * from './ticketStatus';
|
|
@@ -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, getAddressDecoder, getAddressEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type MatchEntry = { player1: Address; player2: Address; matchId: bigint; timestamp: bigint; };
|
|
12
|
+
|
|
13
|
+
export type MatchEntryArgs = { player1: Address; player2: Address; matchId: number | bigint; timestamp: number | bigint; };
|
|
14
|
+
|
|
15
|
+
export function getMatchEntryEncoder(): FixedSizeEncoder<MatchEntryArgs> {
|
|
16
|
+
return getStructEncoder([['player1', getAddressEncoder()], ['player2', getAddressEncoder()], ['matchId', getU64Encoder()], ['timestamp', getI64Encoder()]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getMatchEntryDecoder(): FixedSizeDecoder<MatchEntry> {
|
|
20
|
+
return getStructDecoder([['player1', getAddressDecoder()], ['player2', getAddressDecoder()], ['matchId', getU64Decoder()], ['timestamp', getI64Decoder()]]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getMatchEntryCodec(): FixedSizeCodec<MatchEntryArgs, MatchEntry> {
|
|
24
|
+
return combineCodec(getMatchEntryEncoder(), getMatchEntryDecoder());
|
|
25
|
+
}
|
|
@@ -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, getAddressDecoder, getAddressEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type MatchFound = { player1: Address; player2: Address; matchId: bigint; timestamp: bigint; };
|
|
12
|
+
|
|
13
|
+
export type MatchFoundArgs = { player1: Address; player2: Address; matchId: number | bigint; timestamp: number | bigint; };
|
|
14
|
+
|
|
15
|
+
export function getMatchFoundEncoder(): FixedSizeEncoder<MatchFoundArgs> {
|
|
16
|
+
return getStructEncoder([['player1', getAddressEncoder()], ['player2', getAddressEncoder()], ['matchId', getU64Encoder()], ['timestamp', getI64Encoder()]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getMatchFoundDecoder(): FixedSizeDecoder<MatchFound> {
|
|
20
|
+
return getStructDecoder([['player1', getAddressDecoder()], ['player2', getAddressDecoder()], ['matchId', getU64Decoder()], ['timestamp', getI64Decoder()]]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getMatchFoundCodec(): FixedSizeCodec<MatchFoundArgs, MatchFound> {
|
|
24
|
+
return combineCodec(getMatchFoundEncoder(), getMatchFoundDecoder());
|
|
25
|
+
}
|
|
@@ -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, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type PendingMatch = { player: Address; opponent: Address; matchId: bigint; };
|
|
12
|
+
|
|
13
|
+
export type PendingMatchArgs = { player: Address; opponent: Address; matchId: number | bigint; };
|
|
14
|
+
|
|
15
|
+
export function getPendingMatchEncoder(): FixedSizeEncoder<PendingMatchArgs> {
|
|
16
|
+
return getStructEncoder([['player', getAddressEncoder()], ['opponent', getAddressEncoder()], ['matchId', getU64Encoder()]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getPendingMatchDecoder(): FixedSizeDecoder<PendingMatch> {
|
|
20
|
+
return getStructDecoder([['player', getAddressDecoder()], ['opponent', getAddressDecoder()], ['matchId', getU64Decoder()]]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getPendingMatchCodec(): FixedSizeCodec<PendingMatchArgs, PendingMatch> {
|
|
24
|
+
return combineCodec(getPendingMatchEncoder(), getPendingMatchDecoder());
|
|
25
|
+
}
|
|
@@ -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, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type QueueEntry = { player: Address; elo: bigint; };
|
|
12
|
+
|
|
13
|
+
export type QueueEntryArgs = { player: Address; elo: number | bigint; };
|
|
14
|
+
|
|
15
|
+
export function getQueueEntryEncoder(): FixedSizeEncoder<QueueEntryArgs> {
|
|
16
|
+
return getStructEncoder([['player', getAddressEncoder()], ['elo', getU64Encoder()]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getQueueEntryDecoder(): FixedSizeDecoder<QueueEntry> {
|
|
20
|
+
return getStructDecoder([['player', getAddressDecoder()], ['elo', getU64Decoder()]]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getQueueEntryCodec(): FixedSizeCodec<QueueEntryArgs, QueueEntry> {
|
|
24
|
+
return combineCodec(getQueueEntryEncoder(), getQueueEntryDecoder());
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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, getUnitDecoder, getUnitEncoder, type Address, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export type TicketStatus = { __kind: "Searching" } | { __kind: "Matched", opponent: Address; matchId: bigint; } | { __kind: "Expired" } | { __kind: "Cancelled" };
|
|
12
|
+
|
|
13
|
+
export type TicketStatusArgs = { __kind: "Searching" } | { __kind: "Matched", opponent: Address; matchId: number | bigint; } | { __kind: "Expired" } | { __kind: "Cancelled" };
|
|
14
|
+
|
|
15
|
+
export function getTicketStatusEncoder(): Encoder<TicketStatusArgs> {
|
|
16
|
+
return getDiscriminatedUnionEncoder([['Searching', getUnitEncoder()], ['Matched', getStructEncoder([['opponent', getAddressEncoder()], ['matchId', getU64Encoder()]])], ['Expired', getUnitEncoder()], ['Cancelled', getUnitEncoder()]]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getTicketStatusDecoder(): Decoder<TicketStatus> {
|
|
20
|
+
return getDiscriminatedUnionDecoder([['Searching', getUnitDecoder()], ['Matched', getStructDecoder([['opponent', getAddressDecoder()], ['matchId', getU64Decoder()]])], ['Expired', getUnitDecoder()], ['Cancelled', getUnitDecoder()]]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getTicketStatusCodec(): Codec<TicketStatusArgs, TicketStatus> {
|
|
24
|
+
return combineCodec(getTicketStatusEncoder(), getTicketStatusDecoder());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Data Enum Helpers.
|
|
28
|
+
export function ticketStatus(kind: 'Searching'): GetDiscriminatedUnionVariant<TicketStatusArgs, '__kind', 'Searching'>;
|
|
29
|
+
export function ticketStatus(kind: 'Matched', data: GetDiscriminatedUnionVariantContent<TicketStatusArgs, '__kind', 'Matched'>): GetDiscriminatedUnionVariant<TicketStatusArgs, '__kind', 'Matched'>;
|
|
30
|
+
export function ticketStatus(kind: 'Expired'): GetDiscriminatedUnionVariant<TicketStatusArgs, '__kind', 'Expired'>;
|
|
31
|
+
export function ticketStatus(kind: 'Cancelled'): GetDiscriminatedUnionVariant<TicketStatusArgs, '__kind', 'Cancelled'>;
|
|
32
|
+
export function ticketStatus<K extends TicketStatusArgs['__kind'], Data>(kind: K, data?: Data) {
|
|
33
|
+
return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isTicketStatus<K extends TicketStatus['__kind']>(kind: K, value: TicketStatus): value is TicketStatus & { __kind: K } {
|
|
37
|
+
return value.__kind === kind;
|
|
38
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type Option, type OptionOrNullable, type ReadonlyUint8Array } from '@solana/kit';
|
|
10
|
+
import { getChoiceDecoder, getChoiceEncoder, getGameResultDecoder, getGameResultEncoder, type Choice, type ChoiceArgs, type GameResult, type GameResultArgs } from '../types';
|
|
11
|
+
|
|
12
|
+
export const GAME_SESSION_DISCRIMINATOR = new Uint8Array([150, 116, 20, 197, 205, 121, 220, 240]);
|
|
13
|
+
|
|
14
|
+
export function getGameSessionDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(GAME_SESSION_DISCRIMINATOR); }
|
|
15
|
+
|
|
16
|
+
export type GameSession = { discriminator: ReadonlyUint8Array; gameId: bigint; player1: Address; player2: Address; player1Choice: Option<Choice>; player2Choice: Option<Choice>; result: GameResult; };
|
|
17
|
+
|
|
18
|
+
export type GameSessionArgs = { gameId: number | bigint; player1: Address; player2: Address; player1Choice: OptionOrNullable<ChoiceArgs>; player2Choice: OptionOrNullable<ChoiceArgs>; result: GameResultArgs; };
|
|
19
|
+
|
|
20
|
+
/** Gets the encoder for {@link GameSessionArgs} account data. */
|
|
21
|
+
export function getGameSessionEncoder(): Encoder<GameSessionArgs> {
|
|
22
|
+
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['gameId', getU64Encoder()], ['player1', getAddressEncoder()], ['player2', getAddressEncoder()], ['player1Choice', getOptionEncoder(getChoiceEncoder())], ['player2Choice', getOptionEncoder(getChoiceEncoder())], ['result', getGameResultEncoder()]]), (value) => ({ ...value, discriminator: GAME_SESSION_DISCRIMINATOR }));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Gets the decoder for {@link GameSession} account data. */
|
|
26
|
+
export function getGameSessionDecoder(): Decoder<GameSession> {
|
|
27
|
+
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['gameId', getU64Decoder()], ['player1', getAddressDecoder()], ['player2', getAddressDecoder()], ['player1Choice', getOptionDecoder(getChoiceDecoder())], ['player2Choice', getOptionDecoder(getChoiceDecoder())], ['result', getGameResultDecoder()]]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Gets the codec for {@link GameSession} account data. */
|
|
31
|
+
export function getGameSessionCodec(): Codec<GameSessionArgs, GameSession> {
|
|
32
|
+
return combineCodec(getGameSessionEncoder(), getGameSessionDecoder());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function decodeGameSession<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<GameSession, TAddress>;
|
|
36
|
+
export function decodeGameSession<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<GameSession, TAddress>;
|
|
37
|
+
export function decodeGameSession<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<GameSession, TAddress> | MaybeAccount<GameSession, TAddress> {
|
|
38
|
+
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getGameSessionDecoder());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function fetchGameSession<TAddress extends string = string>(
|
|
42
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
43
|
+
address: Address<TAddress>,
|
|
44
|
+
config?: FetchAccountConfig,
|
|
45
|
+
): Promise<Account<GameSession, TAddress>> {
|
|
46
|
+
const maybeAccount = await fetchMaybeGameSession(rpc, address, config);
|
|
47
|
+
assertAccountExists(maybeAccount);
|
|
48
|
+
return maybeAccount;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function fetchMaybeGameSession<TAddress extends string = string>(
|
|
52
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
53
|
+
address: Address<TAddress>,
|
|
54
|
+
config?: FetchAccountConfig,
|
|
55
|
+
): Promise<MaybeAccount<GameSession, TAddress>> {
|
|
56
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
57
|
+
return decodeGameSession(maybeAccount);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function fetchAllGameSession(
|
|
61
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
62
|
+
addresses: Array<Address>,
|
|
63
|
+
config?: FetchAccountsConfig,
|
|
64
|
+
): Promise<Account<GameSession>[]> {
|
|
65
|
+
const maybeAccounts = await fetchAllMaybeGameSession(rpc, addresses, config);
|
|
66
|
+
assertAccountsExist(maybeAccounts);
|
|
67
|
+
return maybeAccounts;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function fetchAllMaybeGameSession(
|
|
71
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
72
|
+
addresses: Array<Address>,
|
|
73
|
+
config?: FetchAccountsConfig,
|
|
74
|
+
): Promise<MaybeAccount<GameSession>[]> {
|
|
75
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
76
|
+
return maybeAccounts.map((maybeAccount) => decodeGameSession(maybeAccount));
|
|
77
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export * from './gameSession';
|
|
10
|
+
export * from './playerProfile';
|
|
@@ -0,0 +1,80 @@
|
|
|
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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';
|
|
10
|
+
|
|
11
|
+
export const PLAYER_PROFILE_DISCRIMINATOR = new Uint8Array([82, 226, 99, 87, 164, 130, 181, 80]);
|
|
12
|
+
|
|
13
|
+
export function getPlayerProfileDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PLAYER_PROFILE_DISCRIMINATOR); }
|
|
14
|
+
|
|
15
|
+
export type PlayerProfile = { discriminator: ReadonlyUint8Array; player: Address; elo: bigint; gamesPlayed: bigint; gamesWon: bigint; };
|
|
16
|
+
|
|
17
|
+
export type PlayerProfileArgs = { player: Address; elo: number | bigint; gamesPlayed: number | bigint; gamesWon: number | bigint; };
|
|
18
|
+
|
|
19
|
+
/** Gets the encoder for {@link PlayerProfileArgs} account data. */
|
|
20
|
+
export function getPlayerProfileEncoder(): FixedSizeEncoder<PlayerProfileArgs> {
|
|
21
|
+
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['player', getAddressEncoder()], ['elo', getU64Encoder()], ['gamesPlayed', getU64Encoder()], ['gamesWon', getU64Encoder()]]), (value) => ({ ...value, discriminator: PLAYER_PROFILE_DISCRIMINATOR }));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Gets the decoder for {@link PlayerProfile} account data. */
|
|
25
|
+
export function getPlayerProfileDecoder(): FixedSizeDecoder<PlayerProfile> {
|
|
26
|
+
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['player', getAddressDecoder()], ['elo', getU64Decoder()], ['gamesPlayed', getU64Decoder()], ['gamesWon', getU64Decoder()]]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Gets the codec for {@link PlayerProfile} account data. */
|
|
30
|
+
export function getPlayerProfileCodec(): FixedSizeCodec<PlayerProfileArgs, PlayerProfile> {
|
|
31
|
+
return combineCodec(getPlayerProfileEncoder(), getPlayerProfileDecoder());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function decodePlayerProfile<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<PlayerProfile, TAddress>;
|
|
35
|
+
export function decodePlayerProfile<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<PlayerProfile, TAddress>;
|
|
36
|
+
export function decodePlayerProfile<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<PlayerProfile, TAddress> | MaybeAccount<PlayerProfile, TAddress> {
|
|
37
|
+
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getPlayerProfileDecoder());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function fetchPlayerProfile<TAddress extends string = string>(
|
|
41
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
42
|
+
address: Address<TAddress>,
|
|
43
|
+
config?: FetchAccountConfig,
|
|
44
|
+
): Promise<Account<PlayerProfile, TAddress>> {
|
|
45
|
+
const maybeAccount = await fetchMaybePlayerProfile(rpc, address, config);
|
|
46
|
+
assertAccountExists(maybeAccount);
|
|
47
|
+
return maybeAccount;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function fetchMaybePlayerProfile<TAddress extends string = string>(
|
|
51
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
52
|
+
address: Address<TAddress>,
|
|
53
|
+
config?: FetchAccountConfig,
|
|
54
|
+
): Promise<MaybeAccount<PlayerProfile, TAddress>> {
|
|
55
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
56
|
+
return decodePlayerProfile(maybeAccount);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function fetchAllPlayerProfile(
|
|
60
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
61
|
+
addresses: Array<Address>,
|
|
62
|
+
config?: FetchAccountsConfig,
|
|
63
|
+
): Promise<Account<PlayerProfile>[]> {
|
|
64
|
+
const maybeAccounts = await fetchAllMaybePlayerProfile(rpc, addresses, config);
|
|
65
|
+
assertAccountsExist(maybeAccounts);
|
|
66
|
+
return maybeAccounts;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function fetchAllMaybePlayerProfile(
|
|
70
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
71
|
+
addresses: Array<Address>,
|
|
72
|
+
config?: FetchAccountsConfig,
|
|
73
|
+
): Promise<MaybeAccount<PlayerProfile>[]> {
|
|
74
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
75
|
+
return maybeAccounts.map((maybeAccount) => decodePlayerProfile(maybeAccount));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getPlayerProfileSize(): number {
|
|
79
|
+
return 64;
|
|
80
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { isProgramError, type Address, type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, type SolanaError } from '@solana/kit';
|
|
10
|
+
import { RPS_GAME_PROGRAM_ADDRESS } from '../programs';
|
|
11
|
+
|
|
12
|
+
/** AlreadyChose: Already chose */
|
|
13
|
+
export const RPS_GAME_ERROR__ALREADY_CHOSE = 0x1770; // 6000
|
|
14
|
+
/** InvalidPlayer: Invalid player */
|
|
15
|
+
export const RPS_GAME_ERROR__INVALID_PLAYER = 0x1771; // 6001
|
|
16
|
+
/** InvalidMatchTicket: Invalid match ticket - not matched or wrong opponent */
|
|
17
|
+
export const RPS_GAME_ERROR__INVALID_MATCH_TICKET = 0x1772; // 6002
|
|
18
|
+
|
|
19
|
+
export type RpsGameError = typeof RPS_GAME_ERROR__ALREADY_CHOSE | typeof RPS_GAME_ERROR__INVALID_MATCH_TICKET | typeof RPS_GAME_ERROR__INVALID_PLAYER;
|
|
20
|
+
|
|
21
|
+
let rpsGameErrorMessages: Record<RpsGameError, string> | undefined;
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
+
rpsGameErrorMessages = { [RPS_GAME_ERROR__ALREADY_CHOSE]: `Already chose`, [RPS_GAME_ERROR__INVALID_MATCH_TICKET]: `Invalid match ticket - not matched or wrong opponent`, [RPS_GAME_ERROR__INVALID_PLAYER]: `Invalid player` };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getRpsGameErrorMessage(code: RpsGameError): string {
|
|
27
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
28
|
+
return (rpsGameErrorMessages as Record<RpsGameError, string>)[code];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return 'Error message not available in production bundles.';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isRpsGameError<TProgramErrorCode extends RpsGameError>(
|
|
35
|
+
error: unknown,
|
|
36
|
+
transactionMessage: { instructions: Record<number, { programAddress: Address }> },
|
|
37
|
+
code?: TProgramErrorCode,
|
|
38
|
+
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> & Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
|
|
39
|
+
return isProgramError<TProgramErrorCode>(error, transactionMessage, RPS_GAME_PROGRAM_ADDRESS, code);
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export * from './accounts';
|
|
10
|
+
export * from './errors';
|
|
11
|
+
export * from './instructions';
|
|
12
|
+
export * from './programs';
|
|
13
|
+
export * from './types';
|