lnrpc: populate new AmpInvoiceState field in CreateRPCInvoice

This commit is contained in:
Olaoluwa Osuntokun 2021-10-14 18:33:32 +02:00
parent d8ce00e016
commit 698b5a8079
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306
5 changed files with 2002 additions and 1687 deletions

View File

@ -370,6 +370,30 @@
},
"description": "Details specific to AMP HTLCs."
},
"lnrpcAMPInvoiceState": {
"type": "object",
"properties": {
"state": {
"$ref": "#/definitions/lnrpcInvoiceHTLCState",
"description": "The state the HTLCs associated with this setID are in."
},
"settle_index": {
"type": "string",
"format": "uint64",
"description": "The settle index of this HTLC set, if the invoice state is settled."
},
"settle_time": {
"type": "string",
"format": "int64",
"description": "The time this HTLC set was settled expressed in unix epoch."
},
"amt_paid_msat": {
"type": "string",
"format": "int64",
"description": "The total amount paid for the sub-invoice expressed in milli satoshis."
}
}
},
"lnrpcFeature": {
"type": "object",
"properties": {
@ -540,11 +564,19 @@
"payment_addr": {
"type": "string",
"format": "byte",
"description": "The payment address of this invoice. This value will be used in MPP\npayments, and also for newer invoies that always require the MPP paylaod\nfor added end-to-end security."
"description": "The payment address of this invoice. This value will be used in MPP\npayments, and also for newer invoices that always require the MPP payload\nfor added end-to-end security."
},
"is_amp": {
"type": "boolean",
"description": "Signals whether or not this is an AMP invoice."
},
"amp_invoice_state": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/lnrpcAMPInvoiceState"
},
"description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.",
"title": "[EXPERIMENTAL]:"
}
}
},

View File

@ -177,6 +177,39 @@ func CreateRPCInvoice(invoice *channeldb.Invoice,
IsAmp: isAmp,
}
rpcInvoice.AmpInvoiceState = make(map[string]*lnrpc.AMPInvoiceState)
for setID, ampState := range invoice.AMPState {
setIDStr := hex.EncodeToString(setID[:])
var state lnrpc.InvoiceHTLCState
switch ampState.State {
case channeldb.HtlcStateAccepted:
state = lnrpc.InvoiceHTLCState_ACCEPTED
case channeldb.HtlcStateSettled:
state = lnrpc.InvoiceHTLCState_SETTLED
case channeldb.HtlcStateCanceled:
state = lnrpc.InvoiceHTLCState_CANCELED
default:
return nil, fmt.Errorf("unknown state %v", ampState.State)
}
rpcInvoice.AmpInvoiceState[setIDStr] = &lnrpc.AMPInvoiceState{
State: state,
SettleIndex: ampState.SettleIndex,
SettleTime: ampState.SettleDate.Unix(),
AmtPaidMsat: int64(ampState.AmtPaid),
}
// If at least one of the present HTLC sets show up as being
// settled, then we'll mark the invoice itself as being
// settled.
if ampState.State == channeldb.HtlcStateSettled {
rpcInvoice.Settled = true // nolint:staticcheck
rpcInvoice.State = lnrpc.Invoice_SETTLED
}
}
if preimage != nil {
rpcInvoice.RPreimage = preimage[:]
}

File diff suppressed because it is too large Load Diff

View File

@ -3056,6 +3056,10 @@ message HopHint {
uint32 cltv_expiry_delta = 5;
}
message SetID {
bytes set_id = 1;
}
message RouteHint {
/*
A list of hop hints that when chained together can assist in reaching a
@ -3064,6 +3068,20 @@ message RouteHint {
repeated HopHint hop_hints = 1;
}
message AMPInvoiceState {
// The state the HTLCs associated with this setID are in.
InvoiceHTLCState state = 1;
// The settle index of this HTLC set, if the invoice state is settled.
uint64 settle_index = 2;
// The time this HTLC set was settled expressed in unix epoch.
int64 settle_time = 3;
// The total amount paid for the sub-invoice expressed in milli satoshis.
int64 amt_paid_msat = 5;
}
message Invoice {
/*
An optional memo to attach along with the invoice. Used for record keeping
@ -3209,7 +3227,7 @@ message Invoice {
/*
The payment address of this invoice. This value will be used in MPP
payments, and also for newer invoies that always require the MPP paylaod
payments, and also for newer invoices that always require the MPP payload
for added end-to-end security.
*/
bytes payment_addr = 26;
@ -3218,6 +3236,16 @@ message Invoice {
Signals whether or not this is an AMP invoice.
*/
bool is_amp = 27;
/*
[EXPERIMENTAL]:
Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the
given set ID. This field is always populated for AMP invoices, and can be
used along side LookupInvoice to obtain the HTLC information related to a
given sub-invoice.
*/
map<string, AMPInvoiceState> amp_invoice_state = 28;
}
enum InvoiceHTLCState {

View File

@ -2838,6 +2838,30 @@
},
"description": "Details specific to AMP HTLCs."
},
"lnrpcAMPInvoiceState": {
"type": "object",
"properties": {
"state": {
"$ref": "#/definitions/lnrpcInvoiceHTLCState",
"description": "The state the HTLCs associated with this setID are in."
},
"settle_index": {
"type": "string",
"format": "uint64",
"description": "The settle index of this HTLC set, if the invoice state is settled."
},
"settle_time": {
"type": "string",
"format": "int64",
"description": "The time this HTLC set was settled expressed in unix epoch."
},
"amt_paid_msat": {
"type": "string",
"format": "int64",
"description": "The total amount paid for the sub-invoice expressed in milli satoshis."
}
}
},
"lnrpcAMPRecord": {
"type": "object",
"properties": {
@ -4755,11 +4779,19 @@
"payment_addr": {
"type": "string",
"format": "byte",
"description": "The payment address of this invoice. This value will be used in MPP\npayments, and also for newer invoies that always require the MPP paylaod\nfor added end-to-end security."
"description": "The payment address of this invoice. This value will be used in MPP\npayments, and also for newer invoices that always require the MPP payload\nfor added end-to-end security."
},
"is_amp": {
"type": "boolean",
"description": "Signals whether or not this is an AMP invoice."
},
"amp_invoice_state": {
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/lnrpcAMPInvoiceState"
},
"description": "Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the\ngiven set ID. This field is always populated for AMP invoices, and can be\nused along side LookupInvoice to obtain the HTLC information related to a\ngiven sub-invoice.",
"title": "[EXPERIMENTAL]:"
}
}
},