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

lightningnetwork / lnd / 24529777950

16 Apr 2026 07:29PM UTC coverage: 62.205% (-0.02%) from 62.223%
24529777950

Pull #10689

github

web-flow
Merge 0c4c96e1a into 52a904118
Pull Request #10689: scripts+GitHub: use bitcoind v30.0

143507 of 230701 relevant lines covered (62.2%)

19105.69 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 getChannelsByPolicyBlockRange = `-- name: GetChannelsByPolicyBlockRange :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.block_height >= $2 AND cp1.block_height < $3)
1230
       OR
1231
       (cp2.block_height >= $2 AND cp2.block_height < $3)
1232
  )
1233
  -- Pagination using compound cursor (max_block_height, id).
1234
  -- We use COALESCE with -1 as sentinel since block heights are always positive.
1235
  AND (
1236
       (CASE
1237
           WHEN COALESCE(cp1.block_height, 0) >= COALESCE(cp2.block_height, 0)
1238
               THEN COALESCE(cp1.block_height, 0)
1239
           ELSE COALESCE(cp2.block_height, 0)
1240
       END > COALESCE($4, -1))
1241
       OR
1242
       (CASE
1243
           WHEN COALESCE(cp1.block_height, 0) >= COALESCE(cp2.block_height, 0)
1244
               THEN COALESCE(cp1.block_height, 0)
1245
           ELSE COALESCE(cp2.block_height, 0)
1246
       END = COALESCE($4, -1)
1247
       AND c.id > COALESCE($5, -1))
1248
  )
1249
ORDER BY
1250
    CASE
1251
        WHEN COALESCE(cp1.block_height, 0) >= COALESCE(cp2.block_height, 0)
1252
            THEN COALESCE(cp1.block_height, 0)
1253
        ELSE COALESCE(cp2.block_height, 0)
1254
    END ASC,
1255
    c.id ASC
1256
LIMIT COALESCE($6, 999999999)
1257
`
1258

1259
type GetChannelsByPolicyBlockRangeParams struct {
1260
        Version         int16
1261
        StartHeight     sql.NullInt64
1262
        EndHeight       sql.NullInt64
1263
        LastBlockHeight sql.NullInt64
1264
        LastID          sql.NullInt64
1265
        MaxResults      interface{}
1266
}
1267

1268
type GetChannelsByPolicyBlockRangeRow 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) GetChannelsByPolicyBlockRange(ctx context.Context, arg GetChannelsByPolicyBlockRangeParams) ([]GetChannelsByPolicyBlockRangeRow, error) {
×
1309
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyBlockRange,
×
1310
                arg.Version,
×
1311
                arg.StartHeight,
×
1312
                arg.EndHeight,
×
1313
                arg.LastBlockHeight,
×
1314
                arg.LastID,
×
1315
                arg.MaxResults,
×
1316
        )
×
1317
        if err != nil {
×
1318
                return nil, err
×
1319
        }
×
1320
        defer rows.Close()
×
1321
        var items []GetChannelsByPolicyBlockRangeRow
×
1322
        for rows.Next() {
×
1323
                var i GetChannelsByPolicyBlockRangeRow
×
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 getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
1406
SELECT
1407
    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,
1408
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature, n1.block_height,
1409
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature, n2.block_height,
1410

1411
    -- Policy 1 (node_id_1)
1412
    cp1.id AS policy1_id,
1413
    cp1.node_id AS policy1_node_id,
1414
    cp1.version AS policy1_version,
1415
    cp1.timelock AS policy1_timelock,
1416
    cp1.fee_ppm AS policy1_fee_ppm,
1417
    cp1.base_fee_msat AS policy1_base_fee_msat,
1418
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1419
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1420
    cp1.last_update AS policy1_last_update,
1421
    cp1.disabled AS policy1_disabled,
1422
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1423
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1424
    cp1.message_flags AS policy1_message_flags,
1425
    cp1.channel_flags AS policy1_channel_flags,
1426
    cp1.signature AS policy1_signature,
1427
    cp1.block_height AS policy1_block_height,
1428
    cp1.disable_flags AS policy1_disable_flags,
1429

1430
    -- Policy 2 (node_id_2)
1431
    cp2.id AS policy2_id,
1432
    cp2.node_id AS policy2_node_id,
1433
    cp2.version AS policy2_version,
1434
    cp2.timelock AS policy2_timelock,
1435
    cp2.fee_ppm AS policy2_fee_ppm,
1436
    cp2.base_fee_msat AS policy2_base_fee_msat,
1437
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1438
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1439
    cp2.last_update AS policy2_last_update,
1440
    cp2.disabled AS policy2_disabled,
1441
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1442
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1443
    cp2.message_flags AS policy2_message_flags,
1444
    cp2.channel_flags AS policy2_channel_flags,
1445
    cp2.signature AS policy2_signature,
1446
    cp2.block_height AS policy2_block_height,
1447
    cp2.disable_flags AS policy2_disable_flags
1448

1449
FROM graph_channels c
1450
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1451
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1452
    LEFT JOIN graph_channel_policies cp1
1453
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1454
    LEFT JOIN graph_channel_policies cp2
1455
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1456
WHERE c.version = $1
1457
  AND (
1458
       (cp1.last_update >= $2 AND cp1.last_update < $3)
1459
       OR
1460
       (cp2.last_update >= $2 AND cp2.last_update < $3)
1461
  )
1462
  -- Pagination using compound cursor (max_update_time, id).
1463
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
1464
  AND (
1465
       (CASE
1466
           WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1467
               THEN COALESCE(cp1.last_update, 0)
1468
           ELSE COALESCE(cp2.last_update, 0)
1469
       END > COALESCE($4, -1))
1470
       OR 
1471
       (CASE
1472
           WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1473
               THEN COALESCE(cp1.last_update, 0)
1474
           ELSE COALESCE(cp2.last_update, 0)
1475
       END = COALESCE($4, -1) 
1476
       AND c.id > COALESCE($5, -1))
1477
  )
1478
ORDER BY
1479
    CASE
1480
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1481
            THEN COALESCE(cp1.last_update, 0)
1482
        ELSE COALESCE(cp2.last_update, 0)
1483
    END ASC,
1484
    c.id ASC
1485
LIMIT COALESCE($6, 999999999)
1486
`
1487

1488
type GetChannelsByPolicyLastUpdateRangeParams struct {
1489
        Version        int16
1490
        StartTime      sql.NullInt64
1491
        EndTime        sql.NullInt64
1492
        LastUpdateTime sql.NullInt64
1493
        LastID         sql.NullInt64
1494
        MaxResults     interface{}
1495
}
1496

1497
type GetChannelsByPolicyLastUpdateRangeRow struct {
1498
        GraphChannel                   GraphChannel
1499
        GraphNode                      GraphNode
1500
        GraphNode_2                    GraphNode
1501
        Policy1ID                      sql.NullInt64
1502
        Policy1NodeID                  sql.NullInt64
1503
        Policy1Version                 sql.NullInt16
1504
        Policy1Timelock                sql.NullInt32
1505
        Policy1FeePpm                  sql.NullInt64
1506
        Policy1BaseFeeMsat             sql.NullInt64
1507
        Policy1MinHtlcMsat             sql.NullInt64
1508
        Policy1MaxHtlcMsat             sql.NullInt64
1509
        Policy1LastUpdate              sql.NullInt64
1510
        Policy1Disabled                sql.NullBool
1511
        Policy1InboundBaseFeeMsat      sql.NullInt64
1512
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1513
        Policy1MessageFlags            sql.NullInt16
1514
        Policy1ChannelFlags            sql.NullInt16
1515
        Policy1Signature               []byte
1516
        Policy1BlockHeight             sql.NullInt64
1517
        Policy1DisableFlags            sql.NullInt16
1518
        Policy2ID                      sql.NullInt64
1519
        Policy2NodeID                  sql.NullInt64
1520
        Policy2Version                 sql.NullInt16
1521
        Policy2Timelock                sql.NullInt32
1522
        Policy2FeePpm                  sql.NullInt64
1523
        Policy2BaseFeeMsat             sql.NullInt64
1524
        Policy2MinHtlcMsat             sql.NullInt64
1525
        Policy2MaxHtlcMsat             sql.NullInt64
1526
        Policy2LastUpdate              sql.NullInt64
1527
        Policy2Disabled                sql.NullBool
1528
        Policy2InboundBaseFeeMsat      sql.NullInt64
1529
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1530
        Policy2MessageFlags            sql.NullInt16
1531
        Policy2ChannelFlags            sql.NullInt16
1532
        Policy2Signature               []byte
1533
        Policy2BlockHeight             sql.NullInt64
1534
        Policy2DisableFlags            sql.NullInt16
1535
}
1536

1537
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
1538
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange,
×
1539
                arg.Version,
×
1540
                arg.StartTime,
×
1541
                arg.EndTime,
×
1542
                arg.LastUpdateTime,
×
1543
                arg.LastID,
×
1544
                arg.MaxResults,
×
1545
        )
×
1546
        if err != nil {
×
1547
                return nil, err
×
1548
        }
×
1549
        defer rows.Close()
×
1550
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
1551
        for rows.Next() {
×
1552
                var i GetChannelsByPolicyLastUpdateRangeRow
×
1553
                if err := rows.Scan(
×
1554
                        &i.GraphChannel.ID,
×
1555
                        &i.GraphChannel.Version,
×
1556
                        &i.GraphChannel.Scid,
×
1557
                        &i.GraphChannel.NodeID1,
×
1558
                        &i.GraphChannel.NodeID2,
×
1559
                        &i.GraphChannel.Outpoint,
×
1560
                        &i.GraphChannel.Capacity,
×
1561
                        &i.GraphChannel.BitcoinKey1,
×
1562
                        &i.GraphChannel.BitcoinKey2,
×
1563
                        &i.GraphChannel.Node1Signature,
×
1564
                        &i.GraphChannel.Node2Signature,
×
1565
                        &i.GraphChannel.Bitcoin1Signature,
×
1566
                        &i.GraphChannel.Bitcoin2Signature,
×
1567
                        &i.GraphChannel.Signature,
×
1568
                        &i.GraphChannel.FundingPkScript,
×
1569
                        &i.GraphChannel.MerkleRootHash,
×
1570
                        &i.GraphNode.ID,
×
1571
                        &i.GraphNode.Version,
×
1572
                        &i.GraphNode.PubKey,
×
1573
                        &i.GraphNode.Alias,
×
1574
                        &i.GraphNode.LastUpdate,
×
1575
                        &i.GraphNode.Color,
×
1576
                        &i.GraphNode.Signature,
×
1577
                        &i.GraphNode.BlockHeight,
×
1578
                        &i.GraphNode_2.ID,
×
1579
                        &i.GraphNode_2.Version,
×
1580
                        &i.GraphNode_2.PubKey,
×
1581
                        &i.GraphNode_2.Alias,
×
1582
                        &i.GraphNode_2.LastUpdate,
×
1583
                        &i.GraphNode_2.Color,
×
1584
                        &i.GraphNode_2.Signature,
×
1585
                        &i.GraphNode_2.BlockHeight,
×
1586
                        &i.Policy1ID,
×
1587
                        &i.Policy1NodeID,
×
1588
                        &i.Policy1Version,
×
1589
                        &i.Policy1Timelock,
×
1590
                        &i.Policy1FeePpm,
×
1591
                        &i.Policy1BaseFeeMsat,
×
1592
                        &i.Policy1MinHtlcMsat,
×
1593
                        &i.Policy1MaxHtlcMsat,
×
1594
                        &i.Policy1LastUpdate,
×
1595
                        &i.Policy1Disabled,
×
1596
                        &i.Policy1InboundBaseFeeMsat,
×
1597
                        &i.Policy1InboundFeeRateMilliMsat,
×
1598
                        &i.Policy1MessageFlags,
×
1599
                        &i.Policy1ChannelFlags,
×
1600
                        &i.Policy1Signature,
×
1601
                        &i.Policy1BlockHeight,
×
1602
                        &i.Policy1DisableFlags,
×
1603
                        &i.Policy2ID,
×
1604
                        &i.Policy2NodeID,
×
1605
                        &i.Policy2Version,
×
1606
                        &i.Policy2Timelock,
×
1607
                        &i.Policy2FeePpm,
×
1608
                        &i.Policy2BaseFeeMsat,
×
1609
                        &i.Policy2MinHtlcMsat,
×
1610
                        &i.Policy2MaxHtlcMsat,
×
1611
                        &i.Policy2LastUpdate,
×
1612
                        &i.Policy2Disabled,
×
1613
                        &i.Policy2InboundBaseFeeMsat,
×
1614
                        &i.Policy2InboundFeeRateMilliMsat,
×
1615
                        &i.Policy2MessageFlags,
×
1616
                        &i.Policy2ChannelFlags,
×
1617
                        &i.Policy2Signature,
×
1618
                        &i.Policy2BlockHeight,
×
1619
                        &i.Policy2DisableFlags,
×
1620
                ); err != nil {
×
1621
                        return nil, err
×
1622
                }
×
1623
                items = append(items, i)
×
1624
        }
1625
        if err := rows.Close(); err != nil {
×
1626
                return nil, err
×
1627
        }
×
1628
        if err := rows.Err(); err != nil {
×
1629
                return nil, err
×
1630
        }
×
1631
        return items, nil
×
1632
}
1633

1634
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1635
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,
1636
    n1.pub_key AS node1_pub_key,
1637
    n2.pub_key AS node2_pub_key
1638
FROM graph_channels c
1639
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1640
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1641
WHERE scid >= $1
1642
  AND scid < $2
1643
`
1644

1645
type GetChannelsBySCIDRangeParams struct {
1646
        StartScid []byte
1647
        EndScid   []byte
1648
}
1649

1650
type GetChannelsBySCIDRangeRow struct {
1651
        GraphChannel GraphChannel
1652
        Node1PubKey  []byte
1653
        Node2PubKey  []byte
1654
}
1655

1656
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1657
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1658
        if err != nil {
×
1659
                return nil, err
×
1660
        }
×
1661
        defer rows.Close()
×
1662
        var items []GetChannelsBySCIDRangeRow
×
1663
        for rows.Next() {
×
1664
                var i GetChannelsBySCIDRangeRow
×
1665
                if err := rows.Scan(
×
1666
                        &i.GraphChannel.ID,
×
1667
                        &i.GraphChannel.Version,
×
1668
                        &i.GraphChannel.Scid,
×
1669
                        &i.GraphChannel.NodeID1,
×
1670
                        &i.GraphChannel.NodeID2,
×
1671
                        &i.GraphChannel.Outpoint,
×
1672
                        &i.GraphChannel.Capacity,
×
1673
                        &i.GraphChannel.BitcoinKey1,
×
1674
                        &i.GraphChannel.BitcoinKey2,
×
1675
                        &i.GraphChannel.Node1Signature,
×
1676
                        &i.GraphChannel.Node2Signature,
×
1677
                        &i.GraphChannel.Bitcoin1Signature,
×
1678
                        &i.GraphChannel.Bitcoin2Signature,
×
1679
                        &i.GraphChannel.Signature,
×
1680
                        &i.GraphChannel.FundingPkScript,
×
1681
                        &i.GraphChannel.MerkleRootHash,
×
1682
                        &i.Node1PubKey,
×
1683
                        &i.Node2PubKey,
×
1684
                ); err != nil {
×
1685
                        return nil, err
×
1686
                }
×
1687
                items = append(items, i)
×
1688
        }
1689
        if err := rows.Close(); err != nil {
×
1690
                return nil, err
×
1691
        }
×
1692
        if err := rows.Err(); err != nil {
×
1693
                return nil, err
×
1694
        }
×
1695
        return items, nil
×
1696
}
1697

