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

lightningnetwork / lnd / 24081604890

07 Apr 2026 12:35PM UTC coverage: 62.163% (+0.06%) from 62.104%
24081604890

Pull #10721

github

web-flow
Merge 95e447f23 into 167f03bb3
Pull Request #10721: paymentsdb: restore sql payment store parity with kv

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

39 existing lines in 14 files now uncovered.

142843 of 229786 relevant lines covered (62.16%)

19225.02 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 fetchHopLevelCustomRecords = `-- name: FetchHopLevelCustomRecords :many
108
SELECT
109
    l.id,
110
    l.hop_id,
111
    l.key,
112
    l.value
113
FROM payment_hop_custom_records l
114
WHERE l.hop_id IN (/*SLICE:hop_ids*/?)
115
ORDER BY l.hop_id ASC, l.key ASC
116
`
117

118
func (q *Queries) FetchHopLevelCustomRecords(ctx context.Context, hopIds []int64) ([]PaymentHopCustomRecord, error) {
×
119
        query := fetchHopLevelCustomRecords
×
120
        var queryParams []interface{}
×
121
        if len(hopIds) > 0 {
×
122
                for _, v := range hopIds {
×
123
                        queryParams = append(queryParams, v)
×
124
                }
×
125
                query = strings.Replace(query, "/*SLICE:hop_ids*/?", makeQueryParams(len(queryParams), len(hopIds)), 1)
×
126
        } else {
×
127
                query = strings.Replace(query, "/*SLICE:hop_ids*/?", "NULL", 1)
×
128
        }
×
129
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
130
        if err != nil {
×
131
                return nil, err
×
132
        }
×
133
        defer rows.Close()
×
134
        var items []PaymentHopCustomRecord
×
135
        for rows.Next() {
×
136
                var i PaymentHopCustomRecord
×
137
                if err := rows.Scan(
×
138
                        &i.ID,
×
139
                        &i.HopID,
×
140
                        &i.Key,
×
141
                        &i.Value,
×
142
                ); err != nil {
×
143
                        return nil, err
×
144
                }
×
145
                items = append(items, i)
×
146
        }
147
        if err := rows.Close(); err != nil {
×
148
                return nil, err
×
149
        }
×
150
        if err := rows.Err(); err != nil {
×
151
                return nil, err
×
152
        }
×
153
        return items, nil
×
154
}
155

156
const fetchHopsForAttempts = `-- name: FetchHopsForAttempts :many
157
SELECT
158
    h.id,
159
    h.htlc_attempt_index,
160
    h.hop_index,
161
    h.pub_key,
162
    h.scid,
163
    h.outgoing_time_lock,
164
    h.amt_to_forward,
165
    h.meta_data,
166
    m.payment_addr AS mpp_payment_addr,
167
    m.total_msat AS mpp_total_msat,
168
    a.root_share AS amp_root_share,
169
    a.set_id AS amp_set_id,
170
    a.child_index AS amp_child_index,
171
    b.encrypted_data,
172
    b.blinding_point,
173
    b.blinded_path_total_amt
174
FROM payment_route_hops h
175
LEFT JOIN payment_route_hop_mpp m ON m.hop_id = h.id
176
LEFT JOIN payment_route_hop_amp a ON a.hop_id = h.id
177
LEFT JOIN payment_route_hop_blinded b ON b.hop_id = h.id
178
WHERE h.htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
179
ORDER BY h.htlc_attempt_index ASC, h.hop_index ASC
180
`
181

182
type FetchHopsForAttemptsRow struct {
183
        ID                  int64
184
        HtlcAttemptIndex    int64
185
        HopIndex            int32
186
        PubKey              []byte
187
        Scid                string
188
        OutgoingTimeLock    int32
189
        AmtToForward        int64
190
        MetaData            []byte
191
        MppPaymentAddr      []byte
192
        MppTotalMsat        sql.NullInt64
193
        AmpRootShare        []byte
194
        AmpSetID            []byte
195
        AmpChildIndex       sql.NullInt32
196
        EncryptedData       []byte
197
        BlindingPoint       []byte
198
        BlindedPathTotalAmt sql.NullInt64
199
}
200

201
func (q *Queries) FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices []int64) ([]FetchHopsForAttemptsRow, error) {
×
202
        query := fetchHopsForAttempts
×
203
        var queryParams []interface{}
×
204
        if len(htlcAttemptIndices) > 0 {
×
205
                for _, v := range htlcAttemptIndices {
×
206
                        queryParams = append(queryParams, v)
×
207
                }
×
208
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", makeQueryParams(len(queryParams), len(htlcAttemptIndices)), 1)
×
209
        } else {
×
210
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", "NULL", 1)
×
211
        }
×
212
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
213
        if err != nil {
×
214
                return nil, err
×
215
        }
×
216
        defer rows.Close()
×
217
        var items []FetchHopsForAttemptsRow
×
218
        for rows.Next() {
×
219
                var i FetchHopsForAttemptsRow
×
220
                if err := rows.Scan(
×
221
                        &i.ID,
×
222
                        &i.HtlcAttemptIndex,
×
223
                        &i.HopIndex,
×
224
                        &i.PubKey,
×
225
                        &i.Scid,
×
226
                        &i.OutgoingTimeLock,
×
227
                        &i.AmtToForward,
×
228
                        &i.MetaData,
×
229
                        &i.MppPaymentAddr,
×
230
                        &i.MppTotalMsat,
×
231
                        &i.AmpRootShare,
×
232
                        &i.AmpSetID,
×
233
                        &i.AmpChildIndex,
×
234
                        &i.EncryptedData,
×
235
                        &i.BlindingPoint,
×
236
                        &i.BlindedPathTotalAmt,
×
237
                ); err != nil {
×
238
                        return nil, err
×
239
                }
×
240
                items = append(items, i)
×
241
        }
242
        if err := rows.Close(); err != nil {
×
243
                return nil, err
×
244
        }
×
245
        if err := rows.Err(); err != nil {
×
246
                return nil, err
×
247
        }
×
248
        return items, nil
×
249
}
250

