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

lightningnetwork / lnd / 17191871672

24 Aug 2025 05:44PM UTC coverage: 66.162% (+8.8%) from 57.321%
17191871672

Pull #9147

github

web-flow
Merge edec0450e into 0c2f045f5
Pull Request #9147: [Part 1|3] Introduce SQL Payment schema into LND

72 of 1878 new or added lines in 12 files covered. (3.83%)

17 existing lines in 7 files now uncovered.

135954 of 205487 relevant lines covered (66.16%)

21319.58 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

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

26
const deleteFailedAttempts = `-- name: DeleteFailedAttempts :exec
27
DELETE FROM payment_htlc_attempts WHERE payment_id = $1 AND htlc_fail_reason IS NOT NULL
28
`
29

30
// TODO(ziggie): Is the htlc_fail_reason always set for a failed attempt?
NEW
31
func (q *Queries) DeleteFailedAttempts(ctx context.Context, paymentID int64) error {
×
NEW
32
        _, err := q.db.ExecContext(ctx, deleteFailedAttempts, paymentID)
×
NEW
33
        return err
×
NEW
34
}
×
35

36
const deleteFailedAttemptsByAttemptIndices = `-- name: DeleteFailedAttemptsByAttemptIndices :exec
37
DELETE FROM payment_htlc_attempts WHERE attempt_index IN (/*SLICE:attempt_indices*/?)
38
`
39

NEW
40
func (q *Queries) DeleteFailedAttemptsByAttemptIndices(ctx context.Context, attemptIndices []int64) error {
×
NEW
41
        query := deleteFailedAttemptsByAttemptIndices
×
NEW
42
        var queryParams []interface{}
×
NEW
43
        if len(attemptIndices) > 0 {
×
NEW
44
                for _, v := range attemptIndices {
×
NEW
45
                        queryParams = append(queryParams, v)
×
NEW
46
                }
×
NEW
47
                query = strings.Replace(query, "/*SLICE:attempt_indices*/?", makeQueryParams(len(queryParams), len(attemptIndices)), 1)
×
NEW
48
        } else {
×
NEW
49
                query = strings.Replace(query, "/*SLICE:attempt_indices*/?", "NULL", 1)
×
NEW
50
        }
×
NEW
51
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
NEW
52
        return err
×
53
}
54

55
const deletePayment = `-- name: DeletePayment :exec
56
/* ─────────────────────────────────────────────
57
   Delete queries
58
   ─────────────────────────────────────────────
59
*/
60

61
DELETE FROM payments WHERE payment_hash = $1
62
`
63

NEW
64
func (q *Queries) DeletePayment(ctx context.Context, paymentHash []byte) error {
×
NEW
65
        _, err := q.db.ExecContext(ctx, deletePayment, paymentHash)
×
NEW
66
        return err
×
NEW
67
}
×
68

69
const deletePayments = `-- name: DeletePayments :exec
70
DELETE FROM payments WHERE id IN (/*SLICE:payment_ids*/?)
71
`
72

NEW
73
func (q *Queries) DeletePayments(ctx context.Context, paymentIds []int64) error {
×
NEW
74
        query := deletePayments
×
NEW
75
        var queryParams []interface{}
×
NEW
76
        if len(paymentIds) > 0 {
×
NEW
77
                for _, v := range paymentIds {
×
NEW
78
                        queryParams = append(queryParams, v)
×
NEW
79
                }
×
NEW
80
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", makeQueryParams(len(queryParams), len(paymentIds)), 1)
×
NEW
81
        } else {
×
NEW
82
                query = strings.Replace(query, "/*SLICE:payment_ids*/?", "NULL", 1)
×
NEW
83
        }
×
NEW
84
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
NEW
85
        return err
×
86
}
87

88
const fetchCustomRecordsForAttempts = `-- name: FetchCustomRecordsForAttempts :many
89
SELECT id, key, value, htlc_attempt_index FROM payment_htlc_attempt_custom_records
90
WHERE htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
91
`
92

