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

lightningnetwork / lnd / 24164304806

08 Apr 2026 11:38PM UTC coverage: 51.215% (-10.9%) from 62.138%
24164304806

Pull #10713

github

web-flow
Merge 0acbe9840 into cb0474885
Pull Request #10713: onionmessage+peer: rate-limit incoming onion messages per-peer and globally

153 of 261 new or added lines in 7 files covered. (58.62%)

25115 existing lines in 293 files now uncovered.

115499 of 225518 relevant lines covered (51.21%)

19525.63 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
        "strings"
12
        "time"
13
)
14

15
const countPayments = `-- name: CountPayments :one
16
SELECT COUNT(*) FROM payments
17
`
18

19
func (q *Queries) CountPayments(ctx context.Context) (int64, error) {
×
20
        row := q.db.QueryRowContext(ctx, countPayments)
×
21
        var count int64
×
22
        err := row.Scan(&count)
×
23
        return count, err
×
24
}
×
25

26
const deleteFailedAttempts = `-- name: DeleteFailedAttempts :exec
27
DELETE FROM payment_htlc_attempts
28
WHERE payment_id = $1
29
AND EXISTS (
30
    SELECT 1 FROM payment_htlc_attempt_resolutions hr
31
    WHERE hr.attempt_index = payment_htlc_attempts.attempt_index
32
    AND hr.resolution_type = 2
33
)
34
`
35

36
// Delete all failed HTLC attempts for the given payment. Resolution type 2
37
// indicates a failed attempt. Uses EXISTS to scope the resolution lookup to
38
// only this payment's attempts, avoiding an O(N) scan of all failed
39
// resolutions across all payments.
40
func (q *Queries) DeleteFailedAttempts(ctx context.Context, paymentID int64) error {
×
41
        _, err := q.db.ExecContext(ctx, deleteFailedAttempts, paymentID)
×
42
        return err
×
43
}
×
44

45
const deletePayment = `-- name: DeletePayment :exec
46
DELETE FROM payments WHERE id = $1
47
`
48

49
func (q *Queries) DeletePayment(ctx context.Context, id int64) error {
×
50
        _, err := q.db.ExecContext(ctx, deletePayment, id)
×
51
        return err
×
52
}
×
53

54
const failAttempt = `-- name: FailAttempt :exec
55
INSERT INTO payment_htlc_attempt_resolutions (
56
    attempt_index,
57
    resolution_time,
58
    resolution_type,
59
    failure_source_index,
60
    htlc_fail_reason,
61
    failure_msg
62
)
63
VALUES (
64
    $1,
65
    $2,
66
    $3,
67
    $4,
68
    $5,
69
    $6
70
)
71
`
72

73
type FailAttemptParams struct {
74
        AttemptIndex       int64
75
        ResolutionTime     time.Time
76
        ResolutionType     int32
77
        FailureSourceIndex sql.NullInt32
78
        HtlcFailReason     sql.NullInt32
79
        FailureMsg         []byte
80
}
81

82
func (q *Queries) FailAttempt(ctx context.Context, arg FailAttemptParams) error {
×
83
        _, err := q.db.ExecContext(ctx, failAttempt,
×
84
                arg.AttemptIndex,
×
85
                arg.ResolutionTime,
×
86
                arg.ResolutionType,
×
87
                arg.FailureSourceIndex,
×
88
                arg.HtlcFailReason,
×
89
                arg.FailureMsg,
×
90
        )
×
91
        return err
×
92
}
×
93

94
const failPayment = `-- name: FailPayment :execresult
95
UPDATE payments SET fail_reason = $1 WHERE payment_identifier = $2
96
`
97

98
type FailPaymentParams struct {
99
        FailReason        sql.NullInt32
100
        PaymentIdentifier []byte
101
}
102

103
func (q *Queries) FailPayment(ctx context.Context, arg FailPaymentParams) (sql.Result, error) {
×
104
        return q.db.ExecContext(ctx, failPayment, arg.FailReason, arg.PaymentIdentifier)
×
105
}
×
106

107
const fetchAllInflightAttempts = `-- name: FetchAllInflightAttempts :many
108
SELECT
109
    ha.id,
110
    ha.attempt_index,
111
    ha.payment_id,
112
    ha.session_key,
113
    ha.attempt_time,
114
    ha.payment_hash,
115
    ha.first_hop_amount_msat,
116
    ha.route_total_time_lock,
117
    ha.route_total_amount,
UNCOV
118
    ha.route_source_key
×
UNCOV
119
FROM payment_htlc_attempts ha
×
UNCOV
120
WHERE NOT EXISTS (
×
UNCOV
121
    SELECT 1 FROM payment_htlc_attempt_resolutions hr
×
UNCOV
122
    WHERE hr.attempt_index = ha.attempt_index
×
UNCOV
123
)
×
UNCOV
124
AND ha.attempt_index > $1
×
UNCOV
125
ORDER BY ha.attempt_index ASC
×
UNCOV
126
LIMIT $2
×
UNCOV
127
`
×
UNCOV
128

×
UNCOV
129
type FetchAllInflightAttemptsParams struct {
×
UNCOV
130
        AttemptIndex int64
×
UNCOV
131
        Limit        int32
×
UNCOV
132
}
×
UNCOV
133

×
UNCOV
134
// Fetch all inflight attempts with their payment data using pagination.
×
UNCOV
135
// Returns attempt data joined with payment and intent data to avoid separate queries.
×
136
func (q *Queries) FetchAllInflightAttempts(ctx context.Context, arg FetchAllInflightAttemptsParams) ([]PaymentHtlcAttempt, error) {
×
137
        rows, err := q.db.QueryContext(ctx, fetchAllInflightAttempts, arg.AttemptIndex, arg.Limit)
×
138
        if err != nil {
×
139
                return nil, err
×
140
        }
×
141
        defer rows.Close()
×
142
        var items []PaymentHtlcAttempt
×
143
        for rows.Next() {
×
144
                var i PaymentHtlcAttempt
×
145
                if err := rows.Scan(
×
146
                        &i.ID,
147
                        &i.AttemptIndex,
×
148
                        &i.PaymentID,
×
149
                        &i.SessionKey,
×
150
                        &i.AttemptTime,
×
151
                        &i.PaymentHash,
×
152
                        &i.FirstHopAmountMsat,
×
153
                        &i.RouteTotalTimeLock,
×
154
                        &i.RouteTotalAmount,
155
                        &i.RouteSourceKey,
156
                ); err != nil {
157
                        return nil, err
158
                }
159
                items = append(items, i)
160
        }
161
        if err := rows.Close(); err != nil {
162
                return nil, err
163
        }
164
        if err := rows.Err(); err != nil {
165
                return nil, err
166
        }
167
        return items, nil
168
}
169

