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

lightningnetwork / lnd / 15856843288

24 Jun 2025 05:04PM UTC coverage: 67.954% (+9.8%) from 58.173%
15856843288

Pull #9937

github

web-flow
Merge 2a6e6683e into 29ff13d83
Pull Request #9937: [13] graph/db: SQL-ize the zombie index

12 of 323 new or added lines in 3 files covered. (3.72%)

26 existing lines in 7 files now uncovered.

134947 of 198585 relevant lines covered (67.95%)

22039.63 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 countZombieChannels = `-- name: CountZombieChannels :one
30
SELECT COUNT(*)
31
FROM zombie_channels
32
WHERE version = $1
33
`
34

NEW
35
func (q *Queries) CountZombieChannels(ctx context.Context, version int16) (int64, error) {
×
NEW
36
        row := q.db.QueryRowContext(ctx, countZombieChannels, version)
×
NEW
37
        var count int64
×
NEW
38
        err := row.Scan(&count)
×
NEW
39
        return count, err
×
NEW
40
}
×
41

42
const createChannel = `-- name: CreateChannel :one
43
/* ─────────────────────────────────────────────
44
   channels table queries
45
   ─────────────────────────────────────────────
46
*/
47

48
INSERT INTO channels (
49
    version, scid, node_id_1, node_id_2,
50
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
51
    node_1_signature, node_2_signature, bitcoin_1_signature,
52
    bitcoin_2_signature
53
) VALUES (
54
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
55
)
56
RETURNING id
57
`
58

59
type CreateChannelParams struct {
60
        Version           int16
61
        Scid              []byte
62
        NodeID1           int64
63
        NodeID2           int64
64
        Outpoint          string
65
        Capacity          sql.NullInt64
66
        BitcoinKey1       []byte
67
        BitcoinKey2       []byte
68
        Node1Signature    []byte
69
        Node2Signature    []byte
70
        Bitcoin1Signature []byte
71
        Bitcoin2Signature []byte
72
}
73

74
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
×
75
        row := q.db.QueryRowContext(ctx, createChannel,
×
76
                arg.Version,
×
77
                arg.Scid,
×
78
                arg.NodeID1,
×
79
                arg.NodeID2,
×
80
                arg.Outpoint,
×
81
                arg.Capacity,
×
82
                arg.BitcoinKey1,
×
83
                arg.BitcoinKey2,
×
84
                arg.Node1Signature,
×
85
                arg.Node2Signature,
×
86
                arg.Bitcoin1Signature,
×
87
                arg.Bitcoin2Signature,
×
88
        )
×
89
        var id int64
×
90
        err := row.Scan(&id)
×
91
        return id, err
×
92
}
×
93

94
const createChannelExtraType = `-- name: CreateChannelExtraType :exec
95
/* ─────────────────────────────────────────────
96
   channel_extra_types table queries
97
   ─────────────────────────────────────────────
98
*/
99

100
INSERT INTO channel_extra_types (
101
    channel_id, type, value
102
)
103
VALUES ($1, $2, $3)
104
`
105

106
type CreateChannelExtraTypeParams struct {
107
        ChannelID int64
108
        Type      int64
109
        Value     []byte
110
}
111

112
func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelExtraTypeParams) error {
×
113
        _, err := q.db.ExecContext(ctx, createChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
114
        return err
×
115
}
×
116

117
const deleteChannel = `-- name: DeleteChannel :exec
118
DELETE FROM channels WHERE id = $1
119
`
120

NEW
121
func (q *Queries) DeleteChannel(ctx context.Context, id int64) error {
×
NEW
122
        _, err := q.db.ExecContext(ctx, deleteChannel, id)
×
NEW
123
        return err
×
NEW
124
}
×
125

126
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
127
DELETE FROM channel_policy_extra_types
128
WHERE channel_policy_id = $1
129
`
130

131
func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error {
×
132
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraTypes, channelPolicyID)
×
133
        return err
×
134
}
×
135

136
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
137
DELETE FROM node_extra_types
138
WHERE node_id = $1
139
  AND type = $2
140
`
141

142
type DeleteExtraNodeTypeParams struct {
143
        NodeID int64
144
        Type   int64
145
}
146

147
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
148
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
149
        return err
×
150
}
×
151

152
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
153
DELETE FROM node_addresses
154
WHERE node_id = $1
155
`
156

157
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
158
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
159
        return err
×
160
}
×
161

162
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
163
DELETE FROM nodes
164
WHERE pub_key = $1
165
  AND version = $2
166
`
167

168
type DeleteNodeByPubKeyParams struct {
169
        PubKey  []byte
170
        Version int16
171
}
172

173
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
174
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
175
}
×
176

177
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
178
DELETE FROM node_features
179
WHERE node_id = $1
180
  AND feature_bit = $2
181
`
182

183
type DeleteNodeFeatureParams struct {
184
        NodeID     int64
185
        FeatureBit int32
186
}
187

188
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
189
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
190
        return err
×
191
}
×
192

193
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
194
DELETE FROM zombie_channels
195
WHERE scid = $1
196
AND version = $2
197
`
198

199
type DeleteZombieChannelParams struct {
200
        Scid    []byte
201
        Version int16
202
}
203

NEW
204
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
NEW
205
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
NEW
206
}
×
207

208
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
209
SELECT
210
    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,
211
    n1.pub_key AS node1_pub_key,
212
    n2.pub_key AS node2_pub_key
213
FROM channels c
214
    JOIN nodes n1 ON c.node_id_1 = n1.id
215
    JOIN nodes n2 ON c.node_id_2 = n2.id
216
WHERE c.scid = $1
217
  AND c.version = $2