1698
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1699
SELECT
1700
    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,
1701
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature, n1.block_height,
1702
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature, n2.block_height,
1703

1704
    -- Policy 1
1705
    cp1.id AS policy1_id,
1706
    cp1.node_id AS policy1_node_id,
1707
    cp1.version AS policy1_version,
1708
    cp1.timelock AS policy1_timelock,
1709
    cp1.fee_ppm AS policy1_fee_ppm,
1710
    cp1.base_fee_msat AS policy1_base_fee_msat,
1711
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1712
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1713
    cp1.last_update AS policy1_last_update,
1714
    cp1.disabled AS policy1_disabled,
1715
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1716
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1717
    cp1.message_flags AS policy1_message_flags,
1718
    cp1.channel_flags AS policy1_channel_flags,
1719
    cp1.signature AS policy1_signature,
1720
    cp1.block_height AS policy1_block_height,
1721
    cp1.disable_flags AS policy1_disable_flags,
1722

1723
    -- Policy 2
1724
    cp2.id AS policy2_id,
1725
    cp2.node_id AS policy2_node_id,
1726
    cp2.version AS policy2_version,
1727
    cp2.timelock AS policy2_timelock,
1728
    cp2.fee_ppm AS policy2_fee_ppm,
1729
    cp2.base_fee_msat AS policy2_base_fee_msat,
1730
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1731
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1732
    cp2.last_update AS policy2_last_update,
1733
    cp2.disabled AS policy2_disabled,
1734
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1735
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1736
    cp2.message_flags AS policy_2_message_flags,
1737
    cp2.channel_flags AS policy_2_channel_flags,
1738
    cp2.signature AS policy2_signature,
1739
    cp2.block_height AS policy2_block_height,
1740
    cp2.disable_flags AS policy2_disable_flags
1741

1742
FROM graph_channels c
1743
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1744
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1745
    LEFT JOIN graph_channel_policies cp1
1746
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1747
    LEFT JOIN graph_channel_policies cp2
1748
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1749
WHERE
1750
    c.version = $1
1751
  AND c.scid IN (/*SLICE:scids*/?)
1752
`
1753

1754
type GetChannelsBySCIDWithPoliciesParams struct {
1755
        Version int16
1756
        Scids   [][]byte
1757
}
1758

1759
type GetChannelsBySCIDWithPoliciesRow struct {
1760
        GraphChannel                   GraphChannel
1761
        GraphNode                      GraphNode
1762
        GraphNode_2                    GraphNode
1763
        Policy1ID                      sql.NullInt64
1764
        Policy1NodeID                  sql.NullInt64
1765
        Policy1Version                 sql.NullInt16
1766
        Policy1Timelock                sql.NullInt32
1767
        Policy1FeePpm                  sql.NullInt64
1768
        Policy1BaseFeeMsat             sql.NullInt64
1769
        Policy1MinHtlcMsat             sql.NullInt64
1770
        Policy1MaxHtlcMsat             sql.NullInt64
1771
        Policy1LastUpdate              sql.NullInt64
1772
        Policy1Disabled                sql.NullBool
1773
        Policy1InboundBaseFeeMsat      sql.NullInt64
1774
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1775
        Policy1MessageFlags            sql.NullInt16
1776
        Policy1ChannelFlags            sql.NullInt16
1777
        Policy1Signature               []byte
1778
        Policy1BlockHeight             sql.NullInt64
1779
        Policy1DisableFlags            sql.NullInt16
1780
        Policy2ID                      sql.NullInt64
1781
        Policy2NodeID                  sql.NullInt64
1782
        Policy2Version                 sql.NullInt16
1783
        Policy2Timelock                sql.NullInt32
1784
        Policy2FeePpm                  sql.NullInt64
1785
        Policy2BaseFeeMsat             sql.NullInt64
1786
        Policy2MinHtlcMsat             sql.NullInt64
1787
        Policy2MaxHtlcMsat             sql.NullInt64
1788
        Policy2LastUpdate              sql.NullInt64
1789
        Policy2Disabled                sql.NullBool
1790
        Policy2InboundBaseFeeMsat      sql.NullInt64
1791
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1792
        Policy2MessageFlags            sql.NullInt16
1793
        Policy2ChannelFlags            sql.NullInt16
1794
        Policy2Signature               []byte
1795
        Policy2BlockHeight             sql.NullInt64
1796
        Policy2DisableFlags            sql.NullInt16
1797
}
1798

1799
func (q *Queries) GetChannelsBySCIDWithPolicies(ctx context.Context, arg GetChannelsBySCIDWithPoliciesParams) ([]GetChannelsBySCIDWithPoliciesRow, error) {
×
1800
        query := getChannelsBySCIDWithPolicies
×
1801
        var queryParams []interface{}
×
1802
        queryParams = append(queryParams, arg.Version)
×
1803
        if len(arg.Scids) > 0 {
×
1804
                for _, v := range arg.Scids {
×
1805
                        queryParams = append(queryParams, v)
×
1806
                }
×
1807
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1808
        } else {
×
1809
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1810
        }
×
1811
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1812
        if err != nil {
×
1813
                return nil, err
×
1814
        }
×
1815
        defer rows.Close()
×
1816
        var items []GetChannelsBySCIDWithPoliciesRow
×
1817
        for rows.Next() {
×
1818
                var i GetChannelsBySCIDWithPoliciesRow
×
1819
                if err := rows.Scan(
×
1820
                        &i.GraphChannel.ID,
×
1821
                        &i.GraphChannel.Version,
×
1822
                        &i.GraphChannel.Scid,
×
1823
                        &i.GraphChannel.NodeID1,
×
1824
                        &i.GraphChannel.NodeID2,
×
1825
                        &i.GraphChannel.Outpoint,
×
1826
                        &i.GraphChannel.Capacity,
×
1827
                        &i.GraphChannel.BitcoinKey1,
×
1828
                        &i.GraphChannel.BitcoinKey2,
×
1829
                        &i.GraphChannel.Node1Signature,
×
1830
                        &i.GraphChannel.Node2Signature,
×
1831
                        &i.GraphChannel.Bitcoin1Signature,
×
1832
                        &i.GraphChannel.Bitcoin2Signature,
×
1833
                        &i.GraphChannel.Signature,
×
1834
                        &i.GraphChannel.FundingPkScript,
×
1835
                        &i.GraphChannel.MerkleRootHash,
×
1836
                        &i.GraphNode.ID,
×
1837
                        &i.GraphNode.Version,
×
1838
                        &i.GraphNode.PubKey,
×
1839
                        &i.GraphNode.Alias,
×
1840
                        &i.GraphNode.LastUpdate,
×
1841
                        &i.GraphNode.Color,
×
1842
                        &i.GraphNode.Signature,
×
1843
                        &i.GraphNode.BlockHeight,
×
1844
                        &i.GraphNode_2.ID,
×
1845
                        &i.GraphNode_2.Version,
×
1846
                        &i.GraphNode_2.PubKey,
×
1847
                        &i.GraphNode_2.Alias,
×
1848
                        &i.GraphNode_2.LastUpdate,
×
1849
                        &i.GraphNode_2.Color,
×
1850
                        &i.GraphNode_2.Signature,
×
1851
                        &i.GraphNode_2.BlockHeight,
×
1852
                        &i.Policy1ID,
×
1853
                        &i.Policy1NodeID,
×
1854
                        &i.Policy1Version,
×
1855
                        &i.Policy1Timelock,
×
1856
                        &i.Policy1FeePpm,
×
1857
                        &i.Policy1BaseFeeMsat,
×
1858
                        &i.Policy1MinHtlcMsat,
×
1859
                        &i.Policy1MaxHtlcMsat,
×
1860
                        &i.Policy1LastUpdate,
×
1861
                        &i.Policy1Disabled,
×
1862
                        &i.Policy1InboundBaseFeeMsat,
×
1863
                        &i.Policy1InboundFeeRateMilliMsat,
×
1864
                        &i.Policy1MessageFlags,
×
1865
                        &i.Policy1ChannelFlags,
×
1866
                        &i.Policy1Signature,
×
1867
                        &i.Policy1BlockHeight,
×
1868
                        &i.Policy1DisableFlags,
×
1869
                        &i.Policy2ID,
×
1870
                        &i.Policy2NodeID,
×
1871
                        &i.Policy2Version,
×
1872
                        &i.Policy2Timelock,
×
1873
                        &i.Policy2FeePpm,
×
1874
                        &i.Policy2BaseFeeMsat,
×
1875
                        &i.Policy2MinHtlcMsat,
×
1876
                        &i.Policy2MaxHtlcMsat,
×
1877
                        &i.Policy2LastUpdate,
×
1878
                        &i.Policy2Disabled,
×
1879
                        &i.Policy2InboundBaseFeeMsat,
×
1880
                        &i.Policy2InboundFeeRateMilliMsat,
×
1881
                        &i.Policy2MessageFlags,
×
1882
                        &i.Policy2ChannelFlags,
×
1883
                        &i.Policy2Signature,
×
1884
                        &i.Policy2BlockHeight,
×
1885
                        &i.Policy2DisableFlags,
×
1886
                ); err != nil {
×
1887
                        return nil, err
×
1888
                }
×
1889
                items = append(items, i)
×
1890
        }
1891
        if err := rows.Close(); err != nil {
×
1892
                return nil, err
×
1893
        }
×
1894
        if err := rows.Err(); err != nil {
×
1895
                return nil, err
×
1896
        }
×
1897
        return items, nil
×
1898
}
1899

1900
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1901
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
1902
WHERE version = $1
1903
  AND scid IN (/*SLICE:scids*/?)
1904
`
1905

1906
type GetChannelsBySCIDsParams struct {
1907
        Version int16
1908
        Scids   [][]byte
1909
}
1910

1911
func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error) {
×
1912
        query := getChannelsBySCIDs
×
1913
        var queryParams []interface{}
×
1914
        queryParams = append(queryParams, arg.Version)
×
1915
        if len(arg.Scids) > 0 {
×
1916
                for _, v := range arg.Scids {
×
1917
                        queryParams = append(queryParams, v)
×
1918
                }
×
1919
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1920
        } else {
×
1921
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1922
        }
×
1923
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1924
        if err != nil {
×
1925
                return nil, err
×
1926
        }
×
1927
        defer rows.Close()
×
1928
        var items []GraphChannel
×
1929
        for rows.Next() {
×
1930
                var i GraphChannel
×
1931
                if err := rows.Scan(
×
1932
                        &i.ID,
×
1933
                        &i.Version,
×
1934
                        &i.Scid,
×
1935
                        &i.NodeID1,
×
1936
                        &i.NodeID2,
×
1937
                        &i.Outpoint,
×
1938
                        &i.Capacity,
×
1939
                        &i.BitcoinKey1,
×
1940
                        &i.BitcoinKey2,
×
1941
                        &i.Node1Signature,
×
1942
                        &i.Node2Signature,
×
1943
                        &i.Bitcoin1Signature,
×
1944
                        &i.Bitcoin2Signature,
×
1945
                        &i.Signature,
×
1946
                        &i.FundingPkScript,
×
1947
                        &i.MerkleRootHash,
×
1948
                ); err != nil {
×
1949
                        return nil, err
×
1950
                }
×
1951
                items = append(items, i)
×
1952
        }
1953
        if err := rows.Close(); err != nil {
×
1954
                return nil, err
×
1955
        }
×
1956
        if err := rows.Err(); err != nil {
×
1957
                return nil, err
×
1958
        }
×
1959
        return items, nil
×
1960
}
1961

1962
const getClosedChannelsSCIDs = `-- name: GetClosedChannelsSCIDs :many
1963
SELECT scid
1964
FROM graph_closed_scids
1965
WHERE scid IN (/*SLICE:scids*/?)
1966
`
1967

1968
func (q *Queries) GetClosedChannelsSCIDs(ctx context.Context, scids [][]byte) ([][]byte, error) {
×
1969
        query := getClosedChannelsSCIDs
×
1970
        var queryParams []interface{}
×
1971
        if len(scids) > 0 {
×
1972
                for _, v := range scids {
×
1973
                        queryParams = append(queryParams, v)
×
1974
                }
×
1975
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(scids)), 1)
×
1976
        } else {
×
1977
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1978
        }
×
1979
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1980
        if err != nil {
×
1981
                return nil, err
×
1982
        }
×
1983
        defer rows.Close()
×
1984
        var items [][]byte
×
1985
        for rows.Next() {
×
1986
                var scid []byte
×
1987
                if err := rows.Scan(&scid); err != nil {
×
1988
                        return nil, err
×
1989
                }
×
1990
                items = append(items, scid)
×
1991
        }
1992
        if err := rows.Close(); err != nil {
×
1993
                return nil, err
×
1994
        }
×
1995
        if err := rows.Err(); err != nil {
×
1996
                return nil, err
×
1997
        }
×
1998
        return items, nil
×
1999
}
2000

2001
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
2002
SELECT node_id, type, value
2003
FROM graph_node_extra_types
2004
WHERE node_id = $1
2005
`
2006

2007
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) {
×
2008
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
2009
        if err != nil {
×
2010
                return nil, err
×
2011
        }
×
2012
        defer rows.Close()
×
2013
        var items []GraphNodeExtraType
×
2014
        for rows.Next() {
×
2015
                var i GraphNodeExtraType
×
2016
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
2017
                        return nil, err
×
2018
                }
×
2019
                items = append(items, i)
×
2020
        }
2021
        if err := rows.Close(); err != nil {
×
2022
                return nil, err
×
2023
        }
×
2024
        if err := rows.Err(); err != nil {
×
2025
                return nil, err
×
2026
        }
×
2027
        return items, nil
×
2028
}
2029

2030
const getNodeAddresses = `-- name: GetNodeAddresses :many
2031
SELECT type, address
2032
FROM graph_node_addresses
2033
WHERE node_id = $1
2034
ORDER BY type ASC, position ASC
2035
`
2036

2037
type GetNodeAddressesRow struct {
2038
        Type    int16
2039
        Address string
2040
}
2041

2042
func (q *Queries) GetNodeAddresses(ctx context.Context, nodeID int64) ([]GetNodeAddressesRow, error) {
×
2043
        rows, err := q.db.QueryContext(ctx, getNodeAddresses, nodeID)
×
2044
        if err != nil {
×
2045
                return nil, err
×
2046
        }
×
2047
        defer rows.Close()
×
2048
        var items []GetNodeAddressesRow
×
2049
        for rows.Next() {
×
2050
                var i GetNodeAddressesRow
×
2051
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
2052
                        return nil, err
×
2053
                }
×
2054
                items = append(items, i)
×
2055
        }
2056
        if err := rows.Close(); err != nil {
×
2057
                return nil, err
×
2058
        }
×
2059
        if err := rows.Err(); err != nil {
×
2060
                return nil, err
×
2061
        }
×
2062
        return items, nil
×
2063
}
2064

2065
const getNodeAddressesBatch = `-- name: GetNodeAddressesBatch :many
2066
SELECT node_id, type, position, address
2067
FROM graph_node_addresses
2068
WHERE node_id IN (/*SLICE:ids*/?)
2069
ORDER BY node_id, type, position
2070
`
2071

2072
func (q *Queries) GetNodeAddressesBatch(ctx context.Context, ids []int64) ([]GraphNodeAddress, error) {
×
2073
        query := getNodeAddressesBatch
×
2074
        var queryParams []interface{}
×
2075
        if len(ids) > 0 {
×
2076
                for _, v := range ids {
×
2077
                        queryParams = append(queryParams, v)
×
2078
                }
×
2079
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
2080
        } else {
×
2081
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
2082
        }
×
2083
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2084
        if err != nil {
×
2085
                return nil, err
×
2086
        }
×
2087
        defer rows.Close()
×
2088
        var items []GraphNodeAddress
×
2089
        for rows.Next() {
×
2090
                var i GraphNodeAddress
×
2091
                if err := rows.Scan(
×
2092
                        &i.NodeID,
×
2093
                        &i.Type,
×
2094
                        &i.Position,
×
2095
                        &i.Address,
×
2096
                ); err != nil {
×
2097
                        return nil, err
×
2098
                }
×
2099
                items = append(items, i)
×
2100
        }
2101
        if err := rows.Close(); err != nil {
×
2102
                return nil, err
×
2103
        }
×
2104
        if err := rows.Err(); err != nil {
×
2105
                return nil, err
×
2106
        }
×
2107
        return items, nil
×
2108
}
2109

2110
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
2111
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2112
FROM graph_nodes
2113
WHERE pub_key = $1
2114
  AND version = $2
2115
`
2116

