mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
025d787fd2
When calling `NotifyExitHopHtlc` it is allowed to pass a chan to subscribe to the HTLC's resolution when it's settled. However, this method will also return immediately if there's already a resolution, which means it behaves like a notifier and a getter. If the caller decides to only use the getter to do a non-blocking lookup, it can pass a nil subscriber chan to bypass the notification.
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package contractcourt
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
|
"github.com/lightningnetwork/lnd/invoices"
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
)
|
|
|
|
type notifyExitHopData struct {
|
|
payHash lntypes.Hash
|
|
paidAmount lnwire.MilliSatoshi
|
|
hodlChan chan<- interface{}
|
|
expiry uint32
|
|
currentHeight int32
|
|
}
|
|
|
|
type mockRegistry struct {
|
|
notifyChan chan notifyExitHopData
|
|
notifyErr error
|
|
notifyResolution invoices.HtlcResolution
|
|
}
|
|
|
|
func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
|
|
paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
|
|
circuitKey models.CircuitKey, hodlChan chan<- interface{},
|
|
wireCustomRecords lnwire.CustomRecords,
|
|
payload invoices.Payload) (invoices.HtlcResolution, error) {
|
|
|
|
// Exit early if the notification channel is nil.
|
|
if hodlChan == nil {
|
|
return r.notifyResolution, r.notifyErr
|
|
}
|
|
|
|
r.notifyChan <- notifyExitHopData{
|
|
hodlChan: hodlChan,
|
|
payHash: payHash,
|
|
paidAmount: paidAmount,
|
|
expiry: expiry,
|
|
currentHeight: currentHeight,
|
|
}
|
|
|
|
return r.notifyResolution, r.notifyErr
|
|
}
|
|
|
|
func (r *mockRegistry) HodlUnsubscribeAll(subscriber chan<- interface{}) {}
|
|
|
|
func (r *mockRegistry) LookupInvoice(context.Context, lntypes.Hash) (
|
|
invoices.Invoice, error) {
|
|
|
|
return invoices.Invoice{}, invoices.ErrInvoiceNotFound
|
|
}
|