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

lightningnetwork / lnd / 17236841262

26 Aug 2025 11:33AM UTC coverage: 66.228% (+8.9%) from 57.321%
17236841262

Pull #9147

github

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

129 of 1847 new or added lines in 13 files covered. (6.98%)

20 existing lines in 7 files now uncovered.

136069 of 205456 relevant lines covered (66.23%)

21357.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

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, first_hop_amount_msat, 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.FirstHopAmountMsat,
×
NEW
347
                        &i.RouteTotalTimeLock,
×
NEW
348
                        &i.RouteTotalAmount,
×
NEW
349
                        &i.RouteSourceKey,
×
NEW
350
                        &i.FailureSourceIndex,
×
NEW
351
                        &i.HtlcFailReason,
×
NEW
352
                        &i.FailureMsg,
×
NEW
353
                        &i.FailTime,
×
NEW
354
                        &i.SettlePreimage,
×
NEW
355
                        &i.SettleTime,
×
NEW
356
                ); err != nil {
×
NEW
357
                        return nil, err
×
NEW
358
                }
×
NEW
359
                items = append(items, i)
×
360
        }
NEW
361
        if err := rows.Close(); err != nil {
×
NEW
362
                return nil, err
×
NEW
363
        }
×
NEW
364
        if err := rows.Err(); err != nil {
×
NEW
365
                return nil, err
×
NEW
366
        }
×
NEW
367
        return items, nil
×
368
}
369

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

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

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

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

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

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

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

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

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

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

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

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

536
const insertHop = `-- name: InsertHop :one
537
INSERT INTO payment_route_hops (
538
    htlc_attempt_index,
539
    hop_index,
540
    pub_key,
541
    scid,
542
    outgoing_time_lock,
543
    amt_to_forward,
544
    meta_data,
545
    legacy_payload,
546
    mpp_payment_addr,
547
    mpp_total_msat,
548
    amp_root_share,
549
    amp_set_id,
550
    amp_child_index,
551
    blinding_point,
552
    encrypted_data,
553
    blinded_path_total_amt
554
) VALUES (
555
        $1,
556
        $2,
557
        $3,
558
        $4,
559
        $5,
560
        $6,
561
        $7,
562
        $8,
563
        $9,
564
        $10,
565
        $11,
566
        $12,
567
        $13,
568
        $14,
569
        $15,
570
        $16
571
) RETURNING id
572
`
573

574
type InsertHopParams struct {
575
        HtlcAttemptIndex    int64
576
        HopIndex            int32
577
        PubKey              []byte
578
        Scid                string
579
        OutgoingTimeLock    int32
580
        AmtToForward        int64
581
        MetaData            []byte
582
        LegacyPayload       bool
583
        MppPaymentAddr      []byte
584
        MppTotalMsat        sql.NullInt64
585
        AmpRootShare        []byte
586
        AmpSetID            []byte
587
        AmpChildIndex       sql.NullInt32
588
        BlindingPoint       []byte
589
        EncryptedData       []byte
590
        BlindedPathTotalAmt sql.NullInt64
591
}
592

NEW
593
func (q *Queries) InsertHop(ctx context.Context, arg InsertHopParams) (int64, error) {
×
NEW
594
        row := q.db.QueryRowContext(ctx, insertHop,
×
NEW
595
                arg.HtlcAttemptIndex,
×
NEW
596
                arg.HopIndex,
×
NEW
597
                arg.PubKey,
×
NEW
598
                arg.Scid,
×
NEW
599
                arg.OutgoingTimeLock,
×
NEW
600
                arg.AmtToForward,
×
NEW
601
                arg.MetaData,
×
NEW
602
                arg.LegacyPayload,
×
NEW
603
                arg.MppPaymentAddr,
×
NEW
604
                arg.MppTotalMsat,
×
NEW
605
                arg.AmpRootShare,
×
NEW
606
                arg.AmpSetID,
×
NEW
607
                arg.AmpChildIndex,
×
NEW
608
                arg.BlindingPoint,
×
NEW
609
                arg.EncryptedData,
×
NEW
610
                arg.BlindedPathTotalAmt,
×
NEW
611
        )
×
NEW
612
        var id int64
×
NEW
613
        err := row.Scan(&id)
×
NEW
614
        return id, err
×
NEW
615
}
×
616

