@@ -62,6 +62,10 @@ type LightningClient interface {
62
62
ListInvoices (ctx context.Context , req ListInvoicesRequest ) (
63
63
* ListInvoicesResponse , error )
64
64
65
+ // ListPayments makes a paginated call to our list payments endpoint.
66
+ ListPayments (ctx context.Context ,
67
+ req ListPaymentsRequest ) (* ListPaymentsResponse , error )
68
+
65
69
// ChannelBackup retrieves the backup for a particular channel. The
66
70
// backup is returned as an encrypted chanbackup.Single payload.
67
71
ChannelBackup (context.Context , wire.OutPoint ) ([]byte , error )
@@ -1022,6 +1026,121 @@ func (s *lightningClient) ListInvoices(ctx context.Context,
1022
1026
}, nil
1023
1027
}
1024
1028
1029
+ // Payment represents a payment made by our node.
1030
+ type Payment struct {
1031
+ // Hash is the payment hash used.
1032
+ Hash lntypes.Hash
1033
+
1034
+ // Preimage is the preimage of the payment. It will have a non-nil value
1035
+ // if the payment is settled.
1036
+ Preimage * lntypes.Preimage
1037
+
1038
+ // Amount is the amount in millisatoshis of the payment.
1039
+ Amount lnwire.MilliSatoshi
1040
+
1041
+ // Fee is the amount in millisatoshis that was paid in fees.
1042
+ Fee lnwire.MilliSatoshi
1043
+
1044
+ // Status describes the state of a payment.
1045
+ Status * PaymentStatus
1046
+
1047
+ // Htlcs is the set of htlc attempts made by the payment.
1048
+ Htlcs []* lnrpc.HTLCAttempt
1049
+
1050
+ // SequenceNumber is a unique id for each payment.
1051
+ SequenceNumber uint64
1052
+ }
1053
+
1054
+ // ListPaymentsRequest contains the request parameters for a paginated
1055
+ // list payments call.
1056
+ type ListPaymentsRequest struct {
1057
+ // MaxPayments is the maximum number of payments to return.
1058
+ MaxPayments uint64
1059
+
1060
+ // Offset is the index from which to start querying.
1061
+ Offset uint64
1062
+
1063
+ // Reversed is set to query our payments backwards.
1064
+ Reversed bool
1065
+
1066
+ // IncludeIncomplete is set if we want to include incomplete payments.
1067
+ IncludeIncomplete bool
1068
+ }
1069
+
1070
+ // ListPaymentsResponse contains the response to a list payments query,
1071
+ // including the index offsets required for paginated queries.
1072
+ type ListPaymentsResponse struct {
1073
+ // FirstIndexOffset is the index offset of the first item in our set.
1074
+ FirstIndexOffset uint64
1075
+
1076
+ // LastIndexOffset is the index offset of the last item in our set.
1077
+ LastIndexOffset uint64
1078
+
1079
+ // Payments is the set of invoices that were returned.
1080
+ Payments []Payment
1081
+ }
1082
+
1083
+ // ListPayments makes a paginated call to our listpayments endpoint.
1084
+ func (s * lightningClient ) ListPayments (ctx context.Context ,
1085
+ req ListPaymentsRequest ) (* ListPaymentsResponse , error ) {
1086
+
1087
+ rpcCtx , cancel := context .WithTimeout (ctx , rpcTimeout )
1088
+ defer cancel ()
1089
+
1090
+ resp , err := s .client .ListPayments (
1091
+ s .adminMac .WithMacaroonAuth (rpcCtx ),
1092
+ & lnrpc.ListPaymentsRequest {
1093
+ IncludeIncomplete : req .IncludeIncomplete ,
1094
+ IndexOffset : req .Offset ,
1095
+ MaxPayments : req .MaxPayments ,
1096
+ Reversed : req .Reversed ,
1097
+ })
1098
+ if err != nil {
1099
+ return nil , err
1100
+ }
1101
+
1102
+ payments := make ([]Payment , len (resp .Payments ))
1103
+ for i , payment := range resp .Payments {
1104
+ hash , err := lntypes .MakeHashFromStr (payment .PaymentHash )
1105
+ if err != nil {
1106
+ return nil , err
1107
+ }
1108
+
1109
+ status , err := unmarshallPaymentStatus (payment )
1110
+ if err != nil {
1111
+ return nil , err
1112
+ }
1113
+
1114
+ pmt := Payment {
1115
+ Hash : hash ,
1116
+ Status : status ,
1117
+ Htlcs : payment .Htlcs ,
1118
+ Amount : lnwire .MilliSatoshi (payment .ValueMsat ),
1119
+ Fee : lnwire .MilliSatoshi (payment .FeeMsat ),
1120
+ SequenceNumber : payment .PaymentIndex ,
1121
+ }
1122
+
1123
+ // Add our preimage if it is known.
1124
+ if payment .PaymentPreimage != "" {
1125
+ preimage , err := lntypes .MakePreimageFromStr (
1126
+ payment .PaymentPreimage ,
1127
+ )
1128
+ if err != nil {
1129
+ return nil , err
1130
+ }
1131
+ pmt .Preimage = & preimage
1132
+ }
1133
+
1134
+ payments [i ] = pmt
1135
+ }
1136
+
1137
+ return & ListPaymentsResponse {
1138
+ FirstIndexOffset : resp .FirstIndexOffset ,
1139
+ LastIndexOffset : resp .LastIndexOffset ,
1140
+ Payments : payments ,
1141
+ }, nil
1142
+ }
1143
+
1025
1144
// ChannelBackup retrieves the backup for a particular channel. The backup is
1026
1145
// returned as an encrypted chanbackup.Single payload.
1027
1146
func (s * lightningClient ) ChannelBackup (ctx context.Context ,
0 commit comments