This module allows subscribers to get notified about HTLC SettleEvents and InvoiceEvents. A subscripiton to HTLC events retrieve the following statistics from its related preceeding ForwardEvent:
* FromPubKey
* FromAlias
* IncomingMSats
* ToAlias
* ToPubKey
* OutgoingMSats
* ChanId_In
* ChanId_Out
* HtlcId_In
* HtlcId_Out
A subscripiton to invoice events retrieves the invoice related fields:
* IsSettled
* SettleAmount_msat
* Preimage
go get github.com/hieblmi/go-lnd-router-events
LND's router RPC interface allows to listen to ForwardEvents that basically represent an attempt from an initiating peer on a route to push a payment through our node. The successful forward events can be obtained by clients who implement
type Observer interface {
Update(event *Event)
GetName() string
}
and register their observer, in this case for forward settlements:
listener := events.New(&events.Config{
MacaroonPath: config.MacaroonPath,
CertPath: config.CertPath,
RpcHost: config.RpcHost,
})
listener.Register(&LndEventObserver{
Name: "YourObserverName",
}, events.Forward)
listener.Start()
The update method then receives successful forward events:
func (o *yourObserver) Update(e *events.Event) {
fmt.Println(e.Type)
fmt.Println(e.IncomingMSats)
fmt.Println(e.OutgoingMSats)
}
To retrieve the details of a successful payment we have to match the SettleEvent's ids to the ids of the preceeding ForwardEvent. In this instance this is solved by keeping a map of [key|ForwardEvent] and retrieve a given forward attempt when the respective SettleEvent occurs. The key is calculated by
IncomingChannelId + OutgoingChannelId + IncomingHtlcId + OutgoingHtlcId
In case the payment through our node isn't successful we will observe a ForwardFailEvent or LinkFailEvent. In these cases we simply remove the respective ForwardEvent from our map.
This stuff is experimental so do use it with care. I am highly appreciative of feedback and ways to improve my understanding of everything Lightning.
If you like what you see you could send me a tip :-)
Download a LightningAddress enabled wallet like Blixt or BlueWallet and tip to: ⚡tips@allmysats.com