251
const fetchHtlcAttemptResolutionsForPayments = `-- name: FetchHtlcAttemptResolutionsForPayments :many
252
SELECT
253
    ha.payment_id,
254
    hr.resolution_type
255
FROM payment_htlc_attempts ha
256
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
257
WHERE ha.payment_id IN (/*SLICE:payment_ids*/?)
258
`
259

260
type FetchHtlcAttemptResolutionsForPaymentsRow struct {
261
        PaymentID      int64
262
        ResolutionType sql.NullInt32
263
}
264

265
// Batch query to fetch only HTLC resolution status for multiple payments.
266
// We don't need to order by payment_id and attempt_time because we will
267
// group the resolutions by payment_id in the background.
268
func (q *Queries) FetchHtlcAttemptResolutionsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptResolutionsForPaymentsRow, error) {
×
269
        query := fetchHtlcAttemptResolutionsForPayments
×
270
        var queryParams []interface{}
×
271
        if len(paymentIds) > 0 {
×
272
                for _, v := range paymentIds {
×
273
                        queryParams = append(queryParams, v)
×
274
                }
×
275
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
276
        } else {
×
277
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
278
        }
×
279
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
280
        if err != nil {
×
281
                return nil, err
×
282
        }
×
283
        defer rows.Close()
×
284
        var items []FetchHtlcAttemptResolutionsForPaymentsRow
×
285
        for rows.Next() {
×
286
                var i FetchHtlcAttemptResolutionsForPaymentsRow
×
287
                if err := rows.Scan(&i.PaymentID, &i.ResolutionType); err != nil {
×
288
                        return nil, err
×
289
                }
×
290
                items = append(items, i)
×
291
        }
292
        if err := rows.Close(); err != nil {
×
293
                return nil, err
×
294
        }
×
295
        if err := rows.Err(); err != nil {
×
296
                return nil, err
×
297
        }
×
298
        return items, nil
×
299
}
300

301
const fetchHtlcAttemptsForPayments = `-- name: FetchHtlcAttemptsForPayments :many
302
SELECT
303
    ha.id,
304
    ha.attempt_index,
305
    ha.payment_id,
306
    ha.session_key,
307
    ha.attempt_time,
308
    ha.payment_hash,
309
    ha.first_hop_amount_msat,
310
    ha.route_total_time_lock,
311
    ha.route_total_amount,
312
    ha.route_source_key,
313
    hr.resolution_type,
314
    hr.resolution_time,
315
    hr.failure_source_index,
316
    hr.htlc_fail_reason,
317
    hr.failure_msg,
318
    hr.settle_preimage
319
FROM payment_htlc_attempts ha
320
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
321
WHERE ha.payment_id IN (/*SLICE:payment_ids*/?)
322
ORDER BY ha.payment_id ASC, ha.attempt_time ASC
323
`
324

325
type FetchHtlcAttemptsForPaymentsRow struct {
326
        ID                 int64
327
        AttemptIndex       int64
328
        PaymentID          int64
329
        SessionKey         []byte
330
        AttemptTime        time.Time
331
        PaymentHash        []byte
332
        FirstHopAmountMsat int64
333
        RouteTotalTimeLock int32
334
        RouteTotalAmount   int64
335
        RouteSourceKey     []byte
336
        ResolutionType     sql.NullInt32
337
        ResolutionTime     sql.NullTime
338
        FailureSourceIndex sql.NullInt32
339
        HtlcFailReason     sql.NullInt32
340
        FailureMsg         []byte
341
        SettlePreimage     []byte
342
}
343

344
func (q *Queries) FetchHtlcAttemptsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptsForPaymentsRow, error) {
×
345
        query := fetchHtlcAttemptsForPayments
×
346
        var queryParams []interface{}
×
347
        if len(paymentIds) > 0 {
×
348
                for _, v := range paymentIds {
×
349
                        queryParams = append(queryParams, v)
×
350
                }
×
351
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
352
        } else {
×
353
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
354
        }
×
355
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
356
        if err != nil {
×
357
                return nil, err
×
358
        }
×
359
        defer rows.Close()
×
360
        var items []FetchHtlcAttemptsForPaymentsRow
×
361
        for rows.Next() {
×
362
                var i FetchHtlcAttemptsForPaymentsRow
×
363
                if err := rows.Scan(
×
364
                        &i.ID,
×
365
                        &i.AttemptIndex,
×
366
                        &i.PaymentID,
×
367
                        &i.SessionKey,
×
368
                        &i.AttemptTime,
×
369
                        &i.PaymentHash,
×
370
                        &i.FirstHopAmountMsat,
×
371
                        &i.RouteTotalTimeLock,
×
372
                        &i.RouteTotalAmount,
×
373
                        &i.RouteSourceKey,
×
374
                        &i.ResolutionType,
×
375
                        &i.ResolutionTime,
×
376
                        &i.FailureSourceIndex,
×
377
                        &i.HtlcFailReason,
×
378
                        &i.FailureMsg,
×
379
                        &i.SettlePreimage,
×
380
                ); err != nil {
×
381
                        return nil, err
×
382
                }
×
383
                items = append(items, i)
×
384
        }
385
        if err := rows.Close(); err != nil {
×
386
                return nil, err
×
387
        }
×
388
        if err := rows.Err(); err != nil {
×
389
                return nil, err
×
390
        }
×
391
        return items, nil
×
392
}
393