218
`
219

220
type GetChannelAndNodesBySCIDParams struct {
221
        Scid    []byte
222
        Version int16
223
}
224

225
type GetChannelAndNodesBySCIDRow struct {
226
        ID                int64
227
        Version           int16
228
        Scid              []byte
229
        NodeID1           int64
230
        NodeID2           int64
231
        Outpoint          string
232
        Capacity          sql.NullInt64
233
        BitcoinKey1       []byte
234
        BitcoinKey2       []byte
235
        Node1Signature    []byte
236
        Node2Signature    []byte
237
        Bitcoin1Signature []byte
238
        Bitcoin2Signature []byte
239
        Node1PubKey       []byte
240
        Node2PubKey       []byte
241
}
242

243
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
244
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
245
        var i GetChannelAndNodesBySCIDRow
×
246
        err := row.Scan(
×
247
                &i.ID,
×
248
                &i.Version,
×
249
                &i.Scid,
×
250
                &i.NodeID1,
×
251
                &i.NodeID2,
×
252
                &i.Outpoint,
×
253
                &i.Capacity,
×
254
                &i.BitcoinKey1,
×
255
                &i.BitcoinKey2,
×
256
                &i.Node1Signature,
×
257
                &i.Node2Signature,
×
258
                &i.Bitcoin1Signature,
×
259
                &i.Bitcoin2Signature,
×
260
                &i.Node1PubKey,
×
261
                &i.Node2PubKey,
×
262
        )
×
263
        return i, err
×
264
}
×
265

266
const getChannelBySCID = `-- name: GetChannelBySCID :one
267
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
268
WHERE scid = $1 AND version = $2
269
`
270

271
type GetChannelBySCIDParams struct {
272
        Scid    []byte
273
        Version int16
274
}
275

276
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
277
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
278
        var i Channel
×
279
        err := row.Scan(
×
280
                &i.ID,
×
281
                &i.Version,
×
282
                &i.Scid,
×
283
                &i.NodeID1,
×
284
                &i.NodeID2,
×
285
                &i.Outpoint,
×
286
                &i.Capacity,
×
287
                &i.BitcoinKey1,
×
288
                &i.BitcoinKey2,
×
289
                &i.Node1Signature,
×
290
                &i.Node2Signature,
×
291
                &i.Bitcoin1Signature,
×
292
                &i.Bitcoin2Signature,
×
293
        )
×
294
        return i, err
×
295
}
×
296

297
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
298
SELECT
299
    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,
300
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
301
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
302

303
    -- Policy 1
304
    cp1.id AS policy1_id,
305
    cp1.node_id AS policy1_node_id,
306
    cp1.version AS policy1_version,
307
    cp1.timelock AS policy1_timelock,
308
    cp1.fee_ppm AS policy1_fee_ppm,
309
    cp1.base_fee_msat AS policy1_base_fee_msat,
310
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
311
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
312
    cp1.last_update AS policy1_last_update,
313
    cp1.disabled AS policy1_disabled,
314
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
315
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
316
    cp1.signature AS policy1_signature,
317

318
    -- Policy 2
319
    cp2.id AS policy2_id,
320
    cp2.node_id AS policy2_node_id,
321
    cp2.version AS policy2_version,
322
    cp2.timelock AS policy2_timelock,
323
    cp2.fee_ppm AS policy2_fee_ppm,
324
    cp2.base_fee_msat AS policy2_base_fee_msat,
325
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
326
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
327
    cp2.last_update AS policy2_last_update,
328
    cp2.disabled AS policy2_disabled,
329
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
330
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
331
    cp2.signature AS policy2_signature
332

333
FROM channels c
334
    JOIN nodes n1 ON c.node_id_1 = n1.id
335
    JOIN nodes n2 ON c.node_id_2 = n2.id
336
    LEFT JOIN channel_policies cp1
337
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
338
    LEFT JOIN channel_policies cp2
339
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
340
WHERE c.scid = $1
341
  AND c.version = $2
342
`
343

344
type GetChannelBySCIDWithPoliciesParams struct {
345
        Scid    []byte
346
        Version int16
347
}
348

349
type GetChannelBySCIDWithPoliciesRow struct {
350
        Channel                        Channel
351
        Node                           Node
352
        Node_2                         Node
353
        Policy1ID                      sql.NullInt64
354
        Policy1NodeID                  sql.NullInt64
355
        Policy1Version                 sql.NullInt16
356
        Policy1Timelock                sql.NullInt32
357
        Policy1FeePpm                  sql.NullInt64
358
        Policy1BaseFeeMsat             sql.NullInt64
359
        Policy1MinHtlcMsat             sql.NullInt64
360
        Policy1MaxHtlcMsat             sql.NullInt64
361
        Policy1LastUpdate              sql.NullInt64
362
        Policy1Disabled                sql.NullBool
363
        Policy1InboundBaseFeeMsat      sql.NullInt64
364
        Policy1InboundFeeRateMilliMsat sql.NullInt64
365
        Policy1Signature               []byte
366
        Policy2ID                      sql.NullInt64
367
        Policy2NodeID                  sql.NullInt64
368
        Policy2Version                 sql.NullInt16
369
        Policy2Timelock                sql.NullInt32
370
        Policy2FeePpm                  sql.NullInt64
371
        Policy2BaseFeeMsat             sql.NullInt64
372
        Policy2MinHtlcMsat             sql.NullInt64
373
        Policy2MaxHtlcMsat             sql.NullInt64
374
        Policy2LastUpdate              sql.NullInt64
375
        Policy2Disabled                sql.NullBool
376
        Policy2InboundBaseFeeMsat      sql.NullInt64
377
        Policy2InboundFeeRateMilliMsat sql.NullInt64
378
        Policy2Signature               []byte
379
}
380

NEW
381
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
NEW
382
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
NEW
383
        var i GetChannelBySCIDWithPoliciesRow
×
NEW
384
        err := row.Scan(
×
NEW
385
                &i.Channel.ID,
×
NEW
386
                &i.Channel.Version,
×
NEW
387
                &i.Channel.Scid,
×
NEW
388
                &i.Channel.NodeID1,
×
NEW
389
                &i.Channel.NodeID2,
×
NEW
390
                &i.Channel.Outpoint,
×
NEW
391
                &i.Channel.Capacity,
×
NEW
392
                &i.Channel.BitcoinKey1,
×
NEW
393
                &i.Channel.BitcoinKey2,
×
NEW
394
                &i.Channel.Node1Signature,
×
NEW
395
                &i.Channel.Node2Signature,
×
NEW
396
                &i.Channel.Bitcoin1Signature,
×
NEW
397
                &i.Channel.Bitcoin2Signature,
×
NEW
398
                &i.Node.ID,
×
NEW
399
                &i.Node.Version,
×
NEW
400
                &i.Node.PubKey,
×
NEW
401
                &i.Node.Alias,
×
NEW
402
                &i.Node.LastUpdate,
×
NEW
403
                &i.Node.Color,
×
NEW
404
                &i.Node.Signature,
×
NEW
405
                &i.Node_2.ID,
×
NEW
406
                &i.Node_2.Version,
×
NEW
407
                &i.Node_2.PubKey,
×
NEW
408
                &i.Node_2.Alias,
×
NEW
409
                &i.Node_2.LastUpdate,
×
NEW
410
                &i.Node_2.Color,
×
NEW
411
                &i.Node_2.Signature,
×
NEW
412
                &i.Policy1ID,
×
NEW
413
                &i.Policy1NodeID,
×
NEW
414
                &i.Policy1Version,
×
NEW
415
                &i.Policy1Timelock,
×
NEW
416
                &i.Policy1FeePpm,
×
NEW
417
                &i.Policy1BaseFeeMsat,
×
NEW
418
                &i.Policy1MinHtlcMsat,
×
NEW
419
                &i.Policy1MaxHtlcMsat,
×
NEW
420
                &i.Policy1LastUpdate,
×
NEW
421
                &i.Policy1Disabled,
×
NEW
422
                &i.Policy1InboundBaseFeeMsat,
×
NEW
423
                &i.Policy1InboundFeeRateMilliMsat,
×
NEW
424
                &i.Policy1Signature,
×
NEW
425
                &i.Policy2ID,
×
NEW
426
                &i.Policy2NodeID,
×
NEW
427
                &i.Policy2Version,
×
NEW
428
                &i.Policy2Timelock,
×
NEW
429
                &i.Policy2FeePpm,
×
NEW
430
                &i.Policy2BaseFeeMsat,
×
NEW
431
                &i.Policy2MinHtlcMsat,
×
NEW
432
                &i.Policy2MaxHtlcMsat,
×
NEW
433
                &i.Policy2LastUpdate,
×
NEW
434
                &i.Policy2Disabled,
×
NEW
435
                &i.Policy2InboundBaseFeeMsat,
×
NEW
436
                &i.Policy2InboundFeeRateMilliMsat,
×
NEW
437
                &i.Policy2Signature,
×
NEW
438
        )
×
NEW
439
        return i, err
×
NEW
440
}
×
441

442
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
443
SELECT
444
    cf.channel_id,
445
    true AS is_feature,
446
    cf.feature_bit AS feature_bit,
447
    NULL AS extra_key,