NEW
93
func (q *Queries) FetchCustomRecordsForAttempts(ctx context.Context, htlcAttemptIndices []int64) ([]PaymentHtlcAttemptCustomRecord, error) {
×
NEW
94
        query := fetchCustomRecordsForAttempts
×
NEW
95
        var queryParams []interface{}
×
NEW
96
        if len(htlcAttemptIndices) > 0 {
×
NEW
97
                for _, v := range htlcAttemptIndices {
×
NEW
98
                        queryParams = append(queryParams, v)
×
NEW
99
                }
×
NEW
100
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", makeQueryParams(len(queryParams), len(htlcAttemptIndices)), 1)
×
NEW
101
        } else {
×
NEW
102
                query = strings.Replace(query, "/*SLICE:htlc_attempt_indices*/?", "NULL", 1)
×
NEW
103
        }
×
NEW
104
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
105
        if err != nil {
×
NEW
106
                return nil, err
×
NEW
107
        }
×
NEW
108
        defer rows.Close()
×
NEW
109
        var items []PaymentHtlcAttemptCustomRecord
×
NEW
110
        for rows.Next() {
×
NEW
111
                var i PaymentHtlcAttemptCustomRecord
×
NEW
112
                if err := rows.Scan(
×
NEW
113
                        &i.ID,
×
NEW
114
                        &i.Key,
×
NEW
115
                        &i.Value,
×
NEW
116
                        &i.HtlcAttemptIndex,
×
NEW
117
                ); err != nil {
×
NEW
118
                        return nil, err
×
NEW
119
                }
×
NEW
120
                items = append(items, i)
×
121
        }
NEW
122
        if err := rows.Close(); err != nil {
×
NEW
123
                return nil, err
×
NEW
124
        }
×
NEW
125
        if err := rows.Err(); err != nil {
×
NEW
126
                return nil, err
×
NEW
127
        }
×
NEW
128
        return items, nil
×
129
}
130

131
const fetchCustomRecordsForHops = `-- name: FetchCustomRecordsForHops :many
132
SELECT id, key, value, hop_id FROM payment_route_hop_custom_records
133
WHERE hop_id IN (/*SLICE:hop_ids*/?)
134
`
135

NEW
136
func (q *Queries) FetchCustomRecordsForHops(ctx context.Context, hopIds []int64) ([]PaymentRouteHopCustomRecord, error) {
×
NEW
137
        query := fetchCustomRecordsForHops
×
NEW
138
        var queryParams []interface{}
×
NEW
139
        if len(hopIds) > 0 {
×
NEW
140
                for _, v := range hopIds {
×
NEW
141
                        queryParams = append(queryParams, v)
×
NEW
142
                }
×
NEW
143
                query = strings.Replace(query, "/*SLICE:hop_ids*/?", makeQueryParams(len(queryParams), len(hopIds)), 1)
×
NEW
144
        } else {
×
NEW
145
                query = strings.Replace(query, "/*SLICE:hop_ids*/?", "NULL", 1)
×
NEW
146
        }
×
NEW
147
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
148
        if err != nil {
×
NEW
149
                return nil, err
×
NEW
150
        }
×
NEW
151
        defer rows.Close()
×
NEW
152
        var items []PaymentRouteHopCustomRecord
×
NEW
153
        for rows.Next() {
×
NEW
154
                var i PaymentRouteHopCustomRecord
×
NEW
155
                if err := rows.Scan(
×
NEW
156
                        &i.ID,
×
NEW
157
                        &i.Key,
×
NEW
158
                        &i.Value,
×
NEW
159
                        &i.HopID,
×
NEW
160
                ); err != nil {
×
NEW
161
                        return nil, err
×
NEW
162
                }
×
NEW
163
                items = append(items, i)
×
164
        }
NEW
165
        if err := rows.Close(); err != nil {
×
NEW
166
                return nil, err
×
NEW
167
        }
×
NEW
168
        if err := rows.Err(); err != nil {
×
NEW
169
                return nil, err
×
NEW
170
        }
×
NEW
171
        return items, nil
×
172
}
173

174
const fetchFirstHopCustomRecords = `-- name: FetchFirstHopCustomRecords :many
175
SELECT id, key, value, payment_id FROM payment_first_hop_custom_records WHERE payment_id = $1
176
`
177

NEW
178
func (q *Queries) FetchFirstHopCustomRecords(ctx context.Context, paymentID int64) ([]PaymentFirstHopCustomRecord, error) {
×
NEW
179
        rows, err := q.db.QueryContext(ctx, fetchFirstHopCustomRecords, paymentID)
×
NEW
180
        if err != nil {
×
NEW
181
                return nil, err
×
NEW
182
        }
×
NEW
183
        defer rows.Close()
×
NEW
184
        var items []PaymentFirstHopCustomRecord
×
NEW
185
        for rows.Next() {
×
NEW
186
                var i PaymentFirstHopCustomRecord
×
NEW
187
                if err := rows.Scan(
×
NEW
188
                        &i.ID,
×
NEW
189
                        &i.Key,
×
NEW
190
                        &i.Value,
×
NEW
191
                        &i.PaymentID,
×
NEW
192
                ); err != nil {
×
NEW
193
                        return nil, err
×
NEW
194
                }
×
NEW
195
                items = append(items, i)
×
196
        }
NEW
197
        if err := rows.Close(); err != nil {
×
NEW
198
                return nil, err
×
NEW
199
        }
×
NEW
200
        if err := rows.Err(); err != nil {
×
NEW
201
                return nil, err
×
NEW
202
        }
×
NEW
203
        return items, nil
×
204
}
205

