Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @paima/rest tsoa endpoint #258

Merged
merged 9 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
bin
.nx
**/dist
**/build
**/lib
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.d.ts
contract-types/
packaged/
packages/engine/paima-rest/src/tsoa/routes.ts
3,661 changes: 1,698 additions & 1,963 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"devDependencies": {
"@eslint/eslintrc": "^2.1.2",
"@eslint/js": "~8.50.0",
"@nx/esbuild": "16.9.1",
"@nx/jest": "16.10.0",
"@nx/js": "16.10.0",
"@nx/linter": "^16.9.1",
"@nx/esbuild": "17.1.3",
"@nx/jest": "17.1.3",
"@nx/js": "17.1.3",
"@nx/linter": "17.1.3",
"@types/eslint-plugin-prettier": "^3.1.1",
"@types/jest": "^29.4.0",
"@types/jest": "^29.5.10",
"@types/node": "^18.17.1",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
Expand All @@ -38,7 +38,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-require-extensions": "^0.1.3",
"husky": "^8.0.3",
"jest": "^29.4.1",
"jest": "29.7.0",
"json5": "^2.2.3",
"nx": "16.9.1",
"prettier": "^3.0.3",
Expand All @@ -47,7 +47,7 @@
"syncpack": "^11.2.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"overrides": {
"web3-eth-contract": "1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@vitejs/plugin-react": "^1.3.0",
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"vite": "^2.9.9"
}
}
6 changes: 3 additions & 3 deletions packages/batcher/webserver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function initializeServer(
console.log('[webserver/track_user_input] error:', err);
res.status(500).json({
success: false,
message: 'Unknown server error, please contact admin',
message: 'Unknown server error, please batcher operator',
});
}
}
Expand Down Expand Up @@ -297,7 +297,7 @@ async function initializeServer(
console.log('[webserver/submit_self_signed_input] error:', err);
res.status(500).json({
success: false,
message: 'Unknown server error, please contact admin',
message: 'Unknown server error, please contact batcher operator',
});
}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ async function initializeServer(
console.log('[webserver/submit_user_input] error:', err);
res.status(500).json({
success: false,
message: 'Unknown server error, please contact admin',
message: 'Unknown server error, please contact batcher operator',
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"author": "Paima Studios",
"devDependencies": {
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"dependencies": {
"assert-never": "^1.2.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
CdeErc20TransferDatum,
ChainDataExtensionDatum,
ChainDataExtensionErc20,
} from '@paima/runtime';
} from '@paima/sm';
import type { Transfer } from '@paima/utils/src/contract-types/ERC20Contract.js';
import { DEFAULT_FUNNEL_TIMEOUT } from '@paima/utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/erc20Deposit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChainDataExtensionDatumType, timeout } from '@paima/utils';
import type { ChainDataExtensionDatum, ChainDataExtensionErc20Deposit } from '@paima/runtime';
import type { ChainDataExtensionDatum, ChainDataExtensionErc20Deposit } from '@paima/sm';
import type { Transfer } from '@paima/utils/src/contract-types/ERC20Contract.js';
import { DEFAULT_FUNNEL_TIMEOUT } from '@paima/utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/erc6551Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
CdeErc6551RegistryDatum,
ChainDataExtensionDatum,
ChainDataExtensionErc6551Registry,
} from '@paima/runtime';
} from '@paima/sm';
import type { AccountCreated } from '@paima/utils/src/contract-types/ERC6551RegistryContract.js';

export default async function getCdeData(
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
CdeErc721TransferDatum,
ChainDataExtensionDatum,
ChainDataExtensionErc721,
} from '@paima/runtime';
} from '@paima/sm';
import type { Transfer } from '@paima/utils/src/contract-types/ERC721Contract.js';

export default async function getCdeData(
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
CdeGenericDatum,
ChainDataExtensionDatum,
ChainDataExtensionGeneric,
} from '@paima/runtime';
} from '@paima/sm';

export default async function getCdeData(
extension: ChainDataExtensionGeneric,
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/paimaErc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
CdeErc721TransferDatum,
ChainDataExtensionDatum,
ChainDataExtensionPaimaErc721,
} from '@paima/runtime';
} from '@paima/sm';
import type { Minted, Transfer } from '@paima/utils/src/contract-types/PaimaERC721Contract.js';

export default async function getCdeData(
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/cde/reading.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type Web3 from 'web3';

import { ChainDataExtensionType } from '@paima/utils';
import type { ChainDataExtensionDatum, ChainDataExtension } from '@paima/runtime';
import type { ChainDataExtensionDatum, ChainDataExtension } from '@paima/sm';

import getCdeErc20Data from './erc20.js';
import getCdeErc721Data from './erc721.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-funnel/src/funnels/BaseFunnel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ChainData, ChainDataExtension, ChainFunnel, PresyncChainData } from '@paima/runtime';
import type { ChainFunnel } from '@paima/runtime';
import type { ChainData, ChainDataExtension, PresyncChainData } from '@paima/sm';
import type { PaimaL2Contract, Web3 } from '@paima/utils';
import type { FunnelCacheManager } from './FunnelCache.js';
import type { PoolClient } from 'pg';
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/funnels/FunnelCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChainData } from '@paima/runtime';
import type { ChainData } from '@paima/sm';

