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

lightningnetwork / lnd / 15710136066

17 Jun 2025 02:30PM UTC coverage: 68.465% (-0.04%) from 68.507%
15710136066

push

github

web-flow
Merge pull request #9887 from ellemouton/graphSQL9-chan-policies-schema

graph/db+sqldb: channel policy SQL schemas, queries and upsert CRUD

0 of 213 new or added lines in 2 files covered. (0.0%)

38 existing lines in 10 files now uncovered.

134571 of 196555 relevant lines covered (68.46%)

22324.56 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

NEW
109
func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error {
×
NEW
110
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraTypes, channelPolicyID)
×
NEW
111
        return err
×
NEW
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

NEW
206
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
NEW
207
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
NEW
208
        var i GetChannelAndNodesBySCIDRow
×
NEW
209
        err := row.Scan(
×
NEW
210
                &i.ID,
×
NEW
211
                &i.Version,
×
NEW
212
                &i.Scid,
×
NEW
213
                &i.NodeID1,
×
NEW
214
                &i.NodeID2,
×
NEW
215
                &i.Outpoint,
×
NEW
216
                &i.Capacity,
×
NEW
217
                &i.BitcoinKey1,
×
NEW
218
                &i.BitcoinKey2,
×
NEW
219
                &i.Node1Signature,
×
NEW
220
                &i.Node2Signature,
×
NEW
221
                &i.Bitcoin1Signature,
×
NEW
222
                &i.Bitcoin2Signature,
×
NEW
223
                &i.Node1PubKey,
×
NEW
224
                &i.Node2PubKey,
×
NEW
225
        )
×
NEW
226
        return i, err
×
NEW
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 getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
261
SELECT node_id, type, value
262
FROM node_extra_types
263
WHERE node_id = $1
264
`
265

266
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
267
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
268
        if err != nil {
×
269
                return nil, err
×
270
        }
×
271
        defer rows.Close()
×
272
        var items []NodeExtraType
×
273
        for rows.Next() {
×
274
                var i NodeExtraType
×
275
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
276
                        return nil, err
×
277
                }
×
278
                items = append(items, i)
×
279
        }
280
        if err := rows.Close(); err != nil {
×
281
                return nil, err
×
282
        }
×
283
        if err := rows.Err(); err != nil {
×
284
                return nil, err
×
285
        }
×
286
        return items, nil
×
287
}
288

289
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
290
SELECT a.type, a.address
291
FROM nodes n
292
LEFT JOIN node_addresses a ON a.node_id = n.id
293
WHERE n.pub_key = $1 AND n.version = $2
294
ORDER BY a.type ASC, a.position ASC
295
`
296

297
type GetNodeAddressesByPubKeyParams struct {
298
        PubKey  []byte
299
        Version int16
300
}
301

302
type GetNodeAddressesByPubKeyRow struct {
303
        Type    sql.NullInt16
304
        Address sql.NullString
305
}
306

307
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
308
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
309
        if err != nil {
×
310
                return nil, err
×
311
        }
×
312
        defer rows.Close()
×
313
        var items []GetNodeAddressesByPubKeyRow
×
314
        for rows.Next() {
×
315
                var i GetNodeAddressesByPubKeyRow
×
316
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
317
                        return nil, err
×
318
                }
×
319
                items = append(items, i)
×
320
        }
321
        if err := rows.Close(); err != nil {
×
322
                return nil, err
×
323
        }
×
324
        if err := rows.Err(); err != nil {
×
325
                return nil, err
×
326
        }
×
327
        return items, nil
×
328
}
329

330
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
331
SELECT id, version, pub_key, alias, last_update, color, signature
332
FROM nodes
333
WHERE pub_key = $1
334
  AND version = $2
