aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-13 12:18:04 -0700
committerAdam Soltys <[email protected]>2024-09-13 12:18:04 -0700
commit183315347b3ce6d4057abe05861c39f5d4b1aa46 (patch)
treef8f585af47f620ace424b9418336bf8d840ea1fe
parentb00fee005fc69f79d300fa71a3619d97f4571c23 (diff)
downloadcoinos-server-183315347b3ce6d4057abe05861c39f5d4b1aa46.tar.gz
coinos-server-183315347b3ce6d4057abe05861c39f5d4b1aa46.zip
allow intra-account sends, write wallets to conf file
-rw-r--r--compose.yml.sample1
-rw-r--r--lib/payments.ts5
-rw-r--r--routes/users.ts5
3 files changed, 8 insertions, 3 deletions
diff --git a/compose.yml.sample b/compose.yml.sample
index 9b350f2c..c29d1654 100644
--- a/compose.yml.sample
+++ b/compose.yml.sample
@@ -18,6 +18,7 @@ services:
- .aws/:/root/.aws
- ./:/home/bun/app
- ./logs:/logs
+ - ./data/bitcoin/bitcoin.conf:/bitcoin.conf
restart: always
bc:
image: asoltys/bitcoin
diff --git a/lib/payments.ts b/lib/payments.ts
index 5f8f3e0a..454c9753 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -422,7 +422,8 @@ export let sendOnchain = async (params) => {
value,
} of tx.vout) {
total += sats(value);
- if (await g(`invoice:${address}`))
+ let invoice = await g(`invoice:${address}`);
+ if (invoice?.account === account)
fail("Cannot send to internal address");
if ((await node.getAddressInfo(address)).ismine) change += sats(value);
@@ -503,7 +504,7 @@ export let sendLightning = async ({
let invoice = await getInvoice(hash);
if (invoice) {
- if (invoice.uid === user.id) fail("Cannot send to self");
+ if (invoice.account === user.id) fail("Cannot send to self");
hash = pr;
} else {
let r;
diff --git a/routes/users.ts b/routes/users.ts
index 83303aa9..25a08ba1 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -1,3 +1,4 @@
+import { appendFile } from "node:fs/promises";
import { g, s, db } from "$lib/db";
import config from "$config";
import { pick, bail, fail, getUser } from "$lib/utils";
@@ -607,7 +608,7 @@ export default {
accounts.push(account);
}
- res.send(accounts);
+ res.send(accounts.reverse());
},
async createAccount(req, res) {
@@ -647,6 +648,8 @@ export default {
await s(`pending:${id}`, 0);
await db.lPush(`${user.id}:accounts`, id);
+ await appendFile("/bitcoin.conf", `wallet=${id}`);
+
res.send(account);
} catch (e) {
bail(res, e.message);