• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 16293644297

15 Jul 2025 12:45PM UTC coverage: 66.709% (-0.6%) from 67.338%
16293644297

Pull #9822

github

web-flow
Merge 488cb4d5f into df6c02e3a
Pull Request #9822: POC Payment SQL Support

805 of 2899 new or added lines in 27 files covered. (27.77%)

102 existing lines in 22 files now uncovered.

135484 of 203097 relevant lines covered (66.71%)

21549.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sqldb/sqlc/payments.sql.go
1
// Code generated by sqlc. DO NOT EDIT.
2
// versions:
3
//   sqlc v1.29.0
4
// source: payments.sql
5

6
package sqlc
7

8
import (
9
        "context"
10
        "database/sql"
11
        "time"
12
)
13

14
const deleteFailedAttempts = `-- name: DeleteFailedAttempts :exec
15
DELETE FROM payment_htlc_attempts WHERE payment_id = $1 AND htlc_fail_reason IS NOT NULL
16
`
17

NEW
18
func (q *Queries) DeleteFailedAttempts(ctx context.Context, paymentID int64) error {
×
NEW
19
        _, err := q.db.ExecContext(ctx, deleteFailedAttempts, paymentID)
×
NEW
20
        return err
×
NEW
21
}
×
22

23
const deleteHTLCAttempt = `-- name: DeleteHTLCAttempt :exec
24
DELETE FROM payment_htlc_attempts WHERE attempt_index = $1
25
`
26

27
// Delete a single HTLC attempt by its index.
NEW
28
func (q *Queries) DeleteHTLCAttempt(ctx context.Context, attemptIndex int64) error {
×
NEW
29
        _, err := q.db.ExecContext(ctx, deleteHTLCAttempt, attemptIndex)
×
NEW
30
        return err
×
NEW
31
}
×
32

33
const deletePayment = `-- name: DeletePayment :exec
34
/* ─────────────────────────────────────────────
35
   delete queries
36
   ─────────────────────────────────────────────
37
*/
38

39
DELETE FROM payments WHERE payment_hash = $1
40
`
41

NEW
42
func (q *Queries) DeletePayment(ctx context.Context, paymentHash []byte) error {
×
NEW
43
        _, err := q.db.ExecContext(ctx, deletePayment, paymentHash)
×
NEW
44
        return err
×
NEW
45
}
×
46

47
const deletePaymentByID = `-- name: DeletePaymentByID :exec
48
DELETE FROM payments WHERE id = $1
49
`
50

NEW
51
func (q *Queries) DeletePaymentByID(ctx context.Context, id int64) error {
×
NEW
52
        _, err := q.db.ExecContext(ctx, deletePaymentByID, id)
×
NEW
53
        return err
×
NEW
54
}
×
55

56
const fetchCustomRecordsForHop = `-- name: FetchCustomRecordsForHop :many
57
SELECT id, key, value, hop_id FROM payment_route_hop_custom_records WHERE hop_id = $1
58
`
59

NEW
60
func (q *Queries) FetchCustomRecordsForHop(ctx context.Context, hopID int64) ([]PaymentRouteHopCustomRecord, error) {
×
NEW
61
        rows, err := q.db.QueryContext(ctx, fetchCustomRecordsForHop, hopID)
×
NEW
62
        if err != nil {
×
NEW
63
                return nil, err
×
NEW
64
        }
×
NEW
65
        defer rows.Close()
×
NEW
66
        var items []PaymentRouteHopCustomRecord
×
NEW
67
        for rows.Next() {
×
NEW
68
                var i PaymentRouteHopCustomRecord
×
NEW
69
                if err := rows.Scan(
×
NEW
70
                        &i.ID,
×
NEW
71
                        &i.Key,
×
NEW
72
                        &i.Value,
×
NEW
73
                        &i.HopID,
×
NEW
74
                ); err != nil {
×
NEW
75
                        return nil, err
×
NEW
76
                }
×
NEW
77
                items = append(items, i)
×
78
        }
NEW
79
        if err := rows.Close(); err != nil {
×
NEW
80
                return nil, err
×
NEW
81
        }
×
NEW
82
        if err := rows.Err(); err != nil {
×
NEW
83
                return nil, err
×
NEW
84
        }
×
NEW
85
        return items, nil
×
86
}
87

88
const fetchDuplicateHopCustomRecordsForHop = `-- name: FetchDuplicateHopCustomRecordsForHop :many
89
SELECT id, key, value, hop_id FROM duplicate_payment_route_hop_custom_records WHERE hop_id = $1
90
`
91

NEW
92
func (q *Queries) FetchDuplicateHopCustomRecordsForHop(ctx context.Context, hopID int64) ([]DuplicatePaymentRouteHopCustomRecord, error) {
×
NEW
93
        rows, err := q.db.QueryContext(ctx, fetchDuplicateHopCustomRecordsForHop, hopID)
×
NEW
94
        if err != nil {
×
NEW
95
                return nil, err
×
NEW
96
        }
×
NEW
97
        defer rows.Close()
×
NEW
98
        var items []DuplicatePaymentRouteHopCustomRecord
×
NEW
99
        for rows.Next() {
×
NEW
100
                var i DuplicatePaymentRouteHopCustomRecord
×
NEW
101
                if err := rows.Scan(
×
NEW
102
                        &i.ID,
×
NEW
103
                        &i.Key,
×
NEW
104
                        &i.Value,
×
NEW
105
                        &i.HopID,
×
NEW
106
                ); err != nil {
×
NEW
107
                        return nil, err
×
NEW
108
                }
×
NEW
109
                items = append(items, i)
×
110
        }
NEW
111
        if err := rows.Close(); err != nil {
×
NEW
112
                return nil, err
×
NEW
113
        }
×
NEW
114
        if err := rows.Err(); err != nil {
×
NEW
115
                return nil, err
×
NEW
116
        }
×
NEW
117
        return items, nil
×
118
}
119