335
`
336

337
type GetNodeByPubKeyParams struct {
338
        PubKey  []byte
339
        Version int16
340
}
341

342
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
343
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
344
        var i Node
×
345
        err := row.Scan(
×
346
                &i.ID,
×
347
                &i.Version,
×
348
                &i.PubKey,
×
349
                &i.Alias,
×
350
                &i.LastUpdate,
×
351
                &i.Color,
×
352
                &i.Signature,
×
353
        )
×
354
        return i, err
×
355
}
×
356

357
const getNodeFeatures = `-- name: GetNodeFeatures :many
358
SELECT node_id, feature_bit
359
FROM node_features
360
WHERE node_id = $1
361
`
362

363
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
364
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
365
        if err != nil {
×
366
                return nil, err
×
367
        }
×
368
        defer rows.Close()
×
369
        var items []NodeFeature
×
370
        for rows.Next() {
×
371
                var i NodeFeature
×
372
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
373
                        return nil, err
×
374
                }
×
375
                items = append(items, i)
×
376
        }
377
        if err := rows.Close(); err != nil {
×
378
                return nil, err
×
379
        }
×
380
        if err := rows.Err(); err != nil {
×
381
                return nil, err
×
382
        }
×
383
        return items, nil
×
384
}
385

386
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
387
SELECT f.feature_bit
388
FROM nodes n
389
    JOIN node_features f ON f.node_id = n.id
390
WHERE n.pub_key = $1
391
  AND n.version = $2
392
`
393

394
type GetNodeFeaturesByPubKeyParams struct {
395
        PubKey  []byte
396
        Version int16
397
}
398

399
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
400
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
401
        if err != nil {
×
402
                return nil, err
×
403
        }
×
404
        defer rows.Close()
×
405
        var items []int32
×
406
        for rows.Next() {
×
407
                var feature_bit int32
×
408
                if err := rows.Scan(&feature_bit); err != nil {
×
409
                        return nil, err
×
410
                }
×
411
                items = append(items, feature_bit)
×
412
        }
413
        if err := rows.Close(); err != nil {
×
414
                return nil, err
×
415
        }
×
416
        if err := rows.Err(); err != nil {
×
417
                return nil, err
×
418
        }
×
419
        return items, nil
×
420
}
421

422
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
423
SELECT id, version, pub_key, alias, last_update, color, signature
424
FROM nodes
425
WHERE last_update >= $1
426
  AND last_update < $2
427
`
428

429
type GetNodesByLastUpdateRangeParams struct {
430
        StartTime sql.NullInt64
431
        EndTime   sql.NullInt64
432
}
433

434
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
435
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
436
        if err != nil {
×
437
                return nil, err
×
438
        }
×
439
        defer rows.Close()
×
440
        var items []Node
×
441
        for rows.Next() {
×
442
                var i Node
×
443
                if err := rows.Scan(
×
444
                        &i.ID,
×
445
                        &i.Version,
×
446
                        &i.PubKey,
×
447
                        &i.Alias,
×
448
                        &i.LastUpdate,
×
449
                        &i.Color,
×
450
                        &i.Signature,
×
451
                ); err != nil {
×
452
                        return nil, err
×
453
                }
×
454
                items = append(items, i)
×
455
        }
456
        if err := rows.Close(); err != nil {
×
457
                return nil, err
×
458
        }
×
459
        if err := rows.Err(); err != nil {
×
460
                return nil, err
×
461
        }
×
462
        return items, nil
×
463
}
464

465
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
466
SELECT sn.node_id, n.pub_key
467
FROM source_nodes sn
468
    JOIN nodes n ON sn.node_id = n.id
469
WHERE n.version = $1
470
`
471

472
type GetSourceNodesByVersionRow struct {
473
        NodeID int64
474
        PubKey []byte
475
}
476

477
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
478
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
479
        if err != nil {
×
480
                return nil, err
×
481
        }
×
482
        defer rows.Close()
×
483
        var items []GetSourceNodesByVersionRow
