@provable-games/budokan-sdk 0.1.8 → 0.1.10

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.
@@ -349,7 +349,7 @@ declare class BudokanClient {
349
349
  * Fetch a single tournament by its ID.
350
350
  * Supports RPC fallback when API is unavailable.
351
351
  */
352
- getTournament(tournamentId: string): Promise<Tournament>;
352
+ getTournament(tournamentId: string): Promise<Tournament | null>;
353
353
  /**
354
354
  * Fetch the leaderboard for a tournament.
355
355
  * Supports RPC fallback when API is unavailable.
@@ -358,9 +358,15 @@ declare class BudokanClient {
358
358
  /**
359
359
  * Fetch registrations for a tournament.
360
360
  * Supports RPC fallback when API is unavailable.
361
- * Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings.
361
+ * Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings,
362
+ * and filter params (`playerAddress`, `gameTokenIds`, `hasSubmitted`, `isBanned`)
363
+ * are applied via on-chain viewer functions where supported.
362
364
  */
363
365
  getTournamentRegistrations(tournamentId: string, params?: {
366
+ playerAddress?: string;
367
+ gameTokenIds?: string[];
368
+ hasSubmitted?: boolean;
369
+ isBanned?: boolean;
364
370
  limit?: number;
365
371
  offset?: number;
366
372
  }): Promise<PaginatedResult<Registration>>;
@@ -349,7 +349,7 @@ declare class BudokanClient {
349
349
  * Fetch a single tournament by its ID.
350
350
  * Supports RPC fallback when API is unavailable.
351
351
  */
352
- getTournament(tournamentId: string): Promise<Tournament>;
352
+ getTournament(tournamentId: string): Promise<Tournament | null>;
353
353
  /**
354
354
  * Fetch the leaderboard for a tournament.
355
355
  * Supports RPC fallback when API is unavailable.
@@ -358,9 +358,15 @@ declare class BudokanClient {
358
358
  /**
359
359
  * Fetch registrations for a tournament.
360
360
  * Supports RPC fallback when API is unavailable.
361
- * Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings.
361
+ * Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings,
362
+ * and filter params (`playerAddress`, `gameTokenIds`, `hasSubmitted`, `isBanned`)
363
+ * are applied via on-chain viewer functions where supported.
362
364
  */
363
365
  getTournamentRegistrations(tournamentId: string, params?: {
366
+ playerAddress?: string;
367
+ gameTokenIds?: string[];
368
+ hasSubmitted?: boolean;
369
+ isBanned?: boolean;
364
370
  limit?: number;
365
371
  offset?: number;
366
372
  }): Promise<PaginatedResult<Registration>>;
package/dist/index.cjs CHANGED
@@ -261,6 +261,10 @@ async function getTournamentLeaderboard(baseUrl, tournamentId, ctx) {
261
261
  }
262
262
  async function getTournamentRegistrations(baseUrl, tournamentId, params, ctx) {
263
263
  const qs = buildQueryString({
264
+ player_address: params?.playerAddress,
265
+ game_token_ids: params?.gameTokenIds?.length ? params.gameTokenIds.join(",") : void 0,
266
+ has_submitted: params?.hasSubmitted,
267
+ is_banned: params?.isBanned,
264
268
  limit: params?.limit,
265
269
  offset: params?.offset
266
270
  });
@@ -1124,7 +1128,9 @@ async function viewerTournamentsByPhase(contract, phase, offset, limit) {
1124
1128
  async function viewerTournamentDetail(contract, tournamentId) {
1125
1129
  return wrapRpcCall(async () => {
1126
1130
  const result = await contract.call("tournament_detail", [tournamentId]);
1127
- return parseTournamentFullState(result);
1131
+ const tournament = parseTournamentFullState(result);
1132
+ if (!tournament.gameAddress || tournament.gameAddress === "0x0") return null;
1133
+ return tournament;
1128
1134
  }, contract.address);
1129
1135
  }
1130
1136
  async function viewerTournamentsBatch(contract, tournamentIds) {
@@ -1147,6 +1153,34 @@ async function viewerRegistrations(contract, tournamentId, offset, limit) {
1147
1153
  };
1148
1154
  }, contract.address);
1149
1155
  }
1156
+ async function viewerRegistrationsByOwner(contract, tournamentId, owner, offset, limit) {
1157
+ return wrapRpcCall(async () => {
1158
+ const result = await contract.call("tournament_registrations_by_owner", [tournamentId, owner, offset, limit]);
1159
+ const obj = result;
1160
+ const entries = obj.entries ?? [];
1161
+ const total = Number(obj.total ?? 0);
1162
+ return {
1163
+ data: entries.map((e) => parseRegistration(e, tournamentId)),
1164
+ total,
1165
+ limit,
1166
+ offset
1167
+ };
1168
+ }, contract.address);
1169
+ }
1170
+ async function viewerRegistrationsByTokenIds(contract, tournamentId, tokenIds, offset, limit) {
1171
+ return wrapRpcCall(async () => {
1172
+ const result = await contract.call("tournament_registrations_by_token_ids", [tournamentId, tokenIds, offset, limit]);
1173
+ const obj = result;
1174
+ const entries = obj.entries ?? [];
1175
+ const total = Number(obj.total ?? 0);
1176
+ return {
1177
+ data: entries.map((e) => parseRegistration(e, tournamentId)),
1178
+ total,
1179
+ limit,
1180
+ offset
1181
+ };
1182
+ }, contract.address);
1183
+ }
1150
1184
  async function viewerLeaderboard(contract, tournamentId, offset, limit) {
1151
1185
  return wrapRpcCall(async () => {
1152
1186
  const result = await contract.call("leaderboard", [tournamentId, offset, limit]);
@@ -2533,11 +2567,16 @@ var BudokanClient = class {
2533
2567
  if (this.resolvedConfig.primarySource === "rpc") {
2534
2568
  return rpcFallback();
2535
2569
  }
2536
- return withFallback(
2537
- () => getTournament(this.resolvedConfig.apiBaseUrl, tournamentId, this.apiCtx),
2538
- rpcFallback,
2539
- this.connectionStatus
2540
- );
2570
+ try {
2571
+ return await getTournament(this.resolvedConfig.apiBaseUrl, tournamentId, this.apiCtx);
2572
+ } catch {
2573
+ try {
2574
+ this.connectionStatus.markApiUnavailable();
2575
+ return await rpcFallback();
2576
+ } catch {
2577
+ return null;
2578
+ }
2579
+ }
2541
2580
  }
2542
2581
  /**
2543
2582
  * Fetch the leaderboard for a tournament.
@@ -2560,13 +2599,21 @@ var BudokanClient = class {
2560
2599
  /**
2561
2600
  * Fetch registrations for a tournament.
2562
2601
  * Supports RPC fallback when API is unavailable.
2563
- * Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings.
2602
+ * Note: In RPC mode, `playerAddress` and `gameAddress` fields will be empty strings,
2603
+ * and filter params (`playerAddress`, `gameTokenIds`, `hasSubmitted`, `isBanned`)
2604
+ * are applied via on-chain viewer functions where supported.
2564
2605
  */
2565
2606
  async getTournamentRegistrations(tournamentId, params) {
2566
2607
  const rpcFallback = async () => {
2567
2608
  const contract = await this.getViewerContract();
2568
2609
  const offset = params?.offset ?? 0;
2569
2610
  const limit = params?.limit ?? 20;
2611
+ if (params?.playerAddress) {
2612
+ return viewerRegistrationsByOwner(contract, tournamentId, params.playerAddress, offset, limit);
2613
+ }
2614
+ if (params?.gameTokenIds?.length) {
2615
+ return viewerRegistrationsByTokenIds(contract, tournamentId, params.gameTokenIds, offset, limit);
2616
+ }
2570
2617
  return viewerRegistrations(contract, tournamentId, offset, limit);
2571
2618
  };
2572
2619
  if (this.resolvedConfig.primarySource === "rpc") {