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

lightningnetwork / lnd / 15736305184

18 Jun 2025 02:55PM UTC coverage: 68.145% (-0.1%) from 68.248%
15736305184

Pull #9935

github

web-flow
Merge ece157b40 into 31c74f20f
Pull Request #9935: [11] graph/db: Implement various "ForEach" methods on the graph SQLStore

4 of 317 new or added lines in 3 files covered. (1.26%)

71 existing lines in 19 files now uncovered.

134474 of 197335 relevant lines covered (68.15%)

22161.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sqldb/sqlc/graph.sql.go
1
// Code generated by sqlc. DO NOT EDIT.
2
// versions:
3
//   sqlc v1.29.0
4
// source: graph.sql
5

6
package sqlc
7

8
import (
9
        "context"
10
        "database/sql"
11
)
12

13
const addSourceNode = `-- name: AddSourceNode :exec
14
/* ─────────────────────────────────────────────
15
   source_nodes table queries
16
   ─────────────────────────────────────────────
17
*/
18

19
INSERT INTO source_nodes (node_id)
20
VALUES ($1)
21
ON CONFLICT (node_id) DO NOTHING
22
`
23

24
func (q *Queries) AddSourceNode(ctx context.Context, nodeID int64) error {
×
25
        _, err := q.db.ExecContext(ctx, addSourceNode, nodeID)
×
26
        return err
×
27
}
×
28

29
const createChannel = `-- name: CreateChannel :one
30
/* ─────────────────────────────────────────────
31
   channels table queries
32
   ─────────────────────────────────────────────
33
*/
34

35
INSERT INTO channels (
36
    version, scid, node_id_1, node_id_2,
37
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
38
    node_1_signature, node_2_signature, bitcoin_1_signature,
39
    bitcoin_2_signature
40
) VALUES (
41
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
42
)
43
RETURNING id
44
`
45

46
type CreateChannelParams struct {
47
        Version           int16
48
        Scid              []byte
49
        NodeID1           int64
50
        NodeID2           int64
51
        Outpoint          string
52
        Capacity          sql.NullInt64
53
        BitcoinKey1       []byte
54
        BitcoinKey2       []byte
55
        Node1Signature    []byte
56
        Node2Signature    []byte
57
        Bitcoin1Signature []byte
58
        Bitcoin2Signature []byte
59
}
60

61
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
×
62
        row := q.db.QueryRowContext(ctx, createChannel,
×
63
                arg.Version,
×
64
                arg.Scid,
×
65
                arg.NodeID1,
×
66
                arg.NodeID2,
×
67
                arg.Outpoint,
×
68
                arg.Capacity,
×
69
                arg.BitcoinKey1,
×
70
                arg.BitcoinKey2,
×
71
                arg.Node1Signature,
×
72
                arg.Node2Signature,
×
73
                arg.Bitcoin1Signature,
×
74
                arg.Bitcoin2Signature,
×
75
        )
×
76
        var id int64
×
77
        err := row.Scan(&id)
×
78
        return id, err
×
79
}
×
80

81
const createChannelExtraType = `-- name: CreateChannelExtraType :exec
82
/* ─────────────────────────────────────────────
83
   channel_extra_types table queries
84
   ─────────────────────────────────────────────
85
*/
86

87
INSERT INTO channel_extra_types (
88
    channel_id, type, value
89
)
90
VALUES ($1, $2, $3)
91
`
92

93
type CreateChannelExtraTypeParams struct {
94
        ChannelID int64
95
        Type      int64
96
        Value     []byte
97
}
98

99
func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelExtraTypeParams) error {
×
100
        _, err := q.db.ExecContext(ctx, createChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
101
        return err
×
102
}
×
103

104
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
105
DELETE FROM channel_policy_extra_types
106
WHERE channel_policy_id = $1
107
`
108

109
func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error {
×
110
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraTypes, channelPolicyID)
×
111
        return err
×
112
}
×
113

114
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
115
DELETE FROM node_extra_types
116
WHERE node_id = $1
117
  AND type = $2
118
`
119

120
type DeleteExtraNodeTypeParams struct {
121
        NodeID int64
122
        Type   int64
123
}
124

125
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
126
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
127
        return err
×
128
}
×
129

130
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
131
DELETE FROM node_addresses
132
WHERE node_id = $1
133
`
134

135
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
136
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
137
        return err
×
138
}
×
139

140
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
141
DELETE FROM nodes
142
WHERE pub_key = $1
143
  AND version = $2
144
`
145

