aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils.js18
-rw-r--r--routes/events.js8
-rw-r--r--routes/users.js1
3 files changed, 17 insertions, 10 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 2854fefc..49f95a00 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,4 +1,5 @@
import store from "$lib/store";
+import redis from "$lib/redis";
import config from "$config";
import db from "$db";
import sequelize from "@sequelize/core";
@@ -7,9 +8,18 @@ import { payments as bcPayments, networks as bcNetworks } from "bitcoinjs-lib";
import { payments as lqPayments, networks as lqNetworks } from "liquidjs-lib";
import lnd from "$lib/lnd";
import ln from "$lib/ln";
+import { coinos } from "$lib/nostr";
const { Op } = sequelize;
+export const sleep = n => new Promise(r => setTimeout(r, n));
+export const wait = async (f, s = 300, n = 1000) => {
+ let i = 0;
+ while (!(await f()) && i < s) (await sleep(n)) && i++;
+ if (i >= s) throw new Error("timeout");
+ return f();
+};
+
export const requirePin = async ({ body, user }) => {
if (!user || (user.pin && user.pin !== body.pin))
throw new Error("Invalid pin");
@@ -47,6 +57,7 @@ export const getUser = async (username, transaction) => {
500
);
+ await wait(() => !!coinos, 100, 10);
coinos.subscribe(`${pubkey}:follows`, {
limit: 1,
kinds: [3],
@@ -193,10 +204,3 @@ export const derivePayRequest = async ({ amount, memo, tip }) => {
).bolt11;
};
-export const sleep = n => new Promise(r => setTimeout(r, n));
-export const wait = async (f, s = 300, n = 1000) => {
- let i = 0;
- while (!(await f()) && i < s) (await sleep(n)) && i++;
- if (i >= s) throw new Error("timeout");
- return f();
-};
diff --git a/routes/events.js b/routes/events.js
index 4dcc44f0..de6a253e 100644
--- a/routes/events.js
+++ b/routes/events.js
@@ -37,9 +37,11 @@ app.get("/nostr/:pubkey", async (req, res) => {
await redis.set(`user:${pubkey}`, JSON.stringify(user));
await wait(() => !store.fetching[pubkey], 100, 100);
- let events = (
- await redis.mGet((await redis.sMembers(pubkey)).map(k => "ev:" + k))
- ).map(JSON.parse);
+ let ids = await redis.sMembers(pubkey);
+
+ let events = ids.length ? (
+ await redis.mGet((id).map(k => "ev:" + k))
+ ).map(JSON.parse) : [];
res.send(events);
} catch (e) {
diff --git a/routes/users.js b/routes/users.js
index 4c6305b5..50d882ad 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -56,6 +56,7 @@ app.get("/me", auth, async (req, res) => {
500
);
+ await wait(() => !!coinos, 100, 10);
coinos.subscribe(`${pubkey}:follows`, {
limit: 1,
kinds: [3],