448
    NULL AS value
449
FROM channel_features cf
450
WHERE cf.channel_id = $1
451

452
UNION ALL
453

454
SELECT
455
    cet.channel_id,
456
    false AS is_feature,
457
    0 AS feature_bit,
458
    cet.type AS extra_key,
459
    cet.value AS value
460
FROM channel_extra_types cet
461
WHERE cet.channel_id = $1
462
`
463

464
type GetChannelFeaturesAndExtrasRow struct {
465
        ChannelID  int64
466
        IsFeature  bool
467
        FeatureBit int32
468
        ExtraKey   interface{}
469
        Value      interface{}
470
}
471

472
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
473
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
474
        if err != nil {
×
475
                return nil, err
×
476
        }
×
477
        defer rows.Close()
×
478
        var items []GetChannelFeaturesAndExtrasRow
×
479
        for rows.Next() {
×
480
                var i GetChannelFeaturesAndExtrasRow
×
481
                if err := rows.Scan(
×
482
                        &i.ChannelID,
×
483
                        &i.IsFeature,
×
484
                        &i.FeatureBit,
×
485
                        &i.ExtraKey,
×
486
                        &i.Value,
×
487
                ); err != nil {
×
488
                        return nil, err
×
489
                }
×
490
                items = append(items, i)
×
491
        }
492
        if err := rows.Close(); err != nil {
×
493
                return nil, err
×
494
        }
×
495
        if err := rows.Err(); err != nil {
×
496
                return nil, err
×
497
        }
×
498
        return items, nil
×
499
}
500

501
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
502
SELECT id, version, channel_id, node_id, timelock, fee_ppm, base_fee_msat, min_htlc_msat, max_htlc_msat, last_update, disabled, inbound_base_fee_msat, inbound_fee_rate_milli_msat, signature
503
FROM channel_policies
504
WHERE channel_id = $1
505
  AND node_id = $2
506
  AND version = $3
507
`
508

509
type GetChannelPolicyByChannelAndNodeParams struct {
510
        ChannelID int64
511
        NodeID    int64
512
        Version   int16
513
}
514

515
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) {
×
516
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
517
        var i ChannelPolicy
×
518
        err := row.Scan(
×
519
                &i.ID,
×
520
                &i.Version,
×
521
                &i.ChannelID,
×
522
                &i.NodeID,
×
523
                &i.Timelock,
×
524
                &i.FeePpm,
×
525
                &i.BaseFeeMsat,
×
526
                &i.MinHtlcMsat,
×
527
                &i.MaxHtlcMsat,
×
528
                &i.LastUpdate,
×
529
                &i.Disabled,
×
530
                &i.InboundBaseFeeMsat,
×
531
                &i.InboundFeeRateMilliMsat,
×
532
                &i.Signature,
×
533
        )
×
534
        return i, err
×
535
}
×
536

537
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
538
SELECT
539
    cp.id AS policy_id,
540
    cp.channel_id,
541
    cp.node_id,
542
    cpet.type,
543
    cpet.value
544
FROM channel_policies cp
545
JOIN channel_policy_extra_types cpet
546
ON cp.id = cpet.channel_policy_id
547
WHERE cp.id = $1 OR cp.id = $2
548
`
549

550
type GetChannelPolicyExtraTypesParams struct {
551
        ID   int64
552
        ID_2 int64
553
}
554

555
type GetChannelPolicyExtraTypesRow struct {
556
        PolicyID  int64
557
        ChannelID int64
558
        NodeID    int64
559
        Type      int64
560
        Value     []byte
561
}
562

563
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
564
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
565
        if err != nil {
×
566
                return nil, err
×
567
        }
×
568
        defer rows.Close()
×
569
        var items []GetChannelPolicyExtraTypesRow
×
570
        for rows.Next() {
×
571
                var i GetChannelPolicyExtraTypesRow
×
572
                if err := rows.Scan(
×
573
                        &i.PolicyID,
×
574
                        &i.ChannelID,
×
575
                        &i.NodeID,
×
576
                        &i.Type,
×
577
                        &i.Value,
×
578
                ); err != nil {
×
579
                        return nil, err
×
580
                }
×
581
                items = append(items, i)
×
582
        }
583
        if err := rows.Close(); err != nil {
×
584
                return nil, err
×
585
        }
×
586
        if err := rows.Err(); err != nil {
×
587
                return nil, err
×
588
        }
×
589
        return items, nil
×
590
}
591

592
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
593
SELECT
594
    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,
595
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
596
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
597

598
    -- Policy 1 (node_id_1)
599
    cp1.id AS policy1_id,
600
    cp1.node_id AS policy1_node_id,
601
    cp1.version AS policy1_version,
602
    cp1.timelock AS policy1_timelock,
603
    cp1.fee_ppm AS policy1_fee_ppm,
604
    cp1.base_fee_msat AS policy1_base_fee_msat,
605
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
606
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
607
    cp1.last_update AS policy1_last_update,
608
    cp1.disabled AS policy1_disabled,
609
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
610
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
611
    cp1.signature AS policy1_signature,
612

613
    -- Policy 2 (node_id_2)
614
    cp2.id AS policy2_id,
615
    cp2.node_id AS policy2_node_id,
616
    cp2.version AS policy2_version,
617
    cp2.timelock AS policy2_timelock,
618
    cp2.fee_ppm AS policy2_fee_ppm,
619
    cp2.base_fee_msat AS policy2_base_fee_msat,
620
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
621
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
622
    cp2.last_update AS policy2_last_update,
623
    cp2.disabled AS policy2_disabled,
624
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
625
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
626
    cp2.signature AS policy2_signature
627

628
FROM channels c
629
    JOIN nodes n1 ON c.node_id_1 = n1.id
630
    JOIN nodes n2 ON c.node_id_2 = n2.id
631
    LEFT JOIN channel_policies cp1
632
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
633
    LEFT JOIN channel_policies cp2
634
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
635
WHERE c.version = $1
636
  AND (
637
       (cp1.last_update >= $2 AND cp1.last_update < $3)
638
       OR
639
       (cp2.last_update >= $2 AND cp2.last_update < $3)
640
  )
641
ORDER BY
642
    CASE
643
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
644
            THEN COALESCE(cp1.last_update, 0)
645
        ELSE COALESCE(cp2.last_update, 0)
646
        END ASC
647
`
648

649
type GetChannelsByPolicyLastUpdateRangeParams struct {
650
        Version   int16
651
        StartTime sql.NullInt64
652
        EndTime   sql.NullInt64
653
}
654

655
type GetChannelsByPolicyLastUpdateRangeRow struct {
656
        Channel                        Channel
657
        Node                           Node
658
        Node_2                         Node
659
        Policy1ID                      sql.NullInt64
660
        Policy1NodeID                  sql.NullInt64
661
        Policy1Version                 sql.NullInt16
662
        Policy1Timelock                sql.NullInt32
663
        Policy1FeePpm                  sql.NullInt64
664
        Policy1BaseFeeMsat             sql.NullInt64
665
        Policy1MinHtlcMsat             sql.NullInt64
666
        Policy1MaxHtlcMsat             sql.NullInt64
667
        Policy1LastUpdate              sql.NullInt64
668
        Policy1Disabled                sql.NullBool
669
        Policy1InboundBaseFeeMsat      sql.NullInt64
670
        Policy1InboundFeeRateMilliMsat sql.NullInt64
671
        Policy1Signature               []byte
672
        Policy2ID                      sql.NullInt64
673
        Policy2NodeID                  sql.NullInt64
674
        Policy2Version                 sql.NullInt16
675
        Policy2Timelock                sql.NullInt32
676
        Policy2FeePpm                  sql.NullInt64
677
        Policy2BaseFeeMsat             sql.NullInt64
678
        Policy2MinHtlcMsat             sql.NullInt64
679
        Policy2MaxHtlcMsat             sql.NullInt64
680
        Policy2LastUpdate              sql.NullInt64
681
        Policy2Disabled                sql.NullBool
682
        Policy2InboundBaseFeeMsat      sql.NullInt64
683
        Policy2InboundFeeRateMilliMsat sql.NullInt64
684
        Policy2Signature               []byte
685
}
686