206
const fetchHopsForAttempt = `-- name: FetchHopsForAttempt :many
207
SELECT id, htlc_attempt_index, hop_index, pub_key, scid, outgoing_time_lock, amt_to_forward, meta_data, legacy_payload, mpp_payment_addr, mpp_total_msat, amp_root_share, amp_set_id, amp_child_index, encrypted_data, blinding_point, blinded_path_total_amt FROM payment_route_hops h
208
WHERE h.htlc_attempt_index = $1
209
ORDER BY h.hop_index ASC
210
`
211

NEW
212
func (q *Queries) FetchHopsForAttempt(ctx context.Context, htlcAttemptIndex int64) ([]PaymentRouteHop, error) {
×
NEW
213
        rows, err := q.db.QueryContext(ctx, fetchHopsForAttempt, htlcAttemptIndex)
×
NEW
214
        if err != nil {
×
NEW
215
                return nil, err
×
NEW
216
        }
×
NEW
217
        defer rows.Close()
×
NEW
218
        var items []PaymentRouteHop
×
NEW
219
        for rows.Next() {
×
NEW
220
                var i PaymentRouteHop
×
NEW
221
                if err := rows.Scan(
×
NEW
222
                        &i.ID,
×
NEW
223
                        &i.HtlcAttemptIndex,
×
NEW
224
                        &i.HopIndex,
×
NEW
225
                        &i.PubKey,
×
NEW
226
                        &i.Scid,
×
NEW
227
                        &i.OutgoingTimeLock,
×
NEW
228
                        &i.AmtToForward,
×
NEW
229
                        &i.MetaData,
×
NEW
230
                        &i.LegacyPayload,
×
NEW
231
                        &i.MppPaymentAddr,
×
NEW
232
                        &i.MppTotalMsat,
×
NEW
233
                        &i.AmpRootShare,
×
NEW
234
                        &i.AmpSetID,
×
NEW
235
                        &i.AmpChildIndex,
×
NEW
236
                        &i.EncryptedData,
×
NEW
237
                        &i.BlindingPoint,
×
NEW
238
                        &i.BlindedPathTotalAmt,
×
NEW
239
                ); err != nil {
×
NEW
240
                        return nil, err
×
NEW
241
                }
×
NEW
242
                items = append(items, i)
×
243
        }
NEW
244
        if err := rows.Close(); err != nil {
×
NEW
245
                return nil, err
×
NEW
246
        }
×
NEW
247
        if err := rows.Err(); err != nil {
×
NEW
248
                return nil, err
×
NEW
249
        }
×
NEW
250
        return items, nil
×
251
}
252

253
const fetchHopsForAttempts = `-- name: FetchHopsForAttempts :many
254
SELECT id, htlc_attempt_index, hop_index, pub_key, scid, outgoing_time_lock, amt_to_forward, meta_data, legacy_payload, mpp_payment_addr, mpp_total_msat, amp_root_share, amp_set_id, amp_child_index, encrypted_data, blinding_point, blinded_path_total_amt FROM payment_route_hops 
255
WHERE htlc_attempt_index IN (/*SLICE:htlc_attempt_indices*/?)
256
`
257

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

309
const fetchHtlcAttempts = `-- name: FetchHtlcAttempts :many
310
SELECT id, attempt_index, payment_id, session_key, attempt_time, payment_hash, route_total_time_lock, route_total_amount, route_source_key, failure_source_index, htlc_fail_reason, failure_msg, fail_time, settle_preimage, settle_time FROM payment_htlc_attempts ha
311
WHERE ha.payment_id = $1 
312
    AND (
313
        ($2 = true AND ha.settle_preimage IS NULL AND ha.htlc_fail_reason IS NULL)
314
        OR
315
        ($2 = false OR $2 IS NULL)
316
    )
317
ORDER BY 
318
    CASE WHEN $3 = false OR $3 IS NULL THEN ha.attempt_time END ASC,
319
    CASE WHEN $3 = true THEN ha.attempt_time END DESC
320
`
321

322
type FetchHtlcAttemptsParams struct {
323
        PaymentID    int64
324
        InFlightOnly interface{}
325
        Reverse      interface{}
326
}
327

