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

lightningnetwork / lnd / 16448527814

22 Jul 2025 03:19PM UTC coverage: 67.239% (+9.7%) from 57.535%
16448527814

Pull #10081

github

web-flow
Merge ddc0e95ed into f09c7aee4
Pull Request #10081: graph/db: use `/*SLICE:<field_name>*/` to optimise various graph queries

20 of 471 new or added lines in 4 files covered. (4.25%)

39 existing lines in 9 files now uncovered.

135503 of 201523 relevant lines covered (67.24%)

21726.29 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
        "strings"
12
)
13

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

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

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

30
const addV1ChannelProof = `-- name: AddV1ChannelProof :execresult
31
UPDATE graph_channels
32
SET node_1_signature = $2,
33
    node_2_signature = $3,
34
    bitcoin_1_signature = $4,
35
    bitcoin_2_signature = $5
36
WHERE scid = $1
37
  AND version = 1
38
`
39

40
type AddV1ChannelProofParams struct {
41
        Scid              []byte
42
        Node1Signature    []byte
43
        Node2Signature    []byte
44
        Bitcoin1Signature []byte
45
        Bitcoin2Signature []byte
46
}
47

48
func (q *Queries) AddV1ChannelProof(ctx context.Context, arg AddV1ChannelProofParams) (sql.Result, error) {
×
49
        return q.db.ExecContext(ctx, addV1ChannelProof,
×
50
                arg.Scid,
×
51
                arg.Node1Signature,
×
52
                arg.Node2Signature,
×
53
                arg.Bitcoin1Signature,
×
54
                arg.Bitcoin2Signature,
×
55
        )
×
56
}
×
57

58
const countZombieChannels = `-- name: CountZombieChannels :one
59
SELECT COUNT(*)
60
FROM graph_zombie_channels
61
WHERE version = $1
62
`
63

64
func (q *Queries) CountZombieChannels(ctx context.Context, version int16) (int64, error) {
×
65
        row := q.db.QueryRowContext(ctx, countZombieChannels, version)
×
66
        var count int64
×
67
        err := row.Scan(&count)
×
68
        return count, err
×
69
}
×
70

71
const createChannel = `-- name: CreateChannel :one
72
/* ─────────────────────────────────────────────
73
   graph_channels table queries
74
   ─────────────────────────────────────────────
75
*/
76

77
INSERT INTO graph_channels (
78
    version, scid, node_id_1, node_id_2,
79
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
80
    node_1_signature, node_2_signature, bitcoin_1_signature,
81
    bitcoin_2_signature
82
) VALUES (
83
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
84
)
85
RETURNING id
86
`
87

88
type CreateChannelParams struct {
89
        Version           int16
90
        Scid              []byte
91
        NodeID1           int64
92
        NodeID2           int64
93
        Outpoint          string
94
        Capacity          sql.NullInt64
95
        BitcoinKey1       []byte
96
        BitcoinKey2       []byte
97
        Node1Signature    []byte
98
        Node2Signature    []byte
99
        Bitcoin1Signature []byte
100
        Bitcoin2Signature []byte
101
}
102

103
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
×
104
        row := q.db.QueryRowContext(ctx, createChannel,
×
105
                arg.Version,
×
106
                arg.Scid,
×
107
                arg.NodeID1,
×
108
                arg.NodeID2,
×
109
                arg.Outpoint,
×
110
                arg.Capacity,
×
111
                arg.BitcoinKey1,
×
112
                arg.BitcoinKey2,
×
113
                arg.Node1Signature,
×
114
                arg.Node2Signature,
×
115
                arg.Bitcoin1Signature,
×
116
                arg.Bitcoin2Signature,
×
117
        )
×
118
        var id int64
×
119
        err := row.Scan(&id)
×
120
        return id, err
×
121
}
×
122

123
const createChannelExtraType = `-- name: CreateChannelExtraType :exec
124
/* ─────────────────────────────────────────────
125
   graph_channel_extra_types table queries
126
   ─────────────────────────────────────────────
127
*/
128

129
INSERT INTO graph_channel_extra_types (
130
    channel_id, type, value
131
)
132
VALUES ($1, $2, $3)
133
`
134

135
type CreateChannelExtraTypeParams struct {
136
        ChannelID int64
137
        Type      int64
138
        Value     []byte
139
}
140

141
func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelExtraTypeParams) error {
×
142
        _, err := q.db.ExecContext(ctx, createChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
143
        return err
×
144
}
×
145

146
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
147
DELETE FROM graph_channel_policy_extra_types
148
WHERE channel_policy_id = $1
149
`
150

151
func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error {
×
152
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraTypes, channelPolicyID)
×
153
        return err
×
154
}
×
155

156
const deleteChannels = `-- name: DeleteChannels :exec
157
DELETE FROM graph_channels
158
WHERE id IN (/*SLICE:ids*/?)
159
`
160

NEW
161
func (q *Queries) DeleteChannels(ctx context.Context, ids []int64) error {
×
NEW
162
        query := deleteChannels
×
NEW
163
        var queryParams []interface{}
×
NEW
164
        if len(ids) > 0 {
×
NEW
165
                for _, v := range ids {
×
NEW
166
                        queryParams = append(queryParams, v)
×
NEW
167
                }
×
NEW
168
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
NEW
169
        } else {
×
NEW
170
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
NEW
171
        }
×
NEW
172
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
NEW
173
        return err
×
174
}
175

176
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
177
DELETE FROM graph_node_extra_types
178
WHERE node_id = $1
179
  AND type = $2
180
`
181

182
type DeleteExtraNodeTypeParams struct {
183
        NodeID int64
184
        Type   int64
185
}
186

187
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
188
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
189
        return err
×
190
}
×
191

192
const deleteNode = `-- name: DeleteNode :exec
193
DELETE FROM graph_nodes
194
WHERE id = $1
195
`
196

197
func (q *Queries) DeleteNode(ctx context.Context, id int64) error {
×
198
        _, err := q.db.ExecContext(ctx, deleteNode, id)
×
199
        return err
×
200
}
×
201

202
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
203
DELETE FROM graph_node_addresses
204
WHERE node_id = $1
205
`
206

207
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
208
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
209
        return err
×
210
}
×
211

212
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
213
DELETE FROM graph_nodes
214
WHERE pub_key = $1
215
  AND version = $2
216
`
217

218
type DeleteNodeByPubKeyParams struct {
219
        PubKey  []byte
220
        Version int16
221
}
222

223
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
224
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
225
}
×
226

227
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
228
DELETE FROM graph_node_features
229
WHERE node_id = $1
230
  AND feature_bit = $2
231
`
232

233
type DeleteNodeFeatureParams struct {
234
        NodeID     int64
235
        FeatureBit int32
236
}
237

238
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
239
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
240
        return err
×
241
}
×
242

243
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
244
DELETE FROM graph_prune_log
245
WHERE block_height >= $1
246
  AND block_height <= $2
247
`
248

249
type DeletePruneLogEntriesInRangeParams struct {
250
        StartHeight int64
251
        EndHeight   int64
252
}
253

254
func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error {
×
255
        _, err := q.db.ExecContext(ctx, deletePruneLogEntriesInRange, arg.StartHeight, arg.EndHeight)
×
256
        return err
×
257
}
×
258

259
const deleteUnconnectedNodes = `-- name: DeleteUnconnectedNodes :many
260
DELETE FROM graph_nodes
261
WHERE
262
    -- Ignore any of our source nodes.
263
    NOT EXISTS (
264
        SELECT 1
265
        FROM graph_source_nodes sn
266
        WHERE sn.node_id = graph_nodes.id
267
    )
268
    -- Select all nodes that do not have any channels.
269
    AND NOT EXISTS (
270
        SELECT 1
271
        FROM graph_channels c
272
        WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id
273
) RETURNING pub_key
274
`
275

276
func (q *Queries) DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error) {
×
277
        rows, err := q.db.QueryContext(ctx, deleteUnconnectedNodes)
×
278
        if err != nil {
×
279
                return nil, err
×
280
        }
×
281
        defer rows.Close()
×
282
        var items [][]byte
×
283
        for rows.Next() {
×
284
                var pub_key []byte
×
285
                if err := rows.Scan(&pub_key); err != nil {
×
286
                        return nil, err
×
287
                }
×
288
                items = append(items, pub_key)
×
289
        }
290
        if err := rows.Close(); err != nil {
×
291
                return nil, err
×
292
        }
×
293
        if err := rows.Err(); err != nil {
×
294
                return nil, err
×
295
        }
×
296
        return items, nil
×
297
}
298

299
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
300
DELETE FROM graph_zombie_channels
301
WHERE scid = $1
302
AND version = $2
303
`
304

305
type DeleteZombieChannelParams struct {
306
        Scid    []byte
307
        Version int16
308
}
309

310
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
311
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
312
}
×
313

314
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
315
SELECT
316
    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,
317
    n1.pub_key AS node1_pub_key,
318
    n2.pub_key AS node2_pub_key
319
FROM graph_channels c
320
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
321
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
322
WHERE c.scid = $1
323
  AND c.version = $2
324
`
325

326
type GetChannelAndNodesBySCIDParams struct {
327
        Scid    []byte
328
        Version int16
329
}
330

331
type GetChannelAndNodesBySCIDRow struct {
332
        ID                int64
333
        Version           int16
334
        Scid              []byte
335
        NodeID1           int64
336
        NodeID2           int64
337
        Outpoint          string
338
        Capacity          sql.NullInt64
339
        BitcoinKey1       []byte
340
        BitcoinKey2       []byte
341
        Node1Signature    []byte
342
        Node2Signature    []byte
343
        Bitcoin1Signature []byte
344
        Bitcoin2Signature []byte
345
        Node1PubKey       []byte
346
        Node2PubKey       []byte
347
}
348

349
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
350
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
351
        var i GetChannelAndNodesBySCIDRow
×
352
        err := row.Scan(
×
353
                &i.ID,
×
354
                &i.Version,
×
355
                &i.Scid,
×
356
                &i.NodeID1,
×
357
                &i.NodeID2,
×
358
                &i.Outpoint,
×
359
                &i.Capacity,
×
360
                &i.BitcoinKey1,
×
361
                &i.BitcoinKey2,
×
362
                &i.Node1Signature,
×
363
                &i.Node2Signature,
×
364
                &i.Bitcoin1Signature,
×
365
                &i.Bitcoin2Signature,
×
366
                &i.Node1PubKey,
×
367
                &i.Node2PubKey,
×
368
        )
×
369
        return i, err
×
370
}
×
371

372
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
373
SELECT
374
    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,
375

376
    n1.pub_key AS node1_pubkey,
377
    n2.pub_key AS node2_pubkey,
378

379
    -- Node 1 policy
380
    cp1.id AS policy_1_id,
381
    cp1.node_id AS policy_1_node_id,
382
    cp1.version AS policy_1_version,
383
    cp1.timelock AS policy_1_timelock,
384
    cp1.fee_ppm AS policy_1_fee_ppm,
385
    cp1.base_fee_msat AS policy_1_base_fee_msat,
386
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
387
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
388
    cp1.last_update AS policy_1_last_update,
389
    cp1.disabled AS policy_1_disabled,
390
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
391
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
392
    cp1.message_flags AS policy_1_message_flags,
393
    cp1.channel_flags AS policy_1_channel_flags,
394
    cp1.signature AS policy_1_signature,
395

396
    -- Node 2 policy
397
    cp2.id AS policy_2_id,
398
    cp2.node_id AS policy_2_node_id,
399
    cp2.version AS policy_2_version,
400
    cp2.timelock AS policy_2_timelock,
401
    cp2.fee_ppm AS policy_2_fee_ppm,
402
    cp2.base_fee_msat AS policy_2_base_fee_msat,
403
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
404
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
405
    cp2.last_update AS policy_2_last_update,
406
    cp2.disabled AS policy_2_disabled,
407
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
408
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
409
    cp2.message_flags AS policy_2_message_flags,
410
    cp2.channel_flags AS policy_2_channel_flags,
411
    cp2.signature AS policy_2_signature