120
const fetchDuplicateHopsForAttempt = `-- name: FetchDuplicateHopsForAttempt :many
121
SELECT id, htlc_attempt_index, hop_index, pub_key, chan_id, outgoing_time_lock, amt_to_forward, meta_data FROM duplicate_payment_route_hops h
122
WHERE h.htlc_attempt_index = $1
123
ORDER BY h.hop_index ASC
124
`
125

NEW
126
func (q *Queries) FetchDuplicateHopsForAttempt(ctx context.Context, htlcAttemptIndex int64) ([]DuplicatePaymentRouteHop, error) {
×
NEW
127
        rows, err := q.db.QueryContext(ctx, fetchDuplicateHopsForAttempt, htlcAttemptIndex)
×
NEW
128
        if err != nil {
×
NEW
129
                return nil, err
×
NEW
130
        }
×
NEW
131
        defer rows.Close()
×
NEW
132
        var items []DuplicatePaymentRouteHop
×
NEW
133
        for rows.Next() {
×
NEW
134
                var i DuplicatePaymentRouteHop
×
NEW
135
                if err := rows.Scan(
×
NEW
136
                        &i.ID,
×
NEW
137
                        &i.HtlcAttemptIndex,
×
NEW
138
                        &i.HopIndex,
×
NEW
139
                        &i.PubKey,
×
NEW
140
                        &i.ChanID,
×
NEW
141
                        &i.OutgoingTimeLock,
×
NEW
142
                        &i.AmtToForward,
×
NEW
143
                        &i.MetaData,
×
NEW
144
                ); err != nil {
×
NEW
145
                        return nil, err
×
NEW
146
                }
×
NEW
147
                items = append(items, i)
×
148
        }
NEW
149
        if err := rows.Close(); err != nil {
×
NEW
150
                return nil, err
×
NEW
151
        }
×
NEW
152
        if err := rows.Err(); err != nil {
×
NEW
153
                return nil, err
×
NEW
154
        }
×
NEW
155
        return items, nil
×
156
}
157

158
const fetchDuplicateHtlcAttempts = `-- name: FetchDuplicateHtlcAttempts :many
159
SELECT id, attempt_index, duplicate_payment_id, session_key, attempt_time, payment_hash, route_total_timelock, route_total_amount, route_source_key, failure_source_index, htlc_fail_reason, failure_msg, fail_time, settle_preimage, settle_time FROM duplicate_payment_htlc_attempts ha
160
WHERE ha.duplicate_payment_id = $1 
161
    AND (
162
        ($2 = true AND ha.settle_preimage IS NULL AND ha.htlc_fail_reason IS NULL)
163
        OR
164
        ($2 = false OR $2 IS NULL)
165
    )
166
ORDER BY 
167
    CASE WHEN $3 = false OR $3 IS NULL THEN ha.attempt_time END ASC,
168
    CASE WHEN $3 = true THEN ha.attempt_time END DESC
169
`
170

171
type FetchDuplicateHtlcAttemptsParams struct {
172
        DuplicatePaymentID int64
173
        InFlightOnly       interface{}
174
        Reverse            interface{}
175
}
176

177
// Fetch HTLC attempts for duplicate payments
NEW
178
func (q *Queries) FetchDuplicateHtlcAttempts(ctx context.Context, arg FetchDuplicateHtlcAttemptsParams) ([]DuplicatePaymentHtlcAttempt, error) {
×
NEW
179
        rows, err := q.db.QueryContext(ctx, fetchDuplicateHtlcAttempts, arg.DuplicatePaymentID, arg.InFlightOnly, arg.Reverse)
×
NEW
180
        if err != nil {
×
NEW
181
                return nil, err
×
NEW
182
        }
×
NEW
183
        defer rows.Close()
×
NEW
184
        var items []DuplicatePaymentHtlcAttempt
×
NEW
185
        for rows.Next() {
×
NEW
186
                var i DuplicatePaymentHtlcAttempt
×
NEW
187
                if err := rows.Scan(
×
NEW
188
                        &i.ID,
×
NEW
189
                        &i.AttemptIndex,
×
NEW
190
                        &i.DuplicatePaymentID,
×
NEW
191
                        &i.SessionKey,
×
NEW
192
                        &i.AttemptTime,
×
NEW
193
                        &i.PaymentHash,
×
NEW
194
                        &i.RouteTotalTimelock,
×
NEW
195
                        &i.RouteTotalAmount,
×
NEW
196
                        &i.RouteSourceKey,
×
NEW
197
                        &i.FailureSourceIndex,
×
NEW
198
                        &i.HtlcFailReason,
×
NEW
199
                        &i.FailureMsg,
×
NEW
200
                        &i.FailTime,
×
NEW
201
                        &i.SettlePreimage,
×
NEW
202
                        &i.SettleTime,
×
NEW
203
                ); err != nil {
×
NEW
204
                        return nil, err
×
NEW
205
                }
×
NEW
206
                items = append(items, i)
×
207
        }
NEW
208
        if err := rows.Close(); err != nil {
×
NEW
209
                return nil, err
×
NEW
210
        }
×
NEW
211
        if err := rows.Err(); err != nil {
×
NEW
212
                return nil, err
×
NEW
213
        }
×
NEW
214
        return items, nil
×
215
}
216

