-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (25 loc) · 778 Bytes
/
index.js
File metadata and controls
33 lines (25 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fastify from "fastify";
import bpo from "bpo";
let app = fastify();
app.post("/proxy", async ({ body: { method, params } }, res) => {
try {
let whitelist = [
"echo",
"estimatesmartfee",
"getblock",
"getblockhash",
"getblockchaininfo",
"getnetworkinfo",
];
if (!whitelist.includes(method)) throw new Error("unsupported method");
if (method === "estimatesmartfee" || method === "getblockhash")
params[0] = parseInt(params[0]);
if (method === "getblock") params[1] = parseInt(params[1]);
res.send(await bpo({})[method](...params));
} catch (e) {
res.code(500).send(e.message);
}
});
let host = process.env.HOST || "0.0.0.0";
let port = process.env.PORT || 8080;
app.listen({ host, port });