146
type DeleteNodeByPubKeyParams struct {
147
        PubKey  []byte
148
        Version int16
149
}
150

151
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
152
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
153
}
×
154

155
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
156
DELETE FROM node_features
157
WHERE node_id = $1
158
  AND feature_bit = $2
159
`
160

161
type DeleteNodeFeatureParams struct {
162
        NodeID     int64
163
        FeatureBit int32
164
}
165

166
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
167
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
168
        return err
×
169
}
×
170

171
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
172
SELECT
173
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
174
    n1.pub_key AS node1_pub_key,
175
    n2.pub_key AS node2_pub_key
176
FROM channels c
177
    JOIN nodes n1 ON c.node_id_1 = n1.id
178
    JOIN nodes n2 ON c.node_id_2 = n2.id
179
WHERE c.scid = $1
180
  AND c.version = $2
181
`
182

183
type GetChannelAndNodesBySCIDParams struct {
184
        Scid    []byte
185
        Version int16
186
}
187

188
type GetChannelAndNodesBySCIDRow struct {
189
        ID                int64
190
        Version           int16
191
        Scid              []byte
192
        NodeID1           int64
193
        NodeID2           int64
194
        Outpoint          string
195
        Capacity          sql.NullInt64
196
        BitcoinKey1       []byte
197
        BitcoinKey2       []byte
198
        Node1Signature    []byte
199
        Node2Signature    []byte
200
        Bitcoin1Signature []byte
201
        Bitcoin2Signature []byte
202
        Node1PubKey       []byte
203
        Node2PubKey       []byte
204
}
205

206
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
207
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
208
        var i GetChannelAndNodesBySCIDRow
×
209
        err := row.Scan(
×
210
                &i.ID,
×
211
                &i.Version,
×
212
                &i.Scid,
×
213
                &i.NodeID1,
×
214
                &i.NodeID2,
×
215
                &i.Outpoint,
×
216
                &i.Capacity,
×
217
                &i.BitcoinKey1,
×
218
                &i.BitcoinKey2,
×
219
                &i.Node1Signature,
×
220
                &i.Node2Signature,
×
221
                &i.Bitcoin1Signature,
×
222
                &i.Bitcoin2Signature,
×
223
                &i.Node1PubKey,
×
224
                &i.Node2PubKey,
×
225
        )
×
226
        return i, err
×
227
}
×
228

229
const getChannelBySCID = `-- name: GetChannelBySCID :one
230
SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM channels
231
WHERE scid = $1 AND version = $2
232
`
233

234
type GetChannelBySCIDParams struct {
235
        Scid    []byte
236
        Version int16
237
}
238

239
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
240
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
241
        var i Channel
×
242
        err := row.Scan(
×
243
                &i.ID,
×
244
                &i.Version,
×
245
                &i.Scid,
×
246
                &i.NodeID1,
×
247
                &i.NodeID2,
×
248
                &i.Outpoint,
×
249
                &i.Capacity,
×
250
                &i.BitcoinKey1,
×
251
                &i.BitcoinKey2,
×
252
                &i.Node1Signature,
×
253
                &i.Node2Signature,
×
254
                &i.Bitcoin1Signature,
×
255
                &i.Bitcoin2Signature,
×
256
        )
×
257
        return i, err
×
258
}
×
259

260
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
261
SELECT
262
    cf.channel_id,
263
    true AS is_feature,
264
    cf.feature_bit AS feature_bit,
265
    NULL AS extra_key,
266
    NULL AS value
267
FROM channel_features cf
268
WHERE cf.channel_id = $1
269

270
UNION ALL
271

272
SELECT
273
    cet.channel_id,
274
    false AS is_feature,
275
    0 AS feature_bit,
276
    cet.type AS extra_key,
277
    cet.value AS value
