From 5cd7544a297fcfec8f57b142cc1f23096607a676 Mon Sep 17 00:00:00 2001 From: poma Date: Thu, 18 Jul 2019 21:20:58 +0300 Subject: [PATCH] move relay to a separate repo --- relay/relay.js | 56 -------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 relay/relay.js diff --git a/relay/relay.js b/relay/relay.js deleted file mode 100644 index f6da5bb..0000000 --- a/relay/relay.js +++ /dev/null @@ -1,56 +0,0 @@ -// This is still WiP -const bigInt = require('snarkjs/src/bigint') -const utils = require('../scripts/utils') - -const express = require('express') -const app = express() -app.use(express.json()) - -// todo get from config -const RPC_ENDPOINT = 'http://localhost:8545' -const NET_ID = 42 -// const PRIVATE_KEY = '' -const MAX_GAS = 1e6 - -const Web3 = require('web3') -const web3 = new Web3(RPC_ENDPOINT, null, { transactionConfirmationBlocks: 1 }) -const contractJson = require('../build/contracts/Mixer.json') -const mixer = new web3.eth.Contract(contractJson.abi, contractJson.networks[NET_ID].address) - -function getMinimumFee() { - // todo calc acceptable fee - return bigInt(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 { - const gas = await mixer.withdraw(proof.pi_a, proof.pi_b, proof.pi_b, proof.publicSignals).estimateGas() - if (gas > MAX_GAS) { - // something is wrong - } - const result = mixer.withdraw(proof.pi_a, proof.pi_b, proof.pi_b, proof.publicSignals).send() - result.once('transactionHash', function(hash){ - resp.send({ transaction: hash }) - }).on('error', function(e){ - console.log(e) - resp.status(400).send('Transaction was reverted') - }) - } catch (e) { - console.log(e) - resp.status(400).send('Transaction was reverted') - } -}) -app.listen(3000)