diff options
| author | Adam Soltys <[email protected]> | 2024-09-23 16:23:19 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-09-23 16:23:19 -0700 |
| commit | 12ad5c9abb74cbe35c5d07233fdd9a7b7f5c2b70 (patch) | |
| tree | 8e023771abd75a7b70e407c651aed3bcfe426ea3 /lib/payments.ts | |
| parent | 01e1686265def675445c0f74a4b92ec4ffd71492 (diff) | |
| download | coinos-server-12ad5c9abb74cbe35c5d07233fdd9a7b7f5c2b70.tar.gz coinos-server-12ad5c9abb74cbe35c5d07233fdd9a7b7f5c2b70.zip | |
reconcile on-chain balance
Diffstat (limited to 'lib/payments.ts')
| -rw-r--r-- | lib/payments.ts | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/payments.ts b/lib/payments.ts index e2b44ea9..4bec9a93 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -40,6 +40,7 @@ export let types = { fund: "fund", liquid: "liquid", ecash: "ecash", + reconcile: "reconcile", }; export let debit = async ({ @@ -140,8 +141,8 @@ export let debit = async ({ export let credit = async ({ hash, amount, - memo = undefined, - ref = undefined, + memo = "", + ref = "", type = types.internal, aid = undefined, }) => { @@ -369,9 +370,7 @@ export let sendOnchain = async (params) => { let { tx, type } = await decode(hex); let node = - aid === user.id - ? rpc(config[type]) - : rpc({ ...config[type], wallet: aid }); + aid === user.id ? rpc(config[type]) : rpc({ ...config[type], wallet: aid }); let { txid } = tx; try { @@ -428,8 +427,7 @@ export let sendOnchain = async (params) => { } of tx.vout) { total += sats(value); let invoice = await g(`invoice:${address}`); - if (invoice?.aid === aid) - fail("Cannot send to internal address"); + if (invoice?.aid === aid) fail("Cannot send to internal address"); if ((await node.getAddressInfo(address)).ismine) { change += sats(value); @@ -604,12 +602,18 @@ export let sendLightning = async ({ } }; -export let sendInternal = async ({ amount, invoice = undefined, recipient, sender }) => { - if (!invoice) invoice = await generate({ - invoice: { amount, type: "lightning" }, - user: recipient, - sender, - }); +export let sendInternal = async ({ + amount, + invoice = undefined, + recipient, + sender, +}) => { + if (!invoice) + invoice = await generate({ + invoice: { amount, type: "lightning" }, + user: recipient, + sender, + }); let { hash } = invoice; let memo; @@ -644,9 +648,7 @@ export let build = async ({ let type = await getAddressType(address); if (!aid) aid = user.id; let node = - aid === user.id - ? rpc(config[type]) - : rpc({ ...config[type], wallet: aid }); + aid === user.id ? rpc(config[type]) : rpc({ ...config[type], wallet: aid }); amount = parseInt(amount); if (amount < 0) fail("invalid amount"); |
