From 886205ca55c2c47e211593916b720373591bdf01 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Mon, 13 Sep 2021 20:38:28 +1000 Subject: [PATCH] fix: transfer --- package.json | 4 +- src/abi/TornadoPool.json | 85 ++++++---- src/artifacts/TornadoPool.d.ts | 145 ++++++++++++------ .../factories/TornadoPool__factory.ts | 85 ++++++---- src/config/bull.config.ts | 2 +- src/constants/contracts.ts | 8 +- src/modules/api/api.controller.ts | 10 +- src/modules/api/api.service.ts | 8 +- src/modules/api/api.validator.ts | 12 +- src/modules/queue/queue.module.ts | 4 +- ....processor.ts => transaction.processor.ts} | 16 +- 11 files changed, 248 insertions(+), 131 deletions(-) rename src/modules/queue/{withdrawal.processor.ts => transaction.processor.ts} (91%) diff --git a/package.json b/package.json index a3a6417..5a3dc01 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", - "start:dev": "nest start --watch", - "start:debug": "nest start --debug --watch", + "start:dev": "NODE_ENV=development nest start --watch", + "start:debug": "NODE_ENV=development nest start --debug --watch", "start:prod": "yarn prebuild; yarn build; node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", diff --git a/src/abi/TornadoPool.json b/src/abi/TornadoPool.json index d014b1e..26c5aaa 100644 --- a/src/abi/TornadoPool.json +++ b/src/abi/TornadoPool.json @@ -10,11 +10,6 @@ "internalType": "contract IVerifier", "name": "_verifier16", "type": "address" - }, - { - "internalType": "bytes32", - "name": "_currentRoot", - "type": "bytes32" } ], "stateMutability": "nonpayable", @@ -112,6 +107,19 @@ { "inputs": [], "name": "MAX_EXT_AMOUNT", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MAX_FEE", "outputs": [ { "internalType": "uint256", @@ -125,17 +133,22 @@ { "inputs": [ { - "internalType": "uint256", + "internalType": "int256", "name": "_extAmount", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "_fee", "type": "uint256" } ], - "name": "calculateExternalAmount", + "name": "calculatePublicAmount", "outputs": [ { - "internalType": "int256", + "internalType": "uint256", "name": "", - "type": "int256" + "type": "uint256" } ], "stateMutability": "pure", @@ -167,6 +180,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_currentRoot", + "type": "bytes32" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -283,12 +309,7 @@ }, { "internalType": "uint256", - "name": "extAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "fee", + "name": "publicAmount", "type": "uint256" }, { @@ -308,11 +329,21 @@ "name": "recipient", "type": "address" }, + { + "internalType": "int256", + "name": "extAmount", + "type": "int256" + }, { "internalType": "address payable", "name": "relayer", "type": "address" }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, { "internalType": "bytes", "name": "encryptedOutput1", @@ -370,12 +401,7 @@ }, { "internalType": "uint256", - "name": "extAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "fee", + "name": "publicAmount", "type": "uint256" }, { @@ -395,11 +421,21 @@ "name": "recipient", "type": "address" }, + { + "internalType": "int256", + "name": "extAmount", + "type": "int256" + }, { "internalType": "address payable", "name": "relayer", "type": "address" }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, { "internalType": "bytes", "name": "encryptedOutput1", @@ -483,12 +519,7 @@ }, { "internalType": "uint256", - "name": "extAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "fee", + "name": "publicAmount", "type": "uint256" }, { diff --git a/src/artifacts/TornadoPool.d.ts b/src/artifacts/TornadoPool.d.ts index d60f782..b4be1a3 100644 --- a/src/artifacts/TornadoPool.d.ts +++ b/src/artifacts/TornadoPool.d.ts @@ -24,9 +24,11 @@ interface TornadoPoolInterface extends ethers.utils.Interface { functions: { "FIELD_SIZE()": FunctionFragment; "MAX_EXT_AMOUNT()": FunctionFragment; - "calculateExternalAmount(uint256)": FunctionFragment; + "MAX_FEE()": FunctionFragment; + "calculatePublicAmount(int256,uint256)": FunctionFragment; "currentCommitmentIndex()": FunctionFragment; "currentRoot()": FunctionFragment; + "initialize(bytes32)": FunctionFragment; "isSpent(bytes32)": FunctionFragment; "nullifierHashes(bytes32)": FunctionFragment; "register(tuple)": FunctionFragment; @@ -45,9 +47,10 @@ interface TornadoPoolInterface extends ethers.utils.Interface { functionFragment: "MAX_EXT_AMOUNT", values?: undefined ): string; + encodeFunctionData(functionFragment: "MAX_FEE", values?: undefined): string; encodeFunctionData( - functionFragment: "calculateExternalAmount", - values: [BigNumberish] + functionFragment: "calculatePublicAmount", + values: [BigNumberish, BigNumberish] ): string; encodeFunctionData( functionFragment: "currentCommitmentIndex", @@ -57,6 +60,10 @@ interface TornadoPoolInterface extends ethers.utils.Interface { functionFragment: "currentRoot", values?: undefined ): string; + encodeFunctionData( + functionFragment: "initialize", + values: [BytesLike] + ): string; encodeFunctionData(functionFragment: "isSpent", values: [BytesLike]): string; encodeFunctionData( functionFragment: "nullifierHashes", @@ -77,13 +84,14 @@ interface TornadoPoolInterface extends ethers.utils.Interface { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; } @@ -99,13 +107,14 @@ interface TornadoPoolInterface extends ethers.utils.Interface { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; } @@ -126,8 +135,7 @@ interface TornadoPoolInterface extends ethers.utils.Interface { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; } ] @@ -138,8 +146,9 @@ interface TornadoPoolInterface extends ethers.utils.Interface { functionFragment: "MAX_EXT_AMOUNT", data: BytesLike ): Result; + decodeFunctionResult(functionFragment: "MAX_FEE", data: BytesLike): Result; decodeFunctionResult( - functionFragment: "calculateExternalAmount", + functionFragment: "calculatePublicAmount", data: BytesLike ): Result; decodeFunctionResult( @@ -150,6 +159,7 @@ interface TornadoPoolInterface extends ethers.utils.Interface { functionFragment: "currentRoot", data: BytesLike ): Result; + decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result; decodeFunctionResult(functionFragment: "isSpent", data: BytesLike): Result; decodeFunctionResult( functionFragment: "nullifierHashes", @@ -232,8 +242,11 @@ export class TornadoPool extends BaseContract { MAX_EXT_AMOUNT(overrides?: CallOverrides): Promise<[BigNumber]>; - calculateExternalAmount( + MAX_FEE(overrides?: CallOverrides): Promise<[BigNumber]>; + + calculatePublicAmount( _extAmount: BigNumberish, + _fee: BigNumberish, overrides?: CallOverrides ): Promise<[BigNumber]>; @@ -241,6 +254,11 @@ export class TornadoPool extends BaseContract { currentRoot(overrides?: CallOverrides): Promise<[string]>; + initialize( + _currentRoot: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + isSpent( _nullifierHash: BytesLike, overrides?: CallOverrides @@ -265,13 +283,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -286,13 +305,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -311,8 +331,7 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, overrides?: CallOverrides @@ -323,8 +342,11 @@ export class TornadoPool extends BaseContract { MAX_EXT_AMOUNT(overrides?: CallOverrides): Promise; - calculateExternalAmount( + MAX_FEE(overrides?: CallOverrides): Promise; + + calculatePublicAmount( _extAmount: BigNumberish, + _fee: BigNumberish, overrides?: CallOverrides ): Promise; @@ -332,6 +354,11 @@ export class TornadoPool extends BaseContract { currentRoot(overrides?: CallOverrides): Promise; + initialize( + _currentRoot: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + isSpent( _nullifierHash: BytesLike, overrides?: CallOverrides @@ -353,13 +380,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -374,13 +402,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -399,8 +428,7 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, overrides?: CallOverrides @@ -411,8 +439,11 @@ export class TornadoPool extends BaseContract { MAX_EXT_AMOUNT(overrides?: CallOverrides): Promise; - calculateExternalAmount( + MAX_FEE(overrides?: CallOverrides): Promise; + + calculatePublicAmount( _extAmount: BigNumberish, + _fee: BigNumberish, overrides?: CallOverrides ): Promise; @@ -420,6 +451,11 @@ export class TornadoPool extends BaseContract { currentRoot(overrides?: CallOverrides): Promise; + initialize( + _currentRoot: BytesLike, + overrides?: CallOverrides + ): Promise; + isSpent( _nullifierHash: BytesLike, overrides?: CallOverrides @@ -444,13 +480,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -465,13 +502,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -490,8 +528,7 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, overrides?: CallOverrides @@ -528,8 +565,11 @@ export class TornadoPool extends BaseContract { MAX_EXT_AMOUNT(overrides?: CallOverrides): Promise; - calculateExternalAmount( + MAX_FEE(overrides?: CallOverrides): Promise; + + calculatePublicAmount( _extAmount: BigNumberish, + _fee: BigNumberish, overrides?: CallOverrides ): Promise; @@ -537,6 +577,11 @@ export class TornadoPool extends BaseContract { currentRoot(overrides?: CallOverrides): Promise; + initialize( + _currentRoot: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + isSpent( _nullifierHash: BytesLike, overrides?: CallOverrides @@ -561,13 +606,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -582,13 +628,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -607,8 +654,7 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, overrides?: CallOverrides @@ -620,8 +666,11 @@ export class TornadoPool extends BaseContract { MAX_EXT_AMOUNT(overrides?: CallOverrides): Promise; - calculateExternalAmount( + MAX_FEE(overrides?: CallOverrides): Promise; + + calculatePublicAmount( _extAmount: BigNumberish, + _fee: BigNumberish, overrides?: CallOverrides ): Promise; @@ -631,6 +680,11 @@ export class TornadoPool extends BaseContract { currentRoot(overrides?: CallOverrides): Promise; + initialize( + _currentRoot: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + isSpent( _nullifierHash: BytesLike, overrides?: CallOverrides @@ -655,13 +709,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -676,13 +731,14 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, _extData: { recipient: string; + extAmount: BigNumberish; relayer: string; + fee: BigNumberish; encryptedOutput1: BytesLike; encryptedOutput2: BytesLike; }, @@ -701,8 +757,7 @@ export class TornadoPool extends BaseContract { inputNullifiers: BytesLike[]; outputCommitments: [BytesLike, BytesLike]; outPathIndices: BigNumberish; - extAmount: BigNumberish; - fee: BigNumberish; + publicAmount: BigNumberish; extDataHash: BytesLike; }, overrides?: CallOverrides diff --git a/src/artifacts/factories/TornadoPool__factory.ts b/src/artifacts/factories/TornadoPool__factory.ts index c5dff10..274b4c9 100644 --- a/src/artifacts/factories/TornadoPool__factory.ts +++ b/src/artifacts/factories/TornadoPool__factory.ts @@ -19,11 +19,6 @@ const _abi = [ name: "_verifier16", type: "address", }, - { - internalType: "bytes32", - name: "_currentRoot", - type: "bytes32", - }, ], stateMutability: "nonpayable", type: "constructor", @@ -120,6 +115,19 @@ const _abi = [ { inputs: [], name: "MAX_EXT_AMOUNT", + outputs: [ + { + internalType: "int256", + name: "", + type: "int256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "MAX_FEE", outputs: [ { internalType: "uint256", @@ -133,17 +141,22 @@ const _abi = [ { inputs: [ { - internalType: "uint256", + internalType: "int256", name: "_extAmount", + type: "int256", + }, + { + internalType: "uint256", + name: "_fee", type: "uint256", }, ], - name: "calculateExternalAmount", + name: "calculatePublicAmount", outputs: [ { - internalType: "int256", + internalType: "uint256", name: "", - type: "int256", + type: "uint256", }, ], stateMutability: "pure", @@ -175,6 +188,19 @@ const _abi = [ stateMutability: "view", type: "function", }, + { + inputs: [ + { + internalType: "bytes32", + name: "_currentRoot", + type: "bytes32", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -291,12 +317,7 @@ const _abi = [ }, { internalType: "uint256", - name: "extAmount", - type: "uint256", - }, - { - internalType: "uint256", - name: "fee", + name: "publicAmount", type: "uint256", }, { @@ -316,11 +337,21 @@ const _abi = [ name: "recipient", type: "address", }, + { + internalType: "int256", + name: "extAmount", + type: "int256", + }, { internalType: "address payable", name: "relayer", type: "address", }, + { + internalType: "uint256", + name: "fee", + type: "uint256", + }, { internalType: "bytes", name: "encryptedOutput1", @@ -378,12 +409,7 @@ const _abi = [ }, { internalType: "uint256", - name: "extAmount", - type: "uint256", - }, - { - internalType: "uint256", - name: "fee", + name: "publicAmount", type: "uint256", }, { @@ -403,11 +429,21 @@ const _abi = [ name: "recipient", type: "address", }, + { + internalType: "int256", + name: "extAmount", + type: "int256", + }, { internalType: "address payable", name: "relayer", type: "address", }, + { + internalType: "uint256", + name: "fee", + type: "uint256", + }, { internalType: "bytes", name: "encryptedOutput1", @@ -491,12 +527,7 @@ const _abi = [ }, { internalType: "uint256", - name: "extAmount", - type: "uint256", - }, - { - internalType: "uint256", - name: "fee", + name: "publicAmount", type: "uint256", }, { diff --git a/src/config/bull.config.ts b/src/config/bull.config.ts index 98a070a..2c27fa9 100644 --- a/src/config/bull.config.ts +++ b/src/config/bull.config.ts @@ -1,7 +1,7 @@ import { registerAs } from '@nestjs/config'; export default registerAs('bull', () => ({ - name: 'withdrawal', + name: 'transaction', redis: { host: process.env.NODE_ENV === 'development' ? 'localhost' : 'redis', port: 6379, diff --git a/src/constants/contracts.ts b/src/constants/contracts.ts index 40e8a94..fd9b99d 100644 --- a/src/constants/contracts.ts +++ b/src/constants/contracts.ts @@ -1,13 +1,13 @@ import { ChainId } from '@/types'; export const CONTRACT_NETWORKS: { [chainId in ChainId]: string } = { - [ChainId.MAINNET]: '0x8Bfac9EF3d73cE08C7CEC339C0fE3B2e57814c1E', - [ChainId.GOERLI]: '0x5900e35C0ED9807d36d6b9b06701e2004194fd5A', - [ChainId.OPTIMISM]: '0xa7727c7807f401FF83a5F96D8b5C4E591b3B0E28', + // [ChainId.MAINNET]: '0x8Bfac9EF3d73cE08C7CEC339C0fE3B2e57814c1E', + [ChainId.GOERLI]: '0x3a4cbAC9C28abb1205B5Ca8AdC54b3306B18eEE7', + [ChainId.OPTIMISM]: '0xcd7318c299A82E887f5180EF865a4c350dFC9fe5', }; export const RPC_LIST: { [chainId in ChainId]: string } = { - [ChainId.MAINNET]: 'https://mainnet.infura.io/v3/eb6a84e726614079948e0b1efce5baa5', + // [ChainId.MAINNET]: 'https://mainnet.infura.io/v3/eb6a84e726614079948e0b1efce5baa5', [ChainId.GOERLI]: 'https://eth-goerli.alchemyapi.io/v2/hlSj0EqPUuLGyyTExs6UqFKnXDrc_eOh', [ChainId.OPTIMISM]: 'https://optimism-kovan.infura.io/v3/8f786b96d16046b78e0287fa61c6fcf8', }; diff --git a/src/modules/api/api.controller.ts b/src/modules/api/api.controller.ts index edcd34f..18a8f2e 100644 --- a/src/modules/api/api.controller.ts +++ b/src/modules/api/api.controller.ts @@ -2,7 +2,7 @@ import { Controller, Body, Param, Res, Get, Post, HttpStatus } from '@nestjs/com import { Response } from 'express'; import { ApiService } from './api.service'; -import { validateWithdrawRequest } from './api.validator'; +import { validateTransactionRequest } from './api.validator'; @Controller() export class ApiController { @@ -29,15 +29,15 @@ export class ApiController { return job; } - @Post('/withdrawal') - async withdrawal(@Res() res: Response, @Body() { body }: any) { - const inputError = validateWithdrawRequest(body); + @Post('/transaction') + async transaction(@Res() res: Response, @Body() { body }: any) { + const inputError = validateTransactionRequest(body); if (inputError) { console.log('Invalid input:', inputError); return res.status(HttpStatus.BAD_REQUEST).json({ error: inputError }); } - return await this.service.withdrawal(JSON.parse(body)); + return await this.service.transaction(JSON.parse(body)); } } diff --git a/src/modules/api/api.service.ts b/src/modules/api/api.service.ts index 7881251..e0b2ede 100644 --- a/src/modules/api/api.service.ts +++ b/src/modules/api/api.service.ts @@ -10,7 +10,7 @@ class ApiService { constructor( private configService: ConfigService, private providerService: ProviderService, - @InjectQueue('withdrawal') private withdrawalQueue: Queue, + @InjectQueue('transaction') private transactionQueue: Queue, ) {} async status(): Promise { @@ -31,14 +31,14 @@ class ApiService { return `This is tornado.cash Relayer service. Check the /status for settings`; } - async withdrawal(data: any): Promise { - const job = await this.withdrawalQueue.add(data); + async transaction(data: any): Promise { + const job = await this.transactionQueue.add(data); return String(job.id); } async getJob(id: string): Promise { - return await this.withdrawalQueue.getJob(id); + return await this.transactionQueue.getJob(id); } private async healthCheck(): Promise { diff --git a/src/modules/api/api.validator.ts b/src/modules/api/api.validator.ts index 4782eca..0cb2e58 100644 --- a/src/modules/api/api.validator.ts +++ b/src/modules/api/api.validator.ts @@ -31,7 +31,7 @@ const recipientType = { }, }; -const withdrawSchema = { +const transactionSchema = { type: 'object', properties: { proof: proofType, @@ -46,9 +46,9 @@ const withdrawSchema = { required: ['proof', 'args'], }; -const validateTornadoWithdraw = ajv.compile(withdrawSchema); +const validateTornadoTransaction = ajv.compile(transactionSchema); -function getInputError(validator: ValidateFunction, data: typeof withdrawSchema) { +function getInputError(validator: ValidateFunction, data: typeof transactionSchema) { validator(data); if (validator.errors) { const [error] = validator.errors; @@ -57,8 +57,8 @@ function getInputError(validator: ValidateFunction, data: typeof withdrawSchema) return null; } -function validateWithdrawRequest(data: typeof withdrawSchema) { - return getInputError(validateTornadoWithdraw, data); +function validateTransactionRequest(data: typeof transactionSchema) { + return getInputError(validateTornadoTransaction, data); } -export { validateWithdrawRequest }; +export { validateTransactionRequest }; diff --git a/src/modules/queue/queue.module.ts b/src/modules/queue/queue.module.ts index ecfcc8b..85cdb0f 100644 --- a/src/modules/queue/queue.module.ts +++ b/src/modules/queue/queue.module.ts @@ -3,13 +3,13 @@ import { Module } from '@nestjs/common'; import { GasPriceService, ProviderService } from '@/services'; -import { WithdrawalProcessor } from './withdrawal.processor'; +import { TransactionProcessor } from './transaction.processor'; import bullConfig from '@/config/bull.config'; @Module({ imports: [BullModule.registerQueue(bullConfig())], - providers: [GasPriceService, ProviderService, WithdrawalProcessor], + providers: [GasPriceService, ProviderService, TransactionProcessor], exports: [BullModule], }) export class QueueModule {} diff --git a/src/modules/queue/withdrawal.processor.ts b/src/modules/queue/transaction.processor.ts similarity index 91% rename from src/modules/queue/withdrawal.processor.ts rename to src/modules/queue/transaction.processor.ts index 7d0e741..5605304 100644 --- a/src/modules/queue/withdrawal.processor.ts +++ b/src/modules/queue/transaction.processor.ts @@ -33,7 +33,7 @@ export type ArgsProof = { extDataHash: string; }; -export interface Withdrawal { +export interface Transaction { extData: ExtData; args: ArgsProof; amount: string; @@ -43,21 +43,21 @@ export interface Withdrawal { } @Injectable() -@Processor('withdrawal') -export class WithdrawalProcessor extends BaseProcessor { +@Processor('transaction') +export class TransactionProcessor extends BaseProcessor { constructor( - @InjectQueue('withdrawal') public withdrawalQueue: Queue, + @InjectQueue('transaction') public transactionQueue: Queue, private gasPriceService: GasPriceService, private providerService: ProviderService, private configService: ConfigService, ) { super(); - this.queueName = 'withdrawal'; - this.queue = withdrawalQueue; + this.queueName = 'transaction'; + this.queue = transactionQueue; } @Process() - async processWithdrawals(job: Job) { + async processTransactions(job: Job) { try { await job.isActive(); @@ -70,7 +70,7 @@ export class WithdrawalProcessor extends BaseProcessor { } } - async submitTx(job: Job) { + async submitTx(job: Job) { try { const txManager = new TxManager(txMangerConfig());