aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-05-26 12:29:03 -0700
committerAdam Soltys <[email protected]>2020-05-26 12:29:03 -0700
commit31ed2a6c954da2e18a8e1d0e0156fe413365ac87 (patch)
tree62514ae77df07687d60fb7784a893b4487880ab9
parent7ea2b4569b5e197881593131c8c519a6dc12b958 (diff)
downloadcoinos-server-31ed2a6c954da2e18a8e1d0e0156fe413365ac87.tar.gz
coinos-server-31ed2a6c954da2e18a8e1d0e0156fe413365ac87.zip
address sweep wip
-rw-r--r--lib/sockets.js2
-rw-r--r--routes/bitcoin/address.js20
-rw-r--r--routes/payments.js1
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");