394
const fetchNonTerminalPayments = `-- name: FetchNonTerminalPayments :many
395
WITH non_terminal_ids AS (
396
    SELECT ha.payment_id AS id
397
    FROM payment_htlc_attempts ha
398
    WHERE NOT EXISTS (
399
        SELECT 1 FROM payment_htlc_attempt_resolutions hr
400
        WHERE hr.attempt_index = ha.attempt_index
401
    )
402

403
    UNION
404

405
    SELECT p.id
406
    FROM payments p
407
    WHERE p.fail_reason IS NULL
408
    AND NOT EXISTS (
409
        SELECT 1 FROM payment_htlc_attempts ha
410
        WHERE ha.payment_id = p.id
411
    )
412

413
    UNION
414

415
    SELECT DISTINCT ha.payment_id AS id
416
    FROM payment_htlc_attempts ha
417
    JOIN payment_htlc_attempt_resolutions hr
418
        ON hr.attempt_index = ha.attempt_index
419
    JOIN payments p
420
        ON p.id = ha.payment_id
421
    WHERE p.fail_reason IS NULL
422
    AND hr.resolution_type = 2
423
    AND NOT EXISTS (
424
        SELECT 1 FROM payment_htlc_attempts ha2
425
        JOIN payment_htlc_attempt_resolutions hr2
426
            ON hr2.attempt_index = ha2.attempt_index
427
        WHERE ha2.payment_id = ha.payment_id
428
        AND hr2.resolution_type = 1
429
    )
430
)
431
SELECT
432
    p.id,
433
    p.amount_msat,
434
    p.created_at,
435
    p.payment_identifier,
436
    p.fail_reason,
437
    pi.intent_type,
438
    pi.intent_payload
439
FROM non_terminal_ids n
440
JOIN payments p
441
    ON p.id = n.id
442
LEFT JOIN payment_intents pi
443
    ON pi.payment_id = p.id
444
WHERE p.id > $1
445
ORDER BY p.id ASC
446
LIMIT $2
447
`
448

449
type FetchNonTerminalPaymentsParams struct {
450
        ID    int64
451
        Limit int32
452
}
453

454
type FetchNonTerminalPaymentsRow struct {
455
        ID                int64
456
        AmountMsat        int64
457
        CreatedAt         time.Time
458
        PaymentIdentifier []byte
459
        FailReason        sql.NullInt32
460
        IntentType        sql.NullInt16
461
        IntentPayload     []byte
462
}
463

464
// Fetch all non-terminal payments using pagination. A payment is
465
// non-terminal if it has an unresolved attempt, or if it has not been
466
// permanently failed and has no settled attempt yet.
NEW
467
func (q *Queries) FetchNonTerminalPayments(ctx context.Context, arg FetchNonTerminalPaymentsParams) ([]FetchNonTerminalPaymentsRow, error) {
×
NEW
468
        rows, err := q.db.QueryContext(ctx, fetchNonTerminalPayments, arg.ID, arg.Limit)
×
NEW
469
        if err != nil {
×
NEW
470
                return nil, err
×
NEW
471
        }
×
NEW
472
        defer rows.Close()
×
NEW
473
        var items []FetchNonTerminalPaymentsRow
×
NEW
474
        for rows.Next() {
×
NEW
475
                var i FetchNonTerminalPaymentsRow
×
NEW
476
                if err := rows.Scan(
×
NEW
477
                        &i.ID,
×
NEW
478
                        &i.AmountMsat,
×
NEW
479
                        &i.CreatedAt,
×
NEW
480
                        &i.PaymentIdentifier,
×
NEW
481
                        &i.FailReason,
×
NEW
482
                        &i.IntentType,
×
NEW
483
                        &i.IntentPayload,
×
NEW
484
                ); err != nil {
×
NEW
485
                        return nil, err
×
NEW
486
                }
×
NEW
487
                items = append(items, i)
×
488
        }
NEW
489
        if err := rows.Close(); err != nil {
×
NEW
490
                return nil, err
×
NEW
491
        }
×
NEW
492
        if err := rows.Err(); err != nil {
×
NEW
493
                return nil, err
×
NEW
494
        }
×
NEW
495
        return items, nil
×
496
}
497

498
const fetchPayment = `-- name: FetchPayment :one
499
SELECT
500
    p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason,
501
    i.intent_type AS "intent_type",
502
    i.intent_payload AS "intent_payload"
503
FROM payments p
504
LEFT JOIN payment_intents i ON i.payment_id = p.id
505
WHERE p.payment_identifier = $1
506
`
507

508
type FetchPaymentRow struct {
509
        Payment       Payment
510
        IntentType    sql.NullInt16
511
        IntentPayload []byte
512
}
513

514
func (q *Queries) FetchPayment(ctx context.Context, paymentIdentifier []byte) (FetchPaymentRow, error) {
×
515
        row := q.db.QueryRowContext(ctx, fetchPayment, paymentIdentifier)
×
516
        var i FetchPaymentRow
×
517
        err := row.Scan(
×
518
                &i.Payment.ID,
×
519
                &i.Payment.AmountMsat,
×
520
                &i.Payment.CreatedAt,
×
521
                &i.Payment.PaymentIdentifier,
×
522
                &i.Payment.FailReason,
×
523
                &i.IntentType,
×
524
                &i.IntentPayload,
×
525
        )
×
526
        return i, err
×
527
}
×
528

529
const fetchPaymentDuplicates = `-- name: FetchPaymentDuplicates :many
530
SELECT
531
    id,
532
    payment_id,
533
    amount_msat,
534
    created_at,
535
    fail_reason,
536
    settle_preimage,
537
    settle_time
538
FROM payment_duplicates
539
WHERE payment_id = $1
540
ORDER BY id ASC
541
`
542

543
// Fetch all duplicate payment records from the payment_duplicates table for
544
// a given payment ID.
545
func (q *Queries) FetchPaymentDuplicates(ctx context.Context, paymentID int64) ([]PaymentDuplicate, error) {
×
546
        rows, err := q.db.QueryContext(ctx, fetchPaymentDuplicates, paymentID)
×
547
        if err != nil {
×
548
                return nil, err
×
549
        }
×
550
        defer rows.Close()
×
551
        var items []PaymentDuplicate
×
552
        for rows.Next() {
×
553
                var i PaymentDuplicate
×
554
                if err := rows.Scan(
×
555
                        &i.ID,
×
556
                        &i.PaymentID,
×
557
                        &i.AmountMsat,
×
558
                        &i.CreatedAt,
×
559
                        &i.FailReason,
×
560
                        &i.SettlePreimage,
×
561
                        &i.SettleTime,
×
562
                ); err != nil {
×
563
                        return nil, err
×
564
                }
×
565
                items = append(items, i)
×
566
        }
567
        if err := rows.Close(); err != nil {
×
568
                return nil, err
×
569
        }
×
570
        if err := rows.Err(); err != nil {
×
571
                return nil, err
×
572
        }
×
573
        return items, nil
×
574
}
575

