Skip to content

Commit

Permalink
Update for PRC-1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceManiac committed Apr 30, 2024
1 parent 20cb2bc commit 369619a
Show file tree
Hide file tree
Showing 4 changed files with 530 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Controller, Get, Path, Query, Route } from 'tsoa';
import { EngineService } from '../EngineService.js';
import { ENV } from '@paima/utils';
import type {
AchievementPublicList,
PlayerAchievements,
Validity,
Game,
Player,
import {
type AchievementPublicList,
type PlayerAchievements,
type Validity,
type Game,
type Player,
getNftOwner,
} from '@paima/utils-backend';
import { getAchievementTypes, getAchievementProgress } from '@paima/db';

Expand All @@ -16,12 +17,12 @@ import { getAchievementTypes, getAchievementProgress } from '@paima/db';
@Route('achievements')
export class AchievementsController extends Controller {
private async game(): Promise<Game> {
return { id: 'DERP' };
return { id: 'TODO' };
}

private async validity(): Promise<Validity> {
return {
chainId: ENV.CHAIN_ID,
caip2: ENV.CHAIN_ID,
block: await EngineService.INSTANCE.getSM().latestProcessedBlockHeight(),
time: new Date().toISOString(),
};
Expand All @@ -35,6 +36,7 @@ export class AchievementsController extends Controller {
const db = EngineService.INSTANCE.getSM().getReadonlyDbConn();
const rows = await getAchievementTypes.run({ category, is_active: isActive }, db);

this.setHeader('Content-Language', 'en');
return {
...(await this.validity()),
...(await this.game()),
Expand All @@ -61,6 +63,7 @@ export class AchievementsController extends Controller {
const db = EngineService.INSTANCE.getSM().getReadonlyDbConn();
const rows = await getAchievementProgress.run({ wallet, names }, db);

this.setHeader('Content-Language', 'en');
return {
...(await this.validity()),
...player,
Expand All @@ -79,15 +82,29 @@ export class AchievementsController extends Controller {
};
}

/* TODO
@Get('nft/{nft_address}')
@Get('erc/{erc}/{cde}/{token_id}')
public async nft(
@Path() nft_address: string,
Comma-separated list.
@Path() erc: string,
@Path() cde: string,
@Path() token_id: string,
@Query() name?: string
): Promise<PlayerAchievements> {
const wallet = await service().getNftOwner(nft_address);
return await this.wallet(wallet, name);
const db = EngineService.INSTANCE.getSM().getReadonlyDbConn();
this.setHeader('Content-Language', 'en');

switch (erc) {
case 'erc721':
const wallet = await getNftOwner(db, cde, BigInt(token_id));
if (wallet) {
return await this.wallet(wallet, name);
}
break;
case 'erc6551':
// TODO
break;
}

this.setStatus(404);
throw new Error('Not found');
}
*/
}
157 changes: 157 additions & 0 deletions packages/engine/paima-rest/src/tsoa/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { EmulatedBlockActiveController } from './../controllers/BasicControllers
import { DeploymentBlockheightToEmulatedController } from './../controllers/BasicControllers';
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
import { ConfirmInputAcceptanceController } from './../controllers/BasicControllers';
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
import { AchievementsController } from './../controllers/AchievementsController';
import type { Request as ExRequest, Response as ExResponse, RequestHandler, Router } from 'express';


Expand Down Expand Up @@ -89,6 +91,66 @@ const models: TsoaRoute.Models = {
"type": {"ref":"Result_boolean_","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"Achievement": {
"dataType": "refObject",
"properties": {
"name": {"dataType":"string","required":true},
"score": {"dataType":"double"},
"category": {"dataType":"string"},
"percentCompleted": {"dataType":"double"},
"isActive": {"dataType":"boolean","required":true},
"displayName": {"dataType":"string","required":true},
"description": {"dataType":"string","required":true},
"spoiler": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["all"]},{"dataType":"enum","enums":["description"]}]},
"iconURI": {"dataType":"string"},
"iconGreyURI": {"dataType":"string"},
"startDate": {"dataType":"string"},
"endDate": {"dataType":"string"},
},
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"AchievementPublicList": {
"dataType": "refObject",
"properties": {
"id": {"dataType":"string","required":true},
"name": {"dataType":"string"},
"version": {"dataType":"string"},
"block": {"dataType":"double","required":true},
"caip2": {"dataType":"double","required":true},
"time": {"dataType":"string"},
"achievements": {"dataType":"array","array":{"dataType":"refObject","ref":"Achievement"},"required":true},
},
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"PlayerAchievement": {
"dataType": "refObject",
"properties": {
"name": {"dataType":"string","required":true},
"completed": {"dataType":"boolean","required":true},
"completedDate": {"dataType":"datetime"},
"completedRate": {"dataType":"nestedObjectLiteral","nestedProperties":{"total":{"dataType":"double","required":true},"progress":{"dataType":"double","required":true}}},
},
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"PlayerAchievements": {
"dataType": "refObject",
"properties": {
"block": {"dataType":"double","required":true},
"caip2": {"dataType":"double","required":true},
"time": {"dataType":"string"},
"wallet": {"dataType":"string","required":true},
"walletType": {"dataType":"string"},
"userId": {"dataType":"string"},
"userName": {"dataType":"string"},
"completed": {"dataType":"double","required":true},
"achievements": {"dataType":"array","array":{"dataType":"refObject","ref":"PlayerAchievement"},"required":true},
},
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
};
const templateService = new ExpressTemplateService(models, {"noImplicitAdditionalProperties":"throw-on-extras","bodyCoercion":true});

Expand Down Expand Up @@ -279,6 +341,101 @@ export function RegisterRoutes(app: Router) {
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
app.get('/achievements/public/list',
...(fetchMiddlewares<RequestHandler>(AchievementsController)),
...(fetchMiddlewares<RequestHandler>(AchievementsController.prototype.public_list)),

function AchievementsController_public_list(request: ExRequest, response: ExResponse, next: any) {
const args: Record<string, TsoaRoute.ParameterSchema> = {
category: {"in":"query","name":"category","dataType":"string"},
isActive: {"in":"query","name":"isActive","dataType":"boolean"},
};

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

let validatedArgs: any[] = [];
try {
validatedArgs = templateService.getValidatedArgs({ args, request, response });

const controller = new AchievementsController();

templateService.apiHandler({
methodName: 'public_list',
controller,
response,
next,
validatedArgs,
successStatus: undefined,
});
} catch (err) {
return next(err);
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
app.get('/achievements/wallet/:wallet',
...(fetchMiddlewares<RequestHandler>(AchievementsController)),
...(fetchMiddlewares<RequestHandler>(AchievementsController.prototype.wallet)),

function AchievementsController_wallet(request: ExRequest, response: ExResponse, next: any) {
const args: Record<string, TsoaRoute.ParameterSchema> = {
wallet: {"in":"path","name":"wallet","required":true,"dataType":"string"},
name: {"in":"query","name":"name","dataType":"string"},
};

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

let validatedArgs: any[] = [];
try {
validatedArgs = templateService.getValidatedArgs({ args, request, response });

const controller = new AchievementsController();

templateService.apiHandler({
methodName: 'wallet',
controller,
response,
next,
validatedArgs,
successStatus: undefined,
});
} catch (err) {
return next(err);
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
app.get('/achievements/erc/:erc/:cde/:token_id',
...(fetchMiddlewares<RequestHandler>(AchievementsController)),
...(fetchMiddlewares<RequestHandler>(AchievementsController.prototype.nft)),

function AchievementsController_nft(request: ExRequest, response: ExResponse, next: any) {
const args: Record<string, TsoaRoute.ParameterSchema> = {
erc: {"in":"path","name":"erc","required":true,"dataType":"string"},
cde: {"in":"path","name":"cde","required":true,"dataType":"string"},
token_id: {"in":"path","name":"token_id","required":true,"dataType":"string"},
name: {"in":"query","name":"name","dataType":"string"},
};

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

let validatedArgs: any[] = [];
try {
validatedArgs = templateService.getValidatedArgs({ args, request, response });

const controller = new AchievementsController();

templateService.apiHandler({
methodName: 'nft',
controller,
response,
next,
validatedArgs,
successStatus: undefined,
});
} catch (err) {
return next(err);
}
});
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa

Expand Down
Loading

0 comments on commit 369619a

Please sign in to comment.