aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-10 10:17:27 -0700
committerAdam Soltys <[email protected]>2024-09-10 10:17:27 -0700
commitbc94288f562223ca3bd0dd969c68c6650adf6089 (patch)
treed10682f94837199c39973951dea5d6e365f1d70f
parent9c77d45cfb56e79e97b70678e21b8d6a56ec6c78 (diff)
downloadcoinos-server-bc94288f562223ca3bd0dd969c68c6650adf6089.tar.gz
coinos-server-bc94288f562223ca3bd0dd969c68c6650adf6089.zip
accounts
-rw-r--r--Dockerfile5
-rwxr-xr-xbun.lockbbin207855 -> 207855 bytes
-rw-r--r--lib/migrate.ts3
-rw-r--r--package.json2
-rw-r--r--routes/payments.ts7
-rw-r--r--routes/users.ts17
6 files changed, 14 insertions, 20 deletions
diff --git a/Dockerfile b/Dockerfile
index 1d50d360..6b9b6e82 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,10 +2,7 @@ FROM oven/bun
ARG NODE_ENV=production
-RUN apt update
-RUN apt install ffmpeg -y
-
-COPY . /home/bun/app
+COPY package.json /home/bun/app
RUN NODE_ENV=development bun i
diff --git a/bun.lockb b/bun.lockb
index ac190d6f..20e97e3d 100755
--- a/bun.lockb
+++ b/bun.lockb
Binary files differ
diff --git a/lib/migrate.ts b/lib/migrate.ts
index cee5e946..c6de972c 100644
--- a/lib/migrate.ts
+++ b/lib/migrate.ts
@@ -1,7 +1,6 @@
import { err, warn, l, line } from "$lib/logging";
import { types } from "$lib/payments";
-import { archive, arc2, db, g, ga, s } from "$lib/db";
-import { wait } from "$lib/utils";
+import { archive, db, g, ga, s } from "$lib/db";
let queued = {};
let migrating = {};
diff --git a/package.json b/package.json
index 97b64cc1..b4d5545e 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"dependencies": {
"@aws-sdk/client-ses": "^3.449.0",
"@cashu/cashu-ts": "github:cashubtc/cashu-ts#development",
- "@coinos/rpc": "^0.0.4",
+ "@coinos/rpc": "^0.0.5",
"@fastify/cors": "^8.3.0",
"@fastify/http-proxy": "^9.5.0",
"@fastify/multipart": "^8.0.0",
diff --git a/routes/payments.ts b/routes/payments.ts
index 34d7c073..dbf5a8fd 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -283,7 +283,8 @@ export default {
if (!p) {
let account;
- if ((await g(`${wallet}:balance`)) !== null) account = wallet;
+ let bal = await g(`balance:${wallet}`);
+ if (bal !== null) account = wallet;
await credit({
hash: address,
amount: sats(amount),
@@ -311,8 +312,8 @@ export default {
.multi()
.set(`invoice:${iid}`, JSON.stringify(invoice))
.set(`payment:${p.id}`, JSON.stringify(p))
- .decrBy(`pending:${p.uid}`, p.amount)
- .incrBy(`balance:${p.uid}`, p.amount)
+ .decrBy(`pending:${p.account || p.uid}`, p.amount)
+ .incrBy(`balance:${p.account || p.uid}`, p.amount)
.exec();
emit(p.uid, "payment", p);
diff --git a/routes/users.ts b/routes/users.ts
index f49ca212..a39bdbe3 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -13,8 +13,10 @@ import { types } from "$lib/payments";
import { bech32 } from "bech32";
import { mail, templates } from "$lib/mail";
import upload from "$lib/upload";
+import rpc from "@coinos/rpc";
-const { encode, decode, fromWords, toWords } = bech32;
+let bc = rpc(config.bitcoin);
+let { encode, decode, fromWords, toWords } = bech32;
export default {
upload,
@@ -567,15 +569,7 @@ export default {
async accounts(req, res) {
let { user } = req;
- let balance = await g(`balance:${user.id}`);
- let accounts: any = [
- {
- balance,
- type: "Cash",
- mint: "https://mint.coinos.io",
- },
- ];
-
+ let accounts = [];
for (let id of await db.lRange(`${user.id}:accounts`, 0, 1)) {
let account = await g(`account:${id}`);
account.balance = await g(`balance:${id}`);
@@ -612,8 +606,11 @@ export default {
let id = v4();
let account = { id, seed, type };
+ await bc.createWallet(id);
+
await s(`account:${id}`, account);
await s(`balance:${id}`, 0);
+ await s(`pending:${id}`, 0);
await db.lPush(`${user.id}:accounts`, id);
res.send(account);