export interface FunnelCacheEntry {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-funnel/src/funnels/block/funnel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ENV, doLog, timeout } from '@paima/utils';
import type { ChainData, ChainFunnel, PresyncChainData } from '@paima/runtime';
import type { ChainFunnel } from '@paima/runtime';
import type { ChainData, PresyncChainData } from '@paima/sm';
import { getBaseChainDataMulti, getBaseChainDataSingle } from '../../reading.js';
import { getUngroupedCdeData } from '../../cde/reading.js';
import { composeChainData, groupCdeData } from '../../utils.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-funnel/src/funnels/emulated/funnel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { PoolClient } from 'pg';

import Prando from '@paima/prando';
import type { ChainData, ChainFunnel, PresyncChainData } from '@paima/runtime';
import type { ChainFunnel } from '@paima/runtime';
import type { ChainData, PresyncChainData } from '@paima/sm';
import { ENV, doLog } from '@paima/utils';
import {
emulatedSelectLatestPrior,
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-funnel/src/funnels/emulated/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PoolClient } from 'pg';

import type { ChainDataExtensionDatum, ChainFunnel } from '@paima/runtime';
import type { ChainDataExtensionDatum } from '@paima/sm';
import type { ChainFunnel } from '@paima/runtime';
import { EmulatedBlocksFunnel } from './funnel.js';
import { DEFAULT_FUNNEL_TIMEOUT, doLog, logError, timeout } from '@paima/utils';
import type { FunnelSharedData } from '../BaseFunnel.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-funnel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { PoolClient } from 'pg';

import { ENV, getPaimaL2Contract, initWeb3, validatePaimaL2ContractAddress } from '@paima/utils';
import { loadChainDataExtensions } from '@paima/runtime';
import type { ChainDataExtension, ChainFunnel, IFunnelFactory } from '@paima/runtime';
import type { ChainFunnel, IFunnelFactory } from '@paima/runtime';
import type { ChainDataExtension } from '@paima/sm';
import { wrapToEmulatedBlocksFunnel } from './funnels/emulated/utils.js';
import { BlockFunnel } from './funnels/block/funnel.js';
import type { FunnelSharedData } from './funnels/BaseFunnel.js';
Expand Down
6 changes: 1 addition & 5 deletions packages/engine/paima-funnel/src/paima-l2-processing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type Web3 from 'web3';
import web3UtilsPkg from 'web3-utils';

import { AddressType, doLog, getReadNamespaces } from '@paima/utils';
import type { SubmittedData } from '@paima/runtime';
import type { PaimaGameInteraction } from '@paima/utils/src/contract-types/PaimaL2Contract.js';
Expand All @@ -11,9 +9,7 @@ import {
createMessageForBatcher,
extractBatches,
} from '@paima/concise';
import { sha3 } from 'web3-utils';

const { toBN, hexToUtf8 } = web3UtilsPkg;
import { toBN, hexToUtf8, sha3 } from 'web3-utils';

interface ValidatedSubmittedData extends SubmittedData {
validated: boolean;
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-funnel/src/reading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { BlockTransactionString } from 'web3-eth';

import { timeout, cutAfterFirstRejected, DEFAULT_FUNNEL_TIMEOUT, doLog, delay } from '@paima/utils';
import type { PaimaL2Contract } from '@paima/utils';
import { TimeoutError, type ChainData } from '@paima/runtime';
import { TimeoutError } from '@paima/runtime';
import type { ChainData } from '@paima/sm';
import type { PaimaGameInteraction } from '@paima/utils/src/contract-types/PaimaL2Contract.js';

import { extractSubmittedData } from './paima-l2-processing.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/paima-funnel/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChainData, ChainDataExtensionDatum, PresyncChainData } from '@paima/runtime';
import type { ChainData, ChainDataExtensionDatum, PresyncChainData } from '@paima/sm';

export function groupCdeData(
fromBlock: number,
Expand Down
1 change: 1 addition & 0 deletions packages/engine/paima-funnel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
{ "path": "../../node-sdk/paima-utils-backend" },
{ "path": "../../paima-sdk/paima-crypto/tsconfig.build.json" },
{ "path": "../../paima-sdk/paima-concise/tsconfig.build.json" },
{ "path": "../paima-sm" },
]
}
25 changes: 25 additions & 0 deletions packages/engine/paima-rest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@paima/rest",
"version": "1.0.0",
"description": "Paima Engine REST, defining the REST endpoints for the Paima node",
"main": "build/index.js",
"type": "module",
"types": "build/index.d.ts",
"scripts": {
"lint:eslint": "eslint .",
"build": "tsc --build tsconfig.build.json",
"prebuild": "npm run compile:api",
"compile:api": "npx tsoa spec-and-routes"
},
"author": "Paima Studios",
"dependencies": {
"express": "^4.18.1",
"yaml": "^2.3.1",
"tsoa": "^6.0.0-rc.5"
},
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.20",
"@types/node": "^18.17.1"
}
}
18 changes: 18 additions & 0 deletions packages/engine/paima-rest/src/EngineService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { GameStateMachine } from '@paima/sm';

export class EngineService {
public static INSTANCE = new EngineService();

private runtime: GameStateMachine | undefined = undefined;

getSM = (): GameStateMachine => {
if (this.runtime == null) {
throw new Error('EngineService: SM not initialized');
}
return this.runtime;
};

updateSM = (runtime: GameStateMachine): void => {
this.runtime = runtime;
};
}
Loading