mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-23 23:31:02 +02:00
Merge pull request #3824 from cfromknecht/invoice-features-rpc
lnrpc: expose features on rpc invoices
This commit is contained in:
commit
cc18d0ae6b
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/zpay32"
|
"github.com/lightningnetwork/lnd/zpay32"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -116,6 +117,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
|||||||
AmtPaid: int64(invoice.AmtPaid),
|
AmtPaid: int64(invoice.AmtPaid),
|
||||||
State: state,
|
State: state,
|
||||||
Htlcs: rpcHtlcs,
|
Htlcs: rpcHtlcs,
|
||||||
|
Features: CreateRPCFeatures(invoice.Terms.Features),
|
||||||
}
|
}
|
||||||
|
|
||||||
if preimage != channeldb.UnknownPreimage {
|
if preimage != channeldb.UnknownPreimage {
|
||||||
@ -125,6 +127,22 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
|||||||
return rpcInvoice, nil
|
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
|
// CreateRPCRouteHints takes in the decoded form of an invoice's route hints
|
||||||
// and converts them into the lnrpc type.
|
// and converts them into the lnrpc type.
|
||||||
func CreateRPCRouteHints(routeHints [][]zpay32.HopHint) []*lnrpc.RouteHint {
|
func CreateRPCRouteHints(routeHints [][]zpay32.HopHint) []*lnrpc.RouteHint {
|
||||||
|
1152
lnrpc/rpc.pb.go
1152
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -2371,6 +2371,9 @@ message Invoice {
|
|||||||
|
|
||||||
/// List of HTLCs paying to this invoice [EXPERIMENTAL].
|
/// List of HTLCs paying to this invoice [EXPERIMENTAL].
|
||||||
repeated InvoiceHTLC htlcs = 22 [json_name = "htlcs"];
|
repeated InvoiceHTLC htlcs = 22 [json_name = "htlcs"];
|
||||||
|
|
||||||
|
/// List of features advertised on the invoice.
|
||||||
|
repeated Feature features = 24 [json_name = "features"];
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InvoiceHTLCState {
|
enum InvoiceHTLCState {
|
||||||
|
@ -2802,6 +2802,13 @@
|
|||||||
"$ref": "#/definitions/lnrpcInvoiceHTLC"
|
"$ref": "#/definitions/lnrpcInvoiceHTLC"
|
||||||
},
|
},
|
||||||
"description": "/ List of HTLCs paying to this invoice [EXPERIMENTAL]."
|
"description": "/ List of HTLCs paying to this invoice [EXPERIMENTAL]."
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/lnrpcFeature"
|
||||||
|
},
|
||||||
|
"description": "/ List of features advertised on the invoice."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
16
rpcserver.go
16
rpcserver.go
@ -4632,20 +4632,6 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
|
|||||||
paymentAddr = payReq.PaymentAddr[:]
|
paymentAddr = payReq.PaymentAddr[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert any features on the payment request into a descriptive format
|
|
||||||
// for the rpc.
|
|
||||||
invFeatures := payReq.Features.Features()
|
|
||||||
features := make([]*lnrpc.Feature, 0, len(invFeatures))
|
|
||||||
for bit := range invFeatures {
|
|
||||||
name := payReq.Features.Name(bit)
|
|
||||||
features = append(features, &lnrpc.Feature{
|
|
||||||
Bit: uint32(bit),
|
|
||||||
Name: name,
|
|
||||||
IsRequired: bit.IsRequired(),
|
|
||||||
IsKnown: name != "unknown",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
dest := payReq.Destination.SerializeCompressed()
|
dest := payReq.Destination.SerializeCompressed()
|
||||||
return &lnrpc.PayReq{
|
return &lnrpc.PayReq{
|
||||||
Destination: hex.EncodeToString(dest),
|
Destination: hex.EncodeToString(dest),
|
||||||
@ -4660,7 +4646,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
|
|||||||
CltvExpiry: int64(payReq.MinFinalCLTVExpiry()),
|
CltvExpiry: int64(payReq.MinFinalCLTVExpiry()),
|
||||||
RouteHints: routeHints,
|
RouteHints: routeHints,
|
||||||
PaymentAddr: paymentAddr,
|
PaymentAddr: paymentAddr,
|
||||||
Features: features,
|
Features: invoicesrpc.CreateRPCFeatures(payReq.Features),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user