fix: transfer

This commit is contained in:
Danil Kovtonyuk 2021-09-13 20:38:28 +10:00 committed by 0xZick
parent 1e08f78316
commit 886205ca55
11 changed files with 248 additions and 131 deletions

View File

@ -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",

View File

@ -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"
},
{

View File

@ -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<string> }
): Promise<ContractTransaction>;
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<BigNumber>;
calculateExternalAmount(
MAX_FEE(overrides?: CallOverrides): Promise<BigNumber>;
calculatePublicAmount(
_extAmount: BigNumberish,
_fee: BigNumberish,
overrides?: CallOverrides
): Promise<BigNumber>;
@ -332,6 +354,11 @@ export class TornadoPool extends BaseContract {
currentRoot(overrides?: CallOverrides): Promise<string>;
initialize(
_currentRoot: BytesLike,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<ContractTransaction>;
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<BigNumber>;
calculateExternalAmount(
MAX_FEE(overrides?: CallOverrides): Promise<BigNumber>;
calculatePublicAmount(
_extAmount: BigNumberish,
_fee: BigNumberish,
overrides?: CallOverrides
): Promise<BigNumber>;
@ -420,6 +451,11 @@ export class TornadoPool extends BaseContract {
currentRoot(overrides?: CallOverrides): Promise<string>;
initialize(
_currentRoot: BytesLike,
overrides?: CallOverrides
): Promise<void>;
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<BigNumber>;
calculateExternalAmount(
MAX_FEE(overrides?: CallOverrides): Promise<BigNumber>;
calculatePublicAmount(
_extAmount: BigNumberish,
_fee: BigNumberish,
overrides?: CallOverrides
): Promise<BigNumber>;
@ -537,6 +577,11 @@ export class TornadoPool extends BaseContract {
currentRoot(overrides?: CallOverrides): Promise<BigNumber>;
initialize(
_currentRoot: BytesLike,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<BigNumber>;
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<PopulatedTransaction>;
calculateExternalAmount(
MAX_FEE(overrides?: CallOverrides): Promise<PopulatedTransaction>;
calculatePublicAmount(
_extAmount: BigNumberish,
_fee: BigNumberish,
overrides?: CallOverrides
): Promise<PopulatedTransaction>;
@ -631,6 +680,11 @@ export class TornadoPool extends BaseContract {
currentRoot(overrides?: CallOverrides): Promise<PopulatedTransaction>;
initialize(
_currentRoot: BytesLike,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<PopulatedTransaction>;
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

View File

@ -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",
},
{

View File

@ -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,

View File

@ -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',
};

View File

@ -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));
}
}

View File

@ -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<Status> {
@ -31,14 +31,14 @@ class ApiService {
return `This is <a href=https://tornado.cash>tornado.cash</a> Relayer service. Check the <a href=/status>/status</a> for settings`;
}
async withdrawal(data: any): Promise<string> {
const job = await this.withdrawalQueue.add(data);
async transaction(data: any): Promise<string> {
const job = await this.transactionQueue.add(data);
return String(job.id);
}
async getJob(id: string): Promise<Job | null> {
return await this.withdrawalQueue.getJob(id);
return await this.transactionQueue.getJob(id);
}
private async healthCheck(): Promise<Health> {

View File

@ -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 };

View File

@ -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 {}

View File

@ -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<Withdrawal> {
@Processor('transaction')
export class TransactionProcessor extends BaseProcessor<Transaction> {
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<Withdrawal>) {
async processTransactions(job: Job<Transaction>) {
try {
await job.isActive();
@ -70,7 +70,7 @@ export class WithdrawalProcessor extends BaseProcessor<Withdrawal> {
}
}
async submitTx(job: Job<Withdrawal>) {
async submitTx(job: Job<Transaction>) {
try {
const txManager = new TxManager(txMangerConfig());