diff options
| author | Adam Soltys <[email protected]> | 2025-05-06 22:14:10 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-05-06 22:14:10 -0700 |
| commit | c7b93725a08333516c89bdb64f4b4149f6b0da2b (patch) | |
| tree | 9fa5c65917cee672e2d63490aeb0d2a6349dbf88 /lib | |
| parent | 414f8faba5374bcbc06f695db77b304f771cab7a (diff) | |
| download | coinos-server-c7b93725a08333516c89bdb64f4b4149f6b0da2b.tar.gz coinos-server-c7b93725a08333516c89bdb64f4b4149f6b0da2b.zip | |
return subtract status
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.ts | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/payments.ts b/lib/payments.ts index b3581847..a0611c51 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -123,13 +123,13 @@ export const debit = async ({ ourfee = await db.debit( `balance:${aid || uid}`, - `credit:${creditType}:${aid ? 0 : uid}`, + `credit:${creditType}:${aid !== uid ? 0 : uid}`, amount || 0, tip || 0, fee || 0, ourfee || 0, ); - + if (ourfee.err) fail(ourfee.err); const id = v4(); @@ -698,10 +698,12 @@ export const build = async ({ if (aid && aid !== user.id) ourfee = 0; if (subtract || amount + fee + ourfee > balance) { - if (amount <= fee + ourfee + dust) + subtract = true; + if (amount <= fee + ourfee + dust) { fail( `insufficient funds ⚡️${balance} of ⚡️${amount + fee + ourfee + dust}`, ); + } outs = [{ [address]: btc(amount - ourfee) }]; raw = await node.createRawTransaction([], outs, 0, replaceable); @@ -731,7 +733,7 @@ export const build = async ({ inputs.push({ witnessUtxo, path }); } - return { feeRate, ourfee, fee, fees, hex: tx.hex, inputs }; + return { feeRate, ourfee, fee, fees, hex: tx.hex, inputs, subtract }; }; export const catchUp = async () => { |