170
const fetchHopLevelCustomRecords = `-- name: FetchHopLevelCustomRecords :many
171
SELECT
172
    l.id,
173
    l.hop_id,
174
    l.key,
175
    l.value
176
FROM payment_hop_custom_records l
177
WHERE l.hop_id IN (/*SLICE:hop_ids*/?)
178
ORDER BY l.hop_id ASC, l.key ASC
179
`
180

181
func (q *Queries) FetchHopLevelCustomRecords(ctx context.Context, hopIds []int64) ([]PaymentHopCustomRecord, error) {
182
        query := fetchHopLevelCustomRecords
183
        var queryParams []interface{}
184
        if len(hopIds) > 0 {
185
                for _, v := range hopIds {
186
                        queryParams = append(queryParams, v)
187
                }
188
                query = strings.Replace(query, "/*SLICE:hop_ids*/?", makeQueryParams(len(queryParams), len(hopIds)), 1)
189
        } else {
190
                query = strings.Replace(query, "/*SLICE:hop_ids*/?", "NULL", 1)
191
        }
192
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
193
        if err != nil {
194
                return nil, err
195
        }
196
        defer rows.Close()
197
        var items []PaymentHopCustomRecord
198
        for rows.Next() {
199
                var i PaymentHopCustomRecord
200
                if err := rows.Scan(
201
                        &i.ID,
×
202
                        &i.HopID,
×
203
                        &i.Key,
×
204
                        &i.Value,
×
205
                ); err != nil {
×
206
                        return nil, err
×
207
                }
×
208
                items = append(items, i)
×
UNCOV
209
        }
×
210
        if err := rows.Close(); err != nil {
×
211
                return nil, err
×
212
        }
×
213
        if err := rows.Err(); err != nil {
×
214
                return nil, err
×
215
        }
×
216
        return items, nil
×
UNCOV
217
}
×
UNCOV
218

×
UNCOV
219
const fetchHopsForAttempts = `-- name: FetchHopsForAttempts :many
×
UNCOV
220
SELECT
×
UNCOV
221
    h.id,
×
UNCOV
222
    h.htlc_attempt_index,
×
UNCOV
223
    h.hop_index,
×
UNCOV
224
    h.pub_key,
×
UNCOV
225
    h.scid,
×
UNCOV
226
    h.outgoing_time_lock,
×
UNCOV
227
    h.amt_to_forward,
×
UNCOV
228
    h.meta_data,
×
UNCOV
229
    m.payment_addr AS mpp_payment_addr,
×
UNCOV
230
    m.total_msat AS mpp_total_msat,
×
UNCOV
231
    a.root_share AS amp_root_share,
×
UNCOV
232
    a.set_id AS amp_set_id,
×
UNCOV
233
    a.child_index AS amp_child_index,
×
UNCOV
234
    b.encrypted_data,
×
UNCOV
235
    b.blinding_point,
×
UNCOV
236
    b.blinded_path_total_amt
×
UNCOV
237
FROM payment_route_hops h
×
UNCOV
238
LEFT JOIN payment_route_hop_mpp m ON m.hop_id = h.id
×
UNCOV
239
LEFT JOIN payment_route_hop_amp a ON a.hop_id = h.id
×
UNCOV
240
LEFT JOIN payment_route_hop_blinded b ON b.hop_id = h.id
×
241
WHERE h.htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
UNCOV
242
ORDER BY h.htlc_attempt_index ASC, h.hop_index ASC
×
UNCOV
243
`
×
UNCOV
244

×
UNCOV
245
type FetchHopsForAttemptsRow struct {
×
UNCOV
246
        ID                  int64
×
UNCOV
247
        HtlcAttemptIndex    int64
×
UNCOV
248
        HopIndex            int32
×
249
        PubKey              []byte
250
        Scid                string
251
        OutgoingTimeLock    int32
252
        AmtToForward        int64
253
        MetaData            []byte
254
        MppPaymentAddr      []byte
255
        MppTotalMsat        sql.NullInt64
256
        AmpRootShare        []byte
257
        AmpSetID            []byte
258
        AmpChildIndex       sql.NullInt32
259
        EncryptedData       []byte
260
        BlindingPoint       []byte
261
        BlindedPathTotalAmt sql.NullInt64
262
}
263

264
func (q *Queries) FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices []int64) ([]FetchHopsForAttemptsRow, error) {
265
        query := fetchHopsForAttempts
266
        var queryParams []interface{}
267
        if len(htlcAttemptIndices) > 0 {
268
                for _, v := range htlcAttemptIndices {
×
269
                        queryParams = append(queryParams, v)
×
270
                }
×
271
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", makeQueryParams(len(queryParams), len(htlcAttemptIndices)), 1)
×
272
        } else {
×
273
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", "NULL", 1)
×
274
        }
×
275
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
276
        if err != nil {
×
277
                return nil, err
×
278
        }
×
279
        defer rows.Close()
×
280
        var items []FetchHopsForAttemptsRow
×
281
        for rows.Next() {
×
282
                var i FetchHopsForAttemptsRow
×
283
                if err := rows.Scan(
×
284
                        &i.ID,
×
285
                        &i.HtlcAttemptIndex,
×
286
                        &i.HopIndex,
×
287
                        &i.PubKey,
×
288
                        &i.Scid,
×
289
                        &i.OutgoingTimeLock,
×
290
                        &i.AmtToForward,
×
291
                        &i.MetaData,
292
                        &i.MppPaymentAddr,
×
293
                        &i.MppTotalMsat,
×
294
                        &i.AmpRootShare,
×
295
                        &i.AmpSetID,
×
296
                        &i.AmpChildIndex,
×
297
                        &i.EncryptedData,
×
298
                        &i.BlindingPoint,
×
299
                        &i.BlindedPathTotalAmt,
300
                ); err != nil {
301
                        return nil, err
302
                }
303
                items = append(items, i)
304
        }
305
        if err := rows.Close(); err != nil {
306
                return nil, err
307
        }
308
        if err := rows.Err(); err != nil {
309
                return nil, err
310
        }
311
        return items, nil
312
}
313

314
const fetchHtlcAttemptResolutionsForPayments = `-- name: FetchHtlcAttemptResolutionsForPayments :many
315
SELECT
316
    ha.payment_id,
317
    hr.resolution_type
318
FROM payment_htlc_attempts ha
319
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
320
WHERE ha.payment_id IN (/*SLICE:payment_ids*/?)
321
`
322

323
type FetchHtlcAttemptResolutionsForPaymentsRow struct {
324
        PaymentID      int64
325
        ResolutionType sql.NullInt32
326
}
327

