diff options
| -rw-r--r-- | index.js | 2 | ||||
| -rw-r--r-- | routes/payments.js | 24 |
2 files changed, 26 insertions, 0 deletions
@@ -87,6 +87,8 @@ app.get("/requests", auth, requests.list); app.post("/requests", auth, requests.create); app.post("/requests/delete", auth, requests.destroy); +app.post("/proxy", payments.proxy); + let host = process.env.HOST || "0.0.0.0"; let port = process.env.PORT || 3119; diff --git a/routes/payments.js b/routes/payments.js index 38611d19..307e8ef6 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -348,5 +348,29 @@ export default { } else fail("Card payment failed"); res.send({ status }); + }, + + async proxy({ body: { method, params } }, res) { + try { + let whitelist = [ + "getblock", + "getblockhash", + "estimatesmartfee", + "echo", + "getblockchaininfo", + "getnetworkinfo" + ]; + + if (!whitelist.includes(method)) fail("unsupported method"); + + if (method === "estimatesmartfee" || method === "getblockhash") + params[0] = parseInt(params[0]); + + if (method === "getblock") params[1] = parseInt(params[1]); + + res.send(await bc[method](...params)); + } catch (e) { + bail(res, e.message); + } } }; |
