aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-08-11 11:48:49 -0700
committerAdam Soltys <[email protected]>2020-08-11 11:48:49 -0700
commit10bfc37a656e9862051a6a58ea2acdc561092f6b (patch)
tree77018a5bc2b3d0b75802f2e34446e489ad08aa5c
parent3980fec05509a060ac41f98b4dd126a13e4bc9cd (diff)
downloadcoinos-server-10bfc37a656e9862051a6a58ea2acdc561092f6b.tar.gz
coinos-server-10bfc37a656e9862051a6a58ea2acdc561092f6b.zip
check password api
-rw-r--r--lib/buildtx.js6
-rw-r--r--routes/bitcoin/send.js2
-rw-r--r--routes/users.js22
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));
+ })
+);