328
// Batch query to fetch only HTLC resolution status for multiple payments.
329
// We don't need to order by payment_id and attempt_time because we will
330
// group the resolutions by payment_id in the background.
331
func (q *Queries) FetchHtlcAttemptResolutionsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptResolutionsForPaymentsRow, error) {
332
        query := fetchHtlcAttemptResolutionsForPayments
333
        var queryParams []interface{}
334
        if len(paymentIds) > 0 {
335
                for _, v := range paymentIds {
336
                        queryParams = append(queryParams, v)
337
                }
338
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
339
        } else {
340
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
341
        }
342
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
343
        if err != nil {
344
                return nil, err
×
345
        }
×
346
        defer rows.Close()
×
347
        var items []FetchHtlcAttemptResolutionsForPaymentsRow
×
348
        for rows.Next() {
×
349
                var i FetchHtlcAttemptResolutionsForPaymentsRow
×
350
                if err := rows.Scan(&i.PaymentID, &i.ResolutionType); err != nil {
×
351
                        return nil, err
×
352
                }
×
353
                items = append(items, i)
×
UNCOV
354
        }
×
355
        if err := rows.Close(); err != nil {
×
356
                return nil, err
×
357
        }
×
358
        if err := rows.Err(); err != nil {
×
359
                return nil, err
×
360
        }
×
361
        return items, nil
×
UNCOV
362
}
×
UNCOV
363

×
UNCOV
364
const fetchHtlcAttemptsForPayments = `-- name: FetchHtlcAttemptsForPayments :many
×
UNCOV
365
SELECT
×
UNCOV
366
    ha.id,
×
UNCOV
367
    ha.attempt_index,
×
UNCOV
368
    ha.payment_id,
×
UNCOV
369
    ha.session_key,
×
UNCOV
370
    ha.attempt_time,
×
UNCOV
371
    ha.payment_hash,
×
UNCOV
372
    ha.first_hop_amount_msat,
×
UNCOV
373
    ha.route_total_time_lock,
×
UNCOV
374
    ha.route_total_amount,
×
UNCOV
375
    ha.route_source_key,
×
UNCOV
376
    hr.resolution_type,
×
UNCOV
377
    hr.resolution_time,
×
UNCOV
378
    hr.failure_source_index,
×
UNCOV
379
    hr.htlc_fail_reason,
×
UNCOV
380
    hr.failure_msg,
×
UNCOV
381
    hr.settle_preimage
×
UNCOV
382
FROM payment_htlc_attempts ha
×
UNCOV
383
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
×
384
WHERE ha.payment_id IN (/*SLICE:payment_ids*/?)
UNCOV
385
ORDER BY ha.payment_id ASC, ha.attempt_time ASC
×
UNCOV
386
`
×
UNCOV
387

×
UNCOV
388
type FetchHtlcAttemptsForPaymentsRow struct {
×
UNCOV
389
        ID                 int64
×
UNCOV
390
        AttemptIndex       int64
×
UNCOV
391
        PaymentID          int64
×
392
        SessionKey         []byte
393
        AttemptTime        time.Time
394
        PaymentHash        []byte
395
        FirstHopAmountMsat int64
396
        RouteTotalTimeLock int32
397
        RouteTotalAmount   int64
398
        RouteSourceKey     []byte
399
        ResolutionType     sql.NullInt32
400
        ResolutionTime     sql.NullTime
401
        FailureSourceIndex sql.NullInt32
402
        HtlcFailReason     sql.NullInt32
403
        FailureMsg         []byte
404
        SettlePreimage     []byte
405
}
406

407
func (q *Queries) FetchHtlcAttemptsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptsForPaymentsRow, error) {
408
        query := fetchHtlcAttemptsForPayments
409
        var queryParams []interface{}
410
        if len(paymentIds) > 0 {
411
                for _, v := range paymentIds {
412
                        queryParams = append(queryParams, v)
413
                }
414
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
415
        } else {
416
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
417
        }
418
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
419
        if err != nil {
420
                return nil, err
421
        }
422
        defer rows.Close()
423
        var items []FetchHtlcAttemptsForPaymentsRow
424
        for rows.Next() {
425
                var i FetchHtlcAttemptsForPaymentsRow
426
                if err := rows.Scan(
427
                        &i.ID,
428
                        &i.AttemptIndex,
429
                        &i.PaymentID,
430
                        &i.SessionKey,
431
                        &i.AttemptTime,
432
                        &i.PaymentHash,
433
                        &i.FirstHopAmountMsat,
434
                        &i.RouteTotalTimeLock,
435
                        &i.RouteTotalAmount,
436
                        &i.RouteSourceKey,
437
                        &i.ResolutionType,
438
                        &i.ResolutionTime,
439
                        &i.FailureSourceIndex,
440
                        &i.HtlcFailReason,
441
                        &i.FailureMsg,
442
                        &i.SettlePreimage,
443
                ); err != nil {
444
                        return nil, err
445
                }
446
                items = append(items, i)
447
        }
448
        if err := rows.Close(); err != nil {
449
                return nil, err
450
        }
451
        if err := rows.Err(); err != nil {
452
                return nil, err
×
453
        }
×
454
        return items, nil
×
UNCOV
455
}
×
UNCOV
456

×
UNCOV
457
const fetchPayment = `-- name: FetchPayment :one
×
UNCOV
458
SELECT
×
UNCOV
459
    p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason,
×
UNCOV
460
    i.intent_type AS "intent_type",
×
UNCOV
461
    i.intent_payload AS "intent_payload"
×
UNCOV
462
FROM payments p
×
UNCOV
463
LEFT JOIN payment_intents i ON i.payment_id = p.id
×
UNCOV
464
WHERE p.payment_identifier = $1
×
UNCOV
465
`
×
UNCOV
466

×
UNCOV
467
type FetchPaymentRow struct {
×
UNCOV
468
        Payment       Payment
×
UNCOV
469
        IntentType    sql.NullInt16
×
UNCOV
470
        IntentPayload []byte
×
UNCOV
471
}
×
UNCOV
472

×
473
func (q *Queries) FetchPayment(ctx context.Context, paymentIdentifier []byte) (FetchPaymentRow, error) {
474
        row := q.db.QueryRowContext(ctx, fetchPayment, paymentIdentifier)
×
475
        var i FetchPaymentRow
×
476
        err := row.Scan(
×
477
                &i.Payment.ID,
×
478
                &i.Payment.AmountMsat,
×
479
                &i.Payment.CreatedAt,
×
480
                &i.Payment.PaymentIdentifier,
×
481
                &i.Payment.FailReason,
482
                &i.IntentType,
483
                &i.IntentPayload,
484
        )
485
        return i, err
486
}
487

488
const fetchPaymentDuplicates = `-- name: FetchPaymentDuplicates :many
489
SELECT
490
    id,
491
    payment_id,
492
    amount_msat,
493
    created_at,
494
    fail_reason,
495
    settle_preimage,
496
    settle_time
497
FROM payment_duplicates
498
WHERE payment_id = $1
UNCOV
499
ORDER BY id ASC
×
UNCOV
500
`
×
UNCOV
501

