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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
module.exports = async (req, res) => {
let { user } = req;
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);
try {
amount = parseInt(amount);
tx = await lq.createRawTransaction(
[],
{
[address]: fixed(amount, 8)
},
0,
false,
{
[address]: asset
}
);
let params = {
subtractFeeFromOutputs: amount === user.balance ? [0] : []
};
if (feeRate) params.feeRate = fixed(feeRate, 8);
tx = await lq.fundRawTransaction(tx, params);
if (config.liquid.walletpass)
await lq.walletPassphrase(config.liquid.walletpass, 300);
let blinded = await lq.blindRawTransaction(tx.hex);
let signed = await lq.signRawTransactionWithWallet(blinded);
decoded = await lq.decodeRawTransaction(signed.hex);
feeRate = Math.round((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);
}
};
|