alexbosworth / lightning

Lightning client methods
MIT License
127 stars 33 forks source link

added ability to add route hints to createInvoice/createHoldInvoice #142

Closed SeverinAlexB closed 1 year ago

SeverinAlexB commented 1 year ago

Do you have a time eta to get this merged?

alexbosworth commented 1 year ago

Oh I didn't see this, does it actually work? I think it won't do anything

SeverinAlexB commented 1 year ago

Works like a charm.

{
      chain_address: undefined,
      created_at: '2023-07-27T02:23:42.000Z',
      description: 'test jit',
      id: 'a5c3aa5b569b651612456805bb13f7752c25ebef169380133a787a88eb40a0f2',
      mtokens: '100000000',
      payment: '325cd0bc2fc37bfd855889ecdf1005405e148f3b67ff1b28257c4d1511027eac',
      request: 'lnbcrt1m1pjvr4fwpp55hp65k6kndj3vyj9dqzmkylhw5kzt6l0z6fcqye60pag366q5reqdqdw3jhxapqdf5hgcqzzsxqrpcgrzjqfl3vv6xpnr9gxk9d6uw6dvmmcsaq3crp3t4ktvxmsky9r2nl6gmwqqqqyqqqqgqqyqqqqqqqqqqqqqq9qsp5xfwdp0p0cdalmp2c38kd7yq9gp0pfremvll3k2p903x32ygz06kq9qyyssqeppevvey7sr6kuwfnxld7r9c2ucxumxzsr6en0vu7hwgw6g5txxh9fl27kkdsnver9hg2lwxn7ee0uyjzlaradgg4kwtcz22aftpywcph7gstu',
      secret: '7ceac91141b61e1e620d44d531b63f86abc088d06e5e488fe81a7e1876200a26',
      tokens: 100000
    }

Decoded: https://lightningdecoder.com/lnbcrt1m1pjvr4fwpp55hp65k6kndj3vyj9dqzmkylhw5kzt6l0z6fcqye60pag366q5reqdqdw3jhxapqdf5hgcqzzsxqrpcgrzjqfl3vv6xpnr9gxk9d6uw6dvmmcsaq3crp3t4ktvxmsky9r2nl6gmwqqqqyqqqqgqqyqqqqqqqqqqqqqq9qsp5xfwdp0p0cdalmp2c38kd7yq9gp0pfremvll3k2p903x32ygz06kq9qyyssqeppevvey7sr6kuwfnxld7r9c2ucxumxzsr6en0vu7hwgw6g5txxh9fl27kkdsnver9hg2lwxn7ee0uyjzlaradgg4kwtcz22aftpywcph7gstu

CleanShot 2023-07-27 at 09 24 34@2x
alexbosworth commented 1 year ago

ah interesting, i'll have to make a regtest setup to try it out

alexbosworth commented 1 year ago

i've been doing it a different way, like this: https://github.com/alexbosworth/balanceofsatoshis/blob/master/offchain/create_invoice.js

SeverinAlexB commented 1 year ago

So if I understand correctly, the user indicates if they want to add private channel hints with is_hinting and then you add all private channels in there?

alexbosworth commented 1 year ago

It allows for selecting individual hints too

alexbosworth commented 1 year ago

I didn't notice that this was added to LND though so it should be added yeah

The changes on the code side i'm thinking about is to make the input of route hints match the output of route hints on decodePaymentRequest because the formatting is a bit different, and also more comments documenting that and also I need to figure out when this was added to LND exactly

SeverinAlexB commented 1 year ago

It allows for selecting individual hints too

Can you point me to the code line? Can't find it.

The changes on the code side i'm thinking about is to make the input of route hints match the output of route hints on decodePaymentRequest because the formatting is a bit different, and also more comments documenting that and also I need to figure out when this was added to LND exactly

That sounds reasonable. Do you want to do that or shall I?

alexbosworth commented 1 year ago

you could edit it, i think i have some code for that translation somewhere but i can't find it

how I do it actually is I pass channel policies around, then compute the hop hints from those: https://github.com/alexbosworth/balanceofsatoshis/blob/master/offchain/sign_payment_request.js#L123

maybe passing channel policies like done above would even be easier or an alternative approach in order to not make the caller do any translation?

alexbosworth commented 1 year ago

i think this would convert the decodepaymentrequest type hints back to the rpc type hints:

const {chanNumber} = require('bolt07');

const routeHints = args.routes.map(route => {
  const path = route.map((hop, i) => {
    if (!i) {
      return;
    }

    return {
      node_id: route[i - [hop].length].public_key,
      chan_id: chanNumber({channel: hop.channel}).number,
      fee_base_msat: hop.base_fee_mtokens,
      fee_proportional_millionths: hop.fee_rate,
      cltv_expiry_delta: hop.cltv_delta,
    };
  });

  return {hop_hints: path.filter(n => !!n)};
});
alexbosworth commented 1 year ago

oh actually i found where a mapper already exists in the codebase: https://github.com/alexbosworth/lightning/blob/master/lnd_requests/route_hint_from_route.js

alexbosworth commented 1 year ago

I merged the combo of that method with invoice, but I had to remove the types since this now shares the decode payment request hints type - could be another PR? ping @bkiac

SeverinAlexB commented 1 year ago

Thx. Sorry, was busy the recent days

bkiac commented 1 year ago

I merged the combo of that method with invoice, but I had to remove the types since this now shares the decode payment request hints type - could be another PR? ping @bkiac

opened a PR with the types #143