×
UNCOV
502
// Fetch all duplicate payment records from the payment_duplicates table for
×
UNCOV
503
// a given payment ID.
×
504
func (q *Queries) FetchPaymentDuplicates(ctx context.Context, paymentID int64) ([]PaymentDuplicate, error) {
×
505
        rows, err := q.db.QueryContext(ctx, fetchPaymentDuplicates, paymentID)
×
506
        if err != nil {
×
507
                return nil, err
×
508
        }
×
509
        defer rows.Close()
×
510
        var items []PaymentDuplicate
×
511
        for rows.Next() {
×
512
                var i PaymentDuplicate
×
513
                if err := rows.Scan(
514
                        &i.ID,
515
                        &i.PaymentID,
516
                        &i.AmountMsat,
517
                        &i.CreatedAt,
518
                        &i.FailReason,
519
                        &i.SettlePreimage,
520
                        &i.SettleTime,
521
                ); err != nil {
522
                        return nil, err
523
                }
524
                items = append(items, i)
525
        }
526
        if err := rows.Close(); err != nil {
527
                return nil, err
528
        }
529
        if err := rows.Err(); err != nil {
530
                return nil, err
×
531
        }
×
532
        return items, nil
×
UNCOV
533
}
×
UNCOV
534

×
UNCOV
535
const fetchPaymentLevelFirstHopCustomRecords = `-- name: FetchPaymentLevelFirstHopCustomRecords :many
×
UNCOV
536
SELECT
×
UNCOV
537
    l.id,
×
UNCOV
538
    l.payment_id,
×
UNCOV
539
    l.key,
×
UNCOV
540
    l.value
×
UNCOV
541
FROM payment_first_hop_custom_records l
×
UNCOV
542
WHERE l.payment_id IN (/*SLICE:payment_ids*/?)
×
UNCOV
543
ORDER BY l.payment_id ASC, l.key ASC
×
UNCOV
544
`
×
UNCOV
545

×
546
func (q *Queries) FetchPaymentLevelFirstHopCustomRecords(ctx context.Context, paymentIds []int64) ([]PaymentFirstHopCustomRecord, error) {
×
547
        query := fetchPaymentLevelFirstHopCustomRecords
×
548
        var queryParams []interface{}
×
549
        if len(paymentIds) > 0 {
×
550
                for _, v := range paymentIds {
×
551
                        queryParams = append(queryParams, v)
552
                }
×
553
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
554
        } else {
×
555
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
556
        }
×
557
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
558
        if err != nil {
×
559
                return nil, err
560
        }
561
        defer rows.Close()
562
        var items []PaymentFirstHopCustomRecord
563
        for rows.Next() {
564
                var i PaymentFirstHopCustomRecord
565
                if err := rows.Scan(
566
                        &i.ID,
567
                        &i.PaymentID,
568
                        &i.Key,
569
                        &i.Value,
570
                ); err != nil {
571
                        return nil, err
572
                }
×
573
                items = append(items, i)
×
UNCOV
574
        }
×
575
        if err := rows.Close(); err != nil {
×
576
                return nil, err
×
577
        }
×
578
        if err := rows.Err(); err != nil {
×
579
                return nil, err
×
580
        }
×
581
        return items, nil
×
UNCOV
582
}
×
UNCOV
583

×
UNCOV
584
const fetchPaymentsByIDs = `-- name: FetchPaymentsByIDs :many
×
UNCOV
585
SELECT
×
UNCOV
586
    p.id,
×
UNCOV
587
    p.amount_msat,
×
UNCOV
588
    p.created_at,
×
UNCOV
589
    p.payment_identifier,
×
UNCOV
590
    p.fail_reason,
×
UNCOV
591
    pi.intent_type,
×
UNCOV
592
    pi.intent_payload
×
UNCOV
593
FROM payments p
×
UNCOV
594
LEFT JOIN payment_intents pi ON pi.payment_id = p.id
×
UNCOV
595
WHERE p.id IN (/*SLICE:payment_ids*/?)
×
UNCOV
596
ORDER BY p.id ASC
×
UNCOV
597
`
×
UNCOV
598

×
UNCOV
599
type FetchPaymentsByIDsRow struct {
×
600
        ID                int64
UNCOV
601
        AmountMsat        int64
×
UNCOV
602
        CreatedAt         time.Time
×
UNCOV
603
        PaymentIdentifier []byte
×
UNCOV
604
        FailReason        sql.NullInt32
×
UNCOV
605
        IntentType        sql.NullInt16
×
UNCOV
606
        IntentPayload     []byte
×
UNCOV
607
}
×
608

609
// Batch fetch payment and intent data for a set of payment IDs.
610
// Used to avoid fetching redundant payment data when processing multiple
611
// attempts for the same payment.
612
func (q *Queries) FetchPaymentsByIDs(ctx context.Context, paymentIds []int64) ([]FetchPaymentsByIDsRow, error) {
613
        query := fetchPaymentsByIDs
614
        var queryParams []interface{}
615
        if len(paymentIds) > 0 {
616
                for _, v := range paymentIds {
617
                        queryParams = append(queryParams, v)
618
                }
619
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
620
        } else {
621
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
622
        }
623
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
624
        if err != nil {
625
                return nil, err
626
        }
627
        defer rows.Close()
628
        var items []FetchPaymentsByIDsRow
629
        for rows.Next() {
630
                var i FetchPaymentsByIDsRow
631
                if err := rows.Scan(
632
                        &i.ID,
633
                        &i.AmountMsat,
634
                        &i.CreatedAt,
635
                        &i.PaymentIdentifier,
636
                        &i.FailReason,
637
                        &i.IntentType,
638
                        &i.IntentPayload,
×
639
                ); err != nil {
×
640
                        return nil, err
×
641
                }
×
642
                items = append(items, i)
×
UNCOV
643
        }
×
644
        if err := rows.Close(); err != nil {
×
645
                return nil, err
×
646
        }
×
647
        if err := rows.Err(); err != nil {
×
648
                return nil, err
×
649
        }
×
650
        return items, nil
×
UNCOV
651
}
×
UNCOV
652

×
UNCOV
653
const fetchPaymentsByIDsMig = `-- name: FetchPaymentsByIDsMig :many
×
UNCOV
654
SELECT
×
UNCOV
655
    p.id,
×
UNCOV
656
    p.amount_msat,
×
UNCOV
657
    p.created_at,
×
UNCOV
658
    p.payment_identifier,
×
UNCOV
659
    p.fail_reason,
×
UNCOV
660
    COUNT(ha.id) AS htlc_attempt_count
×
UNCOV
661
FROM payments p
×
UNCOV
662
LEFT JOIN payment_htlc_attempts ha ON ha.payment_id = p.id
×
UNCOV
663
WHERE p.id IN (/*SLICE:payment_ids*/?)
×
UNCOV
664
GROUP BY p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason
×
UNCOV
665
ORDER BY p.id ASC
×
UNCOV
666
`
×
UNCOV
667

