2020-05-13 14:39:52 +00:00
|
|
|
const express = require('express');
|
|
|
|
const Web3 = require('web3');
|
|
|
|
const parseArgs = require('minimist');
|
|
|
|
const Account = require('./account.js');
|
|
|
|
const utils = require('./utils.js');
|
|
|
|
|
|
|
|
|
|
|
|
const argv = parseArgs(process.argv.slice(2), {string: ["sender"], default: {"endpoint": "ws://127.0.0.1:8546"}});
|
|
|
|
const web3 = new Web3(argv["endpoint"]);
|
|
|
|
const account = new Account(web3);
|
|
|
|
|
|
|
|
const BucketConfig = utils.loadJSON(`./dist/contracts/Bucket.json`);
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const port = 3000;
|
|
|
|
|
2020-05-14 08:13:36 +00:00
|
|
|
async function redeem(message, sig) {
|
2020-05-13 14:39:52 +00:00
|
|
|
const Bucket = utils.json2Contract(web3, BucketConfig);
|
|
|
|
Bucket.transactionConfirmationBlocks = 1;
|
|
|
|
Bucket.options.address = bucket;
|
2020-05-14 08:13:36 +00:00
|
|
|
let methodCall = Bucket.methods.redeem(message, sig);
|
2020-05-13 14:39:52 +00:00
|
|
|
return account.sendMethod(methodCall, Bucket.options.address);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function redeemRequest(req, res) {
|
2020-05-14 08:13:36 +00:00
|
|
|
let receipt = redeem(req.body.bucket, req.body.message, req.body.sig);
|
2020-05-13 14:39:52 +00:00
|
|
|
res.json({tx: receipt.transactionHash});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
await account.init(argv);
|
|
|
|
app.use(express.json());
|
|
|
|
app.post('/redeem', redeemRequest);
|
|
|
|
app.listen(port, () => console.log(`Relayer listening at http://localhost:${port}`));
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|