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

lightningnetwork / lnd / 23301371212

19 Mar 2026 03:01PM UTC coverage: 62.289% (-0.05%) from 62.341%
23301371212

push

github

web-flow
Merge pull request #10649 from ziggie1984/fix-payments-sql-query

payments/db: fix FilterPayments efficiency and sync bugfixes to migration1

0 of 91 new or added lines in 3 files covered. (0.0%)

124 existing lines in 22 files now uncovered.

141017 of 226390 relevant lines covered (62.29%)

19433.35 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,
118
    ha.route_source_key
119
FROM payment_htlc_attempts ha
120
WHERE NOT EXISTS (
121
    SELECT 1 FROM payment_htlc_attempt_resolutions hr
122
    WHERE hr.attempt_index = ha.attempt_index
123
)
124
AND ha.attempt_index > $1
125
ORDER BY ha.attempt_index ASC
126
LIMIT $2
127
`
128

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

134
// Fetch all inflight attempts with their payment data using pagination.
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)
×
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
×
217
}
218

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

245
type FetchHopsForAttemptsRow struct {
246
        ID                  int64
247
        HtlcAttemptIndex    int64
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)
×
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
×
362
}
363

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

388
type FetchHtlcAttemptsForPaymentsRow struct {
389
        ID                 int64
390
        AttemptIndex       int64
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
×
455
}
456

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

467
type FetchPaymentRow struct {
468
        Payment       Payment
469
        IntentType    sql.NullInt16
470
        IntentPayload []byte
471
}
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
499
ORDER BY id ASC
500
`
501

502
// Fetch all duplicate payment records from the payment_duplicates table for
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
×
533
}
534

535
const fetchPaymentLevelFirstHopCustomRecords = `-- name: FetchPaymentLevelFirstHopCustomRecords :many
536
SELECT
537
    l.id,
538
    l.payment_id,
539
    l.key,
540
    l.value
541
FROM payment_first_hop_custom_records l
542
WHERE l.payment_id IN (/*SLICE:payment_ids*/?)
543
ORDER BY l.payment_id ASC, l.key ASC
544
`
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)
×
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
×
582
}
583

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

599
type FetchPaymentsByIDsRow struct {
600
        ID                int64
601
        AmountMsat        int64
602
        CreatedAt         time.Time
603
        PaymentIdentifier []byte
604
        FailReason        sql.NullInt32
605
        IntentType        sql.NullInt16
606
        IntentPayload     []byte
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)
×
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
×
651
}
652

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

668
type FetchPaymentsByIDsMigRow struct {
669
        ID                int64
670
        AmountMsat        int64
671
        CreatedAt         time.Time
672
        PaymentIdentifier []byte
673
        FailReason        sql.NullInt32
674
        HtlcAttemptCount  int64
675
}
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)
×
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
×
717
}
718

719
const fetchRouteLevelFirstHopCustomRecords = `-- name: FetchRouteLevelFirstHopCustomRecords :many
720
SELECT
721
    l.id,
722
    l.htlc_attempt_index,
723
    l.key,
724
    l.value
725
FROM payment_attempt_first_hop_custom_records l
726
WHERE l.htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
727
ORDER BY l.htlc_attempt_index ASC, l.key ASC
728
`
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)
×
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
×
766
}
767

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

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

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

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

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

925
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
926
INSERT INTO payment_htlc_attempts (
927
    payment_id,
928
    attempt_index,
929
    session_key,
930
    attempt_time,
931
    payment_hash,
932
    first_hop_amount_msat,
933
    route_total_time_lock,
934
    route_total_amount,
935
    route_source_key)
936
VALUES (
937
    $1,
938
    $2,
939
    $3,
940
    $4,
941
    $5, 
942
    $6, 
943
    $7, 
944
    $8, 
945
    $9)
946
RETURNING id
947
`
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,
987
    $3,
988
    NULL
989
)
990
RETURNING id
991
`
992

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

999
// Insert a new payment and return its ID.
1000
// When creating a payment we don't have a fail reason because we start the
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
}
×
1032

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 {
1054
        PaymentID      int64
1055
        AmountMsat     int64
1056
        CreatedAt      time.Time
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
`
1090

1091
type InsertPaymentFirstHopCustomRecordParams struct {
1092
        PaymentID int64
1093
        Key       int64
1094
        Value     []byte
1095
}
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
}
×
1101

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
}
×
1125

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
)
1172
RETURNING id
1173
`
1174

1175
type InsertPaymentMigParams struct {
1176
        AmountMsat        int64
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,
1212
    $4,
1213
    $5,
1214
    $6,
1215
    $7
1216
)
1217
RETURNING id
1218
`
1219

1220
type InsertRouteHopParams struct {
1221
        HtlcAttemptIndex int64
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,
1256
    $4
1257
)
1258
`
1259

1260
type InsertRouteHopAmpParams struct {
1261
        HopID      int64
1262
        RootShare  []byte
1263
        SetID      []byte
1264
        ChildIndex int32
1265
}
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 {
1293
        HopID               int64
1294
        EncryptedData       []byte
1295
        BlindingPoint       []byte
1296
        BlindedPathTotalAmt sql.NullInt64
1297
}
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
1325
        TotalMsat   int64
1326
}
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
}
×
1332

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
}
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