412
FROM graph_channels c
413
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
414
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
415
    LEFT JOIN graph_channel_policies cp1
416
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
417
    LEFT JOIN graph_channel_policies cp2
418
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
419
WHERE c.outpoint = $1 AND c.version = $2
420
`
421

422
type GetChannelByOutpointWithPoliciesParams struct {
423
        Outpoint string
424
        Version  int16
425
}
426

427
type GetChannelByOutpointWithPoliciesRow struct {
428
        GraphChannel                   GraphChannel
429
        Node1Pubkey                    []byte
430
        Node2Pubkey                    []byte
431
        Policy1ID                      sql.NullInt64
432
        Policy1NodeID                  sql.NullInt64
433
        Policy1Version                 sql.NullInt16
434
        Policy1Timelock                sql.NullInt32
435
        Policy1FeePpm                  sql.NullInt64
436
        Policy1BaseFeeMsat             sql.NullInt64
437
        Policy1MinHtlcMsat             sql.NullInt64
438
        Policy1MaxHtlcMsat             sql.NullInt64
439
        Policy1LastUpdate              sql.NullInt64
440
        Policy1Disabled                sql.NullBool
441
        Policy1InboundBaseFeeMsat      sql.NullInt64
442
        Policy1InboundFeeRateMilliMsat sql.NullInt64
443
        Policy1MessageFlags            sql.NullInt16
444
        Policy1ChannelFlags            sql.NullInt16
445
        Policy1Signature               []byte
446
        Policy2ID                      sql.NullInt64
447
        Policy2NodeID                  sql.NullInt64
448
        Policy2Version                 sql.NullInt16
449
        Policy2Timelock                sql.NullInt32
450
        Policy2FeePpm                  sql.NullInt64
451
        Policy2BaseFeeMsat             sql.NullInt64
452
        Policy2MinHtlcMsat             sql.NullInt64
453
        Policy2MaxHtlcMsat             sql.NullInt64
454
        Policy2LastUpdate              sql.NullInt64
455
        Policy2Disabled                sql.NullBool
456
        Policy2InboundBaseFeeMsat      sql.NullInt64
457
        Policy2InboundFeeRateMilliMsat sql.NullInt64
458
        Policy2MessageFlags            sql.NullInt16
459
        Policy2ChannelFlags            sql.NullInt16
460
        Policy2Signature               []byte
461
}
462

463
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
464
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
465
        var i GetChannelByOutpointWithPoliciesRow
×
466
        err := row.Scan(
×
467
                &i.GraphChannel.ID,
×
468
                &i.GraphChannel.Version,
×
469
                &i.GraphChannel.Scid,
×
470
                &i.GraphChannel.NodeID1,
×
471
                &i.GraphChannel.NodeID2,
×
472
                &i.GraphChannel.Outpoint,
×
473
                &i.GraphChannel.Capacity,
×
474
                &i.GraphChannel.BitcoinKey1,
×
475
                &i.GraphChannel.BitcoinKey2,
×
476
                &i.GraphChannel.Node1Signature,
×
477
                &i.GraphChannel.Node2Signature,
×
478
                &i.GraphChannel.Bitcoin1Signature,
×
479
                &i.GraphChannel.Bitcoin2Signature,
×
480
                &i.Node1Pubkey,
×
481
                &i.Node2Pubkey,
×
482
                &i.Policy1ID,
×
483
                &i.Policy1NodeID,
×
484
                &i.Policy1Version,
×
485
                &i.Policy1Timelock,
×
486
                &i.Policy1FeePpm,
×
487
                &i.Policy1BaseFeeMsat,
×
488
                &i.Policy1MinHtlcMsat,
×
489
                &i.Policy1MaxHtlcMsat,
×
490
                &i.Policy1LastUpdate,
×
491
                &i.Policy1Disabled,
×
492
                &i.Policy1InboundBaseFeeMsat,
×
493
                &i.Policy1InboundFeeRateMilliMsat,
×
494
                &i.Policy1MessageFlags,
×
495
                &i.Policy1ChannelFlags,
×
496
                &i.Policy1Signature,
×
497
                &i.Policy2ID,
×
498
                &i.Policy2NodeID,
×
499
                &i.Policy2Version,
×
500
                &i.Policy2Timelock,
×
501
                &i.Policy2FeePpm,
×
502
                &i.Policy2BaseFeeMsat,
×
503
                &i.Policy2MinHtlcMsat,
×
504
                &i.Policy2MaxHtlcMsat,
×
505
                &i.Policy2LastUpdate,
×
506
                &i.Policy2Disabled,
×
507
                &i.Policy2InboundBaseFeeMsat,
×
508
                &i.Policy2InboundFeeRateMilliMsat,
×
509
                &i.Policy2MessageFlags,
×
510
                &i.Policy2ChannelFlags,
×
511
                &i.Policy2Signature,
×
512
        )
×
513
        return i, err
×
514
}
×
515

516
const getChannelBySCID = `-- name: GetChannelBySCID :one
517
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 graph_channels
518
WHERE scid = $1 AND version = $2
519
`
520

521
type GetChannelBySCIDParams struct {
522
        Scid    []byte
523
        Version int16
524
}
525

526
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GraphChannel, error) {
×
527
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
528
        var i GraphChannel
×
529
        err := row.Scan(
×
530
                &i.ID,
×
531
                &i.Version,
×
532
                &i.Scid,
×
533
                &i.NodeID1,
×
534
                &i.NodeID2,
×
535
                &i.Outpoint,
×
536
                &i.Capacity,
×
537
                &i.BitcoinKey1,
×
538
                &i.BitcoinKey2,
×
539
                &i.Node1Signature,
×
540
                &i.Node2Signature,
×
541
                &i.Bitcoin1Signature,
×
542
                &i.Bitcoin2Signature,
×
543
        )
×
544
        return i, err
×
545
}
×
546

547
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
548
SELECT
549
    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,
550
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
551
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
552

553
    -- Policy 1
554
    cp1.id AS policy1_id,
555
    cp1.node_id AS policy1_node_id,
556
    cp1.version AS policy1_version,
557
    cp1.timelock AS policy1_timelock,
558
    cp1.fee_ppm AS policy1_fee_ppm,
559
    cp1.base_fee_msat AS policy1_base_fee_msat,
560
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
561
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
562
    cp1.last_update AS policy1_last_update,
563
    cp1.disabled AS policy1_disabled,
564
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
565
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
566
    cp1.message_flags AS policy1_message_flags,
567
    cp1.channel_flags AS policy1_channel_flags,
568
    cp1.signature AS policy1_signature,
569

570
    -- Policy 2
571
    cp2.id AS policy2_id,
572
    cp2.node_id AS policy2_node_id,
573
    cp2.version AS policy2_version,
574
    cp2.timelock AS policy2_timelock,
575
    cp2.fee_ppm AS policy2_fee_ppm,
576
    cp2.base_fee_msat AS policy2_base_fee_msat,
577
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
578
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
579
    cp2.last_update AS policy2_last_update,
580
    cp2.disabled AS policy2_disabled,
581
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
582
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
583
    cp2.message_flags AS policy_2_message_flags,
584
    cp2.channel_flags AS policy_2_channel_flags,
585
    cp2.signature AS policy2_signature
586

587
FROM graph_channels c
588
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
589
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
590
    LEFT JOIN graph_channel_policies cp1
591
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
592
    LEFT JOIN graph_channel_policies cp2
593
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
594
WHERE c.scid = $1
595
  AND c.version = $2
596
`
597

598
type GetChannelBySCIDWithPoliciesParams struct {
599
        Scid    []byte
600
        Version int16
601
}
602

603
type GetChannelBySCIDWithPoliciesRow struct {
604
        GraphChannel                   GraphChannel
605
        GraphNode                      GraphNode
606
        GraphNode_2                    GraphNode
607
        Policy1ID                      sql.NullInt64
608
        Policy1NodeID                  sql.NullInt64
609
        Policy1Version                 sql.NullInt16
610
        Policy1Timelock                sql.NullInt32
611
        Policy1FeePpm                  sql.NullInt64
612
        Policy1BaseFeeMsat             sql.NullInt64
613
        Policy1MinHtlcMsat             sql.NullInt64
614
        Policy1MaxHtlcMsat             sql.NullInt64
615
        Policy1LastUpdate              sql.NullInt64
616
        Policy1Disabled                sql.NullBool
617
        Policy1InboundBaseFeeMsat      sql.NullInt64
618
        Policy1InboundFeeRateMilliMsat sql.NullInt64
619
        Policy1MessageFlags            sql.NullInt16
620
        Policy1ChannelFlags            sql.NullInt16
621
        Policy1Signature               []byte
622
        Policy2ID                      sql.NullInt64
623
        Policy2NodeID                  sql.NullInt64
624
        Policy2Version                 sql.NullInt16
625
        Policy2Timelock                sql.NullInt32
626
        Policy2FeePpm                  sql.NullInt64
627
        Policy2BaseFeeMsat             sql.NullInt64
628
        Policy2MinHtlcMsat             sql.NullInt64
629
        Policy2MaxHtlcMsat             sql.NullInt64
630
        Policy2LastUpdate              sql.NullInt64
631
        Policy2Disabled                sql.NullBool
632
        Policy2InboundBaseFeeMsat      sql.NullInt64
633
        Policy2InboundFeeRateMilliMsat sql.NullInt64
634
        Policy2MessageFlags            sql.NullInt16
635
        Policy2ChannelFlags            sql.NullInt16
636
        Policy2Signature               []byte
637
}
638

639
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
640
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
641
        var i GetChannelBySCIDWithPoliciesRow
×
642
        err := row.Scan(
×
643
                &i.GraphChannel.ID,
×
644
                &i.GraphChannel.Version,
×
645
                &i.GraphChannel.Scid,
×
646
                &i.GraphChannel.NodeID1,
×
647
                &i.GraphChannel.NodeID2,
×
648
                &i.GraphChannel.Outpoint,
×
649
                &i.GraphChannel.Capacity,
×
650
                &i.GraphChannel.BitcoinKey1,
×
651
                &i.GraphChannel.BitcoinKey2,
×
652
                &i.GraphChannel.Node1Signature,
×
653
                &i.GraphChannel.Node2Signature,
×
654
                &i.GraphChannel.Bitcoin1Signature,
×
655
                &i.GraphChannel.Bitcoin2Signature,
×
656
                &i.GraphNode.ID,
×
657
                &i.GraphNode.Version,
×
658
                &i.GraphNode.PubKey,
×
659
                &i.GraphNode.Alias,
×
660
                &i.GraphNode.LastUpdate,
×
661
                &i.GraphNode.Color,
×
662
                &i.GraphNode.Signature,
×
663
                &i.GraphNode_2.ID,
×
664
                &i.GraphNode_2.Version,
×
665
                &i.GraphNode_2.PubKey,
×
666
                &i.GraphNode_2.Alias,
×
667
                &i.GraphNode_2.LastUpdate,
×
668
                &i.GraphNode_2.Color,
×
669
                &i.GraphNode_2.Signature,
×
670
                &i.Policy1ID,
×
671
                &i.Policy1NodeID,
×
672
                &i.Policy1Version,
×
673
                &i.Policy1Timelock,
×
674
                &i.Policy1FeePpm,
×
675
                &i.Policy1BaseFeeMsat,
×
676
                &i.Policy1MinHtlcMsat,
×
677
                &i.Policy1MaxHtlcMsat,
×
678
                &i.Policy1LastUpdate,
×
679
                &i.Policy1Disabled,
×
680
                &i.Policy1InboundBaseFeeMsat,
×
681
                &i.Policy1InboundFeeRateMilliMsat,
×
682
                &i.Policy1MessageFlags,
×
683
                &i.Policy1ChannelFlags,
×
684
                &i.Policy1Signature,
×
685
                &i.Policy2ID,
×
686
                &i.Policy2NodeID,
×
687
                &i.Policy2Version,
×
688
                &i.Policy2Timelock,
×
689
                &i.Policy2FeePpm,
×
690
                &i.Policy2BaseFeeMsat,
×
691
                &i.Policy2MinHtlcMsat,
×
692
                &i.Policy2MaxHtlcMsat,
×
693
                &i.Policy2LastUpdate,
×
694
                &i.Policy2Disabled,
×
695
                &i.Policy2InboundBaseFeeMsat,
×
696
                &i.Policy2InboundFeeRateMilliMsat,
×
697
                &i.Policy2MessageFlags,
×
698
                &i.Policy2ChannelFlags,
×
699
                &i.Policy2Signature,
×
700
        )
×
701
        return i, err
×
702
}
×
703

704
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
705
SELECT
706
    cf.channel_id,
707
    true AS is_feature,
708
    cf.feature_bit AS feature_bit,
709
    NULL AS extra_key,
710
    NULL AS value
711
FROM graph_channel_features cf
712
WHERE cf.channel_id = $1
713

714
UNION ALL
715

716
SELECT
717
    cet.channel_id,
718
    false AS is_feature,
719
    0 AS feature_bit,
720
    cet.type AS extra_key,
721
    cet.value AS value
722
FROM graph_channel_extra_types cet
723
WHERE cet.channel_id = $1
724
`
725

726
type GetChannelFeaturesAndExtrasRow struct {
727
        ChannelID  int64
728
        IsFeature  bool
729
        FeatureBit int32
730
        ExtraKey   interface{}
731
        Value      interface{}
732
}
733

734
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
735
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
736
        if err != nil {
×
737
                return nil, err
×
738
        }
×
739
        defer rows.Close()
×
740
        var items []GetChannelFeaturesAndExtrasRow
×
741
        for rows.Next() {
×
742
                var i GetChannelFeaturesAndExtrasRow
×
743
                if err := rows.Scan(
×
744
                        &i.ChannelID,
×
745
                        &i.IsFeature,
×
746
                        &i.FeatureBit,
×
747
                        &i.ExtraKey,
×
748
                        &i.Value,
×
749
                ); err != nil {
×
750
                        return nil, err
×
751
                }
×
752
                items = append(items, i)
×
753
        }
754
        if err := rows.Close(); err != nil {
×
755
                return nil, err
×
756
        }
×
757
        if err := rows.Err(); err != nil {
×
758
                return nil, err
×
759
        }
×
760
        return items, nil
×
761
}
762

763
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
764
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, message_flags, channel_flags, signature
765
FROM graph_channel_policies
766
WHERE channel_id = $1
767
  AND node_id = $2
768
  AND version = $3
769
`
770

771
type GetChannelPolicyByChannelAndNodeParams struct {
772
        ChannelID int64
773
        NodeID    int64
774
        Version   int16
775
}
776

777
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (GraphChannelPolicy, error) {
×
778
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
779
        var i GraphChannelPolicy
×
780
        err := row.Scan(
×
781
                &i.ID,
×
782
                &i.Version,
×
783
                &i.ChannelID,
×
784
                &i.NodeID,
×
785
                &i.Timelock,
×
786
                &i.FeePpm,
×
787
                &i.BaseFeeMsat,
×
788
                &i.MinHtlcMsat,
×
789
                &i.MaxHtlcMsat,
×
790
                &i.LastUpdate,
×
791
                &i.Disabled,
×
792
                &i.InboundBaseFeeMsat,
×
793
                &i.InboundFeeRateMilliMsat,
×
794
                &i.MessageFlags,
×
795
                &i.ChannelFlags,
×
796
                &i.Signature,
×
797
        )
×
798
        return i, err
×
799
}
×
800

801
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
802
SELECT
803
    cp.id AS policy_id,
804
    cp.channel_id,
805
    cp.node_id,
806
    cpet.type,
807
    cpet.value
808
FROM graph_channel_policies cp
809
JOIN graph_channel_policy_extra_types cpet
810
ON cp.id = cpet.channel_policy_id
811
WHERE cp.id = $1 OR cp.id = $2
812
`
813

814
type GetChannelPolicyExtraTypesParams struct {
815
        ID   int64
816
        ID_2 int64
817
}
818

819
type GetChannelPolicyExtraTypesRow struct {
820
        PolicyID  int64
821
        ChannelID int64
822
        NodeID    int64
823
        Type      int64
824
        Value     []byte
825
}
826

827
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
828
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
829
        if err != nil {
×
830
                return nil, err
×
831
        }
×
832
        defer rows.Close()
×
833
        var items []GetChannelPolicyExtraTypesRow
×
834
        for rows.Next() {
×
835
                var i GetChannelPolicyExtraTypesRow
×
836
                if err := rows.Scan(
×
837
                        &i.PolicyID,
×
838
                        &i.ChannelID,
×
839
                        &i.NodeID,
×
840
                        &i.Type,
×
841
                        &i.Value,
×
842
                ); err != nil {
×
843
                        return nil, err
×
844
                }
×
845
                items = append(items, i)
×
846
        }
847
        if err := rows.Close(); err != nil {
×
848
                return nil, err
×
849
        }
×
850
        if err := rows.Err(); err != nil {
×
851
                return nil, err
×
852
        }
×
853
        return items, nil
×
854
}
855

856
const getChannelsByOutpoints = `-- name: GetChannelsByOutpoints :many
857
SELECT
858
    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,
859
    n1.pub_key AS node1_pubkey,
860
    n2.pub_key AS node2_pubkey
861
FROM graph_channels c
862
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
863
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
864
WHERE c.outpoint IN
865
    (/*SLICE:outpoints*/?)
866
`
867

868
type GetChannelsByOutpointsRow struct {
869
        GraphChannel GraphChannel
870
        Node1Pubkey  []byte
871
        Node2Pubkey  []byte
872
}
873

NEW
874
func (q *Queries) GetChannelsByOutpoints(ctx context.Context, outpoints []string) ([]GetChannelsByOutpointsRow, error) {
×
NEW
875
        query := getChannelsByOutpoints
×
NEW
876
        var queryParams []interface{}
×
NEW
877
        if len(outpoints) > 0 {
×
NEW
878
                for _, v := range outpoints {
×
NEW
879
                        queryParams = append(queryParams, v)
×
NEW
880
                }
×
NEW
881
                query = strings.Replace(query, "/*SLICE:outpoints*/?", makeQueryParams(len(queryParams), len(outpoints)), 1)
×
NEW
882
        } else {
×
NEW
883
                query = strings.Replace(query, "/*SLICE:outpoints*/?", "NULL", 1)
×
NEW
884
        }
×
NEW
885
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
886
        if err != nil {
×
NEW
887
                return nil, err
×
NEW
888
        }
×
NEW
889
        defer rows.Close()
×
NEW
890
        var items []GetChannelsByOutpointsRow
×
NEW
891
        for rows.Next() {
×
NEW
892
                var i GetChannelsByOutpointsRow
×
NEW
893
                if err := rows.Scan(
×
NEW
894
                        &i.GraphChannel.ID,
×
NEW
895
                        &i.GraphChannel.Version,
×
NEW
896
                        &i.GraphChannel.Scid,
×
NEW
897
                        &i.GraphChannel.NodeID1,
×
NEW
898
                        &i.GraphChannel.NodeID2,
×
NEW
899
                        &i.GraphChannel.Outpoint,
×
NEW
900
                        &i.GraphChannel.Capacity,
×
NEW
901
                        &i.GraphChannel.BitcoinKey1,
×
NEW
902
                        &i.GraphChannel.BitcoinKey2,
×
NEW
903
                        &i.GraphChannel.Node1Signature,
×
NEW
904
                        &i.GraphChannel.Node2Signature,
×
NEW
905
                        &i.GraphChannel.Bitcoin1Signature,
×
NEW
906
                        &i.GraphChannel.Bitcoin2Signature,
×
NEW
907
                        &i.Node1Pubkey,
×
NEW
908
                        &i.Node2Pubkey,
×
NEW
909
                ); err != nil {
×
NEW
910
                        return nil, err
×
NEW
911
                }
×
NEW
912
                items = append(items, i)
×
913
        }
NEW
914
        if err := rows.Close(); err != nil {
×
NEW
915
                return nil, err
×
NEW
916
        }
×
NEW
917
        if err := rows.Err(); err != nil {
×
NEW
918
                return nil, err
×
NEW
919
        }
×
NEW
920
        return items, nil
×
921
}
922

923
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
924
SELECT
925
    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,
926
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
927
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
928

929
    -- Policy 1 (node_id_1)
930
    cp1.id AS policy1_id,
931
    cp1.node_id AS policy1_node_id,
932
    cp1.version AS policy1_version,
933
    cp1.timelock AS policy1_timelock,
934
    cp1.fee_ppm AS policy1_fee_ppm,
935
    cp1.base_fee_msat AS policy1_base_fee_msat,
936
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
937
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
938
    cp1.last_update AS policy1_last_update,
939
    cp1.disabled AS policy1_disabled,
940
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
941
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
942
    cp1.message_flags AS policy1_message_flags,
943
    cp1.channel_flags AS policy1_channel_flags,
944
    cp1.signature AS policy1_signature,
945

946
    -- Policy 2 (node_id_2)
947
    cp2.id AS policy2_id,
948
    cp2.node_id AS policy2_node_id,
949
    cp2.version AS policy2_version,
950
    cp2.timelock AS policy2_timelock,
951
    cp2.fee_ppm AS policy2_fee_ppm,
952
    cp2.base_fee_msat AS policy2_base_fee_msat,
953
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
954
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
955
    cp2.last_update AS policy2_last_update,
956
    cp2.disabled AS policy2_disabled,
957
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
958
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
959
    cp2.message_flags AS policy2_message_flags,
960
    cp2.channel_flags AS policy2_channel_flags,
961
    cp2.signature AS policy2_signature
962

963
FROM graph_channels c
964
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
965
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
966
    LEFT JOIN graph_channel_policies cp1
967
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
968
    LEFT JOIN graph_channel_policies cp2
969
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
970
WHERE c.version = $1
971
  AND (
972
       (cp1.last_update >= $2 AND cp1.last_update < $3)
973
       OR
974
       (cp2.last_update >= $2 AND cp2.last_update < $3)
975
  )
976
ORDER BY
977
    CASE
978
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
979
            THEN COALESCE(cp1.last_update, 0)
980
        ELSE COALESCE(cp2.last_update, 0)
981
        END ASC
982
`
983

984
type GetChannelsByPolicyLastUpdateRangeParams struct {
985
        Version   int16
986
        StartTime sql.NullInt64
987
        EndTime   sql.NullInt64
988
}
989

990
type GetChannelsByPolicyLastUpdateRangeRow struct {
991
        GraphChannel                   GraphChannel
992
        GraphNode                      GraphNode
993
        GraphNode_2                    GraphNode
994
        Policy1ID                      sql.NullInt64
995
        Policy1NodeID                  sql.NullInt64
996
        Policy1Version                 sql.NullInt16
997
        Policy1Timelock                sql.NullInt32
998
        Policy1FeePpm                  sql.NullInt64
999
        Policy1BaseFeeMsat             sql.NullInt64
1000
        Policy1MinHtlcMsat             sql.NullInt64
1001
        Policy1MaxHtlcMsat             sql.NullInt64
1002
        Policy1LastUpdate              sql.NullInt64
1003
        Policy1Disabled                sql.NullBool
1004
        Policy1InboundBaseFeeMsat      sql.NullInt64
1005
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1006
        Policy1MessageFlags            sql.NullInt16
1007
        Policy1ChannelFlags            sql.NullInt16
1008
        Policy1Signature               []byte
1009
        Policy2ID                      sql.NullInt64
1010
        Policy2NodeID                  sql.NullInt64
1011
        Policy2Version                 sql.NullInt16
1012
        Policy2Timelock                sql.NullInt32
1013
        Policy2FeePpm                  sql.NullInt64
1014
        Policy2BaseFeeMsat             sql.NullInt64
1015
        Policy2MinHtlcMsat             sql.NullInt64
1016
        Policy2MaxHtlcMsat             sql.NullInt64
1017
        Policy2LastUpdate              sql.NullInt64
1018
        Policy2Disabled                sql.NullBool
1019
        Policy2InboundBaseFeeMsat      sql.NullInt64
1020
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1021
        Policy2MessageFlags            sql.NullInt16
1022
        Policy2ChannelFlags            sql.NullInt16
1023
        Policy2Signature               []byte
1024
}
1025

1026
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
1027
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
1028
        if err != nil {
×
1029
                return nil, err
×
1030
        }
×
1031
        defer rows.Close()
×
1032
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
1033
        for rows.Next() {
×
1034
                var i GetChannelsByPolicyLastUpdateRangeRow
×
1035
                if err := rows.Scan(
×
1036
                        &i.GraphChannel.ID,
×
1037
                        &i.GraphChannel.Version,
×
1038
                        &i.GraphChannel.Scid,
×
1039
                        &i.GraphChannel.NodeID1,
×
1040
                        &i.GraphChannel.NodeID2,
×
1041
                        &i.GraphChannel.Outpoint,
×
1042
                        &i.GraphChannel.Capacity,
×
1043
                        &i.GraphChannel.BitcoinKey1,
×
1044
                        &i.GraphChannel.BitcoinKey2,
×
1045
                        &i.GraphChannel.Node1Signature,
×
1046
                        &i.GraphChannel.Node2Signature,
×
1047
                        &i.GraphChannel.Bitcoin1Signature,
×
1048
                        &i.GraphChannel.Bitcoin2Signature,
×
1049
                        &i.GraphNode.ID,
×
1050
                        &i.GraphNode.Version,
×
1051
                        &i.GraphNode.PubKey,
×
1052
                        &i.GraphNode.Alias,
×
1053
                        &i.GraphNode.LastUpdate,
×
1054
                        &i.GraphNode.Color,
×
1055
                        &i.GraphNode.Signature,
×
1056
                        &i.GraphNode_2.ID,
×
1057
                        &i.GraphNode_2.Version,
×
1058
                        &i.GraphNode_2.PubKey,
×
1059
                        &i.GraphNode_2.Alias,
×
1060
                        &i.GraphNode_2.LastUpdate,
×
1061
                        &i.GraphNode_2.Color,
×
1062
                        &i.GraphNode_2.Signature,
×
1063
                        &i.Policy1ID,
×
1064
                        &i.Policy1NodeID,
×
1065
                        &i.Policy1Version,
×
1066
                        &i.Policy1Timelock,
×
1067
                        &i.Policy1FeePpm,
×
1068
                        &i.Policy1BaseFeeMsat,
×
1069
                        &i.Policy1MinHtlcMsat,
×
1070
                        &i.Policy1MaxHtlcMsat,
×
1071
                        &i.Policy1LastUpdate,
×
1072
                        &i.Policy1Disabled,
×
1073
                        &i.Policy1InboundBaseFeeMsat,
×
1074
                        &i.Policy1InboundFeeRateMilliMsat,
×
1075
                        &i.Policy1MessageFlags,
×
1076
                        &i.Policy1ChannelFlags,
×
1077
                        &i.Policy1Signature,
×
1078
                        &i.Policy2ID,
×
1079
                        &i.Policy2NodeID,
×
1080
                        &i.Policy2Version,
×
1081
                        &i.Policy2Timelock,
×
1082
                        &i.Policy2FeePpm,
×
1083
                        &i.Policy2BaseFeeMsat,
×
1084
                        &i.Policy2MinHtlcMsat,
×
1085
                        &i.Policy2MaxHtlcMsat,
×
1086
                        &i.Policy2LastUpdate,
×
1087
                        &i.Policy2Disabled,
×
1088
                        &i.Policy2InboundBaseFeeMsat,
×
1089
                        &i.Policy2InboundFeeRateMilliMsat,
×
1090
                        &i.Policy2MessageFlags,
×
1091
                        &i.Policy2ChannelFlags,
×
1092
                        &i.Policy2Signature,
×
1093
                ); err != nil {
×
1094
                        return nil, err
×
1095
                }
×
1096
                items = append(items, i)
×
1097
        }
1098
        if err := rows.Close(); err != nil {
×
1099
                return nil, err
×
1100
        }
×
1101
        if err := rows.Err(); err != nil {
×
1102
                return nil, err
×
1103
        }
×
1104
        return items, nil
×
1105
}
1106

1107
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1108
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,
1109
    n1.pub_key AS node1_pub_key,
1110
    n2.pub_key AS node2_pub_key
1111
FROM graph_channels c
1112
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1113
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1114
WHERE scid >= $1
1115
  AND scid < $2
1116
`
1117

1118
type GetChannelsBySCIDRangeParams struct {
1119
        StartScid []byte
1120
        EndScid   []byte
1121
}
1122

1123
type GetChannelsBySCIDRangeRow struct {
1124
        GraphChannel GraphChannel
1125
        Node1PubKey  []byte
1126
        Node2PubKey  []byte
1127
}
1128

1129
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1130
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1131
        if err != nil {
×
1132
                return nil, err
×
1133
        }
×
1134
        defer rows.Close()
×
1135
        var items []GetChannelsBySCIDRangeRow
×
1136
        for rows.Next() {
×
1137
                var i GetChannelsBySCIDRangeRow
×
1138
                if err := rows.Scan(
×
1139
                        &i.GraphChannel.ID,
×
1140
                        &i.GraphChannel.Version,
×
1141
                        &i.GraphChannel.Scid,
×
1142
                        &i.GraphChannel.NodeID1,
×
1143
                        &i.GraphChannel.NodeID2,
×
1144
                        &i.GraphChannel.Outpoint,
×
1145
                        &i.GraphChannel.Capacity,
×
1146
                        &i.GraphChannel.BitcoinKey1,
×
1147
                        &i.GraphChannel.BitcoinKey2,
×
1148
                        &i.GraphChannel.Node1Signature,
×
1149
                        &i.GraphChannel.Node2Signature,
×
1150
                        &i.GraphChannel.Bitcoin1Signature,
×
1151
                        &i.GraphChannel.Bitcoin2Signature,
×
1152
                        &i.Node1PubKey,
×
1153
                        &i.Node2PubKey,
×
1154
                ); err != nil {
×
1155
                        return nil, err
×
1156
                }
×
1157
                items = append(items, i)
×
1158
        }
1159
        if err := rows.Close(); err != nil {
×
1160
                return nil, err
×
1161
        }
×
1162
        if err := rows.Err(); err != nil {
×
1163
                return nil, err
×
1164
        }
×
1165
        return items, nil
×
1166
}
1167

1168
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1169
SELECT
1170
    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,
1171
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1172
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1173

1174
    -- Policy 1
1175
    cp1.id AS policy1_id,
1176
    cp1.node_id AS policy1_node_id,
1177
    cp1.version AS policy1_version,
1178
    cp1.timelock AS policy1_timelock,
1179
    cp1.fee_ppm AS policy1_fee_ppm,
1180
    cp1.base_fee_msat AS policy1_base_fee_msat,
1181
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1182
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1183
    cp1.last_update AS policy1_last_update,
1184
    cp1.disabled AS policy1_disabled,
1185
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1186
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1187
    cp1.message_flags AS policy1_message_flags,
1188
    cp1.channel_flags AS policy1_channel_flags,
1189
    cp1.signature AS policy1_signature,
1190

1191
    -- Policy 2
1192
    cp2.id AS policy2_id,
1193
    cp2.node_id AS policy2_node_id,
1194
    cp2.version AS policy2_version,
1195
    cp2.timelock AS policy2_timelock,
1196
    cp2.fee_ppm AS policy2_fee_ppm,
1197
    cp2.base_fee_msat AS policy2_base_fee_msat,
1198
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1199
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1200
    cp2.last_update AS policy2_last_update,
1201
    cp2.disabled AS policy2_disabled,
1202
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1203
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1204
    cp2.message_flags AS policy_2_message_flags,
1205
    cp2.channel_flags AS policy_2_channel_flags,
1206
    cp2.signature AS policy2_signature
1207

1208
FROM graph_channels c
1209
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1210
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1211
    LEFT JOIN graph_channel_policies cp1
1212
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1213
    LEFT JOIN graph_channel_policies cp2
1214
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1215
WHERE
1216
    c.version = $1
1217
  AND c.scid IN (/*SLICE:scids*/?)
1218
`
1219

1220
type GetChannelsBySCIDWithPoliciesParams struct {
1221
        Version int16
1222
        Scids   [][]byte
1223
}
1224

1225
type GetChannelsBySCIDWithPoliciesRow struct {
1226
        GraphChannel                   GraphChannel
1227
        GraphNode                      GraphNode
1228
        GraphNode_2                    GraphNode
1229
        Policy1ID                      sql.NullInt64
1230
        Policy1NodeID                  sql.NullInt64
1231
        Policy1Version                 sql.NullInt16
1232
        Policy1Timelock                sql.NullInt32
1233
        Policy1FeePpm                  sql.NullInt64
1234
        Policy1BaseFeeMsat             sql.NullInt64
1235
        Policy1MinHtlcMsat             sql.NullInt64
1236
        Policy1MaxHtlcMsat             sql.NullInt64
1237
        Policy1LastUpdate              sql.NullInt64
1238
        Policy1Disabled                sql.NullBool
1239
        Policy1InboundBaseFeeMsat      sql.NullInt64
1240
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1241
        Policy1MessageFlags            sql.NullInt16
1242
        Policy1ChannelFlags            sql.NullInt16
1243
        Policy1Signature               []byte
1244
        Policy2ID                      sql.NullInt64
1245
        Policy2NodeID                  sql.NullInt64
1246
        Policy2Version                 sql.NullInt16
1247
        Policy2Timelock                sql.NullInt32
1248
        Policy2FeePpm                  sql.NullInt64
1249
        Policy2BaseFeeMsat             sql.NullInt64
1250
        Policy2MinHtlcMsat             sql.NullInt64
1251
        Policy2MaxHtlcMsat             sql.NullInt64
1252
        Policy2LastUpdate              sql.NullInt64
1253
        Policy2Disabled                sql.NullBool
1254
        Policy2InboundBaseFeeMsat      sql.NullInt64
1255
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1256
        Policy2MessageFlags            sql.NullInt16
1257
        Policy2ChannelFlags            sql.NullInt16
1258
        Policy2Signature               []byte
1259
}
1260

NEW
1261
func (q *Queries) GetChannelsBySCIDWithPolicies(ctx context.Context, arg GetChannelsBySCIDWithPoliciesParams) ([]GetChannelsBySCIDWithPoliciesRow, error) {
×
NEW
1262
        query := getChannelsBySCIDWithPolicies
×
NEW
1263
        var queryParams []interface{}
×
NEW
1264
        queryParams = append(queryParams, arg.Version)
×
NEW
1265
        if len(arg.Scids) > 0 {
×
NEW
1266
                for _, v := range arg.Scids {
×
NEW
1267
                        queryParams = append(queryParams, v)
×
NEW
1268
                }
×
NEW
1269
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
NEW
1270
        } else {
×
NEW
1271
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
NEW
1272
        }
×
NEW
1273
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
1274
        if err != nil {
×
NEW
1275
                return nil, err
×
NEW
1276
        }
×
NEW
1277
        defer rows.Close()
×
NEW
1278
        var items []GetChannelsBySCIDWithPoliciesRow
×
NEW
1279
        for rows.Next() {
×
NEW
1280
                var i GetChannelsBySCIDWithPoliciesRow
×
NEW
1281
                if err := rows.Scan(
×
NEW
1282
                        &i.GraphChannel.ID,
×
NEW
1283
                        &i.GraphChannel.Version,
×
NEW
1284
                        &i.GraphChannel.Scid,
×
NEW
1285
                        &i.GraphChannel.NodeID1,
×
NEW
1286
                        &i.GraphChannel.NodeID2,
×
NEW
1287
                        &i.GraphChannel.Outpoint,
×
NEW
1288
                        &i.GraphChannel.Capacity,
×
NEW
1289
                        &i.GraphChannel.BitcoinKey1,
×
NEW
1290
                        &i.GraphChannel.BitcoinKey2,
×
NEW
1291
                        &i.GraphChannel.Node1Signature,
×
NEW
1292
                        &i.GraphChannel.Node2Signature,
×
NEW
1293
                        &i.GraphChannel.Bitcoin1Signature,
×
NEW
1294
                        &i.GraphChannel.Bitcoin2Signature,
×
NEW
1295
                        &i.GraphNode.ID,
×
NEW
1296
                        &i.GraphNode.Version,
×
NEW
1297
                        &i.GraphNode.PubKey,
×
NEW
1298
                        &i.GraphNode.Alias,
×
NEW
1299
                        &i.GraphNode.LastUpdate,
×
NEW
1300
                        &i.GraphNode.Color,
×
NEW
1301
                        &i.GraphNode.Signature,
×
NEW
1302
                        &i.GraphNode_2.ID,
×
NEW
1303
                        &i.GraphNode_2.Version,
×
NEW
1304
                        &i.GraphNode_2.PubKey,
×
NEW
1305
                        &i.GraphNode_2.Alias,
×
NEW
1306
                        &i.GraphNode_2.LastUpdate,
×
NEW
1307
                        &i.GraphNode_2.Color,
×
NEW
1308
                        &i.GraphNode_2.Signature,
×
NEW
1309
                        &i.Policy1ID,
×
NEW
1310
                        &i.Policy1NodeID,
×
NEW
1311
                        &i.Policy1Version,
×
NEW
1312
                        &i.Policy1Timelock,
×
NEW
1313
                        &i.Policy1FeePpm,
×
NEW
1314
                        &i.Policy1BaseFeeMsat,
×
NEW
1315
                        &i.Policy1MinHtlcMsat,
×
NEW
1316
                        &i.Policy1MaxHtlcMsat,
×
NEW
1317
                        &i.Policy1LastUpdate,
×
NEW
1318
                        &i.Policy1Disabled,
×
NEW
1319
                        &i.Policy1InboundBaseFeeMsat,
×
NEW
1320
                        &i.Policy1InboundFeeRateMilliMsat,
×
NEW
1321
                        &i.Policy1MessageFlags,
×
NEW
1322
                        &i.Policy1ChannelFlags,
×
NEW
1323
                        &i.Policy1Signature,
×
NEW
1324
                        &i.Policy2ID,
×
NEW
1325
                        &i.Policy2NodeID,
×
NEW
1326
                        &i.Policy2Version,
×
NEW
1327
                        &i.Policy2Timelock,
×
NEW
1328
                        &i.Policy2FeePpm,
×
NEW
1329
                        &i.Policy2BaseFeeMsat,
×
NEW
1330
                        &i.Policy2MinHtlcMsat,
×
NEW
1331
                        &i.Policy2MaxHtlcMsat,
×
NEW
1332
                        &i.Policy2LastUpdate,
×
NEW
1333
                        &i.Policy2Disabled,
×
NEW
1334
                        &i.Policy2InboundBaseFeeMsat,
×
NEW
1335
                        &i.Policy2InboundFeeRateMilliMsat,
×
NEW
1336
                        &i.Policy2MessageFlags,
×
NEW
1337
                        &i.Policy2ChannelFlags,
×
NEW
1338
                        &i.Policy2Signature,
×
NEW
1339
                ); err != nil {
×
NEW
1340
                        return nil, err
×
NEW
1341
                }
×
NEW
1342
                items = append(items, i)
×
1343
        }
NEW
1344
        if err := rows.Close(); err != nil {
×
NEW
1345
                return nil, err
×
NEW
1346
        }
×
NEW
1347
        if err := rows.Err(); err != nil {
×
NEW
1348
                return nil, err
×
NEW
1349
        }
×
NEW
1350
        return items, nil
×
1351
}
1352

1353
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1354
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 graph_channels
1355
WHERE version = $1
1356
  AND scid IN (/*SLICE:scids*/?)
1357
`
1358

1359
type GetChannelsBySCIDsParams struct {
1360
        Version int16
1361
        Scids   [][]byte
1362
}
1363

NEW
1364
func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error) {
×
NEW
1365
        query := getChannelsBySCIDs
×
NEW
1366
        var queryParams []interface{}
×
NEW
1367
        queryParams = append(queryParams, arg.Version)
×
NEW
1368
        if len(arg.Scids) > 0 {
×
NEW
1369
                for _, v := range arg.Scids {
×
NEW
1370
                        queryParams = append(queryParams, v)
×
NEW
1371
                }
×
NEW
1372
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
NEW
1373
        } else {
×
NEW
1374
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
NEW
1375
        }
×
NEW
1376
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
1377
        if err != nil {
×
NEW
1378
                return nil, err
×
NEW
1379
        }
×
NEW
1380
        defer rows.Close()
×
NEW
1381
        var items []GraphChannel
×
NEW
1382
        for rows.Next() {
×
NEW
1383
                var i GraphChannel
×
NEW
1384
                if err := rows.Scan(
×
NEW
1385
                        &i.ID,
×
NEW
1386
                        &i.Version,
×
NEW
1387
                        &i.Scid,
×
NEW
1388
                        &i.NodeID1,
×
NEW
1389
                        &i.NodeID2,
×
NEW
1390
                        &i.Outpoint,
×
NEW
1391
                        &i.Capacity,
×
NEW
1392
                        &i.BitcoinKey1,
×
NEW
1393
                        &i.BitcoinKey2,
×
NEW
1394
                        &i.Node1Signature,
×
NEW
1395
                        &i.Node2Signature,
×
NEW
1396
                        &i.Bitcoin1Signature,
×
NEW
1397
                        &i.Bitcoin2Signature,
×
NEW
1398
                ); err != nil {
×
NEW
1399
                        return nil, err
×
NEW
1400
                }
×
NEW
1401
                items = append(items, i)
×
1402
        }
NEW
1403
        if err := rows.Close(); err != nil {
×
NEW
1404
                return nil, err
×
NEW
1405
        }
×
NEW
1406
        if err := rows.Err(); err != nil {
×
NEW
1407
                return nil, err
×
NEW
1408
        }
×
NEW
1409
        return items, nil
×
1410
}
1411

1412
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1413
SELECT node_id, type, value
1414
FROM graph_node_extra_types
1415
WHERE node_id = $1
1416
`
1417

1418
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) {
×
1419
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1420
        if err != nil {
×
1421
                return nil, err
×
1422
        }
×
1423
        defer rows.Close()
×
1424
        var items []GraphNodeExtraType
×
1425
        for rows.Next() {
×
1426
                var i GraphNodeExtraType
×
1427
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1428
                        return nil, err
×
1429
                }
×
1430
                items = append(items, i)
×
1431
        }
1432
        if err := rows.Close(); err != nil {
×
1433
                return nil, err
×
1434
        }
×
1435
        if err := rows.Err(); err != nil {
×
1436
                return nil, err
×
1437
        }
×
1438
        return items, nil
×
1439
}
1440

1441
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
1442
SELECT a.type, a.address
1443
FROM graph_nodes n
1444
LEFT JOIN graph_node_addresses a ON a.node_id = n.id
1445
WHERE n.pub_key = $1 AND n.version = $2
1446
ORDER BY a.type ASC, a.position ASC
1447
`
1448

1449
type GetNodeAddressesByPubKeyParams struct {
1450
        PubKey  []byte
1451
        Version int16
1452
}
1453

1454
type GetNodeAddressesByPubKeyRow struct {
1455
        Type    sql.NullInt16
1456
        Address sql.NullString
1457
}
1458

1459
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
1460
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
1461
        if err != nil {
×
1462
                return nil, err
×
1463
        }
×
1464
        defer rows.Close()
×
1465
        var items []GetNodeAddressesByPubKeyRow
×
1466
        for rows.Next() {
×
1467
                var i GetNodeAddressesByPubKeyRow
×
1468
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1469
                        return nil, err
×
1470
                }
×
1471
                items = append(items, i)
×
1472
        }
1473
        if err := rows.Close(); err != nil {
×
1474
                return nil, err
×
1475
        }
×
1476
        if err := rows.Err(); err != nil {
×
1477
                return nil, err
×
1478
        }
×
1479
        return items, nil
×
1480
}
1481

1482
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1483
SELECT id, version, pub_key, alias, last_update, color, signature
1484
FROM graph_nodes
1485
WHERE pub_key = $1
1486
  AND version = $2
1487
`
1488

1489
type GetNodeByPubKeyParams struct {
1490
        PubKey  []byte
1491
        Version int16
1492
}
1493

1494
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1495
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1496
        var i GraphNode
×
1497
        err := row.Scan(
×
1498
                &i.ID,
×
1499
                &i.Version,
×
1500
                &i.PubKey,
×
1501
                &i.Alias,
×
1502
                &i.LastUpdate,
×
1503
                &i.Color,
×
1504
                &i.Signature,
×
1505
        )
×
1506
        return i, err
×
1507
}
×
1508

1509
const getNodeFeatures = `-- name: GetNodeFeatures :many
1510
SELECT node_id, feature_bit
1511
FROM graph_node_features
1512
WHERE node_id = $1
1513
`
1514

1515
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1516
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1517
        if err != nil {
×
1518
                return nil, err
×
1519
        }
×
1520
        defer rows.Close()
×
1521
        var items []GraphNodeFeature
×
1522
        for rows.Next() {
×
1523
                var i GraphNodeFeature
×
1524
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1525
                        return nil, err
×
1526
                }
×
1527
                items = append(items, i)
×
1528
        }
1529
        if err := rows.Close(); err != nil {
×
1530
                return nil, err
×
1531
        }
×
1532
        if err := rows.Err(); err != nil {
×
1533
                return nil, err
×
1534
        }
×
1535
        return items, nil
×
1536
}
1537

1538
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1539
SELECT f.feature_bit
1540
FROM graph_nodes n
1541
    JOIN graph_node_features f ON f.node_id = n.id
1542
WHERE n.pub_key = $1
1543
  AND n.version = $2
1544
`
1545

1546
type GetNodeFeaturesByPubKeyParams struct {
1547
        PubKey  []byte
1548
        Version int16
1549
}
1550

1551
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1552
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1553
        if err != nil {
×
1554
                return nil, err
×
1555
        }
×
1556
        defer rows.Close()
×
1557
        var items []int32
×
1558
        for rows.Next() {
×
1559
                var feature_bit int32
×
1560
                if err := rows.Scan(&feature_bit); err != nil {
×
1561
                        return nil, err
×
1562
                }
×
1563
                items = append(items, feature_bit)
×
1564
        }
1565
        if err := rows.Close(); err != nil {
×
1566
                return nil, err
×
1567
        }
×
1568
        if err := rows.Err(); err != nil {
×
1569
                return nil, err
×
1570
        }
×
1571
        return items, nil
×
1572
}
1573

1574
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1575
SELECT id
1576
FROM graph_nodes
1577
WHERE pub_key = $1
1578
  AND version = $2
1579
`
1580

1581
type GetNodeIDByPubKeyParams struct {
1582
        PubKey  []byte
1583
        Version int16
1584
}
1585

1586
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1587
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1588
        var id int64
×
1589
        err := row.Scan(&id)
×
1590
        return id, err
×
1591
}
×
1592

1593
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1594
SELECT id, version, pub_key, alias, last_update, color, signature
1595
FROM graph_nodes
1596
WHERE last_update >= $1
1597
  AND last_update < $2
1598
`
1599

1600
type GetNodesByLastUpdateRangeParams struct {
1601
        StartTime sql.NullInt64
1602
        EndTime   sql.NullInt64
1603
}
1604

1605
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
1606
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1607
        if err != nil {
×
1608
                return nil, err
×
1609
        }
×
1610
        defer rows.Close()
×
1611
        var items []GraphNode
×
1612
        for rows.Next() {
×
1613
                var i GraphNode
×
1614
                if err := rows.Scan(
×
1615
                        &i.ID,
×
1616
                        &i.Version,
×
1617
                        &i.PubKey,
×
1618
                        &i.Alias,
×
1619
                        &i.LastUpdate,
×
1620
                        &i.Color,
×
1621
                        &i.Signature,
×
1622
                ); err != nil {
×
1623
                        return nil, err
×
1624
                }
×
1625
                items = append(items, i)
×
1626
        }
1627
        if err := rows.Close(); err != nil {
×
1628
                return nil, err
×
1629
        }
×
1630
        if err := rows.Err(); err != nil {
×
1631
                return nil, err
×
1632
        }
×
1633
        return items, nil
×
1634
}
1635

1636
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
1637
SELECT block_hash
1638
FROM graph_prune_log
1639
WHERE block_height = $1
1640
`
1641

1642
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
1643
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
1644
        var block_hash []byte
×
1645
        err := row.Scan(&block_hash)
×
1646
        return block_hash, err
×
1647
}
×
1648

1649
const getPruneTip = `-- name: GetPruneTip :one
1650
SELECT block_height, block_hash
1651
FROM graph_prune_log
1652
ORDER BY block_height DESC
1653
LIMIT 1
1654
`
1655

1656
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
1657
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1658
        var i GraphPruneLog
×
1659
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1660
        return i, err
×
1661
}
×
1662

1663
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1664
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
1665
FROM graph_channels
1666
WHERE node_1_signature IS NOT NULL
1667
  AND scid >= $1
1668
  AND scid < $2
1669
`
1670

1671
type GetPublicV1ChannelsBySCIDParams struct {
1672
        StartScid []byte
1673
        EndScid   []byte
1674
}
1675

1676
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
1677
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1678
        if err != nil {
×
1679
                return nil, err
×
1680
        }
×
1681
        defer rows.Close()
×
1682
        var items []GraphChannel
×
1683
        for rows.Next() {
×
1684
                var i GraphChannel
×
1685
                if err := rows.Scan(
×
1686
                        &i.ID,
×
1687
                        &i.Version,
×
1688
                        &i.Scid,
×
1689
                        &i.NodeID1,
×
1690
                        &i.NodeID2,
×
1691
                        &i.Outpoint,
×
1692
                        &i.Capacity,
×
1693
                        &i.BitcoinKey1,
×
1694
                        &i.BitcoinKey2,
×
1695
                        &i.Node1Signature,
×
1696
                        &i.Node2Signature,
×
1697
                        &i.Bitcoin1Signature,
×
1698
                        &i.Bitcoin2Signature,
×
1699
                ); err != nil {
×
1700
                        return nil, err
×
1701
                }
×
1702
                items = append(items, i)
×
1703
        }
1704
        if err := rows.Close(); err != nil {
×
1705
                return nil, err
×
1706
        }
×
1707
        if err := rows.Err(); err != nil {
×
1708
                return nil, err
×
1709
        }
×
1710
        return items, nil
×
1711
}
1712

1713
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1714
SELECT scid from graph_channels
1715
WHERE outpoint = $1 AND version = $2
1716
`
1717

1718
type GetSCIDByOutpointParams struct {
1719
        Outpoint string
1720
        Version  int16
1721
}
1722

1723
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1724
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1725
        var scid []byte
×
1726
        err := row.Scan(&scid)
×
1727
        return scid, err
×
1728
}
×
1729

1730
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1731
SELECT sn.node_id, n.pub_key
1732
FROM graph_source_nodes sn
1733
    JOIN graph_nodes n ON sn.node_id = n.id
1734
WHERE n.version = $1
1735
`
1736

1737
type GetSourceNodesByVersionRow struct {
1738
        NodeID int64
1739
        PubKey []byte
1740
}
1741

1742
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1743
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1744
        if err != nil {
×
1745
                return nil, err
×
1746
        }
×
1747
        defer rows.Close()
×
1748
        var items []GetSourceNodesByVersionRow
×
1749
        for rows.Next() {
×
1750
                var i GetSourceNodesByVersionRow
×
1751
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1752
                        return nil, err
×
1753
                }
×
1754
                items = append(items, i)
×
1755
        }
1756
        if err := rows.Close(); err != nil {
×
1757
                return nil, err
×
1758
        }
×
1759
        if err := rows.Err(); err != nil {
×
1760
                return nil, err
×
1761
        }
×
1762
        return items, nil
×
1763
}
1764

1765
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1766
SELECT c.scid
1767
FROM graph_channels c
1768
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
1769
WHERE cp.disabled = true
1770
AND c.version = 1
1771
GROUP BY c.scid
1772
HAVING COUNT(*) > 1
1773
`
1774

1775
// NOTE: this is V1 specific since for V1, disabled is a
1776
// simple, single boolean. The proposed V2 policy
1777
// structure will have a more complex disabled bit vector
1778
// and so the query for V2 may differ.
1779
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1780
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1781
        if err != nil {
×
1782
                return nil, err
×
1783
        }
×
1784
        defer rows.Close()
×
1785
        var items [][]byte
×
1786
        for rows.Next() {
×
1787
                var scid []byte
×
1788
                if err := rows.Scan(&scid); err != nil {
×
1789
                        return nil, err
×
1790
                }
×
1791
                items = append(items, scid)
×
1792
        }
1793
        if err := rows.Close(); err != nil {
×
1794
                return nil, err
×
1795
        }
×
1796
        if err := rows.Err(); err != nil {
×
1797
                return nil, err
×
1798
        }
×
1799
        return items, nil
×
1800
}
1801

1802
const getZombieChannel = `-- name: GetZombieChannel :one
1803
SELECT scid, version, node_key_1, node_key_2
1804
FROM graph_zombie_channels
1805
WHERE scid = $1
1806
AND version = $2
1807
`
1808

1809
type GetZombieChannelParams struct {
1810
        Scid    []byte
1811
        Version int16
1812
}
1813

1814
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
1815
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1816
        var i GraphZombieChannel
×
1817
        err := row.Scan(
×
1818
                &i.Scid,
×
1819
                &i.Version,
×
1820
                &i.NodeKey1,
×
1821
                &i.NodeKey2,
×
1822
        )
×
1823
        return i, err
×
1824
}
×
1825

1826
const highestSCID = `-- name: HighestSCID :one
1827
SELECT scid
1828
FROM graph_channels
1829
WHERE version = $1
1830
ORDER BY scid DESC
1831
LIMIT 1
1832
`
1833

1834
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1835
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1836
        var scid []byte
×
1837
        err := row.Scan(&scid)
×
1838
        return scid, err
×
1839
}
×
1840

1841
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1842
/* ─────────────────────────────────────────────
1843
   graph_channel_policy_extra_types table queries
1844
   ─────────────────────────────────────────────
1845
*/
1846

1847
INSERT INTO graph_channel_policy_extra_types (
1848
    channel_policy_id, type, value
1849
)
1850
VALUES ($1, $2, $3)
1851
`
1852

1853
type InsertChanPolicyExtraTypeParams struct {
1854
        ChannelPolicyID int64
1855
        Type            int64
1856
        Value           []byte
1857
}
1858

1859
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1860
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1861
        return err
×
1862
}
×
1863

1864
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1865
/* ─────────────────────────────────────────────
1866
   graph_channel_features table queries
1867
   ─────────────────────────────────────────────
1868
*/
1869

1870
INSERT INTO graph_channel_features (
1871
    channel_id, feature_bit
1872
) VALUES (
1873
    $1, $2
1874
)
1875
`
1876

1877
type InsertChannelFeatureParams struct {
1878
        ChannelID  int64
1879
        FeatureBit int32
1880
}
1881

1882
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1883
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1884
        return err
×
1885
}
×
1886

1887
const insertClosedChannel = `-- name: InsertClosedChannel :exec
1888
/* ─────────────────────────────────────────────
1889
   graph_closed_scid table queries
1890
   ────────────────────────────────────────────-
1891
*/
1892

1893
INSERT INTO graph_closed_scids (scid)
1894
VALUES ($1)
1895
ON CONFLICT (scid) DO NOTHING
1896
`
1897

1898
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
1899
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
1900
        return err
×
1901
}
×
1902

1903
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1904
/* ─────────────────────────────────────────────
1905
   graph_node_addresses table queries
1906
   ───────────────────────────────────��─────────
1907
*/
1908

1909
INSERT INTO graph_node_addresses (
1910
    node_id,
1911
    type,
1912
    address,
1913
    position
1914
) VALUES (
1915
    $1, $2, $3, $4
1916
 )
1917
`
1918

1919
type InsertNodeAddressParams struct {
1920
        NodeID   int64
1921
        Type     int16
1922
        Address  string
1923
        Position int32
1924
}
1925

1926
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1927
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1928
                arg.NodeID,
×
1929
                arg.Type,
×
1930
                arg.Address,
×
1931
                arg.Position,
×
1932
        )
×
1933
        return err
×
1934
}
×
1935

1936
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1937
/* ─────────────────────────────────────────────
1938
   graph_node_features table queries
1939
   ─────────────────────────────────────────────
1940
*/
1941

1942
INSERT INTO graph_node_features (
1943
    node_id, feature_bit
1944
) VALUES (
1945
    $1, $2
1946
)
1947
`
1948

1949
type InsertNodeFeatureParams struct {
1950
        NodeID     int64
1951
        FeatureBit int32
1952
}
1953

1954
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1955
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1956
        return err
×
1957
}
×
1958

1959
const isClosedChannel = `-- name: IsClosedChannel :one
1960
SELECT EXISTS (
1961
    SELECT 1
1962
    FROM graph_closed_scids
1963
    WHERE scid = $1
1964
)
1965
`
1966

1967
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
1968
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
1969
        var exists bool
×
1970
        err := row.Scan(&exists)
×
1971
        return exists, err
×
1972
}
×
1973

1974
const isPublicV1Node = `-- name: IsPublicV1Node :one
1975
SELECT EXISTS (
1976
    SELECT 1
1977
    FROM graph_channels c
1978
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1979
    -- NOTE: we hard-code the version here since the clauses
1980
    -- here that determine if a node is public is specific
1981
    -- to the V1 gossip protocol. In V1, a node is public
1982
    -- if it has a public channel and a public channel is one
1983
    -- where we have the set of signatures of the channel
1984
    -- announcement. It is enough to just check that we have
1985
    -- one of the signatures since we only ever set them
1986
    -- together.
1987
    WHERE c.version = 1
1988
      AND c.bitcoin_1_signature IS NOT NULL
1989
      AND n.pub_key = $1
1990
)
1991
`
1992

1993
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
1994
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
1995
        var exists bool
×
1996
        err := row.Scan(&exists)
×
1997
        return exists, err
×
1998
}
×
1999

2000
const isZombieChannel = `-- name: IsZombieChannel :one
2001
SELECT EXISTS (
2002
    SELECT 1
2003
    FROM graph_zombie_channels
2004
    WHERE scid = $1
2005
    AND version = $2
2006
) AS is_zombie
2007
`
2008

2009
type IsZombieChannelParams struct {
2010
        Scid    []byte
2011
        Version int16
2012
}
2013

2014
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2015
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2016
        var is_zombie bool
×
2017
        err := row.Scan(&is_zombie)
×
2018
        return is_zombie, err
×
2019
}
×
2020

2021
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2022
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,
2023
    n1.pub_key AS node1_pubkey,
2024
    n2.pub_key AS node2_pubkey,
2025

2026
    -- Policy 1
2027
    -- TODO(elle): use sqlc.embed to embed policy structs
2028
    --  once this issue is resolved:
2029
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2030
    cp1.id AS policy1_id,
2031
    cp1.node_id AS policy1_node_id,
2032
    cp1.version AS policy1_version,
2033
    cp1.timelock AS policy1_timelock,
2034
    cp1.fee_ppm AS policy1_fee_ppm,
2035
    cp1.base_fee_msat AS policy1_base_fee_msat,
2036
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2037
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2038
    cp1.last_update AS policy1_last_update,
2039
    cp1.disabled AS policy1_disabled,
2040
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2041
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2042
    cp1.message_flags AS policy1_message_flags,
2043
    cp1.channel_flags AS policy1_channel_flags,
2044
    cp1.signature AS policy1_signature,
2045

2046
       -- Policy 2
2047
    cp2.id AS policy2_id,
2048
    cp2.node_id AS policy2_node_id,
2049
    cp2.version AS policy2_version,
2050
    cp2.timelock AS policy2_timelock,
2051
    cp2.fee_ppm AS policy2_fee_ppm,
2052
    cp2.base_fee_msat AS policy2_base_fee_msat,
2053
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2054
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2055
    cp2.last_update AS policy2_last_update,
2056
    cp2.disabled AS policy2_disabled,
2057
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2058
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2059
    cp2.message_flags AS policy2_message_flags,
2060
    cp2.channel_flags AS policy2_channel_flags,
2061
    cp2.signature AS policy2_signature
2062

2063
FROM graph_channels c
2064
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2065
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2066
    LEFT JOIN graph_channel_policies cp1
2067
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2068
    LEFT JOIN graph_channel_policies cp2
2069
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2070
WHERE c.version = $1
2071
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2072
`
2073

2074
type ListChannelsByNodeIDParams struct {
2075
        Version int16
2076
        NodeID1 int64
2077
}
2078

2079
type ListChannelsByNodeIDRow struct {
2080
        GraphChannel                   GraphChannel
2081
        Node1Pubkey                    []byte
2082
        Node2Pubkey                    []byte
2083
        Policy1ID                      sql.NullInt64
2084
        Policy1NodeID                  sql.NullInt64
2085
        Policy1Version                 sql.NullInt16
2086
        Policy1Timelock                sql.NullInt32
2087
        Policy1FeePpm                  sql.NullInt64
2088
        Policy1BaseFeeMsat             sql.NullInt64
2089
        Policy1MinHtlcMsat             sql.NullInt64
2090
        Policy1MaxHtlcMsat             sql.NullInt64
2091
        Policy1LastUpdate              sql.NullInt64
2092
        Policy1Disabled                sql.NullBool
2093
        Policy1InboundBaseFeeMsat      sql.NullInt64
2094
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2095
        Policy1MessageFlags            sql.NullInt16
2096
        Policy1ChannelFlags            sql.NullInt16
2097
        Policy1Signature               []byte
2098
        Policy2ID                      sql.NullInt64
2099
        Policy2NodeID                  sql.NullInt64
2100
        Policy2Version                 sql.NullInt16
2101
        Policy2Timelock                sql.NullInt32
2102
        Policy2FeePpm                  sql.NullInt64
2103
        Policy2BaseFeeMsat             sql.NullInt64
2104
        Policy2MinHtlcMsat             sql.NullInt64
2105
        Policy2MaxHtlcMsat             sql.NullInt64
2106
        Policy2LastUpdate              sql.NullInt64
2107
        Policy2Disabled                sql.NullBool
2108
        Policy2InboundBaseFeeMsat      sql.NullInt64
2109
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2110
        Policy2MessageFlags            sql.NullInt16
2111
        Policy2ChannelFlags            sql.NullInt16
2112
        Policy2Signature               []byte
2113
}
2114

2115
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2116
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2117
        if err != nil {
×
2118
                return nil, err
×
2119
        }
×
2120
        defer rows.Close()
×
2121
        var items []ListChannelsByNodeIDRow
×
2122
        for rows.Next() {
×
2123
                var i ListChannelsByNodeIDRow
×
2124
                if err := rows.Scan(
×
2125
                        &i.GraphChannel.ID,
×
2126
                        &i.GraphChannel.Version,
×
2127
                        &i.GraphChannel.Scid,
×
2128
                        &i.GraphChannel.NodeID1,
×
2129
                        &i.GraphChannel.NodeID2,
×
2130
                        &i.GraphChannel.Outpoint,
×
2131
                        &i.GraphChannel.Capacity,
×
2132
                        &i.GraphChannel.BitcoinKey1,
×
2133
                        &i.GraphChannel.BitcoinKey2,
×
2134
                        &i.GraphChannel.Node1Signature,
×
2135
                        &i.GraphChannel.Node2Signature,
×
2136
                        &i.GraphChannel.Bitcoin1Signature,
×
2137
                        &i.GraphChannel.Bitcoin2Signature,
×
2138
                        &i.Node1Pubkey,
×
2139
                        &i.Node2Pubkey,
×
2140
                        &i.Policy1ID,
×
2141
                        &i.Policy1NodeID,
×
2142
                        &i.Policy1Version,
×
2143
                        &i.Policy1Timelock,
×
2144
                        &i.Policy1FeePpm,
×
2145
                        &i.Policy1BaseFeeMsat,
×
2146
                        &i.Policy1MinHtlcMsat,
×
2147
                        &i.Policy1MaxHtlcMsat,
×
2148
                        &i.Policy1LastUpdate,
×
2149
                        &i.Policy1Disabled,
×
2150
                        &i.Policy1InboundBaseFeeMsat,
×
2151
                        &i.Policy1InboundFeeRateMilliMsat,
×
2152
                        &i.Policy1MessageFlags,
×
2153
                        &i.Policy1ChannelFlags,
×
2154
                        &i.Policy1Signature,
×
2155
                        &i.Policy2ID,
×
2156
                        &i.Policy2NodeID,
×
2157
                        &i.Policy2Version,
×
2158
                        &i.Policy2Timelock,
×
2159
                        &i.Policy2FeePpm,
×
2160
                        &i.Policy2BaseFeeMsat,
×
2161
                        &i.Policy2MinHtlcMsat,
×
2162
                        &i.Policy2MaxHtlcMsat,
×
2163
                        &i.Policy2LastUpdate,
×
2164
                        &i.Policy2Disabled,
×
2165
                        &i.Policy2InboundBaseFeeMsat,
×
2166
                        &i.Policy2InboundFeeRateMilliMsat,
×
2167
                        &i.Policy2MessageFlags,
×
2168
                        &i.Policy2ChannelFlags,
×
2169
                        &i.Policy2Signature,
×
2170
                ); err != nil {
×
2171
                        return nil, err
×
2172
                }
×
2173
                items = append(items, i)
×
2174
        }
2175
        if err := rows.Close(); err != nil {
×
2176
                return nil, err
×
2177
        }
×
2178
        if err := rows.Err(); err != nil {
×
2179
                return nil, err
×
2180
        }
×
2181
        return items, nil
×
2182
}
2183

2184
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
2185
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
2186
FROM graph_channels c
2187
WHERE c.version = $1 AND c.id > $2
2188
ORDER BY c.id
2189
LIMIT $3
2190
`
2191

2192
type ListChannelsPaginatedParams struct {
2193
        Version int16
2194
        ID      int64
2195
        Limit   int32
2196
}
2197

2198
type ListChannelsPaginatedRow struct {
2199
        ID          int64
2200
        BitcoinKey1 []byte
2201
        BitcoinKey2 []byte
2202
        Outpoint    string
2203
}
2204

2205
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
2206
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
2207
        if err != nil {
×
2208
                return nil, err
×
2209
        }
×
2210
        defer rows.Close()
×
2211
        var items []ListChannelsPaginatedRow
×
2212
        for rows.Next() {
×
2213
                var i ListChannelsPaginatedRow
×
2214
                if err := rows.Scan(
×
2215
                        &i.ID,
×
2216
                        &i.BitcoinKey1,
×
2217
                        &i.BitcoinKey2,
×
2218
                        &i.Outpoint,
×
2219
                ); err != nil {
×
2220
                        return nil, err
×
2221
                }
×
2222
                items = append(items, i)
×
2223
        }
2224
        if err := rows.Close(); err != nil {
×
2225
                return nil, err
×
2226
        }
×
2227
        if err := rows.Err(); err != nil {
×
2228
                return nil, err
×
2229
        }
×
2230
        return items, nil
×
2231
}
2232

2233
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
2234
SELECT
2235
    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,
2236

2237
    -- Join node pubkeys
2238
    n1.pub_key AS node1_pubkey,
2239
    n2.pub_key AS node2_pubkey,
2240

2241
    -- Node 1 policy
2242
    cp1.id AS policy_1_id,
2243
    cp1.node_id AS policy_1_node_id,
2244
    cp1.version AS policy_1_version,
2245
    cp1.timelock AS policy_1_timelock,
2246
    cp1.fee_ppm AS policy_1_fee_ppm,
2247
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2248
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2249
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2250
    cp1.last_update AS policy_1_last_update,
2251
    cp1.disabled AS policy_1_disabled,
2252
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2253
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2254
    cp1.message_flags AS policy1_message_flags,
2255
    cp1.channel_flags AS policy1_channel_flags,
2256
    cp1.signature AS policy_1_signature,
2257

2258
    -- Node 2 policy
2259
    cp2.id AS policy_2_id,
2260
    cp2.node_id AS policy_2_node_id,
2261
    cp2.version AS policy_2_version,
2262
    cp2.timelock AS policy_2_timelock,
2263
    cp2.fee_ppm AS policy_2_fee_ppm,
2264
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2265
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2266
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2267
    cp2.last_update AS policy_2_last_update,
2268
    cp2.disabled AS policy_2_disabled,
2269
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2270
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2271
    cp2.message_flags AS policy2_message_flags,
2272
    cp2.channel_flags AS policy2_channel_flags,
2273
    cp2.signature AS policy_2_signature
2274

2275
FROM graph_channels c
2276
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2277
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2278
LEFT JOIN graph_channel_policies cp1
2279
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2280
LEFT JOIN graph_channel_policies cp2
2281
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2282
WHERE c.version = $1 AND c.id > $2
2283
ORDER BY c.id
2284
LIMIT $3
2285
`
2286

2287
type ListChannelsWithPoliciesPaginatedParams struct {
2288
        Version int16
2289
        ID      int64
2290
        Limit   int32
2291
}
2292

2293
type ListChannelsWithPoliciesPaginatedRow struct {
2294
        GraphChannel                   GraphChannel
2295
        Node1Pubkey                    []byte
2296
        Node2Pubkey                    []byte
2297
        Policy1ID                      sql.NullInt64
2298
        Policy1NodeID                  sql.NullInt64
2299
        Policy1Version                 sql.NullInt16
2300
        Policy1Timelock                sql.NullInt32
2301
        Policy1FeePpm                  sql.NullInt64
2302
        Policy1BaseFeeMsat             sql.NullInt64
2303
        Policy1MinHtlcMsat             sql.NullInt64
2304
        Policy1MaxHtlcMsat             sql.NullInt64
2305
        Policy1LastUpdate              sql.NullInt64
2306
        Policy1Disabled                sql.NullBool
2307
        Policy1InboundBaseFeeMsat      sql.NullInt64
2308
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2309
        Policy1MessageFlags            sql.NullInt16
2310
        Policy1ChannelFlags            sql.NullInt16
2311
        Policy1Signature               []byte
2312
        Policy2ID                      sql.NullInt64
2313
        Policy2NodeID                  sql.NullInt64
2314
        Policy2Version                 sql.NullInt16
2315
        Policy2Timelock                sql.NullInt32
2316
        Policy2FeePpm                  sql.NullInt64
2317
        Policy2BaseFeeMsat             sql.NullInt64
2318
        Policy2MinHtlcMsat             sql.NullInt64
2319
        Policy2MaxHtlcMsat             sql.NullInt64
2320
        Policy2LastUpdate              sql.NullInt64
2321
        Policy2Disabled                sql.NullBool
2322
        Policy2InboundBaseFeeMsat      sql.NullInt64
2323
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2324
        Policy2MessageFlags            sql.NullInt16
2325
        Policy2ChannelFlags            sql.NullInt16
2326
        Policy2Signature               []byte
2327
}
2328

2329
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
2330
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
2331
        if err != nil {
×
2332
                return nil, err
×
2333
        }
×
2334
        defer rows.Close()
×
2335
        var items []ListChannelsWithPoliciesPaginatedRow
×
2336
        for rows.Next() {
×
2337
                var i ListChannelsWithPoliciesPaginatedRow
×
2338
                if err := rows.Scan(
×
2339
                        &i.GraphChannel.ID,
×
2340
                        &i.GraphChannel.Version,
×
2341
                        &i.GraphChannel.Scid,
×
2342
                        &i.GraphChannel.NodeID1,
×
2343
                        &i.GraphChannel.NodeID2,
×
2344
                        &i.GraphChannel.Outpoint,
×
2345
                        &i.GraphChannel.Capacity,
×
2346
                        &i.GraphChannel.BitcoinKey1,
×
2347
                        &i.GraphChannel.BitcoinKey2,
×
2348
                        &i.GraphChannel.Node1Signature,
×
2349
                        &i.GraphChannel.Node2Signature,
×
2350
                        &i.GraphChannel.Bitcoin1Signature,
×
2351
                        &i.GraphChannel.Bitcoin2Signature,
×
2352
                        &i.Node1Pubkey,
×
2353
                        &i.Node2Pubkey,
×
2354
                        &i.Policy1ID,
×
2355
                        &i.Policy1NodeID,
×
2356
                        &i.Policy1Version,
×
2357
                        &i.Policy1Timelock,
×
2358
                        &i.Policy1FeePpm,
×
2359
                        &i.Policy1BaseFeeMsat,
×
2360
                        &i.Policy1MinHtlcMsat,
×
2361
                        &i.Policy1MaxHtlcMsat,
×
2362
                        &i.Policy1LastUpdate,
×
2363
                        &i.Policy1Disabled,
×
2364
                        &i.Policy1InboundBaseFeeMsat,
×
2365
                        &i.Policy1InboundFeeRateMilliMsat,
×
2366
                        &i.Policy1MessageFlags,
×
2367
                        &i.Policy1ChannelFlags,
×
2368
                        &i.Policy1Signature,
×
2369
                        &i.Policy2ID,
×
2370
                        &i.Policy2NodeID,
×
2371
                        &i.Policy2Version,
×
2372
                        &i.Policy2Timelock,
×
2373
                        &i.Policy2FeePpm,
×
2374
                        &i.Policy2BaseFeeMsat,
×
2375
                        &i.Policy2MinHtlcMsat,
×
2376
                        &i.Policy2MaxHtlcMsat,
×
2377
                        &i.Policy2LastUpdate,
×
2378
                        &i.Policy2Disabled,
×
2379
                        &i.Policy2InboundBaseFeeMsat,
×
2380
                        &i.Policy2InboundFeeRateMilliMsat,
×
2381
                        &i.Policy2MessageFlags,
×
2382
                        &i.Policy2ChannelFlags,
×
2383
                        &i.Policy2Signature,
×
2384
                ); err != nil {
×
2385
                        return nil, err
×
2386
                }
×
2387
                items = append(items, i)
×
2388
        }
2389
        if err := rows.Close(); err != nil {
×
2390
                return nil, err
×
2391
        }
×
2392
        if err := rows.Err(); err != nil {
×
2393
                return nil, err
×
2394
        }
×
2395
        return items, nil
×
2396
}
2397

2398
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2399
SELECT id, pub_key
2400
FROM graph_nodes
2401
WHERE version = $1  AND id > $2
2402
ORDER BY id
2403
LIMIT $3
2404
`
2405

2406
type ListNodeIDsAndPubKeysParams struct {
2407
        Version int16
2408
        ID      int64
2409
        Limit   int32
2410
}
2411

2412
type ListNodeIDsAndPubKeysRow struct {
2413
        ID     int64
2414
        PubKey []byte
2415
}
2416

2417
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2418
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2419
        if err != nil {
×
2420
                return nil, err
×
2421
        }
×
2422
        defer rows.Close()
×
2423
        var items []ListNodeIDsAndPubKeysRow
×
2424
        for rows.Next() {
×
2425
                var i ListNodeIDsAndPubKeysRow
×
2426
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2427
                        return nil, err
×
2428
                }
×
2429
                items = append(items, i)
×
2430
        }
2431
        if err := rows.Close(); err != nil {
×
2432
                return nil, err
×
2433
        }
×
2434
        if err := rows.Err(); err != nil {
×
2435
                return nil, err
×
2436
        }
×
2437
        return items, nil
×
2438
}
2439

2440
const listNodesPaginated = `-- name: ListNodesPaginated :many
2441
SELECT id, version, pub_key, alias, last_update, color, signature
2442
FROM graph_nodes
2443
WHERE version = $1 AND id > $2
2444
ORDER BY id
2445
LIMIT $3
2446
`
2447

2448
type ListNodesPaginatedParams struct {
2449
        Version int16
2450
        ID      int64
2451
        Limit   int32
2452
}
2453

2454
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
2455
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2456
        if err != nil {
×
2457
                return nil, err
×
2458
        }
×
2459
        defer rows.Close()
×
2460
        var items []GraphNode
×
2461
        for rows.Next() {
×
2462
                var i GraphNode
×
2463
                if err := rows.Scan(
×
2464
                        &i.ID,
×
2465
                        &i.Version,
×
2466
                        &i.PubKey,
×
2467
                        &i.Alias,
×
2468
                        &i.LastUpdate,
×
2469
                        &i.Color,
×
2470
                        &i.Signature,
×
2471
                ); err != nil {
×
2472
                        return nil, err
×
2473
                }
×
2474
                items = append(items, i)
×
2475
        }
2476
        if err := rows.Close(); err != nil {
×
2477
                return nil, err
×
2478
        }
×
2479
        if err := rows.Err(); err != nil {
×
2480
                return nil, err
×
2481
        }
×
2482
        return items, nil
×
2483
}
2484

2485
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2486
/* ─────────────────────────────────────────────
2487
   graph_channel_policies table queries
2488
   ─────────────────────────────────────────────
2489
*/
2490

2491
INSERT INTO graph_channel_policies (
2492
    version, channel_id, node_id, timelock, fee_ppm,
2493
    base_fee_msat, min_htlc_msat, last_update, disabled,
2494
    max_htlc_msat, inbound_base_fee_msat,
2495
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2496
    signature
2497
) VALUES  (
2498
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2499
)
2500
ON CONFLICT (channel_id, node_id, version)
2501
    -- Update the following fields if a conflict occurs on channel_id,
2502
    -- node_id, and version.
2503
    DO UPDATE SET
2504
        timelock = EXCLUDED.timelock,
2505
        fee_ppm = EXCLUDED.fee_ppm,
2506
        base_fee_msat = EXCLUDED.base_fee_msat,
2507
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2508
        last_update = EXCLUDED.last_update,
2509
        disabled = EXCLUDED.disabled,
2510
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2511
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2512
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2513
        message_flags = EXCLUDED.message_flags,
2514
        channel_flags = EXCLUDED.channel_flags,
2515
        signature = EXCLUDED.signature
2516
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
2517
RETURNING id
2518
`
2519

2520
type UpsertEdgePolicyParams struct {
2521
        Version                 int16
2522
        ChannelID               int64
2523
        NodeID                  int64
2524
        Timelock                int32
2525
        FeePpm                  int64
2526
        BaseFeeMsat             int64
2527
        MinHtlcMsat             int64
2528
        LastUpdate              sql.NullInt64
2529
        Disabled                sql.NullBool
2530
        MaxHtlcMsat             sql.NullInt64
2531
        InboundBaseFeeMsat      sql.NullInt64
2532
        InboundFeeRateMilliMsat sql.NullInt64
2533
        MessageFlags            sql.NullInt16
2534
        ChannelFlags            sql.NullInt16
2535
        Signature               []byte
2536
}
2537

2538
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2539
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2540
                arg.Version,
×
2541
                arg.ChannelID,
×
2542
                arg.NodeID,
×
2543
                arg.Timelock,
×
2544
                arg.FeePpm,
×
2545
                arg.BaseFeeMsat,
×
2546
                arg.MinHtlcMsat,
×
2547
                arg.LastUpdate,
×
2548
                arg.Disabled,
×
2549
                arg.MaxHtlcMsat,
×
2550
                arg.InboundBaseFeeMsat,
×
2551
                arg.InboundFeeRateMilliMsat,
×
2552
                arg.MessageFlags,
×
2553
                arg.ChannelFlags,
×
2554
                arg.Signature,
×
2555
        )
×
2556
        var id int64
×
2557
        err := row.Scan(&id)
×
2558
        return id, err
×
2559
}
×
2560

2561
const upsertNode = `-- name: UpsertNode :one
2562
/* ─────────────────────────────────────────────
2563
   graph_nodes table queries
2564
   ───────────────────────────��─────────────────
2565
*/
2566

2567
INSERT INTO graph_nodes (
2568
    version, pub_key, alias, last_update, color, signature
2569
) VALUES (
2570
    $1, $2, $3, $4, $5, $6
2571
)
2572
ON CONFLICT (pub_key, version)
2573
    -- Update the following fields if a conflict occurs on pub_key
2574
    -- and version.
2575
    DO UPDATE SET
2576
        alias = EXCLUDED.alias,
2577
        last_update = EXCLUDED.last_update,
2578
        color = EXCLUDED.color,
2579
        signature = EXCLUDED.signature
2580
WHERE graph_nodes.last_update IS NULL
2581
    OR EXCLUDED.last_update > graph_nodes.last_update
2582
RETURNING id
2583
`
2584

2585
type UpsertNodeParams struct {
2586
        Version    int16
2587
        PubKey     []byte
2588
        Alias      sql.NullString
2589
        LastUpdate sql.NullInt64
2590
        Color      sql.NullString
2591
        Signature  []byte
2592
}
2593

2594
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2595
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2596
                arg.Version,
×
2597
                arg.PubKey,
×
2598
                arg.Alias,
×
2599
                arg.LastUpdate,
×
2600
                arg.Color,
×
2601
                arg.Signature,
×
2602
        )
×
2603
        var id int64
×
2604
        err := row.Scan(&id)
×
2605
        return id, err
×
2606
}
×
2607

2608
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2609
/* ─────────────────────────────────────────────
2610
   graph_node_extra_types table queries
2611
   ─────────────────────────────────────────────
2612
*/
2613

2614
INSERT INTO graph_node_extra_types (
2615
    node_id, type, value
2616
)
2617
VALUES ($1, $2, $3)
2618
ON CONFLICT (type, node_id)
2619
    -- Update the value if a conflict occurs on type
2620
    -- and node_id.
2621
    DO UPDATE SET value = EXCLUDED.value
2622
`
2623

2624
type UpsertNodeExtraTypeParams struct {
2625
        NodeID int64
2626
        Type   int64
2627
        Value  []byte
2628
}
2629

2630
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2631
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2632
        return err
×
2633
}
×
2634

2635
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2636
/* ───────────────────────────���─────────────────
2637
    graph_prune_log table queries
2638
    ─────────────────────────────────────────────
2639
*/
2640

2641
INSERT INTO graph_prune_log (
2642
    block_height, block_hash
2643
) VALUES (
2644
    $1, $2
2645
)
2646
ON CONFLICT(block_height) DO UPDATE SET
2647
    block_hash = EXCLUDED.block_hash
2648
`
2649

2650
type UpsertPruneLogEntryParams struct {
2651
        BlockHeight int64
2652
        BlockHash   []byte
2653
}
2654

2655
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2656
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2657
        return err
×
2658
}
×
2659

2660
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2661
/* ─────────────────────────────────────────────
2662
   graph_zombie_channels table queries
2663
   ─────────────────────────────────────────────
2664
*/
2665

2666
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
2667
VALUES ($1, $2, $3, $4)
2668
ON CONFLICT (scid, version)
2669
DO UPDATE SET
2670
    -- If a conflict exists for the SCID and version pair, then we
2671
    -- update the node keys.
2672
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
2673
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
2674
`
2675

2676
type UpsertZombieChannelParams struct {
2677
        Scid     []byte
2678
        Version  int16
2679
        NodeKey1 []byte
2680
        NodeKey2 []byte
2681
}
2682

2683
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2684
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2685
                arg.Scid,
×
2686
                arg.Version,
×
2687
                arg.NodeKey1,
×
2688
                arg.NodeKey2,
×
2689
        )
×
2690
        return err
×
2691
}
×
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