lnrpc: report invoice state

Expose the new invoice state field over rpc.
This commit is contained in:
Joost Jager 2018-12-19 16:03:48 +01:00
parent 5515713b88
commit 1199f17cd9
No known key found for this signature in database
GPG Key ID: AE6B0D042C8E38D9
4 changed files with 613 additions and 540 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1699,7 +1699,7 @@ message Invoice {
int64 value = 5 [json_name = "value"];
/// Whether this invoice has been fulfilled
bool settled = 6 [json_name = "settled"];
bool settled = 6 [json_name = "settled", deprecated = true];
/// When this invoice was created
int64 creation_date = 7 [json_name = "creation_date"];
@ -1777,7 +1777,18 @@ message Invoice {
here as well.
*/
int64 amt_paid_msat = 20 [json_name = "amt_paid_msat"];
enum InvoiceState {
OPEN = 0;
SETTLED = 1;
}
/**
The state the invoice is in.
*/
InvoiceState state = 21 [json_name = "state"];
}
message AddInvoiceResponse {
bytes r_hash = 1 [json_name = "r_hash"];

View File

@ -1127,6 +1127,14 @@
],
"default": "COOPERATIVE_CLOSE"
},
"InvoiceInvoiceState": {
"type": "string",
"enum": [
"OPEN",
"SETTLED"
],
"default": "OPEN"
},
"PendingChannelsResponseClosedChannel": {
"type": "object",
"properties": {
@ -2125,6 +2133,10 @@
"type": "string",
"format": "int64",
"description": "*\nThe amount that was accepted for this invoice, in millisatoshis. This will\nONLY be set if this invoice has been settled. We provide this field as if\nthe invoice was created with a zero value, then we need to record what\namount was ultimately accepted. Additionally, it's possible that the sender\npaid MORE that was specified in the original invoice. So we'll record that\nhere as well."
},
"state": {
"$ref": "#/definitions/InvoiceInvoiceState",
"description": "*\nThe state the invoice is in."
}
}
},

View File

@ -3305,6 +3305,16 @@ func createRPCInvoice(invoice *channeldb.Invoice) (*lnrpc.Invoice, error) {
isSettled := invoice.Terms.State == channeldb.ContractSettled
var state lnrpc.Invoice_InvoiceState
switch invoice.Terms.State {
case channeldb.ContractOpen:
state = lnrpc.Invoice_OPEN
case channeldb.ContractSettled:
state = lnrpc.Invoice_SETTLED
default:
return nil, fmt.Errorf("unknown invoice state")
}
return &lnrpc.Invoice{
Memo: string(invoice.Memo[:]),
Receipt: invoice.Receipt[:],
@ -3326,6 +3336,7 @@ func createRPCInvoice(invoice *channeldb.Invoice) (*lnrpc.Invoice, error) {
AmtPaidSat: int64(satAmtPaid),
AmtPaidMsat: int64(invoice.AmtPaid),
AmtPaid: int64(invoice.AmtPaid),
State: state,
}, nil
}