2117
type GetNodeByPubKeyParams struct {
2118
        PubKey  []byte
2119
        Version int16
2120
}
2121

2122
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
2123
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
2124
        var i GraphNode
×
2125
        err := row.Scan(
×
2126
                &i.ID,
×
2127
                &i.Version,
×
2128
                &i.PubKey,
×
2129
                &i.Alias,
×
2130
                &i.LastUpdate,
×
2131
                &i.Color,
×
2132
                &i.Signature,
×
2133
                &i.BlockHeight,
×
2134
        )
×
2135
        return i, err
×
2136
}
×
2137

2138
const getNodeExtraTypesBatch = `-- name: GetNodeExtraTypesBatch :many
2139
SELECT node_id, type, value
2140
FROM graph_node_extra_types
2141
WHERE node_id IN (/*SLICE:ids*/?)
2142
ORDER BY node_id, type
2143
`
2144

2145
func (q *Queries) GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]GraphNodeExtraType, error) {
×
2146
        query := getNodeExtraTypesBatch
×
2147
        var queryParams []interface{}
×
2148
        if len(ids) > 0 {
×
2149
                for _, v := range ids {
×
2150
                        queryParams = append(queryParams, v)
×
2151
                }
×
2152
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
2153
        } else {
×
2154
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
2155
        }
×
2156
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2157
        if err != nil {
×
2158
                return nil, err
×
2159
        }
×
2160
        defer rows.Close()
×
2161
        var items []GraphNodeExtraType
×
2162
        for rows.Next() {
×
2163
                var i GraphNodeExtraType
×
2164
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
2165
                        return nil, err
×
2166
                }
×
2167
                items = append(items, i)
×
2168
        }
2169
        if err := rows.Close(); err != nil {
×
2170
                return nil, err
×
2171
        }
×
2172
        if err := rows.Err(); err != nil {
×
2173
                return nil, err
×
2174
        }
×
2175
        return items, nil
×
2176
}
2177

2178
const getNodeFeatures = `-- name: GetNodeFeatures :many
2179
SELECT node_id, feature_bit
2180
FROM graph_node_features
2181
WHERE node_id = $1
2182
`
2183

2184
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
2185
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
2186
        if err != nil {
×
2187
                return nil, err
×
2188
        }
×
2189
        defer rows.Close()
×
2190
        var items []GraphNodeFeature
×
2191
        for rows.Next() {
×
2192
                var i GraphNodeFeature
×
2193
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
2194
                        return nil, err
×
2195
                }
×
2196
                items = append(items, i)
×
2197
        }
2198
        if err := rows.Close(); err != nil {
×
2199
                return nil, err
×
2200
        }
×
2201
        if err := rows.Err(); err != nil {
×
2202
                return nil, err
×
2203
        }
×
2204
        return items, nil
×
2205
}
2206

2207
const getNodeFeaturesBatch = `-- name: GetNodeFeaturesBatch :many
2208
SELECT node_id, feature_bit
2209
FROM graph_node_features
2210
WHERE node_id IN (/*SLICE:ids*/?)
2211
ORDER BY node_id, feature_bit
2212
`
2213

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

2247
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
2248
SELECT f.feature_bit
2249
FROM graph_nodes n
2250
    JOIN graph_node_features f ON f.node_id = n.id
2251
WHERE n.pub_key = $1
2252
  AND n.version = $2
2253
`
2254

2255
type GetNodeFeaturesByPubKeyParams struct {
2256
        PubKey  []byte
2257
        Version int16
2258
}
2259

2260
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
2261
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
2262
        if err != nil {
×
2263
                return nil, err
×
2264
        }
×
2265
        defer rows.Close()
×
2266
        var items []int32
×
2267
        for rows.Next() {
×
2268
                var feature_bit int32
×
2269
                if err := rows.Scan(&feature_bit); err != nil {
×
2270
                        return nil, err
×
2271
                }
×
2272
                items = append(items, feature_bit)
×
2273
        }
2274
        if err := rows.Close(); err != nil {
×
2275
                return nil, err
×
2276
        }
×
2277
        if err := rows.Err(); err != nil {
×
2278
                return nil, err
×
2279
        }
×
2280
        return items, nil
×
2281
}
2282

2283
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
2284
SELECT id
2285
FROM graph_nodes
2286
WHERE pub_key = $1
2287
  AND version = $2
2288
`
2289

2290
type GetNodeIDByPubKeyParams struct {
2291
        PubKey  []byte
2292
        Version int16
2293
}
2294

2295
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
2296
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
2297
        var id int64
×
2298
        err := row.Scan(&id)
×
2299
        return id, err
×
2300
}
×
2301

2302
const getNodesByBlockHeightRange = `-- name: GetNodesByBlockHeightRange :many
2303
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2304
FROM graph_nodes
2305
WHERE graph_nodes.version = $1
2306
  AND block_height >= $2
2307
  AND block_height < $3
2308
  -- Pagination: We use (block_height, pub_key) as a compound cursor.
2309
  -- This ensures stable ordering and allows us to resume from where we left off.
2310
  -- We use COALESCE with -1 as sentinel since block heights are always positive.
2311
  AND (
2312
    block_height > COALESCE($4, -1)
2313
    OR
2314
    (block_height = COALESCE($4, -1)
2315
     AND pub_key > $5)
2316
  )
2317
  -- Optional filter for public nodes only.
2318
  AND (
2319
    COALESCE($6, FALSE) IS FALSE
2320
    OR
2321
    -- For V2 protocol, a node is public if it has at least one announced
2322
    -- v2 channel (indicated by a non-empty channel announcement signature).
2323
    EXISTS (
2324
      SELECT 1
2325
      FROM graph_channels c
2326
      WHERE c.version = graph_nodes.version
2327
        AND COALESCE(length(c.signature), 0) > 0
2328
        AND (c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id)
2329
    )
2330
  )
2331
ORDER BY block_height ASC, pub_key ASC
2332
LIMIT COALESCE($7, 999999999)
2333
`
2334

2335
type GetNodesByBlockHeightRangeParams struct {
2336
        Version         int16
2337
        StartHeight     sql.NullInt64
2338
        EndHeight       sql.NullInt64
2339
        LastBlockHeight sql.NullInt64
2340
        LastPubKey      []byte
2341
        OnlyPublic      interface{}
2342
        MaxResults      interface{}
2343
}
2344

2345
func (q *Queries) GetNodesByBlockHeightRange(ctx context.Context, arg GetNodesByBlockHeightRangeParams) ([]GraphNode, error) {
×
2346
        rows, err := q.db.QueryContext(ctx, getNodesByBlockHeightRange,
×
2347
                arg.Version,
×
2348
                arg.StartHeight,
×
2349
                arg.EndHeight,
×
2350
                arg.LastBlockHeight,
×
2351
                arg.LastPubKey,
×
2352
                arg.OnlyPublic,
×
2353
                arg.MaxResults,
×
2354
        )
×
2355
        if err != nil {
×
2356
                return nil, err
×
2357
        }
×
2358
        defer rows.Close()
×
2359
        var items []GraphNode
×
2360
        for rows.Next() {
×
2361
                var i GraphNode
×
2362
                if err := rows.Scan(
×
2363
                        &i.ID,
×
2364
                        &i.Version,
×
2365
                        &i.PubKey,
×
2366
                        &i.Alias,
×
2367
                        &i.LastUpdate,
×
2368
                        &i.Color,
×
2369
                        &i.Signature,
×
2370
                        &i.BlockHeight,
×
2371
                ); err != nil {
×
2372
                        return nil, err
×
2373
                }
×
2374
                items = append(items, i)
×
2375
        }
2376
        if err := rows.Close(); err != nil {
×
2377
                return nil, err
×
2378
        }
×
2379
        if err := rows.Err(); err != nil {
×
2380
                return nil, err
×
2381
        }
×
2382
        return items, nil
×
2383
}
2384

2385
const getNodesByIDs = `-- name: GetNodesByIDs :many
2386
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2387
FROM graph_nodes
2388
WHERE id IN (/*SLICE:ids*/?)
2389
`
2390

2391
func (q *Queries) GetNodesByIDs(ctx context.Context, ids []int64) ([]GraphNode, error) {
×
2392
        query := getNodesByIDs
×
2393
        var queryParams []interface{}
×
2394
        if len(ids) > 0 {
×
2395
                for _, v := range ids {
×
2396
                        queryParams = append(queryParams, v)
×
2397
                }
×
2398
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
2399
        } else {
×
2400
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
2401
        }
×
2402
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2403
        if err != nil {
×
2404
                return nil, err
×
2405
        }
×
2406
        defer rows.Close()
×
2407
        var items []GraphNode
×
2408
        for rows.Next() {
×
2409
                var i GraphNode
×
2410
                if err := rows.Scan(
×
2411
                        &i.ID,
×
2412
                        &i.Version,
×
2413
                        &i.PubKey,
×
2414
                        &i.Alias,
×
2415
                        &i.LastUpdate,
×
2416
                        &i.Color,
×
2417
                        &i.Signature,
×
2418
                        &i.BlockHeight,
×
2419
                ); 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 getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
2434
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2435
FROM graph_nodes
2436
WHERE version = 1
2437
  AND last_update >= $1
2438
  AND last_update < $2
2439
  -- Pagination: We use (last_update, pub_key) as a compound cursor.
2440
  -- This ensures stable ordering and allows us to resume from where we left off.
2441
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
2442
  AND (
2443
    last_update > COALESCE($3, -1)
2444
    OR
2445
    (last_update = COALESCE($3, -1)
2446
     AND pub_key > $4)
2447
  )
2448
ORDER BY last_update ASC, pub_key ASC
2449
LIMIT COALESCE($5, 999999999)
2450
`
2451

2452
type GetNodesByLastUpdateRangeParams struct {
2453
        StartTime  sql.NullInt64
2454
        EndTime    sql.NullInt64
2455
        LastUpdate sql.NullInt64
2456
        LastPubKey []byte
2457
        MaxResults interface{}
2458
}
2459

2460
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
2461
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange,
×
2462
                arg.StartTime,
×
2463
                arg.EndTime,
×
2464
                arg.LastUpdate,
×
2465
                arg.LastPubKey,
×
2466
                arg.MaxResults,
×
2467
        )
×
2468
        if err != nil {
×
2469
                return nil, err
×
2470
        }
×
2471
        defer rows.Close()
×
2472
        var items []GraphNode
×
2473
        for rows.Next() {
×
2474
                var i GraphNode
×
2475
                if err := rows.Scan(
×
2476
                        &i.ID,
×
2477
                        &i.Version,
×
2478
                        &i.PubKey,
×
2479
                        &i.Alias,
×
2480
                        &i.LastUpdate,
×
2481
                        &i.Color,
×
2482
                        &i.Signature,
×
2483
                        &i.BlockHeight,
×
2484
                ); err != nil {
×
2485
                        return nil, err
×
2486
                }
×
2487
                items = append(items, i)
×
2488
        }
2489
        if err := rows.Close(); err != nil {
×
2490
                return nil, err
×
2491
        }
×
2492
        if err := rows.Err(); err != nil {
×
2493
                return nil, err
×
2494
        }
×
2495
        return items, nil
×
2496
}
2497

2498
const getPruneEntriesForHeights = `-- name: GetPruneEntriesForHeights :many
2499
SELECT block_height, block_hash
2500
FROM graph_prune_log
2501
WHERE block_height
2502
   IN (/*SLICE:heights*/?)
2503
`
2504

2505
func (q *Queries) GetPruneEntriesForHeights(ctx context.Context, heights []int64) ([]GraphPruneLog, error) {
×
2506
        query := getPruneEntriesForHeights
×
2507
        var queryParams []interface{}
×
2508
        if len(heights) > 0 {
×
2509
                for _, v := range heights {
×
2510
                        queryParams = append(queryParams, v)
×
2511
                }
×
2512
                query = strings.Replace(query, "/*SLICE:heights*/?", makeQueryParams(len(queryParams), len(heights)), 1)
×
2513
        } else {
×
2514
                query = strings.Replace(query, "/*SLICE:heights*/?", "NULL", 1)
×
2515
        }
×
2516
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2517
        if err != nil {
×
2518
                return nil, err
×
2519
        }
×
2520
        defer rows.Close()
×
2521
        var items []GraphPruneLog
×
2522
        for rows.Next() {
×
2523
                var i GraphPruneLog
×
2524
                if err := rows.Scan(&i.BlockHeight, &i.BlockHash); err != nil {
×
2525
                        return nil, err
×
2526
                }
×
2527
                items = append(items, i)
×
2528
        }
2529
        if err := rows.Close(); err != nil {
×
2530
                return nil, err
×
2531
        }
×
2532
        if err := rows.Err(); err != nil {
×
2533
                return nil, err
×
2534
        }
×
2535
        return items, nil
×
2536
}
2537

2538
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
2539
SELECT block_hash
2540
FROM graph_prune_log
2541
WHERE block_height = $1
2542
`
2543

2544
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
2545
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
2546
        var block_hash []byte
×
2547
        err := row.Scan(&block_hash)
×
2548
        return block_hash, err
×
2549
}
×
2550

2551
const getPruneTip = `-- name: GetPruneTip :one
2552
SELECT block_height, block_hash
2553
FROM graph_prune_log
2554
ORDER BY block_height DESC
2555
LIMIT 1
2556
`
2557

2558
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
2559
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
2560
        var i GraphPruneLog
×
2561
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
2562
        return i, err
×
2563
}
×
2564

2565
const getPublicNodesByLastUpdateRange = `-- name: GetPublicNodesByLastUpdateRange :many
2566
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
2567
FROM graph_nodes
2568
WHERE version = 1
2569
  AND last_update >= $1
2570
  AND last_update <= $2
2571
  -- Pagination: We use (last_update, pub_key) as a compound cursor.
2572
  -- This ensures stable ordering and allows us to resume from where we left off.
2573
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
2574
  AND (
2575
    last_update > COALESCE($3, -1)
2576
    OR
2577
    (last_update = COALESCE($3, -1)
2578
     AND pub_key > $4)
2579
  )
2580
  AND (
2581
    EXISTS (
2582
        SELECT 1
2583
        FROM graph_channels c
2584
        WHERE c.version = 1
2585
          AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
2586
          AND c.node_id_1 = graph_nodes.id
2587
    )
2588
    OR EXISTS (
2589
        SELECT 1
2590
        FROM graph_channels c
2591
        WHERE c.version = 1
2592
          AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
2593
          AND c.node_id_2 = graph_nodes.id
2594
    )
2595
  )
2596
ORDER BY last_update ASC, pub_key ASC
2597
LIMIT COALESCE($5, 999999999)
2598
`
2599