617
const insertHopCustomRecord = `-- name: InsertHopCustomRecord :exec
618
INSERT INTO payment_route_hop_custom_records (
619
    hop_id,
620
    key,
621
    value
622
) VALUES (
623
    $1,
624
    $2,
625
    $3
626
)
627
`
628

629
type InsertHopCustomRecordParams struct {
630
        HopID int64
631
        Key   int64
632
        Value []byte
633
}
634

NEW
635
func (q *Queries) InsertHopCustomRecord(ctx context.Context, arg InsertHopCustomRecordParams) error {
×
NEW
636
        _, err := q.db.ExecContext(ctx, insertHopCustomRecord, arg.HopID, arg.Key, arg.Value)
×
NEW
637
        return err
×
NEW
638
}
×
639

640
const insertHtlAttemptFirstHopCustomRecord = `-- name: InsertHtlAttemptFirstHopCustomRecord :exec
641
INSERT INTO payment_htlc_attempt_custom_records (
642
    htlc_attempt_index,
643
    key,
644
    value
645
) VALUES (
646
    $1,
647
    $2,
648
    $3
649
)
650
`
651

652
type InsertHtlAttemptFirstHopCustomRecordParams struct {
653
        HtlcAttemptIndex int64
654
        Key              int64
655
        Value            []byte
656
}
657

NEW
658
func (q *Queries) InsertHtlAttemptFirstHopCustomRecord(ctx context.Context, arg InsertHtlAttemptFirstHopCustomRecordParams) error {
×
NEW
659
        _, err := q.db.ExecContext(ctx, insertHtlAttemptFirstHopCustomRecord, arg.HtlcAttemptIndex, arg.Key, arg.Value)
×
NEW
660
        return err
×
NEW
661
}
×
662

663
const insertHtlcAttempt = `-- name: InsertHtlcAttempt :one
664
INSERT INTO payment_htlc_attempts (
665
    attempt_index,
666
    payment_id,
667
    session_key,
668
    attempt_time,
669
    payment_hash,
670
    route_total_time_lock,
671
    route_total_amount,
672
    route_source_key,
673
    first_hop_amount_msat
674
) VALUES (
675
    $1,
676
    $2,
677
    $3,
678
    $4,
679
    $5,
680
    $6,
681
    $7,
682
    $8,
683
    $9
684
) RETURNING id
685
`
686

687
type InsertHtlcAttemptParams struct {
688
        AttemptIndex       int64
689
        PaymentID          int64
690
        SessionKey         []byte
691
        AttemptTime        time.Time
692
        PaymentHash        []byte
693
        RouteTotalTimeLock int32
694
        RouteTotalAmount   int64
695
        RouteSourceKey     []byte
696
        FirstHopAmountMsat int64
697
}
698

NEW
699
func (q *Queries) InsertHtlcAttempt(ctx context.Context, arg InsertHtlcAttemptParams) (int64, error) {
×
NEW
700
        row := q.db.QueryRowContext(ctx, insertHtlcAttempt,
×
NEW
701
                arg.AttemptIndex,
×
NEW
702
                arg.PaymentID,
×
NEW
703
                arg.SessionKey,
×
NEW
704
                arg.AttemptTime,
×
NEW
705
                arg.PaymentHash,
×
NEW
706
                arg.RouteTotalTimeLock,
×
NEW
707
                arg.RouteTotalAmount,
×
NEW
708
                arg.RouteSourceKey,
×
NEW
709
                arg.FirstHopAmountMsat,
×
NEW
710
        )
×
NEW
711
        var id int64
×
NEW
712
        err := row.Scan(&id)
×
NEW
713
        return id, err
×
NEW
714
}
×
715

716
const insertPayment = `-- name: InsertPayment :one
717
/* ─────────────────────────────────────────────
718
   Insert queries
719
   ─────────────────────────────────────────────
720
*/
721

722
INSERT INTO payments (
723
    payment_request,
724
    amount_msat,
725
    created_at,
726
    payment_hash
727
) VALUES (
728
    $1,
729
    $2,
730
    $3,
731
    $4
732
) RETURNING id
733
`
734

