aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-03-18 00:27:09 -0700
committerAdam Soltys <[email protected]>2023-03-18 00:27:09 -0700
commitbdd9a349f9fcbc5b105e654701b8e24c639bdb18 (patch)
treec52e200e40566cd7a6ff8c8fa55a796e0d6a0c18
parentee9e8c1169dade53aab0f77a78d5c0c006373622 (diff)
downloadcoinos-server-bdd9a349f9fcbc5b105e654701b8e24c639bdb18.tar.gz
coinos-server-bdd9a349f9fcbc5b105e654701b8e24c639bdb18.zip
fix pins
-rw-r--r--lib/payments.js2
-rw-r--r--routes/payments.js43
-rw-r--r--routes/users.js9
3 files changed, 27 insertions, 27 deletions
diff --git a/lib/payments.js b/lib/payments.js
index 2c62a3b7..b1e57d9c 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -162,7 +162,7 @@ export let confirm = async (address, txid, vout) => {
p.confirmed = true;
emit(p.uid, "payment", p);
-
+
l("confirming", txid, p.uid);
await db
diff --git a/routes/payments.js b/routes/payments.js
index b8999f55..b6e5fc06 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -15,12 +15,12 @@ import ln from "$lib/ln";
let seen = [];
let catchUp = async () => {
let txns = await bc.listTransactions("*", 50);
- txns = txns.filter(tx => tx.category === "receive" && tx.confirmations > 0);
+ txns = txns.filter((tx) => tx.category === "receive" && tx.confirmations > 0);
for (let { txid } of txns) {
try {
if (seen.includes(txid)) continue;
await got.post(`http://localhost:${process.env.PORT || 3119}/bitcoin`, {
- json: { txid, wallet: config.bitcoin.wallet }
+ json: { txid, wallet: config.bitcoin.wallet },
});
seen.push(txid);
@@ -53,7 +53,7 @@ export default {
await got
.post(`${config.classic}/admin/credit`, {
json: { username, amount, source },
- headers: { authorization: `Bearer ${config.admin}` }
+ headers: { authorization: `Bearer ${config.admin}` },
})
.json();
} else if (payreq) {
@@ -123,7 +123,7 @@ export default {
let payments = (await db.lRange(`${id}:payments`, 0, -1)) || [];
payments = (
await Promise.all(
- payments.map(async id => {
+ payments.map(async (id) => {
let p = await g(`payment:${id}`);
if (p.created < start || p.created > end) return;
if (p.type === types.internal) p.with = await g(`user:${p.ref}`);
@@ -131,7 +131,7 @@ export default {
})
)
)
- .filter(p => p)
+ .filter((p) => p)
.sort((a, b) => b.created - a.created);
let total = payments.length;
@@ -158,7 +158,7 @@ export default {
let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14));
let decoded = await ln.decodepay(payreq);
let { msatoshi, payee } = decoded;
- let node = nodes.find(n => n.nodeid === payee);
+ let node = nodes.find((n) => n.nodeid === payee);
let alias = node ? node.alias : payee.substr(0, 12);
res.send({ alias, amount: Math.round(msatoshi / 1000) });
@@ -168,13 +168,13 @@ export default {
let amount = await g(`pot:${name}`);
if (!amount) return bail(res, "pot not found");
let payments = (await db.lRange(`pot:${name}:payments`, 0, -1)) || [];
- payments = await Promise.all(payments.map(hash => g(`payment:${hash}`)));
+ payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`)));
await Promise.all(
- payments.map(async p => (p.user = await g(`user:${p.uid}`)))
+ payments.map(async (p) => (p.user = await g(`user:${p.uid}`)))
);
- payments = payments.filter(p => p);
+ payments = payments.filter((p) => p);
res.send({ amount, payments });
},
@@ -182,16 +182,13 @@ export default {
amount = parseInt(amount);
await t(`pot:${name}`, async (balance, db) => {
if (balance < amount) fail("Insufficient funds");
- await db
- .multi()
- .decrBy(`pot:${name}`, amount)
- .exec();
+ await db.multi().decrBy(`pot:${name}`, amount).exec();
});
let hash = v4();
await s(`invoice:${hash}`, {
uid: user.id,
- received: 0
+ received: 0,
});
let payment = await credit(hash, amount, "", name, types.pot);
@@ -251,7 +248,7 @@ export default {
let tx = await bc.fundRawTransaction(raw, {
feeRate,
subtractFeeFromOutputs,
- replaceable
+ replaceable,
});
let fee = sats(tx.fee);
@@ -294,7 +291,7 @@ export default {
for (let {
scriptPubKey: { address },
- value
+ value,
} of tx.vout) {
total += sats(value);
if (
@@ -329,13 +326,13 @@ export default {
"card[number]": number,
"card[exp_month]": month,
"card[exp_year]": year,
- "card[cvc]": cvc
+ "card[cvc]": cvc,
};
let { id: source } = await got
.post(`${stripe}/tokens`, {
form,
- username
+ username,
})
.json();
@@ -344,13 +341,13 @@ export default {
amount,
currency,
source,
- description: "starter coupon"
+ description: "starter coupon",
};
let r = await got
.post(`${stripe}/charges`, {
form,
- username
+ username,
})
.json();
@@ -360,7 +357,7 @@ export default {
let memo = "stripe";
await s(`invoice:${hash}`, {
uid: user.id,
- received: 0
+ received: 0,
});
amount = sats(amount / store.rates[currency]);
let uid = await g("user:coinos");
@@ -380,7 +377,7 @@ export default {
"estimatesmartfee",
"echo",
"getblockchaininfo",
- "getnetworkinfo"
+ "getnetworkinfo",
];
if (!whitelist.includes(method)) fail("unsupported method");
@@ -422,5 +419,5 @@ export default {
} catch (e) {
bail(res, e.message);
}
- }
+ },
};
diff --git a/routes/users.js b/routes/users.js
index aa0ffdcc..9ac668f4 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -418,9 +418,12 @@ export default {
},
async lower(req, res) {
- for await (let k of db.scanIterator({ MATCH: "payment:*" })) {
- let p = await g(k);
- if (p.ref && p.ref.startsWith("2dad97")) console.log(k, p);
+ for await (let k of db.scanIterator({ MATCH: "user:*" })) {
+ let u = await g(k);
+ if (u.pin && !u.haspin) {
+ u.haspin = true;
+ s(k, u);
+ }
}
res.send("ok");