×
484
        for rows.Next() {
×
485
                var i GetSourceNodesByVersionRow
×
486
                if err := rows.Scan(&i.NodeID, &i.PubKey); 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 highestSCID = `-- name: HighestSCID :one
501
SELECT scid
502
FROM channels
503
WHERE version = $1
504
ORDER BY scid DESC
505
LIMIT 1
506
`
507

508
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
509
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
510
        var scid []byte
×
511
        err := row.Scan(&scid)
×
512
        return scid, err
×
513
}
×
514

515
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
516
/* ─────────────────────────────────────────────
517
   channel_policy_extra_types table queries
518
   ─────────────────────────────────────────────
519
*/
520

521
INSERT INTO channel_policy_extra_types (
522
    channel_policy_id, type, value
523
)
524
VALUES ($1, $2, $3)
525
`
526

527
type InsertChanPolicyExtraTypeParams struct {
528
        ChannelPolicyID int64
529
        Type            int64
530
        Value           []byte
531
}
532

NEW
533
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
NEW
534
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
NEW
535
        return err
×
NEW
536
}
×
537

538
const insertChannelFeature = `-- name: InsertChannelFeature :exec
539
/* ─────────────────────────────────────────────
540
   channel_features table queries
541
   ─────────────────────────────────────────────
542
*/
543

544
INSERT INTO channel_features (
545
    channel_id, feature_bit
546
) VALUES (
547
    $1, $2
548
)
549
`
550

551
type InsertChannelFeatureParams struct {
552
        ChannelID  int64
553
        FeatureBit int32
554
}
555

556
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
557
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
558
        return err
×
559
}
×
560

561
const insertNodeAddress = `-- name: InsertNodeAddress :exec
562
/* ─────────────────────────────────────────────
563
   node_addresses table queries
564
   ─────────────────────────────────────────────
565
*/
566

567
INSERT INTO node_addresses (
568
    node_id,
569
    type,
570
    address,
571
    position
572
) VALUES (
573
    $1, $2, $3, $4
574
 )
575
`
576

577
type InsertNodeAddressParams struct {
578
        NodeID   int64
579
        Type     int16
580
        Address  string
581
        Position int32
582
}
583

584
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
585
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
586
                arg.NodeID,
×
587
                arg.Type,
×
588
                arg.Address,
×
589
                arg.Position,
×
590
        )
×
591
        return err
×
592
}
×
593

594
const insertNodeFeature = `-- name: InsertNodeFeature :exec
595
/* ─────────────────────────────────────────────
596
   node_features table queries
597
   ─────────────────────────────────────────────
598
*/
599

600
INSERT INTO node_features (
601
    node_id, feature_bit
602
) VALUES (
603
    $1, $2
604
)
605
`
606

607
type InsertNodeFeatureParams struct {
608
        NodeID     int64
609
        FeatureBit int32
610
}
611

612
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
613
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
614
        return err
×
615
}
×
616

617
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
618
/* ─────────────────────────────────────────────
619
   channel_policies table queries
620
   ─────────────────────────────────────────────
621
*/
622

623
INSERT INTO channel_policies (
624
    version, channel_id, node_id, timelock, fee_ppm,
625
    base_fee_msat, min_htlc_msat, last_update, disabled,
626
    max_htlc_msat, inbound_base_fee_msat,
627
    inbound_fee_rate_milli_msat, signature
628
) VALUES  (
629
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
630
)
631
ON CONFLICT (channel_id, node_id, version)
632
    -- Update the following fields if a conflict occurs on channel_id,
633
    -- node_id, and version.
634
    DO UPDATE SET
635
        timelock = EXCLUDED.timelock,
636
        fee_ppm = EXCLUDED.fee_ppm,
637
        base_fee_msat = EXCLUDED.base_fee_msat,
638
        min_htlc_msat = EXCLUDED.min_htlc_msat,
639
        last_update = EXCLUDED.last_update,
640
        disabled = EXCLUDED.disabled,
641
        max_htlc_msat = EXCLUDED.max_htlc_msat,
642
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
643
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
644
        signature = EXCLUDED.signature
645
WHERE EXCLUDED.last_update > channel_policies.last_update
646
RETURNING id
647
`
648

