aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/buildtx.js2
-rw-r--r--lib/persist.js18
-rw-r--r--lib/register.js4
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/buildtx.js b/lib/buildtx.js
index 876f6fff..5e0fe29f 100644
--- a/lib/buildtx.js
+++ b/lib/buildtx.js
@@ -2,7 +2,7 @@ const axios = require("axios");
const bitcoin = require("bitcoinjs-lib");
const coinselect = require("coinselect");
const split = require("coinselect/split");
-const api = prod ? "https://blockstream.info/api" : "http://localhost:3001";
+const api = prod ? "https://blockstream.info/api" : "http://localhost:3095";
const SATS = 100000000;
const network = prod
? bitcoin.networks["bitcoin"]
diff --git a/lib/persist.js b/lib/persist.js
new file mode 100644
index 00000000..24d00693
--- /dev/null
+++ b/lib/persist.js
@@ -0,0 +1,18 @@
+fs = require("fs");
+
+module.exports = (path, initial = {}) => {
+ try {
+ return require("../" + path);
+ } catch {
+ return new Proxy(initial, {
+ set(obj, prop, value) {
+ fs.writeFileSync(
+ path,
+ JSON.stringify({ ...obj, [prop]: value }, null, 2),
+ "utf-8"
+ );
+ return Reflect.set(...arguments);
+ }
+ });
+ }
+};
diff --git a/lib/register.js b/lib/register.js
index 23e20a72..a8d420ba 100644
--- a/lib/register.js
+++ b/lib/register.js
@@ -2,7 +2,7 @@ const authenticator = require("otplib").authenticator;
const axios = require("axios");
const bcrypt = require("bcrypt");
-register = async (user, ip, requireChallenge) => {
+register = ah(async (user, ip, requireChallenge) => {
if (!(user && user.username)) throw new Error("Username required");
let exists = await db.User.count({ where: { username: user.username } });
@@ -59,4 +59,4 @@ register = async (user, ip, requireChallenge) => {
await user.save();
l.info("new user", user.username, ip);
return user;
-};
+});