278
FROM channel_extra_types cet
279
WHERE cet.channel_id = $1
280
`
281

282
type GetChannelFeaturesAndExtrasRow struct {
283
        ChannelID  int64
284
        IsFeature  bool
285
        FeatureBit int32
286
        ExtraKey   interface{}
287
        Value      interface{}
288
}
289

290
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
291
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
292
        if err != nil {
×
293
                return nil, err
×
294
        }
×
295
        defer rows.Close()
×
296
        var items []GetChannelFeaturesAndExtrasRow
×
297
        for rows.Next() {
×
298
                var i GetChannelFeaturesAndExtrasRow
×
299
                if err := rows.Scan(
×
300
                        &i.ChannelID,
×
301
                        &i.IsFeature,
×
302
                        &i.FeatureBit,
×
303
                        &i.ExtraKey,
×
304
                        &i.Value,
×
305
                ); err != nil {
×
306
                        return nil, err
×
307
                }
×
308
                items = append(items, i)
×
309
        }
310
        if err := rows.Close(); err != nil {
×
311
                return nil, err
×
312
        }
×
313
        if err := rows.Err(); err != nil {
×
314
                return nil, err
×
315
        }
×
316
        return items, nil
×
317
}
318

319
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
320
SELECT
321
    cp.id AS policy_id,
322
    cp.channel_id,
323
    cp.node_id,
324
    cpet.type,
325
    cpet.value
326
FROM channel_policies cp
327
JOIN channel_policy_extra_types cpet
328
ON cp.id = cpet.channel_policy_id
329
WHERE cp.id = $1 OR cp.id = $2
330
`
331

332
type GetChannelPolicyExtraTypesParams struct {
333
        ID   int64
334
        ID_2 int64
335
}
336

337
type GetChannelPolicyExtraTypesRow struct {
338
        PolicyID  int64
339
        ChannelID int64
340
        NodeID    int64
341
        Type      int64
342
        Value     []byte
343
}
344

345
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
346
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
347
        if err != nil {
×
348
                return nil, err
×
349
        }
×
350
        defer rows.Close()
×
351
        var items []GetChannelPolicyExtraTypesRow
×
352
        for rows.Next() {
×
353
                var i GetChannelPolicyExtraTypesRow
×
354
                if err := rows.Scan(
×
355
                        &i.PolicyID,
×
356
                        &i.ChannelID,
×
357
                        &i.NodeID,
×
358
                        &i.Type,
×
359
                        &i.Value,
×
360
                ); err != nil {
×
361
                        return nil, err
×
362
                }
×
363
                items = append(items, i)
×
364
        }
365
        if err := rows.Close(); err != nil {
×
366
                return nil, err
×
367
        }
×
368
        if err := rows.Err(); err != nil {
×
369
                return nil, err
×
370
        }
×
371
        return items, nil
×
372
}
373

374
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
375
SELECT node_id, type, value
376
FROM node_extra_types
377
WHERE node_id = $1
378
`
379

380
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
381
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
382
        if err != nil {
×
383
                return nil, err
×
384
        }
×
385
        defer rows.Close()
×
386
        var items []NodeExtraType
×
387
        for rows.Next() {
×
388
                var i NodeExtraType
×
389
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
390
                        return nil, err
×
391
                }
×
392
                items = append(items, i)
×
393
        }
394
        if err := rows.Close(); err != nil {
×
395
                return nil, err
×
396
        }
×
397
        if err := rows.Err(); err != nil {
×
398
                return nil, err
×
399
        }
×
400
        return items, nil
×
401
}
402

403
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
404
SELECT a.type, a.address
405
FROM nodes n
406
LEFT JOIN node_addresses a ON a.node_id = n.id
407
WHERE n.pub_key = $1 AND n.version = $2
408
ORDER BY a.type ASC, a.position ASC
409
`
410

411
type GetNodeAddressesByPubKeyParams struct {
412
        PubKey  []byte
413
        Version int16
414
}
415

416
type GetNodeAddressesByPubKeyRow struct {
417
        Type    sql.NullInt16
418
        Address sql.NullString
419
}
420

421
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
422
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
423
        if err != nil {
×
424
                return nil, err
×
425
        }
×
426
        defer rows.Close()
×
427
        var items []GetNodeAddressesByPubKeyRow
×
428
        for rows.Next() {
×
429
                var i GetNodeAddressesByPubKeyRow
×
430
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
431
                        return nil, err
×
432
                }
×
433
                items = append(items, i)
×
434
        }
435
        if err := rows.Close(); err != nil {
×
436
                return nil, err
×
437
        }
×
438
        if err := rows.Err(); err != nil {
×
439
                return nil, err
×
440
        }
×
441
        return items, nil
×
442
}
443

444
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
445
SELECT id, version, pub_key, alias, last_update, color, signature
446
FROM nodes
447
WHERE pub_key = $1
448
  AND version = $2