×
UNCOV
668
type FetchPaymentsByIDsMigRow struct {
×
669
        ID                int64
UNCOV
670
        AmountMsat        int64
×
UNCOV
671
        CreatedAt         time.Time
×
UNCOV
672
        PaymentIdentifier []byte
×
UNCOV
673
        FailReason        sql.NullInt32
×
UNCOV
674
        HtlcAttemptCount  int64
×
UNCOV
675
}
×
UNCOV
676

×
677
// Migration-specific batch fetch that returns payment data along with HTLC
678
// attempt counts for structural validation during KV to SQL migration.
679
func (q *Queries) FetchPaymentsByIDsMig(ctx context.Context, paymentIds []int64) ([]FetchPaymentsByIDsMigRow, error) {
680
        query := fetchPaymentsByIDsMig
681
        var queryParams []interface{}
682
        if len(paymentIds) > 0 {
683
                for _, v := range paymentIds {
684
                        queryParams = append(queryParams, v)
685
                }
686
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
687
        } else {
688
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
689
        }
690
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
691
        if err != nil {
692
                return nil, err
693
        }
694
        defer rows.Close()
695
        var items []FetchPaymentsByIDsMigRow
696
        for rows.Next() {
697
                var i FetchPaymentsByIDsMigRow
698
                if err := rows.Scan(
699
                        &i.ID,
700
                        &i.AmountMsat,
701
                        &i.CreatedAt,
702
                        &i.PaymentIdentifier,
703
                        &i.FailReason,
704
                        &i.HtlcAttemptCount,
705
                ); err != nil {
×
706
                        return nil, err
×
707
                }
×
708
                items = append(items, i)
×
UNCOV
709
        }
×
710
        if err := rows.Close(); err != nil {
×
711
                return nil, err
×
712
        }
×
713
        if err := rows.Err(); err != nil {
×
714
                return nil, err
×
715
        }
×
716
        return items, nil
×
UNCOV
717
}
×
UNCOV
718

×
UNCOV
719
const fetchRouteLevelFirstHopCustomRecords = `-- name: FetchRouteLevelFirstHopCustomRecords :many
×
UNCOV
720
SELECT
×
UNCOV
721
    l.id,
×
UNCOV
722
    l.htlc_attempt_index,
×
UNCOV
723
    l.key,
×
UNCOV
724
    l.value
×
UNCOV
725
FROM payment_attempt_first_hop_custom_records l
×
UNCOV
726
WHERE l.htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
×
UNCOV
727
ORDER BY l.htlc_attempt_index ASC, l.key ASC
×
UNCOV
728
`
×
UNCOV
729

×
730
func (q *Queries) FetchRouteLevelFirstHopCustomRecords(ctx context.Context, htlcAttemptIndices []int64) ([]PaymentAttemptFirstHopCustomRecord, error) {
×
731
        query := fetchRouteLevelFirstHopCustomRecords
×
732
        var queryParams []interface{}
×
733
        if len(htlcAttemptIndices) > 0 {
×
734
                for _, v := range htlcAttemptIndices {
×
735
                        queryParams = append(queryParams, v)
736
                }
×
737
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", makeQueryParams(len(queryParams), len(htlcAttemptIndices)), 1)
×
738
        } else {
×
739
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", "NULL", 1)
×
740
        }
×
741
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
742
        if err != nil {
×
743
                return nil, err
744
        }
745
        defer rows.Close()
746
        var items []PaymentAttemptFirstHopCustomRecord
747
        for rows.Next() {
748
                var i PaymentAttemptFirstHopCustomRecord
749
                if err := rows.Scan(
750
                        &i.ID,
751
                        &i.HtlcAttemptIndex,
752
                        &i.Key,
753
                        &i.Value,
754
                ); err != nil {
755
                        return nil, err
756
                }
×
757
                items = append(items, i)
×
UNCOV
758
        }
×
759
        if err := rows.Close(); err != nil {
×
760
                return nil, err
×
761
        }
×
762
        if err := rows.Err(); err != nil {
×
763
                return nil, err
×
764
        }
×
765
        return items, nil
×
UNCOV
766
}
×
UNCOV
767

×
UNCOV
768
const filterPayments = `-- name: FilterPayments :many
×
UNCOV
769
/* ─────────────────────────────────────────────
×
UNCOV
770
   fetch queries
×
UNCOV
771
   ─────────────────────────────────────────────
×
UNCOV
772
*/
×
UNCOV
773

×
UNCOV
774
SELECT
×
UNCOV
775
    p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason,
×
UNCOV
776
    i.intent_type AS "intent_type",
×
UNCOV
777
    i.intent_payload AS "intent_payload"
×
UNCOV
778
FROM payments p
×
UNCOV
779
LEFT JOIN payment_intents i ON i.payment_id = p.id
×
UNCOV
780
WHERE p.id > COALESCE($1, -1)
×
UNCOV
781
  AND p.id < COALESCE($2, 9223372036854775807)
×
UNCOV
782
  -- NOTE: We use non-nullable time params with Go-side defaults instead of
×
UNCOV
783
  -- COALESCE, because COALESCE with text fallback causes type mismatch on
×
784
  -- Postgres (timestamp vs text), and OR-based optional filters can prevent
UNCOV
785
  -- the planner from using the created_at index.
×
UNCOV
786
  AND p.created_at >= $3
×
UNCOV
787
  AND p.created_at <= $4
×
UNCOV
788
  AND (
×
UNCOV
789
      i.intent_type = $5 OR
×
UNCOV
790
      $5 IS NULL OR i.intent_type IS NULL
×
UNCOV
791
  )
×
792
ORDER BY p.id ASC
793
LIMIT $6
794
`
795

796
type FilterPaymentsParams struct {
797
        IndexOffsetGet sql.NullInt64
798
        IndexOffsetLet sql.NullInt64
799
        CreatedAfter   time.Time
800
        CreatedBefore  time.Time
801
        IntentType     sql.NullInt16
802
        NumLimit       int32
803
}
804

805
type FilterPaymentsRow struct {
806
        Payment       Payment
807
        IntentType    sql.NullInt16
808
        IntentPayload []byte
809
}
810

811
func (q *Queries) FilterPayments(ctx context.Context, arg FilterPaymentsParams) ([]FilterPaymentsRow, error) {
812
        rows, err := q.db.QueryContext(ctx, filterPayments,
813
                arg.IndexOffsetGet,
814
                arg.IndexOffsetLet,
815
                arg.CreatedAfter,
816
                arg.CreatedBefore,
817
                arg.IntentType,
818
                arg.NumLimit,
819
        )
820
        if err != nil {
821
                return nil, err
822
        }
823
        defer rows.Close()
824
        var items []FilterPaymentsRow
825
        for rows.Next() {
826
                var i FilterPaymentsRow
827
                if err := rows.Scan(
828
                        &i.Payment.ID,
829
                        &i.Payment.AmountMsat,
830
                        &i.Payment.CreatedAt,
831
                        &i.Payment.PaymentIdentifier,
832
                        &i.Payment.FailReason,
833
                        &i.IntentType,
834
                        &i.IntentPayload,
835
                ); err != nil {
836
                        return nil, err
837
                }
×
838
                items = append(items, i)
×
UNCOV
839
        }
×
840
        if err := rows.Close(); err != nil {
×
841
                return nil, err
×
842
        }
×
843
        if err := rows.Err(); err != nil {
×
844
                return nil, err
×
845
        }
×
846
        return items, nil
×
UNCOV
847
}
×
UNCOV
848

