mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-08-14 04:22:54 +02:00
「🏗️」 wip: started doing the api for the contract
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@avalabs/avalanchejs": "^5.0.0",
|
||||||
"@fastify/cookie": "^11.0.2",
|
"@fastify/cookie": "^11.0.2",
|
||||||
"@fastify/env": "^5.0.2",
|
"@fastify/env": "^5.0.2",
|
||||||
"@fastify/jwt": "^9.1.0",
|
"@fastify/jwt": "^9.1.0",
|
||||||
|
63
pnpm-lock.yaml
generated
63
pnpm-lock.yaml
generated
@ -8,6 +8,9 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@avalabs/avalanchejs':
|
||||||
|
specifier: ^5.0.0
|
||||||
|
version: 5.0.0
|
||||||
'@fastify/cookie':
|
'@fastify/cookie':
|
||||||
specifier: ^11.0.2
|
specifier: ^11.0.2
|
||||||
version: 11.0.2
|
version: 11.0.2
|
||||||
@ -67,6 +70,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==}
|
resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==}
|
||||||
engines: {node: '>=6.0.0'}
|
engines: {node: '>=6.0.0'}
|
||||||
|
|
||||||
|
'@avalabs/avalanchejs@5.0.0':
|
||||||
|
resolution: {integrity: sha512-0hJK/Hdf8v+q05c8+5K6arFmzq7o1W4I05/Dmr+Es1XRi8canvTu1Y0RruYd6ea2rrvX3UhKrPs3BzLhCTHDrw==}
|
||||||
|
engines: {node: '>=20'}
|
||||||
|
|
||||||
'@babel/code-frame@7.27.1':
|
'@babel/code-frame@7.27.1':
|
||||||
resolution: {integrity: sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==}
|
resolution: {integrity: sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==}
|
||||||
engines: {node: '>=6.9.0'}
|
engines: {node: '>=6.9.0'}
|
||||||
@ -231,6 +238,11 @@ packages:
|
|||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [win32]
|
os: [win32]
|
||||||
|
|
||||||
|
'@ethereumjs/rlp@5.0.0':
|
||||||
|
resolution: {integrity: sha512-WuS1l7GJmB0n0HsXLozCoEFc9IwYgf3l0gCkKVYgR67puVF1O4OpEaN0hWmm1c+iHUHFCKt1hJrvy5toLg+6ag==}
|
||||||
|
engines: {node: '>=18'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
'@fastify/ajv-compiler@4.0.2':
|
'@fastify/ajv-compiler@4.0.2':
|
||||||
resolution: {integrity: sha512-Rkiu/8wIjpsf46Rr+Fitd3HRP+VsxUFDDeag0hs9L0ksfnwx2g7SPQQTFL0E8Qv+rfXzQOxBJnjUB9ITUDjfWQ==}
|
resolution: {integrity: sha512-Rkiu/8wIjpsf46Rr+Fitd3HRP+VsxUFDDeag0hs9L0ksfnwx2g7SPQQTFL0E8Qv+rfXzQOxBJnjUB9ITUDjfWQ==}
|
||||||
|
|
||||||
@ -286,6 +298,16 @@ packages:
|
|||||||
resolution: {integrity: sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==}
|
resolution: {integrity: sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
||||||
|
'@noble/curves@1.3.0':
|
||||||
|
resolution: {integrity: sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==}
|
||||||
|
|
||||||
|
'@noble/hashes@1.3.3':
|
||||||
|
resolution: {integrity: sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==}
|
||||||
|
engines: {node: '>= 16'}
|
||||||
|
|
||||||
|
'@noble/secp256k1@2.0.0':
|
||||||
|
resolution: {integrity: sha512-rUGBd95e2a45rlmFTqQJYEFA4/gdIARFfuTuTqLglz0PZ6AKyzyXsEZZq7UZn8hZsvaBgpCzKKBJizT2cJERXw==}
|
||||||
|
|
||||||
'@opentelemetry/api@1.9.0':
|
'@opentelemetry/api@1.9.0':
|
||||||
resolution: {integrity: sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==}
|
resolution: {integrity: sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==}
|
||||||
engines: {node: '>=8.0.0'}
|
engines: {node: '>=8.0.0'}
|
||||||
@ -402,6 +424,9 @@ packages:
|
|||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [win32]
|
os: [win32]
|
||||||
|
|
||||||
|
'@scure/base@1.1.5':
|
||||||
|
resolution: {integrity: sha512-Brj9FiG2W1MRQSTB212YVPRrcbjkv48FoZi/u4l/zds/ieRrqsh7aUf6CLwkAq61oKXr/ZlTzlY66gLIj3TFTQ==}
|
||||||
|
|
||||||
'@sindresorhus/is@5.6.0':
|
'@sindresorhus/is@5.6.0':
|
||||||
resolution: {integrity: sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==}
|
resolution: {integrity: sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==}
|
||||||
engines: {node: '>=14.16'}
|
engines: {node: '>=14.16'}
|
||||||
@ -1191,6 +1216,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
|
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
|
|
||||||
|
micro-eth-signer@0.7.2:
|
||||||
|
resolution: {integrity: sha512-uFH23nqPNdg2KZ9ZdvLG4GO3bTAOWRhwGTsecY4Et2IdQOJ26x6inu8lJ9oyslnYL/0o1vnETCGhMimMvO0SqQ==}
|
||||||
|
|
||||||
|
micro-packed@0.5.3:
|
||||||
|
resolution: {integrity: sha512-zWRoH+qUb/ZMp9gVZhexvRGCENDM5HEQF4sflqpdilUHWK2/zKR7/MT8GBctnTwbhNJwy1iuk5q6+TYP7/twYA==}
|
||||||
|
|
||||||
mime-db@1.52.0:
|
mime-db@1.52.0:
|
||||||
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
@ -1660,6 +1691,14 @@ snapshots:
|
|||||||
'@jridgewell/gen-mapping': 0.3.12
|
'@jridgewell/gen-mapping': 0.3.12
|
||||||
'@jridgewell/trace-mapping': 0.3.29
|
'@jridgewell/trace-mapping': 0.3.29
|
||||||
|
|
||||||
|
'@avalabs/avalanchejs@5.0.0':
|
||||||
|
dependencies:
|
||||||
|
'@noble/curves': 1.3.0
|
||||||
|
'@noble/hashes': 1.3.3
|
||||||
|
'@noble/secp256k1': 2.0.0
|
||||||
|
'@scure/base': 1.1.5
|
||||||
|
micro-eth-signer: 0.7.2
|
||||||
|
|
||||||
'@babel/code-frame@7.27.1':
|
'@babel/code-frame@7.27.1':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@babel/helper-validator-identifier': 7.27.1
|
'@babel/helper-validator-identifier': 7.27.1
|
||||||
@ -1746,6 +1785,8 @@ snapshots:
|
|||||||
'@esbuild/win32-x64@0.25.6':
|
'@esbuild/win32-x64@0.25.6':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
'@ethereumjs/rlp@5.0.0': {}
|
||||||
|
|
||||||
'@fastify/ajv-compiler@4.0.2':
|
'@fastify/ajv-compiler@4.0.2':
|
||||||
dependencies:
|
dependencies:
|
||||||
ajv: 8.17.1
|
ajv: 8.17.1
|
||||||
@ -1811,6 +1852,14 @@ snapshots:
|
|||||||
|
|
||||||
'@lukeed/ms@2.0.2': {}
|
'@lukeed/ms@2.0.2': {}
|
||||||
|
|
||||||
|
'@noble/curves@1.3.0':
|
||||||
|
dependencies:
|
||||||
|
'@noble/hashes': 1.3.3
|
||||||
|
|
||||||
|
'@noble/hashes@1.3.3': {}
|
||||||
|
|
||||||
|
'@noble/secp256k1@2.0.0': {}
|
||||||
|
|
||||||
'@opentelemetry/api@1.9.0': {}
|
'@opentelemetry/api@1.9.0': {}
|
||||||
|
|
||||||
'@pnpm/config.env-replace@1.1.0': {}
|
'@pnpm/config.env-replace@1.1.0': {}
|
||||||
@ -1885,6 +1934,8 @@ snapshots:
|
|||||||
'@rollup/rollup-win32-x64-msvc@4.44.2':
|
'@rollup/rollup-win32-x64-msvc@4.44.2':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
'@scure/base@1.1.5': {}
|
||||||
|
|
||||||
'@sindresorhus/is@5.6.0': {}
|
'@sindresorhus/is@5.6.0': {}
|
||||||
|
|
||||||
'@solidity-parser/parser@0.20.2': {}
|
'@solidity-parser/parser@0.20.2': {}
|
||||||
@ -2679,6 +2730,18 @@ snapshots:
|
|||||||
|
|
||||||
math-intrinsics@1.1.0: {}
|
math-intrinsics@1.1.0: {}
|
||||||
|
|
||||||
|
micro-eth-signer@0.7.2:
|
||||||
|
dependencies:
|
||||||
|
'@ethereumjs/rlp': 5.0.0
|
||||||
|
'@noble/curves': 1.3.0
|
||||||
|
'@noble/hashes': 1.3.3
|
||||||
|
'@scure/base': 1.1.5
|
||||||
|
micro-packed: 0.5.3
|
||||||
|
|
||||||
|
micro-packed@0.5.3:
|
||||||
|
dependencies:
|
||||||
|
'@scure/base': 1.1.5
|
||||||
|
|
||||||
mime-db@1.52.0: {}
|
mime-db@1.52.0: {}
|
||||||
|
|
||||||
mime-types@2.1.35:
|
mime-types@2.1.35:
|
||||||
|
13
src/api/scoreStore/default.js
Normal file
13
src/api/scoreStore/default.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { evm } from '@avalabs/avalanchejs';
|
||||||
|
import scoreDB from '../../utils/scoreDB.js';
|
||||||
|
import { getTx } from './getTx.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import('fastify').FastifyInstance} fastify
|
||||||
|
* @param {import('fastify').FastifyPluginOptions} options
|
||||||
|
*/
|
||||||
|
export default async function(fastify, options) {
|
||||||
|
fastify.get("/:id", async (request, reply) => {
|
||||||
|
return getTx(request, reply, fastify);
|
||||||
|
});
|
||||||
|
}
|
19
src/api/scoreStore/getTx.js
Normal file
19
src/api/scoreStore/getTx.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import scoreDB from "../../utils/scoreDB.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @async
|
||||||
|
* @param {import("fastify".FastifyRequest)} request
|
||||||
|
* @param {import("fastify").FastifyReply} reply
|
||||||
|
* @param {import("fastify").FastifyInstance} fastify
|
||||||
|
*
|
||||||
|
* @returns {import('fastify').FastifyReply}
|
||||||
|
*/
|
||||||
|
export async function getTx(request, reply, fastify) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
fastify.log.error(err);
|
||||||
|
return reply.code(500).send({ error: "Internal server error" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
52
src/utils/scoreDB.js
Normal file
52
src/utils/scoreDB.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { Int } from "@avalabs/avalanchejs";
|
||||||
|
import Database from "better-sqlite3";
|
||||||
|
|
||||||
|
var env = process.env.NODE_ENV || 'development';
|
||||||
|
let database;
|
||||||
|
|
||||||
|
if (!env || env === 'development') {
|
||||||
|
database = new Database(":memory:", { verbose: console.log });
|
||||||
|
} else {
|
||||||
|
var dbPath = process.env.DB_PATH || '/db/db.sqlite';
|
||||||
|
database = new Database(dbPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Can be used to prepare the database
|
||||||
|
*/
|
||||||
|
function prepareDB() {
|
||||||
|
database.exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS scoresTx (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
txHash TEXT
|
||||||
|
) STRICT
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Can be used to add a score hash to the DB
|
||||||
|
* @param {Int} The id of the score
|
||||||
|
* @param {String} The hash of the score
|
||||||
|
*/
|
||||||
|
function addTx(id, txHash) {
|
||||||
|
const txAdd = database.prepare('INSERT INTO scoresTx (id, txHash) VALUES (?, ?)');
|
||||||
|
txAdd.run(id, txHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Can be used to get a tx hash from an id
|
||||||
|
* @param {Int} The id to get
|
||||||
|
* @returns {String} The tx hash
|
||||||
|
*/
|
||||||
|
function getTx(id) {
|
||||||
|
const txGet = database.prepare('SELECT txHash FROM credentials WHERE id = ?;')
|
||||||
|
return txGet.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const scoreDB = {
|
||||||
|
prepareDB,
|
||||||
|
addTx,
|
||||||
|
getTx
|
||||||
|
};
|
||||||
|
|
||||||
|
export default scoreDB;
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
pragma solidity 0.8.28;
|
pragma solidity 0.8.28;
|
||||||
|
|
||||||
import "src/contract/main.sol";
|
import "src/contract/scoreStore.sol";
|
||||||
import "forge-std/Test.sol";
|
import "forge-std/Test.sol";
|
||||||
|
|
||||||
contract scoreStoreTest is Test {
|
contract scoreStoreTest is Test {
|
||||||
@ -22,12 +22,12 @@ contract scoreStoreTest is Test {
|
|||||||
assertEq(s.p1Score, 5);
|
assertEq(s.p1Score, 5);
|
||||||
assertEq(s.p2Score, 8);
|
assertEq(s.p2Score, 8);
|
||||||
|
|
||||||
id = scoreS.addScore("ahhhhh", "test", 5, 8);
|
id = scoreS.addScore("ahhhhh", "test", 7, 8);
|
||||||
|
|
||||||
s = scoreS.getScore(id);
|
s = scoreS.getScore(id);
|
||||||
assertEq(s.p1, "ahhhhh");
|
assertEq(s.p1, "ahhhhh");
|
||||||
assertEq(s.p2, "test");
|
assertEq(s.p2, "test");
|
||||||
assertEq(s.p1Score, 5);
|
assertEq(s.p1Score, 7);
|
||||||
assertEq(s.p2Score, 8);
|
assertEq(s.p2Score, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user