217
const fetchDuplicatePayments = `-- name: FetchDuplicatePayments :many
218
SELECT id, payment_id, payment_hash, payment_request, amount_msat, created_at, fail_reason FROM duplicate_payments
219
WHERE payment_hash = $1
220
ORDER BY created_at ASC
221
`
222

NEW
223
func (q *Queries) FetchDuplicatePayments(ctx context.Context, paymentHash []byte) ([]DuplicatePayment, error) {
×
NEW
224
        rows, err := q.db.QueryContext(ctx, fetchDuplicatePayments, paymentHash)
×
NEW
225
        if err != nil {
×
NEW
226
                return nil, err
×
NEW
227
        }
×
NEW
228
        defer rows.Close()
×
NEW
229
        var items []DuplicatePayment
×
NEW
230
        for rows.Next() {
×
NEW
231
                var i DuplicatePayment
×
NEW
232
                if err := rows.Scan(
×
NEW
233
                        &i.ID,
×
NEW
234
                        &i.PaymentID,
×
NEW
235
                        &i.PaymentHash,
×
NEW
236
                        &i.PaymentRequest,
×
NEW
237
                        &i.AmountMsat,
×
NEW
238
                        &i.CreatedAt,
×
NEW
239
                        &i.FailReason,
×
NEW
240
                ); err != nil {
×
NEW
241
                        return nil, err
×
NEW
242
                }
×
NEW
243
                items = append(items, i)
×
244
        }
NEW
245
        if err := rows.Close(); err != nil {
×
NEW
246
                return nil, err
×
NEW
247
        }
×
NEW
248
        if err := rows.Err(); err != nil {
×
NEW
249
                return nil, err
×
NEW
250
        }
×
NEW
251
        return items, nil
×
252
}
253

254
const fetchFirstHopCustomRecords = `-- name: FetchFirstHopCustomRecords :many
255
SELECT id, key, value, payment_id FROM payment_first_hop_custom_records WHERE payment_id = $1
256
`
257

NEW
258
func (q *Queries) FetchFirstHopCustomRecords(ctx context.Context, paymentID int64) ([]PaymentFirstHopCustomRecord, error) {
×
NEW
259
        rows, err := q.db.QueryContext(ctx, fetchFirstHopCustomRecords, paymentID)
×
NEW
260
        if err != nil {
×
NEW
261
                return nil, err
×
NEW
262
        }
×
NEW
263
        defer rows.Close()
×
NEW
264
        var items []PaymentFirstHopCustomRecord
×
NEW
265
        for rows.Next() {
×
NEW
266
                var i PaymentFirstHopCustomRecord
×
NEW
267
                if err := rows.Scan(
×
NEW
268
                        &i.ID,
×
NEW
269
                        &i.Key,
×
NEW
270
                        &i.Value,
×
NEW
271
                        &i.PaymentID,
×
NEW
272
                ); err != nil {
×
NEW
273
                        return nil, err
×
NEW
274
                }
×
NEW
275
                items = append(items, i)
×
276
        }
NEW
277
        if err := rows.Close(); err != nil {
×
NEW
278
                return nil, err
×
NEW
279
        }
×
NEW
280
        if err := rows.Err(); err != nil {
×
NEW
281
                return nil, err
×
NEW
282
        }
×
NEW
283
        return items, nil
×
284
}
285

286
const fetchHopsForAttempt = `-- name: FetchHopsForAttempt :many
287
SELECT id, htlc_attempt_index, hop_index, pub_key, chan_id, outgoing_time_lock, amt_to_forward, meta_data, legacy_payload, mpp_payment_addr, mpp_total_msat, amp_root_share, amp_set_id, amp_child_index, encrypted_data, blinding_point, blinded_path_total_amt FROM payment_route_hops h
288
WHERE h.htlc_attempt_index = $1
289
ORDER BY h.hop_index ASC
290
`
291

NEW
292
func (q *Queries) FetchHopsForAttempt(ctx context.Context, htlcAttemptIndex int64) ([]PaymentRouteHop, error) {
×
NEW
293
        rows, err := q.db.QueryContext(ctx, fetchHopsForAttempt, htlcAttemptIndex)
×
NEW
294
        if err != nil {
×
NEW
295
                return nil, err
×
NEW
296
        }
×
NEW
297
        defer rows.Close()
×
NEW
298
        var items []PaymentRouteHop
×
NEW
299
        for rows.Next() {
×
NEW
300
                var i PaymentRouteHop
×
NEW
301
                if err := rows.Scan(
×
NEW
302
                        &i.ID,
×
NEW
303
                        &i.HtlcAttemptIndex,
×
NEW
304
                        &i.HopIndex,
×
NEW
305
                        &i.PubKey,
×
NEW
306
                        &i.ChanID,
×
NEW
307
                        &i.OutgoingTimeLock,
×
NEW
308
                        &i.AmtToForward,
×
NEW
309
                        &i.MetaData,
×
NEW
310
                        &i.LegacyPayload,
×
NEW
311
                        &i.MppPaymentAddr,
×
NEW
312
                        &i.MppTotalMsat,
×
NEW
313
                        &i.AmpRootShare,
×
NEW
314
                        &i.AmpSetID,
×
NEW
315
                        &i.AmpChildIndex,
×
NEW
316
                        &i.EncryptedData,
×
NEW
317
                        &i.BlindingPoint,
×
NEW
318
                        &i.BlindedPathTotalAmt,
×
NEW
319
                ); err != nil {
×
NEW
320
                        return nil, err
×
NEW
321
                }
×
NEW
322
                items = append(items, i)
×
323
        }
NEW
324
        if err := rows.Close(); err != nil {
×
NEW
325
                return nil, err
×
NEW
326
        }
×
NEW
327
        if err := rows.Err(); err != nil {
×
NEW
328
                return nil, err
×
NEW
329
        }
×
NEW
330
        return items, nil
×
331
}
332