×
UNCOV
849
const filterPaymentsDesc = `-- name: FilterPaymentsDesc :many
×
UNCOV
850
SELECT
×
UNCOV
851
    p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason,
×
UNCOV
852
    i.intent_type AS "intent_type",
×
UNCOV
853
    i.intent_payload AS "intent_payload"
×
UNCOV
854
FROM payments p
×
UNCOV
855
LEFT JOIN payment_intents i ON i.payment_id = p.id
×
UNCOV
856
WHERE p.id > COALESCE($1, -1)
×
UNCOV
857
  AND p.id < COALESCE($2, 9223372036854775807)
×
UNCOV
858
  -- NOTE: We use non-nullable time params with Go-side defaults instead of
×
UNCOV
859
  -- COALESCE, because COALESCE with text fallback causes type mismatch on
×
UNCOV
860
  -- Postgres (timestamp vs text), and OR-based optional filters can prevent
×
UNCOV
861
  -- the planner from using the created_at index.
×
UNCOV
862
  AND p.created_at >= $3
×
UNCOV
863
  AND p.created_at <= $4
×
UNCOV
864
  AND (
×
865
      i.intent_type = $5 OR
UNCOV
866
      $5 IS NULL OR i.intent_type IS NULL
×
UNCOV
867
  )
×
UNCOV
868
ORDER BY p.id DESC
×
UNCOV
869
LIMIT $6
×
UNCOV
870
`
×
UNCOV
871

×
UNCOV
872
type FilterPaymentsDescParams struct {
×
873
        IndexOffsetGet sql.NullInt64
874
        IndexOffsetLet sql.NullInt64
875
        CreatedAfter   time.Time
876
        CreatedBefore  time.Time
877
        IntentType     sql.NullInt16
878
        NumLimit       int32
879
}
880

881
type FilterPaymentsDescRow struct {
882
        Payment       Payment
883
        IntentType    sql.NullInt16
884
        IntentPayload []byte
885
}
886

887
func (q *Queries) FilterPaymentsDesc(ctx context.Context, arg FilterPaymentsDescParams) ([]FilterPaymentsDescRow, error) {
888
        rows, err := q.db.QueryContext(ctx, filterPaymentsDesc,
889
                arg.IndexOffsetGet,
890
                arg.IndexOffsetLet,
891
                arg.CreatedAfter,
892
                arg.CreatedBefore,
893
                arg.IntentType,
894
                arg.NumLimit,
895
        )
896
        if err != nil {
897
                return nil, err
898
        }
899
        defer rows.Close()
900
        var items []FilterPaymentsDescRow
901
        for rows.Next() {
902
                var i FilterPaymentsDescRow
903
                if err := rows.Scan(
904
                        &i.Payment.ID,
905
                        &i.Payment.AmountMsat,
906
                        &i.Payment.CreatedAt,
907
                        &i.Payment.PaymentIdentifier,
908
                        &i.Payment.FailReason,
909
                        &i.IntentType,
910
                        &i.IntentPayload,
911
                ); err != nil {
912
                        return nil, err
913
                }
×
914
                items = append(items, i)
×
UNCOV
915
        }
×
916
        if err := rows.Close(); err != nil {
×
917
                return nil, err
×
918
        }
×
919
        if err := rows.Err(); err != nil {
×
920
                return nil, err
×
921
        }
×
922
        return items, nil
×
UNCOV
923
}
×
UNCOV
924

×
UNCOV
925
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
×
UNCOV
926
INSERT INTO payment_htlc_attempts (
×
UNCOV
927
    payment_id,
×
UNCOV
928
    attempt_index,
×
UNCOV
929
    session_key,
×
UNCOV
930
    attempt_time,
×
UNCOV
931
    payment_hash,
×
UNCOV
932
    first_hop_amount_msat,
×
UNCOV
933
    route_total_time_lock,
×
UNCOV
934
    route_total_amount,
×
UNCOV
935
    route_source_key)
×
UNCOV
936
VALUES (
×
UNCOV
937
    $1,
×
UNCOV
938
    $2,
×
UNCOV
939
    $3,
×
UNCOV
940
    $4,
×
941
    $5, 
UNCOV
942
    $6, 
×
UNCOV
943
    $7, 
×
UNCOV
944
    $8, 
×
UNCOV
945
    $9)
×
UNCOV
946
RETURNING id
×
UNCOV
947
`
×
UNCOV
948

×
949
type InsertHtlcAttemptParams struct {
950
        PaymentID          int64
951
        AttemptIndex       int64
952
        SessionKey         []byte
953
        AttemptTime        time.Time
954
        PaymentHash        []byte
955
        FirstHopAmountMsat int64
956
        RouteTotalTimeLock int32
957
        RouteTotalAmount   int64
958
        RouteSourceKey     []byte
959
}
960

961
func (q *Queries) InsertHtlcAttempt(ctx context.Context, arg InsertHtlcAttemptParams) (int64, error) {
962
        row := q.db.QueryRowContext(ctx, insertHtlcAttempt,
963
                arg.PaymentID,
964
                arg.AttemptIndex,
965
                arg.SessionKey,
966
                arg.AttemptTime,
967
                arg.PaymentHash,
968
                arg.FirstHopAmountMsat,
969
                arg.RouteTotalTimeLock,
970
                arg.RouteTotalAmount,
971
                arg.RouteSourceKey,
972
        )
973
        var id int64
974
        err := row.Scan(&id)
975
        return id, err
976
}
977

978
const insertPayment = `-- name: InsertPayment :one
979
INSERT INTO payments (
980
    amount_msat, 
981
    created_at, 
982
    payment_identifier,
983
    fail_reason)