735
type InsertPaymentParams struct {
736
        PaymentRequest []byte
737
        AmountMsat     int64
738
        CreatedAt      time.Time
739
        PaymentHash    []byte
740
}
741

NEW
742
func (q *Queries) InsertPayment(ctx context.Context, arg InsertPaymentParams) (int64, error) {
×
NEW
743
        row := q.db.QueryRowContext(ctx, insertPayment,
×
NEW
744
                arg.PaymentRequest,
×
NEW
745
                arg.AmountMsat,
×
NEW
746
                arg.CreatedAt,
×
NEW
747
                arg.PaymentHash,
×
NEW
748
        )
×
NEW
749
        var id int64
×
NEW
750
        err := row.Scan(&id)
×
NEW
751
        return id, err
×
NEW
752
}
×
753

754
const updateHtlcAttemptFailInfo = `-- name: UpdateHtlcAttemptFailInfo :one
755
UPDATE payment_htlc_attempts
756
SET htlc_fail_reason = $1, fail_time = $2, failure_source_index = $3, failure_msg = $4
757
WHERE attempt_index = $5
758
RETURNING id
759
`
760

761
type UpdateHtlcAttemptFailInfoParams struct {
762
        HtlcFailReason     sql.NullInt32
763
        FailTime           sql.NullTime
764
        FailureSourceIndex sql.NullInt32
765
        FailureMsg         []byte
766
        AttemptIndex       int64
767
}
768

NEW
769
func (q *Queries) UpdateHtlcAttemptFailInfo(ctx context.Context, arg UpdateHtlcAttemptFailInfoParams) (int64, error) {
×
NEW
770
        row := q.db.QueryRowContext(ctx, updateHtlcAttemptFailInfo,
×
NEW
771
                arg.HtlcFailReason,
×
NEW
772
                arg.FailTime,
×
NEW
773
                arg.FailureSourceIndex,
×
NEW
774
                arg.FailureMsg,
×
NEW
775
                arg.AttemptIndex,
×
NEW
776
        )
×
NEW
777
        var id int64
×
NEW
778
        err := row.Scan(&id)
×
NEW
779
        return id, err
×
NEW
780
}
×
781

782
const updateHtlcAttemptSettleInfo = `-- name: UpdateHtlcAttemptSettleInfo :one
783
/* ─────────────────────────────────────────────
784
   Update queries
785
   ─────────────────────────────────────────────
786
*/
787

788
UPDATE payment_htlc_attempts
789
SET settle_preimage = $1, settle_time = $2
790
WHERE attempt_index = $3
791
RETURNING id
792
`
793

794
type UpdateHtlcAttemptSettleInfoParams struct {
795
        SettlePreimage []byte
796
        SettleTime     sql.NullTime
797
        AttemptIndex   int64
798
}
799

NEW
800
func (q *Queries) UpdateHtlcAttemptSettleInfo(ctx context.Context, arg UpdateHtlcAttemptSettleInfoParams) (int64, error) {
×
NEW
801
        row := q.db.QueryRowContext(ctx, updateHtlcAttemptSettleInfo, arg.SettlePreimage, arg.SettleTime, arg.AttemptIndex)
×
NEW
802
        var id int64
×
NEW
803
        err := row.Scan(&id)
×
NEW
804
        return id, err
×
NEW
805
}
×
806

807
const updatePaymentFailReason = `-- name: UpdatePaymentFailReason :one
808
UPDATE payments
809
SET fail_reason = $1
810
WHERE payment_hash = $2
811
RETURNING id
812
`
813

814
type UpdatePaymentFailReasonParams struct {
815
        FailReason  sql.NullInt32
816
        PaymentHash []byte
817
}
818

NEW
819
func (q *Queries) UpdatePaymentFailReason(ctx context.Context, arg UpdatePaymentFailReasonParams) (int64, error) {
×
NEW
820
        row := q.db.QueryRowContext(ctx, updatePaymentFailReason, arg.FailReason, arg.PaymentHash)
×
NEW
821
        var id int64
×
NEW
822
        err := row.Scan(&id)
×
NEW
823
        return id, err
×
NEW
824
}
×
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