2600
type GetPublicNodesByLastUpdateRangeParams struct {
2601
        StartTime  sql.NullInt64
2602
        EndTime    sql.NullInt64
2603
        LastUpdate sql.NullInt64
2604
        LastPubKey []byte
2605
        MaxResults interface{}
2606
}
2607

2608
// Returns only public V1 nodes within the given last_update range. A V1 node
2609
// is public if it has at least one channel with a bitcoin_1_signature set. The
2610
// public check uses two separate EXISTS probes (one per node_id column)
2611
// instead of a single OR on node_id_1/node_id_2 so the planner can use the
2612
// channel node-id indexes directly.
2613
func (q *Queries) GetPublicNodesByLastUpdateRange(ctx context.Context, arg GetPublicNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
2614
        rows, err := q.db.QueryContext(ctx, getPublicNodesByLastUpdateRange,
×
2615
                arg.StartTime,
×
2616
                arg.EndTime,
×
2617
                arg.LastUpdate,
×
2618
                arg.LastPubKey,
×
2619
                arg.MaxResults,
×
2620
        )
×
2621
        if err != nil {
×
2622
                return nil, err
×
2623
        }
×
2624
        defer rows.Close()
×
2625
        var items []GraphNode
×
2626
        for rows.Next() {
×
2627
                var i GraphNode
×
2628
                if err := rows.Scan(
×
2629
                        &i.ID,
×
2630
                        &i.Version,
×
2631
                        &i.PubKey,
×
2632
                        &i.Alias,
×
2633
                        &i.LastUpdate,
×
2634
                        &i.Color,
×
2635
                        &i.Signature,
×
2636
                        &i.BlockHeight,
×
2637
                ); err != nil {
×
2638
                        return nil, err
×
2639
                }
×
2640
                items = append(items, i)
×
2641
        }
2642
        if err := rows.Close(); err != nil {
×
2643
                return nil, err
×
2644
        }
×
2645
        if err := rows.Err(); err != nil {
×
2646
                return nil, err
×
2647
        }
×
2648
        return items, nil
×
2649
}
2650

2651
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
2652
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
2653
FROM graph_channels
2654
WHERE version = 1
2655
  AND COALESCE(length(node_1_signature), 0) > 0
2656
  AND scid >= $1
2657
  AND scid < $2
2658
ORDER BY scid ASC
2659
`
2660

2661
type GetPublicV1ChannelsBySCIDParams struct {
2662
        StartScid []byte
2663
        EndScid   []byte
2664
}
2665

2666
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
2667
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
2668
        if err != nil {
×
2669
                return nil, err
×
2670
        }
×
2671
        defer rows.Close()
×
2672
        var items []GraphChannel
×
2673
        for rows.Next() {
×
2674
                var i GraphChannel
×
2675
                if err := rows.Scan(
×
2676
                        &i.ID,
×
2677
                        &i.Version,
×
2678
                        &i.Scid,
×
2679
                        &i.NodeID1,
×
2680
                        &i.NodeID2,
×
2681
                        &i.Outpoint,
×
2682
                        &i.Capacity,
×
2683
                        &i.BitcoinKey1,
×
2684
                        &i.BitcoinKey2,
×
2685
                        &i.Node1Signature,
×
2686
                        &i.Node2Signature,
×
2687
                        &i.Bitcoin1Signature,
×
2688
                        &i.Bitcoin2Signature,
×
2689
                        &i.Signature,
×
2690
                        &i.FundingPkScript,
×
2691
                        &i.MerkleRootHash,
×
2692
                ); err != nil {
×
2693
                        return nil, err
×
2694
                }
×
2695
                items = append(items, i)
×
2696
        }
2697
        if err := rows.Close(); err != nil {
×
2698
                return nil, err
×
2699
        }
×
2700
        if err := rows.Err(); err != nil {
×
2701
                return nil, err
×
2702
        }
×
2703
        return items, nil
×
2704
}
2705

2706
const getPublicV2ChannelsBySCID = `-- name: GetPublicV2ChannelsBySCID :many
2707
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
2708
FROM graph_channels
2709
WHERE version = 2
2710
  AND COALESCE(length(signature), 0) > 0
2711
  AND scid >= $1
2712
  AND scid < $2
2713
ORDER BY scid ASC
2714
`
2715

2716
type GetPublicV2ChannelsBySCIDParams struct {
2717
        StartScid []byte
2718
        EndScid   []byte
2719
}
2720

2721
func (q *Queries) GetPublicV2ChannelsBySCID(ctx context.Context, arg GetPublicV2ChannelsBySCIDParams) ([]GraphChannel, error) {
×
2722
        rows, err := q.db.QueryContext(ctx, getPublicV2ChannelsBySCID, arg.StartScid, arg.EndScid)
×
2723
        if err != nil {
×
2724
                return nil, err
×
2725
        }
×
2726
        defer rows.Close()
×
2727
        var items []GraphChannel
×
2728
        for rows.Next() {
×
2729
                var i GraphChannel
×
2730
                if err := rows.Scan(
×
2731
                        &i.ID,
×
2732
                        &i.Version,
×
2733
                        &i.Scid,
×
2734
                        &i.NodeID1,
×
2735
                        &i.NodeID2,
×
2736
                        &i.Outpoint,
×
2737
                        &i.Capacity,
×
2738
                        &i.BitcoinKey1,
×
2739
                        &i.BitcoinKey2,
×
2740
                        &i.Node1Signature,
×
2741
                        &i.Node2Signature,
×
2742
                        &i.Bitcoin1Signature,
×
2743
                        &i.Bitcoin2Signature,
×
2744
                        &i.Signature,
×
2745
                        &i.FundingPkScript,
×
2746
                        &i.MerkleRootHash,
×
2747
                ); err != nil {
×
2748
                        return nil, err
×
2749
                }
×
2750
                items = append(items, i)
×
2751
        }
2752
        if err := rows.Close(); err != nil {
×
2753
                return nil, err
×
2754
        }
×
2755
        if err := rows.Err(); err != nil {
×
2756
                return nil, err
×
2757
        }
×
2758
        return items, nil
×
2759
}
2760

2761
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
2762
SELECT scid from graph_channels
2763
WHERE outpoint = $1 AND version = $2
2764
`
2765

2766
type GetSCIDByOutpointParams struct {
2767
        Outpoint string
2768
        Version  int16
2769
}
2770

2771
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
2772
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
2773
        var scid []byte
×
2774
        err := row.Scan(&scid)
×
2775
        return scid, err
×
2776
}
×
2777

2778
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
2779
SELECT sn.node_id, n.pub_key
2780
FROM graph_source_nodes sn
2781
    JOIN graph_nodes n ON sn.node_id = n.id
2782
WHERE n.version = $1
2783
`
2784

2785
type GetSourceNodesByVersionRow struct {
2786
        NodeID int64
2787
        PubKey []byte
2788
}
2789

2790
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
2791
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
2792
        if err != nil {
×
2793
                return nil, err
×
2794
        }
×
2795
        defer rows.Close()
×
2796
        var items []GetSourceNodesByVersionRow
×
2797
        for rows.Next() {
×
2798
                var i GetSourceNodesByVersionRow
×
2799
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
2800
                        return nil, err
×
2801
                }
×
2802
                items = append(items, i)
×
2803
        }
2804
        if err := rows.Close(); err != nil {
×
2805
                return nil, err
×
2806
        }
×
2807
        if err := rows.Err(); err != nil {
×
2808
                return nil, err
×
2809
        }
×
2810
        return items, nil
×
2811
}
2812

2813
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
2814
SELECT c.scid
2815
FROM graph_channels c
2816
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2817
WHERE cp.disabled = true
2818
AND c.version = 1
2819
GROUP BY c.scid
2820
HAVING COUNT(*) > 1
2821
`
2822

2823
// NOTE: this is V1 specific since for V1, disabled is a
2824
// simple, single boolean. The proposed V2 policy
2825
// structure will have a more complex disabled bit vector
2826
// and so the query for V2 may differ.
2827
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2828
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
2829
        if err != nil {
×
2830
                return nil, err
×
2831
        }
×
2832
        defer rows.Close()
×
2833
        var items [][]byte
×
2834
        for rows.Next() {
×
2835
                var scid []byte
×
2836
                if err := rows.Scan(&scid); err != nil {
×
2837
                        return nil, err
×
2838
                }
×
2839
                items = append(items, scid)
×
2840
        }
2841
        if err := rows.Close(); err != nil {
×
2842
                return nil, err
×
2843
        }
×
2844
        if err := rows.Err(); err != nil {
×
2845
                return nil, err
×
2846
        }
×
2847
        return items, nil
×
2848
}
2849

2850
const getV2DisabledSCIDs = `-- name: GetV2DisabledSCIDs :many
2851
SELECT c.scid
2852
FROM graph_channels c
2853
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2854
WHERE COALESCE(cp.disable_flags, 0) != 0
2855
AND c.version = 2
2856
GROUP BY c.scid
2857
HAVING COUNT(*) > 1
2858
`
2859

2860
// NOTE: this is V2 specific since V2 uses a disable flag
2861
// bit vector instead of a single boolean.
2862
func (q *Queries) GetV2DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2863
        rows, err := q.db.QueryContext(ctx, getV2DisabledSCIDs)
×
2864
        if err != nil {
×
2865
                return nil, err
×
2866
        }
×
2867
        defer rows.Close()
×
2868
        var items [][]byte
×
2869
        for rows.Next() {
×
2870
                var scid []byte
×
2871
                if err := rows.Scan(&scid); err != nil {
×
2872
                        return nil, err
×
2873
                }
×
2874
                items = append(items, scid)
×
2875
        }
2876
        if err := rows.Close(); err != nil {
×
2877
                return nil, err
×
2878
        }
×
2879
        if err := rows.Err(); err != nil {
×
2880
                return nil, err
×
2881
        }
×
2882
        return items, nil
×
2883
}
2884

2885
const getZombieChannel = `-- name: GetZombieChannel :one
2886
SELECT scid, version, node_key_1, node_key_2
2887
FROM graph_zombie_channels
2888
WHERE scid = $1
2889
AND version = $2
2890
`
2891

2892
type GetZombieChannelParams struct {
2893
        Scid    []byte
2894
        Version int16
2895
}
2896

2897
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
2898
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
2899
        var i GraphZombieChannel
×
2900
        err := row.Scan(
×
2901
                &i.Scid,
×
2902
                &i.Version,
×
2903
                &i.NodeKey1,
×
2904
                &i.NodeKey2,
×
2905
        )
×
2906
        return i, err
×
2907
}
×
2908

2909
const getZombieChannelsSCIDs = `-- name: GetZombieChannelsSCIDs :many
2910
SELECT scid, version, node_key_1, node_key_2
2911
FROM graph_zombie_channels
2912
WHERE version = $1
2913
  AND scid IN (/*SLICE:scids*/?)
2914
`
2915

2916
type GetZombieChannelsSCIDsParams struct {
2917
        Version int16
2918
        Scids   [][]byte
2919
}
2920

2921
func (q *Queries) GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error) {
×
2922
        query := getZombieChannelsSCIDs
×
2923
        var queryParams []interface{}
×
2924
        queryParams = append(queryParams, arg.Version)
×
2925
        if len(arg.Scids) > 0 {
×
2926
                for _, v := range arg.Scids {
×
2927
                        queryParams = append(queryParams, v)
×
2928
                }
×
2929
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
2930
        } else {
×
2931
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
2932
        }
×
2933
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2934
        if err != nil {
×
2935
                return nil, err
×
2936
        }
×
2937
        defer rows.Close()
×
2938
        var items []GraphZombieChannel
×
2939
        for rows.Next() {
×
2940
                var i GraphZombieChannel
×
2941
                if err := rows.Scan(
×
2942
                        &i.Scid,
×
2943
                        &i.Version,
×
2944
                        &i.NodeKey1,
×
2945
                        &i.NodeKey2,
×
2946
                ); err != nil {
×
2947
                        return nil, err
×
2948
                }
×
2949
                items = append(items, i)
×
2950
        }
2951
        if err := rows.Close(); err != nil {
×
2952
                return nil, err
×
2953
        }
×
2954
        if err := rows.Err(); err != nil {
×
2955
                return nil, err
×
2956
        }
×
2957
        return items, nil
×
2958
}
2959

2960
const highestSCID = `-- name: HighestSCID :one
2961
SELECT scid
2962
FROM graph_channels
2963
WHERE version = $1
2964
ORDER BY scid DESC
2965
LIMIT 1
2966
`
2967

2968
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
2969
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
2970
        var scid []byte
×
2971
        err := row.Scan(&scid)
×
2972
        return scid, err
×
2973
}
×
2974

2975
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2976
/* ─────────────────────────────────────────────
2977
   graph_channel_features table queries
2978
   ─────────────────────────────────────────────
2979
*/
2980

2981
INSERT INTO graph_channel_features (
2982
    channel_id, feature_bit
2983
) VALUES (
2984
    $1, $2
2985
) ON CONFLICT (channel_id, feature_bit)
2986
    -- Do nothing if the channel_id and feature_bit already exist.
2987
    DO NOTHING
2988
`
2989

2990
type InsertChannelFeatureParams struct {
2991
        ChannelID  int64
2992
        FeatureBit int32
2993
}
2994

2995
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2996
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2997
        return err
×
2998
}
×
2999

3000
const insertChannelMig = `-- name: InsertChannelMig :one
3001
INSERT INTO graph_channels (
3002
    version, scid, node_id_1, node_id_2,
3003
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
3004
    node_1_signature, node_2_signature, bitcoin_1_signature,
3005
    bitcoin_2_signature
3006
) VALUES (
3007
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
3008
) ON CONFLICT (scid, version)
3009
    -- If a conflict occurs, we have already migrated this channel. However, we
3010
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
3011
    -- otherwise, the "RETURNING id" part does not work.
3012
    DO UPDATE SET
3013
        node_id_1 = EXCLUDED.node_id_1,
3014
        node_id_2 = EXCLUDED.node_id_2,
3015
        outpoint = EXCLUDED.outpoint,
3016
        capacity = EXCLUDED.capacity,
3017
        bitcoin_key_1 = EXCLUDED.bitcoin_key_1,
3018
        bitcoin_key_2 = EXCLUDED.bitcoin_key_2,
3019
        node_1_signature = EXCLUDED.node_1_signature,
3020
        node_2_signature = EXCLUDED.node_2_signature,
3021
        bitcoin_1_signature = EXCLUDED.bitcoin_1_signature,
3022
        bitcoin_2_signature = EXCLUDED.bitcoin_2_signature
3023
RETURNING id
3024
`
3025

3026
type InsertChannelMigParams struct {
3027
        Version           int16
3028
        Scid              []byte
3029
        NodeID1           int64
3030
        NodeID2           int64
3031
        Outpoint          string
3032
        Capacity          sql.NullInt64
3033
        BitcoinKey1       []byte
3034
        BitcoinKey2       []byte
3035
        Node1Signature    []byte
3036
        Node2Signature    []byte
3037
        Bitcoin1Signature []byte
3038
        Bitcoin2Signature []byte
3039
}
3040

3041
// NOTE: This query is only meant to be used by the graph SQL migration since
3042
// for that migration, in order to be retry-safe, we don't want to error out if
3043
// we re-insert the same channel again (which would error if the normal
3044
// CreateChannel query is used because of the uniqueness constraint on the scid
3045
// and version columns).
3046
func (q *Queries) InsertChannelMig(ctx context.Context, arg InsertChannelMigParams) (int64, error) {
×
3047
        row := q.db.QueryRowContext(ctx, insertChannelMig,
×
3048
                arg.Version,
×
3049
                arg.Scid,
×
3050
                arg.NodeID1,
×
3051
                arg.NodeID2,
×
3052
                arg.Outpoint,
×
3053
                arg.Capacity,
×
3054
                arg.BitcoinKey1,
×
3055
                arg.BitcoinKey2,
×
3056
                arg.Node1Signature,
×
3057
                arg.Node2Signature,
×
3058
                arg.Bitcoin1Signature,
×
3059
                arg.Bitcoin2Signature,
×
3060
        )
×
3061
        var id int64
×
3062
        err := row.Scan(&id)
×
3063
        return id, err
×
3064
}
×
3065

3066
const insertClosedChannel = `-- name: InsertClosedChannel :exec
3067
/* ─────────────────────────────────────────────
3068
   graph_closed_scid table queries
3069
   ────────────────────────────────────────────-
3070
*/
3071

3072
INSERT INTO graph_closed_scids (scid)
3073
VALUES ($1)
3074
ON CONFLICT (scid) DO NOTHING
3075
`
3076

3077
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
3078
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
3079
        return err
×
3080
}
×
3081

3082
const insertEdgePolicyMig = `-- name: InsertEdgePolicyMig :one
3083
INSERT INTO graph_channel_policies (
3084
    version, channel_id, node_id, timelock, fee_ppm,
3085
    base_fee_msat, min_htlc_msat, last_update, disabled,
3086
    max_htlc_msat, inbound_base_fee_msat,
3087
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
3088
    signature
3089
) VALUES  (
3090
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
3091
)
3092
ON CONFLICT (channel_id, node_id, version)
3093
    -- If a conflict occurs, we have already migrated this policy. However, we
3094
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
3095
    -- otherwise, the "RETURNING id" part does not work.
3096
    DO UPDATE SET
3097
        timelock = EXCLUDED.timelock,
3098
        fee_ppm = EXCLUDED.fee_ppm,
3099
        base_fee_msat = EXCLUDED.base_fee_msat,
3100
        min_htlc_msat = EXCLUDED.min_htlc_msat,
3101
        last_update = EXCLUDED.last_update,
3102
        disabled = EXCLUDED.disabled,
3103
        max_htlc_msat = EXCLUDED.max_htlc_msat,
3104
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
3105
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
3106
        message_flags = EXCLUDED.message_flags,
3107
        channel_flags = EXCLUDED.channel_flags,
3108
        signature = EXCLUDED.signature
3109
RETURNING id
3110
`
3111

3112
type InsertEdgePolicyMigParams struct {
3113
        Version                 int16
3114
        ChannelID               int64
3115
        NodeID                  int64
3116
        Timelock                int32
3117
        FeePpm                  int64
3118
        BaseFeeMsat             int64
3119
        MinHtlcMsat             int64
3120
        LastUpdate              sql.NullInt64
3121
        Disabled                sql.NullBool
3122
        MaxHtlcMsat             sql.NullInt64
3123
        InboundBaseFeeMsat      sql.NullInt64
3124
        InboundFeeRateMilliMsat sql.NullInt64
3125
        MessageFlags            sql.NullInt16
3126
        ChannelFlags            sql.NullInt16
3127
        Signature               []byte
3128
}
3129

3130
// NOTE: This query is only meant to be used by the graph SQL migration since
3131
// for that migration, in order to be retry-safe, we don't want to error out if
3132
// we re-insert the same policy (which would error if the normal
3133
// UpsertEdgePolicy query is used because of the constraint in that query that
3134
// requires a policy update to have a newer last_update than the existing one).
3135
func (q *Queries) InsertEdgePolicyMig(ctx context.Context, arg InsertEdgePolicyMigParams) (int64, error) {
×
3136
        row := q.db.QueryRowContext(ctx, insertEdgePolicyMig,
×
3137
                arg.Version,
×
3138
                arg.ChannelID,
×
3139
                arg.NodeID,
×
3140
                arg.Timelock,
×
3141
                arg.FeePpm,
×
3142
                arg.BaseFeeMsat,
×
3143
                arg.MinHtlcMsat,
×
3144
                arg.LastUpdate,
×
3145
                arg.Disabled,
×
3146
                arg.MaxHtlcMsat,
×
3147
                arg.InboundBaseFeeMsat,
×
3148
                arg.InboundFeeRateMilliMsat,
×
3149
                arg.MessageFlags,
×
3150
                arg.ChannelFlags,
×
3151
                arg.Signature,
×
3152
        )
×
3153
        var id int64
×
3154
        err := row.Scan(&id)
×
3155
        return id, err
×
3156
}
×
3157

3158
const insertNodeFeature = `-- name: InsertNodeFeature :exec
3159
/* ─────────────────────────────────────────────
3160
   graph_node_features table queries
3161
   ─────────────────────────────────────────────
3162
*/
3163

3164
INSERT INTO graph_node_features (
3165
    node_id, feature_bit
3166
) VALUES (
3167
    $1, $2
3168
) ON CONFLICT (node_id, feature_bit)
3169
    -- Do nothing if the feature already exists for the node.
3170
    DO NOTHING
3171
`
3172

3173
type InsertNodeFeatureParams struct {
3174
        NodeID     int64
3175
        FeatureBit int32
3176
}
3177

3178
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
3179
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
3180
        return err
×
3181
}
×
3182

3183
const insertNodeMig = `-- name: InsertNodeMig :one
3184
/* ─────────────────────────────────────────────
3185
   Migration specific queries
3186

3187
   NOTE: once sqldbv2 is in place, these queries can be contained to a package
3188
   dedicated to the migration that requires it, and so we can then remove
3189
   it from the main set of "live" queries that the code-base has access to.
3190
   ────────────────────────────────────────────-
3191
*/
3192

3193
INSERT INTO graph_nodes (
3194
    version, pub_key, alias, last_update, color, signature
3195
) VALUES (
3196
    $1, $2, $3, $4, $5, $6
3197
)
3198
ON CONFLICT (pub_key, version)
3199
    -- If a conflict occurs, we have already migrated this node. However, we
3200
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
3201
    -- otherwise, the "RETURNING id" part does not work.
3202
    DO UPDATE SET
3203
        alias = EXCLUDED.alias,
3204
        last_update = EXCLUDED.last_update,
3205
        color = EXCLUDED.color,
3206
        signature = EXCLUDED.signature
3207
RETURNING id
3208
`
3209

3210
type InsertNodeMigParams struct {
3211
        Version    int16
3212
        PubKey     []byte
3213
        Alias      sql.NullString
3214
        LastUpdate sql.NullInt64
3215
        Color      sql.NullString
3216
        Signature  []byte
3217
}
3218

3219
// NOTE: This query is only meant to be used by the graph SQL migration since
3220
// for that migration, in order to be retry-safe, we don't want to error out if
3221
// we re-insert the same node (which would error if the normal UpsertNode query
3222
// is used because of the constraint in that query that requires a node update
3223
// to have a newer last_update than the existing node).
3224
func (q *Queries) InsertNodeMig(ctx context.Context, arg InsertNodeMigParams) (int64, error) {
×
3225
        row := q.db.QueryRowContext(ctx, insertNodeMig,
×
3226
                arg.Version,
×
3227
                arg.PubKey,
×
3228
                arg.Alias,
×
3229
                arg.LastUpdate,
×
3230
                arg.Color,
×
3231
                arg.Signature,
×
3232
        )
×
3233
        var id int64
×
3234
        err := row.Scan(&id)
×
3235
        return id, err
×
3236
}
×
3237

3238
const isClosedChannel = `-- name: IsClosedChannel :one
3239
SELECT EXISTS (
3240
    SELECT 1
3241
    FROM graph_closed_scids
3242
    WHERE scid = $1
3243
)
3244
`
3245

3246
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
3247
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
3248
        var exists bool
×
3249
        err := row.Scan(&exists)
×
3250
        return exists, err
×
3251
}
×
3252

3253
const isPublicV1Node = `-- name: IsPublicV1Node :one
3254
SELECT EXISTS (
3255
    SELECT 1
3256
    FROM graph_channels c
3257
    JOIN graph_nodes n ON n.id = c.node_id_1
3258
    -- NOTE: we hard-code the version here since the clauses
3259
    -- here that determine if a node is public is specific
3260
    -- to the V1 gossip protocol. In V1, a node is public
3261
    -- if it has a public channel and a public channel is one
3262
    -- where we have the set of signatures of the channel
3263
    -- announcement. It is enough to just check that we have
3264
    -- one of the signatures since we only ever set them
3265
    -- together.
3266
    WHERE c.version = 1
3267
      AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
3268
      AND n.pub_key = $1
3269
    UNION ALL
3270
    SELECT 1
3271
    FROM graph_channels c
3272
    JOIN graph_nodes n ON n.id = c.node_id_2
3273
    WHERE c.version = 1
3274
      AND COALESCE(length(c.bitcoin_1_signature), 0) > 0
3275
      AND n.pub_key = $1
3276
)
3277
`
3278

3279
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
3280
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
3281
        var exists bool
×
3282
        err := row.Scan(&exists)
×
3283
        return exists, err
×
3284
}
×
3285

3286
const isPublicV2Node = `-- name: IsPublicV2Node :one
3287
SELECT EXISTS (
3288
    SELECT 1
3289
    FROM graph_channels c
3290
    JOIN graph_nodes n ON n.id = c.node_id_1
3291
    -- NOTE: we hard-code the version here since the clauses
3292
    -- here that determine if a node is public is specific
3293
    -- to the V2 gossip protocol.
3294
    WHERE c.version = 2
3295
      AND COALESCE(length(c.signature), 0) > 0
3296
      AND n.pub_key = $1
3297

3298
    UNION ALL
3299

3300
    SELECT 1
3301
    FROM graph_channels c
3302
    JOIN graph_nodes n ON n.id = c.node_id_2
3303
    WHERE c.version = 2
3304
      AND COALESCE(length(c.signature), 0) > 0
3305
      AND n.pub_key = $1
3306
)
3307
`
3308

3309
func (q *Queries) IsPublicV2Node(ctx context.Context, pubKey []byte) (bool, error) {
×
3310
        row := q.db.QueryRowContext(ctx, isPublicV2Node, pubKey)
×
3311
        var exists bool
×
3312
        err := row.Scan(&exists)
×
3313
        return exists, err
×
3314
}
×
3315

3316
const isZombieChannel = `-- name: IsZombieChannel :one
3317
SELECT EXISTS (
3318
    SELECT 1
3319
    FROM graph_zombie_channels
3320
    WHERE scid = $1
3321
    AND version = $2
3322
) AS is_zombie
3323
`
3324

3325
type IsZombieChannelParams struct {
3326
        Scid    []byte
3327
        Version int16
3328
}
3329

3330
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
3331
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
3332
        var is_zombie bool
×
3333
        err := row.Scan(&is_zombie)
×
3334
        return is_zombie, err
×
3335
}
×
3336

3337
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
3338
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,
3339
    n1.pub_key AS node1_pubkey,
3340
    n2.pub_key AS node2_pubkey,
3341

3342
    -- Policy 1
3343
    -- TODO(elle): use sqlc.embed to embed policy structs
3344
    --  once this issue is resolved:
3345
    --  https://github.com/sqlc-dev/sqlc/issues/2997
3346
    cp1.id AS policy1_id,
3347
    cp1.node_id AS policy1_node_id,
3348
    cp1.version AS policy1_version,
3349
    cp1.timelock AS policy1_timelock,
3350
    cp1.fee_ppm AS policy1_fee_ppm,
3351
    cp1.base_fee_msat AS policy1_base_fee_msat,
3352
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
3353
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
3354
    cp1.last_update AS policy1_last_update,
3355
    cp1.disabled AS policy1_disabled,
3356
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3357
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3358
    cp1.message_flags AS policy1_message_flags,
3359
    cp1.channel_flags AS policy1_channel_flags,
3360
    cp1.signature AS policy1_signature,
3361
    cp1.block_height AS policy1_block_height,
3362
    cp1.disable_flags AS policy1_disable_flags,
3363

3364
       -- Policy 2
3365
    cp2.id AS policy2_id,
3366
    cp2.node_id AS policy2_node_id,
3367
    cp2.version AS policy2_version,
3368
    cp2.timelock AS policy2_timelock,
3369
    cp2.fee_ppm AS policy2_fee_ppm,
3370
    cp2.base_fee_msat AS policy2_base_fee_msat,
3371
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
3372
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
3373
    cp2.last_update AS policy2_last_update,
3374
    cp2.disabled AS policy2_disabled,
3375
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3376
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3377
    cp2.message_flags AS policy2_message_flags,
3378
    cp2.channel_flags AS policy2_channel_flags,
3379
    cp2.signature AS policy2_signature,
3380
    cp2.block_height AS policy2_block_height,
3381
    cp2.disable_flags AS policy2_disable_flags
3382

3383
FROM graph_channels c
3384
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3385
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3386
    LEFT JOIN graph_channel_policies cp1
3387
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3388
    LEFT JOIN graph_channel_policies cp2
3389
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3390
WHERE c.version = $1
3391
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
3392
`
3393

3394
type ListChannelsByNodeIDParams struct {
3395
        Version int16
3396
        NodeID1 int64
3397
}
3398

3399
type ListChannelsByNodeIDRow struct {
3400
        GraphChannel                   GraphChannel
3401
        Node1Pubkey                    []byte
3402
        Node2Pubkey                    []byte
3403
        Policy1ID                      sql.NullInt64
3404
        Policy1NodeID                  sql.NullInt64
3405
        Policy1Version                 sql.NullInt16
3406
        Policy1Timelock                sql.NullInt32
3407
        Policy1FeePpm                  sql.NullInt64
3408
        Policy1BaseFeeMsat             sql.NullInt64
3409
        Policy1MinHtlcMsat             sql.NullInt64
3410
        Policy1MaxHtlcMsat             sql.NullInt64
3411
        Policy1LastUpdate              sql.NullInt64
3412
        Policy1Disabled                sql.NullBool
3413
        Policy1InboundBaseFeeMsat      sql.NullInt64
3414
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3415
        Policy1MessageFlags            sql.NullInt16
3416
        Policy1ChannelFlags            sql.NullInt16
3417
        Policy1Signature               []byte
3418
        Policy1BlockHeight             sql.NullInt64
3419
        Policy1DisableFlags            sql.NullInt16
3420
        Policy2ID                      sql.NullInt64
3421
        Policy2NodeID                  sql.NullInt64
3422
        Policy2Version                 sql.NullInt16
3423
        Policy2Timelock                sql.NullInt32
3424
        Policy2FeePpm                  sql.NullInt64
3425
        Policy2BaseFeeMsat             sql.NullInt64
3426
        Policy2MinHtlcMsat             sql.NullInt64
3427
        Policy2MaxHtlcMsat             sql.NullInt64
3428
        Policy2LastUpdate              sql.NullInt64
3429
        Policy2Disabled                sql.NullBool
3430
        Policy2InboundBaseFeeMsat      sql.NullInt64
3431
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3432
        Policy2MessageFlags            sql.NullInt16
3433
        Policy2ChannelFlags            sql.NullInt16
3434
        Policy2Signature               []byte
3435
        Policy2BlockHeight             sql.NullInt64
3436
        Policy2DisableFlags            sql.NullInt16
3437
}
3438

3439
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
3440
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
3441
        if err != nil {
×
3442
                return nil, err
×
3443
        }
×
3444
        defer rows.Close()
×
3445
        var items []ListChannelsByNodeIDRow
×
3446
        for rows.Next() {
×
3447
                var i ListChannelsByNodeIDRow
×
3448
                if err := rows.Scan(
×
3449
                        &i.GraphChannel.ID,
×
3450
                        &i.GraphChannel.Version,
×
3451
                        &i.GraphChannel.Scid,
×
3452
                        &i.GraphChannel.NodeID1,
×
3453
                        &i.GraphChannel.NodeID2,
×
3454
                        &i.GraphChannel.Outpoint,
×
3455
                        &i.GraphChannel.Capacity,
×
3456
                        &i.GraphChannel.BitcoinKey1,
×
3457
                        &i.GraphChannel.BitcoinKey2,
×
3458
                        &i.GraphChannel.Node1Signature,
×
3459
                        &i.GraphChannel.Node2Signature,
×
3460
                        &i.GraphChannel.Bitcoin1Signature,
×
3461
                        &i.GraphChannel.Bitcoin2Signature,
×
3462
                        &i.GraphChannel.Signature,
×
3463
                        &i.GraphChannel.FundingPkScript,
×
3464
                        &i.GraphChannel.MerkleRootHash,
×
3465
                        &i.Node1Pubkey,
×
3466
                        &i.Node2Pubkey,
×
3467
                        &i.Policy1ID,
×
3468
                        &i.Policy1NodeID,
×
3469
                        &i.Policy1Version,
×
3470
                        &i.Policy1Timelock,
×
3471
                        &i.Policy1FeePpm,
×
3472
                        &i.Policy1BaseFeeMsat,
×
3473
                        &i.Policy1MinHtlcMsat,
×
3474
                        &i.Policy1MaxHtlcMsat,
×
3475
                        &i.Policy1LastUpdate,
×
3476
                        &i.Policy1Disabled,
×
3477
                        &i.Policy1InboundBaseFeeMsat,
×
3478
                        &i.Policy1InboundFeeRateMilliMsat,
×
3479
                        &i.Policy1MessageFlags,
×
3480
                        &i.Policy1ChannelFlags,
×
3481
                        &i.Policy1Signature,
×
3482
                        &i.Policy1BlockHeight,
×
3483
                        &i.Policy1DisableFlags,
×
3484
                        &i.Policy2ID,
×
3485
                        &i.Policy2NodeID,
×
3486
                        &i.Policy2Version,
×
3487
                        &i.Policy2Timelock,
×
3488
                        &i.Policy2FeePpm,
×
3489
                        &i.Policy2BaseFeeMsat,
×
3490
                        &i.Policy2MinHtlcMsat,
×
3491
                        &i.Policy2MaxHtlcMsat,
×
3492
                        &i.Policy2LastUpdate,
×
3493
                        &i.Policy2Disabled,
×
3494
                        &i.Policy2InboundBaseFeeMsat,
×
3495
                        &i.Policy2InboundFeeRateMilliMsat,
×
3496
                        &i.Policy2MessageFlags,
×
3497
                        &i.Policy2ChannelFlags,
×
3498
                        &i.Policy2Signature,
×
3499
                        &i.Policy2BlockHeight,
×
3500
                        &i.Policy2DisableFlags,
×
3501
                ); err != nil {
×
3502
                        return nil, err
×
3503
                }
×
3504
                items = append(items, i)
×
3505
        }
3506
        if err := rows.Close(); err != nil {
×
3507
                return nil, err
×
3508
        }
×
3509
        if err := rows.Err(); err != nil {
×
3510
                return nil, err
×
3511
        }
×
3512
        return items, nil
×
3513
}
3514

3515
const listChannelsForNodeIDs = `-- name: ListChannelsForNodeIDs :many
3516
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,
3517
       n1.pub_key AS node1_pubkey,
3518
       n2.pub_key AS node2_pubkey,
3519

3520
       -- Policy 1
3521
       -- TODO(elle): use sqlc.embed to embed policy structs
3522
       --  once this issue is resolved:
3523
       --  https://github.com/sqlc-dev/sqlc/issues/2997
3524
       cp1.id AS policy1_id,
3525
       cp1.node_id AS policy1_node_id,
3526
       cp1.version AS policy1_version,
3527
       cp1.timelock AS policy1_timelock,
3528
       cp1.fee_ppm AS policy1_fee_ppm,
3529
       cp1.base_fee_msat AS policy1_base_fee_msat,
3530
       cp1.min_htlc_msat AS policy1_min_htlc_msat,
3531
       cp1.max_htlc_msat AS policy1_max_htlc_msat,
3532
       cp1.last_update AS policy1_last_update,
3533
       cp1.disabled AS policy1_disabled,
3534
       cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3535
       cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3536
       cp1.message_flags AS policy1_message_flags,
3537
       cp1.channel_flags AS policy1_channel_flags,
3538
       cp1.signature AS policy1_signature,
3539
    cp1.block_height AS policy1_block_height,
3540
    cp1.disable_flags AS policy1_disable_flags,
3541

3542
       -- Policy 2
3543
       cp2.id AS policy2_id,
3544
       cp2.node_id AS policy2_node_id,
3545
       cp2.version AS policy2_version,
3546
       cp2.timelock AS policy2_timelock,
3547
       cp2.fee_ppm AS policy2_fee_ppm,
3548
       cp2.base_fee_msat AS policy2_base_fee_msat,
3549
       cp2.min_htlc_msat AS policy2_min_htlc_msat,
3550
       cp2.max_htlc_msat AS policy2_max_htlc_msat,
3551
       cp2.last_update AS policy2_last_update,
3552
       cp2.disabled AS policy2_disabled,
3553
       cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3554
       cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3555
       cp2.message_flags AS policy2_message_flags,
3556
       cp2.channel_flags AS policy2_channel_flags,
3557
       cp2.signature AS policy2_signature,
3558
    cp2.block_height AS policy2_block_height,
3559
    cp2.disable_flags AS policy2_disable_flags
3560

3561
FROM graph_channels c
3562
         JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3563
         JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3564
         LEFT JOIN graph_channel_policies cp1
3565
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3566
         LEFT JOIN graph_channel_policies cp2
3567
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3568
WHERE c.version = $1
3569
  AND (c.node_id_1 IN (/*SLICE:node1_ids*/?)
3570
   OR c.node_id_2 IN (/*SLICE:node2_ids*/?))
3571
`
3572

3573
type ListChannelsForNodeIDsParams struct {
3574
        Version  int16
3575
        Node1Ids []int64
3576
        Node2Ids []int64
3577
}
3578

3579
type ListChannelsForNodeIDsRow struct {
3580
        GraphChannel                   GraphChannel
3581
        Node1Pubkey                    []byte
3582
        Node2Pubkey                    []byte
3583
        Policy1ID                      sql.NullInt64
3584
        Policy1NodeID                  sql.NullInt64
3585
        Policy1Version                 sql.NullInt16
3586
        Policy1Timelock                sql.NullInt32
3587
        Policy1FeePpm                  sql.NullInt64
3588
        Policy1BaseFeeMsat             sql.NullInt64
3589
        Policy1MinHtlcMsat             sql.NullInt64
3590
        Policy1MaxHtlcMsat             sql.NullInt64
3591
        Policy1LastUpdate              sql.NullInt64
3592
        Policy1Disabled                sql.NullBool
3593
        Policy1InboundBaseFeeMsat      sql.NullInt64
3594
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3595
        Policy1MessageFlags            sql.NullInt16
3596
        Policy1ChannelFlags            sql.NullInt16
3597
        Policy1Signature               []byte
3598
        Policy1BlockHeight             sql.NullInt64
3599
        Policy1DisableFlags            sql.NullInt16
3600
        Policy2ID                      sql.NullInt64
3601
        Policy2NodeID                  sql.NullInt64
3602
        Policy2Version                 sql.NullInt16
3603
        Policy2Timelock                sql.NullInt32
3604
        Policy2FeePpm                  sql.NullInt64
3605
        Policy2BaseFeeMsat             sql.NullInt64
3606
        Policy2MinHtlcMsat             sql.NullInt64
3607
        Policy2MaxHtlcMsat             sql.NullInt64
3608
        Policy2LastUpdate              sql.NullInt64
3609
        Policy2Disabled                sql.NullBool
3610
        Policy2InboundBaseFeeMsat      sql.NullInt64
3611
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3612
        Policy2MessageFlags            sql.NullInt16
3613
        Policy2ChannelFlags            sql.NullInt16
3614
        Policy2Signature               []byte
3615
        Policy2BlockHeight             sql.NullInt64
3616
        Policy2DisableFlags            sql.NullInt16
3617
}
3618

3619
func (q *Queries) ListChannelsForNodeIDs(ctx context.Context, arg ListChannelsForNodeIDsParams) ([]ListChannelsForNodeIDsRow, error) {
×
3620
        query := listChannelsForNodeIDs
×
3621
        var queryParams []interface{}
×
3622
        queryParams = append(queryParams, arg.Version)
×
3623
        if len(arg.Node1Ids) > 0 {
×
3624
                for _, v := range arg.Node1Ids {
×
3625
                        queryParams = append(queryParams, v)
×
3626
                }
×
3627
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", makeQueryParams(len(queryParams), len(arg.Node1Ids)), 1)
×
3628
        } else {
×
3629
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", "NULL", 1)
×
3630
        }
×
3631
        if len(arg.Node2Ids) > 0 {
×
3632
                for _, v := range arg.Node2Ids {
×
3633
                        queryParams = append(queryParams, v)
×
3634
                }
×
3635
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", makeQueryParams(len(queryParams), len(arg.Node2Ids)), 1)
×
3636
        } else {
×
3637
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", "NULL", 1)
×
3638
        }
×
3639
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
3640
        if err != nil {
×
3641
                return nil, err
×
3642
        }
×
3643
        defer rows.Close()
×
3644
        var items []ListChannelsForNodeIDsRow
×
3645
        for rows.Next() {
×
3646
                var i ListChannelsForNodeIDsRow
×
3647
                if err := rows.Scan(
×
3648
                        &i.GraphChannel.ID,
×
3649
                        &i.GraphChannel.Version,
×
3650
                        &i.GraphChannel.Scid,
×
3651
                        &i.GraphChannel.NodeID1,
×
3652
                        &i.GraphChannel.NodeID2,
×
3653
                        &i.GraphChannel.Outpoint,
×
3654
                        &i.GraphChannel.Capacity,
×
3655
                        &i.GraphChannel.BitcoinKey1,
×
3656
                        &i.GraphChannel.BitcoinKey2,
×
3657
                        &i.GraphChannel.Node1Signature,
×
3658
                        &i.GraphChannel.Node2Signature,
×
3659
                        &i.GraphChannel.Bitcoin1Signature,
×
3660
                        &i.GraphChannel.Bitcoin2Signature,
×
3661
                        &i.GraphChannel.Signature,
×
3662
                        &i.GraphChannel.FundingPkScript,
×
3663
                        &i.GraphChannel.MerkleRootHash,
×
3664
                        &i.Node1Pubkey,
×
3665
                        &i.Node2Pubkey,
×
3666
                        &i.Policy1ID,
×
3667
                        &i.Policy1NodeID,
×
3668
                        &i.Policy1Version,
×
3669
                        &i.Policy1Timelock,
×
3670
                        &i.Policy1FeePpm,
×
3671
                        &i.Policy1BaseFeeMsat,
×
3672
                        &i.Policy1MinHtlcMsat,
×
3673
                        &i.Policy1MaxHtlcMsat,
×
3674
                        &i.Policy1LastUpdate,
×
3675
                        &i.Policy1Disabled,
×
3676
                        &i.Policy1InboundBaseFeeMsat,
×
3677
                        &i.Policy1InboundFeeRateMilliMsat,
×
3678
                        &i.Policy1MessageFlags,
×
3679
                        &i.Policy1ChannelFlags,
×
3680
                        &i.Policy1Signature,
×
3681
                        &i.Policy1BlockHeight,
×
3682
                        &i.Policy1DisableFlags,
×
3683
                        &i.Policy2ID,
×
3684
                        &i.Policy2NodeID,
×
3685
                        &i.Policy2Version,
×
3686
                        &i.Policy2Timelock,
×
3687
                        &i.Policy2FeePpm,
×
3688
                        &i.Policy2BaseFeeMsat,
×
3689
                        &i.Policy2MinHtlcMsat,
×
3690
                        &i.Policy2MaxHtlcMsat,
×
3691
                        &i.Policy2LastUpdate,
×
3692
                        &i.Policy2Disabled,
×
3693
                        &i.Policy2InboundBaseFeeMsat,
×
3694
                        &i.Policy2InboundFeeRateMilliMsat,
×
3695
                        &i.Policy2MessageFlags,
×
3696
                        &i.Policy2ChannelFlags,
×
3697
                        &i.Policy2Signature,
×
3698
                        &i.Policy2BlockHeight,
×
3699
                        &i.Policy2DisableFlags,
×
3700
                ); err != nil {
×
3701
                        return nil, err
×
3702
                }
×
3703
                items = append(items, i)
×
3704
        }
3705
        if err := rows.Close(); err != nil {
×
3706
                return nil, err
×
3707
        }
×
3708
        if err := rows.Err(); err != nil {
×
3709
                return nil, err
×
3710
        }
×
3711
        return items, nil
×
3712
}
3713

3714
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
3715
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
3716
FROM graph_channels c
3717
WHERE c.version = $1 AND c.id > $2
3718
ORDER BY c.id
3719
LIMIT $3
3720
`
3721

3722
type ListChannelsPaginatedParams struct {
3723
        Version int16
3724
        ID      int64
3725
        Limit   int32
3726
}
3727

3728
type ListChannelsPaginatedRow struct {
3729
        ID          int64
3730
        BitcoinKey1 []byte
3731
        BitcoinKey2 []byte
3732
        Outpoint    string
3733
}
3734

3735
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
3736
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
3737
        if err != nil {
×
3738
                return nil, err
×
3739
        }
×
3740
        defer rows.Close()
×
3741
        var items []ListChannelsPaginatedRow
×
3742
        for rows.Next() {
×
3743
                var i ListChannelsPaginatedRow
×
3744
                if err := rows.Scan(
×
3745
                        &i.ID,
×
3746
                        &i.BitcoinKey1,
×
3747
                        &i.BitcoinKey2,
×
3748
                        &i.Outpoint,
×
3749
                ); err != nil {
×
3750
                        return nil, err
×
3751
                }
×
3752
                items = append(items, i)
×
3753
        }
3754
        if err := rows.Close(); err != nil {
×
3755
                return nil, err
×
3756
        }
×
3757
        if err := rows.Err(); err != nil {
×
3758
                return nil, err
×
3759
        }
×
3760
        return items, nil
×
3761
}
3762

3763
const listChannelsPaginatedV2 = `-- name: ListChannelsPaginatedV2 :many
3764
SELECT id, outpoint, funding_pk_script
3765
FROM graph_channels c
3766
WHERE c.version = 2 AND c.id > $1
3767
ORDER BY c.id
3768
LIMIT $2
3769
`
3770

3771
type ListChannelsPaginatedV2Params struct {
3772
        ID    int64
3773
        Limit int32
3774
}
3775

3776
type ListChannelsPaginatedV2Row struct {
3777
        ID              int64
3778
        Outpoint        string
3779
        FundingPkScript []byte
3780
}
3781

3782
func (q *Queries) ListChannelsPaginatedV2(ctx context.Context, arg ListChannelsPaginatedV2Params) ([]ListChannelsPaginatedV2Row, error) {
×
3783
        rows, err := q.db.QueryContext(ctx, listChannelsPaginatedV2, arg.ID, arg.Limit)
×
3784
        if err != nil {
×
3785
                return nil, err
×
3786
        }
×
3787
        defer rows.Close()
×
3788
        var items []ListChannelsPaginatedV2Row
×
3789
        for rows.Next() {
×
3790
                var i ListChannelsPaginatedV2Row
×
3791
                if err := rows.Scan(&i.ID, &i.Outpoint, &i.FundingPkScript); err != nil {
×
3792
                        return nil, err
×
3793
                }
×
3794
                items = append(items, i)
×
3795
        }
3796
        if err := rows.Close(); err != nil {
×
3797
                return nil, err
×
3798
        }
×
3799
        if err := rows.Err(); err != nil {
×
3800
                return nil, err
×
3801
        }
×
3802
        return items, nil
×
3803
}
3804

3805
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
3806
SELECT
3807
    c.id as id,
3808
    c.scid as scid,
3809
    c.capacity AS capacity,
3810

3811
    -- Join node pubkeys
3812
    n1.pub_key AS node1_pubkey,
3813
    n2.pub_key AS node2_pubkey,
3814

3815
    -- Node 1 policy
3816
    cp1.version AS policy1_version,
3817
    cp1.timelock AS policy_1_timelock,
3818
    cp1.fee_ppm AS policy_1_fee_ppm,
3819
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3820
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3821
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3822
    cp1.disabled AS policy_1_disabled,
3823
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3824
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3825
    cp1.message_flags AS policy1_message_flags,
3826
    cp1.channel_flags AS policy1_channel_flags,
3827
    cp1.block_height AS policy1_block_height,
3828
    cp1.disable_flags AS policy1_disable_flags,
3829

3830
    -- Node 2 policy
3831
    cp2.version AS policy2_version,
3832
    cp2.timelock AS policy_2_timelock,
3833
    cp2.fee_ppm AS policy_2_fee_ppm,
3834
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3835
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3836
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3837
    cp2.disabled AS policy_2_disabled,
3838
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3839
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3840
    cp2.message_flags AS policy2_message_flags,
3841
    cp2.channel_flags AS policy2_channel_flags,
3842
    cp2.block_height AS policy2_block_height,
3843
    cp2.disable_flags AS policy2_disable_flags
3844

3845
FROM graph_channels c
3846
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3847
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3848
LEFT JOIN graph_channel_policies cp1
3849
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3850
LEFT JOIN graph_channel_policies cp2
3851
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3852
WHERE c.version = $1 AND c.id > $2
3853
ORDER BY c.id
3854
LIMIT $3
3855
`
3856

3857
type ListChannelsWithPoliciesForCachePaginatedParams struct {
3858
        Version int16
3859
        ID      int64
3860
        Limit   int32
3861
}
3862

3863
type ListChannelsWithPoliciesForCachePaginatedRow struct {
3864
        ID                             int64
3865
        Scid                           []byte
3866
        Capacity                       sql.NullInt64
3867
        Node1Pubkey                    []byte
3868
        Node2Pubkey                    []byte
3869
        Policy1Version                 sql.NullInt16
3870
        Policy1Timelock                sql.NullInt32
3871
        Policy1FeePpm                  sql.NullInt64
3872
        Policy1BaseFeeMsat             sql.NullInt64
3873
        Policy1MinHtlcMsat             sql.NullInt64
3874
        Policy1MaxHtlcMsat             sql.NullInt64
3875
        Policy1Disabled                sql.NullBool
3876
        Policy1InboundBaseFeeMsat      sql.NullInt64
3877
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3878
        Policy1MessageFlags            sql.NullInt16
3879
        Policy1ChannelFlags            sql.NullInt16
3880
        Policy1BlockHeight             sql.NullInt64
3881
        Policy1DisableFlags            sql.NullInt16
3882
        Policy2Version                 sql.NullInt16
3883
        Policy2Timelock                sql.NullInt32
3884
        Policy2FeePpm                  sql.NullInt64
3885
        Policy2BaseFeeMsat             sql.NullInt64
3886
        Policy2MinHtlcMsat             sql.NullInt64
3887
        Policy2MaxHtlcMsat             sql.NullInt64
3888
        Policy2Disabled                sql.NullBool
3889
        Policy2InboundBaseFeeMsat      sql.NullInt64
3890
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3891
        Policy2MessageFlags            sql.NullInt16
3892
        Policy2ChannelFlags            sql.NullInt16
3893
        Policy2BlockHeight             sql.NullInt64
3894
        Policy2DisableFlags            sql.NullInt16
3895
}
3896

3897
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
3898
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
3899
        if err != nil {
×
3900
                return nil, err
×
3901
        }
×
3902
        defer rows.Close()
×
3903
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
3904
        for rows.Next() {
×
3905
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
3906
                if err := rows.Scan(
×
3907
                        &i.ID,
×
3908
                        &i.Scid,
×
3909
                        &i.Capacity,
×
3910
                        &i.Node1Pubkey,
×
3911
                        &i.Node2Pubkey,
×
3912
                        &i.Policy1Version,
×
3913
                        &i.Policy1Timelock,
×
3914
                        &i.Policy1FeePpm,
×
3915
                        &i.Policy1BaseFeeMsat,
×
3916
                        &i.Policy1MinHtlcMsat,
×
3917
                        &i.Policy1MaxHtlcMsat,
×
3918
                        &i.Policy1Disabled,
×
3919
                        &i.Policy1InboundBaseFeeMsat,
×
3920
                        &i.Policy1InboundFeeRateMilliMsat,
×
3921
                        &i.Policy1MessageFlags,
×
3922
                        &i.Policy1ChannelFlags,
×
3923
                        &i.Policy1BlockHeight,
×
3924
                        &i.Policy1DisableFlags,
×
3925
                        &i.Policy2Version,
×
3926
                        &i.Policy2Timelock,
×
3927
                        &i.Policy2FeePpm,
×
3928
                        &i.Policy2BaseFeeMsat,
×
3929
                        &i.Policy2MinHtlcMsat,
×
3930
                        &i.Policy2MaxHtlcMsat,
×
3931
                        &i.Policy2Disabled,
×
3932
                        &i.Policy2InboundBaseFeeMsat,
×
3933
                        &i.Policy2InboundFeeRateMilliMsat,
×
3934
                        &i.Policy2MessageFlags,
×
3935
                        &i.Policy2ChannelFlags,
×
3936
                        &i.Policy2BlockHeight,
×
3937
                        &i.Policy2DisableFlags,
×
3938
                ); err != nil {
×
3939
                        return nil, err
×
3940
                }
×
3941
                items = append(items, i)
×
3942
        }
3943
        if err := rows.Close(); err != nil {
×
3944
                return nil, err
×
3945
        }
×
3946
        if err := rows.Err(); err != nil {
×
3947
                return nil, err
×
3948
        }
×
3949
        return items, nil
×
3950
}
3951

3952
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
3953
SELECT
3954
    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,
3955

3956
    -- Join node pubkeys
3957
    n1.pub_key AS node1_pubkey,
3958
    n2.pub_key AS node2_pubkey,
3959

3960
    -- Node 1 policy
3961
    cp1.id AS policy_1_id,
3962
    cp1.node_id AS policy_1_node_id,
3963
    cp1.version AS policy_1_version,
3964
    cp1.timelock AS policy_1_timelock,
3965
    cp1.fee_ppm AS policy_1_fee_ppm,
3966
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3967
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3968
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3969
    cp1.last_update AS policy_1_last_update,
3970
    cp1.disabled AS policy_1_disabled,
3971
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3972
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3973
    cp1.message_flags AS policy1_message_flags,
3974
    cp1.channel_flags AS policy1_channel_flags,
3975
    cp1.block_height AS policy1_block_height,
3976
    cp1.disable_flags AS policy1_disable_flags,
3977
    cp1.signature AS policy_1_signature,
3978

3979
    -- Node 2 policy
3980
    cp2.id AS policy_2_id,
3981
    cp2.node_id AS policy_2_node_id,
3982
    cp2.version AS policy_2_version,
3983
    cp2.timelock AS policy_2_timelock,
3984
    cp2.fee_ppm AS policy_2_fee_ppm,
3985
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3986
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3987
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3988
    cp2.last_update AS policy_2_last_update,
3989
    cp2.disabled AS policy_2_disabled,
3990
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3991
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3992
    cp2.message_flags AS policy2_message_flags,
3993
    cp2.channel_flags AS policy2_channel_flags,
3994
    cp2.signature AS policy_2_signature,
3995
    cp2.block_height AS policy_2_block_height,
3996
    cp2.disable_flags AS policy_2_disable_flags
3997

3998
FROM graph_channels c
3999
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
4000
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
4001
LEFT JOIN graph_channel_policies cp1
4002
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
4003
LEFT JOIN graph_channel_policies cp2
4004
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
4005
WHERE c.version = $1 AND c.id > $2
4006
ORDER BY c.id
4007
LIMIT $3
4008
`
4009

4010
type ListChannelsWithPoliciesPaginatedParams struct {
4011
        Version int16
4012
        ID      int64
4013
        Limit   int32
4014
}
4015

4016
type ListChannelsWithPoliciesPaginatedRow struct {
4017
        GraphChannel                   GraphChannel
4018
        Node1Pubkey                    []byte
4019
        Node2Pubkey                    []byte
4020
        Policy1ID                      sql.NullInt64
4021
        Policy1NodeID                  sql.NullInt64
4022
        Policy1Version                 sql.NullInt16
4023
        Policy1Timelock                sql.NullInt32
4024
        Policy1FeePpm                  sql.NullInt64
4025
        Policy1BaseFeeMsat             sql.NullInt64
4026
        Policy1MinHtlcMsat             sql.NullInt64
4027
        Policy1MaxHtlcMsat             sql.NullInt64
4028
        Policy1LastUpdate              sql.NullInt64
4029
        Policy1Disabled                sql.NullBool
4030
        Policy1InboundBaseFeeMsat      sql.NullInt64
4031
        Policy1InboundFeeRateMilliMsat sql.NullInt64
4032
        Policy1MessageFlags            sql.NullInt16
4033
        Policy1ChannelFlags            sql.NullInt16
4034
        Policy1BlockHeight             sql.NullInt64
4035
        Policy1DisableFlags            sql.NullInt16
4036
        Policy1Signature               []byte
4037
        Policy2ID                      sql.NullInt64
4038
        Policy2NodeID                  sql.NullInt64
4039
        Policy2Version                 sql.NullInt16
4040
        Policy2Timelock                sql.NullInt32
4041
        Policy2FeePpm                  sql.NullInt64
4042
        Policy2BaseFeeMsat             sql.NullInt64
4043
        Policy2MinHtlcMsat             sql.NullInt64
4044
        Policy2MaxHtlcMsat             sql.NullInt64
4045
        Policy2LastUpdate              sql.NullInt64
4046
        Policy2Disabled                sql.NullBool
4047
        Policy2InboundBaseFeeMsat      sql.NullInt64
4048
        Policy2InboundFeeRateMilliMsat sql.NullInt64
4049
        Policy2MessageFlags            sql.NullInt16
4050
        Policy2ChannelFlags            sql.NullInt16
4051
        Policy2Signature               []byte
4052
        Policy2BlockHeight             sql.NullInt64
4053
        Policy2DisableFlags            sql.NullInt16
4054
}
4055

4056
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
4057
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
4058
        if err != nil {
×
4059
                return nil, err
×
4060
        }
×
4061
        defer rows.Close()
×
4062
        var items []ListChannelsWithPoliciesPaginatedRow
×
4063
        for rows.Next() {
×
4064
                var i ListChannelsWithPoliciesPaginatedRow
×
4065
                if err := rows.Scan(
×
4066
                        &i.GraphChannel.ID,
×
4067
                        &i.GraphChannel.Version,
×
4068
                        &i.GraphChannel.Scid,
×
4069
                        &i.GraphChannel.NodeID1,
×
4070
                        &i.GraphChannel.NodeID2,
×
4071
                        &i.GraphChannel.Outpoint,
×
4072
                        &i.GraphChannel.Capacity,
×
4073
                        &i.GraphChannel.BitcoinKey1,
×
4074
                        &i.GraphChannel.BitcoinKey2,
×
4075
                        &i.GraphChannel.Node1Signature,
×
4076
                        &i.GraphChannel.Node2Signature,
×
4077
                        &i.GraphChannel.Bitcoin1Signature,
×
4078
                        &i.GraphChannel.Bitcoin2Signature,
×
4079
                        &i.GraphChannel.Signature,
×
4080
                        &i.GraphChannel.FundingPkScript,
×
4081
                        &i.GraphChannel.MerkleRootHash,
×
4082
                        &i.Node1Pubkey,
×
4083
                        &i.Node2Pubkey,
×
4084
                        &i.Policy1ID,
×
4085
                        &i.Policy1NodeID,
×
4086
                        &i.Policy1Version,
×
4087
                        &i.Policy1Timelock,
×
4088
                        &i.Policy1FeePpm,
×
4089
                        &i.Policy1BaseFeeMsat,
×
4090
                        &i.Policy1MinHtlcMsat,
×
4091
                        &i.Policy1MaxHtlcMsat,
×
4092
                        &i.Policy1LastUpdate,
×
4093
                        &i.Policy1Disabled,
×
4094
                        &i.Policy1InboundBaseFeeMsat,
×
4095
                        &i.Policy1InboundFeeRateMilliMsat,
×
4096
                        &i.Policy1MessageFlags,
×
4097
                        &i.Policy1ChannelFlags,
×
4098
                        &i.Policy1BlockHeight,
×
4099
                        &i.Policy1DisableFlags,
×
4100
                        &i.Policy1Signature,
×
4101
                        &i.Policy2ID,
×
4102
                        &i.Policy2NodeID,
×
4103
                        &i.Policy2Version,
×
4104
                        &i.Policy2Timelock,
×
4105
                        &i.Policy2FeePpm,
×
4106
                        &i.Policy2BaseFeeMsat,
×
4107
                        &i.Policy2MinHtlcMsat,
×
4108
                        &i.Policy2MaxHtlcMsat,
×
4109
                        &i.Policy2LastUpdate,
×
4110
                        &i.Policy2Disabled,
×
4111
                        &i.Policy2InboundBaseFeeMsat,
×
4112
                        &i.Policy2InboundFeeRateMilliMsat,
×
4113
                        &i.Policy2MessageFlags,
×
4114
                        &i.Policy2ChannelFlags,
×
4115
                        &i.Policy2Signature,
×
4116
                        &i.Policy2BlockHeight,
×
4117
                        &i.Policy2DisableFlags,
×
4118
                ); err != nil {
×
4119
                        return nil, err
×
4120
                }
×
4121
                items = append(items, i)
×
4122
        }
4123
        if err := rows.Close(); err != nil {
×
4124
                return nil, err
×
4125
        }
×
4126
        if err := rows.Err(); err != nil {
×
4127
                return nil, err
×
4128
        }
×
4129
        return items, nil
×
4130
}
4131

4132
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
4133
SELECT id, pub_key
4134
FROM graph_nodes
4135
WHERE version = $1  AND id > $2
4136
ORDER BY id
4137
LIMIT $3
4138
`
4139

4140
type ListNodeIDsAndPubKeysParams struct {
4141
        Version int16
4142
        ID      int64
4143
        Limit   int32
4144
}
4145

4146
type ListNodeIDsAndPubKeysRow struct {
4147
        ID     int64
4148
        PubKey []byte
4149
}
4150

4151
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
4152
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
4153
        if err != nil {
×
4154
                return nil, err
×
4155
        }
×
4156
        defer rows.Close()
×
4157
        var items []ListNodeIDsAndPubKeysRow
×
4158
        for rows.Next() {
×
4159
                var i ListNodeIDsAndPubKeysRow
×
4160
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
4161
                        return nil, err
×
4162
                }
×
4163
                items = append(items, i)
×
4164
        }
4165
        if err := rows.Close(); err != nil {
×
4166
                return nil, err
×
4167
        }
×
4168
        if err := rows.Err(); err != nil {
×
4169
                return nil, err
×
4170
        }
×
4171
        return items, nil
×
4172
}
4173

4174
const listNodesPaginated = `-- name: ListNodesPaginated :many
4175
SELECT id, version, pub_key, alias, last_update, color, signature, block_height
4176
FROM graph_nodes
4177
WHERE version = $1 AND id > $2
4178
ORDER BY id
4179
LIMIT $3
4180
`
4181

4182
type ListNodesPaginatedParams struct {
4183
        Version int16
4184
        ID      int64
4185
        Limit   int32
4186
}
4187

4188
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
4189
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
4190
        if err != nil {
×
4191
                return nil, err
×
4192
        }
×
4193
        defer rows.Close()
×
4194
        var items []GraphNode
×
4195
        for rows.Next() {
×
4196
                var i GraphNode
×
4197
                if err := rows.Scan(
×
4198
                        &i.ID,
×
4199
                        &i.Version,
×
4200
                        &i.PubKey,
×
4201
                        &i.Alias,
×
4202
                        &i.LastUpdate,
×
4203
                        &i.Color,
×
4204
                        &i.Signature,
×
4205
                        &i.BlockHeight,
×
4206
                ); err != nil {
×
4207
                        return nil, err
×
4208
                }
×
4209
                items = append(items, i)
×
4210
        }
4211
        if err := rows.Close(); err != nil {
×
4212
                return nil, err
×
4213
        }
×
4214
        if err := rows.Err(); err != nil {
×
4215
                return nil, err
×
4216
        }
×
4217
        return items, nil
×
4218
}
4219

4220
const nodeExists = `-- name: NodeExists :one
4221
SELECT EXISTS (
4222
    SELECT 1
4223
    FROM graph_nodes
4224
    WHERE pub_key = $1
4225
      AND version = $2
4226
) AS node_exists
4227
`
4228

4229
type NodeExistsParams struct {
4230
        PubKey  []byte
4231
        Version int16
4232
}
4233

4234
func (q *Queries) NodeExists(ctx context.Context, arg NodeExistsParams) (bool, error) {
×
4235
        row := q.db.QueryRowContext(ctx, nodeExists, arg.PubKey, arg.Version)
×
4236
        var node_exists bool
×
4237
        err := row.Scan(&node_exists)
×
4238
        return node_exists, err
×
4239
}
×
4240

4241
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
4242
/* ─────────────────────────────────────────────
4243
   graph_channel_policy_extra_types table queries
4244
   ─────────────────────────────────────────────
4245
*/
4246

4247
INSERT INTO graph_channel_policy_extra_types (
4248
    channel_policy_id, type, value
4249
)
4250
VALUES ($1, $2, $3)
4251
ON CONFLICT (channel_policy_id, type)
4252
    -- If a conflict occurs on channel_policy_id and type, then we update the
4253
    -- value.
4254
    DO UPDATE SET value = EXCLUDED.value
4255
`
4256

4257
type UpsertChanPolicyExtraTypeParams struct {
4258
        ChannelPolicyID int64
4259
        Type            int64
4260
        Value           []byte
4261
}
4262

4263
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
4264
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
4265
        return err
×
4266
}
×
4267

4268
const upsertChannelExtraType = `-- name: UpsertChannelExtraType :exec
4269
/* ─────────────────────────────────────────────
4270
   graph_channel_extra_types table queries
4271
   ─────────────────────────────────────────────
4272
*/
4273

4274
INSERT INTO graph_channel_extra_types (
4275
    channel_id, type, value
4276
)
4277
VALUES ($1, $2, $3)
4278
    ON CONFLICT (channel_id, type)
4279
    -- Update the value if a conflict occurs on channel_id and type.
4280
    DO UPDATE SET value = EXCLUDED.value
4281
`
4282

4283
type UpsertChannelExtraTypeParams struct {
4284
        ChannelID int64
4285
        Type      int64
4286
        Value     []byte
4287
}
4288

4289
func (q *Queries) UpsertChannelExtraType(ctx context.Context, arg UpsertChannelExtraTypeParams) error {
×
4290
        _, err := q.db.ExecContext(ctx, upsertChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
4291
        return err
×
4292
}
×
4293

4294
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
4295
/* ─────────────────────────────────────────────
4296
   graph_channel_policies table queries
4297
   ─────────────────────────────────────────────
4298
*/
4299

4300
INSERT INTO graph_channel_policies (
4301
    version, channel_id, node_id, timelock, fee_ppm,
4302
    base_fee_msat, min_htlc_msat, last_update, disabled,
4303
    max_htlc_msat, inbound_base_fee_msat,
4304
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
4305
    signature, block_height, disable_flags
4306
) VALUES  (
4307
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
4308
)
4309
ON CONFLICT (channel_id, node_id, version)
4310
    -- Update the following fields if a conflict occurs on channel_id,
4311
    -- node_id, and version.
4312
    DO UPDATE SET
4313
        timelock = EXCLUDED.timelock,
4314
        fee_ppm = EXCLUDED.fee_ppm,
4315
        base_fee_msat = EXCLUDED.base_fee_msat,
4316
        min_htlc_msat = EXCLUDED.min_htlc_msat,
4317
        last_update = EXCLUDED.last_update,
4318
        disabled = EXCLUDED.disabled,
4319
        max_htlc_msat = EXCLUDED.max_htlc_msat,
4320
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
4321
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
4322
        message_flags = EXCLUDED.message_flags,
4323
        channel_flags = EXCLUDED.channel_flags,
4324
        signature = EXCLUDED.signature,
4325
        block_height = EXCLUDED.block_height,
4326
        disable_flags = EXCLUDED.disable_flags
4327
WHERE (
4328
    EXCLUDED.version = 1 AND (
4329
        graph_channel_policies.last_update IS NULL
4330
        OR EXCLUDED.last_update > graph_channel_policies.last_update
4331
    )
4332
)
4333
OR (
4334
    EXCLUDED.version = 2 AND (
4335
        graph_channel_policies.block_height IS NULL
4336
        OR EXCLUDED.block_height >= graph_channel_policies.block_height
4337
    )
4338
)
4339
RETURNING id
4340
`
4341

4342
type UpsertEdgePolicyParams struct {
4343
        Version                 int16
4344
        ChannelID               int64
4345
        NodeID                  int64
4346
        Timelock                int32
4347
        FeePpm                  int64
4348
        BaseFeeMsat             int64
4349
        MinHtlcMsat             int64
4350
        LastUpdate              sql.NullInt64
4351
        Disabled                sql.NullBool
4352
        MaxHtlcMsat             sql.NullInt64
4353
        InboundBaseFeeMsat      sql.NullInt64
4354
        InboundFeeRateMilliMsat sql.NullInt64
4355
        MessageFlags            sql.NullInt16
4356
        ChannelFlags            sql.NullInt16
4357
        Signature               []byte
4358
        BlockHeight             sql.NullInt64
4359
        DisableFlags            sql.NullInt16
4360
}
4361

4362
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
4363
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
4364
                arg.Version,
×
4365
                arg.ChannelID,
×
4366
                arg.NodeID,
×
4367
                arg.Timelock,
×
4368
                arg.FeePpm,
×
4369
                arg.BaseFeeMsat,
×
4370
                arg.MinHtlcMsat,
×
4371
                arg.LastUpdate,
×
4372
                arg.Disabled,
×
4373
                arg.MaxHtlcMsat,
×
4374
                arg.InboundBaseFeeMsat,
×
4375
                arg.InboundFeeRateMilliMsat,
×
4376
                arg.MessageFlags,
×
4377
                arg.ChannelFlags,
×
4378
                arg.Signature,
×
4379
                arg.BlockHeight,
×
4380
                arg.DisableFlags,
×
4381
        )
×
4382
        var id int64
×
4383
        err := row.Scan(&id)
×
4384
        return id, err
×
4385
}
×
4386

4387
const upsertNode = `-- name: UpsertNode :one
4388
/* ─────────────────────────────────────────────
4389
   graph_nodes table queries
4390
   ───────────────────────────��─────────────────
4391
*/
4392

4393
INSERT INTO graph_nodes (
4394
    version, pub_key, alias, last_update, block_height, color, signature
4395
) VALUES (
4396
    $1, $2, $3, $4, $5, $6, $7
4397
)
4398
ON CONFLICT (pub_key, version)
4399
    -- Update the following fields if a conflict occurs on pub_key
4400
    -- and version.
4401
    DO UPDATE SET
4402
        alias = EXCLUDED.alias,
4403
        last_update = EXCLUDED.last_update,
4404
        block_height = EXCLUDED.block_height,
4405
        color = EXCLUDED.color,
4406
        signature = EXCLUDED.signature
4407
WHERE (graph_nodes.last_update IS NULL
4408
    OR EXCLUDED.last_update > graph_nodes.last_update)
4409
AND (graph_nodes.block_height IS NULL
4410
    OR EXCLUDED.block_height >= graph_nodes.block_height)
4411
RETURNING id
4412
`
4413

4414
type UpsertNodeParams struct {
4415
        Version     int16
4416
        PubKey      []byte
4417
        Alias       sql.NullString
4418
        LastUpdate  sql.NullInt64
4419
        BlockHeight sql.NullInt64
4420
        Color       sql.NullString
4421
        Signature   []byte
4422
}
4423

4424
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
4425
        row := q.db.QueryRowContext(ctx, upsertNode,
×
4426
                arg.Version,
×
4427
                arg.PubKey,
×
4428
                arg.Alias,
×
4429
                arg.LastUpdate,
×
4430
                arg.BlockHeight,
×
4431
                arg.Color,
×
4432
                arg.Signature,
×
4433
        )
×
4434
        var id int64
×
4435
        err := row.Scan(&id)
×
4436
        return id, err
×
4437
}
×
4438

4439
const upsertNodeAddress = `-- name: UpsertNodeAddress :exec
4440
/* ─────────────────────────────────────────────
4441
   graph_node_addresses table queries
4442
   ───────────────────────────────────��─────────
4443
*/
4444

4445
INSERT INTO graph_node_addresses (
4446
    node_id,
4447
    type,
4448
    address,
4449
    position
4450
) VALUES (
4451
    $1, $2, $3, $4
4452
) ON CONFLICT (node_id, type, position)
4453
    DO UPDATE SET address = EXCLUDED.address
4454
`
4455

4456
type UpsertNodeAddressParams struct {
4457
        NodeID   int64
4458
        Type     int16
4459
        Address  string
4460
        Position int32
4461
}
4462

4463
func (q *Queries) UpsertNodeAddress(ctx context.Context, arg UpsertNodeAddressParams) error {
×
4464
        _, err := q.db.ExecContext(ctx, upsertNodeAddress,
×
4465
                arg.NodeID,
×
4466
                arg.Type,
×
4467
                arg.Address,
×
4468
                arg.Position,
×
4469
        )
×
4470
        return err
×
4471
}
×
4472

4473
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
4474
/* ─────────────────────────────────────────────
4475
   graph_node_extra_types table queries
4476
   ─────────────────────────────────────────────
4477
*/
4478

4479
INSERT INTO graph_node_extra_types (
4480
    node_id, type, value
4481
)
4482
VALUES ($1, $2, $3)
4483
ON CONFLICT (type, node_id)
4484
    -- Update the value if a conflict occurs on type
4485
    -- and node_id.
4486
    DO UPDATE SET value = EXCLUDED.value
4487
`
4488

4489
type UpsertNodeExtraTypeParams struct {
4490
        NodeID int64
4491
        Type   int64
4492
        Value  []byte
4493
}
4494

4495
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
4496
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
4497
        return err
×
4498
}
×
4499

4500
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
4501
/* ───────────────────────────���─────────────────
4502
    graph_prune_log table queries
4503
    ─────────────────────────────────────────────
4504
*/
4505

4506
INSERT INTO graph_prune_log (
4507
    block_height, block_hash
4508
) VALUES (
4509
    $1, $2
4510
)
4511
ON CONFLICT(block_height) DO UPDATE SET
4512
    block_hash = EXCLUDED.block_hash
4513
`
4514

4515
type UpsertPruneLogEntryParams struct {
4516
        BlockHeight int64
4517
        BlockHash   []byte
4518
}
4519

4520
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
4521
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
4522
        return err
×
4523
}
×
4524

4525
const upsertSourceNode = `-- name: UpsertSourceNode :one
4526
INSERT INTO graph_nodes (
4527
    version, pub_key, alias, last_update, block_height, color, signature
4528
) VALUES (
4529
    $1, $2, $3, $4, $5, $6, $7
4530
)
4531
ON CONFLICT (pub_key, version)
4532
    -- Update the following fields if a conflict occurs on pub_key
4533
    -- and version.
4534
    DO UPDATE SET
4535
        alias = EXCLUDED.alias,
4536
        last_update = EXCLUDED.last_update,
4537
        block_height = EXCLUDED.block_height,
4538
        color = EXCLUDED.color,
4539
        signature = EXCLUDED.signature
4540
WHERE graph_nodes.last_update IS NULL
4541
    OR EXCLUDED.last_update >= graph_nodes.last_update
4542
AND (graph_nodes.block_height IS NULL
4543
   OR EXCLUDED.block_height >= graph_nodes.block_height)
4544
RETURNING id
4545
`
4546

4547
type UpsertSourceNodeParams struct {
4548
        Version     int16
4549
        PubKey      []byte
4550
        Alias       sql.NullString
4551
        LastUpdate  sql.NullInt64
4552
        BlockHeight sql.NullInt64
4553
        Color       sql.NullString
4554
        Signature   []byte
4555
}
4556

4557
// We use a separate upsert for our own node since we want to be less strict
4558
// about the last_update field. For our own node, we always want to
4559
// update the record even if the last_update is the same as what we have.
4560
func (q *Queries) UpsertSourceNode(ctx context.Context, arg UpsertSourceNodeParams) (int64, error) {
×
4561
        row := q.db.QueryRowContext(ctx, upsertSourceNode,
×
4562
                arg.Version,
×
4563
                arg.PubKey,
×
4564
                arg.Alias,
×
4565
                arg.LastUpdate,
×
4566
                arg.BlockHeight,
×
4567
                arg.Color,
×
4568
                arg.Signature,
×
4569
        )
×
4570
        var id int64
×
4571
        err := row.Scan(&id)
×
4572
        return id, err
×
4573
}
×
4574

4575
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
4576
/* ─────────────────────────────────────────────
4577
   graph_zombie_channels table queries
4578
   ─────────────────────────────────────────────
4579
*/
4580

4581
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
4582
VALUES ($1, $2, $3, $4)
4583
ON CONFLICT (scid, version)
4584
DO UPDATE SET
4585
    -- If a conflict exists for the SCID and version pair, then we
4586
    -- update the node keys.
4587
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
4588
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
4589
`
4590

4591
type UpsertZombieChannelParams struct {
4592
        Scid     []byte
4593
        Version  int16
4594
        NodeKey1 []byte
4595
        NodeKey2 []byte
4596
}
4597

4598
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
4599
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
4600
                arg.Scid,
×
4601
                arg.Version,
×
4602
                arg.NodeKey1,
×
4603
                arg.NodeKey2,
×
4604
        )
×
4605
        return err
×
4606
}
×
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