333
const fetchHtlcAttempts = `-- name: FetchHtlcAttempts :many
334
SELECT id, attempt_index, payment_id, session_key, attempt_time, payment_hash, route_total_timelock, route_total_amount, route_first_hop_amount, route_source_key, failure_source_index, htlc_fail_reason, failure_msg, fail_time, settle_preimage, settle_time FROM payment_htlc_attempts ha
335
WHERE ha.payment_id = $1 
336
    AND (
337
        ($2 = true AND ha.settle_preimage IS NULL AND ha.htlc_fail_reason IS NULL)
338
        OR
339
        ($2 = false OR $2 IS NULL)
340
    )
341
ORDER BY 
342
    CASE WHEN $3 = false OR $3 IS NULL THEN ha.attempt_time END ASC,
343
    CASE WHEN $3 = true THEN ha.attempt_time END DESC
344
`
345

346
type FetchHtlcAttemptsParams struct {
347
        PaymentID    int64
348
        InFlightOnly interface{}
349
        Reverse      interface{}
350
}
351

352
// This will not include the hops for the htlc attempts which can be fetched
353
// with the FetchHopsForAttempt query.
NEW
354
func (q *Queries) FetchHtlcAttempts(ctx context.Context, arg FetchHtlcAttemptsParams) ([]PaymentHtlcAttempt, error) {
×
NEW
355
        rows, err := q.db.QueryContext(ctx, fetchHtlcAttempts, arg.PaymentID, arg.InFlightOnly, arg.Reverse)
×
NEW
356
        if err != nil {
×
NEW
357
                return nil, err
×
NEW
358
        }
×
NEW
359
        defer rows.Close()
×
NEW
360
        var items []PaymentHtlcAttempt
×
NEW
361
        for rows.Next() {
×
NEW
362
                var i PaymentHtlcAttempt
×
NEW
363
                if err := rows.Scan(
×
NEW
364
                        &i.ID,
×
NEW
365
                        &i.AttemptIndex,
×
NEW
366
                        &i.PaymentID,
×
NEW
367
                        &i.SessionKey,
×
NEW
368
                        &i.AttemptTime,
×
NEW
369
                        &i.PaymentHash,
×
NEW
370
                        &i.RouteTotalTimelock,
×
NEW
371
                        &i.RouteTotalAmount,
×
NEW
372
                        &i.RouteFirstHopAmount,
×
NEW
373
                        &i.RouteSourceKey,
×
NEW
374
                        &i.FailureSourceIndex,
×
NEW
375
                        &i.HtlcFailReason,
×
NEW
376
                        &i.FailureMsg,
×
NEW
377
                        &i.FailTime,
×
NEW
378
                        &i.SettlePreimage,
×
NEW
379
                        &i.SettleTime,
×
NEW
380
                ); err != nil {
×
NEW
381
                        return nil, err
×
NEW
382
                }
×
NEW
383
                items = append(items, i)
×
384
        }
NEW
385
        if err := rows.Close(); err != nil {
×
NEW
386
                return nil, err
×
NEW
387
        }
×
NEW
388
        if err := rows.Err(); err != nil {
×
NEW
389
                return nil, err
×
NEW
390
        }
×
NEW
391
        return items, nil
×
392
}
393

394
const fetchInflightHTLCAttempts = `-- name: FetchInflightHTLCAttempts :many
395
SELECT id, attempt_index, payment_id, session_key, attempt_time, payment_hash, route_total_timelock, route_total_amount, route_first_hop_amount, route_source_key, failure_source_index, htlc_fail_reason, failure_msg, fail_time, settle_preimage, settle_time FROM payment_htlc_attempts WHERE  settle_preimage IS NULL AND htlc_fail_reason IS NULL
396
`
397

NEW
398
func (q *Queries) FetchInflightHTLCAttempts(ctx context.Context) ([]PaymentHtlcAttempt, error) {
×
NEW
399
        rows, err := q.db.QueryContext(ctx, fetchInflightHTLCAttempts)
×
NEW
400
        if err != nil {
×
NEW
401
                return nil, err
×
NEW
402
        }
×
NEW
403
        defer rows.Close()
×
NEW
404
        var items []PaymentHtlcAttempt
×
NEW
405
        for rows.Next() {
×
NEW
406
                var i PaymentHtlcAttempt
×
NEW
407
                if err := rows.Scan(
×
NEW
408
                        &i.ID,
×
NEW
409
                        &i.AttemptIndex,
×
NEW
410
                        &i.PaymentID,
×
NEW
411
                        &i.SessionKey,
×
NEW
412
                        &i.AttemptTime,
×
NEW
413
                        &i.PaymentHash,
×
NEW
414
                        &i.RouteTotalTimelock,
×
NEW
415
                        &i.RouteTotalAmount,
×
NEW
416
                        &i.RouteFirstHopAmount,
×
NEW
417
                        &i.RouteSourceKey,
×
NEW
418
                        &i.FailureSourceIndex,
×
NEW
419
                        &i.HtlcFailReason,
×
NEW
420
                        &i.FailureMsg,
×
NEW
421
                        &i.FailTime,
×
NEW
422
                        &i.SettlePreimage,
×
NEW
423
                        &i.SettleTime,
×
NEW
424
                ); err != nil {
×
NEW
425
                        return nil, err
×
NEW
426
                }
×
NEW
427
                items = append(items, i)
×
428
        }
NEW
429
        if err := rows.Close(); err != nil {
×
NEW
430
                return nil, err
×
NEW
431
        }
×
NEW
432
        if err := rows.Err(); err != nil {
×
NEW
433
                return nil, err
×
NEW
434
        }
×
NEW
435
        return items, nil
×
436
}
437