984
VALUES (
985
    $1,
986
    $2,
UNCOV
987
    $3,
×
UNCOV
988
    NULL
×
UNCOV
989
)
×
UNCOV
990
RETURNING id
×
UNCOV
991
`
×
UNCOV
992

×
UNCOV
993
type InsertPaymentParams struct {
×
UNCOV
994
        AmountMsat        int64
×
UNCOV
995
        CreatedAt         time.Time
×
UNCOV
996
        PaymentIdentifier []byte
×
UNCOV
997
}
×
UNCOV
998

×
UNCOV
999
// Insert a new payment and return its ID.
×
UNCOV
1000
// When creating a payment we don't have a fail reason because we start the
×
UNCOV
1001
// payment process.
×
1002
func (q *Queries) InsertPayment(ctx context.Context, arg InsertPaymentParams) (int64, error) {
×
1003
        row := q.db.QueryRowContext(ctx, insertPayment, arg.AmountMsat, arg.CreatedAt, arg.PaymentIdentifier)
1004
        var id int64
1005
        err := row.Scan(&id)
1006
        return id, err
1007
}
1008

1009
const insertPaymentAttemptFirstHopCustomRecord = `-- name: InsertPaymentAttemptFirstHopCustomRecord :exec
1010
INSERT INTO payment_attempt_first_hop_custom_records (
1011
    htlc_attempt_index,
1012
    key,
1013
    value
1014
)
1015
VALUES (
1016
    $1,
1017
    $2,
1018
    $3
1019
)
1020
`
1021

1022
type InsertPaymentAttemptFirstHopCustomRecordParams struct {
1023
        HtlcAttemptIndex int64
1024
        Key              int64
1025
        Value            []byte
1026
}
1027

1028
func (q *Queries) InsertPaymentAttemptFirstHopCustomRecord(ctx context.Context, arg InsertPaymentAttemptFirstHopCustomRecordParams) error {
×
1029
        _, err := q.db.ExecContext(ctx, insertPaymentAttemptFirstHopCustomRecord, arg.HtlcAttemptIndex, arg.Key, arg.Value)
×
1030
        return err
×
1031
}
×
UNCOV
1032

×
UNCOV
1033
const insertPaymentDuplicateMig = `-- name: InsertPaymentDuplicateMig :one
×
1034
INSERT INTO payment_duplicates (
1035
    payment_id,
1036
    amount_msat,
1037
    created_at,
1038
    fail_reason,
1039
    settle_preimage,
1040
    settle_time
1041
)
1042
VALUES (
1043
    $1,
1044
    $2,
1045
    $3,
1046
    $4,
1047
    $5,
1048
    $6
1049
)
1050
RETURNING id
1051
`
1052

1053
type InsertPaymentDuplicateMigParams struct {
UNCOV
1054
        PaymentID      int64
×
UNCOV
1055
        AmountMsat     int64
×
UNCOV
1056
        CreatedAt      time.Time
×
UNCOV
1057
        FailReason     sql.NullInt32
×
1058
        SettlePreimage []byte
1059
        SettleTime     sql.NullTime
1060
}
1061

1062
// Insert a duplicate payment record into the payment_duplicates table and
1063
// return its ID.
1064
func (q *Queries) InsertPaymentDuplicateMig(ctx context.Context, arg InsertPaymentDuplicateMigParams) (int64, error) {
1065
        row := q.db.QueryRowContext(ctx, insertPaymentDuplicateMig,
1066
                arg.PaymentID,
1067
                arg.AmountMsat,
1068
                arg.CreatedAt,
1069
                arg.FailReason,
1070
                arg.SettlePreimage,
1071
                arg.SettleTime,
1072
        )
1073
        var id int64
1074
        err := row.Scan(&id)
1075
        return id, err
1076
}
1077

1078
const insertPaymentFirstHopCustomRecord = `-- name: InsertPaymentFirstHopCustomRecord :exec
1079
INSERT INTO payment_first_hop_custom_records (
1080
    payment_id,
1081
    key,
1082
    value
1083
)
1084
VALUES (
1085
    $1,
1086
    $2,
1087
    $3
1088
)
1089
`
UNCOV
1090

×
UNCOV
1091
type InsertPaymentFirstHopCustomRecordParams struct {
×
UNCOV
1092
        PaymentID int64
×
UNCOV
1093
        Key       int64
×
UNCOV
1094
        Value     []byte
×
UNCOV
1095
}
×
UNCOV
1096

×
1097
func (q *Queries) InsertPaymentFirstHopCustomRecord(ctx context.Context, arg InsertPaymentFirstHopCustomRecordParams) error {
×
1098
        _, err := q.db.ExecContext(ctx, insertPaymentFirstHopCustomRecord, arg.PaymentID, arg.Key, arg.Value)
×
1099
        return err
×
1100
}
×
UNCOV
1101

×
UNCOV
1102
const insertPaymentHopCustomRecord = `-- name: InsertPaymentHopCustomRecord :exec
×
1103
INSERT INTO payment_hop_custom_records (
1104
    hop_id,
1105
    key,
1106
    value
1107
)
1108
VALUES (
1109
    $1,
1110
    $2,
1111
    $3
1112
)
1113
`
1114

1115
type InsertPaymentHopCustomRecordParams struct {
1116
        HopID int64
1117
        Key   int64
1118
        Value []byte
1119
}
1120

1121
func (q *Queries) InsertPaymentHopCustomRecord(ctx context.Context, arg InsertPaymentHopCustomRecordParams) error {
1122
        _, err := q.db.ExecContext(ctx, insertPaymentHopCustomRecord, arg.HopID, arg.Key, arg.Value)
1123
        return err
×
1124
}
×
UNCOV
1125

×
UNCOV
1126
const insertPaymentIntent = `-- name: InsertPaymentIntent :one
×
1127
INSERT INTO payment_intents (
1128
    payment_id,
1129
    intent_type, 
1130
    intent_payload)
1131
VALUES (
1132
    $1,
1133
    $2, 
1134
    $3
1135
)
1136
RETURNING id
1137
`
1138

1139
type InsertPaymentIntentParams struct {
1140
        PaymentID     int64
1141
        IntentType    int16
1142
        IntentPayload []byte
1143
}
1144

1145
// Insert a payment intent for a given payment and return its ID.
1146
func (q *Queries) InsertPaymentIntent(ctx context.Context, arg InsertPaymentIntentParams) (int64, error) {
1147
        row := q.db.QueryRowContext(ctx, insertPaymentIntent, arg.PaymentID, arg.IntentType, arg.IntentPayload)
×
1148
        var id int64
×
1149
        err := row.Scan(&id)
×
1150
        return id, err
×
1151
}
1152

1153
const insertPaymentMig = `-- name: InsertPaymentMig :one
1154
/* ─────────────────────────────────────────────
1155
   Migration-specific queries
1156

1157
   These queries are used ONLY for the one-time migration from KV to SQL.
1158
   ─────────────────────────────────────────────
1159
*/
1160

1161
INSERT INTO payments (
1162
    amount_msat,
1163
    created_at,
1164
    payment_identifier,
1165
    fail_reason)
