alexbosworth / ln-service

Node.js interface to LND
MIT License
319 stars 60 forks source link

subscribeToInvoice method not working #149

Open lastcron opened 3 years ago

lastcron commented 3 years ago

I Just notice that in the supported versions, Ver LND 0.13.3-beta.rc2 is not yet supported. So this is just a heads up that the subscribeToInvoice method is not working on the RC2 version , we had to use subscribeToInvoices instead. ( with an s at the end )

Also in this RC2 version the subscribeToInvoices is not reporting invoice cancellations.

Thank for such a great work.

alexbosworth commented 3 years ago

what doesn't work exactly about subscribeToInvoice?

lastcron commented 3 years ago

After subscribing to the method subscribeToInvoice the event is not being fired when an invoice gets payed.

We previously had ver 13.2 working normally , the issue appeared after updating the lnd server to 0.13.3-beta.rc2.

Thanks again.

alexbosworth commented 3 years ago

Can you share some code? I can't reproduce a problem with subscribeToInvoice on 0.13.3-beta.rc2, I do get an event when the invoice is paid

lastcron commented 3 years ago
import {
   payViaRoutes,
   getInvoice,
   createInvoice,
   decodePaymentRequest,
   payViaPaymentDetails,
   createInvoice as createInvoiceRequest,
   subscribeToInvoice,
   subscribeToInvoices,
   authenticatedLndGrpc,
   getChannelBalance,
 } from "ln-service";

 const { lnd } = authenticatedLndGrpc({
  cert: process.env.CERT,
  macaroon: process.env.MACAROON,
  socket: `${process.env.LNDSERVER}:10009`,
});

const newInvoice = (tokens, description) => {
    const expiresIn: Date = new Date();
    expiresIn.setSeconds(expiresIn.getSeconds() + 60);
    expiresIn.toLocaleString("UTC", {
      timeZone: "UTC",
    });
    const invoice = await createInvoiceRequest({
         lnd,
         tokens,
         description,
         expires_at: expiresIn.toISOString(),
       });
       const sub = subscribeToInvoice({ id: invoice.id, lnd });
       sub.on("invoice_updated", async (info: any) => {
           console.log(info)
       })
}
newInvoice(10000, 'MyPayment'); 
alexbosworth commented 3 years ago

maybe it is an ordering issue, does it work if you put the subscription before the create invoice request?

lastcron commented 3 years ago

I need the invoice.id for the subcription. If I put the subscription before the create invoice I will not have that parameter available.

alexbosworth commented 3 years ago

ok yeah that makes sense

it should show updates after the creation though, maybe nothing is retaining the subscription? I don't know why it would be related to the lnd version

jfrader commented 9 months ago

For me the same issue using

lightning
        .subscribeToInvoice({ lnd, id })
        .on("invoice_updated", (invoice: lightning.SubscribeToInvoiceInvoiceUpdatedEvent) => {
          logger.debug(JSON.stringify(invoice))
          if (invoice.is_confirmed) {
            onConfirmed(invoice)
          }
        })

This works on LND v0.16.2-beta in SIMNET using polarlightning, but after deploying the same code to an environment with LND v0.17.3-beta in TESTNET, it is not triggering

jfrader commented 9 months ago

Update: After realizing I built LND from source using make install as opposed to make release-install which adds the tags needed for this method, this issue can be closed I guess. Its working in latest version v0.17.3-beta