New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ListPayments: filter out non-succeeded payments, include payment status #3190
Merged
Roasbeef
merged 2 commits into
lightningnetwork:master
from
halseth:listpayments-status-filter
Jun 13, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4131,7 +4131,7 @@ func marshallTopologyChange(topChange *routing.TopologyChange) *lnrpc.GraphTopol | |
|
||
// ListPayments returns a list of all outgoing payments. | ||
func (r *rpcServer) ListPayments(ctx context.Context, | ||
_ *lnrpc.ListPaymentsRequest) (*lnrpc.ListPaymentsResponse, error) { | ||
req *lnrpc.ListPaymentsRequest) (*lnrpc.ListPaymentsResponse, error) { | ||
|
||
rpcsLog.Debugf("[ListPayments]") | ||
|
||
|
@@ -4140,10 +4140,15 @@ func (r *rpcServer) ListPayments(ctx context.Context, | |
return nil, err | ||
} | ||
|
||
paymentsResp := &lnrpc.ListPaymentsResponse{ | ||
Payments: make([]*lnrpc.Payment, len(payments)), | ||
} | ||
for i, payment := range payments { | ||
paymentsResp := &lnrpc.ListPaymentsResponse{} | ||
for _, payment := range payments { | ||
// To keep compatibility with the old API, we only return | ||
// non-suceeded payments if requested. | ||
if payment.Status != channeldb.StatusSucceeded && | ||
!req.NonSucceeded { | ||
continue | ||
} | ||
|
||
// If a payment attempt has been made we can fetch the route. | ||
// Otherwise we'll just populate the RPC response with an empty | ||
// one. | ||
|
@@ -4165,8 +4170,13 @@ func (r *rpcServer) ListPayments(ctx context.Context, | |
msatValue := int64(payment.Info.Value) | ||
satValue := int64(payment.Info.Value.ToSatoshis()) | ||
|
||
status, err := convertPaymentStatus(payment.Status) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
paymentHash := payment.Info.PaymentHash | ||
paymentsResp.Payments[i] = &lnrpc.Payment{ | ||
paymentsResp.Payments = append(paymentsResp.Payments, &lnrpc.Payment{ | ||
PaymentHash: hex.EncodeToString(paymentHash[:]), | ||
Value: satValue, | ||
ValueMsat: msatValue, | ||
|
@@ -4176,12 +4186,36 @@ func (r *rpcServer) ListPayments(ctx context.Context, | |
Fee: int64(route.TotalFees().ToSatoshis()), | ||
PaymentPreimage: hex.EncodeToString(preimage[:]), | ||
PaymentRequest: string(payment.Info.PaymentRequest), | ||
} | ||
Status: status, | ||
}) | ||
} | ||
|
||
return paymentsResp, nil | ||
} | ||
|
||
// convertPaymentStatus converts a channeldb.PaymentStatus to the type expected | ||
// by the RPC. | ||
func convertPaymentStatus(dbStatus channeldb.PaymentStatus) ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this something that could be defined in |
||
lnrpc.Payment_PaymentStatus, error) { | ||
|
||
switch dbStatus { | ||
case channeldb.StatusUnknown: | ||
return lnrpc.Payment_UNKNOWN, nil | ||
|
||
case channeldb.StatusInFlight: | ||
return lnrpc.Payment_IN_FLIGHT, nil | ||
|
||
case channeldb.StatusSucceeded: | ||
return lnrpc.Payment_SUCCEEDED, nil | ||
|
||
case channeldb.StatusFailed: | ||
return lnrpc.Payment_FAILED, nil | ||
|
||
default: | ||
return 0, fmt.Errorf("unhandled payment status %v", dbStatus) | ||
} | ||
} | ||
|
||
// DeleteAllPayments deletes all outgoing payments from DB. | ||
func (r *rpcServer) DeleteAllPayments(ctx context.Context, | ||
_ *lnrpc.DeleteAllPaymentsRequest) (*lnrpc.DeleteAllPaymentsResponse, error) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming suggestion:
include_incomplete
orinclude_unsuccessful
?