diff options
| -rw-r--r-- | lib/fixed.js | 22 | ||||
| -rw-r--r-- | lib/utils.js | 2 | ||||
| -rw-r--r-- | routes/bitcoin/fee.js | 5 | ||||
| -rw-r--r-- | routes/liquid/fee.js | 10 | ||||
| -rw-r--r-- | routes/users.js | 28 |
5 files changed, 34 insertions, 33 deletions
diff --git a/lib/fixed.js b/lib/fixed.js new file mode 100644 index 00000000..bd0710b9 --- /dev/null +++ b/lib/fixed.js @@ -0,0 +1,22 @@ +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 5674f2fc..a9f42c81 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,6 +1,8 @@ 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 fab17307..cac514b3 100644 --- a/routes/bitcoin/fee.js +++ b/routes/bitcoin/fee.js @@ -6,8 +6,11 @@ module.exports = async (req, res) => { let recipient = await db.User.findOne({ where: { address } }); - if (recipient) + + if (recipient) { + l.info("emitting"); emit(user.username, "to", recipient); + } try { amount = parseInt(amount); diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js index d041a5e2..e7fd4d0d 100644 --- a/routes/liquid/fee.js +++ b/routes/liquid/fee.js @@ -3,9 +3,13 @@ module.exports = async (req, res) => { let { address, asset, amount, feeRate } = req.body; let tx, fee; + let recipient = await db.User.findOne({ where: { confidential: address } }); + + l.info(address, recipient.username); + if (recipient) emit(user.username, "to", recipient); @@ -15,7 +19,7 @@ module.exports = async (req, res) => { tx = await lq.createRawTransaction( [], { - [address]: (amount / SATS).toFixed(8) + [address]: fixed(amount, 8) }, 0, false, @@ -28,7 +32,7 @@ module.exports = async (req, res) => { subtractFeeFromOutputs: amount === user.balance ? [0] : [] }; - if (feeRate) params.feeRate = (feeRate / SATS).toFixed(8); + if (feeRate) params.feeRate = fixed(feeRate, 8); tx = await lq.fundRawTransaction(tx, params); @@ -40,8 +44,6 @@ 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 f3d99049..e08d4790 100644 --- a/routes/users.js +++ b/routes/users.js @@ -104,34 +104,6 @@ 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", |
