diff --git a/packages/backend/src/registry.ts b/packages/backend/src/registry.ts index 1519da71..4f1cf626 100644 --- a/packages/backend/src/registry.ts +++ b/packages/backend/src/registry.ts @@ -5,7 +5,7 @@ import { Octokit } from 'octokit'; import { inc as semverInc } from 'semver'; import { DeepPartial } from 'typeorm'; -import { Account, Registry as LaconicRegistry, getGasPrice, parseGasAndFees } from '@cerc-io/registry-sdk'; +import { Account, Registry as LaconicRegistry, getGasPrice, parseGasAndFees, IndexedTx } from '@cerc-io/registry-sdk'; import { RegistryConfig } from './config'; import { @@ -505,6 +505,15 @@ export class Registry { return account.address; } + async getTxResponse(txHash: string): Promise { + const account = new Account(Buffer.from(this.registryConfig.privateKey, 'hex')); + await account.init(); + const laconicClient = await this.registry.getLaconicClient(account); + const txResponse: IndexedTx | null = await laconicClient.getTx(txHash); + + return txResponse; + } + getLrn(appName: string): string { assert(this.registryConfig.authority, "Authority doesn't exist"); return `lrn://${this.registryConfig.authority}/applications/${appName}`; diff --git a/packages/backend/src/resolvers.ts b/packages/backend/src/resolvers.ts index 7995765d..3fe9a9be 100644 --- a/packages/backend/src/resolvers.ts +++ b/packages/backend/src/resolvers.ts @@ -84,6 +84,17 @@ export const createResolvers = async (service: Service): Promise => { address: async (_: any, __: any, context: any) => { return service.getAddress(); }, + + verifyTx: async ( + _: any, + { + txHash, + amount, + senderAddress, + }: { txHash: string; amount: string; senderAddress: string }, + ) => { + return service.verifyTx(txHash, amount, senderAddress); + }, }, // TODO: Return error in GQL response diff --git a/packages/backend/src/schema.gql b/packages/backend/src/schema.gql index c4427b02..4ea3f22c 100644 --- a/packages/backend/src/schema.gql +++ b/packages/backend/src/schema.gql @@ -265,6 +265,7 @@ type Query { domains(projectId: String!, filter: FilterDomainsInput): [Domain] deployers: [Deployer] address: String! + verifyTx(txhash: String!, amount: String!, senderAddress: String!): Boolean! } type Mutation { diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index 6f48cc9e..0788db85 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -1405,4 +1405,26 @@ export class Service { async getAddress(): Promise { return this.laconicRegistry.getAddress(); } + + async verifyTx(txhash: string, amountSent: string, senderAddress: string): Promise { + const txResponse = await this.laconicRegistry.getTxResponse(txhash); + if (!txResponse) { + log('Transaction response not found'); + return false; + } + + const transfer = txResponse.events.find(e => e.type === 'transfer' && e.attributes.some(a => a.key === 'msg_index')); + if (!transfer) { + log('No transfer event found'); + return false; + } + + const sender = transfer.attributes.find(a => a.key === 'sender')?.value; + const recipient = transfer.attributes.find(a => a.key === 'recipient')?.value; + const amount = transfer.attributes.find(a => a.key === 'amount')?.value; + + const recipientAddress = await this.getAddress(); + + return amount === amountSent && sender === senderAddress && recipient === recipientAddress; + } } diff --git a/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx b/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx index 9879c56d..7e855240 100644 --- a/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx +++ b/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx @@ -14,7 +14,6 @@ import { ArrowRightCircleFilledIcon, LoadingIcon, } from 'components/shared/CustomIcon'; -import { Checkbox } from 'components/shared/Checkbox'; import { Button } from 'components/shared/Button'; import { useToast } from 'components/shared/Toast'; @@ -169,15 +168,6 @@ const CreateRepo = () => { )} /> -
- ( - - )} - /> -