328
// This will not include the hops for the htlc attempts which are in a separate
329
// table.
NEW
330
func (q *Queries) FetchHtlcAttempts(ctx context.Context, arg FetchHtlcAttemptsParams) ([]PaymentHtlcAttempt, error) {
×
NEW
331
        rows, err := q.db.QueryContext(ctx, fetchHtlcAttempts, arg.PaymentID, arg.InFlightOnly, arg.Reverse)
×
NEW
332
        if err != nil {
×
NEW
333
                return nil, err
×
NEW
334
        }
×
NEW
335
        defer rows.Close()
×
NEW
336
        var items []PaymentHtlcAttempt
×
NEW
337
        for rows.Next() {
×
NEW
338
                var i PaymentHtlcAttempt
×
NEW
339
                if err := rows.Scan(
×
NEW
340
                        &i.ID,
×
NEW
341
                        &i.AttemptIndex,
×
NEW
342
                        &i.PaymentID,
×
NEW
343
                        &i.SessionKey,
×
NEW
344
                        &i.AttemptTime,
×
NEW
345
                        &i.PaymentHash,
×
NEW
346
                        &i.RouteTotalTimeLock,
×
NEW
347
                        &i.RouteTotalAmount,
×
NEW
348
                        &i.RouteSourceKey,
×
NEW
349
                        &i.FailureSourceIndex,
×
NEW
350
                        &i.HtlcFailReason,
×
NEW
351
                        &i.FailureMsg,
×
NEW
352
                        &i.FailTime,
×
NEW
353
                        &i.SettlePreimage,
×
NEW
354
                        &i.SettleTime,
×
NEW
355
                ); err != nil {
×
NEW
356
                        return nil, err
×
NEW
357
                }
×
NEW
358
                items = append(items, i)
×
359
        }
NEW
360
        if err := rows.Close(); err != nil {
×
NEW
361
                return nil, err
×
NEW
362
        }
×
NEW
363
        if err := rows.Err(); err != nil {
×
NEW
364
                return nil, err
×
NEW
365
        }
×
NEW
366
        return items, nil
×
367
}
368

369
const fetchPayment = `-- name: FetchPayment :one
370
SELECT id, payment_request, amount_msat, created_at, payment_hash, fail_reason FROM payments WHERE payment_hash = $1
371
`
372

NEW
373
func (q *Queries) FetchPayment(ctx context.Context, paymentHash []byte) (Payment, error) {
×
NEW
374
        row := q.db.QueryRowContext(ctx, fetchPayment, paymentHash)
×
NEW
375
        var i Payment
×
NEW
376
        err := row.Scan(
×
NEW
377
                &i.ID,
×
NEW
378
                &i.PaymentRequest,
×
NEW
379
                &i.AmountMsat,
×
NEW
380
                &i.CreatedAt,
×
NEW
381
                &i.PaymentHash,
×
NEW
382
                &i.FailReason,
×
NEW
383
        )
×
NEW
384
        return i, err
×
NEW
385
}
×
386

387
const fetchPayments = `-- name: FetchPayments :many
388
SELECT id, payment_request, amount_msat, created_at, payment_hash, fail_reason FROM payments WHERE payment_hash IN (/*SLICE:payment_hashes*/?)
389
`
390

NEW
391
func (q *Queries) FetchPayments(ctx context.Context, paymentHashes [][]byte) ([]Payment, error) {
×
NEW
392
        query := fetchPayments
×
NEW
393
        var queryParams []interface{}
×
NEW
394
        if len(paymentHashes) > 0 {
×
NEW
395
                for _, v := range paymentHashes {
×
NEW
396
                        queryParams = append(queryParams, v)
×
NEW
397
                }
×
NEW
398
                query = strings.Replace(query, "/*SLICE:payment_hashes*/?", makeQueryParams(len(queryParams), len(paymentHashes)), 1)
×
NEW
399
        } else {
×
NEW
400
                query = strings.Replace(query, "/*SLICE:payment_hashes*/?", "NULL", 1)
×
NEW
401
        }
×
NEW
402
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
403
        if err != nil {
×
NEW
404
                return nil, err
×
NEW
405
        }
×
NEW
406
        defer rows.Close()
×
NEW
407
        var items []Payment
×
NEW
408
        for rows.Next() {
×
NEW
409
                var i Payment
×
NEW
410
                if err := rows.Scan(
×
NEW
411
                        &i.ID,
×
NEW
412
                        &i.PaymentRequest,
×
NEW
413
                        &i.AmountMsat,
×
NEW
414
                        &i.CreatedAt,
×
NEW
415
                        &i.PaymentHash,
×
NEW
416
                        &i.FailReason,
×
NEW
417
                ); err != nil {
×
NEW
418
                        return nil, err
×
NEW
419
                }
×
NEW
420
                items = append(items, i)
×
421
        }
NEW
422
        if err := rows.Close(); err != nil {
×
NEW
423
                return nil, err
×
NEW
424
        }
×
NEW
425
        if err := rows.Err(); err != nil {
×
NEW
426
                return nil, err
×
NEW
427
        }
×
NEW
428
        return items, nil
×
429
}
430

