aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-05-16 22:09:10 -0700
committerAdam Soltys <[email protected]>2020-05-16 22:09:10 -0700
commitf35282246da3a77d2d7e6dc193e12997832d1423 (patch)
tree23f64098c3f2cef7aa6cf68ab6754572117749e9
parent957b15980849e857995048dc13de8d8c6914f16d (diff)
downloadcoinos-server-f35282246da3a77d2d7e6dc193e12997832d1423.tar.gz
coinos-server-f35282246da3a77d2d7e6dc193e12997832d1423.zip
Revert "drop recaptcha"
This reverts commit 8a5496b3cd2e898e204367b8ca7c6e8f4d7b6055.
-rw-r--r--lib/fixed.js22
-rw-r--r--lib/utils.js2
-rw-r--r--routes/bitcoin/fee.js5
-rw-r--r--routes/liquid/fee.js4
-rw-r--r--routes/users.js28
5 files changed, 32 insertions, 29 deletions
diff --git a/lib/fixed.js b/lib/fixed.js
deleted file mode 100644
index bd0710b9..00000000
--- a/lib/fixed.js
+++ /dev/null
@@ -1,22 +0,0 @@
-module.exports = function(n, p) {
- if (!parseInt(p)) return parseInt(n).toFixed(0);
- else {
- let x = n / 10 ** p;
- if (Math.abs(x) < 1.0) {
- var e = parseInt(x.toString().split('e-')[1]);
- if (e) {
- x *= Math.pow(10, e - 1);
- x = x.toFixed(9 - e);
- x = '0.' + new Array(e).join('0') + x.toString().substring(2);
- }
- } else {
- var e = parseInt(x.toString().split('+')[1]);
- if (e > 20) {
- e -= 20;
- x /= Math.pow(10, e);
- x += new Array(e + 1).join('0');
- }
- }
- return x;
- }
-}
diff --git a/lib/utils.js b/lib/utils.js
index a9f42c81..5674f2fc 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,8 +1,6 @@
const sequelize = require("sequelize");
const { Op } = sequelize;
-fixed = require('./fixed');
-
getUser = async (username, transaction) => {
let params = {
include: [
diff --git a/routes/bitcoin/fee.js b/routes/bitcoin/fee.js
index 3faff265..8a0db177 100644
--- a/routes/bitcoin/fee.js
+++ b/routes/bitcoin/fee.js
@@ -7,11 +7,8 @@ module.exports = async (req, res) => {
attributes: ['username'],
where: { address }
});
-
- if (recipient) {
- l.info("emitting");
+ if (recipient)
emit(user.username, "to", recipient);
- }
try {
amount = parseInt(amount);
diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js
index 5b574544..6a884657 100644
--- a/routes/liquid/fee.js
+++ b/routes/liquid/fee.js
@@ -29,7 +29,7 @@ module.exports = async (req, res) => {
subtractFeeFromOutputs: amount === user.balance ? [0] : [],
};
- if (feeRate) params.feeRate = fixed(feeRate, 8);
+ if (feeRate) params.feeRate = (feeRate / SATS).toFixed(8);
tx = await lq.fundRawTransaction(tx, params);
@@ -41,6 +41,8 @@ module.exports = async (req, res) => {
decoded = await lq.decodeRawTransaction(signed.hex);
feeRate = Math.round((tx.fee * SATS * 1000) / decoded.vsize);
+ l.info("estimated", asset);
+
res.send({ feeRate, tx });
} catch (e) {
l.error("error estimating liquid fee", e);
diff --git a/routes/users.js b/routes/users.js
index e7ab873c..bc4debdf 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -83,6 +83,34 @@ app.post("/register", async (req, res) => {
let ip = req.headers["x-forwarded-for"] || req.connection.remoteAddress;
+ try {
+ const url = `https://www.google.com/recaptcha/api/siteverify?secret=${config.captcha}&response=${user.token}&remoteip=${ip}`;
+ let captcha = await axios.post(
+ url,
+ {
+ secret: config.captcha,
+ response: user.token,
+ remoteip: ip,
+ },
+ { timeout: 1000 }
+ );
+
+ let { success, score } = captcha.data;
+
+ if (!success || score < 0.3) {
+ l.warn("failed registration attempt", ip);
+
+ if (ip !== "192.168.1.5") {
+ const spawn = require("child_process").spawn;
+ proc = spawn("iptables", ["-I", "INPUT", "-s", ip, "-j", "DROP"]);
+ }
+
+ return res.status(500).send("Failed captcha");
+ }
+ } catch (e) {
+ l.error(e.message);
+ }
+
let countries = {
CA: "CAD",
US: "USD",