aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-23 23:08:09 -0800
committerAdam Soltys <[email protected]>2023-11-23 23:34:35 -0800
commit13f3c21b9ddf9884f190a6fcf7acf50440c82547 (patch)
treed29a3d8c91b9f5df5e38990800a3259732dc557b /routes
parent04a941b76b916384a3215502d362f4f3b51074a5 (diff)
downloadcoinos-server-13f3c21b9ddf9884f190a6fcf7acf50440c82547.tar.gz
coinos-server-13f3c21b9ddf9884f190a6fcf7acf50440c82547.zip
use payment ids
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.js6
-rw-r--r--routes/shopify.js1
-rw-r--r--routes/users.js87
3 files changed, 6 insertions, 88 deletions
diff --git a/routes/payments.js b/routes/payments.js
index 1a1dfaa9..7cda38d7 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -221,6 +221,7 @@ export default {
async get({ params: { hash } }, res) {
let p = await g(`payment:${hash}`);
+ if (typeof p === "string") p = await g(`payment:${p}`);
if (p.type === types.internal) p.with = await g(`user:${p.ref}`);
res.send(p);
},
@@ -316,6 +317,8 @@ export default {
for (let { address, amount, category, vout } of details) {
if (category !== "receive") continue;
let p = await g(`payment:${txid}:${vout}`);
+ if (typeof p === "string") p = await g(`payment:${p}`);
+
if (!p) {
await credit(
address,
@@ -331,6 +334,7 @@ export default {
}
res.send({});
} catch (e) {
+ console.log(e);
warn(`problem processing ${txid}`);
bail(res, e.message);
}
@@ -527,7 +531,7 @@ export default {
let u = await g(k);
let id = k.split(":")[1];
- if (typeof u === "String") {
+ if (typeof u === "string") {
id = u;
u = await g(`user:${u}`);
}
diff --git a/routes/shopify.js b/routes/shopify.js
index aaecbed0..5d972372 100644
--- a/routes/shopify.js
+++ b/routes/shopify.js
@@ -14,6 +14,7 @@ let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
export default async ({ body: { hash }, params: { id } }, res) => {
let p = await g(`payment:${hash}`);
+ if (typeof p === "string") p = await g(`payment:${p}`);
let user = await g(`user:${p.uid}`);
try {
diff --git a/routes/users.js b/routes/users.js
index 67428abc..75bff8b5 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -273,93 +273,6 @@ export default {
let uid = await g(`user:${username}`);
let user = await getUser(username);
- if (classic && !(user && user.migrated)) {
- uid = user ? user.id : v4();
-
- try {
- let { token } = await got
- .post(`${classic}/login`, { json: { username, password } })
- .json();
-
- if (!token) fail();
-
- user = await got(`${classic}/admin/migrate/${username}?zero=true`, {
- headers: { authorization: `Bearer ${config.admin}` },
- }).json();
-
- let { balance } = user;
- if (!user) fail();
-
- uid = user.uuid;
-
- user = {
- ...pick(user, fields),
- id: uid,
- about: user.address,
- migrated: true,
- haspin: !!user.pin,
- };
-
- await s(`user:${username}`, uid);
- await s(`user:${uid}`, user);
- await s(`balance:${uid}`, balance);
-
- let payments = await got(`${classic}/payments`, {
- headers: { authorization: `Bearer ${token}` },
- }).json();
-
- for (let p of payments) {
- let n = pick(p, [
- "amount",
- "fee",
- "confirmed",
- "rate",
- "currency",
- "preimage",
- ]);
- n.id = v4();
- n.created = parseISO(p.createdAt).getTime();
- n.type = p.network;
- if (!["bitcoin", "lightning"].includes(n.type))
- n.type = types.internal;
-
- if (n.type === types.internal) {
- if (!p.with) continue;
-
- let id = await g(`user:${p.with.username.toLowerCase()}`);
- let u = id && (await g(`user:${id}`));
-
- if (!u) {
- u = await got(
- `${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
- {
- headers: { authorization: `Bearer ${config.admin}` },
- }
- ).json();
-
- u = { id: u.uuid, about: u.address, ...pick(u, fields) };
- delete u.address;
-
- await s(`user:${p.with.username.toLowerCase()}`, u.id);
- await s(`user:${u.id}`, u);
-
- l("added missing user", u.username);
- }
-
- if (!(u && u.id)) continue;
- n.ref = u.id;
- }
-
- await s(`payment:${n.id}`, n);
- await db.lPush(`${uid}:payments`, n.id);
- }
-
- l("migrated user", user.username);
- } catch (e) {
- warn("classic login failed", username);
- }
- }
-
if (
!user ||
(user.password &&