431
const filterPayments = `-- name: FilterPayments :many
432
/* ─────────────────────────────────────────────
433
   fetch queries
434
   ─────────────────────────────────────────────
435
*/
436

437
SELECT id, payment_request, amount_msat, created_at, payment_hash, fail_reason FROM payments
438
WHERE (
439
    -- This will exclude payments which have the failed reason set. These 
440
    -- payments might not be final yet meaning that they still can be inflight
441
    -- but they will transition to failed when all corresponding HTLCs are
442
    -- resolved.     
443
    ($1 = true AND fail_reason IS NULL) OR
444
    $1 = false OR $1 IS NULL
445
)
446
 AND (
447
    id > $2 OR
448
    $2 IS NULL 
449

450
) AND (
451
    id < $3 OR
452
    $3 IS NULL
453
) AND (
454
    created_at >= $4 OR
455
    $4 IS NULL
456
) AND (
457
    created_at <= $5 OR
458
    $5 IS NULL
459
)
460
ORDER BY 
461
    CASE WHEN $6 = false OR $6 IS NULL THEN id END ASC,
462
    CASE WHEN $6 = true THEN id END DESC
463
LIMIT $7
464
`
465

466
type FilterPaymentsParams struct {
467
        ExcludeFailed  interface{}
468
        IndexOffsetGet sql.NullInt64
469
        IndexOffsetLet sql.NullInt64
470
        CreatedAfter   sql.NullTime
471
        CreatedBefore  sql.NullTime
472
        Reverse        interface{}
473
        NumLimit       int32
474
}
475

NEW
476
func (q *Queries) FilterPayments(ctx context.Context, arg FilterPaymentsParams) ([]Payment, error) {
×
NEW
477
        rows, err := q.db.QueryContext(ctx, filterPayments,
×
NEW
478
                arg.ExcludeFailed,
×
NEW
479
                arg.IndexOffsetGet,
×
NEW
480
                arg.IndexOffsetLet,
×
NEW
481
                arg.CreatedAfter,
×
NEW
482
                arg.CreatedBefore,
×
NEW
483
                arg.Reverse,
×
NEW
484
                arg.NumLimit,
×
NEW
485
        )
×
NEW
486
        if err != nil {
×
NEW
487
                return nil, err
×
NEW
488
        }
×
NEW
489
        defer rows.Close()
×
NEW
490
        var items []Payment
×
NEW
491
        for rows.Next() {
×
NEW
492
                var i Payment
×
NEW
493
                if err := rows.Scan(
×
NEW
494
                        &i.ID,
×
NEW
495
                        &i.PaymentRequest,
×
NEW
496
                        &i.AmountMsat,
×
NEW
497
                        &i.CreatedAt,
×
NEW
498
                        &i.PaymentHash,
×
NEW
499
                        &i.FailReason,
×
NEW
500
                ); err != nil {
×
NEW
501
                        return nil, err
×
NEW
502
                }
×
NEW
503
                items = append(items, i)
×
504
        }
NEW
505
        if err := rows.Close(); err != nil {
×
NEW
506
                return nil, err
×
NEW
507
        }
×
NEW
508
        if err := rows.Err(); err != nil {
×
NEW
509
                return nil, err
×
NEW
510
        }
×
NEW
511
        return items, nil
×
512
}
513

514
const insertFirstHopCustomRecord = `-- name: InsertFirstHopCustomRecord :exec
515
INSERT INTO payment_first_hop_custom_records (
516
    payment_id,
517
    key,
518
    value
519
) VALUES (
520
    $1, $2, $3
521
)
522
`
523

524
type InsertFirstHopCustomRecordParams struct {
525
        PaymentID int64
526
        Key       int64
527
        Value     []byte
528
}
529

NEW
530
func (q *Queries) InsertFirstHopCustomRecord(ctx context.Context, arg InsertFirstHopCustomRecordParams) error {
×
NEW
531
        _, err := q.db.ExecContext(ctx, insertFirstHopCustomRecord, arg.PaymentID, arg.Key, arg.Value)
×
NEW
532
        return err
×
NEW
533
}
×
534

535
const insertFirstHopCustomRecordsBatch = `-- name: InsertFirstHopCustomRecordsBatch :exec
536
INSERT INTO payment_first_hop_custom_records (payment_id, key, value)
537
SELECT 
538
    $1 as payment_id,
539
    unnest(/*SLICE:keys*/?) as key,
540
    unnest(/*SLICE:values*/?) as value
541
`
542

543
type InsertFirstHopCustomRecordsBatchParams struct {
544
        PaymentID int64
545
        Keys      []interface{}
546
        Values    []interface{}
547
}
548