438
const fetchPayment = `-- name: FetchPayment :one
439
SELECT id, payment_type, payment_request, amount_msat, created_at, payment_hash, fail_reason, has_duplicate_payment FROM payments WHERE payment_hash = $1
440
`
441

NEW
442
func (q *Queries) FetchPayment(ctx context.Context, paymentHash []byte) (Payment, error) {
×
NEW
443
        row := q.db.QueryRowContext(ctx, fetchPayment, paymentHash)
×
NEW
444
        var i Payment
×
NEW
445
        err := row.Scan(
×
NEW
446
                &i.ID,
×
NEW
447
                &i.PaymentType,
×
NEW
448
                &i.PaymentRequest,
×
NEW
449
                &i.AmountMsat,
×
NEW
450
                &i.CreatedAt,
×
NEW
451
                &i.PaymentHash,
×
NEW
452
                &i.FailReason,
×
NEW
453
                &i.HasDuplicatePayment,
×
NEW
454
        )
×
NEW
455
        return i, err
×
NEW
456
}
×
457

458
const filterPayments = `-- name: FilterPayments :many
459
/* ─────────────────────────────────────────────
460
   fetch queries
461
   ─────────────────────────────────────────────
462
*/
463

464
SELECT id, payment_type, payment_request, amount_msat, created_at, payment_hash, fail_reason, has_duplicate_payment FROM payments
465
WHERE (
466
    -- This will include payments which have the failed reason set. This means
467
    -- that they are not settled however they are still not necessarily failed
468
    -- because they are still in flight but we know for sure that if they are
469
    -- currently in flight that they will transition to failed. This helps us
470
    -- to not fetch payments that we know are failed or will transition to 
471
    -- failed.
472
    ($1 = true AND fail_reason IS NULL) OR
473
    $1 = false OR $1 IS NULL
474
) AND (
475
    -- Optional cursor-based pagination.
476
    $2 IS NULL OR
477
    id >= $2
478
) AND (
479
    id <= $3 OR
480
    $3 IS NULL
481
) AND (
482
    -- Optional date filters.
483
    ($4 IS NULL) OR
484
    ($4 IS NOT NULL AND created_at >= $4)
485
) AND (
486
    created_at < $5 OR
487
    $5 IS NULL
488
)
489
ORDER BY 
490
    CASE WHEN $6 = false OR $6 IS NULL THEN id END ASC,
491
    CASE WHEN $6 = true THEN id END DESC
492
LIMIT $8 OFFSET $7
493
`
494

495
type FilterPaymentsParams struct {
496
        ExcludeFailed  interface{}
497
        IndexOffsetGet interface{}
498
        IndexOffsetLet sql.NullInt64
499
        CreatedAfter   interface{}
500
        CreatedBefore  sql.NullTime
501
        Reverse        interface{}
502
        NumOffset      int32
503
        NumLimit       int32
504
}
505

NEW
506
func (q *Queries) FilterPayments(ctx context.Context, arg FilterPaymentsParams) ([]Payment, error) {
×
NEW
507
        rows, err := q.db.QueryContext(ctx, filterPayments,
×
NEW
508
                arg.ExcludeFailed,
×
NEW
509
                arg.IndexOffsetGet,
×
NEW
510
                arg.IndexOffsetLet,
×
NEW
511
                arg.CreatedAfter,
×
NEW
512
                arg.CreatedBefore,
×
NEW
513
                arg.Reverse,
×
NEW
514
                arg.NumOffset,
×
NEW
515
                arg.NumLimit,
×
NEW
516
        )
×
NEW
517
        if err != nil {
×
NEW
518
                return nil, err
×
NEW
519
        }
×
NEW
520
        defer rows.Close()
×
NEW
521
        var items []Payment
×
NEW
522
        for rows.Next() {
×
NEW
523
                var i Payment
×
NEW
524
                if err := rows.Scan(
×
NEW
525
                        &i.ID,
×
NEW
526
                        &i.PaymentType,
×
NEW
527
                        &i.PaymentRequest,
×
NEW
528
                        &i.AmountMsat,
×
NEW
529
                        &i.CreatedAt,
×
NEW
530
                        &i.PaymentHash,
×
NEW
531
                        &i.FailReason,
×
NEW
532
                        &i.HasDuplicatePayment,
×
NEW
533
                ); err != nil {
×
NEW
534
                        return nil, err
×
NEW
535
                }
×
NEW
536
                items = append(items, i)
×
537
        }
NEW
538
        if err := rows.Close(); err != nil {
×
NEW
539
                return nil, err
×
NEW
540
        }
×
NEW
541
        if err := rows.Err(); err != nil {
×
NEW
542
                return nil, err
×
NEW
543
        }
×
NEW
544
        return items, nil
×
545
}
546

