aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.dockerignore19
-rw-r--r--.gitignore1
-rw-r--r--Dockerfile8
-rw-r--r--db/index.js8
-rw-r--r--docker-compose.yml27
-rw-r--r--index.js4
-rw-r--r--routes/lightning/invoice.js11
-rw-r--r--routes/payments.js54
8 files changed, 90 insertions, 42 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..4901d87f
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,19 @@
+node_modules/
+.env
+yarn-error.log
+.pnp*
+.yarn*
+tls.*
+leveldb
+swaps
+exceptions
+fx
+uploads
+verified
+data
+lnurl-server.sqlite3
+watcher.log
+mysql
+config/bitcoin
+config/liquid
+config/lightning
diff --git a/.gitignore b/.gitignore
index c606860e..50584753 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@ watcher.log
build.json
build.sh
config
+mysql
diff --git a/Dockerfile b/Dockerfile
index 57631e3a..f2b111ec 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,12 +1,16 @@
-FROM node:15-alpine
+FROM node:slim
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV
-RUN apk add --no-cache -U git
+RUN apt-get update
+RUN apt-get install git make gcc g++ python libzmq3-dev -y
RUN git clone https://github.com/asoltys/coinos-server /app
WORKDIR /app
+
RUN yarn install
+ENV SHELL /bin/bash
+
CMD ["yarn", "start"]
diff --git a/db/index.js b/db/index.js
index 86827bca..e18aec8e 100644
--- a/db/index.js
+++ b/db/index.js
@@ -89,10 +89,10 @@ User.hasMany(Payment, {
foreignKey: "user_id"
});
-// User.belongsTo(Account, {
-// as: "account",
-// foreignKey: "account_id"
-// });
+User.belongsTo(Account, {
+ as: "account",
+ foreignKey: "account_id"
+});
Invoice.belongsTo(Account, {
as: "account",
diff --git a/docker-compose.yml b/docker-compose.yml
index e3b8e5a3..7bba494c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -8,16 +8,20 @@ services:
restart: on-failure
ports:
- '3119:3119'
+ environment:
+ NODE_ENV: development
volumes:
- ./config:/app/config
+ - ./:/app
+ - ./config/lightning:/lightning
bitcoin:
image: asoltys/bitcoin:latest
container_name: bitcoin
ports:
- - ${BITCOIN_PEER_PORT}:19000
- - ${BITCOIN_NODE_PORT}:19001
+ - ${BITCOIN_PEER_PORT}:18442
+ - ${BITCOIN_NODE_PORT}:18443
volumes:
- - ./liquidregtest/config/:/config
+ - ./config/bitcoin:/config
restart: unless-stopped
liquid:
image: asoltys/liquid:latest
@@ -28,13 +32,13 @@ services:
- ${LIQUID_BLOCK_PORT}:18602
- ${LIQUID_TX_PORT}:18603
volumes:
- - ./liquidregtest/liquid-config/:/config
+ - ./config/liquid:/config
restart: unless-stopped
lightning:
- image: asoltys/lightning:latest
+ image: elementsproject/lightningd:latest
container_name: lightning
environment:
- - LIGHTNINGD_NETWORK: regtest
+ LIGHTNINGD_NETWORK: regtest
volumes:
- ./config/lightning:/root/.lightning
restart: unless-stopped
@@ -79,4 +83,13 @@ services:
ports:
- ${LIQUID_ESPLORA_PORT}:5000
restart: unless-stopped
-
+ maria:
+ container_name: mariadb
+ image: mariadb:10.6.1
+ restart: always
+ environment:
+ MARIADB_ROOT_PASSWORD: ${ROOT_PASSWORD}
+ volumes:
+ - ./mysql:/var/lib/mysql
+ ports:
+ - 3307:3306
diff --git a/index.js b/index.js
index 82a225ac..6295155f 100644
--- a/index.js
+++ b/index.js
@@ -73,14 +73,10 @@ require("./lib/send");
require("./routes/assets");
require("./routes/invoices");
require("./routes/payments");
-/*
-*/
-/*
require("./routes/info");
require("./routes/swaps");
require("./routes/users");
require("./routes/funding");
-*/
if (config.lnurl) require("./routes/lnurl");
if (config.imap) require("./lib/mail");
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 140a3002..1f3a0528 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -1,13 +1,20 @@
module.exports = ah(async (req, res) => {
let { amount, memo, tip } = req.body;
if (!tip) tip = 0;
+ let value = amount + tip;
try {
if (config.lna.clightning) {
- const invoice = await lna.invoice(`${amount + tip}sat` || "any", new Date(), memo, 360);
+ if (!memo) memo = "coinos";
+ const invoice = await lna.invoice(
+ value ? `${value}sat` : "any",
+ new Date(),
+ memo,
+ 360
+ );
res.send(invoice.bolt11);
} else {
- const invoice = await lna.addInvoice({ value: amount + tip, memo });
+ const invoice = await lna.addInvoice({ value, memo });
res.send(invoice.payment_request);
}
} catch (e) {
diff --git a/routes/payments.js b/routes/payments.js
index 005223af..a52ad395 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -12,7 +12,7 @@ ah(async () => {
const exceptions = [];
try {
- read(fs.createReadStream("exceptions"), data => exceptions.push(data));
+ read(fs.createReadStream("exceptions"), (data) => exceptions.push(data));
} catch (e) {
l.warn("couldn't read exceptions file", e.message);
}
@@ -21,8 +21,8 @@ ah(async () => {
await db.Invoice.findAll({
include: {
model: db.User,
- as: "user"
- }
+ as: "user",
+ },
})
).map(({ address, user, unconfidential }) => {
if (address && user) addresses[address] = user.username;
@@ -34,8 +34,8 @@ ah(async () => {
where: { pubkey: { [Op.ne]: null } },
include: {
model: db.User,
- as: "user"
- }
+ as: "user",
+ },
});
accounts.map(({ address, user: { username } }) => {
@@ -47,35 +47,35 @@ ah(async () => {
payments = (
await db.Payment.findAll({
- attributes: ["hash"]
+ attributes: ["hash"],
})
- ).map(p => p.hash);
+ ).map((p) => p.hash);
setInterval(async () => {
const unconfirmed = (
await db.Payment.findAll({
where: {
- confirmed: 0
- }
+ confirmed: 0,
+ },
})
- ).map(p => p.hash);
+ ).map((p) => p.hash);
const transactions = await bc.listTransactions("*", 1000);
transactions
.filter(
- tx =>
+ (tx) =>
tx.category === "receive" &&
tx.confirmations > 0 &&
unconfirmed.includes(tx.txid)
)
- .map(tx => {
+ .map((tx) => {
l.warn("tx unconfirmed in db", tx.txid, tx.address);
});
const unaccounted = [];
- transactions.map(tx => {
+ transactions.map((tx) => {
if (!payments.includes(tx.txid) && !exceptions.includes(tx.txid)) {
unaccounted.push(tx.txid);
}
@@ -89,8 +89,7 @@ ah(async () => {
if (config.lna) {
if (config.lna.clightning) {
- const lnapath = join(require("os").homedir(), ".lightningreg/regtest");
- lna = require("clightning-client")(lnapath);
+ lna = require("clightning-client")(config.lna.dir);
} else {
throw new Error("lnd not supported");
}
@@ -120,10 +119,14 @@ ah(async () => {
require("./bitcoin/receive");
setTimeout(async () => {
- const address = await bc.getNewAddress();
- const { hdkeypath } = await bc.getAddressInfo(address);
- const parts = hdkeypath.split("/");
- app.set("bcAddressIndex", parts[parts.length - 1].slice(0, -1));
+ try {
+ const address = await bc.getNewAddress();
+ const { hdkeypath } = await bc.getAddressInfo(address);
+ const parts = hdkeypath.split("/");
+ app.set("bcAddressIndex", parts[parts.length - 1].slice(0, -1));
+ } catch (e) {
+ console.error(e);
+ }
}, 50);
}
@@ -137,13 +140,18 @@ ah(async () => {
require("./liquid/receive");
setTimeout(async () => {
- const address = await lq.getNewAddress();
- const { hdkeypath } = await lq.getAddressInfo(address);
- const parts = hdkeypath.split("/");
- app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1));
+ try {
+ const address = await lq.getNewAddress();
+ const { hdkeypath } = await lq.getAddressInfo(address);
+ const parts = hdkeypath.split("/");
+ app.set("lqAddressIndex", parts[parts.length - 1].slice(0, -1));
+ } catch (e) {
+ console.error(e);
+ }
}, 50);
}
+
app.get(
"/payments",
auth,