invoices: extract invoice decoding from registry
Previously it was difficult to use the invoice registry in unit tests, because it used zpay32 to decode the invoice. For that to succeed, a valid signature is required on the payment request. This commit injects the decode dependency on a different level so that it is easier to mock.
This commit is contained in:
3 files changed
+29
-13
No files matched your search
@@ -46,6 +46,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
"github.com/lightningnetwork/lnd/zpay32"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -284,6 +285,14 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
|
||||
readBufferPool, runtime.NumCPU(), pool.DefaultWorkerTimeout,
|
||||
)
|
||||
|
||||
decodeFinalCltvExpiry := func(payReq string) (uint32, error) {
|
||||
invoice, err := zpay32.Decode(payReq, activeNetParams.Params)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint32(invoice.MinFinalCLTVExpiry()), nil
|
||||
}
|
||||
|
||||
s := &server{
|
||||
chanDB: chanDB,
|
||||
cc: cc,
|
||||
@@ -291,7 +300,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
|
||||
writePool: writePool,
|
||||
readPool: readPool,
|
||||
|
||||
invoices: invoices.NewRegistry(chanDB, activeNetParams.Params),
|
||||
invoices: invoices.NewRegistry(chanDB, decodeFinalCltvExpiry),
|
||||
|
||||
channelNotifier: channelnotifier.New(chanDB),
|
||||
|
||||
|
||||
Reference in new issue
Block a user