diff options
| author | Adam Soltys <[email protected]> | 2023-03-01 13:50:47 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-01 13:50:52 -0800 |
| commit | 5b9f051af683e885cc52d0cfeba1618b670785b0 (patch) | |
| tree | 12b82292d7a63d7d24132017780d66652b65636b | |
| parent | 62f514de9f0e8f4d935246aa4081b9c82e0f5b0a (diff) | |
| download | coinos-server-5b9f051af683e885cc52d0cfeba1618b670785b0.tar.gz coinos-server-5b9f051af683e885cc52d0cfeba1618b670785b0.zip | |
proxy endpoint
| -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); + } } }; |
