blob: 9dbb7e0a6c2d5797d010e7e3dd9b667eaae8b5af (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
module.exports = async (req, res) => {
let { user } = req;
let { address, amount, feeRate } = req.body;
let tx, fee;
try {
amount = parseInt(amount);
tx = await lq.createRawTransaction([], {
[address]: (amount / SATS).toFixed(8)
});
let params = {
subtractFeeFromOutputs: amount === user.balance ? [0] : []
}
if (feeRate) params.feeRate = (feeRate / SATS).toFixed(8);
tx = await lq.fundRawTransaction(tx, params);
if (config.liquid.walletpass)
await lq.walletPassphrase(config.liquid.walletpass, 300);
let signed = (await lq.signRawTransactionWithWallet(tx.hex));
decoded = await lq.decodeRawTransaction(signed.hex);
feeRate = parseInt(tx.fee * SATS * 1000 / decoded.vsize);
res.send({ feeRate, tx });
} catch (e) {
l.error("error estimating liquid fee", e);
return res.status(500).send(e.message);
}
};
|