Merge pull request #3693 from cfromknecht/tlv-invoice

migrate to tlv for invoice body
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2019-11-25 18:00:52 -06:00
commit cb2b8b4513
22 files changed
+1569 -822

No files matched your search

+10 -11
View File
@@ -57,10 +57,6 @@ type AddInvoiceData struct {
// description_hash field is not being used.
Memo string
// Deprecated. An optional cryptographic receipt of payment which is not
// implemented.
Receipt []byte
// The preimage which will allow settling an incoming HTLC payable to
// this preimage. If Preimage is set, Hash should be nil. If both
// Preimage and Hash are nil, a random preimage is generated.
@@ -154,10 +150,6 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
return nil, nil, fmt.Errorf("memo too large: %v bytes "+
"(maxsize=%v)", len(invoice.Memo), channeldb.MaxMemoSize)
}
if len(invoice.Receipt) > channeldb.MaxReceiptSize {
return nil, nil, fmt.Errorf("receipt too large: %v bytes "+
"(maxsize=%v)", len(invoice.Receipt), channeldb.MaxReceiptSize)
}
if len(invoice.DescriptionHash) > 0 && len(invoice.DescriptionHash) != 32 {
return nil, nil, fmt.Errorf("description hash is %v bytes, must be 32",
len(invoice.DescriptionHash))
@@ -371,6 +363,13 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
}
// Set a blank feature vector, as our invoice generation forbids nil
// features.
invoiceFeatures := lnwire.NewFeatureVector(
lnwire.NewRawFeatureVector(), lnwire.Features,
)
options = append(options, zpay32.Features(invoiceFeatures))
// Create and encode the payment request as a bech32 (zpay32) string.
creationDate := time.Now()
payReq, err := zpay32.NewInvoice(
@@ -392,13 +391,13 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
newInvoice := &channeldb.Invoice{
CreationDate: creationDate,
Memo: []byte(invoice.Memo),
Receipt: invoice.Receipt,
PaymentRequest: []byte(payReqString),
FinalCltvDelta: int32(payReq.MinFinalCLTVExpiry()),
Expiry: payReq.Expiry(),
Terms: channeldb.ContractTerm{
FinalCltvDelta: int32(payReq.MinFinalCLTVExpiry()),
Expiry: payReq.Expiry(),
Value: amtMSat,
PaymentPreimage: paymentPreimage,
Features: invoiceFeatures,
},
}
+5 -6
View File
@@ -43,10 +43,10 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
satAmt := invoice.Terms.Value.ToSatoshis()
satAmtPaid := invoice.AmtPaid.ToSatoshis()
isSettled := invoice.Terms.State == channeldb.ContractSettled
isSettled := invoice.State == channeldb.ContractSettled
var state lnrpc.Invoice_InvoiceState
switch invoice.Terms.State {
switch invoice.State {
case channeldb.ContractOpen:
state = lnrpc.Invoice_OPEN
case channeldb.ContractSettled:
@@ -57,7 +57,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
state = lnrpc.Invoice_ACCEPTED
default:
return nil, fmt.Errorf("unknown invoice state %v",
invoice.Terms.State)
invoice.State)
}
rpcHtlcs := make([]*lnrpc.InvoiceHTLC, 0, len(invoice.Htlcs))
@@ -94,7 +94,6 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
rpcInvoice := &lnrpc.Invoice{
Memo: string(invoice.Memo[:]),
Receipt: invoice.Receipt[:],
RHash: decoded.PaymentHash[:],
Value: int64(satAmt),
ValueMsat: int64(invoice.Terms.Value),
@@ -103,8 +102,8 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
Settled: isSettled,
PaymentRequest: paymentRequest,
DescriptionHash: descHash,
Expiry: int64(invoice.Expiry.Seconds()),
CltvExpiry: uint64(invoice.FinalCltvDelta),
Expiry: int64(invoice.Terms.Expiry.Seconds()),
CltvExpiry: uint64(invoice.Terms.FinalCltvDelta),
FallbackAddr: fallbackAddr,
RouteHints: routeHints,
AddIndex: invoice.AddIndex,
+553 -565
View File
File diff suppressed because it is too large. Load diff
+1 -4
View File
@@ -2217,10 +2217,7 @@ message Invoice {
*/
string memo = 1 [json_name = "memo"];
/** Deprecated. An optional cryptographic receipt of payment which is not
implemented.
*/
bytes receipt = 2 [json_name = "receipt", deprecated = true];
reserved 2;
/**
The hex-encoded preimage (32 byte) which will allow settling an incoming
-5
View File
@@ -2660,11 +2660,6 @@
"type": "string",
"description": "*\nAn optional memo to attach along with the invoice. Used for record keeping\npurposes for the invoice's creator, and will also be set in the description\nfield of the encoded payment request if the description_hash field is not\nbeing used."
},
"receipt": {
"type": "string",
"format": "byte",
"description": "* Deprecated. An optional cryptographic receipt of payment which is not\nimplemented."
},
"r_preimage": {
"type": "string",
"format": "byte",