diff options
| -rw-r--r-- | routes/payments.js | 2 | ||||
| -rw-r--r-- | routes/users.js | 23 |
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 { |
