aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.js29
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);