From 33025588bc64f6cacb1c903fc6e9c133e08e1f2e Mon Sep 17 00:00:00 2001 From: CosmoWorker Date: Mon, 24 Mar 2025 13:31:53 +0000 Subject: [PATCH 1/6] added Transactions model for payouts --- .../migration.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/db/prisma/migrations/20250323143423_update_validator_and_transactions_model/migration.sql diff --git a/packages/db/prisma/migrations/20250323143423_update_validator_and_transactions_model/migration.sql b/packages/db/prisma/migrations/20250323143423_update_validator_and_transactions_model/migration.sql new file mode 100644 index 0000000..d1909dc --- /dev/null +++ b/packages/db/prisma/migrations/20250323143423_update_validator_and_transactions_model/migration.sql @@ -0,0 +1,17 @@ +-- AlterTable +ALTER TABLE "Validator" ADD COLUMN "isPaidOut" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "lockedAt" TIMESTAMP(3); + +-- CreateTable +CREATE TABLE "Transactions" ( + "id" TEXT NOT NULL, + "amount" INTEGER NOT NULL, + "signature" TEXT NOT NULL, + "validatorId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Transactions_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Transactions" ADD CONSTRAINT "Transactions_validatorId_fkey" FOREIGN KEY ("validatorId") REFERENCES "Validator"("id") ON DELETE RESTRICT ON UPDATE CASCADE; From 0c8f9d4b96ec69545c46cda723f2dd2763c89cbd Mon Sep 17 00:00:00 2001 From: CosmoWorker Date: Mon, 24 Mar 2025 13:34:43 +0000 Subject: [PATCH 2/6] updated validator endpoint with locks --- apps/api/index.ts | 98 ++++++++++++++++++++++++++++++-- apps/api/middleware.ts | 25 ++++---- apps/api/types.d.ts | 1 - apps/frontend/.gitignore | 3 + apps/validator/index.ts | 4 +- bun.lock | 3 + packages/db/package.json | 1 + packages/db/prisma/schema.prisma | 42 +++++++++----- packages/db/src/index.ts | 3 +- 9 files changed, 145 insertions(+), 35 deletions(-) diff --git a/apps/api/index.ts b/apps/api/index.ts index e791ed7..ddaf2ba 100644 --- a/apps/api/index.ts +++ b/apps/api/index.ts @@ -1,9 +1,10 @@ import express from "express" import { authMiddleware } from "./middleware"; import { prismaClient } from "db/client"; +import {Prisma} from "db/client"; import cors from "cors"; -import { Transaction, SystemProgram, Connection } from "@solana/web3.js"; - +import { Transaction, SystemProgram, Connection, Keypair, PublicKey, sendAndConfirmTransaction } from "@solana/web3.js"; +const privateKey=process.env.PRIVATE_KEY; const connection = new Connection("https://api.mainnet-beta.solana.com"); const app = express(); @@ -42,7 +43,9 @@ app.get("/api/v1/website/status", authMiddleware, async (req, res) => { } }) - res.json(data) + res.json({ + data + }); }) @@ -84,7 +87,94 @@ app.delete("/api/v1/website/", authMiddleware, async (req, res) => { }) app.post("/api/v1/payout/:validatorId", async (req, res) => { - + const validatorId=req.params.validatorId; + + const txn=await prismaClient.$transaction(async (prisma)=>{ + const validator=await prisma.validator.findUnique({ + where:{ + id: validatorId + }, + select:{ + id: true, + pendingPayouts: true, + publicKey: true, + lockedAt: true + } + }) + + if (!validator){ + res.status(404).json({ + message: "Validator not found" + }); + return; + } + + if (validator.lockedAt){ + res.json({ + message: "Payout is still in process" + }); + return; + } + + if (validator.pendingPayouts===0){ + res.json({ + message: "No payout left" + }); + return; + } + + await prisma.validator.update({ + where:{ + id: validatorId + }, + data:{ + lockedAt: new Date() + } + }); + return validator; + }); + if (!txn) return; + + try{ + const fromKeypair=Keypair.fromSecretKey(Uint8Array.from(JSON.parse(privateKey!))); + const toPublicKey= new PublicKey(txn.publicKey); + const amount=txn.pendingPayouts * 1000000; + + const transaction=new Transaction().add( + SystemProgram.transfer({ + fromPubkey: fromKeypair.publicKey, + toPubkey: toPublicKey, + lamports: amount + }) + ); + + const signature=await sendAndConfirmTransaction(connection, transaction, [fromKeypair]); + await prismaClient.validator.update({ + where:{id: validatorId}, + data:{ + pendingPayouts: 0, + isPaidOut: true, + lockedAt: null, + transactions:{ + create:{ + amount: amount, + signature: signature, + createdAt: new Date + } as Prisma.TransactionsCreateWithoutValidatorInput + } + } + }); + + res.json({ + message: "Payout Successful with signature: ", signature + }) + }catch(e){ + console.log("Error processing payout", e); + res.status(500).json({ + messsage: "Error processing payout" + }); + } + }) app.listen(8080); diff --git a/apps/api/middleware.ts b/apps/api/middleware.ts index 5217ce0..ba9e0ff 100644 --- a/apps/api/middleware.ts +++ b/apps/api/middleware.ts @@ -5,16 +5,21 @@ import { JWT_PUBLIC_KEY } from "./config"; export function authMiddleware(req: Request, res: Response, next: NextFunction) { const token = req.headers['authorization']; if (!token) { - return res.status(401).json({ error: 'Unauthorized' }); + res.status(401).json({ error: 'Unauthorized' }); + return; } - - const decoded = jwt.verify(token, JWT_PUBLIC_KEY); - console.log(decoded); - if (!decoded || !decoded.sub) { - return res.status(401).json({ error: 'Unauthorized' }); + try{ + const decoded = jwt.verify(token, JWT_PUBLIC_KEY); + console.log(decoded); + if (!decoded || !decoded.sub) { + res.status(401).json({ error: 'Unauthorized' }); + return; + } + req.userId = decoded.sub as string; + next(); + }catch(e){ + res.status(401).json({ + error: 'Invalid Token' + }) } - - req.userId = decoded.sub as string; - - next() } \ No newline at end of file diff --git a/apps/api/types.d.ts b/apps/api/types.d.ts index 9bdaea1..59f6419 100644 --- a/apps/api/types.d.ts +++ b/apps/api/types.d.ts @@ -1,4 +1,3 @@ - declare namespace Express { interface Request { userId?: string diff --git a/apps/frontend/.gitignore b/apps/frontend/.gitignore index 5ef6a52..e2764f9 100644 --- a/apps/frontend/.gitignore +++ b/apps/frontend/.gitignore @@ -39,3 +39,6 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +# clerk configuration (can include secrets) +/.clerk/ diff --git a/apps/validator/index.ts b/apps/validator/index.ts index 1736c7e..7f6b1d3 100644 --- a/apps/validator/index.ts +++ b/apps/validator/index.ts @@ -92,6 +92,4 @@ async function signMessage(message: string, keypair: Keypair) { main(); -setInterval(async () => { - -}, 10000); \ No newline at end of file +setInterval(async () => {}, 10000); \ No newline at end of file diff --git a/bun.lock b/bun.lock index 1b01488..a9b67e1 100644 --- a/bun.lock +++ b/bun.lock @@ -105,6 +105,7 @@ "packages/db": { "name": "db", "dependencies": { + "@prisma/client": "6.5.0", "prisma": "^6.5.0", }, "devDependencies": { @@ -327,6 +328,8 @@ "@nolyfill/is-core-module": ["@nolyfill/is-core-module@1.0.39", "", {}, "sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA=="], + "@prisma/client": ["@prisma/client@6.5.0", "", { "peerDependencies": { "prisma": "*", "typescript": ">=5.1.0" }, "optionalPeers": ["prisma", "typescript"] }, "sha512-M6w1Ql/BeiGoZmhMdAZUXHu5sz5HubyVcKukbLs3l0ELcQb8hTUJxtGEChhv4SVJ0QJlwtLnwOLgIRQhpsm9dw=="], + "@prisma/config": ["@prisma/config@6.5.0", "", { "dependencies": { "esbuild": ">=0.12 <1", "esbuild-register": "3.6.0" } }, "sha512-sOH/2Go9Zer67DNFLZk6pYOHj+rumSb0VILgltkoxOjYnlLqUpHPAN826vnx8HigqnOCxj9LRhT6U7uLiIIWgw=="], "@prisma/debug": ["@prisma/debug@6.5.0", "", {}, "sha512-fc/nusYBlJMzDmDepdUtH9aBsJrda2JNErP9AzuHbgUEQY0/9zQYZdNlXmKoIWENtio+qarPNe/+DQtrX5kMcQ=="], diff --git a/packages/db/package.json b/packages/db/package.json index 833e905..9d56099 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -12,6 +12,7 @@ "typescript": "^5.0.0" }, "dependencies": { + "@prisma/client": "6.5.0", "prisma": "^6.5.0" }, "prisma": { diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index a3b9521..4b7c767 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -14,36 +14,48 @@ datasource db { } model User { - id String @id @default(uuid()) + id String @id @default(uuid()) email String } model Website { - id String @id @default(uuid()) - url String - userId String - ticks WebsiteTick[] - disabled Boolean @default(false) + id String @id @default(uuid()) + url String + userId String + ticks WebsiteTick[] + disabled Boolean @default(false) } model Validator { - id String @id @default(uuid()) - publicKey String - location String - ip String - pendingPayouts Int @default(0) - ticks WebsiteTick[] + id String @id @default(uuid()) + publicKey String + location String + ip String + pendingPayouts Int @default(0) + ticks WebsiteTick[] + transactions Transactions[] + isPaidOut Boolean @default(false) + lockedAt DateTime? } model WebsiteTick { - id String @id @default(uuid()) + id String @id @default(uuid()) websiteId String validatorId String createdAt DateTime status WebsiteStatus latency Float - website Website @relation(fields: [websiteId], references: [id]) - validator Validator @relation(fields: [validatorId], references: [id]) + website Website @relation(fields: [websiteId], references: [id]) + validator Validator @relation(fields: [validatorId], references: [id]) +} + +model Transactions{ + id String @id @default(uuid()) + amount Int + signature String + validatorId String + validator Validator @relation(fields: [validatorId], references: [id]) + createdAt DateTime } enum WebsiteStatus { diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 7b50121..1427342 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -1,5 +1,4 @@ import { PrismaClient } from "@prisma/client" +export { Prisma } from "@prisma/client" export const prismaClient = new PrismaClient() - - From 96ffaec691578bfde4b5f6aa34fc048fddd2b310 Mon Sep 17 00:00:00 2001 From: CosmoWorker Date: Tue, 25 Mar 2025 07:31:47 +0000 Subject: [PATCH 3/6] added_poller_with_transactionStatus_retryCount --- apps/poller/.gitignore | 34 ++++++++++++++++++ apps/poller/README.md | 15 ++++++++ apps/poller/index.ts | 1 + apps/poller/package.json | 16 +++++++++ apps/poller/src/poller.ts | 74 +++++++++++++++++++++++++++++++++++++++ apps/poller/tsconfig.json | 28 +++++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 apps/poller/.gitignore create mode 100644 apps/poller/README.md create mode 100644 apps/poller/index.ts create mode 100644 apps/poller/package.json create mode 100644 apps/poller/src/poller.ts create mode 100644 apps/poller/tsconfig.json diff --git a/apps/poller/.gitignore b/apps/poller/.gitignore new file mode 100644 index 0000000..a14702c --- /dev/null +++ b/apps/poller/.gitignore @@ -0,0 +1,34 @@ +# dependencies (bun install) +node_modules + +# output +out +dist +*.tgz + +# code coverage +coverage +*.lcov + +# logs +logs +_.log +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# caches +.eslintcache +.cache +*.tsbuildinfo + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/apps/poller/README.md b/apps/poller/README.md new file mode 100644 index 0000000..7d9691f --- /dev/null +++ b/apps/poller/README.md @@ -0,0 +1,15 @@ +# poller + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.2.5. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/apps/poller/index.ts b/apps/poller/index.ts new file mode 100644 index 0000000..f67b2c6 --- /dev/null +++ b/apps/poller/index.ts @@ -0,0 +1 @@ +console.log("Hello via Bun!"); \ No newline at end of file diff --git a/apps/poller/package.json b/apps/poller/package.json new file mode 100644 index 0000000..2a59318 --- /dev/null +++ b/apps/poller/package.json @@ -0,0 +1,16 @@ +{ + "name": "poller", + "module": "index.ts", + "type": "module", + "private": true, + "devDependencies": { + "@types/bun": "latest", + "db": "*" + }, + "peerDependencies": { + "typescript": "^5" + }, + "dependencies": { + "@solana/web3.js": "^1.98.0" + } +} \ No newline at end of file diff --git a/apps/poller/src/poller.ts b/apps/poller/src/poller.ts new file mode 100644 index 0000000..7ae5d16 --- /dev/null +++ b/apps/poller/src/poller.ts @@ -0,0 +1,74 @@ +import { Connection, Keypair, PublicKey, sendAndConfirmTransaction, SystemProgram, Transaction } from "@solana/web3.js"; +import {prismaClient} from "db/client"; + +const connection= new Connection(`${process.env.RPC_URL}`); +const maxRetries=3; + +const pollPendingTransactions=async()=>{ + const pendingTxns= await prismaClient.transactions.findMany({ + where:{status: { + in:["Pending", "Failure"] + }} + }); + + for (const txn of pendingTxns){ + try{ + const txnStatus=await connection.getSignatureStatus(txn.signature); + if(txnStatus.value?.confirmationStatus==="finalized"){ + await prismaClient.$transaction([ + prismaClient.transactions.update({ + where:{id: txn.id}, + data:{ + status: "Success" + } + }), + prismaClient.validator.update({ + where:{id: txn.id}, + data:{ + isPaidOut: true, + pendingPayouts: 0 + } + }) + ]); + }else if(txnStatus.value?.err){ + if (txn.retryCount>=maxRetries){ + console.log(`Transaction ${txn.id} exceeded retry limit`); + break; + } + else { + console.log(`Retrying transaction ${txn.id} attemp no. ${txn.retryCount+1}`); + const fromKeypair=Keypair.fromSecretKey(Uint8Array.from(JSON.parse(`${process.env.PRIVATE_KEY}`))); + const toPublicKey= new PublicKey(txn.validatorId); + const amount= txn.amount; + + const transaction= new Transaction().add( + SystemProgram.transfer({ + fromPubkey: fromKeypair.publicKey, + toPubkey: toPublicKey, + lamports: amount + }) + ) + const newSignature= await sendAndConfirmTransaction(connection, transaction, [fromKeypair]); + await prismaClient.transactions.update({ + where:{id: txn.id}, + data:{ + status: "Pending", + signature: newSignature, + retryCount: {increment: 1} + } + }) + } + }else{ + await prismaClient.transactions.update({ + where:{id: txn.id}, + data:{ + status: "Failure" + } + }); + } + }catch(e){ + console.log(`Error checking the txn with id${txn.id}`, e); + } + } + +}; diff --git a/apps/poller/tsconfig.json b/apps/poller/tsconfig.json new file mode 100644 index 0000000..ab0f0b0 --- /dev/null +++ b/apps/poller/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + // Environment setup & latest features + "lib": ["esnext"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} From 189a560288732ef33d676cb48d48ac291ee5d970 Mon Sep 17 00:00:00 2001 From: CosmoWorker Date: Tue, 25 Mar 2025 07:33:23 +0000 Subject: [PATCH 4/6] minor-change-transactionType --- apps/api/index.ts | 5 +-- bun.lock | 15 +++++++++ .../migration.sql | 11 +++++++ .../migration.sql | 4 +++ packages/db/prisma/schema.prisma | 32 ++++++++++++------- 5 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 packages/db/prisma/migrations/20250324140824_add_transaction_status_enum/migration.sql create mode 100644 packages/db/prisma/migrations/20250325005536_add_retry_count/migration.sql diff --git a/apps/api/index.ts b/apps/api/index.ts index ddaf2ba..9db0c71 100644 --- a/apps/api/index.ts +++ b/apps/api/index.ts @@ -152,14 +152,11 @@ app.post("/api/v1/payout/:validatorId", async (req, res) => { await prismaClient.validator.update({ where:{id: validatorId}, data:{ - pendingPayouts: 0, - isPaidOut: true, lockedAt: null, transactions:{ create:{ amount: amount, - signature: signature, - createdAt: new Date + signature: signature } as Prisma.TransactionsCreateWithoutValidatorInput } } diff --git a/bun.lock b/bun.lock index a9b67e1..34bdbed 100644 --- a/bun.lock +++ b/bun.lock @@ -77,6 +77,19 @@ "typescript": "^5.0.0", }, }, + "apps/poller": { + "name": "poller", + "dependencies": { + "@solana/web3.js": "^1.98.0", + }, + "devDependencies": { + "@types/bun": "latest", + "db": "*", + }, + "peerDependencies": { + "typescript": "^5", + }, + }, "apps/validator": { "name": "validator", "dependencies": { @@ -1316,6 +1329,8 @@ "picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="], + "poller": ["poller@workspace:apps/poller"], + "possible-typed-array-names": ["possible-typed-array-names@1.1.0", "", {}, "sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg=="], "postcss": ["postcss@8.5.3", "", { "dependencies": { "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A=="], diff --git a/packages/db/prisma/migrations/20250324140824_add_transaction_status_enum/migration.sql b/packages/db/prisma/migrations/20250324140824_add_transaction_status_enum/migration.sql new file mode 100644 index 0000000..9412815 --- /dev/null +++ b/packages/db/prisma/migrations/20250324140824_add_transaction_status_enum/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - Added the required column `status` to the `Transactions` table without a default value. This is not possible if the table is not empty. + +*/ +-- CreateEnum +CREATE TYPE "TransactionStatus" AS ENUM ('Pending', 'Success', 'Failure'); + +-- AlterTable +ALTER TABLE "Transactions" ADD COLUMN "status" "TransactionStatus" NOT NULL; diff --git a/packages/db/prisma/migrations/20250325005536_add_retry_count/migration.sql b/packages/db/prisma/migrations/20250325005536_add_retry_count/migration.sql new file mode 100644 index 0000000..bcb479d --- /dev/null +++ b/packages/db/prisma/migrations/20250325005536_add_retry_count/migration.sql @@ -0,0 +1,4 @@ +-- AlterTable +ALTER TABLE "Transactions" ADD COLUMN "retryCount" INTEGER NOT NULL DEFAULT 0, +ALTER COLUMN "createdAt" SET DEFAULT CURRENT_TIMESTAMP, +ALTER COLUMN "status" SET DEFAULT 'Pending'; diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 4b7c767..2b99d8c 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -14,48 +14,56 @@ datasource db { } model User { - id String @id @default(uuid()) + id String @id @default(uuid()) email String } model Website { - id String @id @default(uuid()) + id String @id @default(uuid()) url String userId String ticks WebsiteTick[] - disabled Boolean @default(false) + disabled Boolean @default(false) } model Validator { - id String @id @default(uuid()) + id String @id @default(uuid()) publicKey String location String ip String - pendingPayouts Int @default(0) + pendingPayouts Int @default(0) ticks WebsiteTick[] transactions Transactions[] - isPaidOut Boolean @default(false) + isPaidOut Boolean @default(false) lockedAt DateTime? } model WebsiteTick { - id String @id @default(uuid()) + id String @id @default(uuid()) websiteId String validatorId String createdAt DateTime status WebsiteStatus latency Float - website Website @relation(fields: [websiteId], references: [id]) - validator Validator @relation(fields: [validatorId], references: [id]) + website Website @relation(fields: [websiteId], references: [id]) + validator Validator @relation(fields: [validatorId], references: [id]) } model Transactions{ - id String @id @default(uuid()) + id String @id @default(uuid()) amount Int signature String validatorId String - validator Validator @relation(fields: [validatorId], references: [id]) - createdAt DateTime + validator Validator @relation(fields: [validatorId], references: [id]) + createdAt DateTime @default(now()) + status TransactionStatus @default(Pending) //having as pending so that poller confirms it later + retryCount Int @default(0) +} + +enum TransactionStatus { + Pending + Success + Failure } enum WebsiteStatus { From a3bd87213c9bbf04aa09dc6382a489402fd3540a Mon Sep 17 00:00:00 2001 From: CosmoWorker Date: Tue, 25 Mar 2025 07:41:38 +0000 Subject: [PATCH 5/6] Added polling interval to the poller --- apps/poller/src/poller.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/poller/src/poller.ts b/apps/poller/src/poller.ts index 7ae5d16..a0a9b4b 100644 --- a/apps/poller/src/poller.ts +++ b/apps/poller/src/poller.ts @@ -3,6 +3,7 @@ import {prismaClient} from "db/client"; const connection= new Connection(`${process.env.RPC_URL}`); const maxRetries=3; +const pollingInterval=5000; const pollPendingTransactions=async()=>{ const pendingTxns= await prismaClient.transactions.findMany({ @@ -72,3 +73,8 @@ const pollPendingTransactions=async()=>{ } }; + +const poll=()=>{ + setInterval(pollPendingTransactions, pollingInterval); +}; +poll(); \ No newline at end of file From 7ade56d22dd1292905257d3142b5927260f93e11 Mon Sep 17 00:00:00 2001 From: CosmoWorker Date: Wed, 9 Apr 2025 01:47:11 +0530 Subject: [PATCH 6/6] fix: changed validator id to public key --- apps/poller/src/poller.ts | 7 ++++++- bun.lock | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/poller/src/poller.ts b/apps/poller/src/poller.ts index a0a9b4b..96fb4a6 100644 --- a/apps/poller/src/poller.ts +++ b/apps/poller/src/poller.ts @@ -39,7 +39,12 @@ const pollPendingTransactions=async()=>{ else { console.log(`Retrying transaction ${txn.id} attemp no. ${txn.retryCount+1}`); const fromKeypair=Keypair.fromSecretKey(Uint8Array.from(JSON.parse(`${process.env.PRIVATE_KEY}`))); - const toPublicKey= new PublicKey(txn.validatorId); + const validator= await prismaClient.validator.findMany({ + where: { + id: txn.validatorId + } + }); + const toPublicKey= new PublicKey(validator.publicKey); const amount= txn.amount; const transaction= new Transaction().add( diff --git a/bun.lock b/bun.lock index 34bdbed..c9323f5 100644 --- a/bun.lock +++ b/bun.lock @@ -491,7 +491,7 @@ "@types/body-parser": ["@types/body-parser@1.19.5", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg=="], - "@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="], + "@types/bun": ["@types/bun@1.2.8", "", { "dependencies": { "bun-types": "1.2.7" } }, "sha512-t8L1RvJVUghW5V+M/fL3Thbxcs0HwNsXsnTEBEfEVqGteiJToOlZ/fyOEaR1kZsNqnu+3XA4RI/qmnX4w6+S+w=="], "@types/connect": ["@types/connect@3.4.38", "", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="], @@ -659,7 +659,7 @@ "bufferutil": ["bufferutil@4.0.9", "", { "dependencies": { "node-gyp-build": "^4.3.0" } }, "sha512-WDtdLmJvAuNNPzByAYpRo2rF1Mmradw6gvWsQKf63476DDXmomT9zUiGypLcG4ibIM67vhAj8jJRdbmEws2Aqw=="], - "bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="], + "bun-types": ["bun-types@1.2.7", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-P4hHhk7kjF99acXqKvltyuMQ2kf/rzIw3ylEDpCxDS9Xa0X0Yp/gJu/vDCucmWpiur5qJ0lwB2bWzOXa2GlHqA=="], "busboy": ["busboy@1.6.0", "", { "dependencies": { "streamsearch": "^1.1.0" } }, "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA=="], @@ -1687,6 +1687,10 @@ "body-parser/debug": ["debug@2.6.9", "", { "dependencies": { "ms": "2.0.0" } }, "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA=="], + "common/@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="], + + "db/@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="], + "eslint-import-resolver-node/debug": ["debug@3.2.7", "", { "dependencies": { "ms": "^2.1.1" } }, "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ=="], "eslint-import-resolver-node/resolve": ["resolve@1.22.10", "", { "dependencies": { "is-core-module": "^2.16.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, "bin": { "resolve": "bin/resolve" } }, "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w=="], @@ -1763,6 +1767,10 @@ "body-parser/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], + "common/@types/bun/bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="], + + "db/@types/bun/bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="], + "express/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], "finalhandler/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="],