1166
VALUES (
1167
    $1,
1168
    $2,
1169
    $3,
1170
    $4
1171
)
UNCOV
1172
RETURNING id
×
UNCOV
1173
`
×
UNCOV
1174

×
UNCOV
1175
type InsertPaymentMigParams struct {
×
UNCOV
1176
        AmountMsat        int64
×
UNCOV
1177
        CreatedAt         time.Time
×
1178
        PaymentIdentifier []byte
1179
        FailReason        sql.NullInt32
1180
}
1181

1182
// Migration-specific payment insert that allows setting fail_reason.
1183
// Normal InsertPayment forces fail_reason to NULL since new payments
1184
// aren't failed yet. During migration, we're inserting historical data
1185
// that may already be failed.
1186
func (q *Queries) InsertPaymentMig(ctx context.Context, arg InsertPaymentMigParams) (int64, error) {
1187
        row := q.db.QueryRowContext(ctx, insertPaymentMig,
1188
                arg.AmountMsat,
1189
                arg.CreatedAt,
1190
                arg.PaymentIdentifier,
1191
                arg.FailReason,
1192
        )
1193
        var id int64
1194
        err := row.Scan(&id)
1195
        return id, err
1196
}
1197

1198
const insertRouteHop = `-- name: InsertRouteHop :one
1199
INSERT INTO payment_route_hops (
1200
    htlc_attempt_index,
1201
    hop_index,
1202
    pub_key,
1203
    scid,
1204
    outgoing_time_lock,
1205
    amt_to_forward,
1206
    meta_data
1207
)
1208
VALUES (
1209
    $1,
1210
    $2,
1211
    $3,
UNCOV
1212
    $4,
×
UNCOV
1213
    $5,
×
UNCOV
1214
    $6,
×
UNCOV
1215
    $7
×
UNCOV
1216
)
×
UNCOV
1217
RETURNING id
×
UNCOV
1218
`
×
UNCOV
1219

×
UNCOV
1220
type InsertRouteHopParams struct {
×
UNCOV
1221
        HtlcAttemptIndex int64
×
UNCOV
1222
        HopIndex         int32
×
1223
        PubKey           []byte
1224
        Scid             string
1225
        OutgoingTimeLock int32
1226
        AmtToForward     int64
1227
        MetaData         []byte
1228
}
1229

1230
func (q *Queries) InsertRouteHop(ctx context.Context, arg InsertRouteHopParams) (int64, error) {
1231
        row := q.db.QueryRowContext(ctx, insertRouteHop,
1232
                arg.HtlcAttemptIndex,
1233
                arg.HopIndex,
1234
                arg.PubKey,
1235
                arg.Scid,
1236
                arg.OutgoingTimeLock,
1237
                arg.AmtToForward,
1238
                arg.MetaData,
1239
        )
1240
        var id int64
1241
        err := row.Scan(&id)
1242
        return id, err
1243
}
1244

1245
const insertRouteHopAmp = `-- name: InsertRouteHopAmp :exec
1246
INSERT INTO payment_route_hop_amp (
1247
    hop_id,
1248
    root_share,
1249
    set_id,
1250
    child_index
1251
)
1252
VALUES (
1253
    $1,
1254
    $2,
1255
    $3,
UNCOV
1256
    $4
×
UNCOV
1257
)
×
UNCOV
1258
`
×
UNCOV
1259

×
UNCOV
1260
type InsertRouteHopAmpParams struct {
×
UNCOV
1261
        HopID      int64
×
UNCOV
1262
        RootShare  []byte
×
UNCOV
1263
        SetID      []byte
×
UNCOV
1264
        ChildIndex int32
×
UNCOV
1265
}
×
UNCOV
1266

×
1267
func (q *Queries) InsertRouteHopAmp(ctx context.Context, arg InsertRouteHopAmpParams) error {
×
1268
        _, err := q.db.ExecContext(ctx, insertRouteHopAmp,
×
1269
                arg.HopID,
×
1270
                arg.RootShare,
1271
                arg.SetID,
1272
                arg.ChildIndex,
1273
        )
1274
        return err
1275
}
1276

1277
const insertRouteHopBlinded = `-- name: InsertRouteHopBlinded :exec
1278
INSERT INTO payment_route_hop_blinded (
1279
    hop_id,
1280
    encrypted_data,
1281
    blinding_point,
1282
    blinded_path_total_amt
1283
)
1284
VALUES (
1285
    $1,
1286
    $2,
1287
    $3,
1288
    $4
1289
)
1290
`
1291

1292
type InsertRouteHopBlindedParams struct {
UNCOV
1293
        HopID               int64
×
UNCOV
1294
        EncryptedData       []byte
×
UNCOV
1295
        BlindingPoint       []byte
×
UNCOV
1296
        BlindedPathTotalAmt sql.NullInt64
×
UNCOV
1297
}
×
UNCOV
1298

×
1299
func (q *Queries) InsertRouteHopBlinded(ctx context.Context, arg InsertRouteHopBlindedParams) error {
×
1300
        _, err := q.db.ExecContext(ctx, insertRouteHopBlinded,
×
1301
                arg.HopID,
×
1302
                arg.EncryptedData,
1303
                arg.BlindingPoint,
1304
                arg.BlindedPathTotalAmt,
1305
        )
1306
        return err
1307
}
1308

1309
const insertRouteHopMpp = `-- name: InsertRouteHopMpp :exec
1310
INSERT INTO payment_route_hop_mpp (
1311
    hop_id,
1312
    payment_addr,
1313
    total_msat
1314
)
1315
VALUES (
1316
    $1,
1317
    $2,
1318
    $3
1319
)
1320
`
1321

1322
type InsertRouteHopMppParams struct {
1323
        HopID       int64
1324
        PaymentAddr []byte
UNCOV
1325
        TotalMsat   int64
×
UNCOV
1326
}
×
UNCOV
1327

×
1328
func (q *Queries) InsertRouteHopMpp(ctx context.Context, arg InsertRouteHopMppParams) error {
×
1329
        _, err := q.db.ExecContext(ctx, insertRouteHopMpp, arg.HopID, arg.PaymentAddr, arg.TotalMsat)
×
1330
        return err
×
1331
}
×
UNCOV
1332

×
UNCOV
1333
const settleAttempt = `-- name: SettleAttempt :exec
×
1334
INSERT INTO payment_htlc_attempt_resolutions (
1335
    attempt_index,
1336
    resolution_time,
1337
    resolution_type,
1338
    settle_preimage
1339
)
1340
VALUES (
1341
    $1,
1342
    $2,
1343
    $3,
1344
    $4
1345
)
1346
`
1347

1348
type SettleAttemptParams struct {
1349
        AttemptIndex   int64
1350
        ResolutionTime time.Time
1351
        ResolutionType int32
1352
        SettlePreimage []byte
1353
}
UNCOV
1354

×
1355
func (q *Queries) SettleAttempt(ctx context.Context, arg SettleAttemptParams) error {
×
1356
        _, err := q.db.ExecContext(ctx, settleAttempt,
×
1357
                arg.AttemptIndex,
×
1358
                arg.ResolutionTime,
1359
                arg.ResolutionType,
1360
                arg.SettlePreimage,
1361
        )
1362
        return err
1363
}
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