687
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
688
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
689
        if err != nil {
×
690
                return nil, err
×
691
        }
×
692
        defer rows.Close()
×
693
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
694
        for rows.Next() {
×
695
                var i GetChannelsByPolicyLastUpdateRangeRow
×
696
                if err := rows.Scan(
×
697
                        &i.Channel.ID,
×
698
                        &i.Channel.Version,
×
699
                        &i.Channel.Scid,
×
700
                        &i.Channel.NodeID1,
×
701
                        &i.Channel.NodeID2,
×
702
                        &i.Channel.Outpoint,
×
703
                        &i.Channel.Capacity,
×
704
                        &i.Channel.BitcoinKey1,
×
705
                        &i.Channel.BitcoinKey2,
×
706
                        &i.Channel.Node1Signature,
×
707
                        &i.Channel.Node2Signature,
×
708
                        &i.Channel.Bitcoin1Signature,
×
709
                        &i.Channel.Bitcoin2Signature,
×
710
                        &i.Node.ID,
×
711
                        &i.Node.Version,
×
712
                        &i.Node.PubKey,
×
713
                        &i.Node.Alias,
×
714
                        &i.Node.LastUpdate,
×
715
                        &i.Node.Color,
×
716
                        &i.Node.Signature,
×
717
                        &i.Node_2.ID,
×
718
                        &i.Node_2.Version,
×
719
                        &i.Node_2.PubKey,
×
720
                        &i.Node_2.Alias,
×
721
                        &i.Node_2.LastUpdate,
×
722
                        &i.Node_2.Color,
×
723
                        &i.Node_2.Signature,
×
724
                        &i.Policy1ID,
×
725
                        &i.Policy1NodeID,
×
726
                        &i.Policy1Version,
×
727
                        &i.Policy1Timelock,
×
728
                        &i.Policy1FeePpm,
×
729
                        &i.Policy1BaseFeeMsat,
×
730
                        &i.Policy1MinHtlcMsat,
×
731
                        &i.Policy1MaxHtlcMsat,
×
732
                        &i.Policy1LastUpdate,
×
733
                        &i.Policy1Disabled,
×
734
                        &i.Policy1InboundBaseFeeMsat,
×
735
                        &i.Policy1InboundFeeRateMilliMsat,
×
736
                        &i.Policy1Signature,
×
737
                        &i.Policy2ID,
×
738
                        &i.Policy2NodeID,
×
739
                        &i.Policy2Version,
×
740
                        &i.Policy2Timelock,
×
741
                        &i.Policy2FeePpm,
×
742
                        &i.Policy2BaseFeeMsat,
×
743
                        &i.Policy2MinHtlcMsat,
×
744
                        &i.Policy2MaxHtlcMsat,
×
745
                        &i.Policy2LastUpdate,
×
746
                        &i.Policy2Disabled,
×
747
                        &i.Policy2InboundBaseFeeMsat,
×
748
                        &i.Policy2InboundFeeRateMilliMsat,
×
749
                        &i.Policy2Signature,
×
750
                ); err != nil {
×
751
                        return nil, err
×
752
                }
×
753
                items = append(items, i)
×
754
        }
755
        if err := rows.Close(); err != nil {
×
756
                return nil, err
×
757
        }
×
758
        if err := rows.Err(); err != nil {
×
759
                return nil, err
×
760
        }
×
761
        return items, nil
×
762
}
763

764
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
765
SELECT node_id, type, value
766
FROM node_extra_types
767
WHERE node_id = $1
768
`
769

770
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
771
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
772
        if err != nil {
×
773
                return nil, err
×
774
        }
×
775
        defer rows.Close()
×
776
        var items []NodeExtraType
×
777
        for rows.Next() {
×
778
                var i NodeExtraType
×
779
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
780
                        return nil, err
×
781
                }
×
782
                items = append(items, i)
×
783
        }
784
        if err := rows.Close(); err != nil {
×
785
                return nil, err
×
786
        }
×
787
        if err := rows.Err(); err != nil {
×
788
                return nil, err
×
789
        }
×
790
        return items, nil
×
791
}
792

793
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
794
SELECT a.type, a.address
795
FROM nodes n
796
LEFT JOIN node_addresses a ON a.node_id = n.id
797
WHERE n.pub_key = $1 AND n.version = $2
798
ORDER BY a.type ASC, a.position ASC
799
`
800

801
type GetNodeAddressesByPubKeyParams struct {
802
        PubKey  []byte
803
        Version int16
804
}
805

806
type GetNodeAddressesByPubKeyRow struct {
807
        Type    sql.NullInt16
808
        Address sql.NullString
809
}
810

811
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
812
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
813
        if err != nil {
×
814
                return nil, err
×
815
        }
×
816
        defer rows.Close()
×
817
        var items []GetNodeAddressesByPubKeyRow
×
818
        for rows.Next() {
×
819
                var i GetNodeAddressesByPubKeyRow
×
820
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
821
                        return nil, err
×
822
                }
×
823
                items = append(items, i)
×
824
        }
825
        if err := rows.Close(); err != nil {
×
826
                return nil, err
×
827
        }
×
828
        if err := rows.Err(); err != nil {
×
829
                return nil, err
×
830
        }
×
831
        return items, nil
×
832
}
833

834
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
835
SELECT id, version, pub_key, alias, last_update, color, signature
836
FROM nodes
837
WHERE pub_key = $1
838
  AND version = $2
839
`
840

841
type GetNodeByPubKeyParams struct {
842
        PubKey  []byte
843
        Version int16
844
}
845

846
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
847
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
848
        var i Node
×
849
        err := row.Scan(
×
850
                &i.ID,
×
851
                &i.Version,
×
852
                &i.PubKey,
×
853
                &i.Alias,
×
854
                &i.LastUpdate,
×
855
                &i.Color,
×
856
                &i.Signature,
×
857
        )
×
858
        return i, err
×
859
}
×
860

861
const getNodeFeatures = `-- name: GetNodeFeatures :many
862
SELECT node_id, feature_bit
863
FROM node_features
864
WHERE node_id = $1
865
`
866

867
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
868
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
869
        if err != nil {
×
870
                return nil, err
×
871
        }
×
872
        defer rows.Close()
×
873
        var items []NodeFeature
×
874
        for rows.Next() {
×
875
                var i NodeFeature
×
876
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
877
                        return nil, err
×
878
                }
×
879
                items = append(items, i)
×
880
        }
881
        if err := rows.Close(); err != nil {
×
882
                return nil, err
×
883
        }
×
884
        if err := rows.Err(); err != nil {
×
885
                return nil, err
×
886
        }
×
887
        return items, nil
×
888
}
889

890
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
891
SELECT f.feature_bit
892
FROM nodes n
893
    JOIN node_features f ON f.node_id = n.id
894
WHERE n.pub_key = $1
895
  AND n.version = $2
896
`
897

898
type GetNodeFeaturesByPubKeyParams struct {
899
        PubKey  []byte
900
        Version int16
901
}
902

903
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
904
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
905
        if err != nil {
×
906
                return nil, err
×
907
        }
×
908
        defer rows.Close()
×
909
        var items []int32
×
910
        for rows.Next() {
×
911
                var feature_bit int32
×
912
                if err := rows.Scan(&feature_bit); err != nil {
×
913
                        return nil, err
×
914
                }
×
915
                items = append(items, feature_bit)
×
916
        }
917
        if err := rows.Close(); err != nil {
×
918
                return nil, err
×
919
        }
×
920
        if err := rows.Err(); err != nil {
×
921
                return nil, err
×
922
        }
×
923
        return items, nil
×
924
}
925

926
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
927
SELECT id
928
FROM nodes
929
WHERE pub_key = $1
930
  AND version = $2
931
`
932

933
type GetNodeIDByPubKeyParams struct {
934
        PubKey  []byte
935
        Version int16
936
}
937

938
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
939
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
940
        var id int64
×
941
        err := row.Scan(&id)
×
942
        return id, err
×
943
}
×
944

945
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
946
SELECT id, version, pub_key, alias, last_update, color, signature
947
FROM nodes
948
WHERE last_update >= $1
949
  AND last_update < $2
950
`
951

952
type GetNodesByLastUpdateRangeParams struct {
953
        StartTime sql.NullInt64
954
        EndTime   sql.NullInt64
955
}
956

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

988
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
989
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
990
FROM channels
991
WHERE node_1_signature IS NOT NULL
992
  AND scid >= $1
993
  AND scid < $2
994
`
995

996
type GetPublicV1ChannelsBySCIDParams struct {
997
        StartScid []byte
998
        EndScid   []byte
999
}
1000

1001
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
×
1002
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1003
        if err != nil {
×
1004
                return nil, err
×
1005
        }
×
1006
        defer rows.Close()
×
1007
        var items []Channel
×
1008
        for rows.Next() {
×
1009
                var i Channel
×
1010
                if err := rows.Scan(
×
1011
                        &i.ID,
×
1012
                        &i.Version,
×
1013
                        &i.Scid,
×
1014
                        &i.NodeID1,
×
1015
                        &i.NodeID2,
×
1016
                        &i.Outpoint,
×
1017
                        &i.Capacity,
×
1018
                        &i.BitcoinKey1,
×
1019
                        &i.BitcoinKey2,
×
1020
                        &i.Node1Signature,
×
1021
                        &i.Node2Signature,
×
1022
                        &i.Bitcoin1Signature,
×
1023
                        &i.Bitcoin2Signature,
×
1024
                ); err != nil {
×
1025
                        return nil, err
×
1026
                }
×
1027
                items = append(items, i)
×
1028
        }
1029
        if err := rows.Close(); err != nil {
×
1030
                return nil, err
×
1031
        }
×
1032
        if err := rows.Err(); err != nil {
×
1033
                return nil, err
×
1034
        }
×
1035
        return items, nil
×
1036
}
1037

1038
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1039
SELECT sn.node_id, n.pub_key
1040
FROM source_nodes sn
1041
    JOIN nodes n ON sn.node_id = n.id
1042
WHERE n.version = $1
1043
`
1044

1045
type GetSourceNodesByVersionRow struct {
1046
        NodeID int64
1047
        PubKey []byte
1048
}
1049

1050
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1051
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1052
        if err != nil {
×
1053
                return nil, err
×
1054
        }
×
1055
        defer rows.Close()
×
1056
        var items []GetSourceNodesByVersionRow
×
1057
        for rows.Next() {
×
1058
                var i GetSourceNodesByVersionRow
×
1059
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1060
                        return nil, err
×
1061
                }
×
1062
                items = append(items, i)
×
1063
        }
1064
        if err := rows.Close(); err != nil {
×
1065
                return nil, err
×
1066
        }
×
1067
        if err := rows.Err(); err != nil {
×
1068
                return nil, err
×
1069
        }
×
1070
        return items, nil
×
1071
}
1072

1073
const getZombieChannel = `-- name: GetZombieChannel :one
1074
SELECT scid, version, node_key_1, node_key_2
1075
FROM zombie_channels
1076
WHERE scid = $1
1077
AND version = $2
1078
`
1079

1080
type GetZombieChannelParams struct {
1081
        Scid    []byte
1082
        Version int16
1083
}
1084

NEW
1085
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) {
×
NEW
1086
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
NEW
1087
        var i ZombieChannel
×
NEW
1088
        err := row.Scan(
×
NEW
1089
                &i.Scid,
×
NEW
1090
                &i.Version,
×
NEW
1091
                &i.NodeKey1,
×
NEW
1092
                &i.NodeKey2,
×
NEW
1093
        )
×
NEW
1094
        return i, err
×
NEW
1095
}
×
1096

1097
const highestSCID = `-- name: HighestSCID :one
1098
SELECT scid
1099
FROM channels
1100
WHERE version = $1
1101
ORDER BY scid DESC
1102
LIMIT 1
1103
`
1104

1105
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1106
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1107
        var scid []byte
×
1108
        err := row.Scan(&scid)
×
1109
        return scid, err
×
1110
}
×
1111

1112
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1113
/* ─────────────────────────────────────────────
1114
   channel_policy_extra_types table queries
1115
   ─────────────────────────────────────────────
1116
*/
1117

1118
INSERT INTO channel_policy_extra_types (
1119
    channel_policy_id, type, value
1120
)
1121
VALUES ($1, $2, $3)
1122
`
1123

1124
type InsertChanPolicyExtraTypeParams struct {
1125
        ChannelPolicyID int64
1126
        Type            int64
1127
        Value           []byte
1128
}
1129

1130
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1131
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1132
        return err
×
1133
}
×
1134

1135
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1136
/* ─────────────────────────────────────────────
1137
   channel_features table queries
1138
   ─────────────────────────────────────────────
1139
*/
1140

1141
INSERT INTO channel_features (
1142
    channel_id, feature_bit
1143
) VALUES (
1144
    $1, $2
1145
)
1146
`
1147

1148
type InsertChannelFeatureParams struct {
1149
        ChannelID  int64
1150
        FeatureBit int32
1151
}
1152

1153
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1154
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1155
        return err
×
1156
}
×
1157

1158
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1159
/* ─────────────────────────────────────────────
1160
   node_addresses table queries
1161
   ─────────────────────────────────────────────
1162
*/
1163

1164
INSERT INTO node_addresses (
1165
    node_id,
1166
    type,
1167
    address,
1168
    position
1169
) VALUES (
1170
    $1, $2, $3, $4
1171
 )
1172
`
1173

1174
type InsertNodeAddressParams struct {
1175
        NodeID   int64
1176
        Type     int16
1177
        Address  string
1178
        Position int32
1179
}
1180

1181
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1182
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1183
                arg.NodeID,
×
1184
                arg.Type,
×
1185
                arg.Address,
×
1186
                arg.Position,
×
1187
        )
×
1188
        return err
×
1189
}
×
1190

1191
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1192
/* ─────────────────────────────────────────────
1193
   node_features table queries
1194
   ─────────────────────────────────────────────
1195
*/
1196

1197
INSERT INTO node_features (
1198
    node_id, feature_bit
1199
) VALUES (
1200
    $1, $2
1201
)
1202
`
1203

1204
type InsertNodeFeatureParams struct {
1205
        NodeID     int64
1206
        FeatureBit int32
1207
}
1208

1209
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1210
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1211
        return err
×
1212
}
×
1213

1214
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1215
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,
1216
    n1.pub_key AS node1_pubkey,
1217
    n2.pub_key AS node2_pubkey,
1218

1219
    -- Policy 1
1220
    -- TODO(elle): use sqlc.embed to embed policy structs
1221
    --  once this issue is resolved:
1222
    --  https://github.com/sqlc-dev/sqlc/issues/2997
1223
    cp1.id AS policy1_id,
1224
    cp1.node_id AS policy1_node_id,
1225
    cp1.version AS policy1_version,
1226
    cp1.timelock AS policy1_timelock,
1227
    cp1.fee_ppm AS policy1_fee_ppm,
1228
    cp1.base_fee_msat AS policy1_base_fee_msat,
1229
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1230
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1231
    cp1.last_update AS policy1_last_update,
1232
    cp1.disabled AS policy1_disabled,
1233
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1234
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1235
    cp1.signature AS policy1_signature,
1236

1237
       -- Policy 2
1238
    cp2.id AS policy2_id,
1239
    cp2.node_id AS policy2_node_id,
1240
    cp2.version AS policy2_version,
1241
    cp2.timelock AS policy2_timelock,
1242
    cp2.fee_ppm AS policy2_fee_ppm,
1243
    cp2.base_fee_msat AS policy2_base_fee_msat,
1244
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1245
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1246
    cp2.last_update AS policy2_last_update,
1247
    cp2.disabled AS policy2_disabled,
1248
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1249
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1250
    cp2.signature AS policy2_signature
1251

1252
FROM channels c
1253
    JOIN nodes n1 ON c.node_id_1 = n1.id
1254
    JOIN nodes n2 ON c.node_id_2 = n2.id
1255
    LEFT JOIN channel_policies cp1
1256
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1257
    LEFT JOIN channel_policies cp2
1258
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1259
WHERE c.version = $1
1260
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1261
`
1262

1263
type ListChannelsByNodeIDParams struct {
1264
        Version int16
1265
        NodeID1 int64
1266
}
1267

1268
type ListChannelsByNodeIDRow struct {
1269
        Channel                        Channel
1270
        Node1Pubkey                    []byte
1271
        Node2Pubkey                    []byte
1272
        Policy1ID                      sql.NullInt64
1273
        Policy1NodeID                  sql.NullInt64
1274
        Policy1Version                 sql.NullInt16
1275
        Policy1Timelock                sql.NullInt32
1276
        Policy1FeePpm                  sql.NullInt64
1277
        Policy1BaseFeeMsat             sql.NullInt64
1278
        Policy1MinHtlcMsat             sql.NullInt64
1279
        Policy1MaxHtlcMsat             sql.NullInt64
1280
        Policy1LastUpdate              sql.NullInt64
1281
        Policy1Disabled                sql.NullBool
1282
        Policy1InboundBaseFeeMsat      sql.NullInt64
1283
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1284
        Policy1Signature               []byte
1285
        Policy2ID                      sql.NullInt64
1286
        Policy2NodeID                  sql.NullInt64
1287
        Policy2Version                 sql.NullInt16
1288
        Policy2Timelock                sql.NullInt32
1289
        Policy2FeePpm                  sql.NullInt64
1290
        Policy2BaseFeeMsat             sql.NullInt64
1291
        Policy2MinHtlcMsat             sql.NullInt64
1292
        Policy2MaxHtlcMsat             sql.NullInt64
1293
        Policy2LastUpdate              sql.NullInt64
1294
        Policy2Disabled                sql.NullBool
1295
        Policy2InboundBaseFeeMsat      sql.NullInt64
1296
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1297
        Policy2Signature               []byte
1298
}
1299

1300
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
1301
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
1302
        if err != nil {
×
1303
                return nil, err
×
1304
        }
×
1305
        defer rows.Close()
×
1306
        var items []ListChannelsByNodeIDRow
×
1307
        for rows.Next() {
×
1308
                var i ListChannelsByNodeIDRow
×
1309
                if err := rows.Scan(
×
1310
                        &i.Channel.ID,
×
1311
                        &i.Channel.Version,
×
1312
                        &i.Channel.Scid,
×
1313
                        &i.Channel.NodeID1,
×
1314
                        &i.Channel.NodeID2,
×
1315
                        &i.Channel.Outpoint,
×
1316
                        &i.Channel.Capacity,
×
1317
                        &i.Channel.BitcoinKey1,
×
1318
                        &i.Channel.BitcoinKey2,
×
1319
                        &i.Channel.Node1Signature,
×
1320
                        &i.Channel.Node2Signature,
×
1321
                        &i.Channel.Bitcoin1Signature,
×
1322
                        &i.Channel.Bitcoin2Signature,
×
1323
                        &i.Node1Pubkey,
×
1324
                        &i.Node2Pubkey,
×
1325
                        &i.Policy1ID,
×
1326
                        &i.Policy1NodeID,
×
1327
                        &i.Policy1Version,
×
1328
                        &i.Policy1Timelock,
×
1329
                        &i.Policy1FeePpm,
×
1330
                        &i.Policy1BaseFeeMsat,
×
1331
                        &i.Policy1MinHtlcMsat,
×
1332
                        &i.Policy1MaxHtlcMsat,
×
1333
                        &i.Policy1LastUpdate,
×
1334
                        &i.Policy1Disabled,
×
1335
                        &i.Policy1InboundBaseFeeMsat,
×
1336
                        &i.Policy1InboundFeeRateMilliMsat,
×
1337
                        &i.Policy1Signature,
×
1338
                        &i.Policy2ID,
×
1339
                        &i.Policy2NodeID,
×
1340
                        &i.Policy2Version,
×
1341
                        &i.Policy2Timelock,
×
1342
                        &i.Policy2FeePpm,
×
1343
                        &i.Policy2BaseFeeMsat,
×
1344
                        &i.Policy2MinHtlcMsat,
×
1345
                        &i.Policy2MaxHtlcMsat,
×
1346
                        &i.Policy2LastUpdate,
×
1347
                        &i.Policy2Disabled,
×
1348
                        &i.Policy2InboundBaseFeeMsat,
×
1349
                        &i.Policy2InboundFeeRateMilliMsat,
×
1350
                        &i.Policy2Signature,
×
1351
                ); err != nil {
×
1352
                        return nil, err
×
1353
                }
×
1354
                items = append(items, i)
×
1355
        }
1356
        if err := rows.Close(); err != nil {
×
1357
                return nil, err
×
1358
        }
×
1359
        if err := rows.Err(); err != nil {
×
1360
                return nil, err
×
1361
        }
×
1362
        return items, nil
×
1363
}
1364

1365
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
1366
SELECT
1367
    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,
1368

1369
    -- Join node pubkeys
1370
    n1.pub_key AS node1_pubkey,
1371
    n2.pub_key AS node2_pubkey,
1372

1373
    -- Node 1 policy
1374
    cp1.id AS policy_1_id,
1375
    cp1.node_id AS policy_1_node_id,
1376
    cp1.version AS policy_1_version,
1377
    cp1.timelock AS policy_1_timelock,
1378
    cp1.fee_ppm AS policy_1_fee_ppm,
1379
    cp1.base_fee_msat AS policy_1_base_fee_msat,
1380
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
1381
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
1382
    cp1.last_update AS policy_1_last_update,
1383
    cp1.disabled AS policy_1_disabled,
1384
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1385
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1386
    cp1.signature AS policy_1_signature,
1387

1388
    -- Node 2 policy
1389
    cp2.id AS policy_2_id,
1390
    cp2.node_id AS policy_2_node_id,
1391
    cp2.version AS policy_2_version,
1392
    cp2.timelock AS policy_2_timelock,
1393
    cp2.fee_ppm AS policy_2_fee_ppm,
1394
    cp2.base_fee_msat AS policy_2_base_fee_msat,
1395
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
1396
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
1397
    cp2.last_update AS policy_2_last_update,
1398
    cp2.disabled AS policy_2_disabled,
1399
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1400
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1401
    cp2.signature AS policy_2_signature
1402

1403
FROM channels c
1404
JOIN nodes n1 ON c.node_id_1 = n1.id
1405
JOIN nodes n2 ON c.node_id_2 = n2.id
1406
LEFT JOIN channel_policies cp1
1407
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1408
LEFT JOIN channel_policies cp2
1409
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1410
WHERE c.version = $1 AND c.id > $2
1411
ORDER BY c.id
1412
LIMIT $3
1413
`
1414

1415
type ListChannelsWithPoliciesPaginatedParams struct {
1416
        Version int16
1417
        ID      int64
1418
        Limit   int32
1419
}
1420

1421
type ListChannelsWithPoliciesPaginatedRow struct {
1422
        Channel                        Channel
1423
        Node1Pubkey                    []byte
1424
        Node2Pubkey                    []byte
1425
        Policy1ID                      sql.NullInt64
1426
        Policy1NodeID                  sql.NullInt64
1427
        Policy1Version                 sql.NullInt16
1428
        Policy1Timelock                sql.NullInt32
1429
        Policy1FeePpm                  sql.NullInt64
1430
        Policy1BaseFeeMsat             sql.NullInt64
1431
        Policy1MinHtlcMsat             sql.NullInt64
1432
        Policy1MaxHtlcMsat             sql.NullInt64
1433
        Policy1LastUpdate              sql.NullInt64
1434
        Policy1Disabled                sql.NullBool
1435
        Policy1InboundBaseFeeMsat      sql.NullInt64
1436
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1437
        Policy1Signature               []byte
1438
        Policy2ID                      sql.NullInt64
1439
        Policy2NodeID                  sql.NullInt64
1440
        Policy2Version                 sql.NullInt16
1441
        Policy2Timelock                sql.NullInt32
1442
        Policy2FeePpm                  sql.NullInt64
1443
        Policy2BaseFeeMsat             sql.NullInt64
1444
        Policy2MinHtlcMsat             sql.NullInt64
1445
        Policy2MaxHtlcMsat             sql.NullInt64
1446
        Policy2LastUpdate              sql.NullInt64
1447
        Policy2Disabled                sql.NullBool
1448
        Policy2InboundBaseFeeMsat      sql.NullInt64
1449
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1450
        Policy2Signature               []byte
1451
}
1452

1453
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
1454
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
1455
        if err != nil {
×
1456
                return nil, err
×
1457
        }
×
1458
        defer rows.Close()
×
1459
        var items []ListChannelsWithPoliciesPaginatedRow
×
1460
        for rows.Next() {
×
1461
                var i ListChannelsWithPoliciesPaginatedRow
×
1462
                if err := rows.Scan(
×
1463
                        &i.Channel.ID,
×
1464
                        &i.Channel.Version,
×
1465
                        &i.Channel.Scid,
×
1466
                        &i.Channel.NodeID1,
×
1467
                        &i.Channel.NodeID2,
×
1468
                        &i.Channel.Outpoint,
×
1469
                        &i.Channel.Capacity,
×
1470
                        &i.Channel.BitcoinKey1,
×
1471
                        &i.Channel.BitcoinKey2,
×
1472
                        &i.Channel.Node1Signature,
×
1473
                        &i.Channel.Node2Signature,
×
1474
                        &i.Channel.Bitcoin1Signature,
×
1475
                        &i.Channel.Bitcoin2Signature,
×
1476
                        &i.Node1Pubkey,
×
1477
                        &i.Node2Pubkey,
×
1478
                        &i.Policy1ID,
×
1479
                        &i.Policy1NodeID,
×
1480
                        &i.Policy1Version,
×
1481
                        &i.Policy1Timelock,
×
1482
                        &i.Policy1FeePpm,
×
1483
                        &i.Policy1BaseFeeMsat,
×
1484
                        &i.Policy1MinHtlcMsat,
×
1485
                        &i.Policy1MaxHtlcMsat,
×
1486
                        &i.Policy1LastUpdate,
×
1487
                        &i.Policy1Disabled,
×
1488
                        &i.Policy1InboundBaseFeeMsat,
×
1489
                        &i.Policy1InboundFeeRateMilliMsat,
×
1490
                        &i.Policy1Signature,
×
1491
                        &i.Policy2ID,
×
1492
                        &i.Policy2NodeID,
×
1493
                        &i.Policy2Version,
×
1494
                        &i.Policy2Timelock,
×
1495
                        &i.Policy2FeePpm,
×
1496
                        &i.Policy2BaseFeeMsat,
×
1497
                        &i.Policy2MinHtlcMsat,
×
1498
                        &i.Policy2MaxHtlcMsat,
×
1499
                        &i.Policy2LastUpdate,
×
1500
                        &i.Policy2Disabled,
×
1501
                        &i.Policy2InboundBaseFeeMsat,
×
1502
                        &i.Policy2InboundFeeRateMilliMsat,
×
1503
                        &i.Policy2Signature,
×
1504
                ); err != nil {
×
1505
                        return nil, err
×
1506
                }
×
1507
                items = append(items, i)
×
1508
        }
1509
        if err := rows.Close(); err != nil {
×
1510
                return nil, err
×
1511
        }
×
1512
        if err := rows.Err(); err != nil {
×
1513
                return nil, err
×
1514
        }
×
1515
        return items, nil
×
1516
}
1517

1518
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
1519
SELECT id, pub_key
1520
FROM nodes
1521
WHERE version = $1  AND id > $2
1522
ORDER BY id
1523
LIMIT $3
1524
`
1525

1526
type ListNodeIDsAndPubKeysParams struct {
1527
        Version int16
1528
        ID      int64
1529
        Limit   int32
1530
}
1531

1532
type ListNodeIDsAndPubKeysRow struct {
1533
        ID     int64
1534
        PubKey []byte
1535
}
1536

1537
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
1538
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
1539
        if err != nil {
×
1540
                return nil, err
×
1541
        }
×
1542
        defer rows.Close()
×
1543
        var items []ListNodeIDsAndPubKeysRow
×
1544
        for rows.Next() {
×
1545
                var i ListNodeIDsAndPubKeysRow
×
1546
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
1547
                        return nil, err
×
1548
                }
×
1549
                items = append(items, i)
×
1550
        }
1551
        if err := rows.Close(); err != nil {
×
1552
                return nil, err
×
1553
        }
×
1554
        if err := rows.Err(); err != nil {
×
1555
                return nil, err
×
1556
        }
×
1557
        return items, nil
×
1558
}
1559

1560
const listNodesPaginated = `-- name: ListNodesPaginated :many
1561
SELECT id, version, pub_key, alias, last_update, color, signature
1562
FROM nodes
1563
WHERE version = $1 AND id > $2
1564
ORDER BY id
1565
LIMIT $3
1566
`
1567

1568
type ListNodesPaginatedParams struct {
1569
        Version int16
1570
        ID      int64
1571
        Limit   int32
1572
}
1573

1574
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) {
×
1575
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
1576
        if err != nil {
×
1577
                return nil, err
×
1578
        }
×
1579
        defer rows.Close()
×
1580
        var items []Node
×
1581
        for rows.Next() {
×
1582
                var i Node
×
1583
                if err := rows.Scan(
×
1584
                        &i.ID,
×
1585
                        &i.Version,
×
1586
                        &i.PubKey,
×
1587
                        &i.Alias,
×
1588
                        &i.LastUpdate,
×
1589
                        &i.Color,
×
1590
                        &i.Signature,
×
1591
                ); err != nil {
×
1592
                        return nil, err
×
1593
                }
×
1594
                items = append(items, i)
×
1595
        }
1596
        if err := rows.Close(); err != nil {
×
1597
                return nil, err
×
1598
        }
×
1599
        if err := rows.Err(); err != nil {
×
1600
                return nil, err
×
1601
        }
×
1602
        return items, nil
×
1603
}
1604

1605
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
1606
/* ─────────────────────────────────────────────
1607
   channel_policies table queries
1608
   ─────────────────────────────────────────────
1609
*/
1610

1611
INSERT INTO channel_policies (
1612
    version, channel_id, node_id, timelock, fee_ppm,
1613
    base_fee_msat, min_htlc_msat, last_update, disabled,
1614
    max_htlc_msat, inbound_base_fee_msat,
1615
    inbound_fee_rate_milli_msat, signature
1616
) VALUES  (
1617
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
1618
)
1619
ON CONFLICT (channel_id, node_id, version)
1620
    -- Update the following fields if a conflict occurs on channel_id,
1621
    -- node_id, and version.
1622
    DO UPDATE SET
1623
        timelock = EXCLUDED.timelock,
1624
        fee_ppm = EXCLUDED.fee_ppm,
1625
        base_fee_msat = EXCLUDED.base_fee_msat,
1626
        min_htlc_msat = EXCLUDED.min_htlc_msat,
1627
        last_update = EXCLUDED.last_update,
1628
        disabled = EXCLUDED.disabled,
1629
        max_htlc_msat = EXCLUDED.max_htlc_msat,
1630
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
1631
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
1632
        signature = EXCLUDED.signature
1633
WHERE EXCLUDED.last_update > channel_policies.last_update
1634
RETURNING id
1635
`
1636

1637
type UpsertEdgePolicyParams struct {
1638
        Version                 int16
1639
        ChannelID               int64
1640
        NodeID                  int64
1641
        Timelock                int32
1642
        FeePpm                  int64
1643
        BaseFeeMsat             int64
1644
        MinHtlcMsat             int64
1645
        LastUpdate              sql.NullInt64
1646
        Disabled                sql.NullBool
1647
        MaxHtlcMsat             sql.NullInt64
1648
        InboundBaseFeeMsat      sql.NullInt64
1649
        InboundFeeRateMilliMsat sql.NullInt64
1650
        Signature               []byte
1651
}
1652

1653
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
1654
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
1655
                arg.Version,
×
1656
                arg.ChannelID,
×
1657
                arg.NodeID,
×
1658
                arg.Timelock,
×
1659
                arg.FeePpm,
×
1660
                arg.BaseFeeMsat,
×
1661
                arg.MinHtlcMsat,
×
1662
                arg.LastUpdate,
×
1663
                arg.Disabled,
×
1664
                arg.MaxHtlcMsat,
×
1665
                arg.InboundBaseFeeMsat,
×
1666
                arg.InboundFeeRateMilliMsat,
×
1667
                arg.Signature,
×
1668
        )
×
1669
        var id int64
×
1670
        err := row.Scan(&id)
×
1671
        return id, err
×
1672
}
×
1673

1674
const upsertNode = `-- name: UpsertNode :one
1675
/* ─────────────────────────────────────────────
1676
   nodes table queries
1677
   ─────────────────────────────────────────────
1678
*/
1679

1680
INSERT INTO nodes (
1681
    version, pub_key, alias, last_update, color, signature
1682
) VALUES (
1683
    $1, $2, $3, $4, $5, $6
1684
)
1685
ON CONFLICT (pub_key, version)
1686
    -- Update the following fields if a conflict occurs on pub_key
1687
    -- and version.
1688
    DO UPDATE SET
1689
        alias = EXCLUDED.alias,
1690
        last_update = EXCLUDED.last_update,
1691
        color = EXCLUDED.color,
1692
        signature = EXCLUDED.signature
1693
WHERE nodes.last_update IS NULL
1694
    OR EXCLUDED.last_update > nodes.last_update
1695
RETURNING id
1696
`
1697

1698
type UpsertNodeParams struct {
1699
        Version    int16
1700
        PubKey     []byte
1701
        Alias      sql.NullString
1702
        LastUpdate sql.NullInt64
1703
        Color      sql.NullString
1704
        Signature  []byte
1705
}
1706

1707
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
1708
        row := q.db.QueryRowContext(ctx, upsertNode,
×
1709
                arg.Version,
×
1710
                arg.PubKey,
×
1711
                arg.Alias,
×
1712
                arg.LastUpdate,
×
1713
                arg.Color,
×
1714
                arg.Signature,
×
1715
        )
×
1716
        var id int64
×
1717
        err := row.Scan(&id)
×
1718
        return id, err
×
1719
}
×
1720

1721
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
1722
/* ─────────────────────────────────────────────
1723
   node_extra_types table queries
1724
   ─────────────────────────────────────────────
1725
*/
1726

1727
INSERT INTO node_extra_types (
1728
    node_id, type, value
1729
)
1730
VALUES ($1, $2, $3)
1731
ON CONFLICT (type, node_id)
1732
    -- Update the value if a conflict occurs on type
1733
    -- and node_id.
1734
    DO UPDATE SET value = EXCLUDED.value
1735
`
1736

1737
type UpsertNodeExtraTypeParams struct {
1738
        NodeID int64
1739
        Type   int64
1740
        Value  []byte
1741
}
1742

1743
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
1744
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
1745
        return err
×
1746
}
×
1747

1748
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
1749
/* ─────────────────────────────────────────────
1750
   zombie_channels table queries
1751
   ─────────────────────────────────────────────
1752
*/
1753

1754
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
1755
VALUES ($1, $2, $3, $4)
1756
ON CONFLICT (scid, version)
1757
DO UPDATE SET
1758
    -- If a conflict exists for the SCID and version pair, then we
1759
    -- update the node keys.
1760
    node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
1761
    node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2)
1762
`
1763

1764
type UpsertZombieChannelParams struct {
1765
        Scid     []byte
1766
        Version  int16
1767
        NodeKey1 []byte
1768
        NodeKey2 []byte
1769
}
1770

NEW
1771
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
NEW
1772
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
NEW
1773
                arg.Scid,
×
NEW
1774
                arg.Version,
×
NEW
1775
                arg.NodeKey1,
×
NEW
1776
                arg.NodeKey2,
×
NEW
1777
        )
×
NEW
1778
        return err
×
NEW
1779
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc