mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-05-02 14:26:06 -04:00
relay wip
This commit is contained in:
parent
6e05a678dd
commit
f3b1b7f96e
3 changed files with 46 additions and 1 deletions
44
relay/relay.js
Normal file
44
relay/relay.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
let bigInt = require('snarkjs/src/bigint');
|
||||
|
||||
require('dotenv').config();
|
||||
const { AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT } = process.env;
|
||||
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
const Web3 = require('web3');
|
||||
web3 = new Web3('http://localhost:8545', null, {transactionConfirmationBlocks: 1});
|
||||
contractJson = require('../build/contracts/Mixer.json');
|
||||
let netId = 42;
|
||||
mixer = new web3.eth.Contract(contractJson.abi, contractJson.networks[netId].address);
|
||||
|
||||
function getMinimumFee() {
|
||||
// todo calc acceptable fee
|
||||
return 1e16;
|
||||
}
|
||||
|
||||
app.post('/deposit', async (req, resp) => {
|
||||
let proof = req.body;
|
||||
if (!(proof.pi_a && proof.pi_b && proof.pi_c && proof.publicSignals)) { // check that it's kinda well formed
|
||||
resp.status(400).end();
|
||||
}
|
||||
|
||||
if (bigInt(proof.publicSignals[3]) < getMinimumFee()) {
|
||||
resp.status(403).send("Fee is too low");
|
||||
}
|
||||
|
||||
if (!utils.snarkVerify(proof)) {
|
||||
resp.status(403).send("Invalid snark proof");
|
||||
}
|
||||
|
||||
try {
|
||||
let receipt = await mixer.withdraw(proof.pi_a, proof.pi_b, proof.pi_b, proof.publicSignals);
|
||||
console.log(receipt);
|
||||
resp.send({transaction: receipt.transactionHash})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
resp.status(400).send("Transaction was reverted");
|
||||
}
|
||||
});
|
||||
app.listen(3000);
|
Loading…
Add table
Add a link
Reference in a new issue