449
`
450

451
type GetNodeByPubKeyParams struct {
452
        PubKey  []byte
453
        Version int16
454
}
455

456
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
457
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
458
        var i Node
×
459
        err := row.Scan(
×
460
                &i.ID,
×
461
                &i.Version,
×
462
                &i.PubKey,
×
463
                &i.Alias,
×
464
                &i.LastUpdate,
×
465
                &i.Color,
×
466
                &i.Signature,
×
467
        )
×
468
        return i, err
×
469
}
×
470

471
const getNodeFeatures = `-- name: GetNodeFeatures :many
472
SELECT node_id, feature_bit
473
FROM node_features
474
WHERE node_id = $1
475
`
476

477
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
478
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
479
        if err != nil {
×
480
                return nil, err
×
481
        }
×
482
        defer rows.Close()
×
483
        var items []NodeFeature
×
484
        for rows.Next() {
×
485
                var i NodeFeature
×
486
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
487
                        return nil, err
×
488
                }
×
489
                items = append(items, i)
×
490
        }
491
        if err := rows.Close(); err != nil {
×
492
                return nil, err
×
493
        }
×
494
        if err := rows.Err(); err != nil {
×
495
                return nil, err
×
496
        }
×
497
        return items, nil
×
498
}
499

500
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
501
SELECT f.feature_bit
502
FROM nodes n
503
    JOIN node_features f ON f.node_id = n.id
504
WHERE n.pub_key = $1
505
  AND n.version = $2
506
`
507

508
type GetNodeFeaturesByPubKeyParams struct {
509
        PubKey  []byte
510
        Version int16
511
}
512

513
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
514
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
515
        if err != nil {
×
516
                return nil, err
×
517
        }
×
518
        defer rows.Close()
×
519
        var items []int32
×
520
        for rows.Next() {
×
521
                var feature_bit int32
×
522
                if err := rows.Scan(&feature_bit); err != nil {
×
523
                        return nil, err
×
524
                }
×
525
                items = append(items, feature_bit)
×
526
        }
527
        if err := rows.Close(); err != nil {
×
528
                return nil, err
×
529
        }
×
530
        if err := rows.Err(); err != nil {
×
531
                return nil, err
×
532
        }
×
533
        return items, nil
×
534
}
535

536
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
537
SELECT id
538
FROM nodes
539
WHERE pub_key = $1
540
  AND version = $2
541
`
542

543
type GetNodeIDByPubKeyParams struct {
544
        PubKey  []byte
545
        Version int16
546
}
547

NEW
548
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
NEW
549
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
NEW
550
        var id int64
×
NEW
551
        err := row.Scan(&id)
×
NEW
552
        return id, err
×
NEW
553
}
×
554

555
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
556
SELECT id, version, pub_key, alias, last_update, color, signature
557
FROM nodes
558
WHERE last_update >= $1
559
  AND last_update < $2
560
`
561

562
type GetNodesByLastUpdateRangeParams struct {
563
        StartTime sql.NullInt64
564
        EndTime   sql.NullInt64
565
}
566

567
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
568
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
569
        if err != nil {
×
570
                return nil, err
×
571
        }
×
572
        defer rows.Close()
×
573
        var items []Node
×
574
        for rows.Next() {
×
575
                var i Node
×
576
                if err := rows.Scan(
×
577
                        &i.ID,
×
578
                        &i.Version,
×
579
                        &i.PubKey,
×
580
                        &i.Alias,
×
581
                        &i.LastUpdate,
×
582
                        &i.Color,
×
583
                        &i.Signature,
×
584
                ); err != nil {
×
585
                        return nil, err
×
586
                }
×
587
                items = append(items, i)
×
588
        }
589
        if err := rows.Close(); err != nil {
×
590
                return nil, err
×
591
        }
×
592
        if err := rows.Err(); err != nil {
×
593
                return nil, err
×
594
        }
×
595
        return items, nil
×
596
}
597

598
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
599
SELECT sn.node_id, n.pub_key
600
FROM source_nodes sn
601
    JOIN nodes n ON sn.node_id = n.id
