aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-20 11:40:10 -0800
committerAdam Soltys <[email protected]>2023-01-20 11:40:10 -0800
commit5dd47b9b2cb5a9359c57079205da68a675e10b45 (patch)
tree48f5065cbd9781342c4ed52300b1d68c2eb7f0e7 /routes
parent5264f702a2217fe8815cb5275aca14a672f6d4bb (diff)
downloadcoinos-server-5dd47b9b2cb5a9359c57079205da68a675e10b45.tar.gz
coinos-server-5dd47b9b2cb5a9359c57079205da68a675e10b45.zip
endpoint renaming
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.js4
-rw-r--r--routes/payments.js32
2 files changed, 26 insertions, 10 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index 62106f3a..8fbb25c1 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -4,6 +4,7 @@ import { emit } from "$lib/sockets";
import { db, g, s } from "$lib/db";
import { bip21, fail } from "$lib/utils";
import { types } from "$lib/payments";
+import { v4 } from "uuid";
import bc from "$lib/bitcoin";
import ln from "$lib/ln";
@@ -33,6 +34,7 @@ export default {
if (amount < 0) fail("invalid amount");
let hash, text;
+ console.log("TYPE", type)
if (type === types.lightning) {
let amt = amount ? `${amount + tip}sat` : "any";
let r = await ln.invoice(amt, new Date(), "", 3600);
@@ -42,6 +44,8 @@ export default {
} else if (type === types.bitcoin) {
hash = await bc.getNewAddress();
text = bip21(hash, invoice);
+ } else if (type === types.internal) {
+ hash = v4();
} else {
fail("unrecognized type");
}
diff --git a/routes/payments.js b/routes/payments.js
index d044f1e8..b92a6f81 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -18,16 +18,14 @@ export default {
let { amount, hash, name, memo, tip } = body;
await requirePin({ body, user });
- let invoice, recipient;
-
- let p = await debit(user, amount, memo, recipient);
+ let p = await debit(hash, amount, memo, user);
if (hash) {
await credit(hash, amount, memo, user.id);
} else {
let pot = name || v4();
await db.incrBy(`pot:${pot}`, amount);
- await db.lPush(`pot:${pot}:payments`, p.hash);
+ await db.lPush(`pot:${pot}:payments`, p.id);
l("funded pot", pot);
}
@@ -43,8 +41,13 @@ export default {
// if (end) where.createdAt[Op.lte] = new Date(parseInt(end));
let payments = (await db.lRange(`${id}:payments`, 0, -1)) || [];
- payments = await Promise.all(payments.map(hash => g(`payment:${hash}`)));
- payments = payments.filter(p => p);
+ payments = await Promise.all(
+ payments.map(async id => {
+ let p = await g(`payment:${id}`);
+ if (p.type === types.internal) p.with = await g(`user:${p.ref}`);
+ return p;
+ })
+ );
res.send({ payments, total: payments.length });
},
@@ -52,7 +55,7 @@ export default {
res.send(await g(`payment:${hash}`));
},
- async query({ body: { payreq } }, res) {
+ async parse({ body: { payreq } }, res) {
let hour = 1000 * 60 * 60;
let { last } = store.nodes;
let { nodes } = store;
@@ -61,11 +64,14 @@ export default {
store.nodes = nodes;
let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14));
- let { msatoshi, payee } = await ln.decodepay(payreq);
+ let decoded = await ln.decodepay(payreq);
+ let { msatoshi, payee, routes } = decoded;
let node = nodes.find(n => n.nodeid === payee);
let alias = node ? node.alias : payee.substr(0, 12);
+ let r = await ln.getroute(payee, msatoshi, 5);
+ console.log(routes, r);
- res.send({ alias, amount: Math.round(msatoshi / 1000) });
+ res.send({ alias, amount: Math.round(msatoshi / 1000), routes });
},
async pot({ params: { name } }, res) {
@@ -108,7 +114,13 @@ export default {
if (confirmations > 0) {
await confirm(address, txid, vout);
} else {
- await credit(address, sats(amount), "", `${txid}:${vout}`, types.bitcoin);
+ await credit(
+ address,
+ sats(amount),
+ "",
+ `${txid}:${vout}`,
+ types.bitcoin
+ );
}
}
}