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

lightningnetwork / lnd / 23185093231

17 Mar 2026 08:25AM UTC coverage: 62.303% (-0.03%) from 62.33%
23185093231

push

github

web-flow
Merge pull request #10582 from ellemouton/g175-db-8

[g175] graph/db: add versioned range queries and complete v2 graph query migration

210 of 471 new or added lines in 11 files covered. (44.59%)

87 existing lines in 22 files now uncovered.

140872 of 226108 relevant lines covered (62.3%)

19402.99 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 addV2ChannelProof = `-- name: AddV2ChannelProof :execresult
59
UPDATE graph_channels
60
SET signature = $2
61
WHERE scid = $1
62
  AND version = 2
63
`
64

65
type AddV2ChannelProofParams struct {
66
        Scid      []byte
67
        Signature []byte
68
}
69

70
func (q *Queries) AddV2ChannelProof(ctx context.Context, arg AddV2ChannelProofParams) (sql.Result, error) {
×
71
        return q.db.ExecContext(ctx, addV2ChannelProof, arg.Scid, arg.Signature)
×
72
}
×
73

74
const countZombieChannels = `-- name: CountZombieChannels :one
75
SELECT COUNT(*)
76
FROM graph_zombie_channels
77
WHERE version = $1
78
`
79

80
func (q *Queries) CountZombieChannels(ctx context.Context, version int16) (int64, error) {
×
81
        row := q.db.QueryRowContext(ctx, countZombieChannels, version)
×
82
        var count int64
×
83
        err := row.Scan(&count)
×
84
        return count, err
×
85
}
×
86

87
const createChannel = `-- name: CreateChannel :one
88
/* ─────────────────────────────────────────────
89
   graph_channels table queries
90
   ─────────────────────────────────────────────
91
*/
92

93
INSERT INTO graph_channels (
94
    version, scid, node_id_1, node_id_2,
95
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
96
    node_1_signature, node_2_signature, bitcoin_1_signature,
97
    bitcoin_2_signature, signature, funding_pk_script, merkle_root_hash
98
) VALUES (
99
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
100
)
101
RETURNING id
102
`
103

104
type CreateChannelParams struct {
105
        Version           int16
106
        Scid              []byte
107
        NodeID1           int64
108
        NodeID2           int64
109
        Outpoint          string
110
        Capacity          sql.NullInt64
111
        BitcoinKey1       []byte
112
        BitcoinKey2       []byte
113
        Node1Signature    []byte
114
        Node2Signature    []byte
115
        Bitcoin1Signature []byte
116
        Bitcoin2Signature []byte
117
        Signature         []byte
118
        FundingPkScript   []byte
119
        MerkleRootHash    []byte
120
}
121

122
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
×
123
        row := q.db.QueryRowContext(ctx, createChannel,
×
124
                arg.Version,
×
125
                arg.Scid,
×
126
                arg.NodeID1,
×
127
                arg.NodeID2,
×
128
                arg.Outpoint,
×
129
                arg.Capacity,
×
130
                arg.BitcoinKey1,
×
131
                arg.BitcoinKey2,
×
132
                arg.Node1Signature,
×
133
                arg.Node2Signature,
×
134
                arg.Bitcoin1Signature,
×
135
                arg.Bitcoin2Signature,
×
136
                arg.Signature,
×
137
                arg.FundingPkScript,
×
138
                arg.MerkleRootHash,
×
139
        )
×
140
        var id int64
×
141
        err := row.Scan(&id)
×
142
        return id, err
×
143
}
×
144

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

377
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
378
SELECT
379
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
380

381
    n1.pub_key AS node1_pubkey,
382
    n2.pub_key AS node2_pubkey,
383

384
    -- Node 1 policy
385
    cp1.id AS policy_1_id,
386
    cp1.node_id AS policy_1_node_id,
387
    cp1.version AS policy_1_version,
388
    cp1.timelock AS policy_1_timelock,
389
    cp1.fee_ppm AS policy_1_fee_ppm,
390
    cp1.base_fee_msat AS policy_1_base_fee_msat,
391
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
392
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
393
    cp1.last_update AS policy_1_last_update,
394
    cp1.disabled AS policy_1_disabled,
395
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
396
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
397
    cp1.message_flags AS policy_1_message_flags,
398
    cp1.channel_flags AS policy_1_channel_flags,
399
    cp1.signature AS policy_1_signature,
400
    cp1.block_height AS policy_1_block_height,
401
    cp1.disable_flags AS policy_1_disable_flags,
402

403
    -- Node 2 policy
404
    cp2.id AS policy_2_id,
405
    cp2.node_id AS policy_2_node_id,
406
    cp2.version AS policy_2_version,
407
    cp2.timelock AS policy_2_timelock,
408
    cp2.fee_ppm AS policy_2_fee_ppm,
409
    cp2.base_fee_msat AS policy_2_base_fee_msat,
410
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
411
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
412
    cp2.last_update AS policy_2_last_update,
413
    cp2.disabled AS policy_2_disabled,
414
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
415
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
416
    cp2.message_flags AS policy_2_message_flags,
417
    cp2.channel_flags AS policy_2_channel_flags,
418
    cp2.signature AS policy_2_signature,
419
    cp2.block_height AS policy_2_block_height,
420
    cp2.disable_flags AS policy_2_disable_flags
421
FROM graph_channels c
422
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
423
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
424
    LEFT JOIN graph_channel_policies cp1
425
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
426
    LEFT JOIN graph_channel_policies cp2
427
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
428
WHERE c.outpoint = $1 AND c.version = $2
429
`
430

431
type GetChannelByOutpointWithPoliciesParams struct {
432
        Outpoint string
433
        Version  int16
434
}
435

436
type GetChannelByOutpointWithPoliciesRow struct {
437
        GraphChannel                   GraphChannel
438
        Node1Pubkey                    []byte
439
        Node2Pubkey                    []byte
440
        Policy1ID                      sql.NullInt64
441
        Policy1NodeID                  sql.NullInt64
442
        Policy1Version                 sql.NullInt16
443
        Policy1Timelock                sql.NullInt32
444
        Policy1FeePpm                  sql.NullInt64
445
        Policy1BaseFeeMsat             sql.NullInt64
446
        Policy1MinHtlcMsat             sql.NullInt64
447
        Policy1MaxHtlcMsat             sql.NullInt64
448
        Policy1LastUpdate              sql.NullInt64
449
        Policy1Disabled                sql.NullBool
450
        Policy1InboundBaseFeeMsat      sql.NullInt64
451
        Policy1InboundFeeRateMilliMsat sql.NullInt64
452
        Policy1MessageFlags            sql.NullInt16
453
        Policy1ChannelFlags            sql.NullInt16
454
        Policy1Signature               []byte
455
        Policy1BlockHeight             sql.NullInt64
456
        Policy1DisableFlags            sql.NullInt16
457
        Policy2ID                      sql.NullInt64
458
        Policy2NodeID                  sql.NullInt64
459
        Policy2Version                 sql.NullInt16
460
        Policy2Timelock                sql.NullInt32
461
        Policy2FeePpm                  sql.NullInt64
462
        Policy2BaseFeeMsat             sql.NullInt64
463
        Policy2MinHtlcMsat             sql.NullInt64
464
        Policy2MaxHtlcMsat             sql.NullInt64
465
        Policy2LastUpdate              sql.NullInt64
466
        Policy2Disabled                sql.NullBool
467
        Policy2InboundBaseFeeMsat      sql.NullInt64
468
        Policy2InboundFeeRateMilliMsat sql.NullInt64
469
        Policy2MessageFlags            sql.NullInt16
470
        Policy2ChannelFlags            sql.NullInt16
471
        Policy2Signature               []byte
472
        Policy2BlockHeight             sql.NullInt64
473
        Policy2DisableFlags            sql.NullInt16
474
}
475

476
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
477
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
478
        var i GetChannelByOutpointWithPoliciesRow
×
479
        err := row.Scan(
×
480
                &i.GraphChannel.ID,
×
481
                &i.GraphChannel.Version,
×
482
                &i.GraphChannel.Scid,
×
483
                &i.GraphChannel.NodeID1,
×
484
                &i.GraphChannel.NodeID2,
×
485
                &i.GraphChannel.Outpoint,
×
486
                &i.GraphChannel.Capacity,
×
487
                &i.GraphChannel.BitcoinKey1,
×
488
                &i.GraphChannel.BitcoinKey2,
×
489
                &i.GraphChannel.Node1Signature,
×
490
                &i.GraphChannel.Node2Signature,
×
491
                &i.GraphChannel.Bitcoin1Signature,
×
492
                &i.GraphChannel.Bitcoin2Signature,
×
493
                &i.GraphChannel.Signature,
×
494
                &i.GraphChannel.FundingPkScript,
×
495
                &i.GraphChannel.MerkleRootHash,
×
496
                &i.Node1Pubkey,
×
497
                &i.Node2Pubkey,
×
498
                &i.Policy1ID,
×
499
                &i.Policy1NodeID,
×
500
                &i.Policy1Version,
×
501
                &i.Policy1Timelock,
×
502
                &i.Policy1FeePpm,
×
503
                &i.Policy1BaseFeeMsat,
×
504
                &i.Policy1MinHtlcMsat,
×
505
                &i.Policy1MaxHtlcMsat,
×
506
                &i.Policy1LastUpdate,
×
507
                &i.Policy1Disabled,
×
508
                &i.Policy1InboundBaseFeeMsat,
×
509
                &i.Policy1InboundFeeRateMilliMsat,
×
510
                &i.Policy1MessageFlags,
×
511
                &i.Policy1ChannelFlags,
×
512
                &i.Policy1Signature,
×
513
                &i.Policy1BlockHeight,
×
514
                &i.Policy1DisableFlags,
×
515
                &i.Policy2ID,
×
516
                &i.Policy2NodeID,
×
517
                &i.Policy2Version,
×
518
                &i.Policy2Timelock,
×
519
                &i.Policy2FeePpm,
×
520
                &i.Policy2BaseFeeMsat,
×
521
                &i.Policy2MinHtlcMsat,
×
522
                &i.Policy2MaxHtlcMsat,
×
523
                &i.Policy2LastUpdate,
×
524
                &i.Policy2Disabled,
×
525
                &i.Policy2InboundBaseFeeMsat,
×
526
                &i.Policy2InboundFeeRateMilliMsat,
×
527
                &i.Policy2MessageFlags,
×
528
                &i.Policy2ChannelFlags,
×
529
                &i.Policy2Signature,
×
530
                &i.Policy2BlockHeight,
×
531
                &i.Policy2DisableFlags,
×
532
        )
×
533
        return i, err
×
534
}
×
535

536
const getChannelBySCID = `-- name: GetChannelBySCID :one
537
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, signature, funding_pk_script, merkle_root_hash FROM graph_channels
538
WHERE scid = $1 AND version = $2
539
`
540

541
type GetChannelBySCIDParams struct {
542
        Scid    []byte
543
        Version int16
544
}
545

546
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GraphChannel, error) {
×
547
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
548
        var i GraphChannel
×
549
        err := row.Scan(
×
550
                &i.ID,
×
551
                &i.Version,
×
552
                &i.Scid,
×
553
                &i.NodeID1,
×
554
                &i.NodeID2,
×
555
                &i.Outpoint,
×
556
                &i.Capacity,
×
557
                &i.BitcoinKey1,
×
558
                &i.BitcoinKey2,
×
559
                &i.Node1Signature,
×
560
                &i.Node2Signature,
×
561
                &i.Bitcoin1Signature,
×
562
                &i.Bitcoin2Signature,
×
563
                &i.Signature,
×
564
                &i.FundingPkScript,
×
565
                &i.MerkleRootHash,
×
566
        )
×
567
        return i, err
×
568
}
×
569

570
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
571
SELECT
572
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
573
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature, n1.block_height,
574
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature, n2.block_height,
575

576
    -- Policy 1
577
    cp1.id AS policy1_id,
578
    cp1.node_id AS policy1_node_id,
579
    cp1.version AS policy1_version,
580
    cp1.timelock AS policy1_timelock,
581
    cp1.fee_ppm AS policy1_fee_ppm,
582
    cp1.base_fee_msat AS policy1_base_fee_msat,
583
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
584
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
585
    cp1.last_update AS policy1_last_update,
586
    cp1.disabled AS policy1_disabled,
587
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
588
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
589
    cp1.message_flags AS policy1_message_flags,
590
    cp1.channel_flags AS policy1_channel_flags,
591
    cp1.signature AS policy1_signature,
592
    cp1.block_height AS policy1_block_height,
593
    cp1.disable_flags AS policy1_disable_flags,
594

595
    -- Policy 2
596
    cp2.id AS policy2_id,
597
    cp2.node_id AS policy2_node_id,
598
    cp2.version AS policy2_version,
599
    cp2.timelock AS policy2_timelock,
600
    cp2.fee_ppm AS policy2_fee_ppm,
601
    cp2.base_fee_msat AS policy2_base_fee_msat,
602
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
603
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
604
    cp2.last_update AS policy2_last_update,
605
    cp2.disabled AS policy2_disabled,
606
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
607
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
608
    cp2.message_flags AS policy_2_message_flags,
609
    cp2.channel_flags AS policy_2_channel_flags,
610
    cp2.signature AS policy2_signature,
611
    cp2.block_height AS policy2_block_height,
612
    cp2.disable_flags AS policy2_disable_flags
613

614
FROM graph_channels c
615
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
616
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
617
    LEFT JOIN graph_channel_policies cp1
618
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
619
    LEFT JOIN graph_channel_policies cp2
620
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
621
WHERE c.scid = $1
622
  AND c.version = $2
623
`
624

625
type GetChannelBySCIDWithPoliciesParams struct {
626
        Scid    []byte
627
        Version int16
628
}
629

630
type GetChannelBySCIDWithPoliciesRow struct {
631
        GraphChannel                   GraphChannel
632
        GraphNode                      GraphNode
633
        GraphNode_2                    GraphNode
634
        Policy1ID                      sql.NullInt64
635
        Policy1NodeID                  sql.NullInt64
636
        Policy1Version                 sql.NullInt16
637
        Policy1Timelock                sql.NullInt32
638
        Policy1FeePpm                  sql.NullInt64
639
        Policy1BaseFeeMsat             sql.NullInt64
640
        Policy1MinHtlcMsat             sql.NullInt64
641
        Policy1MaxHtlcMsat             sql.NullInt64
642
        Policy1LastUpdate              sql.NullInt64
643
        Policy1Disabled                sql.NullBool
644
        Policy1InboundBaseFeeMsat      sql.NullInt64
645
        Policy1InboundFeeRateMilliMsat sql.NullInt64
646
        Policy1MessageFlags            sql.NullInt16
647
        Policy1ChannelFlags            sql.NullInt16
648
        Policy1Signature               []byte
649
        Policy1BlockHeight             sql.NullInt64
650
        Policy1DisableFlags            sql.NullInt16
651
        Policy2ID                      sql.NullInt64
652
        Policy2NodeID                  sql.NullInt64
653
        Policy2Version                 sql.NullInt16
654
        Policy2Timelock                sql.NullInt32
655
        Policy2FeePpm                  sql.NullInt64
656
        Policy2BaseFeeMsat             sql.NullInt64
657
        Policy2MinHtlcMsat             sql.NullInt64
658
        Policy2MaxHtlcMsat             sql.NullInt64
659
        Policy2LastUpdate              sql.NullInt64
660
        Policy2Disabled                sql.NullBool
661
        Policy2InboundBaseFeeMsat      sql.NullInt64
662
        Policy2InboundFeeRateMilliMsat sql.NullInt64
663
        Policy2MessageFlags            sql.NullInt16
664
        Policy2ChannelFlags            sql.NullInt16
665
        Policy2Signature               []byte
666
        Policy2BlockHeight             sql.NullInt64
667
        Policy2DisableFlags            sql.NullInt16
668
}
669

670
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
671
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
672
        var i GetChannelBySCIDWithPoliciesRow
×
673
        err := row.Scan(
×
674
                &i.GraphChannel.ID,
×
675
                &i.GraphChannel.Version,
×
676
                &i.GraphChannel.Scid,
×
677
                &i.GraphChannel.NodeID1,
×
678
                &i.GraphChannel.NodeID2,
×
679
                &i.GraphChannel.Outpoint,
×
680
                &i.GraphChannel.Capacity,
×
681
                &i.GraphChannel.BitcoinKey1,
×
682
                &i.GraphChannel.BitcoinKey2,
×
683
                &i.GraphChannel.Node1Signature,
×
684
                &i.GraphChannel.Node2Signature,
×
685
                &i.GraphChannel.Bitcoin1Signature,
×
686
                &i.GraphChannel.Bitcoin2Signature,
×
687
                &i.GraphChannel.Signature,
×
688
                &i.GraphChannel.FundingPkScript,
×
689
                &i.GraphChannel.MerkleRootHash,
×
690
                &i.GraphNode.ID,
×
691
                &i.GraphNode.Version,
×
692
                &i.GraphNode.PubKey,
×
693
                &i.GraphNode.Alias,
×
694
                &i.GraphNode.LastUpdate,
×
695
                &i.GraphNode.Color,
×
696
                &i.GraphNode.Signature,
×
697
                &i.GraphNode.BlockHeight,
×
698
                &i.GraphNode_2.ID,
×
699
                &i.GraphNode_2.Version,
×
700
                &i.GraphNode_2.PubKey,
×
701
                &i.GraphNode_2.Alias,
×
702
                &i.GraphNode_2.LastUpdate,
×
703
                &i.GraphNode_2.Color,
×
704
                &i.GraphNode_2.Signature,
×
705
                &i.GraphNode_2.BlockHeight,
×
706
                &i.Policy1ID,
×
707
                &i.Policy1NodeID,
×
708
                &i.Policy1Version,
×
709
                &i.Policy1Timelock,
×
710
                &i.Policy1FeePpm,
×
711
                &i.Policy1BaseFeeMsat,
×
712
                &i.Policy1MinHtlcMsat,
×
713
                &i.Policy1MaxHtlcMsat,
×
714
                &i.Policy1LastUpdate,
×
715
                &i.Policy1Disabled,
×
716
                &i.Policy1InboundBaseFeeMsat,
×
717
                &i.Policy1InboundFeeRateMilliMsat,
×
718
                &i.Policy1MessageFlags,
×
719
                &i.Policy1ChannelFlags,
×
720
                &i.Policy1Signature,
×
721
                &i.Policy1BlockHeight,
×
722
                &i.Policy1DisableFlags,
×
723
                &i.Policy2ID,
×
724
                &i.Policy2NodeID,
×
725
                &i.Policy2Version,
×
726
                &i.Policy2Timelock,
×
727
                &i.Policy2FeePpm,
×
728
                &i.Policy2BaseFeeMsat,
×
729
                &i.Policy2MinHtlcMsat,
×
730
                &i.Policy2MaxHtlcMsat,
×
731
                &i.Policy2LastUpdate,
×
732
                &i.Policy2Disabled,
×
733
                &i.Policy2InboundBaseFeeMsat,
×
734
                &i.Policy2InboundFeeRateMilliMsat,
×
735
                &i.Policy2MessageFlags,
×
736
                &i.Policy2ChannelFlags,
×
737
                &i.Policy2Signature,
×
738
                &i.Policy2BlockHeight,
×
739
                &i.Policy2DisableFlags,
×
740
        )