547
const insertDuplicateHop = `-- name: InsertDuplicateHop :one
548
INSERT INTO duplicate_payment_route_hops (
549
    htlc_attempt_index,
550
    hop_index,
551
    pub_key,
552
    chan_id,
553
    outgoing_time_lock,
554
    amt_to_forward,
555
    meta_data
556
) VALUES ($1, $2, $3, $4,
557
 $5, $6, $7) RETURNING id
558
`
559

560
type InsertDuplicateHopParams struct {
561
        HtlcAttemptIndex int64
562
        HopIndex         int32
563
        PubKey           []byte
564
        ChanID           string
565
        OutgoingTimeLock int32
566
        AmtToForward     int64
567
        MetaData         []byte
568
}
569

NEW
570
func (q *Queries) InsertDuplicateHop(ctx context.Context, arg InsertDuplicateHopParams) (int64, error) {
×
NEW
571
        row := q.db.QueryRowContext(ctx, insertDuplicateHop,
×
NEW
572
                arg.HtlcAttemptIndex,
×
NEW
573
                arg.HopIndex,
×
NEW
574
                arg.PubKey,
×
NEW
575
                arg.ChanID,
×
NEW
576
                arg.OutgoingTimeLock,
×
NEW
577
                arg.AmtToForward,
×
NEW
578
                arg.MetaData,
×
NEW
579
        )
×
NEW
580
        var id int64
×
NEW
581
        err := row.Scan(&id)
×
NEW
582
        return id, err
×
NEW
583
}
×
584

585
const insertDuplicateHopCustomRecord = `-- name: InsertDuplicateHopCustomRecord :exec
586
INSERT INTO duplicate_payment_route_hop_custom_records (
587
    hop_id,
588
    key,
589
    value
590
) VALUES ($1, $2, $3)
591
`
592

593
type InsertDuplicateHopCustomRecordParams struct {
594
        HopID int64
595
        Key   int64
596
        Value []byte
597
}
598

NEW
599
func (q *Queries) InsertDuplicateHopCustomRecord(ctx context.Context, arg InsertDuplicateHopCustomRecordParams) error {
×
NEW
600
        _, err := q.db.ExecContext(ctx, insertDuplicateHopCustomRecord, arg.HopID, arg.Key, arg.Value)
×
NEW
601
        return err
×
NEW
602
}
×
603

604
const insertDuplicateHtlcAttempt = `-- name: InsertDuplicateHtlcAttempt :one
605
INSERT INTO duplicate_payment_htlc_attempts (
606
    attempt_index,
607
    duplicate_payment_id,
608
    payment_hash,
609
    attempt_time,
610
    session_key,
611
    route_total_timeLock,
612
    route_total_amount,
613
    route_source_key
614
) VALUES ($1, $2, $3, $4, 
615
$5, $6, $7, 
616
$8) RETURNING id
617
`
618

619
type InsertDuplicateHtlcAttemptParams struct {
620
        AttemptIndex       int64
621
        DuplicatePaymentID int64
622
        PaymentHash        []byte
623
        AttemptTime        time.Time
624
        SessionKey         []byte
625
        RouteTotalTimelock int32
626
        RouteTotalAmount   int64
627
        RouteSourceKey     []byte
628
}
629

NEW
630
func (q *Queries) InsertDuplicateHtlcAttempt(ctx context.Context, arg InsertDuplicateHtlcAttemptParams) (int64, error) {
×
NEW
631
        row := q.db.QueryRowContext(ctx, insertDuplicateHtlcAttempt,
×
NEW
632
                arg.AttemptIndex,
×
NEW
633
                arg.DuplicatePaymentID,
×
NEW
634
                arg.PaymentHash,
×
NEW
635
                arg.AttemptTime,
×
NEW
636
                arg.SessionKey,
×
NEW
637
                arg.RouteTotalTimelock,
×
NEW
638
                arg.RouteTotalAmount,
×
NEW
639
                arg.RouteSourceKey,
×
NEW
640
        )
×
NEW
641
        var id int64
×
NEW
642
        err := row.Scan(&id)
×
NEW
643
        return id, err
×
NEW
644
}
×
645

646
const insertDuplicatePayment = `-- name: InsertDuplicatePayment :one
647
INSERT INTO duplicate_payments (
648
    payment_hash,
649
    payment_request,
650
    amount_msat,
651
    created_at,
652
    fail_reason
653
) VALUES (
654
    $1, $2,
655
    $3, $4, $5
656
) RETURNING id
657
`
658

659
type InsertDuplicatePaymentParams struct {
660
        PaymentHash    []byte
661
        PaymentRequest []byte
662
        AmountMsat     int64
663
        CreatedAt      time.Time
664
        FailReason     sql.NullInt32
665
}
666

NEW
667
func (q *Queries) InsertDuplicatePayment(ctx context.Context, arg InsertDuplicatePaymentParams) (int64, error) {
×
NEW
668
        row := q.db.QueryRowContext(ctx, insertDuplicatePayment,
×
NEW
669
                arg.PaymentHash,
×
NEW
670
                arg.PaymentRequest,
×
NEW
671
                arg.AmountMsat,
×
NEW
672
                arg.CreatedAt,
×
NEW
673
                arg.FailReason,
×
NEW
674
        )
×
NEW
675
        var id int64
×
NEW
676
        err := row.Scan(&id)
×
NEW
677
        return id, err
×
NEW
678
}
×
679

680
const insertFirstHopCustomRecord = `-- name: InsertFirstHopCustomRecord :exec
681
INSERT INTO payment_first_hop_custom_records (
682
    payment_id,
683
    key,
684
    value
685
) VALUES ($1, $2, $3)
686
`
687

688
type InsertFirstHopCustomRecordParams struct {
689
        PaymentID int64
690
        Key       int64
691
        Value     []byte
692
}
693

NEW
694
func (q *Queries) InsertFirstHopCustomRecord(ctx context.Context, arg InsertFirstHopCustomRecordParams) error {
×
NEW
695
        _, err := q.db.ExecContext(ctx, insertFirstHopCustomRecord, arg.PaymentID, arg.Key, arg.Value)
×
NEW
696
        return err
×
NEW
697
}
×
698

699
const insertHop = `-- name: InsertHop :one
700
INSERT INTO payment_route_hops (
701
    htlc_attempt_index,
702
    hop_index,
703
    pub_key,
704
    chan_id,
705
    outgoing_time_lock,
706
    amt_to_forward,
707
    meta_data,
708
    legacy_payload,
709
    mpp_payment_addr,
710
    mpp_total_msat,
711
    amp_root_share,
712
    amp_set_id,
713
    amp_child_index,
714
    encrypted_data,
715
    blinding_point,
716
    blinded_path_total_amt
717
) VALUES ($1, $2, $3, $4,
718
 $5, $6, $7, $8,
719
$9, $10, $11, $12,
720
$13, $14, $15, 
721
$16) RETURNING id
722
`
723

724
type InsertHopParams struct {
725
        HtlcAttemptIndex    int64
726
        HopIndex            int32
727
        PubKey              []byte
728
        ChanID              string
729
        OutgoingTimeLock    int32
730
        AmtToForward        int64
731
        MetaData            []byte
732
        LegacyPayload       bool
733
        MppPaymentAddr      []byte
734
        MppTotalMsat        sql.NullInt64
735
        AmpRootShare        []byte
736
        AmpSetID            []byte
737
        AmpChildIndex       sql.NullInt32
738
        EncryptedData       []byte
739
        BlindingPoint       []byte
740
        BlindedPathTotalAmt sql.NullInt64
741
}
742

NEW
743
func (q *Queries) InsertHop(ctx context.Context, arg InsertHopParams) (int64, error) {
×
NEW
744
        row := q.db.QueryRowContext(ctx, insertHop,
×
NEW
745
                arg.HtlcAttemptIndex,
×
NEW
746
                arg.HopIndex,
×
NEW
747
                arg.PubKey,
×
NEW
748
                arg.ChanID,
×
NEW
749
                arg.OutgoingTimeLock,
×
NEW
750
                arg.AmtToForward,
×
NEW
751
                arg.MetaData,
×
NEW
752
                arg.LegacyPayload,
×
NEW
753
                arg.MppPaymentAddr,
×
NEW
754
                arg.MppTotalMsat,
×
NEW
755
                arg.AmpRootShare,
×
NEW
756
                arg.AmpSetID,
×
NEW
757
                arg.AmpChildIndex,
×
NEW
758
                arg.EncryptedData,
×
NEW
759
                arg.BlindingPoint,
×
NEW
760
                arg.BlindedPathTotalAmt,
×
NEW
761
        )
×
NEW
762
        var id int64
×
NEW
763
        err := row.Scan(&id)
×
NEW
764
        return id, err
×
NEW
765
}
×
766

767
const insertHopCustomRecord = `-- name: InsertHopCustomRecord :exec
768
INSERT INTO payment_route_hop_custom_records (
769
    hop_id,
770
    key,
771
    value
772
) VALUES ($1, $2, $3)
773
`
774

775
type InsertHopCustomRecordParams struct {
776
        HopID int64
777
        Key   int64
778
        Value []byte
779
}
780

NEW
781
func (q *Queries) InsertHopCustomRecord(ctx context.Context, arg InsertHopCustomRecordParams) error {
×
NEW
782
        _, err := q.db.ExecContext(ctx, insertHopCustomRecord, arg.HopID, arg.Key, arg.Value)
×
NEW
783
        return err
×
NEW
784
}
×
785

786
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
787
INSERT INTO payment_htlc_attempts (
788
    attempt_index,
789
    payment_id,
790
    payment_hash,
791
    attempt_time,
792
    session_key,
793
    route_total_timeLock,
794
    route_total_amount,
795
    route_first_hop_amount,
796
    route_source_key
797
) VALUES ($1, $2, $3, $4, 
798
$5, $6, $7, 
799
$8, $9) RETURNING id
800
`
801

802
type InsertHtlcAttemptParams struct {
803
        AttemptIndex        int64
804
        PaymentID           int64
805
        PaymentHash         []byte
806
        AttemptTime         time.Time
807
        SessionKey          []byte
808
        RouteTotalTimelock  int32
809
        RouteTotalAmount    int64
810
        RouteFirstHopAmount sql.NullInt64
811
        RouteSourceKey      []byte
812
}
813

NEW
814
func (q *Queries) InsertHtlcAttempt(ctx context.Context, arg InsertHtlcAttemptParams) (int64, error) {
×
NEW
815
        row := q.db.QueryRowContext(ctx, insertHtlcAttempt,
×
NEW
816
                arg.AttemptIndex,
×
NEW
817
                arg.PaymentID,
×
NEW
818
                arg.PaymentHash,
×
NEW
819
                arg.AttemptTime,
×
NEW
820
                arg.SessionKey,
×
NEW
821
                arg.RouteTotalTimelock,
×
NEW
822
                arg.RouteTotalAmount,
×
NEW
823
                arg.RouteFirstHopAmount,
×
NEW
824
                arg.RouteSourceKey,
×
NEW
825
        )
×
NEW
826
        var id int64
×
NEW
827
        err := row.Scan(&id)
×
NEW
828
        return id, err
×
NEW
829
}
×
830

831
const insertPayment = `-- name: InsertPayment :one
832
/* ─────────────────────────────────────────────
833
   insert queries
834
   ─────────────────────────────────────────────
835
*/
836

837
INSERT INTO payments (
838
    payment_type, 
839
    payment_request, 
840
    amount_msat, 
841
    created_at,
842
    payment_hash
843
) VALUES (
844
    $1, $2, 
845
    $3, $4, $5
846
) RETURNING id
847
`
848

849
type InsertPaymentParams struct {
850
        PaymentType    sql.NullInt32
851
        PaymentRequest []byte
852
        AmountMsat     int64
853
        CreatedAt      time.Time
854
        PaymentHash    []byte
855
}
856

NEW
857
func (q *Queries) InsertPayment(ctx context.Context, arg InsertPaymentParams) (int64, error) {
×
NEW
858
        row := q.db.QueryRowContext(ctx, insertPayment,
×
NEW
859
                arg.PaymentType,
×
NEW
860
                arg.PaymentRequest,
×
NEW
861
                arg.AmountMsat,
×
NEW
862
                arg.CreatedAt,
×
NEW
863
                arg.PaymentHash,
×
NEW
864
        )
×
NEW
865
        var id int64
×
NEW
866
        err := row.Scan(&id)
×
NEW
867
        return id, err
×
NEW
868
}
×
869

870
const nextHtlcAttemptIndex = `-- name: NextHtlcAttemptIndex :one
871
/* ─────────────────────────────────────────────
872
   sequence number queries
873
   ─────────────────────────────────────────────
874
*/
875

876
UPDATE payment_sequences 
877
SET current_value = current_value + 1 
878
WHERE name = 'htlc_attempt_index' 
879
RETURNING current_value
880
`
881

NEW
882
func (q *Queries) NextHtlcAttemptIndex(ctx context.Context) (int64, error) {
×
NEW
883
        row := q.db.QueryRowContext(ctx, nextHtlcAttemptIndex)
×
NEW
884
        var current_value int64
×
NEW
885
        err := row.Scan(&current_value)
×
NEW
886
        return current_value, err
×
NEW
887
}
×
888

889
const updateHtlcAttemptFailInfo = `-- name: UpdateHtlcAttemptFailInfo :one
890
UPDATE payment_htlc_attempts 
891
SET failure_source_index = $1, 
892
htlc_fail_reason = $2, failure_msg = $3,
893
 fail_time = $4
894
WHERE attempt_index = $5
895
RETURNING id
896
`
897

898
type UpdateHtlcAttemptFailInfoParams struct {
899
        FailureSourceIndex sql.NullInt32
900
        HtlcFailReason     sql.NullInt32
901
        FailureMsg         []byte
902
        FailTime           sql.NullTime
903
        AttemptIndex       int64
904
}
905

NEW
906
func (q *Queries) UpdateHtlcAttemptFailInfo(ctx context.Context, arg UpdateHtlcAttemptFailInfoParams) (int64, error) {
×
NEW
907
        row := q.db.QueryRowContext(ctx, updateHtlcAttemptFailInfo,
×
NEW
908
                arg.FailureSourceIndex,
×
NEW
909
                arg.HtlcFailReason,
×
NEW
910
                arg.FailureMsg,
×
NEW
911
                arg.FailTime,
×
NEW
912
                arg.AttemptIndex,
×
NEW
913
        )
×
NEW
914
        var id int64
×
NEW
915
        err := row.Scan(&id)
×
NEW
916
        return id, err
×
NEW
917
}
×
918

919
const updateHtlcAttemptSettleInfo = `-- name: UpdateHtlcAttemptSettleInfo :one
920
/* ─────────────────────────────────────────────
921
   update queries
922
   ─────────────────────────────────────────────
923
*/
924

925
UPDATE payment_htlc_attempts 
926
SET settle_preimage = $1, settle_time = $2 
927
WHERE attempt_index = $3
928
RETURNING id
929
`
930

931
type UpdateHtlcAttemptSettleInfoParams struct {
932
        SettlePreimage []byte
933
        SettleTime     sql.NullTime
934
        AttemptIndex   int64
935
}
936

NEW
937
func (q *Queries) UpdateHtlcAttemptSettleInfo(ctx context.Context, arg UpdateHtlcAttemptSettleInfoParams) (int64, error) {
×
NEW
938
        row := q.db.QueryRowContext(ctx, updateHtlcAttemptSettleInfo, arg.SettlePreimage, arg.SettleTime, arg.AttemptIndex)
×
NEW
939
        var id int64
×
NEW
940
        err := row.Scan(&id)
×
NEW
941
        return id, err
×
NEW
942
}
×
943

944
const updatePaymentFailReason = `-- name: UpdatePaymentFailReason :one
945
UPDATE payments 
946
SET fail_reason = $1
947
WHERE payment_hash = $2
948
RETURNING id
949
`
950

951
type UpdatePaymentFailReasonParams struct {
952
        FailReason  sql.NullInt32
953
        PaymentHash []byte
954
}
955

NEW
956
func (q *Queries) UpdatePaymentFailReason(ctx context.Context, arg UpdatePaymentFailReasonParams) (int64, error) {
×
NEW
957
        row := q.db.QueryRowContext(ctx, updatePaymentFailReason, arg.FailReason, arg.PaymentHash)
×
NEW
958
        var id int64
×
NEW
959
        err := row.Scan(&id)
×
NEW
960
        return id, err
×
NEW
961
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc