loopout: use optional routing plugin for the main swap invoice

This commit is contained in:
Andras Banki-Horvath 2021-12-01 16:50:54 +01:00
parent 04ebc8d568
commit 1943edfd78
No known key found for this signature in database
GPG key ID: 80E5375C094198D8
2 changed files with 175 additions and 44 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/zpay32"
)
@ -27,24 +28,29 @@ func FeeRateAsPercentage(feeRate int64) float64 {
return float64(feeRate) / (FeeRateTotalParts / 100)
}
// DecodeInvoice gets the hash and the amount of an invoice.
// DecodeInvoice gets the destination, hash and the amount of an invoice.
// It requires an amount to be specified.
func DecodeInvoice(params *chaincfg.Params,
payReq string) (lntypes.Hash, btcutil.Amount, error) {
payReq string) (route.Vertex, lntypes.Hash, btcutil.Amount, error) {
swapPayReq, err := zpay32.Decode(
payReq, params,
)
if err != nil {
return lntypes.Hash{}, 0, err
return route.Vertex{}, lntypes.Hash{}, 0, err
}
if swapPayReq.MilliSat == nil {
return lntypes.Hash{}, 0, errors.New("no amount in invoice")
return route.Vertex{}, lntypes.Hash{}, 0,
errors.New("no amount in invoice")
}
var hash lntypes.Hash
copy(hash[:], swapPayReq.PaymentHash[:])
return hash, swapPayReq.MilliSat.ToSatoshis(), nil
var destination route.Vertex
destPubKey := swapPayReq.Destination.SerializeCompressed()
copy(destination[:], destPubKey)
return destination, hash, swapPayReq.MilliSat.ToSatoshis(), nil
}