NEW
549
func (q *Queries) InsertFirstHopCustomRecordsBatch(ctx context.Context, arg InsertFirstHopCustomRecordsBatchParams) error {
×
NEW
550
        query := insertFirstHopCustomRecordsBatch
×
NEW
551
        var queryParams []interface{}
×
NEW
552
        queryParams = append(queryParams, arg.PaymentID)
×
NEW
553
        if len(arg.Keys) > 0 {
×
NEW
554
                for _, v := range arg.Keys {
×
NEW
555
                        queryParams = append(queryParams, v)
×
NEW
556
                }
×
NEW
557
                query = strings.Replace(query, "/*SLICE:keys*/?", makeQueryParams(len(queryParams), len(arg.Keys)), 1)
×
NEW
558
        } else {
×
NEW
559
                query = strings.Replace(query, "/*SLICE:keys*/?", "NULL", 1)
×
NEW
560
        }
×
NEW
561
        if len(arg.Values) > 0 {
×
NEW
562
                for _, v := range arg.Values {
×
NEW
563
                        queryParams = append(queryParams, v)
×
NEW
564
                }
×
NEW
565
                query = strings.Replace(query, "/*SLICE:values*/?", makeQueryParams(len(queryParams), len(arg.Values)), 1)
×
NEW
566
        } else {
×
NEW
567
                query = strings.Replace(query, "/*SLICE:values*/?", "NULL", 1)
×
NEW
568
        }
×
NEW
569
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
NEW
570
        return err
×
571
}
572

573
const insertHop = `-- name: InsertHop :one
574
INSERT INTO payment_route_hops (
575
    htlc_attempt_index,
576
    hop_index,
577
    pub_key,
578
    scid,
579
    outgoing_time_lock,
580
    amt_to_forward,
581
    meta_data,
582
    legacy_payload,
583
    mpp_payment_addr,
584
    mpp_total_msat,
585
    amp_root_share,
586
    amp_set_id,
587
    amp_child_index,
588
    blinding_point,
589
    encrypted_data,
590
    blinded_path_total_amt
591
) VALUES (
592
        $1,
593
        $2,
594
        $3,
595
        $4,
596
        $5,
597
        $6,
598
        $7,
599
        $8,
600
        $9,
601
        $10,
602
        $11,
603
        $12,
604
        $13,
605
        $14,
606
        $15,
607
        $16
608
) RETURNING id
609
`
610

611
type InsertHopParams struct {
612
        HtlcAttemptIndex    int64
613
        HopIndex            int32
614
        PubKey              []byte
615
        Scid                string
616
        OutgoingTimeLock    int32
617
        AmtToForward        int64
618
        MetaData            []byte
619
        LegacyPayload       bool
620
        MppPaymentAddr      []byte
621
        MppTotalMsat        sql.NullInt64
622
        AmpRootShare        []byte
623
        AmpSetID            []byte
624
        AmpChildIndex       sql.NullInt32
625
        BlindingPoint       []byte
626
        EncryptedData       []byte
627
        BlindedPathTotalAmt sql.NullInt64
628
}
629

NEW
630
func (q *Queries) InsertHop(ctx context.Context, arg InsertHopParams) (int64, error) {
×
NEW
631
        row := q.db.QueryRowContext(ctx, insertHop,
×
NEW
632
                arg.HtlcAttemptIndex,
×
NEW
633
                arg.HopIndex,
×
NEW
634
                arg.PubKey,
×
NEW
635
                arg.Scid,
×
NEW
636
                arg.OutgoingTimeLock,
×
NEW
637
                arg.AmtToForward,
×
NEW
638
                arg.MetaData,
×
NEW
639
                arg.LegacyPayload,
×
NEW
640
                arg.MppPaymentAddr,
×
NEW
641
                arg.MppTotalMsat,
×
NEW
642
                arg.AmpRootShare,
×
NEW
643
                arg.AmpSetID,
×
NEW
644
                arg.AmpChildIndex,
×
NEW
645
                arg.BlindingPoint,
×
NEW
646
                arg.EncryptedData,
×
NEW
647
                arg.BlindedPathTotalAmt,
×
NEW
648
        )
×
NEW
649
        var id int64
×
NEW
650
        err := row.Scan(&id)
×
NEW
651
        return id, err
×
NEW
652
}
×
653

654
const insertHopCustomRecordsBatch = `-- name: InsertHopCustomRecordsBatch :exec
655
INSERT INTO payment_route_hop_custom_records (
656
    hop_id,
657
    key,
658
    value
659
) SELECT
660
    $1 as hop_id,
661
    unnest(/*SLICE:keys*/?) as key,
662
    unnest(/*SLICE:values*/?) as value
663
`
664

665
type InsertHopCustomRecordsBatchParams struct {
666
        HopID  int64
667
        Keys   []interface{}
668
        Values []interface{}
669
}
670

NEW
671
func (q *Queries) InsertHopCustomRecordsBatch(ctx context.Context, arg InsertHopCustomRecordsBatchParams) error {
×
NEW
672
        query := insertHopCustomRecordsBatch
×
NEW
673
        var queryParams []interface{}
×
NEW
674
        queryParams = append(queryParams, arg.HopID)
×
NEW
675
        if len(arg.Keys) > 0 {
×
NEW
676
                for _, v := range arg.Keys {
×
NEW
677
                        queryParams = append(queryParams, v)
×
NEW
678
                }
×
NEW
679
                query = strings.Replace(query, "/*SLICE:keys*/?", makeQueryParams(len(queryParams), len(arg.Keys)), 1)
×
NEW
680
        } else {
×
NEW
681
                query = strings.Replace(query, "/*SLICE:keys*/?", "NULL", 1)
×
NEW
682
        }
×
NEW
683
        if len(arg.Values) > 0 {
×
NEW
684
                for _, v := range arg.Values {
×
NEW
685
                        queryParams = append(queryParams, v)
×
NEW
686
                }
×
NEW
687
                query = strings.Replace(query, "/*SLICE:values*/?", makeQueryParams(len(queryParams), len(arg.Values)), 1)
×
NEW
688
        } else {
×
NEW
689
                query = strings.Replace(query, "/*SLICE:values*/?", "NULL", 1)
×
NEW
690
        }
×
NEW
691
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
NEW
692
        return err
×
693
}
694

695
const insertHtlAttemptCustomRecordsBatch = `-- name: InsertHtlAttemptCustomRecordsBatch :exec
696
INSERT INTO payment_htlc_attempt_custom_records (
697
    htlc_attempt_index,
698
    key,
699
    value
700
) SELECT
701
    $1 as htlc_attempt_index,
702
    unnest(/*SLICE:keys*/?) as key,
703
    unnest(/*SLICE:values*/?) as value
704
`
705

706
type InsertHtlAttemptCustomRecordsBatchParams struct {
707
        HtlcAttemptIndex int64
708
        Keys             []interface{}
709
        Values           []interface{}
710
}
711

NEW
712
func (q *Queries) InsertHtlAttemptCustomRecordsBatch(ctx context.Context, arg InsertHtlAttemptCustomRecordsBatchParams) error {
×
NEW
713
        query := insertHtlAttemptCustomRecordsBatch
×
NEW
714
        var queryParams []interface{}
×
NEW
715
        queryParams = append(queryParams, arg.HtlcAttemptIndex)
×
NEW
716
        if len(arg.Keys) > 0 {
×
NEW
717
                for _, v := range arg.Keys {
×
NEW
718
                        queryParams = append(queryParams, v)
×
NEW
719
                }
×
NEW
720
                query = strings.Replace(query, "/*SLICE:keys*/?", makeQueryParams(len(queryParams), len(arg.Keys)), 1)
×
NEW
721
        } else {
×
NEW
722
                query = strings.Replace(query, "/*SLICE:keys*/?", "NULL", 1)
×
NEW
723
        }
×
NEW
724
        if len(arg.Values) > 0 {
×
NEW
725
                for _, v := range arg.Values {
×
NEW
726
                        queryParams = append(queryParams, v)
×
NEW
727
                }
×
NEW
728
                query = strings.Replace(query, "/*SLICE:values*/?", makeQueryParams(len(queryParams), len(arg.Values)), 1)
×
NEW
729
        } else {
×
NEW
730
                query = strings.Replace(query, "/*SLICE:values*/?", "NULL", 1)
×
NEW
731
        }
×
NEW
732
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
NEW
733
        return err
×
734
}
735

736
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
737
INSERT INTO payment_htlc_attempts (
738
    attempt_index,
739
    payment_id,
740
    session_key,
741
    attempt_time,
742
    payment_hash,
743
    route_total_time_lock,
744
    route_total_amount,
745
    route_source_key
746
) VALUES (
747
    $1,
748
    $2,
749
    $3,
750
    $4,
751
    $5,
752
    $6,
753
    $7,
754
    $8
755
) RETURNING id
756
`
757

758
type InsertHtlcAttemptParams struct {
759
        AttemptIndex       int64
760
        PaymentID          int64
761
        SessionKey         []byte
762
        AttemptTime        time.Time
763
        PaymentHash        []byte
764
        RouteTotalTimeLock int32
765
        RouteTotalAmount   int64
766
        RouteSourceKey     []byte
767
}
768

NEW
769
func (q *Queries) InsertHtlcAttempt(ctx context.Context, arg InsertHtlcAttemptParams) (int64, error) {
×
NEW
770
        row := q.db.QueryRowContext(ctx, insertHtlcAttempt,
×
NEW
771
                arg.AttemptIndex,
×
NEW
772
                arg.PaymentID,
×
NEW
773
                arg.SessionKey,
×
NEW
774
                arg.AttemptTime,
×
NEW
775
                arg.PaymentHash,
×
NEW
776
                arg.RouteTotalTimeLock,
×
NEW
777
                arg.RouteTotalAmount,
×
NEW
778
                arg.RouteSourceKey,
×
NEW
779
        )
×
NEW
780
        var id int64
×
NEW
781
        err := row.Scan(&id)
×
NEW
782
        return id, err
×
NEW
783
}
×
784

785
const insertPayment = `-- name: InsertPayment :one
786
/* ─────────────────────────────────────────────
787
   Insert queries
788
   ─────────────────────────────────────────────
789
*/
790

791
INSERT INTO payments (
792
    payment_request, 
793
    amount_msat, 
794
    created_at,
795
    payment_hash
796
) VALUES (
797
    $1, 
798
    $2, 
799
    $3,
800
    $4
801
) RETURNING id
802
`
803

804
type InsertPaymentParams struct {
805
        PaymentRequest []byte
806
        AmountMsat     int64
807
        CreatedAt      time.Time
808
        PaymentHash    []byte
809
}
810

NEW
811
func (q *Queries) InsertPayment(ctx context.Context, arg InsertPaymentParams) (int64, error) {
×
NEW
812
        row := q.db.QueryRowContext(ctx, insertPayment,
×
NEW
813
                arg.PaymentRequest,
×
NEW
814
                arg.AmountMsat,
×
NEW
815
                arg.CreatedAt,
×
NEW
816
                arg.PaymentHash,
×
NEW
817
        )
×
NEW
818
        var id int64
×
NEW
819
        err := row.Scan(&id)
×
NEW
820
        return id, err
×
NEW
821
}
×
822

823
const updateHtlcAttemptFailInfo = `-- name: UpdateHtlcAttemptFailInfo :one
824
UPDATE payment_htlc_attempts 
825
SET htlc_fail_reason = $1, fail_time = $2, failure_source_index = $3, failure_msg = $4
826
WHERE attempt_index = $5
827
RETURNING id
828
`
829

830
type UpdateHtlcAttemptFailInfoParams struct {
831
        HtlcFailReason     sql.NullInt32
832
        FailTime           sql.NullTime
833
        FailureSourceIndex sql.NullInt32
834
        FailureMsg         []byte
835
        AttemptIndex       int64
836
}
837

NEW
838
func (q *Queries) UpdateHtlcAttemptFailInfo(ctx context.Context, arg UpdateHtlcAttemptFailInfoParams) (int64, error) {
×
NEW
839
        row := q.db.QueryRowContext(ctx, updateHtlcAttemptFailInfo,
×
NEW
840
                arg.HtlcFailReason,
×
NEW
841
                arg.FailTime,
×
NEW
842
                arg.FailureSourceIndex,
×
NEW
843
                arg.FailureMsg,
×
NEW
844
                arg.AttemptIndex,
×
NEW
845
        )
×
NEW
846
        var id int64
×
NEW
847
        err := row.Scan(&id)
×
NEW
848
        return id, err
×
NEW
849
}
×
850

851
const updateHtlcAttemptSettleInfo = `-- name: UpdateHtlcAttemptSettleInfo :one
852
/* ─────────────────────────────────────────────
853
   Update queries
854
   ─────────────────────────────────────────────
855
*/
856

857
UPDATE payment_htlc_attempts 
858
SET settle_preimage = $1, settle_time = $2 
859
WHERE attempt_index = $3
860
RETURNING id
861
`
862

863
type UpdateHtlcAttemptSettleInfoParams struct {
864
        SettlePreimage []byte
865
        SettleTime     sql.NullTime
866
        AttemptIndex   int64
867
}
868

NEW
869
func (q *Queries) UpdateHtlcAttemptSettleInfo(ctx context.Context, arg UpdateHtlcAttemptSettleInfoParams) (int64, error) {
×
NEW
870
        row := q.db.QueryRowContext(ctx, updateHtlcAttemptSettleInfo, arg.SettlePreimage, arg.SettleTime, arg.AttemptIndex)
×
NEW
871
        var id int64
×
NEW
872
        err := row.Scan(&id)
×
NEW
873
        return id, err
×
NEW
874
}
×
875

876
const updatePaymentFailReason = `-- name: UpdatePaymentFailReason :one
877
UPDATE payments 
878
SET fail_reason = $1
879
WHERE payment_hash = $2
880
RETURNING id
881
`
882

883
type UpdatePaymentFailReasonParams struct {
884
        FailReason  sql.NullInt32
885
        PaymentHash []byte
886
}
887

NEW
888
func (q *Queries) UpdatePaymentFailReason(ctx context.Context, arg UpdatePaymentFailReasonParams) (int64, error) {
×
NEW
889
        row := q.db.QueryRowContext(ctx, updatePaymentFailReason, arg.FailReason, arg.PaymentHash)
×
NEW
890
        var id int64
×
NEW
891
        err := row.Scan(&id)
×
NEW
892
        return id, err
×
NEW
893
}
×
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

© 2025 Coveralls, Inc