Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I monitor incoming payments? #160

Open
basharov opened this issue Jun 8, 2022 · 4 comments
Open

How can I monitor incoming payments? #160

basharov opened this issue Jun 8, 2022 · 4 comments

Comments

@basharov
Copy link

basharov commented Jun 8, 2022

I can subscribe to outcoming payments with this:

const subPayments = subscribeToPastPayments({ lnd })
subPayments.on('payment', async (payment: any) => {})

When I get this event, I fetch the balance via calling getChainBalance() which returns me the accurate updated balance.

However, when I create an invoice and pay it from another wallet, I only see this option to track the event of the incoming payment:

const subInvoices = subscribeToInvoices({ lnd })
subInvoices.on('invoice_updated', async (invoice: any) => {
  console.log(invoice)
  if (invoice.is_confirmed) {
    // check balance here
  }
})

But, it won't return the accurate updated balance sometimes. It returns some balance but then it changes and this is not accurate.

So, I hope there is some other subscription I can use to see the fact of the balance change.

Is there any?

Thanks!

@alexbosworth
Copy link
Owner

You could try subscribeToForwards

balance changing overall does not have an API

@basharov
Copy link
Author

basharov commented Jun 8, 2022

You could try subscribeToForwards

balance changing overall does not have an API

First, thank you Alex for the lightning-fast response!
Second, yes, seems like it's what I need, shows the correct final balance, thank you!

@basharov
Copy link
Author

basharov commented Jun 8, 2022

Actually seems like this one returns the balance in similar way as invoice subscription, with the value which then changes without any way to detect it. Probably I can just run a background service which would query via rpc periodically, like every 5 seconds?

@alexbosworth
Copy link
Owner

Yes since there is no balance changing API you can do polling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants