aboutsummaryrefslogtreecommitdiffstats
path: root/routes
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 /routes
parent9c77d45cfb56e79e97b70678e21b8d6a56ec6c78 (diff)
downloadcoinos-server-bc94288f562223ca3bd0dd969c68c6650adf6089.tar.gz
coinos-server-bc94288f562223ca3bd0dd969c68c6650adf6089.zip
accounts
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts7
-rw-r--r--routes/users.ts17
2 files changed, 11 insertions, 13 deletions
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);