Skip to content

Commit

Permalink
accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
asoltys committed Sep 10, 2024
1 parent 9c77d45 commit bc94288
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions lib/migrate.ts
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions routes/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 7 additions & 10 deletions routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bc94288

Please sign in to comment.