×
741
        return i, err
×
742
}
×
743

744
const getChannelExtrasBatch = `-- name: GetChannelExtrasBatch :many
745
SELECT
746
    channel_id,
747
    type,
748
    value
749
FROM graph_channel_extra_types
750
WHERE channel_id IN (/*SLICE:chan_ids*/?)
751
ORDER BY channel_id, type
752
`
753

754
func (q *Queries) GetChannelExtrasBatch(ctx context.Context, chanIds []int64) ([]GraphChannelExtraType, error) {
×
755
        query := getChannelExtrasBatch
×
756
        var queryParams []interface{}
×
757
        if len(chanIds) > 0 {
×
758
                for _, v := range chanIds {
×
759
                        queryParams = append(queryParams, v)
×
760
                }
×
761
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", makeQueryParams(len(queryParams), len(chanIds)), 1)
×
762
        } else {
×
763
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", "NULL", 1)
×
764
        }
×
765
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
766
        if err != nil {
×
767
                return nil, err
×
768
        }
×
769
        defer rows.Close()
×
770
        var items []GraphChannelExtraType
×
771
        for rows.Next() {
×
772
                var i GraphChannelExtraType
×
773
                if err := rows.Scan(&i.ChannelID, &i.Type, &i.Value); err != nil {
×
774
                        return nil, err
×
775
                }
×
776
                items = append(items, i)
×
777
        }
778
        if err := rows.Close(); err != nil {
×
779
                return nil, err
×
780
        }
×
781
        if err := rows.Err(); err != nil {
×
782
                return nil, err
×
783
        }
×
784
        return items, nil
×
785
}
786

787
const getChannelFeaturesBatch = `-- name: GetChannelFeaturesBatch :many
788
SELECT
789
    channel_id,
790
    feature_bit
791
FROM graph_channel_features
792
WHERE channel_id IN (/*SLICE:chan_ids*/?)
793
ORDER BY channel_id, feature_bit
794
`
795

796
func (q *Queries) GetChannelFeaturesBatch(ctx context.Context, chanIds []int64) ([]GraphChannelFeature, error) {
×
797
        query := getChannelFeaturesBatch
×
798
        var queryParams []interface{}
×
799
        if len(chanIds) > 0 {
×
800
                for _, v := range chanIds {
×
801
                        queryParams = append(queryParams, v)
×
802
                }
×
803
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", makeQueryParams(len(queryParams), len(chanIds)), 1)
×
804
        } else {
×
805
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", "NULL", 1)
×
806
        }
×
807
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
808
        if err != nil {
×
809
                return nil, err
×
810
        }
×
811
        defer rows.Close()
×
812
        var items []GraphChannelFeature
×
813
        for rows.Next() {
×
814
                var i GraphChannelFeature
×
815
                if err := rows.Scan(&i.ChannelID, &i.FeatureBit); err != nil {
×
816
                        return nil, err
×
817
                }
×
818
                items = append(items, i)
×
819
        }
820
        if err := rows.Close(); err != nil {
×
821
                return nil, err
×
822
        }
×
823
        if err := rows.Err(); err != nil {
×
824
                return nil, err
×
825
        }
×
826
        return items, nil
×
827
}
828

829
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
830
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, block_height, disable_flags
831
FROM graph_channel_policies
832
WHERE channel_id = $1
833
  AND node_id = $2
834
  AND version = $3
835
`
836

837
type GetChannelPolicyByChannelAndNodeParams struct {
838
        ChannelID int64
839
        NodeID    int64
840
        Version   int16
841
}
842

843
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (GraphChannelPolicy, error) {
×
844
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
845
        var i GraphChannelPolicy
×
846
        err := row.Scan(
×
847
                &i.ID,
×
848
                &i.Version,
×
849
                &i.ChannelID,
×
850
                &i.NodeID,
×
851
                &i.Timelock,
×
852
                &i.FeePpm,
×
853
                &i.BaseFeeMsat,
×
854
                &i.MinHtlcMsat,
×
855
                &i.MaxHtlcMsat,
×
856
                &i.LastUpdate,
×
857
                &i.Disabled,
×
858
                &i.InboundBaseFeeMsat,
×
859
                &i.InboundFeeRateMilliMsat,
×
860
                &i.MessageFlags,
×
861
                &i.ChannelFlags,
×
862
                &i.Signature,
×
863
                &i.BlockHeight,
×
864
                &i.DisableFlags,
×
865
        )
×
866
        return i, err
×
867
}
×
868

869
const getChannelPolicyExtraTypesBatch = `-- name: GetChannelPolicyExtraTypesBatch :many
870
SELECT
871
    channel_policy_id as policy_id,
872
    type,
873
    value
874
FROM graph_channel_policy_extra_types
875
WHERE channel_policy_id IN (/*SLICE:policy_ids*/?)
876
ORDER BY channel_policy_id, type
877
`
878

879
type GetChannelPolicyExtraTypesBatchRow struct {
880
        PolicyID int64
881
        Type     int64
882
        Value    []byte
883
}
884

885
func (q *Queries) GetChannelPolicyExtraTypesBatch(ctx context.Context, policyIds []int64) ([]GetChannelPolicyExtraTypesBatchRow, error) {
×
886
        query := getChannelPolicyExtraTypesBatch
×
887
        var queryParams []interface{}
×
888
        if len(policyIds) > 0 {
×
889
                for _, v := range policyIds {
×
890
                        queryParams = append(queryParams, v)
×
891
                }
×
892
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", makeQueryParams(len(queryParams), len(policyIds)), 1)
×
893
        } else {
×
894
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", "NULL", 1)
×
895
        }
×
896
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
897
        if err != nil {
×
898
                return nil, err
×
899
        }
×
900
        defer rows.Close()
×
901
        var items []GetChannelPolicyExtraTypesBatchRow
×
902
        for rows.Next() {
×
903
                var i GetChannelPolicyExtraTypesBatchRow
×
904
                if err := rows.Scan(&i.PolicyID, &i.Type, &i.Value); err != nil {
×
905
                        return nil, err
×
906
                }
×
907
                items = append(items, i)
×
908
        }
909
        if err := rows.Close(); err != nil {
×
910
                return nil, err
×
911
        }
×
912
        if err := rows.Err(); err != nil {
×
913
                return nil, err
×
914
        }
×
915
        return items, nil
×
916
}
917

918
const getChannelsByIDs = `-- name: GetChannelsByIDs :many
919
SELECT
920
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
921

922
    -- Minimal node data.
923
    n1.id AS node1_id,
924
    n1.pub_key AS node1_pub_key,
925
    n2.id AS node2_id,
926
    n2.pub_key AS node2_pub_key,
927

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

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

966
FROM graph_channels c
967
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
968
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
969
    LEFT JOIN graph_channel_policies cp1
970
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
971
    LEFT JOIN graph_channel_policies cp2
972
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
973
WHERE c.id IN (/*SLICE:ids*/?)
974
`
975

976
type GetChannelsByIDsRow struct {
977
        GraphChannel                   GraphChannel
978
        Node1ID                        int64
979
        Node1PubKey                    []byte
980
        Node2ID                        int64
981
        Node2PubKey                    []byte
982
        Policy1ID                      sql.NullInt64
983
        Policy1NodeID                  sql.NullInt64
984
        Policy1Version                 sql.NullInt16
985
        Policy1Timelock                sql.NullInt32
986
        Policy1FeePpm                  sql.NullInt64
987
        Policy1BaseFeeMsat             sql.NullInt64
988
        Policy1MinHtlcMsat             sql.NullInt64
989
        Policy1MaxHtlcMsat             sql.NullInt64
990
        Policy1LastUpdate              sql.NullInt64
991
        Policy1Disabled                sql.NullBool
992
        Policy1InboundBaseFeeMsat      sql.NullInt64
993
        Policy1InboundFeeRateMilliMsat sql.NullInt64
994
        Policy1MessageFlags            sql.NullInt16
995
        Policy1ChannelFlags            sql.NullInt16
996
        Policy1Signature               []byte
997
        Policy1BlockHeight             sql.NullInt64
998
        Policy1DisableFlags            sql.NullInt16
999
        Policy2ID                      sql.NullInt64
1000
        Policy2NodeID                  sql.NullInt64
1001
        Policy2Version                 sql.NullInt16
1002
        Policy2Timelock                sql.NullInt32
1003
        Policy2FeePpm                  sql.NullInt64
1004
        Policy2BaseFeeMsat             sql.NullInt64
1005
        Policy2MinHtlcMsat             sql.NullInt64
1006
        Policy2MaxHtlcMsat             sql.NullInt64
1007
        Policy2LastUpdate              sql.NullInt64
1008
        Policy2Disabled                sql.NullBool
1009
        Policy2InboundBaseFeeMsat      sql.NullInt64
1010
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1011
        Policy2MessageFlags            sql.NullInt16
1012
        Policy2ChannelFlags            sql.NullInt16
1013
        Policy2Signature               []byte
1014
        Policy2BlockHeight             sql.NullInt64
1015
        Policy2DisableFlags            sql.NullInt16
1016
}
1017

1018
func (q *Queries) GetChannelsByIDs(ctx context.Context, ids []int64) ([]GetChannelsByIDsRow, error) {
×
1019
        query := getChannelsByIDs
×
1020
        var queryParams []interface{}
×
1021
        if len(ids) > 0 {
×
1022
                for _, v := range ids {
×
1023
                        queryParams = append(queryParams, v)
×
1024
                }
×
1025
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1026
        } else {
×
1027
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1028
        }
×
1029
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1030
        if err != nil {
×
1031
                return nil, err
×
1032
        }
×
1033
        defer rows.Close()
×
1034
        var items []GetChannelsByIDsRow
×
1035
        for rows.Next() {
×
1036
                var i GetChannelsByIDsRow
×
1037
                if err := rows.Scan(
×
1038
                        &i.GraphChannel.ID,
×
1039
                        &i.GraphChannel.Version,
×
1040
                        &i.GraphChannel.Scid,
×
1041
                        &i.GraphChannel.NodeID1,
×
1042
                        &i.GraphChannel.NodeID2,
×
1043
                        &i.GraphChannel.Outpoint,
×
1044
                        &i.GraphChannel.Capacity,
×
1045
                        &i.GraphChannel.BitcoinKey1,
×
1046
                        &i.GraphChannel.BitcoinKey2,
×
1047
                        &i.GraphChannel.Node1Signature,
×
1048
                        &i.GraphChannel.Node2Signature,
×
1049
                        &i.GraphChannel.Bitcoin1Signature,
×
1050
                        &i.GraphChannel.Bitcoin2Signature,
×
1051
                        &i.GraphChannel.Signature,
×
1052
                        &i.GraphChannel.FundingPkScript,
×
1053
                        &i.GraphChannel.MerkleRootHash,
×
1054
                        &i.Node1ID,
×
1055
                        &i.Node1PubKey,
×
1056
                        &i.Node2ID,
×
1057
                        &i.Node2PubKey,
×
1058
                        &i.Policy1ID,
×
1059
                        &i.Policy1NodeID,
×
1060
                        &i.Policy1Version,
×
1061
                        &i.Policy1Timelock,
×
1062
                        &i.Policy1FeePpm,
×
1063
                        &i.Policy1BaseFeeMsat,
×
1064
                        &i.Policy1MinHtlcMsat,
×
1065
                        &i.Policy1MaxHtlcMsat,
×
1066
                        &i.Policy1LastUpdate,
×
1067
                        &i.Policy1Disabled,
×
1068
                        &i.Policy1InboundBaseFeeMsat,
×
1069
                        &i.Policy1InboundFeeRateMilliMsat,
×
1070
                        &i.Policy1MessageFlags,
×
1071
                        &i.Policy1ChannelFlags,
×
1072
                        &i.Policy1Signature,
×
1073
                        &i.Policy1BlockHeight,
×
1074
                        &i.Policy1DisableFlags,
×
1075
                        &i.Policy2ID,
×
1076
                        &i.Policy2NodeID,
×
1077
                        &i.Policy2Version,
×
1078
                        &i.Policy2Timelock,
×
1079
                        &i.Policy2FeePpm,
×
1080
                        &i.Policy2BaseFeeMsat,
×
1081
                        &i.Policy2MinHtlcMsat,
×
1082
                        &i.Policy2MaxHtlcMsat,
×
1083
                        &i.Policy2LastUpdate,
×
1084
                        &i.Policy2Disabled,
×
1085
                        &i.Policy2InboundBaseFeeMsat,
×
1086
                        &i.Policy2InboundFeeRateMilliMsat,
×
1087
                        &i.Policy2MessageFlags,
×
1088
                        &i.Policy2ChannelFlags,
×
1089
                        &i.Policy2Signature,
×
1090
                        &i.Policy2BlockHeight,
×
1091
                        &i.Policy2DisableFlags,
×
1092
                ); err != nil {
×
1093
                        return nil, err
×
1094
                }
×
1095
                items = append(items, i)
×
1096
        }
1097
        if err := rows.Close(); err != nil {
×
1098
                return nil, err
×
1099
        }
×
1100
        if err := rows.Err(); err != nil {
×
1101
                return nil, err
×
1102
        }
×
1103
        return items, nil
×
1104
}
1105

1106
const getChannelsByOutpoints = `-- name: GetChannelsByOutpoints :many
1107
SELECT
1108
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
1109
    n1.pub_key AS node1_pubkey,
1110
    n2.pub_key AS node2_pubkey
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 c.outpoint IN
1115
    (/*SLICE:outpoints*/?)
1116
`
1117

1118
type GetChannelsByOutpointsRow struct {
1119
        GraphChannel GraphChannel
1120
        Node1Pubkey  []byte
1121
        Node2Pubkey  []byte
1122
}
1123

1124
func (q *Queries) GetChannelsByOutpoints(ctx context.Context, outpoints []string) ([]GetChannelsByOutpointsRow, error) {
×
1125
        query := getChannelsByOutpoints
×
1126
        var queryParams []interface{}
×
1127
        if len(outpoints) > 0 {
×
1128
                for _, v := range outpoints {
×
1129
                        queryParams = append(queryParams, v)
×
1130
                }
×
1131
                query = strings.Replace(query, "/*SLICE:outpoints*/?", makeQueryParams(len(queryParams), len(outpoints)), 1)
×
1132
        } else {
×
1133
                query = strings.Replace(query, "/*SLICE:outpoints*/?", "NULL", 1)
×
1134
        }
×
1135
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1136
        if err != nil {
×
1137
                return nil, err
×
1138
        }
×
1139
        defer rows.Close()
×
1140
        var items []GetChannelsByOutpointsRow
×
1141
        for rows.Next() {
×
1142
                var i GetChannelsByOutpointsRow
×
1143
                if err := rows.Scan(
×
1144
                        &i.GraphChannel.ID,
×
1145
                        &i.GraphChannel.Version,
×
1146
                        &i.GraphChannel.Scid,
×
1147
                        &i.GraphChannel.NodeID1,
×
1148
                        &i.GraphChannel.NodeID2,
×
1149
                        &i.GraphChannel.Outpoint,
×
1150
                        &i.GraphChannel.Capacity,
×
1151
                        &i.GraphChannel.BitcoinKey1,
×
1152
                        &i.GraphChannel.BitcoinKey2,
×
1153
                        &i.GraphChannel.Node1Signature,
×
1154
                        &i.GraphChannel.Node2Signature,
×
1155
                        &i.GraphChannel.Bitcoin1Signature,
×
1156
                        &i.GraphChannel.Bitcoin2Signature,
×
1157
                        &i.GraphChannel.Signature,
×
1158
                        &i.GraphChannel.FundingPkScript,
×
1159
                        &i.GraphChannel.MerkleRootHash,
×
1160
                        &i.Node1Pubkey,
×
1161
                        &i.Node2Pubkey,
×
1162
                ); err != nil {
×
1163
                        return nil, err
×
1164
                }
×
1165
                items = append(items, i)
×
1166
        }
1167
        if err := rows.Close(); err != nil {
×
1168
                return nil, err
×
1169
        }
×
1170
        if err := rows.Err(); err != nil {
×
1171
                return nil, err
×
1172
        }
×
1173
        return items, nil
×
1174
}
1175

1176
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
1177
SELECT
1178
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
1179
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature, n1.block_height,
1180
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature, n2.block_height,
1181

1182
    -- Policy 1 (node_id_1)
1183
    cp1.id AS policy1_id,
1184
    cp1.node_id AS policy1_node_id,
1185
    cp1.version AS policy1_version,
1186
    cp1.timelock AS policy1_timelock,
1187
    cp1.fee_ppm AS policy1_fee_ppm,
1188
    cp1.base_fee_msat AS policy1_base_fee_msat,
1189
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1190
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1191
    cp1.last_update AS policy1_last_update,
1192
    cp1.disabled AS policy1_disabled,
1193
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1194
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1195
    cp1.message_flags AS policy1_message_flags,
1196
    cp1.channel_flags AS policy1_channel_flags,
1197
    cp1.signature AS policy1_signature,
1198
    cp1.block_height AS policy1_block_height,
1199
    cp1.disable_flags AS policy1_disable_flags,
1200

1201
    -- Policy 2 (node_id_2)
1202
    cp2.id AS policy2_id,
1203
    cp2.node_id AS policy2_node_id,
1204
    cp2.version AS policy2_version,
1205
    cp2.timelock AS policy2_timelock,
1206
    cp2.fee_ppm AS policy2_fee_ppm,
1207
    cp2.base_fee_msat AS policy2_base_fee_msat,
1208
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1209
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1210
    cp2.last_update AS policy2_last_update,
1211
    cp2.disabled AS policy2_disabled,
1212
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1213
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1214
    cp2.message_flags AS policy2_message_flags,
1215
    cp2.channel_flags AS policy2_channel_flags,
1216
    cp2.signature AS policy2_signature,
1217
    cp2.block_height AS policy2_block_height,
1218
    cp2.disable_flags AS policy2_disable_flags
1219

1220
FROM graph_channels c
1221
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1222
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1223
    LEFT JOIN graph_channel_policies cp1
1224
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1225
    LEFT JOIN graph_channel_policies cp2
1226
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1227
WHERE c.version = $1
1228
  AND (
1229
       (cp1.last_update >= $2 AND cp1.last_update < $3)
1230
       OR
1231
       (cp2.last_update >= $2 AND cp2.last_update < $3)
1232
  )
1233
  -- Pagination using compound cursor (max_update_time, id).
1234
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
1235
  AND (
1236
       (CASE
1237
           WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1238
               THEN COALESCE(cp1.last_update, 0)
1239
           ELSE COALESCE(cp2.last_update, 0)
1240
       END > COALESCE($4, -1))
1241
       OR 
1242
       (CASE
1243
           WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1244
               THEN COALESCE(cp1.last_update, 0)
1245
           ELSE COALESCE(cp2.last_update, 0)
1246
       END = COALESCE($4, -1) 
1247
       AND c.id > COALESCE($5, -1))
1248
  )
1249
ORDER BY
1250
    CASE
1251
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1252
            THEN COALESCE(cp1.last_update, 0)
1253
        ELSE COALESCE(cp2.last_update, 0)
1254
    END ASC,
1255
    c.id ASC
1256
LIMIT COALESCE($6, 999999999)
1257
`
1258

