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

lightningnetwork / lnd / 23063587730

13 Mar 2026 05:50PM UTC coverage: 62.261% (-0.1%) from 62.366%
23063587730

push

github

web-flow
Merge pull request #10535 from ziggie1984/kvdb-sql-payments-improvements

improve speed of retrieval of payments

9 of 225 new or added lines in 10 files covered. (4.0%)

393 existing lines in 32 files now uncovered.

140787 of 226124 relevant lines covered (62.26%)

19396.68 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
)
UNCOV
34
`
×
UNCOV
35

×
UNCOV
36
// Delete all failed HTLC attempts for the given payment. Resolution type 2
×
NEW
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
}
×
UNCOV
44

×
UNCOV
45
const deletePayment = `-- name: DeletePayment :exec
×
UNCOV
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
UNCOV
76
        ResolutionType     int32
×
UNCOV
77
        FailureSourceIndex sql.NullInt32
×
UNCOV
78
        HtlcFailReason     sql.NullInt32
×
UNCOV
79
        FailureMsg         []byte
×
UNCOV
80
}
×
UNCOV
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
`
UNCOV
97

×
UNCOV
98
type FailPaymentParams struct {
×
UNCOV
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 {
UNCOV
130
        AttemptIndex int64
×
UNCOV
131
        Limit        int32
×
UNCOV
132
}
×
UNCOV
133

×
UNCOV
134
// Fetch all inflight attempts with their payment data using pagination.
×
UNCOV
135
// Returns attempt data joined with payment and intent data to avoid separate queries.
×
136
func (q *Queries) FetchAllInflightAttempts(ctx context.Context, arg FetchAllInflightAttemptsParams) ([]PaymentHtlcAttempt, error) {
×
137
        rows, err := q.db.QueryContext(ctx, fetchAllInflightAttempts, arg.AttemptIndex, arg.Limit)
×
138
        if err != nil {
×
139
                return nil, err
×
140
        }
×
141
        defer rows.Close()
×
142
        var items []PaymentHtlcAttempt
×
143
        for rows.Next() {
×
144
                var i PaymentHtlcAttempt
×
145
                if err := rows.Scan(
×
146
                        &i.ID,
×
147
                        &i.AttemptIndex,
×
148
                        &i.PaymentID,
×
149
                        &i.SessionKey,
×
150
                        &i.AttemptTime,
×
151
                        &i.PaymentHash,
×
152
                        &i.FirstHopAmountMsat,
×
153
                        &i.RouteTotalTimeLock,
×
154
                        &i.RouteTotalAmount,
×
155
                        &i.RouteSourceKey,
×
156
                ); err != nil {
×
157
                        return nil, err
×
158
                }
×
159
                items = append(items, i)
×
UNCOV
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,
UNCOV
175
    l.value
×
UNCOV
176
FROM payment_hop_custom_records l
×
UNCOV
177
WHERE l.hop_id IN (/*SLICE:hop_ids*/?)
×
UNCOV
178
ORDER BY l.hop_id ASC, l.key ASC
×
UNCOV
179
`
×
UNCOV
180

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

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

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

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

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

×
UNCOV
502
// Fetch all duplicate payment records from the payment_duplicates table for
×
UNCOV
503
// a given payment ID.
×
504
func (q *Queries) FetchPaymentDuplicates(ctx context.Context, paymentID int64) ([]PaymentDuplicate, error) {
×
505
        rows, err := q.db.QueryContext(ctx, fetchPaymentDuplicates, paymentID)
×
506
        if err != nil {
×
507
                return nil, err
×
508
        }
×
509
        defer rows.Close()
×
510
        var items []PaymentDuplicate
×
511
        for rows.Next() {
×
512
                var i PaymentDuplicate
×
513
                if err := rows.Scan(
×
514
                        &i.ID,
×
515
                        &i.PaymentID,
×
516
                        &i.AmountMsat,
×
517
                        &i.CreatedAt,
×
518
                        &i.FailReason,
×
519
                        &i.SettlePreimage,
×
520
                        &i.SettleTime,
×
521
                ); err != nil {
×
522
                        return nil, err
×
523
                }
×
524
                items = append(items, i)
×
UNCOV
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,
UNCOV
540
    l.value
×
UNCOV
541
FROM payment_first_hop_custom_records l
×
UNCOV
542
WHERE l.payment_id IN (/*SLICE:payment_ids*/?)
×
UNCOV
543
ORDER BY l.payment_id ASC, l.key ASC
×
UNCOV
544
`
×
UNCOV
545

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

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

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

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

×
730
func (q *Queries) FetchRouteLevelFirstHopCustomRecords(ctx context.Context, htlcAttemptIndices []int64) ([]PaymentAttemptFirstHopCustomRecord, error) {
×
731
        query := fetchRouteLevelFirstHopCustomRecords
×
732
        var queryParams []interface{}
×
733
        if len(htlcAttemptIndices) > 0 {
×
734
                for _, v := range htlcAttemptIndices {
×
735
                        queryParams = append(queryParams, v)
×
736
                }
×
737
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", makeQueryParams(len(queryParams), len(htlcAttemptIndices)), 1)
×
738
        } else {
×
739
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", "NULL", 1)
×
740
        }
×
741
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
742
        if err != nil {
×
743
                return nil, err
×
744
        }
×
745
        defer rows.Close()
×
746
        var items []PaymentAttemptFirstHopCustomRecord
×
747
        for rows.Next() {
×
748
                var i PaymentAttemptFirstHopCustomRecord
×
749
                if err := rows.Scan(
×
750
                        &i.ID,
×
751
                        &i.HtlcAttemptIndex,
×
752
                        &i.Key,
×
753
                        &i.Value,
×
754
                ); err != nil {
×
755
                        return nil, err
×
756
                }
×
757
                items = append(items, i)
×
UNCOV
758
        }
×
759
        if err := rows.Close(); err != nil {
×
760
                return nil, err
×
761
        }
×
762
        if err := rows.Err(); err != nil {
×
763
                return nil, err
×
764
        }
×
765
        return items, nil
×
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 (
781
    p.id > $1 OR
782
    $1 IS NULL
783
) AND (
784
    p.id < $2 OR
785
    $2 IS NULL
786
) AND (
787
    p.created_at >= $3 OR
788
    $3 IS NULL
789
) AND (
790
    p.created_at <= $4 OR
791
    $4 IS NULL
792
) AND (
793
    i.intent_type = $5 OR
794
    $5 IS NULL OR i.intent_type IS NULL
795
)
796
ORDER BY
797
    CASE WHEN $6 = false OR $6 IS NULL THEN p.id END ASC,
798
    CASE WHEN $6 = true THEN p.id END DESC
799
LIMIT $7
800
`
801

802
type FilterPaymentsParams struct {
803
        IndexOffsetGet sql.NullInt64
804
        IndexOffsetLet sql.NullInt64
805
        CreatedAfter   sql.NullTime
806
        CreatedBefore  sql.NullTime
807
        IntentType     sql.NullInt16
808
        Reverse        interface{}
809
        NumLimit       int32
810
}
811

UNCOV
812
type FilterPaymentsRow struct {
×
UNCOV
813
        Payment       Payment
×
UNCOV
814
        IntentType    sql.NullInt16
×
UNCOV
815
        IntentPayload []byte
×
UNCOV
816
}
×
UNCOV
817

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

857
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
858
INSERT INTO payment_htlc_attempts (
859
    payment_id,
860
    attempt_index,
861
    session_key,
862
    attempt_time,
863
    payment_hash,
864
    first_hop_amount_msat,
865
    route_total_time_lock,
866
    route_total_amount,
867
    route_source_key)
868
VALUES (
869
    $1,
870
    $2,
871
    $3,
872
    $4,
873
    $5, 
874
    $6, 
875
    $7, 
876
    $8, 
877
    $9)
878
RETURNING id
879
`
880

881
type InsertHtlcAttemptParams struct {
882
        PaymentID          int64
883
        AttemptIndex       int64
884
        SessionKey         []byte
885
        AttemptTime        time.Time
886
        PaymentHash        []byte
UNCOV
887
        FirstHopAmountMsat int64
×
UNCOV
888
        RouteTotalTimeLock int32
×
UNCOV
889
        RouteTotalAmount   int64
×
UNCOV
890
        RouteSourceKey     []byte
×
UNCOV
891
}
×
UNCOV
892

×
893
func (q *Queries) InsertHtlcAttempt(ctx context.Context, arg InsertHtlcAttemptParams) (int64, error) {
×
894
        row := q.db.QueryRowContext(ctx, insertHtlcAttempt,
×
895
                arg.PaymentID,
×
896
                arg.AttemptIndex,
×
897
                arg.SessionKey,
×
898
                arg.AttemptTime,
×
899
                arg.PaymentHash,
×
900
                arg.FirstHopAmountMsat,
×
901
                arg.RouteTotalTimeLock,
×
902
                arg.RouteTotalAmount,
×
903
                arg.RouteSourceKey,
×
904
        )
×
905
        var id int64
×
906
        err := row.Scan(&id)
×
907
        return id, err
×
908
}
×
909

910
const insertPayment = `-- name: InsertPayment :one
911
INSERT INTO payments (
912
    amount_msat, 
913
    created_at, 
914
    payment_identifier,
915
    fail_reason)
916
VALUES (
917
    $1,
918
    $2,
919
    $3,
920
    NULL
921
)
922
RETURNING id
923
`
924

925
type InsertPaymentParams struct {
926
        AmountMsat        int64
927
        CreatedAt         time.Time
UNCOV
928
        PaymentIdentifier []byte
×
UNCOV
929
}
×
UNCOV
930

×
UNCOV
931
// Insert a new payment and return its ID.
×
UNCOV
932
// When creating a payment we don't have a fail reason because we start the
×
UNCOV
933
// payment process.
×
934
func (q *Queries) InsertPayment(ctx context.Context, arg InsertPaymentParams) (int64, error) {
×
935
        row := q.db.QueryRowContext(ctx, insertPayment, arg.AmountMsat, arg.CreatedAt, arg.PaymentIdentifier)
×
936
        var id int64
×
937
        err := row.Scan(&id)
×
938
        return id, err
×
939
}
×
940

941
const insertPaymentAttemptFirstHopCustomRecord = `-- name: InsertPaymentAttemptFirstHopCustomRecord :exec
942
INSERT INTO payment_attempt_first_hop_custom_records (
943
    htlc_attempt_index,
944
    key,
945
    value
946
)
947
VALUES (
948
    $1,
949
    $2,
950
    $3
951
)
952
`
953

UNCOV
954
type InsertPaymentAttemptFirstHopCustomRecordParams struct {
×
UNCOV
955
        HtlcAttemptIndex int64
×
UNCOV
956
        Key              int64
×
UNCOV
957
        Value            []byte
×
958
}
959

960
func (q *Queries) InsertPaymentAttemptFirstHopCustomRecord(ctx context.Context, arg InsertPaymentAttemptFirstHopCustomRecordParams) error {
×
961
        _, err := q.db.ExecContext(ctx, insertPaymentAttemptFirstHopCustomRecord, arg.HtlcAttemptIndex, arg.Key, arg.Value)
×
962
        return err
×
963
}
×
964

965
const insertPaymentDuplicateMig = `-- name: InsertPaymentDuplicateMig :one
966
INSERT INTO payment_duplicates (
967
    payment_id,
968
    amount_msat,
969
    created_at,
970
    fail_reason,
971
    settle_preimage,
972
    settle_time
973
)
974
VALUES (
975
    $1,
976
    $2,
977
    $3,
978
    $4,
979
    $5,
980
    $6
981
)
982
RETURNING id
983
`
984

985
type InsertPaymentDuplicateMigParams struct {
986
        PaymentID      int64
987
        AmountMsat     int64
988
        CreatedAt      time.Time
989
        FailReason     sql.NullInt32
UNCOV
990
        SettlePreimage []byte
×
UNCOV
991
        SettleTime     sql.NullTime
×
UNCOV
992
}
×
UNCOV
993

×
UNCOV
994
// Insert a duplicate payment record into the payment_duplicates table and
×
UNCOV
995
// return its ID.
×
996
func (q *Queries) InsertPaymentDuplicateMig(ctx context.Context, arg InsertPaymentDuplicateMigParams) (int64, error) {
×
997
        row := q.db.QueryRowContext(ctx, insertPaymentDuplicateMig,
×
998
                arg.PaymentID,
×
999
                arg.AmountMsat,
×
1000
                arg.CreatedAt,
×
1001
                arg.FailReason,
×
1002
                arg.SettlePreimage,
×
1003
                arg.SettleTime,
×
1004
        )
×
1005
        var id int64
×
1006
        err := row.Scan(&id)
×
1007
        return id, err
×
1008
}
×
1009

1010
const insertPaymentFirstHopCustomRecord = `-- name: InsertPaymentFirstHopCustomRecord :exec
1011
INSERT INTO payment_first_hop_custom_records (
1012
    payment_id,
1013
    key,
1014
    value
1015
)
1016
VALUES (
1017
    $1,
1018
    $2,
1019
    $3
1020
)
1021
`
1022

UNCOV
1023
type InsertPaymentFirstHopCustomRecordParams struct {
×
UNCOV
1024
        PaymentID int64
×
UNCOV
1025
        Key       int64
×
UNCOV
1026
        Value     []byte
×
1027
}
1028

1029
func (q *Queries) InsertPaymentFirstHopCustomRecord(ctx context.Context, arg InsertPaymentFirstHopCustomRecordParams) error {
×
1030
        _, err := q.db.ExecContext(ctx, insertPaymentFirstHopCustomRecord, arg.PaymentID, arg.Key, arg.Value)
×
1031
        return err
×
1032
}
×
1033

1034
const insertPaymentHopCustomRecord = `-- name: InsertPaymentHopCustomRecord :exec
1035
INSERT INTO payment_hop_custom_records (
1036
    hop_id,
1037
    key,
1038
    value
1039
)
1040
VALUES (
1041
    $1,
1042
    $2,
1043
    $3
1044
)
1045
`
1046

UNCOV
1047
type InsertPaymentHopCustomRecordParams struct {
×
UNCOV
1048
        HopID int64
×
UNCOV
1049
        Key   int64
×
UNCOV
1050
        Value []byte
×
1051
}
1052

1053
func (q *Queries) InsertPaymentHopCustomRecord(ctx context.Context, arg InsertPaymentHopCustomRecordParams) error {
×
1054
        _, err := q.db.ExecContext(ctx, insertPaymentHopCustomRecord, arg.HopID, arg.Key, arg.Value)
×
1055
        return err
×
1056
}
×
1057

1058
const insertPaymentIntent = `-- name: InsertPaymentIntent :one
1059
INSERT INTO payment_intents (
1060
    payment_id,
1061
    intent_type, 
1062
    intent_payload)
1063
VALUES (
1064
    $1,
1065
    $2, 
1066
    $3
1067
)
1068
RETURNING id
1069
`
1070

1071
type InsertPaymentIntentParams struct {
UNCOV
1072
        PaymentID     int64
×
UNCOV
1073
        IntentType    int16
×
UNCOV
1074
        IntentPayload []byte
×
UNCOV
1075
}
×
UNCOV
1076

×
UNCOV
1077
// Insert a payment intent for a given payment and return its ID.
×
1078
func (q *Queries) InsertPaymentIntent(ctx context.Context, arg InsertPaymentIntentParams) (int64, error) {
×
1079
        row := q.db.QueryRowContext(ctx, insertPaymentIntent, arg.PaymentID, arg.IntentType, arg.IntentPayload)
×
1080
        var id int64
×
1081
        err := row.Scan(&id)
×
1082
        return id, err
×
1083
}
×
1084

1085
const insertPaymentMig = `-- name: InsertPaymentMig :one
1086
/* ─────────────────────────────────────────────
1087
   Migration-specific queries
1088

1089
   These queries are used ONLY for the one-time migration from KV to SQL.
1090
   ─────────────────────────────────────────────
1091
*/
1092

1093
INSERT INTO payments (
1094
    amount_msat,
1095
    created_at,
1096
    payment_identifier,
1097
    fail_reason)
1098
VALUES (
1099
    $1,
1100
    $2,
1101
    $3,
1102
    $4
1103
)
1104
RETURNING id
1105
`
1106

1107
type InsertPaymentMigParams struct {
1108
        AmountMsat        int64
1109
        CreatedAt         time.Time
1110
        PaymentIdentifier []byte
1111
        FailReason        sql.NullInt32
UNCOV
1112
}
×
UNCOV
1113

×
UNCOV
1114
// Migration-specific payment insert that allows setting fail_reason.
×
UNCOV
1115
// Normal InsertPayment forces fail_reason to NULL since new payments
×
UNCOV
1116
// aren't failed yet. During migration, we're inserting historical data
×
UNCOV
1117
// that may already be failed.
×
1118
func (q *Queries) InsertPaymentMig(ctx context.Context, arg InsertPaymentMigParams) (int64, error) {
×
1119
        row := q.db.QueryRowContext(ctx, insertPaymentMig,
×
1120
                arg.AmountMsat,
×
1121
                arg.CreatedAt,
×
1122
                arg.PaymentIdentifier,
×
1123
                arg.FailReason,
×
1124
        )
×
1125
        var id int64
×
1126
        err := row.Scan(&id)
×
1127
        return id, err
×
1128
}
×
1129

1130
const insertRouteHop = `-- name: InsertRouteHop :one
1131
INSERT INTO payment_route_hops (
1132
    htlc_attempt_index,
1133
    hop_index,
1134
    pub_key,
1135
    scid,
1136
    outgoing_time_lock,
1137
    amt_to_forward,
1138
    meta_data
1139
)
1140
VALUES (
1141
    $1,
1142
    $2,
1143
    $3,
1144
    $4,
1145
    $5,
1146
    $6,
1147
    $7
1148
)
1149
RETURNING id
1150
`
1151

1152
type InsertRouteHopParams struct {
1153
        HtlcAttemptIndex int64
1154
        HopIndex         int32
1155
        PubKey           []byte
UNCOV
1156
        Scid             string
×
UNCOV
1157
        OutgoingTimeLock int32
×
UNCOV
1158
        AmtToForward     int64
×
UNCOV
1159
        MetaData         []byte
×
UNCOV
1160
}
×
UNCOV
1161

×
1162
func (q *Queries) InsertRouteHop(ctx context.Context, arg InsertRouteHopParams) (int64, error) {
×
1163
        row := q.db.QueryRowContext(ctx, insertRouteHop,
×
1164
                arg.HtlcAttemptIndex,
×
1165
                arg.HopIndex,
×
1166
                arg.PubKey,
×
1167
                arg.Scid,
×
1168
                arg.OutgoingTimeLock,
×
1169
                arg.AmtToForward,
×
1170
                arg.MetaData,
×
1171
        )
×
1172
        var id int64
×
1173
        err := row.Scan(&id)
×
1174
        return id, err
×
1175
}
×
1176

1177
const insertRouteHopAmp = `-- name: InsertRouteHopAmp :exec
1178
INSERT INTO payment_route_hop_amp (
1179
    hop_id,
1180
    root_share,
1181
    set_id,
1182
    child_index
1183
)
1184
VALUES (
1185
    $1,
1186
    $2,
1187
    $3,
1188
    $4
1189
)
1190
`
1191

1192
type InsertRouteHopAmpParams struct {
UNCOV
1193
        HopID      int64
×
UNCOV
1194
        RootShare  []byte
×
UNCOV
1195
        SetID      []byte
×
UNCOV
1196
        ChildIndex int32
×
UNCOV
1197
}
×
UNCOV
1198

×
1199
func (q *Queries) InsertRouteHopAmp(ctx context.Context, arg InsertRouteHopAmpParams) error {
×
1200
        _, err := q.db.ExecContext(ctx, insertRouteHopAmp,
×
1201
                arg.HopID,
×
1202
                arg.RootShare,
×
1203
                arg.SetID,
×
1204
                arg.ChildIndex,
×
1205
        )
×
1206
        return err
×
1207
}
×
1208

1209
const insertRouteHopBlinded = `-- name: InsertRouteHopBlinded :exec
1210
INSERT INTO payment_route_hop_blinded (
1211
    hop_id,
1212
    encrypted_data,
1213
    blinding_point,
1214
    blinded_path_total_amt
1215
)
1216
VALUES (
1217
    $1,
1218
    $2,
1219
    $3,
1220
    $4
1221
)
1222
`
1223

1224
type InsertRouteHopBlindedParams struct {
UNCOV
1225
        HopID               int64
×
UNCOV
1226
        EncryptedData       []byte
×
UNCOV
1227
        BlindingPoint       []byte
×
UNCOV
1228
        BlindedPathTotalAmt sql.NullInt64
×
UNCOV
1229
}
×
UNCOV
1230

×
1231
func (q *Queries) InsertRouteHopBlinded(ctx context.Context, arg InsertRouteHopBlindedParams) error {
×
1232
        _, err := q.db.ExecContext(ctx, insertRouteHopBlinded,
×
1233
                arg.HopID,
×
1234
                arg.EncryptedData,
×
1235
                arg.BlindingPoint,
×
1236
                arg.BlindedPathTotalAmt,
×
1237
        )
×
1238
        return err
×
1239
}
×
1240

1241
const insertRouteHopMpp = `-- name: InsertRouteHopMpp :exec
1242
INSERT INTO payment_route_hop_mpp (
1243
    hop_id,
1244
    payment_addr,
1245
    total_msat
1246
)
1247
VALUES (
1248
    $1,
1249
    $2,
1250
    $3
1251
)
1252
`
1253

UNCOV
1254
type InsertRouteHopMppParams struct {
×
UNCOV
1255
        HopID       int64
×
UNCOV
1256
        PaymentAddr []byte
×
UNCOV
1257
        TotalMsat   int64
×
1258
}
1259

1260
func (q *Queries) InsertRouteHopMpp(ctx context.Context, arg InsertRouteHopMppParams) error {
×
1261
        _, err := q.db.ExecContext(ctx, insertRouteHopMpp, arg.HopID, arg.PaymentAddr, arg.TotalMsat)
×
1262
        return err
×
1263
}
×
1264

1265
const settleAttempt = `-- name: SettleAttempt :exec
1266
INSERT INTO payment_htlc_attempt_resolutions (
1267
    attempt_index,
1268
    resolution_time,
1269
    resolution_type,
1270
    settle_preimage
1271
)
1272
VALUES (
1273
    $1,
1274
    $2,
1275
    $3,
1276
    $4
1277
)
1278
`
1279

1280
type SettleAttemptParams struct {
UNCOV
1281
        AttemptIndex   int64
×
UNCOV
1282
        ResolutionTime time.Time
×
UNCOV
1283
        ResolutionType int32
×
UNCOV
1284
        SettlePreimage []byte
×
UNCOV
1285
}
×
UNCOV
1286

×
1287
func (q *Queries) SettleAttempt(ctx context.Context, arg SettleAttemptParams) error {
×
1288
        _, err := q.db.ExecContext(ctx, settleAttempt,
×
1289
                arg.AttemptIndex,
×
1290
                arg.ResolutionTime,
×
1291
                arg.ResolutionType,
×
1292
                arg.SettlePreimage,
×
1293
        )
×
1294
        return err
×
1295
}
×
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