rpcserver: populate features on lnrpc invoices

In the process, we also move the feature serialization into the
invoicesrpc package, so that it can be shared between the invoicesrpc
and main rpcserver.
This commit is contained in:
Conner Fromknecht
2019-12-11 16:37:02 -08:00
parent 7446495b6d
commit aba49c9a5a
2 changed files with 19 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/zpay32"
)
@@ -116,6 +117,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
AmtPaid: int64(invoice.AmtPaid),
State: state,
Htlcs: rpcHtlcs,
Features: CreateRPCFeatures(invoice.Terms.Features),
}
if preimage != channeldb.UnknownPreimage {
@@ -125,6 +127,22 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
return rpcInvoice, nil
}
// CreateRPCFeatures maps a feature vector into a list of lnrpc.Features.
func CreateRPCFeatures(fv *lnwire.FeatureVector) []*lnrpc.Feature {
features := fv.Features()
rpcFeatures := make([]*lnrpc.Feature, 0, len(features))
for bit := range features {
rpcFeatures = append(rpcFeatures, &lnrpc.Feature{
Bit: uint32(bit),
Name: fv.Name(bit),
IsRequired: bit.IsRequired(),
IsKnown: fv.IsKnown(bit),
})
}
return rpcFeatures
}
// CreateRPCRouteHints takes in the decoded form of an invoice's route hints
// and converts them into the lnrpc type.
func CreateRPCRouteHints(routeHints [][]zpay32.HopHint) []*lnrpc.RouteHint {