mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 11:11:53 +01:00
lnrpc+invoicesrpc: report invoice htlcs
This commit is contained in:
parent
d6d9ec6aa5
commit
45cd76e9eb
@ -60,6 +60,38 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
||||
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{
|
||||
Memo: string(invoice.Memo[:]),
|
||||
Receipt: invoice.Receipt[:],
|
||||
@ -81,6 +113,7 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
|
||||
AmtPaidMsat: int64(invoice.AmtPaid),
|
||||
AmtPaid: int64(invoice.AmtPaid),
|
||||
State: state,
|
||||
Htlcs: rpcHtlcs,
|
||||
}
|
||||
|
||||
if preimage != channeldb.UnknownPreimage {
|
||||
|
1243
lnrpc/rpc.pb.go
1243
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -2117,6 +2117,42 @@ message Invoice {
|
||||
The state the invoice is in.
|
||||
*/
|
||||
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 {
|
||||
|
@ -2489,9 +2489,70 @@
|
||||
"state": {
|
||||
"$ref": "#/definitions/InvoiceInvoiceState",
|
||||
"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": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user