diff options
| author | Adam Soltys <[email protected]> | 2024-09-13 23:18:20 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-13 23:18:20 -0700 |
| commit | fb9b4cc39df1608aa1a04286408f03e244f8f15f (patch) | |
| tree | 40fd6c4f4ba0a9b1237f90225be8f1c89cf4e49b /lib/payments.ts | |
| parent | 183315347b3ce6d4057abe05861c39f5d4b1aa46 (diff) | |
| download | coinos-server-fb9b4cc39df1608aa1a04286408f03e244f8f15f.tar.gz coinos-server-fb9b4cc39df1608aa1a04286408f03e244f8f15f.zip | |
add default account if missing
Diffstat (limited to 'lib/payments.ts')
| -rw-r--r-- | lib/payments.ts | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/payments.ts b/lib/payments.ts index 454c9753..3f5cd152 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -84,6 +84,7 @@ export let debit = async ({ let tip = parseInt(invoice?.tip) || null; if (tip < 0) fail("Invalid tip"); + console.log("AMT", amount); if (!amount || amount < 0) fail("Amount must be greater than zero"); let ourfee: any = [types.bitcoin, types.liquid, types.lightning].includes( @@ -366,7 +367,10 @@ export let sendOnchain = async (params) => { if (!hex) ({ hex } = await build(params)); let { tx, type } = await decode(hex); - let node = rpc({ ...config[type], wallet: account }); + let node = + account === user.id + ? rpc(config[type]) + : rpc({ ...config[type], wallet: account }); let { txid } = tx; try { @@ -426,7 +430,9 @@ export let sendOnchain = async (params) => { if (invoice?.account === account) fail("Cannot send to internal address"); - if ((await node.getAddressInfo(address)).ismine) change += sats(value); + if ((await node.getAddressInfo(address)).ismine) { + change += sats(value); + } } fee = totalIn - total; @@ -611,9 +617,20 @@ let getAddressType = async (a) => { } }; -export let build = async ({ account, amount, address, feeRate, subtract }) => { +export let build = async ({ + account, + amount, + address, + feeRate, + subtract, + user, +}) => { let type = await getAddressType(address); - let node = rpc({ ...config[type], wallet: account }); + let node = + account === user.id + ? rpc(config[type]) + : rpc({ ...config[type], wallet: account }); + amount = parseInt(amount); if (amount < 0) fail("invalid amount"); @@ -649,6 +666,7 @@ export let build = async ({ account, amount, address, feeRate, subtract }) => { fee = sats(tx.fee); } catch (e) { if (e.message.startsWith("Insufficient")) subtract = true; + else throw e; } let balance = await g(`balance:${account}`); |
