aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-02-10 09:57:00 -0500
committerAdam Soltys <[email protected]>2021-02-10 09:57:00 -0500
commit9d4e7bee7d884fba7da27df7180390bad9a80bdc (patch)
treea99e8e112558f527eef9b98914bb52f52b0c07ee
parente671baeb092ea6523027118bd1bba7bd85290823 (diff)
downloadcoinos-server-9d4e7bee7d884fba7da27df7180390bad9a80bdc.tar.gz
coinos-server-9d4e7bee7d884fba7da27df7180390bad9a80bdc.zip
amount from pay request should take precedence if provided
-rw-r--r--lib/send.js8
-rw-r--r--routes/liquid/send.js1
-rwxr-xr-xwatcher.sh1
3 files changed, 8 insertions, 2 deletions
diff --git a/lib/send.js b/lib/send.js
index 37cbdfdb..98fa4d2c 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -1,9 +1,10 @@
const bolt11 = require("bolt11");
+const { Op } = require("sequelize");
send = async (amount, memo, hash, user) => {
let payreq = bolt11.decode(hash);
- if (!amount) amount = payreq.satoshis;
+ if (!amount || payreq.satoshis > amount) amount = payreq.satoshis;
if (seen.includes(hash)) {
l.warn("attempted to pay a paid invoice", user.username);
@@ -17,7 +18,10 @@ send = async (amount, memo, hash, user) => {
where: {
user_id: user.id,
asset: config.liquid.btcasset,
- pubkey: null
+ pubkey: null,
+ balance: {
+ [Op.gte]: amount
+ },
},
lock: transaction.LOCK.UPDATE,
transaction
diff --git a/routes/liquid/send.js b/routes/liquid/send.js
index 04b90814..01b1a41d 100644
--- a/routes/liquid/send.js
+++ b/routes/liquid/send.js
@@ -81,6 +81,7 @@ module.exports = ah(async (req, res) => {
pubkey: null
},
lock: transaction.LOCK.UPDATE,
+ order: [['balance', 'DESC']],
transaction
});
diff --git a/watcher.sh b/watcher.sh
index 74451bf6..b900a50c 100755
--- a/watcher.sh
+++ b/watcher.sh
@@ -12,6 +12,7 @@ do
if "$low"; then
echo "Balance below threshold, shutting down"
yarn pm2 stop 0 > /dev/null
+ cd /root/mailgun && node index.js
exit
fi
sleep 10