From c6c3edff8b27b1ccdccb7d614241fd87872c4c59 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Thu, 14 May 2020 13:39:26 +0300 Subject: [PATCH] add bucket check endpoint --- scripts/relay.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/relay.js b/scripts/relay.js index 5f7eee7..a7fe840 100644 --- a/scripts/relay.js +++ b/scripts/relay.js @@ -5,7 +5,7 @@ const Account = require('./account.js'); const utils = require('./utils.js'); const fs = require('fs'); -const argv = parseArgs(process.argv.slice(2), {string: ["sender"], default: {"endpoint": "ws://127.0.0.1:8546"}}); +const argv = parseArgs(process.argv.slice(2), {string: ["sender", "bucket"], default: {"endpoint": "ws://127.0.0.1:8546"}}); const web3 = new Web3(argv["endpoint"]); const account = new Account(web3); @@ -72,6 +72,14 @@ async function redeemRequest(req, res) { } } +function bucketRequest(req, res) { + if (validateBucket(req.params.address)) { + res.status(200).json({"allowed": true}); + } else { + res.status(404).json({"allowed": false}); + } +} + function loadBucketList(path) { let file = fs.readFileSync(path, 'utf8'); allowedBuckets = file.split("\n").map((line) => line.toLowerCase().trim()); @@ -109,6 +117,7 @@ async function run() { app.use(express.json()); app.post('/redeem', redeemRequest); + app.get('/bucket/:address', bucketRequest); app.listen(port, () => console.log(`Relayer listening at http://localhost:${port}`)); }