diff options
| -rw-r--r-- | lib/buildtx.js | 6 | ||||
| -rw-r--r-- | routes/bitcoin/send.js | 2 | ||||
| -rw-r--r-- | routes/users.js | 22 |
3 files changed, 23 insertions, 7 deletions
diff --git a/lib/buildtx.js b/lib/buildtx.js index 351f8081..0da8c456 100644 --- a/lib/buildtx.js +++ b/lib/buildtx.js @@ -35,11 +35,12 @@ module.exports = async ({ address, amount, feeRate, user }) => { } ]; + debugger let { inputs, outputs, fee } = coinselect(utxos, targets, feeRate); if (!inputs || !outputs) { - l.info("utxos", amount, feeRate, utxos, inputs, outputs); - throw new Error("Failed to create transaction"); + l.info("utxos", amount, feeRate, utxos.map(u => u.value)); + throw new Error("Couldn't find inputs for transaction, check your balance/fee"); } let psbt = new bitcoin.Psbt({ network }); @@ -71,6 +72,5 @@ module.exports = async ({ address, amount, feeRate, user }) => { feeRate = Math.round(feeRate * 1000); psbt = psbt.toBase64(); - l.info("returning", { tx: psbt, feeRate }); return { tx: psbt, feeRate }; }; diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index ddf07f3c..2d539d5a 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -53,7 +53,7 @@ module.exports = ah(async (req, res) => { await account.save({ transaction }); params = { - amount: -total, + amount: -amount, fee, memo, account_id: account.id, diff --git a/routes/users.js b/routes/users.js index 36184ab4..ececd37b 100644 --- a/routes/users.js +++ b/routes/users.js @@ -369,10 +369,14 @@ app.post( const { id } = req.body; try { - const account = await db.Account.update(req.body, { + await db.Account.update(req.body, { where: { id, user_id: user.id }, }); + const account = await db.Account.findOne({ + where: { id }, + }); + emit(user.username, "account", account); res.end(); } catch (e) { @@ -410,9 +414,9 @@ app.post( user.payments = payments; user.account = account; - console.log(user.account.id); - + emit(user.username, "account", account.get({ plain: true })); emit(user.username, "user", user); + res.end(); } catch (e) { l.error(e.message); @@ -525,3 +529,15 @@ app.post( }); }) ); + +app.post( + "/password", + auth, + ah(async function (req, res) { + const { user } = req; + const { password } = req.body; + + if (!user.password) return res.send(true); + res.send(await bcrypt.compare(password, user.password)); + }) +); |
