diff options
| author | Adam Soltys <[email protected]> | 2023-01-20 11:40:10 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-20 11:40:10 -0800 |
| commit | 5dd47b9b2cb5a9359c57079205da68a675e10b45 (patch) | |
| tree | 48f5065cbd9781342c4ed52300b1d68c2eb7f0e7 /lib | |
| parent | 5264f702a2217fe8815cb5275aca14a672f6d4bb (diff) | |
| download | coinos-server-5dd47b9b2cb5a9359c57079205da68a675e10b45.tar.gz coinos-server-5dd47b9b2cb5a9359c57079205da68a675e10b45.zip | |
endpoint renaming
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/payments.js b/lib/payments.js index e12f7858..af08cb84 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -16,15 +16,20 @@ export const types = { }; export let debit = async ( - user, + hash, amount, memo, - to, + user, type = types.internal, id = v4() ) => { + console.log("HASH", hash) + let ref; + let invoice = await g(`invoice:${hash}`); + if (invoice) ref = invoice.uid; + console.log("REF", ref) + let { id: uid, currency, username } = user; - to = to && to.id; amount = parseInt(amount); @@ -46,22 +51,20 @@ export let debit = async ( rate: store.rates[currency], currency, type, - to, + ref, created: Date.now() }; - if (!to) delete p.to; - - await s(`payment:${hash}`, p); - await db.lPush(`${uid}:payments`, hash); + await s(`payment:${id}`, p); + await db.lPush(`${uid}:payments`, id); - l("sent internal", user.username, amount); + l("sent", type, user.username, amount); emit(user.id, "payment", p); return p; }; -export let credit = async (hash, amount, memo, from, type = "internal") => { +export let credit = async (hash, amount, memo, ref, type = types.internal) => { amount = parseInt(amount); let invoice = await g(`invoice:${hash}`); if (!invoice) return; @@ -77,7 +80,7 @@ export let credit = async (hash, amount, memo, from, type = "internal") => { rate: store.rates[currency], currency, memo, - from, + ref, type, confirmed: true, created: Date.now() @@ -93,7 +96,7 @@ export let credit = async (hash, amount, memo, from, type = "internal") => { let balance = "balance"; if (type === types.bitcoin) { - let [txid, vout] = from.split(":").slice(-2); + let [txid, vout] = ref.split(":").slice(-2); p.id = `${txid}:${vout}`; p.confirmed = false; balance = "pending"; @@ -109,7 +112,7 @@ export let credit = async (hash, amount, memo, from, type = "internal") => { .incrBy(`${balance}:${uid}`, amount) .exec(); - l("received internal", username, amount); + l("received", type, username, amount); emit(uid, "payment", p); notify(user, `Received ${amount} sats`); callWebhook(invoice, p); |
