diff --git a/packages/engine/paima-rest/src/controllers/AchievementsController.ts b/packages/engine/paima-rest/src/controllers/AchievementsController.ts index 2161224d..9d0a75b6 100644 --- a/packages/engine/paima-rest/src/controllers/AchievementsController.ts +++ b/packages/engine/paima-rest/src/controllers/AchievementsController.ts @@ -9,7 +9,7 @@ import { type Player, getNftOwner, } from '@paima/utils-backend'; -import { getAchievementTypes, getAchievementProgress } from '@paima/db'; +import { getAchievementTypes, getAchievementProgress, getMainAddress } from '@paima/db'; // ---------------------------------------------------------------------------- // Controller and routes per PRC-1 @@ -60,10 +60,16 @@ export class AchievementsController extends Controller { /** Comma-separated list. */ @Query() name?: string ): Promise { - const names = name ? name.split(',') : ['*']; - const player: Player = { wallet }; // TODO: walletType, userId, userName - const db = EngineService.INSTANCE.getSM().getReadonlyDbConn(); + const { address, id } = await getMainAddress(wallet, db); + + const player: Player = { + wallet: address, + userId: String(id), + // TODO: walletType, userName + }; + + const names = name ? name.split(',') : ['*']; const rows = await getAchievementProgress.run({ wallet, names }, db); this.setHeader('Content-Language', 'en'); @@ -100,14 +106,15 @@ export class AchievementsController extends Controller { const wallet = await getNftOwner(db, cde, BigInt(token_id)); if (wallet) { return await this.wallet(wallet, name); + } else { + // TODO: throw a different error if no CDE with that name exists + this.setStatus(404); + throw new Error('No owner for that NFT'); } - break; - case 'erc6551': - // TODO - break; + // Future expansion: erc6551 + default: + this.setStatus(404); + throw new Error(`No support for /erc/${erc}`); } - - this.setStatus(404); - throw new Error('Not found'); } } diff --git a/packages/node-sdk/paima-db/src/delegate-wallet.ts b/packages/node-sdk/paima-db/src/delegate-wallet.ts index 9d14f811..c0c13e07 100644 --- a/packages/node-sdk/paima-db/src/delegate-wallet.ts +++ b/packages/node-sdk/paima-db/src/delegate-wallet.ts @@ -10,6 +10,7 @@ import { getMainAddressFromAddress, } from './sql/wallet-delegation.queries.js'; import type { PoolClient, Notification, Client } from 'pg'; +import type { IDatabaseConnection } from '@pgtyped/runtime/lib/tag'; export type WalletDelegate = { address: string; id: number }; export const NO_USER_ID = -1; @@ -26,7 +27,7 @@ export const addressCache = new Map(); // If wallet does not exist, It will NOT be created in address table. export async function getMainAddress( _address: string, - DBConn: PoolClient + DBConn: IDatabaseConnection ): Promise { const address = _address.toLocaleLowerCase(); let addressMapping: WalletDelegate | undefined = addressCache.get(address);