649
type UpsertEdgePolicyParams struct {
650
        Version                 int16
651
        ChannelID               int64
652
        NodeID                  int64
653
        Timelock                int32
654
        FeePpm                  int64
655
        BaseFeeMsat             int64
656
        MinHtlcMsat             int64
657
        LastUpdate              sql.NullInt64
658
        Disabled                sql.NullBool
659
        MaxHtlcMsat             sql.NullInt64
660
        InboundBaseFeeMsat      sql.NullInt64
661
        InboundFeeRateMilliMsat sql.NullInt64
662
        Signature               []byte
663
}
664

NEW
665
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
NEW
666
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
NEW
667
                arg.Version,
×
NEW
668
                arg.ChannelID,
×
NEW
669
                arg.NodeID,
×
NEW
670
                arg.Timelock,
×
NEW
671
                arg.FeePpm,
×
NEW
672
                arg.BaseFeeMsat,
×
NEW
673
                arg.MinHtlcMsat,
×
NEW
674
                arg.LastUpdate,
×
NEW
675
                arg.Disabled,
×
NEW
676
                arg.MaxHtlcMsat,
×
NEW
677
                arg.InboundBaseFeeMsat,
×
NEW
678
                arg.InboundFeeRateMilliMsat,
×
NEW
679
                arg.Signature,
×
NEW
680
        )
×
NEW
681
        var id int64
×
NEW
682
        err := row.Scan(&id)
×
NEW
683
        return id, err
×
NEW
684
}
×
685

686
const upsertNode = `-- name: UpsertNode :one
687
/* ─────────────────────────────────────────────
688
   nodes table queries
689
   ─────────────────────────────────────────────
690
*/
691

692
INSERT INTO nodes (
693
    version, pub_key, alias, last_update, color, signature
694
) VALUES (
695
    $1, $2, $3, $4, $5, $6
696
)
697
ON CONFLICT (pub_key, version)
698
    -- Update the following fields if a conflict occurs on pub_key
699
    -- and version.
700
    DO UPDATE SET
701
        alias = EXCLUDED.alias,
702
        last_update = EXCLUDED.last_update,
703
        color = EXCLUDED.color,
704
        signature = EXCLUDED.signature
705
WHERE nodes.last_update IS NULL
706
    OR EXCLUDED.last_update > nodes.last_update
707
RETURNING id
708
`
709

710
type UpsertNodeParams struct {
711
        Version    int16
712
        PubKey     []byte
713
        Alias      sql.NullString
714
        LastUpdate sql.NullInt64
715
        Color      sql.NullString
716
        Signature  []byte
717
}
718

719
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
720
        row := q.db.QueryRowContext(ctx, upsertNode,
×
721
                arg.Version,
×
722
                arg.PubKey,
×
723
                arg.Alias,
×
724
                arg.LastUpdate,
×
725
                arg.Color,
×
726
                arg.Signature,
×
727
        )
×
728
        var id int64
×
729
        err := row.Scan(&id)
×
730
        return id, err
×
731
}
×
732

733
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
734
/* ─────────────────────────────────────────────
735
   node_extra_types table queries
736
   ─────────────────────────────────────────────
737
*/
738

739
INSERT INTO node_extra_types (
740
    node_id, type, value
741
)
742
VALUES ($1, $2, $3)
743
ON CONFLICT (type, node_id)
744
    -- Update the value if a conflict occurs on type
745
    -- and node_id.
746
    DO UPDATE SET value = EXCLUDED.value
747
`
748

749
type UpsertNodeExtraTypeParams struct {
750
        NodeID int64
751
        Type   int64
752
        Value  []byte
753
}
754

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