602
WHERE n.version = $1
603
`
604

605
type GetSourceNodesByVersionRow struct {
606
        NodeID int64
607
        PubKey []byte
608
}
609

610
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
611
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
612
        if err != nil {
×
613
                return nil, err
×
614
        }
×
615
        defer rows.Close()
×
616
        var items []GetSourceNodesByVersionRow
×
617
        for rows.Next() {
×
618
                var i GetSourceNodesByVersionRow
×
619
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
620
                        return nil, err
×
621
                }
×
622
                items = append(items, i)
×
623
        }
624
        if err := rows.Close(); err != nil {
×
625
                return nil, err
×
626
        }
×
627
        if err := rows.Err(); err != nil {
×
628
                return nil, err
×
629
        }
×
630
        return items, nil
×
631
}
632

633
const highestSCID = `-- name: HighestSCID :one
634
SELECT scid
635
FROM channels
636
WHERE version = $1
637
ORDER BY scid DESC
638
LIMIT 1
639
`
640

641
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
642
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
643
        var scid []byte
×
644
        err := row.Scan(&scid)
×
645
        return scid, err
×
646
}
×
647

648
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
649
/* ─────────────────────────────────────────────
650
   channel_policy_extra_types table queries
651
   ─────────────────────────────────────────────
652
*/
653

654
INSERT INTO channel_policy_extra_types (
655
    channel_policy_id, type, value
656
)
657
VALUES ($1, $2, $3)
658
`
659

660
type InsertChanPolicyExtraTypeParams struct {
661
        ChannelPolicyID int64
662
        Type            int64
663
        Value           []byte
664
}
665

666
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
667
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
668
        return err
×
669
}
×
670

671
const insertChannelFeature = `-- name: InsertChannelFeature :exec
672
/* ─────────────────────────────────────────────
673
   channel_features table queries
674
   ─────────────────────────────────────────────
675
*/
676

677
INSERT INTO channel_features (
678
    channel_id, feature_bit
679
) VALUES (
680
    $1, $2
681
)
682
`
683

684
type InsertChannelFeatureParams struct {
685
        ChannelID  int64
686
        FeatureBit int32
687
}
688

689
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
690
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
691
        return err
×
692
}
×
693

694
const insertNodeAddress = `-- name: InsertNodeAddress :exec
695
/* ─────────────────────────────────────────────
696
   node_addresses table queries
697
   ─────────────────────────────────────────────
698
*/
699

700
INSERT INTO node_addresses (
701
    node_id,
702
    type,
703
    address,
704
    position
705
) VALUES (
706
    $1, $2, $3, $4
707
 )
708
`
709

710
type InsertNodeAddressParams struct {
711
        NodeID   int64
712
        Type     int16
713
        Address  string
714
        Position int32
715
}
716

717
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
718
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
719
                arg.NodeID,
×
720
                arg.Type,
×
721
                arg.Address,
×
722
                arg.Position,
×
723
        )
×
724
        return err
×
725
}
×
726

727
const insertNodeFeature = `-- name: InsertNodeFeature :exec
728
/* ─────────────────────────────────────────────
729
   node_features table queries
730
   ─────────────────────────────────────────────
731
*/
732

733
INSERT INTO node_features (
734
    node_id, feature_bit
735
) VALUES (
736
    $1, $2
737
)
738
`
739

740
type InsertNodeFeatureParams struct {
741
        NodeID     int64
742
        FeatureBit int32
743
}
744

745
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
746
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
747
        return err
×
748
}
×
749

750
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
751
SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
752
    n1.pub_key AS node1_pubkey,
753
    n2.pub_key AS node2_pubkey,
754

755
    -- Policy 1
756
    -- TODO(elle): use sqlc.embed to embed policy structs
757
    --  once this issue is resolved:
758
    --  https://github.com/sqlc-dev/sqlc/issues/2997
759
    cp1.id AS policy1_id,
760
    cp1.node_id AS policy1_node_id,
761
    cp1.version AS policy1_version,
762
    cp1.timelock AS policy1_timelock,
763
    cp1.fee_ppm AS policy1_fee_ppm,
764
    cp1.base_fee_msat AS policy1_base_fee_msat,
765
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
766
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
767
    cp1.last_update AS policy1_last_update,
768
    cp1.disabled AS policy1_disabled,
769
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
770
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
771
    cp1.signature AS policy1_signature,
772

773
       -- Policy 2
774
    cp2.id AS policy2_id,
775
    cp2.node_id AS policy2_node_id,
776
    cp2.version AS policy2_version,
777
    cp2.timelock AS policy2_timelock,
778
    cp2.fee_ppm AS policy2_fee_ppm,
779
    cp2.base_fee_msat AS policy2_base_fee_msat,
