lnrpc+invoicesrpc: report invoice htlcs
This commit is contained in:
4 files changed
+827
-546
No files matched your search
@@ -60,6 +60,38 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
|||||||
invoice.Terms.State)
|
invoice.Terms.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpcHtlcs := make([]*lnrpc.InvoiceHTLC, 0, len(invoice.Htlcs))
|
||||||
|
for key, htlc := range invoice.Htlcs {
|
||||||
|
var state lnrpc.InvoiceHTLCState
|
||||||
|
switch htlc.State {
|
||||||
|
case channeldb.HtlcStateAccepted:
|
||||||
|
state = lnrpc.InvoiceHTLCState_ACCEPTED
|
||||||
|
case channeldb.HtlcStateSettled:
|
||||||
|
state = lnrpc.InvoiceHTLCState_SETTLED
|
||||||
|
case channeldb.HtlcStateCancelled:
|
||||||
|
state = lnrpc.InvoiceHTLCState_CANCELLED
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unknown state %v", htlc.State)
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcHtlc := lnrpc.InvoiceHTLC{
|
||||||
|
ChanId: key.ChanID.ToUint64(),
|
||||||
|
HtlcIndex: key.HtlcID,
|
||||||
|
AcceptHeight: int32(htlc.AcceptHeight),
|
||||||
|
AcceptTime: htlc.AcceptTime.Unix(),
|
||||||
|
ExpiryHeight: int32(htlc.Expiry),
|
||||||
|
AmtMsat: uint64(htlc.Amt),
|
||||||
|
State: state,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only report resolved times if htlc is resolved.
|
||||||
|
if htlc.State != channeldb.HtlcStateAccepted {
|
||||||
|
rpcHtlc.ResolveTime = htlc.ResolveTime.Unix()
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcHtlcs = append(rpcHtlcs, &rpcHtlc)
|
||||||
|
}
|
||||||
|
|
||||||
rpcInvoice := &lnrpc.Invoice{
|
rpcInvoice := &lnrpc.Invoice{
|
||||||
Memo: string(invoice.Memo[:]),
|
Memo: string(invoice.Memo[:]),
|
||||||
Receipt: invoice.Receipt[:],
|
Receipt: invoice.Receipt[:],
|
||||||
@@ -81,6 +113,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
|||||||
AmtPaidMsat: int64(invoice.AmtPaid),
|
AmtPaidMsat: int64(invoice.AmtPaid),
|
||||||
AmtPaid: int64(invoice.AmtPaid),
|
AmtPaid: int64(invoice.AmtPaid),
|
||||||
State: state,
|
State: state,
|
||||||
|
Htlcs: rpcHtlcs,
|
||||||
}
|
}
|
||||||
|
|
||||||
if preimage != channeldb.UnknownPreimage {
|
if preimage != channeldb.UnknownPreimage {
|
||||||
|
|||||||
+697
-546
File diff suppressed because it is too large.
Load diff
@@ -2117,6 +2117,42 @@ message Invoice {
|
|||||||
The state the invoice is in.
|
The state the invoice is in.
|
||||||
*/
|
*/
|
||||||
InvoiceState state = 21 [json_name = "state"];
|
InvoiceState state = 21 [json_name = "state"];
|
||||||
|
|
||||||
|
/// List of HTLCs paying to this invoice [EXPERIMENTAL].
|
||||||
|
repeated InvoiceHTLC htlcs = 22 [json_name = "htlcs"];
|
||||||
|
}
|
||||||
|
|
||||||
|
enum InvoiceHTLCState {
|
||||||
|
ACCEPTED = 0;
|
||||||
|
SETTLED = 1;
|
||||||
|
CANCELLED = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Details of an HTLC that paid to an invoice
|
||||||
|
message InvoiceHTLC {
|
||||||
|
/// Short channel id over which the htlc was received.
|
||||||
|
uint64 chan_id = 1 [json_name = "chan_id"];
|
||||||
|
|
||||||
|
/// Index identifying the htlc on the channel.
|
||||||
|
uint64 htlc_index = 2 [json_name = "htlc_index"];
|
||||||
|
|
||||||
|
/// The amount of the htlc in msat.
|
||||||
|
uint64 amt_msat = 3 [json_name = "amt_msat"];
|
||||||
|
|
||||||
|
/// Block height at which this htlc was accepted.
|
||||||
|
int32 accept_height = 4 [json_name = "accept_height"];
|
||||||
|
|
||||||
|
/// Time at which this htlc was accepted.
|
||||||
|
int64 accept_time = 5 [json_name = "accept_time"];
|
||||||
|
|
||||||
|
/// Time at which this htlc was settled or cancelled.
|
||||||
|
int64 resolve_time = 6 [json_name = "resolve_time"];
|
||||||
|
|
||||||
|
/// Block height at which this htlc expires.
|
||||||
|
int32 expiry_height = 7 [json_name = "expiry_height"];
|
||||||
|
|
||||||
|
/// Current state the htlc is in.
|
||||||
|
InvoiceHTLCState state = 8 [json_name = "state"];
|
||||||
}
|
}
|
||||||
|
|
||||||
message AddInvoiceResponse {
|
message AddInvoiceResponse {
|
||||||
|
|||||||
@@ -2489,9 +2489,70 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"$ref": "#/definitions/InvoiceInvoiceState",
|
"$ref": "#/definitions/InvoiceInvoiceState",
|
||||||
"description": "*\nThe state the invoice is in."
|
"description": "*\nThe state the invoice is in."
|
||||||
|
},
|
||||||
|
"htlcs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/lnrpcInvoiceHTLC"
|
||||||
|
},
|
||||||
|
"description": "/ List of HTLCs paying to this invoice [EXPERIMENTAL]."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"lnrpcInvoiceHTLC": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"chan_id": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uint64",
|
||||||
|
"description": "/ Short channel id over which the htlc was received."
|
||||||
|
},
|
||||||
|
"htlc_index": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uint64",
|
||||||
|
"description": "/ Index identifying the htlc on the channel."
|
||||||
|
},
|
||||||
|
"amt_msat": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uint64",
|
||||||
|
"description": "/ The amount of the htlc in msat."
|
||||||
|
},
|
||||||
|
"accept_height": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "/ Block height at which this htlc was accepted."
|
||||||
|
},
|
||||||
|
"accept_time": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "int64",
|
||||||
|
"description": "/ Time at which this htlc was accepted."
|
||||||
|
},
|
||||||
|
"resolve_time": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "int64",
|
||||||
|
"description": "/ Time at which this htlc was settled or cancelled."
|
||||||
|
},
|
||||||
|
"expiry_height": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32",
|
||||||
|
"description": "/ Block height at which this htlc expires."
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"$ref": "#/definitions/lnrpcInvoiceHTLCState",
|
||||||
|
"description": "/ Current state the htlc is in."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "/ Details of an HTLC that paid to an invoice"
|
||||||
|
},
|
||||||
|
"lnrpcInvoiceHTLCState": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"ACCEPTED",
|
||||||
|
"SETTLED",
|
||||||
|
"CANCELLED"
|
||||||
|
],
|
||||||
|
"default": "ACCEPTED"
|
||||||
|
},
|
||||||
"lnrpcLightningAddress": {
|
"lnrpcLightningAddress": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
Reference in new issue
Block a user