diff options
| author | Adam Soltys <[email protected]> | 2023-03-07 23:30:55 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-07 23:30:55 -0800 |
| commit | 7fec7cc3e7c51a9892869732b5bfe65922ee7818 (patch) | |
| tree | 8295bc3616f3d954d46c8baf986c4152c3c4e008 | |
| parent | 40f3fb4912467030313f4666a733ec7e0c4c0c58 (diff) | |
| download | coinos-server-7fec7cc3e7c51a9892869732b5bfe65922ee7818.tar.gz coinos-server-7fec7cc3e7c51a9892869732b5bfe65922ee7818.zip | |
get payment rate from invoice
| -rw-r--r-- | lib/payments.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/payments.js b/lib/payments.js index aaf39210..ff6e9ba5 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -26,13 +26,16 @@ export let debit = async ( id = v4() ) => { let ref, tip; + let { id: uid, currency, username } = user; + + let rate = store.rates[currency]; + let invoice = await g(`invoice:${hash}`); if (invoice) { ref = invoice.uid; + if (Math.abs(invoice.rate / rate - 1) < 0.01) rate = invoice.rate; } - let { id: uid, currency, username } = user; - amount = parseInt(amount); if (!amount || amount < 0) fail("Amount must be greater than zero"); @@ -46,7 +49,15 @@ export let debit = async ( let covered = Math.min(credit, ourfee) || 0; ourfee -= covered; - l("debiting", user.username, balance, amount, fee, ourfee, amount + fee + ourfee); + l( + "debiting", + user.username, + balance, + amount, + fee, + ourfee, + amount + fee + ourfee + ); if (balance < amount + fee + ourfee) fail("Insufficient funds"); await db .multi() @@ -69,7 +80,7 @@ export let debit = async ( memo, uid, confirmed: true, - rate: store.rates[currency], + rate, currency, type, ref, @@ -96,11 +107,14 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { let { id: uid, currency, username } = user; + let rate = store.rates[currency]; + if (Math.abs(invoice.rate / rate - 1) < 0.01) rate = invoice.rate; + let p = { hash, amount, uid, - rate: store.rates[currency], + rate, currency, memo, ref, @@ -152,6 +166,7 @@ export let confirm = async (address, txid, vout) => { if (!p) return db.sAdd("missed", id); p.confirmed = true; + emit(p.uid, "payment", p); await db .multi() |
