diff options
| -rw-r--r-- | lib/sockets.js | 2 | ||||
| -rw-r--r-- | routes/bitcoin/address.js | 20 | ||||
| -rw-r--r-- | routes/payments.js | 1 |
3 files changed, 22 insertions, 1 deletions
diff --git a/lib/sockets.js b/lib/sockets.js index cc6da34c..e297703b 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -48,7 +48,7 @@ wss.on("connection", function (ws, req) { names[id] = username; ws.ok = true; - ws.send(JSON.stringify({ type: "networks", data: networks })); + ws.send(JSON.stringify({ type: "nodes", data: networks })); ws.send(JSON.stringify({ type: "rates", data: app.get("rates") })); ws.send(JSON.stringify({ type: "login", data: await getUser(username) })); l.info("socket open", username, id); diff --git a/routes/bitcoin/address.js b/routes/bitcoin/address.js new file mode 100644 index 00000000..3434f107 --- /dev/null +++ b/routes/bitcoin/address.js @@ -0,0 +1,20 @@ +const axios = require("axios"); +const api = "https://blockstream.info/api"; + +module.exports = async (req, res) => { + try { + let { address } = req.body; + let { + data: { + chain_stats: { funded_txo_sum: balance }, + }, + } = await axios.get(`${api}/address/${address}`); + + let utxos = []; + // let { data: utxos } = await axios.get(`${api}/address/${address}/utxo`); + res.send({ balance, utxos }); + } catch (e) { + l.error("error retrieving address info", e.message); + return res.status(500).send(e.message); + } +}; diff --git a/routes/payments.js b/routes/payments.js index ab35c9a0..cfeb8450 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -40,6 +40,7 @@ const { join } = require("path"); if (config.bitcoin) { bc = new BitcoinCore(config.bitcoin); + app.get("/bitcoin/address", auth, require("./bitcoin/address")); app.post("/bitcoin/fee", auth, require("./bitcoin/fee")); app.post("/bitcoin/send", auth, require("./bitcoin/send")); require("./bitcoin/receive"); |