780
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
781
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
782
    cp2.last_update AS policy2_last_update,
783
    cp2.disabled AS policy2_disabled,
784
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
785
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
786
    cp2.signature AS policy2_signature
787

788
FROM channels c
789
    JOIN nodes n1 ON c.node_id_1 = n1.id
790
    JOIN nodes n2 ON c.node_id_2 = n2.id
791
    LEFT JOIN channel_policies cp1
792
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
793
    LEFT JOIN channel_policies cp2
794
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
795
WHERE c.version = $1
796
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
797
`
798

799
type ListChannelsByNodeIDParams struct {
800
        Version int16
801
        NodeID1 int64
802
}
803

804
type ListChannelsByNodeIDRow struct {
805
        Channel                        Channel
806
        Node1Pubkey                    []byte
807
        Node2Pubkey                    []byte
808
        Policy1ID                      sql.NullInt64
809
        Policy1NodeID                  sql.NullInt64
810
        Policy1Version                 sql.NullInt16
811
        Policy1Timelock                sql.NullInt32
812
        Policy1FeePpm                  sql.NullInt64
813
        Policy1BaseFeeMsat             sql.NullInt64
814
        Policy1MinHtlcMsat             sql.NullInt64
815
        Policy1MaxHtlcMsat             sql.NullInt64
816
        Policy1LastUpdate              sql.NullInt64
817
        Policy1Disabled                sql.NullBool
818
        Policy1InboundBaseFeeMsat      sql.NullInt64
819
        Policy1InboundFeeRateMilliMsat sql.NullInt64
820
        Policy1Signature               []byte
821
        Policy2ID                      sql.NullInt64
822
        Policy2NodeID                  sql.NullInt64
823
        Policy2Version                 sql.NullInt16
824
        Policy2Timelock                sql.NullInt32
825
        Policy2FeePpm                  sql.NullInt64
826
        Policy2BaseFeeMsat             sql.NullInt64
827
        Policy2MinHtlcMsat             sql.NullInt64
828
        Policy2MaxHtlcMsat             sql.NullInt64
829
        Policy2LastUpdate              sql.NullInt64
830
        Policy2Disabled                sql.NullBool
831
        Policy2InboundBaseFeeMsat      sql.NullInt64
832
        Policy2InboundFeeRateMilliMsat sql.NullInt64
833
        Policy2Signature               []byte
834
}
835

836
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
837
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
838
        if err != nil {
×
839
                return nil, err
×
840
        }
×
841
        defer rows.Close()
×
842
        var items []ListChannelsByNodeIDRow
×
843
        for rows.Next() {
×
844
                var i ListChannelsByNodeIDRow
×
845
                if err := rows.Scan(
×
846
                        &i.Channel.ID,
×
847
                        &i.Channel.Version,
×
848
                        &i.Channel.Scid,
×
849
                        &i.Channel.NodeID1,
×
850
                        &i.Channel.NodeID2,
×
851
                        &i.Channel.Outpoint,
×
852
                        &i.Channel.Capacity,
×
853
                        &i.Channel.BitcoinKey1,
×
854
                        &i.Channel.BitcoinKey2,
×
855
                        &i.Channel.Node1Signature,
×
856
                        &i.Channel.Node2Signature,
×
857
                        &i.Channel.Bitcoin1Signature,
×
858
                        &i.Channel.Bitcoin2Signature,
×
859
                        &i.Node1Pubkey,
×
860
                        &i.Node2Pubkey,
×
861
                        &i.Policy1ID,
×
862
                        &i.Policy1NodeID,
×
863
                        &i.Policy1Version,
×
864
                        &i.Policy1Timelock,
×
865
                        &i.Policy1FeePpm,
×
866
                        &i.Policy1BaseFeeMsat,
×
867
                        &i.Policy1MinHtlcMsat,
×
868
                        &i.Policy1MaxHtlcMsat,
×
869
                        &i.Policy1LastUpdate,
×
870
                        &i.Policy1Disabled,
×
871
                        &i.Policy1InboundBaseFeeMsat,
×
872
                        &i.Policy1InboundFeeRateMilliMsat,
×
873
                        &i.Policy1Signature,
×
874
                        &i.Policy2ID,
×
875
                        &i.Policy2NodeID,
×
876
                        &i.Policy2Version,
×
877
                        &i.Policy2Timelock,
×
878
                        &i.Policy2FeePpm,
×
879
                        &i.Policy2BaseFeeMsat,
×
880
                        &i.Policy2MinHtlcMsat,
×
881
                        &i.Policy2MaxHtlcMsat,
×
882
                        &i.Policy2LastUpdate,
×
883
                        &i.Policy2Disabled,
×
884
                        &i.Policy2InboundBaseFeeMsat,
×
885
                        &i.Policy2InboundFeeRateMilliMsat,
×
886
                        &i.Policy2Signature,
×
887
                ); err != nil {
×
888
                        return nil, err
×
889
                }
×
890
                items = append(items, i)
×
891
        }
892
        if err := rows.Close(); err != nil {
×
893
                return nil, err
×
894
        }
×
895
        if err := rows.Err(); err != nil {
×
896
                return nil, err
×
897
        }
×
898
        return items, nil
×
899
}
900

901
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
902
SELECT id, pub_key
903
FROM nodes
904
WHERE version = $1  AND id > $2
905
ORDER BY id
906
LIMIT $3
907
`
908

909
type ListNodeIDsAndPubKeysParams struct {
910
        Version int16
911
        ID      int64
912
        Limit   int32
913
}
914

915
type ListNodeIDsAndPubKeysRow struct {
916
        ID     int64
917
        PubKey []byte
918
}
919

NEW
920
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
NEW
921
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
NEW
922
        if err != nil {
×
NEW
923
                return nil, err
×
NEW
924
        }
×
NEW
925
        defer rows.Close()
×
NEW
926
        var items []ListNodeIDsAndPubKeysRow
×
NEW
927
        for rows.Next() {
×
NEW
928
                var i ListNodeIDsAndPubKeysRow
×
NEW
929
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
NEW
930
                        return nil, err
×
NEW
931
                }
×
NEW
932
                items = append(items, i)
×
933
        }
NEW
934
        if err := rows.Close(); err != nil {
×
NEW
935
                return nil, err
×
NEW
936
        }
×
NEW
937
        if err := rows.Err(); err != nil {
×
NEW
938
                return nil, err
×
NEW
939
        }
×
NEW
940
        return items, nil
×
941
}
942

943
const listNodesPaginated = `-- name: ListNodesPaginated :many
944
SELECT id, version, pub_key, alias, last_update, color, signature
945
FROM nodes
946
WHERE version = $1 AND id > $2
947
ORDER BY id
948
LIMIT $3
949
`
950

951
type ListNodesPaginatedParams struct {
952
        Version int16
953
        ID      int64
954
        Limit   int32
955
}
956

NEW
957
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) {
×
NEW
958
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
NEW
959
        if err != nil {
×
NEW
960
                return nil, err
×
NEW
961
        }
×
NEW
962
        defer rows.Close()
×
NEW
963
        var items []Node
×
NEW
964
        for rows.Next() {
×
NEW
965
                var i Node
×
NEW
966
                if err := rows.Scan(
×
NEW
967
                        &i.ID,
×
NEW
968
                        &i.Version,
×
NEW
969
                        &i.PubKey,
×
NEW
970
                        &i.Alias,
×
NEW
971
                        &i.LastUpdate,
×
NEW
972
                        &i.Color,
×
NEW
973
                        &i.Signature,
×
NEW
974
                ); err != nil {
×
NEW
975
                        return nil, err
×
NEW
976
                }
×
NEW
977
                items = append(items, i)
×
978
        }
NEW
979
        if err := rows.Close(); err != nil {
×
NEW
980
                return nil, err
×
NEW
981
        }
×
NEW
982
        if err := rows.Err(); err != nil {
×
NEW
983
                return nil, err
×
NEW
984
        }
×
NEW
985
        return items, nil
×
986
}
987

988
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
989
/* ─────────────────────────────────────────────
990
   channel_policies table queries
991
   ─────────────────────────────────────────────
992
*/
993

994
INSERT INTO channel_policies (
995
    version, channel_id, node_id, timelock, fee_ppm,
996
    base_fee_msat, min_htlc_msat, last_update, disabled,
997
    max_htlc_msat, inbound_base_fee_msat,
998
    inbound_fee_rate_milli_msat, signature
999
) VALUES  (
1000
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
1001
)
1002
ON CONFLICT (channel_id, node_id, version)
1003
    -- Update the following fields if a conflict occurs on channel_id,
1004
    -- node_id, and version.
1005
    DO UPDATE SET
1006
        timelock = EXCLUDED.timelock,
1007
        fee_ppm = EXCLUDED.fee_ppm,
1008
        base_fee_msat = EXCLUDED.base_fee_msat,
1009
        min_htlc_msat = EXCLUDED.min_htlc_msat,
1010
        last_update = EXCLUDED.last_update,
1011
        disabled = EXCLUDED.disabled,
1012
        max_htlc_msat = EXCLUDED.max_htlc_msat,
1013
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
1014
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
1015
        signature = EXCLUDED.signature
1016
WHERE EXCLUDED.last_update > channel_policies.last_update
1017
RETURNING id
1018
`
1019

1020
type UpsertEdgePolicyParams struct {
1021
        Version                 int16
1022
        ChannelID               int64
1023
        NodeID                  int64
1024
        Timelock                int32
1025
        FeePpm                  int64
1026
        BaseFeeMsat             int64
1027
        MinHtlcMsat             int64
1028
        LastUpdate              sql.NullInt64
1029
        Disabled                sql.NullBool
1030
        MaxHtlcMsat             sql.NullInt64
1031
        InboundBaseFeeMsat      sql.NullInt64
1032
        InboundFeeRateMilliMsat sql.NullInt64
1033
        Signature               []byte
1034
}
1035

1036
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
1037
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
1038
                arg.Version,
×
1039
                arg.ChannelID,
×
1040
                arg.NodeID,
×
1041
                arg.Timelock,
×
1042
                arg.FeePpm,
×
1043
                arg.BaseFeeMsat,
×
1044
                arg.MinHtlcMsat,
×
1045
                arg.LastUpdate,
×
1046
                arg.Disabled,
×
1047
                arg.MaxHtlcMsat,
×
1048
                arg.InboundBaseFeeMsat,
×
1049
                arg.InboundFeeRateMilliMsat,
×
1050
                arg.Signature,
×
1051
        )
×
1052
        var id int64
×
1053
        err := row.Scan(&id)
×
1054
        return id, err
×
1055
}
×
1056

1057
const upsertNode = `-- name: UpsertNode :one
1058
/* ─────────────────────────────────────────────
1059
   nodes table queries
1060
   ─────────────────────────────────────────────
1061
*/
1062

1063
INSERT INTO nodes (
1064
    version, pub_key, alias, last_update, color, signature
1065
) VALUES (
1066
    $1, $2, $3, $4, $5, $6
1067
)
1068
ON CONFLICT (pub_key, version)
1069
    -- Update the following fields if a conflict occurs on pub_key
1070
    -- and version.
1071
    DO UPDATE SET
1072
        alias = EXCLUDED.alias,
1073
        last_update = EXCLUDED.last_update,
1074
        color = EXCLUDED.color,
1075
        signature = EXCLUDED.signature
1076
WHERE nodes.last_update IS NULL
1077
    OR EXCLUDED.last_update > nodes.last_update
1078
RETURNING id
1079
`
1080

1081
type UpsertNodeParams struct {
1082
        Version    int16
1083
        PubKey     []byte
1084
        Alias      sql.NullString
1085
        LastUpdate sql.NullInt64
1086
        Color      sql.NullString
1087
        Signature  []byte
1088
}
1089

1090
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
1091
        row := q.db.QueryRowContext(ctx, upsertNode,
×
1092
                arg.Version,
×
1093
                arg.PubKey,
×
1094
                arg.Alias,
×
1095
                arg.LastUpdate,
×
1096
                arg.Color,
×
1097
                arg.Signature,
×
1098
        )
×
1099
        var id int64
×
1100
        err := row.Scan(&id)
×
1101
        return id, err
×
1102
}
×
1103

1104
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
1105
/* ─────────────────────────────────────────────
1106
   node_extra_types table queries
1107
   ─────────────────────────────────────────────
1108
*/
1109

1110
INSERT INTO node_extra_types (
1111
    node_id, type, value
1112
)
1113
VALUES ($1, $2, $3)
1114
ON CONFLICT (type, node_id)
1115
    -- Update the value if a conflict occurs on type
1116
    -- and node_id.
1117
    DO UPDATE SET value = EXCLUDED.value
1118
`
1119

1120
type UpsertNodeExtraTypeParams struct {
1121
        NodeID int64
1122
        Type   int64
1123
        Value  []byte
1124
}
1125

1126
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
1127
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
1128
        return err
×
1129
}
×
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