| ofs | hex dump | ascii |
|---|
| 0000 | 52 49 46 46 9a 15 00 00 57 45 42 50 56 50 38 20 8e 15 00 00 70 49 00 9d 01 2a 80 00 80 00 3e 69 | RIFF....WEBPVP8.....pI...*....>i |
| 0020 | 2a 90 46 24 22 a1 a1 39 77 df 58 80 0d 09 6c 00 9d 32 97 7a 7f b8 fe 55 7e 51 fc 8e d5 ff b7 ff | *.F$"..9w.X...l..2.z...U~Q...... |
| 0040 | 70 fd 5b fd cf dc 07 2d 3c dd e4 d1 cf 5f f5 ff bf fe 48 fc cd ff 1f ea 87 f4 67 b0 1f ea af ec | p.[....-<...._....H.......g..... |
| 0060 | 57 b7 cf f9 5e a8 7f 70 7d 45 7e e0 7e dc 7b be ff c6 f5 61 fd ab d4 1b f9 87 f8 8f fc 5d 85 5e | W...^..p}E~.~.{....a.........].^ |
| 0080 | 81 7f b9 fe 9b 7f ba 1f 08 df d8 ff e1 7e e3 7b 53 ff f9 ec d5 d3 5b e1 5f e6 7c 15 f2 27 f1 2f | .............~.{S.....[._.|..'./ |
| 00a0 | dd fd 05 71 7f d9 0e a2 9d d1 ff 3f cd ee fe 7e 5f 6a 23 ed 2d e5 30 11 dd 27 f8 7e 74 e9 71 fa | ...q.......?...~_j#.-.0..'.~t.q. |
| 00c0 | 1f b0 47 8c 3e 87 fe c2 e0 60 88 d5 7b 79 82 b1 36 a1 97 00 d9 ab cc d5 e4 17 73 1c 27 aa 39 6e | ..G.>....`..{y..6.........s.'.9n |
| 00e0 | 6a cc 5f b0 57 69 4f b5 7f 0b 9b 47 48 09 a0 0c 07 7c f8 01 aa 7b 48 fc 75 08 9d 76 ba f2 34 b5 | j._.WiO....GH....|...{H.u..v..4. |
| 0100 | 8d 5c 5d 29 e5 dd f0 66 64 0c f4 59 72 02 16 7d bf 8a 62 98 16 f9 72 4a b7 d6 82 f6 e3 42 0e 03 | .\])...fd..Yr..}..b...rJ.....B.. |
| 0120 | 5d 0e 04 e5 76 a8 2a a2 d8 67 22 31 1b 37 65 46 b2 65 7e 43 2a 73 66 5d 79 cd e7 93 c9 11 33 b2 | ]...v.*..g"1.7eF.e~C*sf]y.....3. |
| 0140 | 16 27 dc 33 4a b4 f2 3b 14 cd b2 ae 01 d5 dc 56 b0 f8 8d 49 48 42 d0 cf 31 b1 ff 61 58 b9 d1 9e | .'.3J..;.......V...IHB..1..aX... |
| 0160 | ff d1 ae 67 d2 01 ee 86 5f 66 ee 86 c7 0f 6f a4 15 18 65 34 08 ee c0 5f 26 41 a2 86 2d 55 e9 67 | ...g...._f....o...e4..._&A..-U.g |
| 0180 | b5 f5 de 56 35 1e 91 5d ec 4b cb 3a 14 1b b0 35 64 6e 34 3a f0 82 2f 06 53 6f 3d 2b d7 de 6c 28 | ...V5..].K.:...5dn4:../.So=+..l( |
| 01a0 | bf ea 3c ed a3 fc 7e 96 a1 b7 70 29 90 f5 c9 c5 74 08 91 73 3d ec 35 a8 3b a3 14 9e 8f 33 cd 85 | ..<...~...p)....t..s=.5.;....3.. |
| 01c0 | 59 93 f5 53 03 4c 44 15 e9 99 9f 5a 29 28 02 8b dd aa 34 94 51 f1 54 4a ed 6f fa c0 94 a7 44 42 | Y..S.LD....Z)(....4.Q.TJ.o....DB |
| 01e0 | d5 09 33 ed 09 3c 4d 0d c8 8b 65 70 35 36 18 6e f8 83 53 7e 85 e7 b2 39 39 f9 84 fa f4 d5 d4 3e | ..3..<M...ep56.n..S~...99......> |
| 0200 | 24 cc 4a 88 57 1f d5 79 5c 1b eb 37 f1 68 14 f4 ca 75 51 4d 8c 23 13 df 83 1a b4 f8 41 84 50 40 | $.J.W..y\..7.h...uQM.#......A.P@ |
| 0220 | 80 4a e8 5e 43 11 96 e2 80 6c ec b3 51 86 3f 0b 90 6f e5 b6 20 ce d8 44 ee b1 88 a4 13 47 95 63 | .J.^C....l..Q.?..o.....D.....G.c |
| 0240 | fb 15 7c 61 a7 e2 d9 6b 05 77 46 7d 11 be 42 8a aa d8 4f c8 63 79 d6 2e 3f 27 7f 6e ab 7e 24 6b | ..|a...k.wF}..B...O.cy..?'.n.~$k |
| 0260 | 6a 08 2d 79 7f 85 3d 00 00 fe f5 40 2d 10 55 df 8f 3e 2c 8e 5c ea 79 5a e3 f1 ef 64 d0 65 04 4a | j.-y..=....@-.U..>,.\.yZ...d.e.J |
| 0280 | 18 8a de e3 73 ef ad f9 05 da f4 b0 d3 c1 5a d9 d3 da 98 75 84 8f 16 d4 3f e3 9a 0e 45 1e e6 0d | ....s.........Z....u....?...E... |
| 02a0 | e0 cf 39 58 c7 6d 09 8d 7f ef 4d e4 a5 70 5a e5 1f 9b 81 ad ba 4c 2d 6b 74 8f c8 11 35 cf 0f 4b | ..9X.m....M..pZ......L-kt...5..K |
| 02c0 | 1b df 60 34 91 b9 5a f7 4c 21 9d db 94 83 c1 5f d0 8d e9 b0 80 2d 7b db 78 4a f9 ba 3b 0f 84 c7 | ..`4..Z.L!....._.....-{.xJ..;... |
| 02e0 | cb 71 98 8c f0 55 92 4d 8e b4 76 e8 64 11 aa 0b 0e 6a 98 8a 38 9b 03 ea fa b8 43 8c 6f d6 1b 10 | .q...U.M..v.d....j..8.....C.o... |
| 0300 | fc 00 5e 37 b0 2e 15 cf aa 37 bf 53 a7 89 dc e6 4a 09 1e b1 7d 61 da aa e2 96 fa 84 02 74 70 49 | ..^7.....7.S....J...}a.......tpI |
| 0320 | 4c 04 fc 49 64 89 eb c4 4d a8 a2 1d 57 5d ff b7 48 ef 4c 89 36 4a e4 76 ad 9b 27 a1 16 eb 24 4c | L..Id...M...W]..H.L.6J.v..'...$L |
| 0340 | aa ec cf 00 c5 fe 76 a4 85 5d 43 1a c3 e1 dd a3 09 19 d8 d4 c2 c2 14 31 f3 9d 45 3f c4 const bolt11 = require("bolt11");
const { Op } = require("sequelize");
send = async (amount, memo, hash, user) => {
let payreq = bolt11.decode(hash);
let routingInfo = payreq.tags.find(t => t.tagName === "routing_info");
if (
routingInfo &&
routingInfo.data.find(d => d.fee_proportional_millionths > 100)
)
throw new Error("Fee rate too high");
if (!amount || payreq.satoshis > amount) amount = payreq.satoshis;
if (seen.includes(hash)) {
l.warn("attempted to pay a paid invoice", user.username);
throw new Error("Invoice has been paid, can't pay again");
}
let error, fee, total, preimage, payment;
await db.transaction(async transaction => {
let account = await db.Account.findOne({
where: {
user_id: user.id,
asset: config.liquid.btcasset,
pubkey: null,
balance: {
[Op.gte]: amount
}
},
lock: transaction.LOCK.UPDATE,
transaction
});
if (!account || account.balance < amount) {
throw new Error("Insufficient funds");
}
await account.decrement({ balance: amount }, { transaction });
await account.reload({ transaction });
if (config.lna.clightning) {
let m = await lna.pay(hash);
let sent;
({
msatoshi: total,
msatoshi_sent: sent,
payment_preimage: preimage
} = m);
fee = parseInt((sent - total) / 1000);
total = parseInt(total / 1000);
} else {
let m = await lna.sendPaymentSync({
amt: amount,
payment_request: hash,
max_parts: 10,
fee_limit: { fixed: Math.min(10000, account.balance) },
});
if (m.payment_error) throw new Error(m.payment_error);
({
payment_route: { total_fees: fee, total_amt: total },
payment_preimage: preimage
} = m);
}
preimage = preimage.toString("hex");
if (seen.includes(preimage)) {
l.warn("duplicate payment detected", preimage);
throw new Error("Duplicate payment detected");
}
});
await db.transaction(async transaction => {
let account = await db.Account.findOne({
where: {
user_id: user.id,
asset: config.liquid.btcasset,
pubkey: null
},
lock: transaction.LOCK.UPDATE,
transaction
});
total = parseInt(total);
fee = parseInt(fee);
await account.decrement({ balance: fee }, { transaction });
await account.reload({ transaction });
payment = await db.Payment.create(
{
amount: -(total - fee),
account_id: account.id,
user_id: user.id,
hash,
memo,
preimage,
rate: app.get("rates")[user.currency],
currency: user.currency,
confirmed: true,
network: "lightning",
fee
},
{ transaction }
);
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
emit(user.username, "account", payment.account);
emit(user.username, "payment", payment);
seen.push(preimage);
seen.push(hash);
l.info("sent lightning", user.username, total - fee, fee);
});
return payment;
};
|