1259
type GetChannelsByPolicyLastUpdateRangeParams struct {
1260
        Version        int16
1261
        StartTime      sql.NullInt64
1262
        EndTime        sql.NullInt64
1263
        LastUpdateTime sql.NullInt64
1264
        LastID         sql.NullInt64
1265
        MaxResults     interface{}
1266
}
1267

1268
type GetChannelsByPolicyLastUpdateRangeRow struct {
1269
        GraphChannel                   GraphChannel
1270
        GraphNode                      GraphNode
1271
        GraphNode_2                    GraphNode
1272
        Policy1ID                      sql.NullInt64
1273
        Policy1NodeID                  sql.NullInt64
1274
        Policy1Version                 sql.NullInt16
1275
        Policy1Timelock                sql.NullInt32
1276
        Policy1FeePpm                  sql.NullInt64
1277
        Policy1BaseFeeMsat             sql.NullInt64
1278
        Policy1MinHtlcMsat             sql.NullInt64
1279
        Policy1MaxHtlcMsat             sql.NullInt64
1280
        Policy1LastUpdate              sql.NullInt64
1281
        Policy1Disabled                sql.NullBool
1282
        Policy1InboundBaseFeeMsat      sql.NullInt64
1283
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1284
        Policy1MessageFlags            sql.NullInt16
1285
        Policy1ChannelFlags            sql.NullInt16
1286
        Policy1Signature               []byte
1287
        Policy1BlockHeight             sql.NullInt64
1288
        Policy1DisableFlags            sql.NullInt16
1289
        Policy2ID                      sql.NullInt64
1290
        Policy2NodeID                  sql.NullInt64
1291
        Policy2Version                 sql.NullInt16
1292
        Policy2Timelock                sql.NullInt32
1293
        Policy2FeePpm                  sql.NullInt64
1294
        Policy2BaseFeeMsat             sql.NullInt64
1295
        Policy2MinHtlcMsat             sql.NullInt64
1296
        Policy2MaxHtlcMsat             sql.NullInt64
1297
        Policy2LastUpdate              sql.NullInt64
1298
        Policy2Disabled                sql.NullBool
1299
        Policy2InboundBaseFeeMsat      sql.NullInt64
1300
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1301
        Policy2MessageFlags            sql.NullInt16
1302
        Policy2ChannelFlags            sql.NullInt16
1303
        Policy2Signature               []byte
1304
        Policy2BlockHeight             sql.NullInt64
1305
        Policy2DisableFlags            sql.NullInt16
1306
}
1307

1308
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
1309
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange,
×
1310
                arg.Version,
×
1311
                arg.StartTime,
×
1312
                arg.EndTime,
×
1313
                arg.LastUpdateTime,
×
1314
                arg.LastID,
×
1315
                arg.MaxResults,
×
1316
        )
×
1317
        if err != nil {
×
1318
                return nil, err
×
1319
        }
×
1320
        defer rows.Close()
×
1321
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
1322
        for rows.Next() {
×
1323
                var i GetChannelsByPolicyLastUpdateRangeRow
×
1324
                if err := rows.Scan(
×
1325
                        &i.GraphChannel.ID,
×
1326
                        &i.GraphChannel.Version,
×
1327
                        &i.GraphChannel.Scid,
×
1328
                        &i.GraphChannel.NodeID1,
×
1329
                        &i.GraphChannel.NodeID2,
×
1330
                        &i.GraphChannel.Outpoint,
×
1331
                        &i.GraphChannel.Capacity,
×
1332
                        &i.GraphChannel.BitcoinKey1,
×
1333
                        &i.GraphChannel.BitcoinKey2,
×
1334
                        &i.GraphChannel.Node1Signature,
×
1335
                        &i.GraphChannel.Node2Signature,
×
1336
                        &i.GraphChannel.Bitcoin1Signature,
×
1337
                        &i.GraphChannel.Bitcoin2Signature,
×
1338
                        &i.GraphChannel.Signature,
×
1339
                        &i.GraphChannel.FundingPkScript,
×
1340
                        &i.GraphChannel.MerkleRootHash,
×
1341
                        &i.GraphNode.ID,
×
1342
                        &i.GraphNode.Version,
×
1343
                        &i.GraphNode.PubKey,
×
1344
                        &i.GraphNode.Alias,
×
1345
                        &i.GraphNode.LastUpdate,
×
1346
                        &i.GraphNode.Color,
×
1347
                        &i.GraphNode.Signature,
×
1348
                        &i.GraphNode.BlockHeight,
×
1349
                        &i.GraphNode_2.ID,
×
1350
                        &i.GraphNode_2.Version,
×
1351
                        &i.GraphNode_2.PubKey,
×
1352
                        &i.GraphNode_2.Alias,
×
1353
                        &i.GraphNode_2.LastUpdate,
×
1354
                        &i.GraphNode_2.Color,
×
1355
                        &i.GraphNode_2.Signature,
×
1356
                        &i.GraphNode_2.BlockHeight,
×
1357
                        &i.Policy1ID,
×
1358
                        &i.Policy1NodeID,
×
1359
                        &i.Policy1Version,
×
1360
                        &i.Policy1Timelock,
×
1361
                        &i.Policy1FeePpm,
×
1362
                        &i.Policy1BaseFeeMsat,
×
1363
                        &i.Policy1MinHtlcMsat,
×
1364
                        &i.Policy1MaxHtlcMsat,
×
1365
                        &i.Policy1LastUpdate,
×
1366
                        &i.Policy1Disabled,
×
1367
                        &i.Policy1InboundBaseFeeMsat,
×
1368
                        &i.Policy1InboundFeeRateMilliMsat,
×
1369
                        &i.Policy1MessageFlags,
×
1370
                        &i.Policy1ChannelFlags,
×
1371
                        &i.Policy1Signature,
×
1372
                        &i.Policy1BlockHeight,
×
1373
                        &i.Policy1DisableFlags,
×
1374
                        &i.Policy2ID,
×
1375
                        &i.Policy2NodeID,
×
1376
                        &i.Policy2Version,
×
1377
                        &i.Policy2Timelock,
×
1378
                        &i.Policy2FeePpm,
×
1379
                        &i.Policy2BaseFeeMsat,
×
1380
                        &i.Policy2MinHtlcMsat,
×
1381
                        &i.Policy2MaxHtlcMsat,
×
1382
                        &i.Policy2LastUpdate,
×
1383
                        &i.Policy2Disabled,
×
1384
                        &i.Policy2InboundBaseFeeMsat,
×
1385
                        &i.Policy2InboundFeeRateMilliMsat,
×
1386
                        &i.Policy2MessageFlags,
×
1387
                        &i.Policy2ChannelFlags,
×
1388
                        &i.Policy2Signature,
×
1389
                        &i.Policy2BlockHeight,
×
1390
                        &i.Policy2DisableFlags,
×
1391
                ); err != nil {
×
1392
                        return nil, err
×
1393
                }
×
1394
                items = append(items, i)
×
1395
        }
1396
        if err := rows.Close(); err != nil {
×
1397
                return nil, err
×
1398
        }
×
1399
        if err := rows.Err(); err != nil {
×
1400
                return nil, err
×
1401
        }
×
1402
        return items, nil
×
1403
}
1404

1405
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1406
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, c.signature, c.funding_pk_script, c.merkle_root_hash,
1407
    n1.pub_key AS node1_pub_key,
1408
    n2.pub_key AS node2_pub_key
1409
FROM graph_channels c
1410
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1411
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1412
WHERE scid >= $1
1413
  AND scid < $2
1414
`
1415

1416
type GetChannelsBySCIDRangeParams struct {
1417
        StartScid []byte
1418
        EndScid   []byte
1419
}
1420

1421
type GetChannelsBySCIDRangeRow struct {
1422
        GraphChannel GraphChannel
1423
        Node1PubKey  []byte
1424
        Node2PubKey  []byte
1425
}
1426

1427
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1428
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1429
        if err != nil {
×
1430
                return nil, err
×
1431
        }
×
1432
        defer rows.Close()
×
1433
        var items []GetChannelsBySCIDRangeRow
×
1434
        for rows.Next() {
×
1435
                var i GetChannelsBySCIDRangeRow
×
1436
                if err := rows.Scan(
×
1437
                        &i.GraphChannel.ID,
×
1438
                        &i.GraphChannel.Version,
×
1439
                        &i.GraphChannel.Scid,
×
1440
                        &i.GraphChannel.NodeID1,
×
1441
                        &i.GraphChannel.NodeID2,
×
1442
                        &i.GraphChannel.Outpoint,
×
1443
                        &i.GraphChannel.Capacity,
×
1444
                        &i.GraphChannel.BitcoinKey1,
×
1445
                        &i.GraphChannel.BitcoinKey2,
×
1446
                        &i.GraphChannel.Node1Signature,
×
1447
                        &i.GraphChannel.Node2Signature,
×
1448
                        &i.GraphChannel.Bitcoin1Signature,
×
1449
                        &i.GraphChannel.Bitcoin2Signature,
×
1450
                        &i.GraphChannel.Signature,
×
1451
                        &i.GraphChannel.FundingPkScript,
×
1452
                        &i.GraphChannel.MerkleRootHash,
×
1453
                        &i.Node1PubKey,
×
1454
                        &i.Node2PubKey,
×
1455
                ); err != nil {
×
1456
                        return nil, err
×
1457
                }
×
1458
                items = append(items, i)
×
1459
        }
1460
        if err := rows.Close(); err != nil {
×
1461
                return nil, err
×
1462
        }
×
1463
        if err := rows.Err(); err != nil {
×
1464
                return nil, err
×
1465
        }
×
1466
        return items, nil
×
1467
}
1468

1469
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1470
SELECT
1471
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
1472
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature, n1.block_height,
1473
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature, n2.block_height,
1474

1475
    -- Policy 1
1476
    cp1.id AS policy1_id,
1477
    cp1.node_id AS policy1_node_id,
1478
    cp1.version AS policy1_version,
1479
    cp1.timelock AS policy1_timelock,
1480
    cp1.fee_ppm AS policy1_fee_ppm,
1481
    cp1.base_fee_msat AS policy1_base_fee_msat,
1482
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1483
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1484
    cp1.last_update AS policy1_last_update,
1485
    cp1.disabled AS policy1_disabled,
1486
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1487
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1488
    cp1.message_flags AS policy1_message_flags,
1489
    cp1.channel_flags AS policy1_channel_flags,
1490
    cp1.signature AS policy1_signature,
1491
    cp1.block_height AS policy1_block_height,
1492
    cp1.disable_flags AS policy1_disable_flags,
1493

1494
    -- Policy 2
1495
    cp2.id AS policy2_id,
1496
    cp2.node_id AS policy2_node_id,
1497
    cp2.version AS policy2_version,
1498
    cp2.timelock AS policy2_timelock,
1499
    cp2.fee_ppm AS policy2_fee_ppm,
1500
    cp2.base_fee_msat AS policy2_base_fee_msat,
1501
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1502
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1503
    cp2.last_update AS policy2_last_update,
1504
    cp2.disabled AS policy2_disabled,
1505
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1506
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1507
    cp2.message_flags AS policy_2_message_flags,
1508
    cp2.channel_flags AS policy_2_channel_flags,
1509
    cp2.signature AS policy2_signature,
1510
    cp2.block_height AS policy2_block_height,
1511
    cp2.disable_flags AS policy2_disable_flags
1512

1513
FROM graph_channels c
1514
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1515
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1516
    LEFT JOIN graph_channel_policies cp1
1517
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1518
    LEFT JOIN graph_channel_policies cp2
1519
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1520
WHERE
1521
    c.version = $1
1522
  AND c.scid IN (/*SLICE:scids*/?)
1523
`
1524

1525
type GetChannelsBySCIDWithPoliciesParams struct {
1526
        Version int16
1527
        Scids   [][]byte
1528
}
1529

1530
type GetChannelsBySCIDWithPoliciesRow struct {
1531
        GraphChannel                   GraphChannel
1532
        GraphNode                      GraphNode
1533
        GraphNode_2                    GraphNode
1534
        Policy1ID                      sql.NullInt64
1535
        Policy1NodeID                  sql.NullInt64
1536
        Policy1Version                 sql.NullInt16
1537
        Policy1Timelock                sql.NullInt32
1538
        Policy1FeePpm                  sql.NullInt64
1539
        Policy1BaseFeeMsat             sql.NullInt64
1540
        Policy1MinHtlcMsat             sql.NullInt64
1541
        Policy1MaxHtlcMsat             sql.NullInt64
1542
        Policy1LastUpdate              sql.NullInt64
1543
        Policy1Disabled                sql.NullBool
1544
        Policy1InboundBaseFeeMsat      sql.NullInt64
1545
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1546
        Policy1MessageFlags            sql.NullInt16
1547
        Policy1ChannelFlags            sql.NullInt16
1548
        Policy1Signature               []byte
1549
        Policy1BlockHeight             sql.NullInt64
1550
        Policy1DisableFlags            sql.NullInt16
1551
        Policy2ID                      sql.NullInt64
1552
        Policy2NodeID                  sql.NullInt64
1553
        Policy2Version                 sql.NullInt16
1554
        Policy2Timelock                sql.NullInt32
1555
        Policy2FeePpm                  sql.NullInt64
1556
        Policy2BaseFeeMsat             sql.NullInt64
1557
        Policy2MinHtlcMsat             sql.NullInt64
1558
        Policy2MaxHtlcMsat             sql.NullInt64
1559
        Policy2LastUpdate              sql.NullInt64
1560
        Policy2Disabled                sql.NullBool
1561
        Policy2InboundBaseFeeMsat      sql.NullInt64
1562
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1563
        Policy2MessageFlags            sql.NullInt16
1564
        Policy2ChannelFlags            sql.NullInt16
1565
        Policy2Signature               []byte
1566
        Policy2BlockHeight             sql.NullInt64
1567
        Policy2DisableFlags            sql.NullInt16
1568
}
1569

1570
func (q *Queries) GetChannelsBySCIDWithPolicies(ctx context.Context, arg GetChannelsBySCIDWithPoliciesParams) ([]GetChannelsBySCIDWithPoliciesRow, error) {
×
1571
        query := getChannelsBySCIDWithPolicies
×
1572
        var queryParams []interface{}
×
1573
        queryParams = append(queryParams, arg.Version)
×
1574
        if len(arg.Scids) > 0 {
×
1575
                for _, v := range arg.Scids {
×
1576
                        queryParams = append(queryParams, v)
×
1577
                }
×
1578
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1579
        } else {
×
1580
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1581
        }
×
1582
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1583
        if err != nil {
×
1584
                return nil, err
×
1585
        }
×
1586
        defer rows.Close()
×
1587
        var items []GetChannelsBySCIDWithPoliciesRow
×
1588
        for rows.Next() {
×
1589
                var i GetChannelsBySCIDWithPoliciesRow
×
1590
                if err := rows.Scan(
×
1591
                        &i.GraphChannel.ID,
×
1592
                        &i.GraphChannel.Version,
×
1593
                        &i.GraphChannel.Scid,
×
1594
                        &i.GraphChannel.NodeID1,
×
1595
                        &i.GraphChannel.NodeID2,
×
1596
                        &i.GraphChannel.Outpoint,
×
1597
                        &i.GraphChannel.Capacity,
×
1598
                        &i.GraphChannel.BitcoinKey1,
×
1599
                        &i.GraphChannel.BitcoinKey2,
×
1600
                        &i.GraphChannel.Node1Signature,
×
1601
                        &i.GraphChannel.Node2Signature,
×
1602
                        &i.GraphChannel.Bitcoin1Signature,
×
1603
                        &i.GraphChannel.Bitcoin2Signature,
×
1604
                        &i.GraphChannel.Signature,
×
1605
                        &i.GraphChannel.FundingPkScript,
×
1606
                        &i.GraphChannel.MerkleRootHash,
×
1607
                        &i.GraphNode.ID,
×
1608
                        &i.GraphNode.Version,
×
1609
                        &i.GraphNode.PubKey,
×
1610
                        &i.GraphNode.Alias,
×
1611
                        &i.GraphNode.LastUpdate,
×
1612
                        &i.GraphNode.Color,
×
1613
                        &i.GraphNode.Signature,
×
1614
                        &i.GraphNode.BlockHeight,
×
1615
                        &i.GraphNode_2.ID,
×
1616
                        &i.GraphNode_2.Version,
×
1617
                        &i.GraphNode_2.PubKey,
×
1618
                        &i.GraphNode_2.Alias,
×
1619
                        &i.GraphNode_2.LastUpdate,
×
1620
                        &i.GraphNode_2.Color,
×
1621
                        &i.GraphNode_2.Signature,
×
1622
                        &i.GraphNode_2.BlockHeight,
×
1623
                        &i.Policy1ID,
×
1624
                        &i.Policy1NodeID,
×
1625
                        &i.Policy1Version,
×
1626
                        &i.Policy1Timelock,
×
1627
                        &i.Policy1FeePpm,
×
1628
                        &i.Policy1BaseFeeMsat,
×
1629
                        &i.Policy1MinHtlcMsat,
×
1630
                        &i.Policy1MaxHtlcMsat,
×
1631
                        &i.Policy1LastUpdate,
×
1632
                        &i.Policy1Disabled,
×
1633
                        &i.Policy1InboundBaseFeeMsat,
×
1634
                        &i.Policy1InboundFeeRateMilliMsat,
×
1635
                        &i.Policy1MessageFlags,
×
1636
                        &i.Policy1ChannelFlags,
×
1637
                        &i.Policy1Signature,
×
1638
                        &i.Policy1BlockHeight,
×
1639
                        &i.Policy1DisableFlags,
×
1640
                        &i.Policy2ID,
×
1641
                        &i.Policy2NodeID,
×
1642
                        &i.Policy2Version,
×
1643
                        &i.Policy2Timelock,
×
1644
                        &i.Policy2FeePpm,
×
1645
                        &i.Policy2BaseFeeMsat,
×
1646
                        &i.Policy2MinHtlcMsat,
×
1647
                        &i.Policy2MaxHtlcMsat,
×
1648
                        &i.Policy2LastUpdate,
×
1649
                        &i.Policy2Disabled,
×
1650
                        &i.Policy2InboundBaseFeeMsat,
×
1651
                        &i.Policy2InboundFeeRateMilliMsat,
×
1652
                        &i.Policy2MessageFlags,
×
1653
                        &i.Policy2ChannelFlags,
×
1654
                        &i.Policy2Signature,
×
1655
                        &i.Policy2BlockHeight,
×
1656
                        &i.Policy2DisableFlags,
×
1657
                ); err != nil {
×
1658
                        return nil, err
×
1659
                }
×
1660
                items = append(items, i)
×
1661
        }
1662
        if err := rows.Close(); err != nil {
×
1663
                return nil, err
×
1664
        }
×
1665
        if err := rows.Err(); err != nil {
×
1666
                return nil, err
×
1667
        }
×
1668
        return items, nil
×
1669
}
1670

1671
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1672
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, signature, funding_pk_script, merkle_root_hash FROM graph_channels
1673
WHERE version = $1
1674
  AND scid IN (/*SLICE:scids*/?)
1675
`
1676

1677
type GetChannelsBySCIDsParams struct {
1678
        Version int16
1679
        Scids   [][]byte
1680
}
1681

1682
func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error) {
×
1683
        query := getChannelsBySCIDs
×
1684
        var queryParams []interface{}
×
1685
        queryParams = append(queryParams, arg.Version)
×
1686
        if len(arg.Scids) > 0 {
×
1687
                for _, v := range arg.Scids {
×
1688
                        queryParams = append(queryParams, v)
×
1689
                }
×
1690
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1691
        } else {
×
1692
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1693
        }
×
1694
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1695
        if err != nil {
×
1696
                return nil, err
×
1697
        }
×
1698
        defer rows.Close()
×
1699
        var items []GraphChannel
×
1700
        for rows.Next() {
×
1701
                var i GraphChannel
×
1702
                if err := rows.Scan(
×
1703
                        &i.ID,
×
1704
                        &i.Version,
×
1705
                        &i.Scid,
×
1706
                        &i.NodeID1,
×
1707
                        &i.NodeID2,
×
1708
                        &i.Outpoint,
×
1709
                        &i.Capacity,
×
1710
                        &i.BitcoinKey1,
×
1711
                        &i.BitcoinKey2,
×
1712
                        &i.Node1Signature,
×
1713
                        &i.Node2Signature,
×
1714
                        &i.Bitcoin1Signature,
×
1715
                        &i.Bitcoin2Signature,
×
1716
                        &i.Signature,
×
1717
                        &i.FundingPkScript,
×
1718
                        &i.MerkleRootHash,
×
1719
                ); err != nil {
×
1720
                        return nil, err
×
1721
                }
×
1722
                items = append(items, i)
×
1723
        }
1724
        if err := rows.Close(); err != nil {
×
1725
                return nil, err
×
1726
        }
×
1727
        if err := rows.Err(); err != nil {
×
1728
                return nil, err
×
1729
        }
×
1730
        return items, nil
×
1731
}
1732

1733
const getClosedChannelsSCIDs = `-- name: GetClosedChannelsSCIDs :many
1734
SELECT scid
1735
FROM graph_closed_scids
1736
WHERE scid IN (/*SLICE:scids*/?)
1737
`
1738

1739
func (q *Queries) GetClosedChannelsSCIDs(ctx context.Context, scids [][]byte) ([][]byte, error) {
×
1740
        query := getClosedChannelsSCIDs
×
1741
        var queryParams []interface{}
×
1742
        if len(scids) > 0 {
×
1743
                for _, v := range scids {
×
1744
                        queryParams = append(queryParams, v)
×
1745
                }
×
1746
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(scids)), 1)
×
1747
        } else {
×
1748
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1749
        }
×
1750
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1751
        if err != nil {
×
1752
                return nil, err
×
1753
        }
×
1754
        defer rows.Close()
×
1755
        var items [][]byte
×
1756
        for rows.Next() {
×
1757
                var scid []byte
×
1758
                if err := rows.Scan(&scid); err != nil {
×
1759
                        return nil, err
×
1760
                }
×
1761
                items = append(items, scid)
×
1762
        }
1763
        if err := rows.Close(); err != nil {
×
1764
                return nil, err
×
1765
        }
×
1766
        if err := rows.Err(); err != nil {
×
1767
                return nil, err
×
1768
        }
×
1769
        return items, nil
×
1770
}
1771

1772
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1773
SELECT node_id, type, value
1774
FROM graph_node_extra_types
1775
WHERE node_id = $1
1776
`
1777

1778
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) {
×
1779
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1780
        if err != nil {
×
1781
                return nil, err
×
1782
        }
×
1783
        defer rows.Close()
×
1784
        var items []GraphNodeExtraType
×
1785
        for rows.Next() {
×
1786
                var i GraphNodeExtraType
×
1787
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1788
                        return nil, err
×
1789
                }
×
1790
                items = append(items, i)
×
1791
        }
1792
        if err := rows.Close(); err != nil {
×
1793
                return nil, err
×
1794
        }
×
1795
        if err := rows.Err(); err != nil {
×
1796
                return nil, err
×
1797
        }
×
1798
        return items, nil
×
1799
}
1800

1801
const getNodeAddresses = `-- name: GetNodeAddresses :many
1802
SELECT type, address
1803
FROM graph_node_addresses
1804
WHERE node_id = $1
1805
ORDER BY type ASC, position ASC
1806
`
1807

1808
type GetNodeAddressesRow struct {
1809
        Type    int16
1810
        Address string
1811
}
1812

1813
func (q *Queries) GetNodeAddresses(ctx context.Context, nodeID int64) ([]GetNodeAddressesRow, error) {
×
1814
        rows, err := q.db.QueryContext(ctx, getNodeAddresses, nodeID)
×
1815
        if err != nil {
×
1816
                return nil, err
×
1817
        }
×
1818
        defer rows.Close()
×
1819
        var items []GetNodeAddressesRow
×
1820
        for rows.Next() {
×
1821
                var i GetNodeAddressesRow
×
1822
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1823
                        return nil, err
×
1824
                }
×
1825
                items = append(items, i)
×
1826
        }
1827
        if err := rows.Close(); err != nil {
×
1828
                return nil, err
×
1829
        }
×
1830
        if err := rows.Err(); err != nil {
×
1831
                return nil, err
×
1832
        }
×
1833
        return items, nil
×
1834
}
1835

1836
const getNodeAddressesBatch = `-- name: GetNodeAddressesBatch :many
1837
SELECT node_id, type, position, address
1838
FROM graph_node_addresses
1839
WHERE node_id IN (/*SLICE:ids*/?)
1840
ORDER BY node_id, type, position
1841
`
1842

1843
func (q *Queries) GetNodeAddressesBatch(ctx context.Context, ids []int64) ([]GraphNodeAddress, error) {
×
1844
        query := getNodeAddressesBatch
×
1845
        var queryParams []interface{}
×
1846
        if len(ids) > 0 {
×
1847
                for _, v := range ids {
×
1848
                        queryParams = append(queryParams, v)
×
1849
                }
×
1850
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1851
        } else {
×
1852
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1853
        }
×
1854
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1855
        if err != nil {
×
1856
                return nil, err
×
1857
        }
×
1858
        defer rows.Close()
×
1859
        var items []GraphNodeAddress
×
1860
        for rows.Next() {
×
1861
                var i GraphNodeAddress
×
1862
                if err := rows.Scan(
×
1863
                        &i.NodeID,
×
1864
                        &i.Type,
×
1865
                        &i.Position,
×
1866
                        &i.Address,
×
1867
                ); err != nil {
×
1868
                        return nil, err
×
1869
                }
×
1870
                items = append(items, i)
×
1871
        }
1872
        if err := rows.Close(); err != nil {
×
1873
                return nil, err
×
1874
        }
×
1875
        if err := rows.Err(); err != nil {
×
1876
                return nil, err
×
1877
        }
×
1878
        return items, nil
×
1879
}
1880

1881
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1882
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
1883
FROM graph_nodes
1884
WHERE pub_key = $1
1885
  AND version = $2
1886
`
1887

1888
type GetNodeByPubKeyParams struct {
1889
        PubKey  []byte
1890
        Version int16
1891
}
1892

1893
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1894
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1895
        var i GraphNode
×
1896
        err := row.Scan(
×
1897
                &i.ID,
×
1898
                &i.Version,
×
1899
                &i.PubKey,
×
1900
                &i.Alias,
×
1901
                &i.LastUpdate,
×
1902
                &i.Color,
×
1903
                &i.Signature,
×
1904
                &i.BlockHeight,
×
1905
        )
×
1906
        return i, err
×
1907
}
×
1908

1909
const getNodeExtraTypesBatch = `-- name: GetNodeExtraTypesBatch :many
1910
SELECT node_id, type, value
1911
FROM graph_node_extra_types
1912
WHERE node_id IN (/*SLICE:ids*/?)
1913
ORDER BY node_id, type
1914
`
1915

1916
func (q *Queries) GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]GraphNodeExtraType, error) {
×
1917
        query := getNodeExtraTypesBatch
×
1918
        var queryParams []interface{}
×
1919
        if len(ids) > 0 {
×
1920
                for _, v := range ids {
×
1921
                        queryParams = append(queryParams, v)
×
1922
                }
×
1923
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1924
        } else {
×
1925
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1926
        }
×
1927
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1928
        if err != nil {
×
1929
                return nil, err
×
1930
        }
×
1931
        defer rows.Close()
×
1932
        var items []GraphNodeExtraType
×
1933
        for rows.Next() {
×
1934
                var i GraphNodeExtraType
×
1935
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1936
                        return nil, err
×
1937
                }
×
1938
                items = append(items, i)
×
1939
        }
1940
        if err := rows.Close(); err != nil {
×
1941
                return nil, err
×
1942
        }
×
1943
        if err := rows.Err(); err != nil {
×
1944
                return nil, err
×
1945
        }
×
1946
        return items, nil
×
1947
}
1948

1949
const getNodeFeatures = `-- name: GetNodeFeatures :many
1950
SELECT node_id, feature_bit
1951
FROM graph_node_features
1952
WHERE node_id = $1
1953
`
1954

1955
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1956
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1957
        if err != nil {
×
1958
                return nil, err
×
1959
        }
×
1960
        defer rows.Close()
×
1961
        var items []GraphNodeFeature
×
1962
        for rows.Next() {
×
1963
                var i GraphNodeFeature
×
1964
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1965
                        return nil, err
×
1966
                }
×
1967
                items = append(items, i)
×
1968
        }
1969
        if err := rows.Close(); err != nil {
×
1970
                return nil, err
×
1971
        }
×
1972
        if err := rows.Err(); err != nil {
×
1973
                return nil, err
×
1974
        }
×
1975
        return items, nil
×
1976
}
1977

1978
const getNodeFeaturesBatch = `-- name: GetNodeFeaturesBatch :many
1979
SELECT node_id, feature_bit
1980
FROM graph_node_features
1981
WHERE node_id IN (/*SLICE:ids*/?)
1982
ORDER BY node_id, feature_bit
1983
`
1984

1985
func (q *Queries) GetNodeFeaturesBatch(ctx context.Context, ids []int64) ([]GraphNodeFeature, error) {
×
1986
        query := getNodeFeaturesBatch
×
1987
        var queryParams []interface{}
×
1988
        if len(ids) > 0 {
×
1989
                for _, v := range ids {
×
1990
                        queryParams = append(queryParams, v)
×
1991
                }
×
1992
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1993
        } else {
×
1994
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1995
        }
×
1996
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1997
        if err != nil {
×
1998
                return nil, err
×
1999
        }
×
2000
        defer rows.Close()
×
2001
        var items []GraphNodeFeature
×
2002
        for rows.Next() {
×
2003
                var i GraphNodeFeature
×
2004
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
2005
                        return nil, err
×
2006
                }
×
2007
                items = append(items, i)
×
2008
        }
2009
        if err := rows.Close(); err != nil {
×
2010
                return nil, err
×
2011
        }
×
2012
        if err := rows.Err(); err != nil {
×
2013
                return nil, err
×
2014
        }
×
2015
        return items, nil
×
2016
}
2017

2018
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
2019
SELECT f.feature_bit
2020
FROM graph_nodes n
2021
    JOIN graph_node_features f ON f.node_id = n.id
2022
WHERE n.pub_key = $1
2023
  AND n.version = $2
2024
`
2025

2026
type GetNodeFeaturesByPubKeyParams struct {
2027
        PubKey  []byte
2028
        Version int16
2029
}
2030

2031
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
2032
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
2033
        if err != nil {
×
2034
                return nil, err
×
2035
        }
×
2036
        defer rows.Close()
×
2037
        var items []int32
×
2038
        for rows.Next() {
×
2039
                var feature_bit int32
×
2040
                if err := rows.Scan(&feature_bit); err != nil {
×
2041
                        return nil, err
×
2042
                }
×
2043
                items = append(items, feature_bit)
×
2044
        }
2045
        if err := rows.Close(); err != nil {
×
2046
                return nil, err
×
2047
        }
×
2048
        if err := rows.Err(); err != nil {
×
2049
                return nil, err
×
2050
        }
×
2051
        return items, nil
×
2052
}
2053

2054
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
2055
SELECT id
2056
FROM graph_nodes
2057
WHERE pub_key = $1
2058
  AND version = $2
2059
`
2060

2061
type GetNodeIDByPubKeyParams struct {
2062
        PubKey  []byte
2063
        Version int16
2064
}
2065

2066
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
2067
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
2068
        var id int64
×
2069
        err := row.Scan(&id)
×
2070
        return id, err
×
2071
}
×
2072

2073
const getNodesByIDs = `-- name: GetNodesByIDs :many
2074
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2075
FROM graph_nodes
2076
WHERE id IN (/*SLICE:ids*/?)
2077
`
2078

2079
func (q *Queries) GetNodesByIDs(ctx context.Context, ids []int64) ([]GraphNode, error) {
×
2080
        query := getNodesByIDs
×
2081
        var queryParams []interface{}
×
2082
        if len(ids) > 0 {
×
2083
                for _, v := range ids {
×
2084
                        queryParams = append(queryParams, v)
×
2085
                }
×
2086
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
2087
        } else {
×
2088
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
2089
        }
×
2090
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2091
        if err != nil {
×
2092
                return nil, err
×
2093
        }
×
2094
        defer rows.Close()
×
2095
        var items []GraphNode
×
2096
        for rows.Next() {
×
2097
                var i GraphNode
×
2098
                if err := rows.Scan(
×
2099
                        &i.ID,
×
2100
                        &i.Version,
×
2101
                        &i.PubKey,
×
2102
                        &i.Alias,
×
2103
                        &i.LastUpdate,
×
2104
                        &i.Color,
×
2105
                        &i.Signature,
×
2106
                        &i.BlockHeight,
×
2107
                ); err != nil {
×
2108
                        return nil, err
×
2109
                }
×
2110
                items = append(items, i)
×
2111
        }
2112
        if err := rows.Close(); err != nil {
×
2113
                return nil, err
×
2114
        }
×
2115
        if err := rows.Err(); err != nil {
×
2116
                return nil, err
×
2117
        }
×
2118
        return items, nil
×
2119
}
2120

2121
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
2122
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2123
FROM graph_nodes
2124
WHERE last_update >= $1
2125
  AND last_update <= $2
2126
  -- Pagination: We use (last_update, pub_key) as a compound cursor.
2127
  -- This ensures stable ordering and allows us to resume from where we left off.
2128
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
2129
  AND (
2130
    -- Include rows with last_update greater than cursor (or all rows if cursor is -1)
2131
    last_update > COALESCE($3, -1)
2132
    OR 
2133
    -- For rows with same last_update, use pub_key as tiebreaker
2134
    (last_update = COALESCE($3, -1) 
2135
     AND pub_key > $4)
2136
  )
2137
  -- Optional filter for public nodes only
2138
  AND (
2139
    -- If only_public is false or not provided, include all nodes
2140
    COALESCE($5, FALSE) IS FALSE
2141
    OR 
2142
    -- For V1 protocol, a node is public if it has at least one public channel.
2143
    -- A public channel has bitcoin_1_signature set (channel announcement received).
2144
    EXISTS (
2145
      SELECT 1
2146
      FROM graph_channels c
2147
      WHERE c.version = 1
2148
        AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
2149
        AND (c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id)
2150
    )
2151
  )
2152
ORDER BY last_update ASC, pub_key ASC
2153
LIMIT COALESCE($6, 999999999)
2154
`
2155

2156
type GetNodesByLastUpdateRangeParams struct {
2157
        StartTime  sql.NullInt64
2158
        EndTime    sql.NullInt64
2159
        LastUpdate sql.NullInt64
2160
        LastPubKey []byte
2161
        OnlyPublic interface{}
2162
        MaxResults interface{}
2163
}
2164

2165
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
2166
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange,
×
2167
                arg.StartTime,
×
2168
                arg.EndTime,
×
2169
                arg.LastUpdate,
×
2170
                arg.LastPubKey,
×
2171
                arg.OnlyPublic,
×
2172
                arg.MaxResults,
×
2173
        )
×
2174
        if err != nil {
×
2175
                return nil, err
×
2176
        }
×
2177
        defer rows.Close()
×
2178
        var items []GraphNode
×
2179
        for rows.Next() {
×
2180
                var i GraphNode
×
2181
                if err := rows.Scan(
×
2182
                        &i.ID,
×
2183
                        &i.Version,
×
2184
                        &i.PubKey,
×
2185
                        &i.Alias,
×
2186
                        &i.LastUpdate,
×
2187
                        &i.Color,
×
2188
                        &i.Signature,
×
2189
                        &i.BlockHeight,
×
2190
                ); err != nil {
×
2191
                        return nil, err
×
2192
                }
×
2193
                items = append(items, i)
×
2194
        }
2195
        if err := rows.Close(); err != nil {
×
2196
                return nil, err
×
2197
        }
×
2198
        if err := rows.Err(); err != nil {
×
2199
                return nil, err
×
2200
        }
×
2201
        return items, nil
×
2202
}
2203

2204
const getPruneEntriesForHeights = `-- name: GetPruneEntriesForHeights :many
2205
SELECT block_height, block_hash
2206
FROM graph_prune_log
2207
WHERE block_height
2208
   IN (/*SLICE:heights*/?)
2209
`
2210

2211
func (q *Queries) GetPruneEntriesForHeights(ctx context.Context, heights []int64) ([]GraphPruneLog, error) {
×
2212
        query := getPruneEntriesForHeights
×
2213
        var queryParams []interface{}
×
2214
        if len(heights) > 0 {
×
2215
                for _, v := range heights {
×
2216
                        queryParams = append(queryParams, v)
×
2217
                }
×
2218
                query = strings.Replace(query, "/*SLICE:heights*/?", makeQueryParams(len(queryParams), len(heights)), 1)
×
2219
        } else {
×
2220
                query = strings.Replace(query, "/*SLICE:heights*/?", "NULL", 1)
×
2221
        }
×
2222
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2223
        if err != nil {
×
2224
                return nil, err
×
2225
        }
×
2226
        defer rows.Close()
×
2227
        var items []GraphPruneLog
×
2228
        for rows.Next() {
×
2229
                var i GraphPruneLog
×
2230
                if err := rows.Scan(&i.BlockHeight, &i.BlockHash); err != nil {
×
2231
                        return nil, err
×
2232
                }
×
2233
                items = append(items, i)
×
2234
        }
2235
        if err := rows.Close(); err != nil {
×
2236
                return nil, err
×
2237
        }
×
2238
        if err := rows.Err(); err != nil {
×
2239
                return nil, err
×
2240
        }
×
2241
        return items, nil
×
2242
}
2243

2244
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
2245
SELECT block_hash
2246
FROM graph_prune_log
2247
WHERE block_height = $1
2248
`
2249

2250
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
2251
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
2252
        var block_hash []byte
×
2253
        err := row.Scan(&block_hash)
×
2254
        return block_hash, err
×
2255
}
×
2256

2257
const getPruneTip = `-- name: GetPruneTip :one
2258
SELECT block_height, block_hash
2259
FROM graph_prune_log
2260
ORDER BY block_height DESC
2261
LIMIT 1
2262
`
2263

2264
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
2265
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
2266
        var i GraphPruneLog
×
2267
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
2268
        return i, err
×
2269
}
×
2270

2271
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
2272
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, signature, funding_pk_script, merkle_root_hash
2273
FROM graph_channels
2274
WHERE version = 1
2275
  AND COALESCE(length(node_1_signature), 0) > 0
2276
  AND scid >= $1
2277
  AND scid < $2
2278
ORDER BY scid ASC
2279
`
2280

2281
type GetPublicV1ChannelsBySCIDParams struct {
2282
        StartScid []byte
2283
        EndScid   []byte
2284
}
2285

2286
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
2287
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
2288
        if err != nil {
×
2289
                return nil, err
×
2290
        }
×
2291
        defer rows.Close()
×
2292
        var items []GraphChannel
×
2293
        for rows.Next() {
×
2294
                var i GraphChannel
×
2295
                if err := rows.Scan(
×
2296
                        &i.ID,
×
2297
                        &i.Version,
×
2298
                        &i.Scid,
×
2299
                        &i.NodeID1,
×
2300
                        &i.NodeID2,
×
2301
                        &i.Outpoint,
×
2302
                        &i.Capacity,
×
2303
                        &i.BitcoinKey1,
×
2304
                        &i.BitcoinKey2,
×
2305
                        &i.Node1Signature,
×
2306
                        &i.Node2Signature,
×
2307
                        &i.Bitcoin1Signature,
×
2308
                        &i.Bitcoin2Signature,
×
2309
                        &i.Signature,
×
2310
                        &i.FundingPkScript,
×
2311
                        &i.MerkleRootHash,
×
2312
                ); err != nil {
×
2313
                        return nil, err
×
2314
                }
×
2315
                items = append(items, i)
×
2316
        }
2317
        if err := rows.Close(); err != nil {
×
2318
                return nil, err
×
2319
        }
×
2320
        if err := rows.Err(); err != nil {
×
2321
                return nil, err
×
2322
        }
×
2323
        return items, nil
×
2324
}
2325

2326
const getPublicV2ChannelsBySCID = `-- name: GetPublicV2ChannelsBySCID :many
2327
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, signature, funding_pk_script, merkle_root_hash
2328
FROM graph_channels
2329
WHERE version = 2
2330
  AND COALESCE(length(signature), 0) > 0
2331
  AND scid >= $1
2332
  AND scid < $2
2333
ORDER BY scid ASC
2334
`
2335

2336
type GetPublicV2ChannelsBySCIDParams struct {
2337
        StartScid []byte
2338
        EndScid   []byte
2339
}
2340

NEW
2341
func (q *Queries) GetPublicV2ChannelsBySCID(ctx context.Context, arg GetPublicV2ChannelsBySCIDParams) ([]GraphChannel, error) {
×
NEW
2342
        rows, err := q.db.QueryContext(ctx, getPublicV2ChannelsBySCID, arg.StartScid, arg.EndScid)
×
NEW
2343
        if err != nil {
×
NEW
2344
                return nil, err
×
NEW
2345
        }
×
NEW
2346
        defer rows.Close()
×
NEW
2347
        var items []GraphChannel
×
NEW
2348
        for rows.Next() {
×
NEW
2349
                var i GraphChannel
×
NEW
2350
                if err := rows.Scan(
×
NEW
2351
                        &i.ID,
×
NEW
2352
                        &i.Version,
×
NEW
2353
                        &i.Scid,
×
NEW
2354
                        &i.NodeID1,
×
NEW
2355
                        &i.NodeID2,
×
NEW
2356
                        &i.Outpoint,
×
NEW
2357
                        &i.Capacity,
×
NEW
2358
                        &i.BitcoinKey1,
×
NEW
2359
                        &i.BitcoinKey2,
×
NEW
2360
                        &i.Node1Signature,
×
NEW
2361
                        &i.Node2Signature,
×
NEW
2362
                        &i.Bitcoin1Signature,
×
NEW
2363
                        &i.Bitcoin2Signature,
×
NEW
2364
                        &i.Signature,
×
NEW
2365
                        &i.FundingPkScript,
×
NEW
2366
                        &i.MerkleRootHash,
×
NEW
2367
                ); err != nil {
×
NEW
2368
                        return nil, err
×
NEW
2369
                }
×
NEW
2370
                items = append(items, i)
×
2371
        }
NEW
2372
        if err := rows.Close(); err != nil {
×
NEW
2373
                return nil, err
×
NEW
2374
        }
×
NEW
2375
        if err := rows.Err(); err != nil {
×
NEW
2376
                return nil, err
×
NEW
2377
        }
×
NEW
2378
        return items, nil
×
2379
}
2380

2381
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
2382
SELECT scid from graph_channels
2383
WHERE outpoint = $1 AND version = $2
2384
`
2385

2386
type GetSCIDByOutpointParams struct {
2387
        Outpoint string
2388
        Version  int16
2389
}
2390

2391
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
2392
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
2393
        var scid []byte
×
2394
        err := row.Scan(&scid)
×
2395
        return scid, err
×
2396
}
×
2397

2398
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
2399
SELECT sn.node_id, n.pub_key
2400
FROM graph_source_nodes sn
2401
    JOIN graph_nodes n ON sn.node_id = n.id
2402
WHERE n.version = $1
2403
`
2404

2405
type GetSourceNodesByVersionRow struct {
2406
        NodeID int64
2407
        PubKey []byte
2408
}
2409

2410
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
2411
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
2412
        if err != nil {
×
2413
                return nil, err
×
2414
        }
×
2415
        defer rows.Close()
×
2416
        var items []GetSourceNodesByVersionRow
×
2417
        for rows.Next() {
×
2418
                var i GetSourceNodesByVersionRow
×
2419
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
2420
                        return nil, err
×
2421
                }
×
2422
                items = append(items, i)
×
2423
        }
2424
        if err := rows.Close(); err != nil {
×
2425
                return nil, err
×
2426
        }
×
2427
        if err := rows.Err(); err != nil {
×
2428
                return nil, err
×
2429
        }
×
2430
        return items, nil
×
2431
}
2432

2433
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
2434
SELECT c.scid
2435
FROM graph_channels c
2436
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2437
WHERE cp.disabled = true
2438
AND c.version = 1
2439
GROUP BY c.scid
2440
HAVING COUNT(*) > 1
2441
`
2442

2443
// NOTE: this is V1 specific since for V1, disabled is a
2444
// simple, single boolean. The proposed V2 policy
2445
// structure will have a more complex disabled bit vector
2446
// and so the query for V2 may differ.
2447
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2448
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
2449
        if err != nil {
×
2450
                return nil, err
×
2451
        }
×
2452
        defer rows.Close()
×
2453
        var items [][]byte
×
2454
        for rows.Next() {
×
2455
                var scid []byte
×
2456
                if err := rows.Scan(&scid); err != nil {
×
2457
                        return nil, err
×
2458
                }
×
2459
                items = append(items, scid)
×
2460
        }
2461
        if err := rows.Close(); err != nil {
×
2462
                return nil, err
×
2463
        }
×
2464
        if err := rows.Err(); err != nil {
×
2465
                return nil, err
×
2466
        }
×
2467
        return items, nil
×
2468
}
2469

2470
const getV2DisabledSCIDs = `-- name: GetV2DisabledSCIDs :many
2471
SELECT c.scid
2472
FROM graph_channels c
2473
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2474
WHERE COALESCE(cp.disable_flags, 0) != 0
2475
AND c.version = 2
2476
GROUP BY c.scid
2477
HAVING COUNT(*) > 1
2478
`
2479

2480
// NOTE: this is V2 specific since V2 uses a disable flag
2481
// bit vector instead of a single boolean.
2482
func (q *Queries) GetV2DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2483
        rows, err := q.db.QueryContext(ctx, getV2DisabledSCIDs)
×
2484
        if err != nil {
×
2485
                return nil, err
×
2486
        }
×
2487
        defer rows.Close()
×
2488
        var items [][]byte
×
2489
        for rows.Next() {
×
2490
                var scid []byte
×
2491
                if err := rows.Scan(&scid); err != nil {
×
2492
                        return nil, err
×
2493
                }
×
2494
                items = append(items, scid)
×
2495
        }
2496
        if err := rows.Close(); err != nil {
×
2497
                return nil, err
×
2498
        }
×
2499
        if err := rows.Err(); err != nil {
×
2500
                return nil, err
×
2501
        }
×
2502
        return items, nil
×
2503
}
2504

2505
const getZombieChannel = `-- name: GetZombieChannel :one
2506
SELECT scid, version, node_key_1, node_key_2
2507
FROM graph_zombie_channels
2508
WHERE scid = $1
2509
AND version = $2
2510
`
2511

2512
type GetZombieChannelParams struct {
2513
        Scid    []byte
2514
        Version int16
2515
}
2516

2517
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
2518
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
2519
        var i GraphZombieChannel
×
2520
        err := row.Scan(
×
2521
                &i.Scid,
×
2522
                &i.Version,
×
2523
                &i.NodeKey1,
×
2524
                &i.NodeKey2,
×
2525
        )
×
2526
        return i, err
×
2527
}
×
2528

2529
const getZombieChannelsSCIDs = `-- name: GetZombieChannelsSCIDs :many
2530
SELECT scid, version, node_key_1, node_key_2
2531
FROM graph_zombie_channels
2532
WHERE version = $1
2533
  AND scid IN (/*SLICE:scids*/?)
2534
`
2535

2536
type GetZombieChannelsSCIDsParams struct {
2537
        Version int16
2538
        Scids   [][]byte
2539
}
2540

2541
func (q *Queries) GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error) {
×
2542
        query := getZombieChannelsSCIDs
×
2543
        var queryParams []interface{}
×
2544
        queryParams = append(queryParams, arg.Version)
×
2545
        if len(arg.Scids) > 0 {
×
2546
                for _, v := range arg.Scids {
×
2547
                        queryParams = append(queryParams, v)
×
2548
                }
×
2549
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
2550
        } else {
×
2551
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
2552
        }
×
2553
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2554
        if err != nil {
×
2555
                return nil, err
×
2556
        }
×
2557
        defer rows.Close()
×
2558
        var items []GraphZombieChannel
×
2559
        for rows.Next() {
×
2560
                var i GraphZombieChannel
×
2561
                if err := rows.Scan(
×
2562
                        &i.Scid,
×
2563
                        &i.Version,
×
2564
                        &i.NodeKey1,
×
2565
                        &i.NodeKey2,
×
2566
                ); err != nil {
×
2567
                        return nil, err
×
2568
                }
×
2569
                items = append(items, i)
×
2570
        }
2571
        if err := rows.Close(); err != nil {
×
2572
                return nil, err
×
2573
        }
×
2574
        if err := rows.Err(); err != nil {
×
2575
                return nil, err
×
2576
        }
×
2577
        return items, nil
×
2578
}
2579

2580
const highestSCID = `-- name: HighestSCID :one
2581
SELECT scid
2582
FROM graph_channels
2583
WHERE version = $1
2584
ORDER BY scid DESC
2585
LIMIT 1
2586
`
2587

2588
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
2589
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
2590
        var scid []byte
×
2591
        err := row.Scan(&scid)
×
2592
        return scid, err
×
2593
}
×
2594

2595
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2596
/* ─────────────────────────────────────────────
2597
   graph_channel_features table queries
2598
   ─────────────────────────────────────────────
2599
*/
2600

2601
INSERT INTO graph_channel_features (
2602
    channel_id, feature_bit
2603
) VALUES (
2604
    $1, $2
2605
) ON CONFLICT (channel_id, feature_bit)
2606
    -- Do nothing if the channel_id and feature_bit already exist.
2607
    DO NOTHING
2608
`
2609

2610
type InsertChannelFeatureParams struct {
2611
        ChannelID  int64
2612
        FeatureBit int32
2613
}
2614

2615
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2616
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2617
        return err
×
2618
}
×
2619

2620
const insertChannelMig = `-- name: InsertChannelMig :one
2621
INSERT INTO graph_channels (
2622
    version, scid, node_id_1, node_id_2,
2623
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
2624
    node_1_signature, node_2_signature, bitcoin_1_signature,
2625
    bitcoin_2_signature
2626
) VALUES (
2627
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
2628
) ON CONFLICT (scid, version)
2629
    -- If a conflict occurs, we have already migrated this channel. However, we
2630
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2631
    -- otherwise, the "RETURNING id" part does not work.
2632
    DO UPDATE SET
2633
        node_id_1 = EXCLUDED.node_id_1,
2634
        node_id_2 = EXCLUDED.node_id_2,
2635
        outpoint = EXCLUDED.outpoint,
2636
        capacity = EXCLUDED.capacity,
2637
        bitcoin_key_1 = EXCLUDED.bitcoin_key_1,
2638
        bitcoin_key_2 = EXCLUDED.bitcoin_key_2,
2639
        node_1_signature = EXCLUDED.node_1_signature,
2640
        node_2_signature = EXCLUDED.node_2_signature,
2641
        bitcoin_1_signature = EXCLUDED.bitcoin_1_signature,
2642
        bitcoin_2_signature = EXCLUDED.bitcoin_2_signature
2643
RETURNING id
2644
`
2645

2646
type InsertChannelMigParams struct {
2647
        Version           int16
2648
        Scid              []byte
2649
        NodeID1           int64
2650
        NodeID2           int64
2651
        Outpoint          string
2652
        Capacity          sql.NullInt64
2653
        BitcoinKey1       []byte
2654
        BitcoinKey2       []byte
2655
        Node1Signature    []byte
2656
        Node2Signature    []byte
2657
        Bitcoin1Signature []byte
2658
        Bitcoin2Signature []byte
2659
}
2660

2661
// NOTE: This query is only meant to be used by the graph SQL migration since
2662
// for that migration, in order to be retry-safe, we don't want to error out if
2663
// we re-insert the same channel again (which would error if the normal
2664
// CreateChannel query is used because of the uniqueness constraint on the scid
2665
// and version columns).
2666
func (q *Queries) InsertChannelMig(ctx context.Context, arg InsertChannelMigParams) (int64, error) {
×
2667
        row := q.db.QueryRowContext(ctx, insertChannelMig,
×
2668
                arg.Version,
×
2669
                arg.Scid,
×
2670
                arg.NodeID1,
×
2671
                arg.NodeID2,
×
2672
                arg.Outpoint,
×
2673
                arg.Capacity,
×
2674
                arg.BitcoinKey1,
×
2675
                arg.BitcoinKey2,
×
2676
                arg.Node1Signature,
×
2677
                arg.Node2Signature,
×
2678
                arg.Bitcoin1Signature,
×
2679
                arg.Bitcoin2Signature,
×
2680
        )
×
2681
        var id int64
×
2682
        err := row.Scan(&id)
×
2683
        return id, err
×
2684
}
×
2685

2686
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2687
/* ─────────────────────────────────────────────
2688
   graph_closed_scid table queries
2689
   ────────────────────────────────────────────-
2690
*/
2691

2692
INSERT INTO graph_closed_scids (scid)
2693
VALUES ($1)
2694
ON CONFLICT (scid) DO NOTHING
2695
`
2696

2697
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2698
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2699
        return err
×
2700
}
×
2701

2702
const insertEdgePolicyMig = `-- name: InsertEdgePolicyMig :one
2703
INSERT INTO graph_channel_policies (
2704
    version, channel_id, node_id, timelock, fee_ppm,
2705
    base_fee_msat, min_htlc_msat, last_update, disabled,
2706
    max_htlc_msat, inbound_base_fee_msat,
2707
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2708
    signature
2709
) VALUES  (
2710
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2711
)
2712
ON CONFLICT (channel_id, node_id, version)
2713
    -- If a conflict occurs, we have already migrated this policy. However, we
2714
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2715
    -- otherwise, the "RETURNING id" part does not work.
2716
    DO UPDATE SET
2717
        timelock = EXCLUDED.timelock,
2718
        fee_ppm = EXCLUDED.fee_ppm,
2719
        base_fee_msat = EXCLUDED.base_fee_msat,
2720
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2721
        last_update = EXCLUDED.last_update,
2722
        disabled = EXCLUDED.disabled,
2723
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2724
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2725
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2726
        message_flags = EXCLUDED.message_flags,
2727
        channel_flags = EXCLUDED.channel_flags,
2728
        signature = EXCLUDED.signature
2729
RETURNING id
2730
`
2731

2732
type InsertEdgePolicyMigParams struct {
2733
        Version                 int16
2734
        ChannelID               int64
2735
        NodeID                  int64
2736
        Timelock                int32
2737
        FeePpm                  int64
2738
        BaseFeeMsat             int64
2739
        MinHtlcMsat             int64
2740
        LastUpdate              sql.NullInt64
2741
        Disabled                sql.NullBool
2742
        MaxHtlcMsat             sql.NullInt64
2743
        InboundBaseFeeMsat      sql.NullInt64
2744
        InboundFeeRateMilliMsat sql.NullInt64
2745
        MessageFlags            sql.NullInt16
2746
        ChannelFlags            sql.NullInt16
2747
        Signature               []byte
2748
}
2749

2750
// NOTE: This query is only meant to be used by the graph SQL migration since
2751
// for that migration, in order to be retry-safe, we don't want to error out if
2752
// we re-insert the same policy (which would error if the normal
2753
// UpsertEdgePolicy query is used because of the constraint in that query that
2754
// requires a policy update to have a newer last_update than the existing one).
2755
func (q *Queries) InsertEdgePolicyMig(ctx context.Context, arg InsertEdgePolicyMigParams) (int64, error) {
×
2756
        row := q.db.QueryRowContext(ctx, insertEdgePolicyMig,
×
2757
                arg.Version,
×
2758
                arg.ChannelID,
×
2759
                arg.NodeID,
×
2760
                arg.Timelock,
×
2761
                arg.FeePpm,
×
2762
                arg.BaseFeeMsat,
×
2763
                arg.MinHtlcMsat,
×
2764
                arg.LastUpdate,
×
2765
                arg.Disabled,
×
2766
                arg.MaxHtlcMsat,
×
2767
                arg.InboundBaseFeeMsat,
×
2768
                arg.InboundFeeRateMilliMsat,
×
2769
                arg.MessageFlags,
×
2770
                arg.ChannelFlags,
×
2771
                arg.Signature,
×
2772
        )
×
2773
        var id int64
×
2774
        err := row.Scan(&id)
×
2775
        return id, err
×
2776
}
×
2777

2778
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2779
/* ─────────────────────────────────────────────
2780
   graph_node_features table queries
2781
   ─────────────────────────────────────────────
2782
*/
2783

2784
INSERT INTO graph_node_features (
2785
    node_id, feature_bit
2786
) VALUES (
2787
    $1, $2
2788
) ON CONFLICT (node_id, feature_bit)
2789
    -- Do nothing if the feature already exists for the node.
2790
    DO NOTHING
2791
`
2792

2793
type InsertNodeFeatureParams struct {
2794
        NodeID     int64
2795
        FeatureBit int32
2796
}
2797

2798
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2799
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2800
        return err
×
2801
}
×
2802

2803
const insertNodeMig = `-- name: InsertNodeMig :one
2804
/* ─────────────────────────────────────────────
2805
   Migration specific queries
2806

2807
   NOTE: once sqldbv2 is in place, these queries can be contained to a package
2808
   dedicated to the migration that requires it, and so we can then remove
2809
   it from the main set of "live" queries that the code-base has access to.
2810
   ────────────────────────────────────────────-
2811
*/
2812

2813
INSERT INTO graph_nodes (
2814
    version, pub_key, alias, last_update, color, signature
2815
) VALUES (
2816
    $1, $2, $3, $4, $5, $6
2817
)
2818
ON CONFLICT (pub_key, version)
2819
    -- If a conflict occurs, we have already migrated this node. However, we
2820
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2821
    -- otherwise, the "RETURNING id" part does not work.
2822
    DO UPDATE SET
2823
        alias = EXCLUDED.alias,
2824
        last_update = EXCLUDED.last_update,
2825
        color = EXCLUDED.color,
2826
        signature = EXCLUDED.signature
2827
RETURNING id
2828
`
2829

2830
type InsertNodeMigParams struct {
2831
        Version    int16
2832
        PubKey     []byte
2833
        Alias      sql.NullString
2834
        LastUpdate sql.NullInt64
2835
        Color      sql.NullString
2836
        Signature  []byte
2837
}
2838

2839
// NOTE: This query is only meant to be used by the graph SQL migration since
2840
// for that migration, in order to be retry-safe, we don't want to error out if
2841
// we re-insert the same node (which would error if the normal UpsertNode query
2842
// is used because of the constraint in that query that requires a node update
2843
// to have a newer last_update than the existing node).
2844
func (q *Queries) InsertNodeMig(ctx context.Context, arg InsertNodeMigParams) (int64, error) {
×
2845
        row := q.db.QueryRowContext(ctx, insertNodeMig,
×
2846
                arg.Version,
×
2847
                arg.PubKey,
×
2848
                arg.Alias,
×
2849
                arg.LastUpdate,
×
2850
                arg.Color,
×
2851
                arg.Signature,
×
2852
        )
×
2853
        var id int64
×
2854
        err := row.Scan(&id)
×
2855
        return id, err
×
2856
}
×
2857

2858
const isClosedChannel = `-- name: IsClosedChannel :one
2859
SELECT EXISTS (
2860
    SELECT 1
2861
    FROM graph_closed_scids
2862
    WHERE scid = $1
2863
)
2864
`
2865

2866
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2867
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2868
        var exists bool
×
2869
        err := row.Scan(&exists)
×
2870
        return exists, err
×
2871
}
×
2872

2873
const isPublicV1Node = `-- name: IsPublicV1Node :one
2874
SELECT EXISTS (
2875
    SELECT 1
2876
    FROM graph_channels c
2877
    JOIN graph_nodes n ON n.id = c.node_id_1
2878
    -- NOTE: we hard-code the version here since the clauses
2879
    -- here that determine if a node is public is specific
2880
    -- to the V1 gossip protocol. In V1, a node is public
2881
    -- if it has a public channel and a public channel is one
2882
    -- where we have the set of signatures of the channel
2883
    -- announcement. It is enough to just check that we have
2884
    -- one of the signatures since we only ever set them
2885
    -- together.
2886
    WHERE c.version = 1
2887
      AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
2888
      AND n.pub_key = $1
2889
    UNION ALL
2890
    SELECT 1
2891
    FROM graph_channels c
2892
    JOIN graph_nodes n ON n.id = c.node_id_2
2893
    WHERE c.version = 1
2894
      AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
2895
      AND n.pub_key = $1
2896
)
2897
`
2898

2899
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2900
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2901
        var exists bool
×
2902
        err := row.Scan(&exists)
×
2903
        return exists, err
×
2904
}
×
2905

2906
const isPublicV2Node = `-- name: IsPublicV2Node :one
2907
SELECT EXISTS (
2908
    SELECT 1
2909
    FROM graph_channels c
2910
    JOIN graph_nodes n ON n.id = c.node_id_1
2911
    -- NOTE: we hard-code the version here since the clauses
2912
    -- here that determine if a node is public is specific
2913
    -- to the V2 gossip protocol.
2914
    WHERE c.version = 2
2915
      AND COALESCE(length(c.signature), 0) > 0
2916
      AND n.pub_key = $1
2917

2918
    UNION ALL
2919

2920
    SELECT 1
2921
    FROM graph_channels c
2922
    JOIN graph_nodes n ON n.id = c.node_id_2
2923
    WHERE c.version = 2
2924
      AND COALESCE(length(c.signature), 0) > 0
2925
      AND n.pub_key = $1
2926
)
2927
`
2928

2929
func (q *Queries) IsPublicV2Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2930
        row := q.db.QueryRowContext(ctx, isPublicV2Node, pubKey)
×
2931
        var exists bool
×
2932
        err := row.Scan(&exists)
×
2933
        return exists, err
×
2934
}
×
2935

2936
const isZombieChannel = `-- name: IsZombieChannel :one
2937
SELECT EXISTS (
2938
    SELECT 1
2939
    FROM graph_zombie_channels
2940
    WHERE scid = $1
2941
    AND version = $2
2942
) AS is_zombie
2943
`
2944

2945
type IsZombieChannelParams struct {
2946
        Scid    []byte
2947
        Version int16
2948
}
2949

2950
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2951
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2952
        var is_zombie bool
×
2953
        err := row.Scan(&is_zombie)
×
2954
        return is_zombie, err
×
2955
}
×
2956

2957
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2958
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, c.signature, c.funding_pk_script, c.merkle_root_hash,
2959
    n1.pub_key AS node1_pubkey,
2960
    n2.pub_key AS node2_pubkey,
2961

2962
    -- Policy 1
2963
    -- TODO(elle): use sqlc.embed to embed policy structs
2964
    --  once this issue is resolved:
2965
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2966
    cp1.id AS policy1_id,
2967
    cp1.node_id AS policy1_node_id,
2968
    cp1.version AS policy1_version,
2969
    cp1.timelock AS policy1_timelock,
2970
    cp1.fee_ppm AS policy1_fee_ppm,
2971
    cp1.base_fee_msat AS policy1_base_fee_msat,
2972
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2973
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2974
    cp1.last_update AS policy1_last_update,
2975
    cp1.disabled AS policy1_disabled,
2976
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2977
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2978
    cp1.message_flags AS policy1_message_flags,
2979
    cp1.channel_flags AS policy1_channel_flags,
2980
    cp1.signature AS policy1_signature,
2981
    cp1.block_height AS policy1_block_height,
2982
    cp1.disable_flags AS policy1_disable_flags,
2983

2984
       -- Policy 2
2985
    cp2.id AS policy2_id,
2986
    cp2.node_id AS policy2_node_id,
2987
    cp2.version AS policy2_version,
2988
    cp2.timelock AS policy2_timelock,
2989
    cp2.fee_ppm AS policy2_fee_ppm,
2990
    cp2.base_fee_msat AS policy2_base_fee_msat,
2991
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2992
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2993
    cp2.last_update AS policy2_last_update,
2994
    cp2.disabled AS policy2_disabled,
2995
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2996
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2997
    cp2.message_flags AS policy2_message_flags,
2998
    cp2.channel_flags AS policy2_channel_flags,
2999
    cp2.signature AS policy2_signature,
3000
    cp2.block_height AS policy2_block_height,
3001
    cp2.disable_flags AS policy2_disable_flags
3002

3003
FROM graph_channels c
3004
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3005
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3006
    LEFT JOIN graph_channel_policies cp1
3007
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3008
    LEFT JOIN graph_channel_policies cp2
3009
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3010
WHERE c.version = $1
3011
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
3012
`
3013

3014
type ListChannelsByNodeIDParams struct {
3015
        Version int16
3016
        NodeID1 int64
3017
}
3018

3019
type ListChannelsByNodeIDRow struct {
3020
        GraphChannel                   GraphChannel
3021
        Node1Pubkey                    []byte
3022
        Node2Pubkey                    []byte
3023
        Policy1ID                      sql.NullInt64
3024
        Policy1NodeID                  sql.NullInt64
3025
        Policy1Version                 sql.NullInt16
3026
        Policy1Timelock                sql.NullInt32
3027
        Policy1FeePpm                  sql.NullInt64
3028
        Policy1BaseFeeMsat             sql.NullInt64
3029
        Policy1MinHtlcMsat             sql.NullInt64
3030
        Policy1MaxHtlcMsat             sql.NullInt64
3031
        Policy1LastUpdate              sql.NullInt64
3032
        Policy1Disabled                sql.NullBool
3033
        Policy1InboundBaseFeeMsat      sql.NullInt64
3034
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3035
        Policy1MessageFlags            sql.NullInt16
3036
        Policy1ChannelFlags            sql.NullInt16
3037
        Policy1Signature               []byte
3038
        Policy1BlockHeight             sql.NullInt64
3039
        Policy1DisableFlags            sql.NullInt16
3040
        Policy2ID                      sql.NullInt64
3041
        Policy2NodeID                  sql.NullInt64
3042
        Policy2Version                 sql.NullInt16
3043
        Policy2Timelock                sql.NullInt32
3044
        Policy2FeePpm                  sql.NullInt64
3045
        Policy2BaseFeeMsat             sql.NullInt64
3046
        Policy2MinHtlcMsat             sql.NullInt64
3047
        Policy2MaxHtlcMsat             sql.NullInt64
3048
        Policy2LastUpdate              sql.NullInt64
3049
        Policy2Disabled                sql.NullBool
3050
        Policy2InboundBaseFeeMsat      sql.NullInt64
3051
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3052
        Policy2MessageFlags            sql.NullInt16
3053
        Policy2ChannelFlags            sql.NullInt16
3054
        Policy2Signature               []byte
3055
        Policy2BlockHeight             sql.NullInt64
3056
        Policy2DisableFlags            sql.NullInt16
3057
}
3058

3059
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
3060
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
3061
        if err != nil {
×
3062
                return nil, err
×
3063
        }
×
3064
        defer rows.Close()
×
3065
        var items []ListChannelsByNodeIDRow
×
3066
        for rows.Next() {
×
3067
                var i ListChannelsByNodeIDRow
×
3068
                if err := rows.Scan(
×
3069
                        &i.GraphChannel.ID,
×
3070
                        &i.GraphChannel.Version,
×
3071
                        &i.GraphChannel.Scid,
×
3072
                        &i.GraphChannel.NodeID1,
×
3073
                        &i.GraphChannel.NodeID2,
×
3074
                        &i.GraphChannel.Outpoint,
×
3075
                        &i.GraphChannel.Capacity,
×
3076
                        &i.GraphChannel.BitcoinKey1,
×
3077
                        &i.GraphChannel.BitcoinKey2,
×
3078
                        &i.GraphChannel.Node1Signature,
×
3079
                        &i.GraphChannel.Node2Signature,
×
3080
                        &i.GraphChannel.Bitcoin1Signature,
×
3081
                        &i.GraphChannel.Bitcoin2Signature,
×
3082
                        &i.GraphChannel.Signature,
×
3083
                        &i.GraphChannel.FundingPkScript,
×
3084
                        &i.GraphChannel.MerkleRootHash,
×
3085
                        &i.Node1Pubkey,
×
3086
                        &i.Node2Pubkey,
×
3087
                        &i.Policy1ID,
×
3088
                        &i.Policy1NodeID,
×
3089
                        &i.Policy1Version,
×
3090
                        &i.Policy1Timelock,
×
3091
                        &i.Policy1FeePpm,
×
3092
                        &i.Policy1BaseFeeMsat,
×
3093
                        &i.Policy1MinHtlcMsat,
×
3094
                        &i.Policy1MaxHtlcMsat,
×
3095
                        &i.Policy1LastUpdate,
×
3096
                        &i.Policy1Disabled,
×
3097
                        &i.Policy1InboundBaseFeeMsat,
×
3098
                        &i.Policy1InboundFeeRateMilliMsat,
×
3099
                        &i.Policy1MessageFlags,
×
3100
                        &i.Policy1ChannelFlags,
×
3101
                        &i.Policy1Signature,
×
3102
                        &i.Policy1BlockHeight,
×
3103
                        &i.Policy1DisableFlags,
×
3104
                        &i.Policy2ID,
×
3105
                        &i.Policy2NodeID,
×
3106
                        &i.Policy2Version,
×
3107
                        &i.Policy2Timelock,
×
3108
                        &i.Policy2FeePpm,
×
3109
                        &i.Policy2BaseFeeMsat,
×
3110
                        &i.Policy2MinHtlcMsat,
×
3111
                        &i.Policy2MaxHtlcMsat,
×
3112
                        &i.Policy2LastUpdate,
×
3113
                        &i.Policy2Disabled,
×
3114
                        &i.Policy2InboundBaseFeeMsat,
×
3115
                        &i.Policy2InboundFeeRateMilliMsat,
×
3116
                        &i.Policy2MessageFlags,
×
3117
                        &i.Policy2ChannelFlags,
×
3118
                        &i.Policy2Signature,
×
3119
                        &i.Policy2BlockHeight,
×
3120
                        &i.Policy2DisableFlags,
×
3121
                ); err != nil {
×
3122
                        return nil, err
×
3123
                }
×
3124
                items = append(items, i)
×
3125
        }
3126
        if err := rows.Close(); err != nil {
×
3127
                return nil, err
×
3128
        }
×
3129
        if err := rows.Err(); err != nil {
×
3130
                return nil, err
×
3131
        }
×
3132
        return items, nil
×
3133
}
3134

3135
const listChannelsForNodeIDs = `-- name: ListChannelsForNodeIDs :many
3136
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, c.signature, c.funding_pk_script, c.merkle_root_hash,
3137
       n1.pub_key AS node1_pubkey,
3138
       n2.pub_key AS node2_pubkey,
3139

3140
       -- Policy 1
3141
       -- TODO(elle): use sqlc.embed to embed policy structs
3142
       --  once this issue is resolved:
3143
       --  https://github.com/sqlc-dev/sqlc/issues/2997
3144
       cp1.id AS policy1_id,
3145
       cp1.node_id AS policy1_node_id,
3146
       cp1.version AS policy1_version,
3147
       cp1.timelock AS policy1_timelock,
3148
       cp1.fee_ppm AS policy1_fee_ppm,
3149
       cp1.base_fee_msat AS policy1_base_fee_msat,
3150
       cp1.min_htlc_msat AS policy1_min_htlc_msat,
3151
       cp1.max_htlc_msat AS policy1_max_htlc_msat,
3152
       cp1.last_update AS policy1_last_update,
3153
       cp1.disabled AS policy1_disabled,
3154
       cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3155
       cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3156
       cp1.message_flags AS policy1_message_flags,
3157
       cp1.channel_flags AS policy1_channel_flags,
3158
       cp1.signature AS policy1_signature,
3159
    cp1.block_height AS policy1_block_height,
3160
    cp1.disable_flags AS policy1_disable_flags,
3161

3162
       -- Policy 2
3163
       cp2.id AS policy2_id,
3164
       cp2.node_id AS policy2_node_id,
3165
       cp2.version AS policy2_version,
3166
       cp2.timelock AS policy2_timelock,
3167
       cp2.fee_ppm AS policy2_fee_ppm,
3168
       cp2.base_fee_msat AS policy2_base_fee_msat,
3169
       cp2.min_htlc_msat AS policy2_min_htlc_msat,
3170
       cp2.max_htlc_msat AS policy2_max_htlc_msat,
3171
       cp2.last_update AS policy2_last_update,
3172
       cp2.disabled AS policy2_disabled,
3173
       cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3174
       cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3175
       cp2.message_flags AS policy2_message_flags,
3176
       cp2.channel_flags AS policy2_channel_flags,
3177
       cp2.signature AS policy2_signature,
3178
    cp2.block_height AS policy2_block_height,
3179
    cp2.disable_flags AS policy2_disable_flags
3180

3181
FROM graph_channels c
3182
         JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3183
         JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3184
         LEFT JOIN graph_channel_policies cp1
3185
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3186
         LEFT JOIN graph_channel_policies cp2
3187
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3188
WHERE c.version = $1
3189
  AND (c.node_id_1 IN (/*SLICE:node1_ids*/?)
3190
   OR c.node_id_2 IN (/*SLICE:node2_ids*/?))
3191
`
3192

3193
type ListChannelsForNodeIDsParams struct {
3194
        Version  int16
3195
        Node1Ids []int64
3196
        Node2Ids []int64
3197
}
3198

3199
type ListChannelsForNodeIDsRow struct {
3200
        GraphChannel                   GraphChannel
3201
        Node1Pubkey                    []byte
3202
        Node2Pubkey                    []byte
3203
        Policy1ID                      sql.NullInt64
3204
        Policy1NodeID                  sql.NullInt64
3205
        Policy1Version                 sql.NullInt16
3206
        Policy1Timelock                sql.NullInt32
3207
        Policy1FeePpm                  sql.NullInt64
3208
        Policy1BaseFeeMsat             sql.NullInt64
3209
        Policy1MinHtlcMsat             sql.NullInt64
3210
        Policy1MaxHtlcMsat             sql.NullInt64
3211
        Policy1LastUpdate              sql.NullInt64
3212
        Policy1Disabled                sql.NullBool
3213
        Policy1InboundBaseFeeMsat      sql.NullInt64
3214
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3215
        Policy1MessageFlags            sql.NullInt16
3216
        Policy1ChannelFlags            sql.NullInt16
3217
        Policy1Signature               []byte
3218
        Policy1BlockHeight             sql.NullInt64
3219
        Policy1DisableFlags            sql.NullInt16
3220
        Policy2ID                      sql.NullInt64
3221
        Policy2NodeID                  sql.NullInt64
3222
        Policy2Version                 sql.NullInt16
3223
        Policy2Timelock                sql.NullInt32
3224
        Policy2FeePpm                  sql.NullInt64
3225
        Policy2BaseFeeMsat             sql.NullInt64
3226
        Policy2MinHtlcMsat             sql.NullInt64
3227
        Policy2MaxHtlcMsat             sql.NullInt64
3228
        Policy2LastUpdate              sql.NullInt64
3229
        Policy2Disabled                sql.NullBool
3230
        Policy2InboundBaseFeeMsat      sql.NullInt64
3231
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3232
        Policy2MessageFlags            sql.NullInt16
3233
        Policy2ChannelFlags            sql.NullInt16
3234
        Policy2Signature               []byte
3235
        Policy2BlockHeight             sql.NullInt64
3236
        Policy2DisableFlags            sql.NullInt16
3237
}
3238

3239
func (q *Queries) ListChannelsForNodeIDs(ctx context.Context, arg ListChannelsForNodeIDsParams) ([]ListChannelsForNodeIDsRow, error) {
×
3240
        query := listChannelsForNodeIDs
×
3241
        var queryParams []interface{}
×
3242
        queryParams = append(queryParams, arg.Version)
×
3243
        if len(arg.Node1Ids) > 0 {
×
3244
                for _, v := range arg.Node1Ids {
×
3245
                        queryParams = append(queryParams, v)
×
3246
                }
×
3247
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", makeQueryParams(len(queryParams), len(arg.Node1Ids)), 1)
×
3248
        } else {
×
3249
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", "NULL", 1)
×
3250
        }
×
3251
        if len(arg.Node2Ids) > 0 {
×
3252
                for _, v := range arg.Node2Ids {
×
3253
                        queryParams = append(queryParams, v)
×
3254
                }
×
3255
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", makeQueryParams(len(queryParams), len(arg.Node2Ids)), 1)
×
3256
        } else {
×
3257
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", "NULL", 1)
×
3258
        }
×
3259
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
3260
        if err != nil {
×
3261
                return nil, err
×
3262
        }
×
3263
        defer rows.Close()
×
3264
        var items []ListChannelsForNodeIDsRow
×
3265
        for rows.Next() {
×
3266
                var i ListChannelsForNodeIDsRow
×
3267
                if err := rows.Scan(
×
3268
                        &i.GraphChannel.ID,
×
3269
                        &i.GraphChannel.Version,
×
3270
                        &i.GraphChannel.Scid,
×
3271
                        &i.GraphChannel.NodeID1,
×
3272
                        &i.GraphChannel.NodeID2,
×
3273
                        &i.GraphChannel.Outpoint,
×
3274
                        &i.GraphChannel.Capacity,
×
3275
                        &i.GraphChannel.BitcoinKey1,
×
3276
                        &i.GraphChannel.BitcoinKey2,
×
3277
                        &i.GraphChannel.Node1Signature,
×
3278
                        &i.GraphChannel.Node2Signature,
×
3279
                        &i.GraphChannel.Bitcoin1Signature,
×
3280
                        &i.GraphChannel.Bitcoin2Signature,
×
3281
                        &i.GraphChannel.Signature,
×
3282
                        &i.GraphChannel.FundingPkScript,
×
3283
                        &i.GraphChannel.MerkleRootHash,
×
3284
                        &i.Node1Pubkey,
×
3285
                        &i.Node2Pubkey,
×
3286
                        &i.Policy1ID,
×
3287
                        &i.Policy1NodeID,
×
3288
                        &i.Policy1Version,
×
3289
                        &i.Policy1Timelock,
×
3290
                        &i.Policy1FeePpm,
×
3291
                        &i.Policy1BaseFeeMsat,
×
3292
                        &i.Policy1MinHtlcMsat,
×
3293
                        &i.Policy1MaxHtlcMsat,
×
3294
                        &i.Policy1LastUpdate,
×
3295
                        &i.Policy1Disabled,
×
3296
                        &i.Policy1InboundBaseFeeMsat,
×
3297
                        &i.Policy1InboundFeeRateMilliMsat,
×
3298
                        &i.Policy1MessageFlags,
×
3299
                        &i.Policy1ChannelFlags,
×
3300
                        &i.Policy1Signature,
×
3301
                        &i.Policy1BlockHeight,
×
3302
                        &i.Policy1DisableFlags,
×
3303
                        &i.Policy2ID,
×
3304
                        &i.Policy2NodeID,
×
3305
                        &i.Policy2Version,
×
3306
                        &i.Policy2Timelock,
×
3307
                        &i.Policy2FeePpm,
×
3308
                        &i.Policy2BaseFeeMsat,
×
3309
                        &i.Policy2MinHtlcMsat,
×
3310
                        &i.Policy2MaxHtlcMsat,
×
3311
                        &i.Policy2LastUpdate,
×
3312
                        &i.Policy2Disabled,
×
3313
                        &i.Policy2InboundBaseFeeMsat,
×
3314
                        &i.Policy2InboundFeeRateMilliMsat,
×
3315
                        &i.Policy2MessageFlags,
×
3316
                        &i.Policy2ChannelFlags,
×
3317
                        &i.Policy2Signature,
×
3318
                        &i.Policy2BlockHeight,
×
3319
                        &i.Policy2DisableFlags,
×
3320
                ); err != nil {
×
3321
                        return nil, err
×
3322
                }
×
3323
                items = append(items, i)
×
3324
        }
3325
        if err := rows.Close(); err != nil {
×
3326
                return nil, err
×
3327
        }
×
3328
        if err := rows.Err(); err != nil {
×
3329
                return nil, err
×
3330
        }
×
3331
        return items, nil
×
3332
}
3333

3334
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
3335
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
3336
FROM graph_channels c
3337
WHERE c.version = $1 AND c.id > $2
3338
ORDER BY c.id
3339
LIMIT $3
3340
`
3341

3342
type ListChannelsPaginatedParams struct {
3343
        Version int16
3344
        ID      int64
3345
        Limit   int32
3346
}
3347

3348
type ListChannelsPaginatedRow struct {
3349
        ID          int64
3350
        BitcoinKey1 []byte
3351
        BitcoinKey2 []byte
3352
        Outpoint    string
3353
}
3354

3355
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
3356
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
3357
        if err != nil {
×
3358
                return nil, err
×
3359
        }
×
3360
        defer rows.Close()
×
3361
        var items []ListChannelsPaginatedRow
×
3362
        for rows.Next() {
×
3363
                var i ListChannelsPaginatedRow
×
3364
                if err := rows.Scan(
×
3365
                        &i.ID,
×
3366
                        &i.BitcoinKey1,
×
3367
                        &i.BitcoinKey2,
×
3368
                        &i.Outpoint,
×
3369
                ); err != nil {
×
3370
                        return nil, err
×
3371
                }
×
3372
                items = append(items, i)
×
3373
        }
3374
        if err := rows.Close(); err != nil {
×
3375
                return nil, err
×
3376
        }
×
3377
        if err := rows.Err(); err != nil {
×
3378
                return nil, err
×
3379
        }
×
3380
        return items, nil
×
3381
}
3382

3383
const listChannelsPaginatedV2 = `-- name: ListChannelsPaginatedV2 :many
3384
SELECT id, outpoint, funding_pk_script
3385
FROM graph_channels c
3386
WHERE c.version = 2 AND c.id > $1
3387
ORDER BY c.id
3388
LIMIT $2
3389
`
3390

3391
type ListChannelsPaginatedV2Params struct {
3392
        ID    int64
3393
        Limit int32
3394
}
3395

3396
type ListChannelsPaginatedV2Row struct {
3397
        ID              int64
3398
        Outpoint        string
3399
        FundingPkScript []byte
3400
}
3401

NEW
3402
func (q *Queries) ListChannelsPaginatedV2(ctx context.Context, arg ListChannelsPaginatedV2Params) ([]ListChannelsPaginatedV2Row, error) {
×
NEW
3403
        rows, err := q.db.QueryContext(ctx, listChannelsPaginatedV2, arg.ID, arg.Limit)
×
NEW
3404
        if err != nil {
×
NEW
3405
                return nil, err
×
NEW
3406
        }
×
NEW
3407
        defer rows.Close()
×
NEW
3408
        var items []ListChannelsPaginatedV2Row
×
NEW
3409
        for rows.Next() {
×
NEW
3410
                var i ListChannelsPaginatedV2Row
×
NEW
3411
                if err := rows.Scan(&i.ID, &i.Outpoint, &i.FundingPkScript); err != nil {
×
NEW
3412
                        return nil, err
×
NEW
3413
                }
×
NEW
3414
                items = append(items, i)
×
3415
        }
NEW
3416
        if err := rows.Close(); err != nil {
×
NEW
3417
                return nil, err
×
NEW
3418
        }
×
NEW
3419
        if err := rows.Err(); err != nil {
×
NEW
3420
                return nil, err
×
NEW
3421
        }
×
NEW
3422
        return items, nil
×
3423
}
3424

3425
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
3426
SELECT
3427
    c.id as id,
3428
    c.scid as scid,
3429
    c.capacity AS capacity,
3430

3431
    -- Join node pubkeys
3432
    n1.pub_key AS node1_pubkey,
3433
    n2.pub_key AS node2_pubkey,
3434

3435
    -- Node 1 policy
3436
    cp1.version AS policy1_version,
3437
    cp1.timelock AS policy_1_timelock,
3438
    cp1.fee_ppm AS policy_1_fee_ppm,
3439
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3440
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3441
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3442
    cp1.disabled AS policy_1_disabled,
3443
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3444
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3445
    cp1.message_flags AS policy1_message_flags,
3446
    cp1.channel_flags AS policy1_channel_flags,
3447
    cp1.block_height AS policy1_block_height,
3448
    cp1.disable_flags AS policy1_disable_flags,
3449

3450
    -- Node 2 policy
3451
    cp2.version AS policy2_version,
3452
    cp2.timelock AS policy_2_timelock,
3453
    cp2.fee_ppm AS policy_2_fee_ppm,
3454
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3455
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3456
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3457
    cp2.disabled AS policy_2_disabled,
3458
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3459
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3460
    cp2.message_flags AS policy2_message_flags,
3461
    cp2.channel_flags AS policy2_channel_flags,
3462
    cp2.block_height AS policy2_block_height,
3463
    cp2.disable_flags AS policy2_disable_flags
3464

3465
FROM graph_channels c
3466
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3467
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3468
LEFT JOIN graph_channel_policies cp1
3469
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3470
LEFT JOIN graph_channel_policies cp2
3471
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3472
WHERE c.version = $1 AND c.id > $2
3473
ORDER BY c.id
3474
LIMIT $3
3475
`
3476

3477
type ListChannelsWithPoliciesForCachePaginatedParams struct {
3478
        Version int16
3479
        ID      int64
3480
        Limit   int32
3481
}
3482

3483
type ListChannelsWithPoliciesForCachePaginatedRow struct {
3484
        ID                             int64
3485
        Scid                           []byte
3486
        Capacity                       sql.NullInt64
3487
        Node1Pubkey                    []byte
3488
        Node2Pubkey                    []byte
3489
        Policy1Version                 sql.NullInt16
3490
        Policy1Timelock                sql.NullInt32
3491
        Policy1FeePpm                  sql.NullInt64
3492
        Policy1BaseFeeMsat             sql.NullInt64
3493
        Policy1MinHtlcMsat             sql.NullInt64
3494
        Policy1MaxHtlcMsat             sql.NullInt64
3495
        Policy1Disabled                sql.NullBool
3496
        Policy1InboundBaseFeeMsat      sql.NullInt64
3497
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3498
        Policy1MessageFlags            sql.NullInt16
3499
        Policy1ChannelFlags            sql.NullInt16
3500
        Policy1BlockHeight             sql.NullInt64
3501
        Policy1DisableFlags            sql.NullInt16
3502
        Policy2Version                 sql.NullInt16
3503
        Policy2Timelock                sql.NullInt32
3504
        Policy2FeePpm                  sql.NullInt64
3505
        Policy2BaseFeeMsat             sql.NullInt64
3506
        Policy2MinHtlcMsat             sql.NullInt64
3507
        Policy2MaxHtlcMsat             sql.NullInt64
3508
        Policy2Disabled                sql.NullBool
3509
        Policy2InboundBaseFeeMsat      sql.NullInt64
3510
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3511
        Policy2MessageFlags            sql.NullInt16
3512
        Policy2ChannelFlags            sql.NullInt16
3513
        Policy2BlockHeight             sql.NullInt64
3514
        Policy2DisableFlags            sql.NullInt16
3515
}
3516

3517
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
3518
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
3519
        if err != nil {
×
3520
                return nil, err
×
3521
        }
×
3522
        defer rows.Close()
×
3523
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
3524
        for rows.Next() {
×
3525
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
3526
                if err := rows.Scan(
×
3527
                        &i.ID,
×
3528
                        &i.Scid,
×
3529
                        &i.Capacity,
×
3530
                        &i.Node1Pubkey,
×
3531
                        &i.Node2Pubkey,
×
3532
                        &i.Policy1Version,
×
3533
                        &i.Policy1Timelock,
×
3534
                        &i.Policy1FeePpm,
×
3535
                        &i.Policy1BaseFeeMsat,
×
3536
                        &i.Policy1MinHtlcMsat,
×
3537
                        &i.Policy1MaxHtlcMsat,
×
3538
                        &i.Policy1Disabled,
×
3539
                        &i.Policy1InboundBaseFeeMsat,
×
3540
                        &i.Policy1InboundFeeRateMilliMsat,
×
3541
                        &i.Policy1MessageFlags,
×
3542
                        &i.Policy1ChannelFlags,
×
3543
                        &i.Policy1BlockHeight,
×
3544
                        &i.Policy1DisableFlags,
×
3545
                        &i.Policy2Version,
×
3546
                        &i.Policy2Timelock,
×
3547
                        &i.Policy2FeePpm,
×
3548
                        &i.Policy2BaseFeeMsat,
×
3549
                        &i.Policy2MinHtlcMsat,
×
3550
                        &i.Policy2MaxHtlcMsat,
×
3551
                        &i.Policy2Disabled,
×
3552
                        &i.Policy2InboundBaseFeeMsat,
×
3553
                        &i.Policy2InboundFeeRateMilliMsat,
×
3554
                        &i.Policy2MessageFlags,
×
3555
                        &i.Policy2ChannelFlags,
×
3556
                        &i.Policy2BlockHeight,
×
3557
                        &i.Policy2DisableFlags,
×
3558
                ); err != nil {
×
3559
                        return nil, err
×
3560
                }
×
3561
                items = append(items, i)
×
3562
        }
3563
        if err := rows.Close(); err != nil {
×
3564
                return nil, err
×
3565
        }
×
3566
        if err := rows.Err(); err != nil {
×
3567
                return nil, err
×
3568
        }
×
3569
        return items, nil
×
3570
}
3571

3572
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
3573
SELECT
3574
    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, c.signature, c.funding_pk_script, c.merkle_root_hash,
3575

3576
    -- Join node pubkeys
3577
    n1.pub_key AS node1_pubkey,
3578
    n2.pub_key AS node2_pubkey,
3579

3580
    -- Node 1 policy
3581
    cp1.id AS policy_1_id,
3582
    cp1.node_id AS policy_1_node_id,
3583
    cp1.version AS policy_1_version,
3584
    cp1.timelock AS policy_1_timelock,
3585
    cp1.fee_ppm AS policy_1_fee_ppm,
3586
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3587
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3588
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3589
    cp1.last_update AS policy_1_last_update,
3590
    cp1.disabled AS policy_1_disabled,
3591
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3592
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3593
    cp1.message_flags AS policy1_message_flags,
3594
    cp1.channel_flags AS policy1_channel_flags,
3595
    cp1.block_height AS policy1_block_height,
3596
    cp1.disable_flags AS policy1_disable_flags,
3597
    cp1.signature AS policy_1_signature,
3598

3599
    -- Node 2 policy
3600
    cp2.id AS policy_2_id,
3601
    cp2.node_id AS policy_2_node_id,
3602
    cp2.version AS policy_2_version,
3603
    cp2.timelock AS policy_2_timelock,
3604
    cp2.fee_ppm AS policy_2_fee_ppm,
3605
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3606
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3607
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3608
    cp2.last_update AS policy_2_last_update,
3609
    cp2.disabled AS policy_2_disabled,
3610
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3611
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3612
    cp2.message_flags AS policy2_message_flags,
3613
    cp2.channel_flags AS policy2_channel_flags,
3614
    cp2.signature AS policy_2_signature,
3615
    cp2.block_height AS policy_2_block_height,
3616
    cp2.disable_flags AS policy_2_disable_flags
3617

3618
FROM graph_channels c
3619
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3620
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3621
LEFT JOIN graph_channel_policies cp1
3622
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3623
LEFT JOIN graph_channel_policies cp2
3624
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3625
WHERE c.version = $1 AND c.id > $2
3626
ORDER BY c.id
3627
LIMIT $3
3628
`
3629

3630
type ListChannelsWithPoliciesPaginatedParams struct {
3631
        Version int16
3632
        ID      int64
3633
        Limit   int32
3634
}
3635

3636
type ListChannelsWithPoliciesPaginatedRow struct {
3637
        GraphChannel                   GraphChannel
3638
        Node1Pubkey                    []byte
3639
        Node2Pubkey                    []byte
3640
        Policy1ID                      sql.NullInt64
3641
        Policy1NodeID                  sql.NullInt64
3642
        Policy1Version                 sql.NullInt16
3643
        Policy1Timelock                sql.NullInt32
3644
        Policy1FeePpm                  sql.NullInt64
3645
        Policy1BaseFeeMsat             sql.NullInt64
3646
        Policy1MinHtlcMsat             sql.NullInt64
3647
        Policy1MaxHtlcMsat             sql.NullInt64
3648
        Policy1LastUpdate              sql.NullInt64
3649
        Policy1Disabled                sql.NullBool
3650
        Policy1InboundBaseFeeMsat      sql.NullInt64
3651
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3652
        Policy1MessageFlags            sql.NullInt16
3653
        Policy1ChannelFlags            sql.NullInt16
3654
        Policy1BlockHeight             sql.NullInt64
3655
        Policy1DisableFlags            sql.NullInt16
3656
        Policy1Signature               []byte
3657
        Policy2ID                      sql.NullInt64
3658
        Policy2NodeID                  sql.NullInt64
3659
        Policy2Version                 sql.NullInt16
3660
        Policy2Timelock                sql.NullInt32
3661
        Policy2FeePpm                  sql.NullInt64
3662
        Policy2BaseFeeMsat             sql.NullInt64
3663
        Policy2MinHtlcMsat             sql.NullInt64
3664
        Policy2MaxHtlcMsat             sql.NullInt64
3665
        Policy2LastUpdate              sql.NullInt64
3666
        Policy2Disabled                sql.NullBool
3667
        Policy2InboundBaseFeeMsat      sql.NullInt64
3668
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3669
        Policy2MessageFlags            sql.NullInt16
3670
        Policy2ChannelFlags            sql.NullInt16
3671
        Policy2Signature               []byte
3672
        Policy2BlockHeight             sql.NullInt64
3673
        Policy2DisableFlags            sql.NullInt16
3674
}
3675

3676
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
3677
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
3678
        if err != nil {
×
3679
                return nil, err
×
3680
        }
×
3681
        defer rows.Close()
×
3682
        var items []ListChannelsWithPoliciesPaginatedRow
×
3683
        for rows.Next() {
×
3684
                var i ListChannelsWithPoliciesPaginatedRow
×
3685
                if err := rows.Scan(
×
3686
                        &i.GraphChannel.ID,
×
3687
                        &i.GraphChannel.Version,
×
3688
                        &i.GraphChannel.Scid,
×
3689
                        &i.GraphChannel.NodeID1,
×
3690
                        &i.GraphChannel.NodeID2,
×
3691
                        &i.GraphChannel.Outpoint,
×
3692
                        &i.GraphChannel.Capacity,
×
3693
                        &i.GraphChannel.BitcoinKey1,
×
3694
                        &i.GraphChannel.BitcoinKey2,
×
3695
                        &i.GraphChannel.Node1Signature,
×
3696
                        &i.GraphChannel.Node2Signature,
×
3697
                        &i.GraphChannel.Bitcoin1Signature,
×
3698
                        &i.GraphChannel.Bitcoin2Signature,
×
3699
                        &i.GraphChannel.Signature,
×
3700
                        &i.GraphChannel.FundingPkScript,
×
3701
                        &i.GraphChannel.MerkleRootHash,
×
3702
                        &i.Node1Pubkey,
×
3703
                        &i.Node2Pubkey,
×
3704
                        &i.Policy1ID,
×
3705
                        &i.Policy1NodeID,
×
3706
                        &i.Policy1Version,
×
3707
                        &i.Policy1Timelock,
×
3708
                        &i.Policy1FeePpm,
×
3709
                        &i.Policy1BaseFeeMsat,
×
3710
                        &i.Policy1MinHtlcMsat,
×
3711
                        &i.Policy1MaxHtlcMsat,
×
3712
                        &i.Policy1LastUpdate,
×
3713
                        &i.Policy1Disabled,
×
3714
                        &i.Policy1InboundBaseFeeMsat,
×
3715
                        &i.Policy1InboundFeeRateMilliMsat,
×
3716
                        &i.Policy1MessageFlags,
×
3717
                        &i.Policy1ChannelFlags,
×
3718
                        &i.Policy1BlockHeight,
×
3719
                        &i.Policy1DisableFlags,
×
3720
                        &i.Policy1Signature,
×
3721
                        &i.Policy2ID,
×
3722
                        &i.Policy2NodeID,
×
3723
                        &i.Policy2Version,
×
3724
                        &i.Policy2Timelock,
×
3725
                        &i.Policy2FeePpm,
×
3726
                        &i.Policy2BaseFeeMsat,
×
3727
                        &i.Policy2MinHtlcMsat,
×
3728
                        &i.Policy2MaxHtlcMsat,
×
3729
                        &i.Policy2LastUpdate,
×
3730
                        &i.Policy2Disabled,
×
3731
                        &i.Policy2InboundBaseFeeMsat,
×
3732
                        &i.Policy2InboundFeeRateMilliMsat,
×
3733
                        &i.Policy2MessageFlags,
×
3734
                        &i.Policy2ChannelFlags,
×
3735
                        &i.Policy2Signature,
×
3736
                        &i.Policy2BlockHeight,
×
3737
                        &i.Policy2DisableFlags,
×
3738
                ); err != nil {
×
3739
                        return nil, err
×
3740
                }
×
3741
                items = append(items, i)
×
3742
        }
3743
        if err := rows.Close(); err != nil {
×
3744
                return nil, err
×
3745
        }
×
3746
        if err := rows.Err(); err != nil {
×
3747
                return nil, err
×
3748
        }
×
3749
        return items, nil
×
3750
}
3751

3752
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
3753
SELECT id, pub_key
3754
FROM graph_nodes
3755
WHERE version = $1  AND id > $2
3756
ORDER BY id
3757
LIMIT $3
3758
`
3759

3760
type ListNodeIDsAndPubKeysParams struct {
3761
        Version int16
3762
        ID      int64
3763
        Limit   int32
3764
}
3765

3766
type ListNodeIDsAndPubKeysRow struct {
3767
        ID     int64
3768
        PubKey []byte
3769
}
3770

3771
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
3772
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
3773
        if err != nil {
×
3774
                return nil, err
×
3775
        }
×
3776
        defer rows.Close()
×
3777
        var items []ListNodeIDsAndPubKeysRow
×
3778
        for rows.Next() {
×
3779
                var i ListNodeIDsAndPubKeysRow
×
3780
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
3781
                        return nil, err
×
3782
                }
×
3783
                items = append(items, i)
×
3784
        }
3785
        if err := rows.Close(); err != nil {
×
3786
                return nil, err
×
3787
        }
×
3788
        if err := rows.Err(); err != nil {
×
3789
                return nil, err
×
3790
        }
×
3791
        return items, nil
×
3792
}
3793

3794
const listNodesPaginated = `-- name: ListNodesPaginated :many
3795
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
3796
FROM graph_nodes
3797
WHERE version = $1 AND id > $2
3798
ORDER BY id
3799
LIMIT $3
3800
`
3801

3802
type ListNodesPaginatedParams struct {
3803
        Version int16
3804
        ID      int64
3805
        Limit   int32
3806
}
3807

3808
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
3809
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
3810
        if err != nil {
×
3811
                return nil, err
×
3812
        }
×
3813
        defer rows.Close()
×
3814
        var items []GraphNode
×
3815
        for rows.Next() {
×
3816
                var i GraphNode
×
3817
                if err := rows.Scan(
×
3818
                        &i.ID,
×
3819
                        &i.Version,
×
3820
                        &i.PubKey,
×
3821
                        &i.Alias,
×
3822
                        &i.LastUpdate,
×
3823
                        &i.Color,
×
3824
                        &i.Signature,
×
3825
                        &i.BlockHeight,
×
3826
                ); err != nil {
×
3827
                        return nil, err
×
3828
                }
×
3829
                items = append(items, i)
×
3830
        }
3831
        if err := rows.Close(); err != nil {
×
3832
                return nil, err
×
3833
        }
×
3834
        if err := rows.Err(); err != nil {
×
3835
                return nil, err
×
3836
        }
×
3837
        return items, nil
×
3838
}
3839

3840
const nodeExists = `-- name: NodeExists :one
3841
SELECT EXISTS (
3842
    SELECT 1
3843
    FROM graph_nodes
3844
    WHERE pub_key = $1
3845
      AND version = $2
3846
) AS node_exists
3847
`
3848

3849
type NodeExistsParams struct {
3850
        PubKey  []byte
3851
        Version int16
3852
}
3853

3854
func (q *Queries) NodeExists(ctx context.Context, arg NodeExistsParams) (bool, error) {
×
3855
        row := q.db.QueryRowContext(ctx, nodeExists, arg.PubKey, arg.Version)
×
3856
        var node_exists bool
×
3857
        err := row.Scan(&node_exists)
×
3858
        return node_exists, err
×
3859
}
×
3860

3861
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
3862
/* ─────────────────────────────────────────────
3863
   graph_channel_policy_extra_types table queries
3864
   ─────────────────────────────────────────────
3865
*/
3866

3867
INSERT INTO graph_channel_policy_extra_types (
3868
    channel_policy_id, type, value
3869
)
3870
VALUES ($1, $2, $3)
3871
ON CONFLICT (channel_policy_id, type)
3872
    -- If a conflict occurs on channel_policy_id and type, then we update the
3873
    -- value.
3874
    DO UPDATE SET value = EXCLUDED.value
3875
`
3876

3877
type UpsertChanPolicyExtraTypeParams struct {
3878
        ChannelPolicyID int64
3879
        Type            int64
3880
        Value           []byte
3881
}
3882

3883
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
3884
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
3885
        return err
×
3886
}
×
3887

3888
const upsertChannelExtraType = `-- name: UpsertChannelExtraType :exec
3889
/* ─────────────────────────────────────────────
3890
   graph_channel_extra_types table queries
3891
   ─────────────────────────────────────────────
3892
*/
3893

3894
INSERT INTO graph_channel_extra_types (
3895
    channel_id, type, value
3896
)
3897
VALUES ($1, $2, $3)
3898
    ON CONFLICT (channel_id, type)
3899
    -- Update the value if a conflict occurs on channel_id and type.
3900
    DO UPDATE SET value = EXCLUDED.value
3901
`
3902

3903
type UpsertChannelExtraTypeParams struct {
3904
        ChannelID int64
3905
        Type      int64
3906
        Value     []byte
3907
}
3908

3909
func (q *Queries) UpsertChannelExtraType(ctx context.Context, arg UpsertChannelExtraTypeParams) error {
×
3910
        _, err := q.db.ExecContext(ctx, upsertChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
3911
        return err
×
3912
}
×
3913

3914
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
3915
/* ─────────────────────────────────────────────
3916
   graph_channel_policies table queries
3917
   ─────────────────────────────────────────────
3918
*/
3919

3920
INSERT INTO graph_channel_policies (
3921
    version, channel_id, node_id, timelock, fee_ppm,
3922
    base_fee_msat, min_htlc_msat, last_update, disabled,
3923
    max_htlc_msat, inbound_base_fee_msat,
3924
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
3925
    signature, block_height, disable_flags
3926
) VALUES  (
3927
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
3928
)
3929
ON CONFLICT (channel_id, node_id, version)
3930
    -- Update the following fields if a conflict occurs on channel_id,
3931
    -- node_id, and version.
3932
    DO UPDATE SET
3933
        timelock = EXCLUDED.timelock,
3934
        fee_ppm = EXCLUDED.fee_ppm,
3935
        base_fee_msat = EXCLUDED.base_fee_msat,
3936
        min_htlc_msat = EXCLUDED.min_htlc_msat,
3937
        last_update = EXCLUDED.last_update,
3938
        disabled = EXCLUDED.disabled,
3939
        max_htlc_msat = EXCLUDED.max_htlc_msat,
3940
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
3941
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
3942
        message_flags = EXCLUDED.message_flags,
3943
        channel_flags = EXCLUDED.channel_flags,
3944
        signature = EXCLUDED.signature,
3945
        block_height = EXCLUDED.block_height,
3946
        disable_flags = EXCLUDED.disable_flags
3947
WHERE (
3948
    EXCLUDED.version = 1 AND (
3949
        graph_channel_policies.last_update IS NULL
3950
        OR EXCLUDED.last_update > graph_channel_policies.last_update
3951
    )
3952
)
3953
OR (
3954
    EXCLUDED.version = 2 AND (
3955
        graph_channel_policies.block_height IS NULL
3956
        OR EXCLUDED.block_height >= graph_channel_policies.block_height
3957
    )
3958
)
3959
RETURNING id
3960
`
3961

3962
type UpsertEdgePolicyParams struct {
3963
        Version                 int16
3964
        ChannelID               int64
3965
        NodeID                  int64
3966
        Timelock                int32
3967
        FeePpm                  int64
3968
        BaseFeeMsat             int64
3969
        MinHtlcMsat             int64
3970
        LastUpdate              sql.NullInt64
3971
        Disabled                sql.NullBool
3972
        MaxHtlcMsat             sql.NullInt64
3973
        InboundBaseFeeMsat      sql.NullInt64
3974
        InboundFeeRateMilliMsat sql.NullInt64
3975
        MessageFlags            sql.NullInt16
3976
        ChannelFlags            sql.NullInt16
3977
        Signature               []byte
3978
        BlockHeight             sql.NullInt64
3979
        DisableFlags            sql.NullInt16
3980
}
3981

3982
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
3983
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
3984
                arg.Version,
×
3985
                arg.ChannelID,
×
3986
                arg.NodeID,
×
3987
                arg.Timelock,
×
3988
                arg.FeePpm,
×
3989
                arg.BaseFeeMsat,
×
3990
                arg.MinHtlcMsat,
×
3991
                arg.LastUpdate,
×
3992
                arg.Disabled,
×
3993
                arg.MaxHtlcMsat,
×
3994
                arg.InboundBaseFeeMsat,
×
3995
                arg.InboundFeeRateMilliMsat,
×
3996
                arg.MessageFlags,
×
3997
                arg.ChannelFlags,
×
3998
                arg.Signature,
×
3999
                arg.BlockHeight,
×
4000
                arg.DisableFlags,
×
4001
        )
×
4002
        var id int64
×
4003
        err := row.Scan(&id)
×
4004
        return id, err
×
4005
}
×
4006

4007
const upsertNode = `-- name: UpsertNode :one
4008
/* ─────────────────────────────────────────────
4009
   graph_nodes table queries
4010
   ───────────────────────────��─────────────────
4011
*/
4012

4013
INSERT INTO graph_nodes (
4014
    version, pub_key, alias, last_update, block_height, color, signature
4015
) VALUES (
4016
    $1, $2, $3, $4, $5, $6, $7
4017
)
4018
ON CONFLICT (pub_key, version)
4019
    -- Update the following fields if a conflict occurs on pub_key
4020
    -- and version.
4021
    DO UPDATE SET
4022
        alias = EXCLUDED.alias,
4023
        last_update = EXCLUDED.last_update,
4024
        block_height = EXCLUDED.block_height,
4025
        color = EXCLUDED.color,
4026
        signature = EXCLUDED.signature
4027
WHERE (graph_nodes.last_update IS NULL
4028
    OR EXCLUDED.last_update > graph_nodes.last_update)
4029
AND (graph_nodes.block_height IS NULL
4030
    OR EXCLUDED.block_height >= graph_nodes.block_height)
4031
RETURNING id
4032
`
4033

4034
type UpsertNodeParams struct {
4035
        Version     int16
4036
        PubKey      []byte
4037
        Alias       sql.NullString
4038
        LastUpdate  sql.NullInt64
4039
        BlockHeight sql.NullInt64
4040
        Color       sql.NullString
4041
        Signature   []byte
4042
}
4043

4044
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
4045
        row := q.db.QueryRowContext(ctx, upsertNode,
×
4046
                arg.Version,
×
4047
                arg.PubKey,
×
4048
                arg.Alias,
×
4049
                arg.LastUpdate,
×
4050
                arg.BlockHeight,
×
4051
                arg.Color,
×
4052
                arg.Signature,
×
4053
        )
×
4054
        var id int64
×
4055
        err := row.Scan(&id)
×
4056
        return id, err
×
4057
}
×
4058

4059
const upsertNodeAddress = `-- name: UpsertNodeAddress :exec
4060
/* ─────────────────────────────────────────────
4061
   graph_node_addresses table queries
4062
   ───────────────────────────────────��─────────
4063
*/
4064

4065
INSERT INTO graph_node_addresses (
4066
    node_id,
4067
    type,
4068
    address,
4069
    position
4070
) VALUES (
4071
    $1, $2, $3, $4
4072
) ON CONFLICT (node_id, type, position)
4073
    DO UPDATE SET address = EXCLUDED.address
4074
`
4075

4076
type UpsertNodeAddressParams struct {
4077
        NodeID   int64
4078
        Type     int16
4079
        Address  string
4080
        Position int32
4081
}
4082

4083
func (q *Queries) UpsertNodeAddress(ctx context.Context, arg UpsertNodeAddressParams) error {
×
4084
        _, err := q.db.ExecContext(ctx, upsertNodeAddress,
×
4085
                arg.NodeID,
×
4086
                arg.Type,
×
4087
                arg.Address,
×
4088
                arg.Position,
×
4089
        )
×
4090
        return err
×
4091
}
×
4092

4093
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
4094
/* ─────────────────────────────────────────────
4095
   graph_node_extra_types table queries
4096
   ─────────────────────────────────────────────
4097
*/
4098

4099
INSERT INTO graph_node_extra_types (
4100
    node_id, type, value
4101
)
4102
VALUES ($1, $2, $3)
4103
ON CONFLICT (type, node_id)
4104
    -- Update the value if a conflict occurs on type
4105
    -- and node_id.
4106
    DO UPDATE SET value = EXCLUDED.value
4107
`
4108

4109
type UpsertNodeExtraTypeParams struct {
4110
        NodeID int64
4111
        Type   int64
4112
        Value  []byte
4113
}
4114

4115
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
4116
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
4117
        return err
×
4118
}
×
4119

4120
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
4121
/* ───────────────────────────���─────────────────
4122
    graph_prune_log table queries
4123
    ─────────────────────────────────────────────
4124
*/
4125

4126
INSERT INTO graph_prune_log (
4127
    block_height, block_hash
4128
) VALUES (
4129
    $1, $2
4130
)
4131
ON CONFLICT(block_height) DO UPDATE SET
4132
    block_hash = EXCLUDED.block_hash
4133
`
4134

4135
type UpsertPruneLogEntryParams struct {
4136
        BlockHeight int64
4137
        BlockHash   []byte
4138
}
4139

4140
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
4141
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
4142
        return err
×
4143
}
×
4144

4145
const upsertSourceNode = `-- name: UpsertSourceNode :one
4146
INSERT INTO graph_nodes (
4147
    version, pub_key, alias, last_update, block_height, color, signature
4148
) VALUES (
4149
    $1, $2, $3, $4, $5, $6, $7
4150
)
4151
ON CONFLICT (pub_key, version)
4152
    -- Update the following fields if a conflict occurs on pub_key
4153
    -- and version.
4154
    DO UPDATE SET
4155
        alias = EXCLUDED.alias,
4156
        last_update = EXCLUDED.last_update,
4157
        block_height = EXCLUDED.block_height,
4158
        color = EXCLUDED.color,
4159
        signature = EXCLUDED.signature
4160
WHERE graph_nodes.last_update IS NULL
4161
    OR EXCLUDED.last_update >= graph_nodes.last_update
4162
AND (graph_nodes.block_height IS NULL
4163
   OR EXCLUDED.block_height >= graph_nodes.block_height)
4164
RETURNING id
4165
`
4166

4167
type UpsertSourceNodeParams struct {
4168
        Version     int16
4169
        PubKey      []byte
4170
        Alias       sql.NullString
4171
        LastUpdate  sql.NullInt64
4172
        BlockHeight sql.NullInt64
4173
        Color       sql.NullString
4174
        Signature   []byte
4175
}
4176

4177
// We use a separate upsert for our own node since we want to be less strict
4178
// about the last_update field. For our own node, we always want to
4179
// update the record even if the last_update is the same as what we have.
4180
func (q *Queries) UpsertSourceNode(ctx context.Context, arg UpsertSourceNodeParams) (int64, error) {
×
4181
        row := q.db.QueryRowContext(ctx, upsertSourceNode,
×
4182
                arg.Version,
×
4183
                arg.PubKey,
×
4184
                arg.Alias,
×
4185
                arg.LastUpdate,
×
4186
                arg.BlockHeight,
×
4187
                arg.Color,
×
4188
                arg.Signature,
×
4189
        )
×
4190
        var id int64
×
4191
        err := row.Scan(&id)
×
4192
        return id, err
×
4193
}
×
4194

4195
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
4196
/* ─────────────────────────────────────────────
4197
   graph_zombie_channels table queries
4198
   ─────────────────────────────────────────────
4199
*/
4200

4201
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
4202
VALUES ($1, $2, $3, $4)
4203
ON CONFLICT (scid, version)
4204
DO UPDATE SET
4205
    -- If a conflict exists for the SCID and version pair, then we
4206
    -- update the node keys.
4207
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
4208
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
4209
`
4210

4211
type UpsertZombieChannelParams struct {
4212
        Scid     []byte
4213
        Version  int16
4214
        NodeKey1 []byte
4215
        NodeKey2 []byte
4216
}
4217

4218
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
4219
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
4220
                arg.Scid,
×
4221
                arg.Version,
×
4222
                arg.NodeKey1,
×
4223
                arg.NodeKey2,
×
4224
        )
×
4225
        return err
×
4226
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc