aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-06-30 14:59:30 -0400
committerAdam Soltys <[email protected]>2021-06-30 14:59:30 -0400
commit9e6091525bfa1e068fa4592b48acd8fa9d8a7fc5 (patch)
treee7ddcfddd22839f797b690ffc841af2737e7d72e
parent3ff26389ca9854d7d34ed28d3f034b2d32938872 (diff)
downloadcoinos-server-9e6091525bfa1e068fa4592b48acd8fa9d8a7fc5.tar.gz
coinos-server-9e6091525bfa1e068fa4592b48acd8fa9d8a7fc5.zip
handle address failure
-rw-r--r--routes/payments.js2
-rw-r--r--routes/users.js23
2 files changed, 17 insertions, 8 deletions
diff --git a/routes/payments.js b/routes/payments.js
index 86c0dd15..fe8092a9 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -144,7 +144,7 @@ ah(async () => {
const parts = hdkeypath.split("/");
app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1));
} catch(e) {
- console.log("Problem getting liquid address", e.message);
+ l.warn("Problem getting liquid address index", e.message);
}
}, 50);
}
diff --git a/routes/users.js b/routes/users.js
index 09ba5d43..25a737ce 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -160,7 +160,8 @@ app.post(
return res.status(500).send("Username taken");
} else {
sockets[username] = sockets[user.username];
- if (user.username !== username) l.info("changing username", user.username, username);
+ if (user.username !== username)
+ l.info("changing username", user.username, username);
user.username = username;
token = jwt.sign({ username }, config.jwt);
@@ -335,10 +336,7 @@ app.post(
(user.password &&
!(await bcrypt.compare(req.body.password, user.password)))
) {
- l.warn(
- "invalid username or password attempt",
- req.body.username
- );
+ l.warn("invalid username or password attempt", req.body.username);
return res.status(401).end();
}
@@ -438,11 +436,22 @@ app.get(
: config.liquid.network
];
type = "p2sh";
-
+
// async request to node to bump its internal index but don't use result
- lq.getNewAddress().catch(console.error);
+ lq.getNewAddress().catch((e) => l.warn("Problem bumping liquid address index", e.message))
i = parseInt(app.get("lqAddressIndex"));
+
+ if (!i) {
+ const { hdkeypath } = await lq.getAddressInfo(
+ await lq.getNewAddress()
+ );
+ const parts = hdkeypath.split("/");
+ i = parts[parts.length - 1].slice(0, -1);
+ }
+
+ if (!i) throw new Error("Problem generating address");
+
hd = fromBase58(config.liquid.masterkey, n).derivePath(`m/0'/0'/${i}'`);
app.set("lqAddressIndex", i + 1);
} else {