576
const fetchPaymentLevelFirstHopCustomRecords = `-- name: FetchPaymentLevelFirstHopCustomRecords :many
577
SELECT
578
    l.id,
579
    l.payment_id,
580
    l.key,
581
    l.value
582
FROM payment_first_hop_custom_records l
583
WHERE l.payment_id IN (/*SLICE:payment_ids*/?)
584
ORDER BY l.payment_id ASC, l.key ASC
585
`
586

587
func (q *Queries) FetchPaymentLevelFirstHopCustomRecords(ctx context.Context, paymentIds []int64) ([]PaymentFirstHopCustomRecord, error) {
×
588
        query := fetchPaymentLevelFirstHopCustomRecords
×
589
        var queryParams []interface{}
×
590
        if len(paymentIds) > 0 {
×
591
                for _, v := range paymentIds {
×
592
                        queryParams = append(queryParams, v)
×
593
                }
×
594
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
595
        } else {
×
596
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
597
        }
×
598
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
599
        if err != nil {
×
600
                return nil, err
×
601
        }
×
602
        defer rows.Close()
×
603
        var items []PaymentFirstHopCustomRecord
×
604
        for rows.Next() {
×
605
                var i PaymentFirstHopCustomRecord
×
606
                if err := rows.Scan(
×
607
                        &i.ID,
×
608
                        &i.PaymentID,
×
609
                        &i.Key,
×
610
                        &i.Value,
×
611
                ); err != nil {
×
612
                        return nil, err
×
613
                }
×
614
                items = append(items, i)
×
615
        }
616
        if err := rows.Close(); err != nil {
×
617
                return nil, err
×
618
        }
×
619
        if err := rows.Err(); err != nil {
×
620
                return nil, err
×
621
        }
×
622
        return items, nil
×
623
}
624

625
const fetchPaymentsByIDs = `-- name: FetchPaymentsByIDs :many
626
SELECT
627
    p.id,
628
    p.amount_msat,
629
    p.created_at,
630
    p.payment_identifier,
631
    p.fail_reason,
632
    pi.intent_type,
633
    pi.intent_payload
634
FROM payments p
635
LEFT JOIN payment_intents pi ON pi.payment_id = p.id
636
WHERE p.id IN (/*SLICE:payment_ids*/?)
637
ORDER BY p.id ASC
638
`
639

640
type FetchPaymentsByIDsRow struct {
641
        ID                int64
642
        AmountMsat        int64
643
        CreatedAt         time.Time
644
        PaymentIdentifier []byte
645
        FailReason        sql.NullInt32
646
        IntentType        sql.NullInt16
647
        IntentPayload     []byte
648
}
649

650
// Batch fetch payment and intent data for a set of payment IDs.
651
// Used to avoid fetching redundant payment data when processing multiple
652
// attempts for the same payment.
653
func (q *Queries) FetchPaymentsByIDs(ctx context.Context, paymentIds []int64) ([]FetchPaymentsByIDsRow, error) {
×
654
        query := fetchPaymentsByIDs
×
655
        var queryParams []interface{}
×
656
        if len(paymentIds) > 0 {
×
657
                for _, v := range paymentIds {
×
658
                        queryParams = append(queryParams, v)
×
659
                }
×
660
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
661
        } else {
×
662
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
663
        }
×
664
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
665
        if err != nil {
×
666
                return nil, err
×
667
        }
×
668
        defer rows.Close()
×
669
        var items []FetchPaymentsByIDsRow
×
670
        for rows.Next() {
×
671
                var i FetchPaymentsByIDsRow
×
672
                if err := rows.Scan(
×
673
                        &i.ID,
×
674
                        &i.AmountMsat,
×
675
                        &i.CreatedAt,
×
676
                        &i.PaymentIdentifier,
×
677
                        &i.FailReason,
×
678
                        &i.IntentType,
×
679
                        &i.IntentPayload,
×
680
                ); err != nil {
×
681
                        return nil, err
×
682
                }
×
683
                items = append(items, i)
×
684
        }
685
        if err := rows.Close(); err != nil {
×
686
                return nil, err
×
687
        }
×
688
        if err := rows.Err(); err != nil {
×
689
                return nil, err
×
690
        }
×
691
        return items, nil
×
692
}
693

694
const fetchPaymentsByIDsMig = `-- name: FetchPaymentsByIDsMig :many
695
SELECT
696
    p.id,
697
    p.amount_msat,
698
    p.created_at,
699
    p.payment_identifier,
700
    p.fail_reason,
701
    COUNT(ha.id) AS htlc_attempt_count
702
FROM payments p
703
LEFT JOIN payment_htlc_attempts ha ON ha.payment_id = p.id
704
WHERE p.id IN (/*SLICE:payment_ids*/?)
705
GROUP BY p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason
706
ORDER BY p.id ASC
707
`
708

709
type FetchPaymentsByIDsMigRow struct {
710
        ID                int64
711
        AmountMsat        int64
712
        CreatedAt         time.Time
713
        PaymentIdentifier []byte
714
        FailReason        sql.NullInt32
715
        HtlcAttemptCount  int64
716
}
717

718
// Migration-specific batch fetch that returns payment data along with HTLC
719
// attempt counts for structural validation during KV to SQL migration.
720
func (q *Queries) FetchPaymentsByIDsMig(ctx context.Context, paymentIds []int64) ([]FetchPaymentsByIDsMigRow, error) {
×
721
        query := fetchPaymentsByIDsMig
×
722
        var queryParams []interface{}
×
723
        if len(paymentIds) > 0 {
×
724
                for _, v := range paymentIds {
×
725
                        queryParams = append(queryParams, v)
×
726
                }
×
727
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
728
        } else {
×
729
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
730
        }
×
731
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
732
        if err != nil {
×
733
                return nil, err
×
734
        }
×
735
        defer rows.Close()
×
736
        var items []FetchPaymentsByIDsMigRow
×
737
        for rows.Next() {
×
738
                var i FetchPaymentsByIDsMigRow
×
739
                if err := rows.Scan(
×
740
                        &i.ID,
×
741
                        &i.AmountMsat,
×
742
                        &i.CreatedAt,
×
743
                        &i.PaymentIdentifier,
×
744
                        &i.FailReason,
×
745
                        &i.HtlcAttemptCount,
×
746
                ); err != nil {
×
747
                        return nil, err
×
748
                }
×
749
                items = append(items, i)
×
750
        }
751
        if err := rows.Close(); err != nil {
×
752
                return nil, err
×
753
        }
×
754
        if err := rows.Err(); err != nil {
×
755
                return nil, err
×
756
        }
×
757
        return items, nil
×
758
}
759

760
const fetchRouteLevelFirstHopCustomRecords = `-- name: FetchRouteLevelFirstHopCustomRecords :many
761
SELECT
762
    l.id,
763
    l.htlc_attempt_index,
764
    l.key,
765
    l.value
766
FROM payment_attempt_first_hop_custom_records l
767
WHERE l.htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
768
ORDER BY l.htlc_attempt_index ASC, l.key ASC
769
`
770

771
func (q *Queries) FetchRouteLevelFirstHopCustomRecords(ctx context.Context, htlcAttemptIndices []int64) ([]PaymentAttemptFirstHopCustomRecord, error) {
×
772
        query := fetchRouteLevelFirstHopCustomRecords
×
773
        var queryParams []interface{}
×
774
        if len(htlcAttemptIndices) > 0 {
×
775
                for _, v := range htlcAttemptIndices {
×
776
                        queryParams = append(queryParams, v)
×
777
                }
×
778
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", makeQueryParams(len(queryParams), len(htlcAttemptIndices)), 1)
×
779
        } else {
×
780
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", "NULL", 1)
×
781
        }
×
782
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
783
        if err != nil {
×
784
                return nil, err
×
785
        }
×
786
        defer rows.Close()
×
787
        var items []PaymentAttemptFirstHopCustomRecord
×
788
        for rows.Next() {
×
789
                var i PaymentAttemptFirstHopCustomRecord
×
790
                if err := rows.Scan(
×
791
                        &i.ID,
×
792
                        &i.HtlcAttemptIndex,
×
793
                        &i.Key,
×
794
                        &i.Value,
×
795
                ); err != nil {
×
796
                        return nil, err
×
797
                }
×
798
                items = append(items, i)
×
799
        }
800
        if err := rows.Close(); err != nil {
×
801
                return nil, err
×
802
        }
×
803
        if err := rows.Err(); err != nil {
×
804
                return nil, err
×
805
        }
×
806
        return items, nil
×
807
}
808

809
const filterPayments = `-- name: FilterPayments :many
810
/* ─────────────────────────────────────────────
811
   fetch queries
812
   ─────────────────────────────────────────────
813
*/
814

815
SELECT
816
    p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason,
817
    i.intent_type AS "intent_type",
818
    i.intent_payload AS "intent_payload"
819
FROM payments p
820
LEFT JOIN payment_intents i ON i.payment_id = p.id
821
WHERE p.id > COALESCE($1, -1)
822
  AND p.id < COALESCE($2, 9223372036854775807)
823
  -- NOTE: We use non-nullable time params with Go-side defaults instead of
824
  -- COALESCE, because COALESCE with text fallback causes type mismatch on
825
  -- Postgres (timestamp vs text), and OR-based optional filters can prevent
826
  -- the planner from using the created_at index.
827
  AND p.created_at >= $3
828
  AND p.created_at <= $4
829
  AND (
830
      i.intent_type = $5 OR
831
      $5 IS NULL OR i.intent_type IS NULL
832
  )
833
ORDER BY p.id ASC
834
LIMIT $6
835
`
836

837
type FilterPaymentsParams struct {
838
        IndexOffsetGet sql.NullInt64
839
        IndexOffsetLet sql.NullInt64
840
        CreatedAfter   time.Time
841
        CreatedBefore  time.Time
842
        IntentType     sql.NullInt16
843
        NumLimit       int32
844
}
845

846
type FilterPaymentsRow struct {
847
        Payment       Payment
848
        IntentType    sql.NullInt16
849
        IntentPayload []byte
850
}
851

852
func (q *Queries) FilterPayments(ctx context.Context, arg FilterPaymentsParams) ([]FilterPaymentsRow, error) {
×
853
        rows, err := q.db.QueryContext(ctx, filterPayments,
×
854
                arg.IndexOffsetGet,
×
855
                arg.IndexOffsetLet,
×
856
                arg.CreatedAfter,
×
857
                arg.CreatedBefore,
×
858
                arg.IntentType,
×
859
                arg.NumLimit,
×
860
        )
×
861
        if err != nil {
×
862
                return nil, err
×
863
        }
×
864
        defer rows.Close()
×
865
        var items []FilterPaymentsRow
×
866
        for rows.Next() {
×
867
                var i FilterPaymentsRow
×
868
                if err := rows.Scan(
×
869
                        &i.Payment.ID,
×
870
                        &i.Payment.AmountMsat,
×
871
                        &i.Payment.CreatedAt,
×
872
                        &i.Payment.PaymentIdentifier,
×
873
                        &i.Payment.FailReason,
×
874
                        &i.IntentType,
×
875
                        &i.IntentPayload,
×
876
                ); err != nil {
×
877
                        return nil, err
×
878
                }
×
879
                items = append(items, i)
×
880
        }
881
        if err := rows.Close(); err != nil {
×
882
                return nil, err
×
883
        }
×
884
        if err := rows.Err(); err != nil {
×
885
                return nil, err
×
886
        }
×
887
        return items, nil
×
888
}
889

890
const filterPaymentsDesc = `-- name: FilterPaymentsDesc :many
891
SELECT
892
    p.id, p.amount_msat, p.created_at, p.payment_identifier, p.fail_reason,
893
    i.intent_type AS "intent_type",
894
    i.intent_payload AS "intent_payload"
895
FROM payments p
896
LEFT JOIN payment_intents i ON i.payment_id = p.id
897
WHERE p.id > COALESCE($1, -1)
898
  AND p.id < COALESCE($2, 9223372036854775807)
899
  -- NOTE: We use non-nullable time params with Go-side defaults instead of
900
  -- COALESCE, because COALESCE with text fallback causes type mismatch on
901
  -- Postgres (timestamp vs text), and OR-based optional filters can prevent
902
  -- the planner from using the created_at index.
903
  AND p.created_at >= $3
904
  AND p.created_at <= $4
905
  AND (
906
      i.intent_type = $5 OR
907
      $5 IS NULL OR i.intent_type IS NULL
908
  )
909
ORDER BY p.id DESC
910
LIMIT $6
911
`
912

913
type FilterPaymentsDescParams struct {
914
        IndexOffsetGet sql.NullInt64
915
        IndexOffsetLet sql.NullInt64
916
        CreatedAfter   time.Time
917
        CreatedBefore  time.Time
918
        IntentType     sql.NullInt16
919
        NumLimit       int32
920
}
921

922
type FilterPaymentsDescRow struct {
923
        Payment       Payment
924
        IntentType    sql.NullInt16
925
        IntentPayload []byte
926
}
927

928
func (q *Queries) FilterPaymentsDesc(ctx context.Context, arg FilterPaymentsDescParams) ([]FilterPaymentsDescRow, error) {
×
929
        rows, err := q.db.QueryContext(ctx, filterPaymentsDesc,
×
930
                arg.IndexOffsetGet,
×
931
                arg.IndexOffsetLet,
×
932
                arg.CreatedAfter,
×
933
                arg.CreatedBefore,
×
934
                arg.IntentType,
×
935
                arg.NumLimit,
×
936
        )
×
937
        if err != nil {
×
938
                return nil, err
×
939
        }
×
940
        defer rows.Close()
×
941
        var items []FilterPaymentsDescRow
×
942
        for rows.Next() {
×
943
                var i FilterPaymentsDescRow
×
944
                if err := rows.Scan(
×
945
                        &i.Payment.ID,
×
946
                        &i.Payment.AmountMsat,
×
947
                        &i.Payment.CreatedAt,
×
948
                        &i.Payment.PaymentIdentifier,
×
949
                        &i.Payment.FailReason,
×
950
                        &i.IntentType,
×
951
                        &i.IntentPayload,
×
952
                ); err != nil {
×
953
                        return nil, err
×
954
                }
×
955
                items = append(items, i)
×
956
        }
957
        if err := rows.Close(); err != nil {
×
958
                return nil, err
×
959
        }
×
960
        if err := rows.Err(); err != nil {
×
961
                return nil, err
×
962
        }
×
963
        return items, nil
×
964
}
965

966
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
967
INSERT INTO payment_htlc_attempts (
968
    payment_id,
969
    attempt_index,
970
    session_key,
971
    attempt_time,
972
    payment_hash,
973
    first_hop_amount_msat,
974
    route_total_time_lock,
975
    route_total_amount,
976
    route_source_key)
977
VALUES (
978
    $1,
979
    $2,
980
    $3,
981
    $4,
982
    $5, 
983
    $6, 
984
    $7, 
985
    $8, 
986
    $9)
987
RETURNING id
988
`
989

990
type InsertHtlcAttemptParams struct {
991
        PaymentID          int64
992
        AttemptIndex       int64
993
        SessionKey         []byte
994
        AttemptTime        time.Time
995
        PaymentHash        []byte
996
        FirstHopAmountMsat int64
997
        RouteTotalTimeLock int32
998
        RouteTotalAmount   int64
999
        RouteSourceKey     []byte
1000
}
1001

1002
func (q *Queries) InsertHtlcAttempt(ctx context.Context, arg InsertHtlcAttemptParams) (int64, error) {
×
1003
        row := q.db.QueryRowContext(ctx, insertHtlcAttempt,
×
1004
                arg.PaymentID,
×
1005
                arg.AttemptIndex,
×
1006
                arg.SessionKey,
×
1007
                arg.AttemptTime,
×
1008
                arg.PaymentHash,
×
1009
                arg.FirstHopAmountMsat,
×
1010
                arg.RouteTotalTimeLock,
×
1011
                arg.RouteTotalAmount,
×
1012
                arg.RouteSourceKey,
×
1013
        )
×
1014
        var id int64
×
1015
        err := row.Scan(&id)
×
1016
        return id, err
×
1017
}
×
1018

1019
const insertPayment = `-- name: InsertPayment :one
1020
INSERT INTO payments (
1021
    amount_msat, 
1022
    created_at, 
1023
    payment_identifier,
1024
    fail_reason)
1025
VALUES (
1026
    $1,
1027
    $2,
1028
    $3,
1029
    NULL
1030
)
1031
RETURNING id
1032
`
1033

1034
type InsertPaymentParams struct {
1035
        AmountMsat        int64
1036
        CreatedAt         time.Time
1037
        PaymentIdentifier []byte
1038
}
1039

1040
// Insert a new payment and return its ID.
1041
// When creating a payment we don't have a fail reason because we start the
1042
// payment process.
1043
func (q *Queries) InsertPayment(ctx context.Context, arg InsertPaymentParams) (int64, error) {
×
1044
        row := q.db.QueryRowContext(ctx, insertPayment, arg.AmountMsat, arg.CreatedAt, arg.PaymentIdentifier)
×
1045
        var id int64
×
1046
        err := row.Scan(&id)
×
1047
        return id, err
×
1048
}
×
1049

1050
const insertPaymentAttemptFirstHopCustomRecord = `-- name: InsertPaymentAttemptFirstHopCustomRecord :exec
1051
INSERT INTO payment_attempt_first_hop_custom_records (
1052
    htlc_attempt_index,
1053
    key,
1054
    value
1055
)
1056
VALUES (
1057
    $1,
1058
    $2,
1059
    $3
1060
)
1061
`
1062

1063
type InsertPaymentAttemptFirstHopCustomRecordParams struct {
1064
        HtlcAttemptIndex int64
1065
        Key              int64
1066
        Value            []byte
1067
}
1068

1069
func (q *Queries) InsertPaymentAttemptFirstHopCustomRecord(ctx context.Context, arg InsertPaymentAttemptFirstHopCustomRecordParams) error {
×
1070
        _, err := q.db.ExecContext(ctx, insertPaymentAttemptFirstHopCustomRecord, arg.HtlcAttemptIndex, arg.Key, arg.Value)
×
1071
        return err
×
1072
}
×
1073

1074
const insertPaymentDuplicateMig = `-- name: InsertPaymentDuplicateMig :one
1075
INSERT INTO payment_duplicates (
1076
    payment_id,
1077
    amount_msat,
1078
    created_at,
1079
    fail_reason,
1080
    settle_preimage,
1081
    settle_time
1082
)
1083
VALUES (
1084
    $1,
1085
    $2,
1086
    $3,
1087
    $4,
1088
    $5,
1089
    $6
1090
)
1091
RETURNING id
1092
`
1093

1094
type InsertPaymentDuplicateMigParams struct {
1095
        PaymentID      int64
1096
        AmountMsat     int64
1097
        CreatedAt      time.Time
1098
        FailReason     sql.NullInt32
1099
        SettlePreimage []byte
1100
        SettleTime     sql.NullTime
1101
}
1102

1103
// Insert a duplicate payment record into the payment_duplicates table and
1104
// return its ID.
1105
func (q *Queries) InsertPaymentDuplicateMig(ctx context.Context, arg InsertPaymentDuplicateMigParams) (int64, error) {
×
1106
        row := q.db.QueryRowContext(ctx, insertPaymentDuplicateMig,
×
1107
                arg.PaymentID,
×
1108
                arg.AmountMsat,
×
1109
                arg.CreatedAt,
×
1110
                arg.FailReason,
×
1111
                arg.SettlePreimage,
×
1112
                arg.SettleTime,
×
1113
        )
×
1114
        var id int64
×
1115
        err := row.Scan(&id)
×
1116
        return id, err
×
1117
}
×
1118

1119
const insertPaymentFirstHopCustomRecord = `-- name: InsertPaymentFirstHopCustomRecord :exec
1120
INSERT INTO payment_first_hop_custom_records (
1121
    payment_id,
1122
    key,
1123
    value
1124
)
1125
VALUES (
1126
    $1,
1127
    $2,
1128
    $3
1129
)
1130
`
1131

1132
type InsertPaymentFirstHopCustomRecordParams struct {
1133
        PaymentID int64
1134
        Key       int64
1135
        Value     []byte
1136
}
1137

1138
func (q *Queries) InsertPaymentFirstHopCustomRecord(ctx context.Context, arg InsertPaymentFirstHopCustomRecordParams) error {
×
1139
        _, err := q.db.ExecContext(ctx, insertPaymentFirstHopCustomRecord, arg.PaymentID, arg.Key, arg.Value)
×
1140
        return err
×
1141
}
×
1142

1143
const insertPaymentHopCustomRecord = `-- name: InsertPaymentHopCustomRecord :exec
1144
INSERT INTO payment_hop_custom_records (
1145
    hop_id,
1146
    key,
1147
    value
1148
)
1149
VALUES (
1150
    $1,
1151
    $2,
1152
    $3
1153
)
1154
`
1155

1156
type InsertPaymentHopCustomRecordParams struct {
1157
        HopID int64
1158
        Key   int64
1159
        Value []byte
1160
}
1161

1162
func (q *Queries) InsertPaymentHopCustomRecord(ctx context.Context, arg InsertPaymentHopCustomRecordParams) error {
×
1163
        _, err := q.db.ExecContext(ctx, insertPaymentHopCustomRecord, arg.HopID, arg.Key, arg.Value)
×
1164
        return err
×
1165
}
×
1166

1167
const insertPaymentIntent = `-- name: InsertPaymentIntent :one
1168
INSERT INTO payment_intents (
1169
    payment_id,
1170
    intent_type, 
1171
    intent_payload)
1172
VALUES (
1173
    $1,
1174
    $2, 
1175
    $3
1176
)
1177
RETURNING id
1178
`
1179

1180
type InsertPaymentIntentParams struct {
1181
        PaymentID     int64
1182
        IntentType    int16
1183
        IntentPayload []byte
1184
}
1185

1186
// Insert a payment intent for a given payment and return its ID.
1187
func (q *Queries) InsertPaymentIntent(ctx context.Context, arg InsertPaymentIntentParams) (int64, error) {
×
1188
        row := q.db.QueryRowContext(ctx, insertPaymentIntent, arg.PaymentID, arg.IntentType, arg.IntentPayload)
×
1189
        var id int64
×
1190
        err := row.Scan(&id)
×
1191
        return id, err
×
1192
}
×
1193

1194
const insertPaymentMig = `-- name: InsertPaymentMig :one
1195
/* ─────────────────────────────────────────────
1196
   Migration-specific queries
1197

1198
   These queries are used ONLY for the one-time migration from KV to SQL.
1199
   ─────────────────────────────────────────────
1200
*/
1201

1202
INSERT INTO payments (
1203
    amount_msat,
1204
    created_at,
1205
    payment_identifier,
1206
    fail_reason)
1207
VALUES (
1208
    $1,
1209
    $2,
1210
    $3,
1211
    $4
1212
)
1213
RETURNING id
1214
`
1215

1216
type InsertPaymentMigParams struct {
1217
        AmountMsat        int64
1218
        CreatedAt         time.Time
1219
        PaymentIdentifier []byte
1220
        FailReason        sql.NullInt32
1221
}
1222

1223
// Migration-specific payment insert that allows setting fail_reason.
1224
// Normal InsertPayment forces fail_reason to NULL since new payments
1225
// aren't failed yet. During migration, we're inserting historical data
1226
// that may already be failed.
1227
func (q *Queries) InsertPaymentMig(ctx context.Context, arg InsertPaymentMigParams) (int64, error) {
×
1228
        row := q.db.QueryRowContext(ctx, insertPaymentMig,
×
1229
                arg.AmountMsat,
×
1230
                arg.CreatedAt,
×
1231
                arg.PaymentIdentifier,
×
1232
                arg.FailReason,
×
1233
        )
×
1234
        var id int64
×
1235
        err := row.Scan(&id)
×
1236
        return id, err
×
1237
}
×
1238

1239
const insertRouteHop = `-- name: InsertRouteHop :one
1240
INSERT INTO payment_route_hops (
1241
    htlc_attempt_index,
1242
    hop_index,
1243
    pub_key,
1244
    scid,
1245
    outgoing_time_lock,
1246
    amt_to_forward,
1247
    meta_data
1248
)
1249
VALUES (
1250
    $1,
1251
    $2,
1252
    $3,
1253
    $4,
1254
    $5,
1255
    $6,
1256
    $7
1257
)
1258
RETURNING id
1259
`
1260

1261
type InsertRouteHopParams struct {
1262
        HtlcAttemptIndex int64
1263
        HopIndex         int32
1264
        PubKey           []byte
1265
        Scid             string
1266
        OutgoingTimeLock int32
1267
        AmtToForward     int64
1268
        MetaData         []byte
1269
}
1270

1271
func (q *Queries) InsertRouteHop(ctx context.Context, arg InsertRouteHopParams) (int64, error) {
×
1272
        row := q.db.QueryRowContext(ctx, insertRouteHop,
×
1273
                arg.HtlcAttemptIndex,
×
1274
                arg.HopIndex,
×
1275
                arg.PubKey,
×
1276
                arg.Scid,
×
1277
                arg.OutgoingTimeLock,
×
1278
                arg.AmtToForward,
×
1279
                arg.MetaData,
×
1280
        )
×
1281
        var id int64
×
1282
        err := row.Scan(&id)
×
1283
        return id, err
×
1284
}
×
1285

1286
const insertRouteHopAmp = `-- name: InsertRouteHopAmp :exec
1287
INSERT INTO payment_route_hop_amp (
1288
    hop_id,
1289
    root_share,
1290
    set_id,
1291
    child_index
1292
)
1293
VALUES (
1294
    $1,
1295
    $2,
1296
    $3,
1297
    $4
1298
)
1299
`
1300

1301
type InsertRouteHopAmpParams struct {
1302
        HopID      int64
1303
        RootShare  []byte
1304
        SetID      []byte
1305
        ChildIndex int32
1306
}
1307

1308
func (q *Queries) InsertRouteHopAmp(ctx context.Context, arg InsertRouteHopAmpParams) error {
×
1309
        _, err := q.db.ExecContext(ctx, insertRouteHopAmp,
×
1310
                arg.HopID,
×
1311
                arg.RootShare,
×
1312
                arg.SetID,
×
1313
                arg.ChildIndex,
×
1314
        )
×
1315
        return err
×
1316
}
×
1317

1318
const insertRouteHopBlinded = `-- name: InsertRouteHopBlinded :exec
1319
INSERT INTO payment_route_hop_blinded (
1320
    hop_id,
1321
    encrypted_data,
1322
    blinding_point,
1323
    blinded_path_total_amt
1324
)
1325
VALUES (
1326
    $1,
1327
    $2,
1328
    $3,
1329
    $4
1330
)
1331
`
1332

1333
type InsertRouteHopBlindedParams struct {
1334
        HopID               int64
1335
        EncryptedData       []byte
1336
        BlindingPoint       []byte
1337
        BlindedPathTotalAmt sql.NullInt64
1338
}
1339

1340
func (q *Queries) InsertRouteHopBlinded(ctx context.Context, arg InsertRouteHopBlindedParams) error {
×
1341
        _, err := q.db.ExecContext(ctx, insertRouteHopBlinded,
×
1342
                arg.HopID,
×
1343
                arg.EncryptedData,
×
1344
                arg.BlindingPoint,
×
1345
                arg.BlindedPathTotalAmt,
×
1346
        )
×
1347
        return err
×
1348
}
×
1349

1350
const insertRouteHopMpp = `-- name: InsertRouteHopMpp :exec
1351
INSERT INTO payment_route_hop_mpp (
1352
    hop_id,
1353
    payment_addr,
1354
    total_msat
1355
)
1356
VALUES (
1357
    $1,
1358
    $2,
1359
    $3
1360
)
1361
`
1362

1363
type InsertRouteHopMppParams struct {
1364
        HopID       int64
1365
        PaymentAddr []byte
1366
        TotalMsat   int64
1367
}
1368

1369
func (q *Queries) InsertRouteHopMpp(ctx context.Context, arg InsertRouteHopMppParams) error {
×
1370
        _, err := q.db.ExecContext(ctx, insertRouteHopMpp, arg.HopID, arg.PaymentAddr, arg.TotalMsat)
×
1371
        return err
×
1372
}
×
1373

1374
const settleAttempt = `-- name: SettleAttempt :exec
1375
INSERT INTO payment_htlc_attempt_resolutions (
1376
    attempt_index,
1377
    resolution_time,
1378
    resolution_type,
1379
    settle_preimage
1380
)
1381
VALUES (
1382
    $1,
1383
    $2,
1384
    $3,
1385
    $4
1386
)
1387
`
1388

1389
type SettleAttemptParams struct {
1390
        AttemptIndex   int64
1391
        ResolutionTime time.Time
1392
        ResolutionType int32
1393
        SettlePreimage []byte
1394
}
1395

1396
func (q *Queries) SettleAttempt(ctx context.Context, arg SettleAttemptParams) error {
×
1397
        _, err := q.db.ExecContext(ctx, settleAttempt,
×
1398
                arg.AttemptIndex,
×
1399
                arg.ResolutionTime,
×
1400
                arg.ResolutionType,
×
1401
                arg.SettlePreimage,
×
1402
        )
×
1403
        return err
×
1404
}
×
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