aboutsummaryrefslogtreecommitdiffstats
path: root/routes/liquid
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-08-03 01:52:33 -0700
committerAdam Soltys <[email protected]>2021-08-03 01:52:33 -0700
commite5e2bcf015b128c71cacf125d6aea4a0dddd30c3 (patch)
tree09af4085f72fa2466cb0f66768be6e882be30f81 /routes/liquid
parent2f52a91c5babde9e374dd9c532448f565bcbfeee (diff)
parent1fbae57bb9540b1c116efc367809ac01ae2e9df2 (diff)
downloadcoinos-server-e5e2bcf015b128c71cacf125d6aea4a0dddd30c3.tar.gz
coinos-server-e5e2bcf015b128c71cacf125d6aea4a0dddd30c3.zip
Merge branch 'prod' into dev
Diffstat (limited to 'routes/liquid')
-rw-r--r--routes/liquid/fee.js9
-rw-r--r--routes/liquid/receive.js8
-rw-r--r--routes/liquid/send.js34
3 files changed, 26 insertions, 25 deletions
diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js
index 2070873a..fad69f13 100644
--- a/routes/liquid/fee.js
+++ b/routes/liquid/fee.js
@@ -3,11 +3,6 @@ const buildTx = require("../../lib/buildliquidtx");
liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => {
let tx, fee;
let node = lq;
- /*
- if (asset === config.liquid.btcasset) {
- node = rare;
- }
- */
if (user.account.pubkey) {
let psbt = await buildTx({
@@ -64,6 +59,8 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => {
}
);
+ l.info("funding tx for fee estimate", tx);
+
tx = await node.fundRawTransaction(tx, params);
let blinded = await node.blindRawTransaction(tx.hex);
@@ -81,7 +78,7 @@ module.exports = ah(async (req, res) => {
let tx = await liquidTx({ ...req.body, user: req.user })
res.send(tx);
} catch (e) {
- l.error("error estimating liquid fee", e.message, e.stack);
+ l.error("error estimating liquid fee", e.message);
return res.status(500).send(e.message);
}
});
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index c377a6b5..259db7c7 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -101,7 +101,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
user_id: user.id,
network: "liquid"
},
- order: [["id", "DESC"]],
+ order: [["id", "DESC"]]
});
if (!invoice) return;
@@ -286,9 +286,9 @@ setInterval(async () => {
for (let i = 0; i < arr.length; i++) {
const hash = arr[i];
- let account, address, user, total;
+ let account, address, user, total, p;
await db.transaction(async transaction => {
- let p = await db.Payment.findOne({
+ p = await db.Payment.findOne({
where: { hash, confirmed: 0, received: 1 },
include: [
{
@@ -347,7 +347,7 @@ setInterval(async () => {
});
let c = convert[address];
- if (address && c) {
+ if (address && c && p.account.asset === network.assetHash) {
l.info(
"liquid detected for conversion request",
address,
diff --git a/routes/liquid/send.js b/routes/liquid/send.js
index 19b7344f..13f77d26 100644
--- a/routes/liquid/send.js
+++ b/routes/liquid/send.js
@@ -1,5 +1,6 @@
const btc = config.liquid.btcasset;
const lcad = config.liquid.cadasset;
+const { Transaction } = require("liquidjs-lib");
sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
if (amount > 10000000) throw new Error("Amount too large");
@@ -48,7 +49,8 @@ sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
const assets = Object.keys(totals);
const payments = [];
- return db.transaction(async transaction => {
+ let main, signed;
+ await db.transaction(async transaction => {
for (let i = 0; i < assets.length; i++) {
let asset = assets[i];
let amount = totals[asset];
@@ -75,12 +77,12 @@ sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
await faucet.reload({ transaction });
await faucet.save({ transaction });
}
-
- total += fee - covered;
}
+
+ total += fee - covered;
}
- if (limit && total > limit)
+ if (limit && total > limit + fee)
throw new Error("Tx amount exceeds authorized amount");
if (asset !== btc || total) {
@@ -132,16 +134,11 @@ sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
}
}
- if (config.liquid.walletpass)
- await lq.walletPassphrase(config.liquid.walletpass, 300);
-
- let blinded = await lq.blindRawTransaction(tx.hex);
- let signed = await lq.signRawTransactionWithWallet(blinded);
- let txid = await lq.sendRawTransaction(signed.hex);
-
- l.info("sent liquid tx", txid, address);
+ signed = await lq.signRawTransactionWithWallet(
+ await lq.blindRawTransaction(tx.hex)
+ );
+ let txid = Transaction.fromHex(signed.hex).getId();
- let main;
for (let i = 0; i < assets.length; i++) {
p = payments[i];
if (p) {
@@ -157,15 +154,22 @@ sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
emit(user.username, "account", main.account);
emit(user.username, "payment", main);
- return main;
});
+
+ if (config.liquid.walletpass)
+ await lq.walletPassphrase(config.liquid.walletpass, 300);
+
+ let txid = await lq.sendRawTransaction(signed.hex);
+ l.info("sent liquid tx", txid, address);
+
+ return main;
};
module.exports = ah(async (req, res) => {
let { user } = req;
try {
- res.send(await sendLiquid({...req.body, user }));
+ res.send(await sendLiquid({ ...req.body, user }));
} catch (e) {
l.error("problem sending liquid", user.username, e.message);
return res.status(500).send(e);