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

lightningnetwork / lnd / 16640523368

31 Jul 2025 05:17AM UTC coverage: 67.074% (-0.1%) from 67.181%
16640523368

push

github

web-flow
Merge pull request #10115 from ellemouton/graphPerf3

[2] graph/db: batch-fetch node data

3 of 336 new or added lines in 3 files covered. (0.89%)

116 existing lines in 20 files now uncovered.

135509 of 202030 relevant lines covered (67.07%)

21670.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sqldb/sqlc/graph.sql.go
1
// Code generated by sqlc. DO NOT EDIT.
2
// versions:
3
//   sqlc v1.29.0
4
// source: graph.sql
5

6
package sqlc
7

8
import (
9
        "context"
10
        "database/sql"
11
        "strings"
12
)
13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

314
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
315
SELECT
316
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
317
    n1.pub_key AS node1_pub_key,
318
    n2.pub_key AS node2_pub_key
319
FROM graph_channels c
320
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
321
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
322
WHERE c.scid = $1
323
  AND c.version = $2
324
`
325

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

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

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

372
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
373
SELECT
374
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
375

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

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

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

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

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

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

516
const getChannelBySCID = `-- name: GetChannelBySCID :one
517
SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM graph_channels
518
WHERE scid = $1 AND version = $2
519
`
520

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

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

547
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
548
SELECT
549
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
550
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
551
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
552

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

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

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

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

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

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

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

714
UNION ALL
715

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

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

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

763
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
764
SELECT id, version, channel_id, node_id, timelock, fee_ppm, base_fee_msat, min_htlc_msat, max_htlc_msat, last_update, disabled, inbound_base_fee_msat, inbound_fee_rate_milli_msat, message_flags, channel_flags, signature
765
FROM graph_channel_policies
766
WHERE channel_id = $1
767
  AND node_id = $2
768
  AND version = $3
769
`
770

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

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

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

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

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

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

856
const getChannelsByOutpoints = `-- name: GetChannelsByOutpoints :many
857
SELECT
858
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
859
    n1.pub_key AS node1_pubkey,
860
    n2.pub_key AS node2_pubkey
861
FROM graph_channels c
862
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
863
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
864
WHERE c.outpoint IN
865
    (/*SLICE:outpoints*/?)
866
`
867

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

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

923
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
924
SELECT
925
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
926
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
927
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
928

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

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

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

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

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

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

1107
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1108
SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
1109
    n1.pub_key AS node1_pub_key,
1110
    n2.pub_key AS node2_pub_key
1111
FROM graph_channels c
1112
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1113
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1114
WHERE scid >= $1
1115
  AND scid < $2
1116
`
1117

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

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

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

1168
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1169
SELECT
1170
    c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
1171
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1172
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1173

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

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

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

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

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

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

1353
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1354
SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM graph_channels
1355
WHERE version = $1
1356
  AND scid IN (/*SLICE:scids*/?)
1357
`
1358

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

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

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

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

1441
const getNodeAddresses = `-- name: GetNodeAddresses :many
1442
SELECT type, address
1443
FROM graph_node_addresses
1444
WHERE node_id = $1
1445
ORDER BY type ASC, position ASC
1446
`
1447

1448
type GetNodeAddressesRow struct {
1449
        Type    int16
1450
        Address string
1451
}
1452

1453
func (q *Queries) GetNodeAddresses(ctx context.Context, nodeID int64) ([]GetNodeAddressesRow, error) {
×
1454
        rows, err := q.db.QueryContext(ctx, getNodeAddresses, nodeID)
×
1455
        if err != nil {
×
1456
                return nil, err
×
1457
        }
×
1458
        defer rows.Close()
×
1459
        var items []GetNodeAddressesRow
×
1460
        for rows.Next() {
×
1461
                var i GetNodeAddressesRow
×
1462
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1463
                        return nil, err
×
1464
                }
×
1465
                items = append(items, i)
×
1466
        }
1467
        if err := rows.Close(); err != nil {
×
1468
                return nil, err
×
1469
        }
×
1470
        if err := rows.Err(); err != nil {
×
1471
                return nil, err
×
1472
        }
×
1473
        return items, nil
×
1474
}
1475

1476
const getNodeAddressesBatch = `-- name: GetNodeAddressesBatch :many
1477
SELECT node_id, type, position, address
1478
FROM graph_node_addresses
1479
WHERE node_id IN (/*SLICE:ids*/?)
1480
ORDER BY node_id, type, position
1481
`
1482

NEW
1483
func (q *Queries) GetNodeAddressesBatch(ctx context.Context, ids []int64) ([]GraphNodeAddress, error) {
×
NEW
1484
        query := getNodeAddressesBatch
×
NEW
1485
        var queryParams []interface{}
×
NEW
1486
        if len(ids) > 0 {
×
NEW
1487
                for _, v := range ids {
×
NEW
1488
                        queryParams = append(queryParams, v)
×
NEW
1489
                }
×
NEW
1490
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
NEW
1491
        } else {
×
NEW
1492
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
NEW
1493
        }
×
NEW
1494
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
1495
        if err != nil {
×
NEW
1496
                return nil, err
×
NEW
1497
        }
×
NEW
1498
        defer rows.Close()
×
NEW
1499
        var items []GraphNodeAddress
×
NEW
1500
        for rows.Next() {
×
NEW
1501
                var i GraphNodeAddress
×
NEW
1502
                if err := rows.Scan(
×
NEW
1503
                        &i.NodeID,
×
NEW
1504
                        &i.Type,
×
NEW
1505
                        &i.Position,
×
NEW
1506
                        &i.Address,
×
NEW
1507
                ); err != nil {
×
NEW
1508
                        return nil, err
×
NEW
1509
                }
×
NEW
1510
                items = append(items, i)
×
1511
        }
NEW
1512
        if err := rows.Close(); err != nil {
×
NEW
1513
                return nil, err
×
NEW
1514
        }
×
NEW
1515
        if err := rows.Err(); err != nil {
×
NEW
1516
                return nil, err
×
NEW
1517
        }
×
NEW
1518
        return items, nil
×
1519
}
1520

1521
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1522
SELECT id, version, pub_key, alias, last_update, color, signature
1523
FROM graph_nodes
1524
WHERE pub_key = $1
1525
  AND version = $2
1526
`
1527

1528
type GetNodeByPubKeyParams struct {
1529
        PubKey  []byte
1530
        Version int16
1531
}
1532

1533
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1534
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1535
        var i GraphNode
×
1536
        err := row.Scan(
×
1537
                &i.ID,
×
1538
                &i.Version,
×
1539
                &i.PubKey,
×
1540
                &i.Alias,
×
1541
                &i.LastUpdate,
×
1542
                &i.Color,
×
1543
                &i.Signature,
×
1544
        )
×
1545
        return i, err
×
1546
}
×
1547

1548
const getNodeExtraTypesBatch = `-- name: GetNodeExtraTypesBatch :many
1549
SELECT node_id, type, value
1550
FROM graph_node_extra_types
1551
WHERE node_id IN (/*SLICE:ids*/?)
1552
ORDER BY node_id, type
1553
`
1554

NEW
1555
func (q *Queries) GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]GraphNodeExtraType, error) {
×
NEW
1556
        query := getNodeExtraTypesBatch
×
NEW
1557
        var queryParams []interface{}
×
NEW
1558
        if len(ids) > 0 {
×
NEW
1559
                for _, v := range ids {
×
NEW
1560
                        queryParams = append(queryParams, v)
×
NEW
1561
                }
×
NEW
1562
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
NEW
1563
        } else {
×
NEW
1564
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
NEW
1565
        }
×
NEW
1566
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
1567
        if err != nil {
×
NEW
1568
                return nil, err
×
NEW
1569
        }
×
NEW
1570
        defer rows.Close()
×
NEW
1571
        var items []GraphNodeExtraType
×
NEW
1572
        for rows.Next() {
×
NEW
1573
                var i GraphNodeExtraType
×
NEW
1574
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
NEW
1575
                        return nil, err
×
NEW
1576
                }
×
NEW
1577
                items = append(items, i)
×
1578
        }
NEW
1579
        if err := rows.Close(); err != nil {
×
NEW
1580
                return nil, err
×
NEW
1581
        }
×
NEW
1582
        if err := rows.Err(); err != nil {
×
NEW
1583
                return nil, err
×
NEW
1584
        }
×
NEW
1585
        return items, nil
×
1586
}
1587

1588
const getNodeFeatures = `-- name: GetNodeFeatures :many
1589
SELECT node_id, feature_bit
1590
FROM graph_node_features
1591
WHERE node_id = $1
1592
`
1593

1594
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1595
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1596
        if err != nil {
×
1597
                return nil, err
×
1598
        }
×
1599
        defer rows.Close()
×
1600
        var items []GraphNodeFeature
×
1601
        for rows.Next() {
×
1602
                var i GraphNodeFeature
×
1603
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1604
                        return nil, err
×
1605
                }
×
1606
                items = append(items, i)
×
1607
        }
1608
        if err := rows.Close(); err != nil {
×
1609
                return nil, err
×
1610
        }
×
1611
        if err := rows.Err(); err != nil {
×
1612
                return nil, err
×
1613
        }
×
1614
        return items, nil
×
1615
}
1616

1617
const getNodeFeaturesBatch = `-- name: GetNodeFeaturesBatch :many
1618
SELECT node_id, feature_bit
1619
FROM graph_node_features
1620
WHERE node_id IN (/*SLICE:ids*/?)
1621
ORDER BY node_id, feature_bit
1622
`
1623

NEW
1624
func (q *Queries) GetNodeFeaturesBatch(ctx context.Context, ids []int64) ([]GraphNodeFeature, error) {
×
NEW
1625
        query := getNodeFeaturesBatch
×
NEW
1626
        var queryParams []interface{}
×
NEW
1627
        if len(ids) > 0 {
×
NEW
1628
                for _, v := range ids {
×
NEW
1629
                        queryParams = append(queryParams, v)
×
NEW
1630
                }
×
NEW
1631
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
NEW
1632
        } else {
×
NEW
1633
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
NEW
1634
        }
×
NEW
1635
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
1636
        if err != nil {
×
NEW
1637
                return nil, err
×
NEW
1638
        }
×
NEW
1639
        defer rows.Close()
×
NEW
1640
        var items []GraphNodeFeature
×
NEW
1641
        for rows.Next() {
×
NEW
1642
                var i GraphNodeFeature
×
NEW
1643
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
NEW
1644
                        return nil, err
×
NEW
1645
                }
×
NEW
1646
                items = append(items, i)
×
1647
        }
NEW
1648
        if err := rows.Close(); err != nil {
×
NEW
1649
                return nil, err
×
NEW
1650
        }
×
NEW
1651
        if err := rows.Err(); err != nil {
×
NEW
1652
                return nil, err
×
NEW
1653
        }
×
NEW
1654
        return items, nil
×
1655
}
1656

1657
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1658
SELECT f.feature_bit
1659
FROM graph_nodes n
1660
    JOIN graph_node_features f ON f.node_id = n.id
1661
WHERE n.pub_key = $1
1662
  AND n.version = $2
1663
`
1664

1665
type GetNodeFeaturesByPubKeyParams struct {
1666
        PubKey  []byte
1667
        Version int16
1668
}
1669

1670
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1671
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1672
        if err != nil {
×
1673
                return nil, err
×
1674
        }
×
1675
        defer rows.Close()
×
1676
        var items []int32
×
1677
        for rows.Next() {
×
1678
                var feature_bit int32
×
1679
                if err := rows.Scan(&feature_bit); err != nil {
×
1680
                        return nil, err
×
1681
                }
×
1682
                items = append(items, feature_bit)
×
1683
        }
1684
        if err := rows.Close(); err != nil {
×
1685
                return nil, err
×
1686
        }
×
1687
        if err := rows.Err(); err != nil {
×
1688
                return nil, err
×
1689
        }
×
1690
        return items, nil
×
1691
}
1692

1693
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1694
SELECT id
1695
FROM graph_nodes
1696
WHERE pub_key = $1
1697
  AND version = $2
1698
`
1699

1700
type GetNodeIDByPubKeyParams struct {
1701
        PubKey  []byte
1702
        Version int16
1703
}
1704

1705
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1706
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1707
        var id int64
×
1708
        err := row.Scan(&id)
×
1709
        return id, err
×
1710
}
×
1711

1712
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1713
SELECT id, version, pub_key, alias, last_update, color, signature
1714
FROM graph_nodes
1715
WHERE last_update >= $1
1716
  AND last_update < $2
1717
`
1718

1719
type GetNodesByLastUpdateRangeParams struct {
1720
        StartTime sql.NullInt64
1721
        EndTime   sql.NullInt64
1722
}
1723

1724
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
1725
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1726
        if err != nil {
×
1727
                return nil, err
×
1728
        }
×
1729
        defer rows.Close()
×
1730
        var items []GraphNode
×
1731
        for rows.Next() {
×
1732
                var i GraphNode
×
1733
                if err := rows.Scan(
×
1734
                        &i.ID,
×
1735
                        &i.Version,
×
1736
                        &i.PubKey,
×
1737
                        &i.Alias,
×
1738
                        &i.LastUpdate,
×
1739
                        &i.Color,
×
1740
                        &i.Signature,
×
1741
                ); err != nil {
×
1742
                        return nil, err
×
1743
                }
×
1744
                items = append(items, i)
×
1745
        }
1746
        if err := rows.Close(); err != nil {
×
1747
                return nil, err
×
1748
        }
×
1749
        if err := rows.Err(); err != nil {
×
1750
                return nil, err
×
1751
        }
×
1752
        return items, nil
×
1753
}
1754

1755
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
1756
SELECT block_hash
1757
FROM graph_prune_log
1758
WHERE block_height = $1
1759
`
1760

1761
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
1762
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
1763
        var block_hash []byte
×
1764
        err := row.Scan(&block_hash)
×
1765
        return block_hash, err
×
1766
}
×
1767

1768
const getPruneTip = `-- name: GetPruneTip :one
1769
SELECT block_height, block_hash
1770
FROM graph_prune_log
1771
ORDER BY block_height DESC
1772
LIMIT 1
1773
`
1774

1775
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
1776
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1777
        var i GraphPruneLog
×
1778
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1779
        return i, err
×
1780
}
×
1781

1782
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1783
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
1784
FROM graph_channels
1785
WHERE node_1_signature IS NOT NULL
1786
  AND scid >= $1
1787
  AND scid < $2
1788
`
1789

1790
type GetPublicV1ChannelsBySCIDParams struct {
1791
        StartScid []byte
1792
        EndScid   []byte
1793
}
1794

1795
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
1796
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1797
        if err != nil {
×
1798
                return nil, err
×
1799
        }
×
1800
        defer rows.Close()
×
1801
        var items []GraphChannel
×
1802
        for rows.Next() {
×
1803
                var i GraphChannel
×
1804
                if err := rows.Scan(
×
1805
                        &i.ID,
×
1806
                        &i.Version,
×
1807
                        &i.Scid,
×
1808
                        &i.NodeID1,
×
1809
                        &i.NodeID2,
×
1810
                        &i.Outpoint,
×
1811
                        &i.Capacity,
×
1812
                        &i.BitcoinKey1,
×
1813
                        &i.BitcoinKey2,
×
1814
                        &i.Node1Signature,
×
1815
                        &i.Node2Signature,
×
1816
                        &i.Bitcoin1Signature,
×
1817
                        &i.Bitcoin2Signature,
×
1818
                ); err != nil {
×
1819
                        return nil, err
×
1820
                }
×
1821
                items = append(items, i)
×
1822
        }
1823
        if err := rows.Close(); err != nil {
×
1824
                return nil, err
×
1825
        }
×
1826
        if err := rows.Err(); err != nil {
×
1827
                return nil, err
×
1828
        }
×
1829
        return items, nil
×
1830
}
1831

1832
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1833
SELECT scid from graph_channels
1834
WHERE outpoint = $1 AND version = $2
1835
`
1836

1837
type GetSCIDByOutpointParams struct {
1838
        Outpoint string
1839
        Version  int16
1840
}
1841

1842
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1843
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1844
        var scid []byte
×
1845
        err := row.Scan(&scid)
×
1846
        return scid, err
×
1847
}
×
1848

1849
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1850
SELECT sn.node_id, n.pub_key
1851
FROM graph_source_nodes sn
1852
    JOIN graph_nodes n ON sn.node_id = n.id
1853
WHERE n.version = $1
1854
`
1855

1856
type GetSourceNodesByVersionRow struct {
1857
        NodeID int64
1858
        PubKey []byte
1859
}
1860

1861
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1862
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1863
        if err != nil {
×
1864
                return nil, err
×
1865
        }
×
1866
        defer rows.Close()
×
1867
        var items []GetSourceNodesByVersionRow
×
1868
        for rows.Next() {
×
1869
                var i GetSourceNodesByVersionRow
×
1870
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1871
                        return nil, err
×
1872
                }
×
1873
                items = append(items, i)
×
1874
        }
1875
        if err := rows.Close(); err != nil {
×
1876
                return nil, err
×
1877
        }
×
1878
        if err := rows.Err(); err != nil {
×
1879
                return nil, err
×
1880
        }
×
1881
        return items, nil
×
1882
}
1883

1884
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1885
SELECT c.scid
1886
FROM graph_channels c
1887
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
1888
WHERE cp.disabled = true
1889
AND c.version = 1
1890
GROUP BY c.scid
1891
HAVING COUNT(*) > 1
1892
`
1893

1894
// NOTE: this is V1 specific since for V1, disabled is a
1895
// simple, single boolean. The proposed V2 policy
1896
// structure will have a more complex disabled bit vector
1897
// and so the query for V2 may differ.
1898
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1899
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1900
        if err != nil {
×
1901
                return nil, err
×
1902
        }
×
1903
        defer rows.Close()
×
1904
        var items [][]byte
×
1905
        for rows.Next() {
×
1906
                var scid []byte
×
1907
                if err := rows.Scan(&scid); err != nil {
×
1908
                        return nil, err
×
1909
                }
×
1910
                items = append(items, scid)
×
1911
        }
1912
        if err := rows.Close(); err != nil {
×
1913
                return nil, err
×
1914
        }
×
1915
        if err := rows.Err(); err != nil {
×
1916
                return nil, err
×
1917
        }
×
1918
        return items, nil
×
1919
}
1920

1921
const getZombieChannel = `-- name: GetZombieChannel :one
1922
SELECT scid, version, node_key_1, node_key_2
1923
FROM graph_zombie_channels
1924
WHERE scid = $1
1925
AND version = $2
1926
`
1927

1928
type GetZombieChannelParams struct {
1929
        Scid    []byte
1930
        Version int16
1931
}
1932

1933
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
1934
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1935
        var i GraphZombieChannel
×
1936
        err := row.Scan(
×
1937
                &i.Scid,
×
1938
                &i.Version,
×
1939
                &i.NodeKey1,
×
1940
                &i.NodeKey2,
×
1941
        )
×
1942
        return i, err
×
1943
}
×
1944

1945
const highestSCID = `-- name: HighestSCID :one
1946
SELECT scid
1947
FROM graph_channels
1948
WHERE version = $1
1949
ORDER BY scid DESC
1950
LIMIT 1
1951
`
1952

1953
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1954
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1955
        var scid []byte
×
1956
        err := row.Scan(&scid)
×
1957
        return scid, err
×
1958
}
×
1959

1960
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1961
/* ─────────────────────────────────────────────
1962
   graph_channel_policy_extra_types table queries
1963
   ─────────────────────────────────────────────
1964
*/
1965

1966
INSERT INTO graph_channel_policy_extra_types (
1967
    channel_policy_id, type, value
1968
)
1969
VALUES ($1, $2, $3)
1970
`
1971

1972
type InsertChanPolicyExtraTypeParams struct {
1973
        ChannelPolicyID int64
1974
        Type            int64
1975
        Value           []byte
1976
}
1977

1978
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1979
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1980
        return err
×
1981
}
×
1982

1983
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1984
/* ─────────────────────────────────────────────
1985
   graph_channel_features table queries
1986
   ─────────────────────────────────────────────
1987
*/
1988

1989
INSERT INTO graph_channel_features (
1990
    channel_id, feature_bit
1991
) VALUES (
1992
    $1, $2
1993
)
1994
`
1995

1996
type InsertChannelFeatureParams struct {
1997
        ChannelID  int64
1998
        FeatureBit int32
1999
}
2000

2001
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2002
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2003
        return err
×
2004
}
×
2005

2006
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2007
/* ─────────────────────────────────────────────
2008
   graph_closed_scid table queries
2009
   ────────────────────────────────────────────-
2010
*/
2011

2012
INSERT INTO graph_closed_scids (scid)
2013
VALUES ($1)
2014
ON CONFLICT (scid) DO NOTHING
2015
`
2016

2017
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2018
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2019
        return err
×
2020
}
×
2021

2022
const insertNodeAddress = `-- name: InsertNodeAddress :exec
2023
/* ─────────────────────────────────────────────
2024
   graph_node_addresses table queries
2025
   ───────────────────────────────────��─────────
2026
*/
2027

2028
INSERT INTO graph_node_addresses (
2029
    node_id,
2030
    type,
2031
    address,
2032
    position
2033
) VALUES (
2034
    $1, $2, $3, $4
2035
 )
2036
`
2037

2038
type InsertNodeAddressParams struct {
2039
        NodeID   int64
2040
        Type     int16
2041
        Address  string
2042
        Position int32
2043
}
2044

2045
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
2046
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
2047
                arg.NodeID,
×
2048
                arg.Type,
×
2049
                arg.Address,
×
2050
                arg.Position,
×
2051
        )
×
2052
        return err
×
2053
}
×
2054

2055
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2056
/* ─────────────────────────────────────────────
2057
   graph_node_features table queries
2058
   ─────────────────────────────────────────────
2059
*/
2060

2061
INSERT INTO graph_node_features (
2062
    node_id, feature_bit
2063
) VALUES (
2064
    $1, $2
2065
)
2066
`
2067

2068
type InsertNodeFeatureParams struct {
2069
        NodeID     int64
2070
        FeatureBit int32
2071
}
2072

2073
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2074
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2075
        return err
×
2076
}
×
2077

2078
const isClosedChannel = `-- name: IsClosedChannel :one
2079
SELECT EXISTS (
2080
    SELECT 1
2081
    FROM graph_closed_scids
2082
    WHERE scid = $1
2083
)
2084
`
2085

2086
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2087
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2088
        var exists bool
×
2089
        err := row.Scan(&exists)
×
2090
        return exists, err
×
2091
}
×
2092

2093
const isPublicV1Node = `-- name: IsPublicV1Node :one
2094
SELECT EXISTS (
2095
    SELECT 1
2096
    FROM graph_channels c
2097
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
2098
    -- NOTE: we hard-code the version here since the clauses
2099
    -- here that determine if a node is public is specific
2100
    -- to the V1 gossip protocol. In V1, a node is public
2101
    -- if it has a public channel and a public channel is one
2102
    -- where we have the set of signatures of the channel
2103
    -- announcement. It is enough to just check that we have
2104
    -- one of the signatures since we only ever set them
2105
    -- together.
2106
    WHERE c.version = 1
2107
      AND c.bitcoin_1_signature IS NOT NULL
2108
      AND n.pub_key = $1
2109
)
2110
`
2111

2112
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2113
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2114
        var exists bool
×
2115
        err := row.Scan(&exists)
×
2116
        return exists, err
×
2117
}
×
2118

2119
const isZombieChannel = `-- name: IsZombieChannel :one
2120
SELECT EXISTS (
2121
    SELECT 1
2122
    FROM graph_zombie_channels
2123
    WHERE scid = $1
2124
    AND version = $2
2125
) AS is_zombie
2126
`
2127

2128
type IsZombieChannelParams struct {
2129
        Scid    []byte
2130
        Version int16
2131
}
2132

2133
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2134
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2135
        var is_zombie bool
×
2136
        err := row.Scan(&is_zombie)
×
2137
        return is_zombie, err
×
2138
}
×
2139

2140
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2141
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,
2142
    n1.pub_key AS node1_pubkey,
2143
    n2.pub_key AS node2_pubkey,
2144

2145
    -- Policy 1
2146
    -- TODO(elle): use sqlc.embed to embed policy structs
2147
    --  once this issue is resolved:
2148
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2149
    cp1.id AS policy1_id,
2150
    cp1.node_id AS policy1_node_id,
2151
    cp1.version AS policy1_version,
2152
    cp1.timelock AS policy1_timelock,
2153
    cp1.fee_ppm AS policy1_fee_ppm,
2154
    cp1.base_fee_msat AS policy1_base_fee_msat,
2155
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2156
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2157
    cp1.last_update AS policy1_last_update,
2158
    cp1.disabled AS policy1_disabled,
2159
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2160
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2161
    cp1.message_flags AS policy1_message_flags,
2162
    cp1.channel_flags AS policy1_channel_flags,
2163
    cp1.signature AS policy1_signature,
2164

2165
       -- Policy 2
2166
    cp2.id AS policy2_id,
2167
    cp2.node_id AS policy2_node_id,
2168
    cp2.version AS policy2_version,
2169
    cp2.timelock AS policy2_timelock,
2170
    cp2.fee_ppm AS policy2_fee_ppm,
2171
    cp2.base_fee_msat AS policy2_base_fee_msat,
2172
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2173
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2174
    cp2.last_update AS policy2_last_update,
2175
    cp2.disabled AS policy2_disabled,
2176
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2177
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2178
    cp2.message_flags AS policy2_message_flags,
2179
    cp2.channel_flags AS policy2_channel_flags,
2180
    cp2.signature AS policy2_signature
2181

2182
FROM graph_channels c
2183
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2184
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2185
    LEFT JOIN graph_channel_policies cp1
2186
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2187
    LEFT JOIN graph_channel_policies cp2
2188
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2189
WHERE c.version = $1
2190
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2191
`
2192

2193
type ListChannelsByNodeIDParams struct {
2194
        Version int16
2195
        NodeID1 int64
2196
}
2197

2198
type ListChannelsByNodeIDRow struct {
2199
        GraphChannel                   GraphChannel
2200
        Node1Pubkey                    []byte
2201
        Node2Pubkey                    []byte
2202
        Policy1ID                      sql.NullInt64
2203
        Policy1NodeID                  sql.NullInt64
2204
        Policy1Version                 sql.NullInt16
2205
        Policy1Timelock                sql.NullInt32
2206
        Policy1FeePpm                  sql.NullInt64
2207
        Policy1BaseFeeMsat             sql.NullInt64
2208
        Policy1MinHtlcMsat             sql.NullInt64
2209
        Policy1MaxHtlcMsat             sql.NullInt64
2210
        Policy1LastUpdate              sql.NullInt64
2211
        Policy1Disabled                sql.NullBool
2212
        Policy1InboundBaseFeeMsat      sql.NullInt64
2213
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2214
        Policy1MessageFlags            sql.NullInt16
2215
        Policy1ChannelFlags            sql.NullInt16
2216
        Policy1Signature               []byte
2217
        Policy2ID                      sql.NullInt64
2218
        Policy2NodeID                  sql.NullInt64
2219
        Policy2Version                 sql.NullInt16
2220
        Policy2Timelock                sql.NullInt32
2221
        Policy2FeePpm                  sql.NullInt64
2222
        Policy2BaseFeeMsat             sql.NullInt64
2223
        Policy2MinHtlcMsat             sql.NullInt64
2224
        Policy2MaxHtlcMsat             sql.NullInt64
2225
        Policy2LastUpdate              sql.NullInt64
2226
        Policy2Disabled                sql.NullBool
2227
        Policy2InboundBaseFeeMsat      sql.NullInt64
2228
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2229
        Policy2MessageFlags            sql.NullInt16
2230
        Policy2ChannelFlags            sql.NullInt16
2231
        Policy2Signature               []byte
2232
}
2233

2234
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2235
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2236
        if err != nil {
×
2237
                return nil, err
×
2238
        }
×
2239
        defer rows.Close()
×
2240
        var items []ListChannelsByNodeIDRow
×
2241
        for rows.Next() {
×
2242
                var i ListChannelsByNodeIDRow
×
2243
                if err := rows.Scan(
×
2244
                        &i.GraphChannel.ID,
×
2245
                        &i.GraphChannel.Version,
×
2246
                        &i.GraphChannel.Scid,
×
2247
                        &i.GraphChannel.NodeID1,
×
2248
                        &i.GraphChannel.NodeID2,
×
2249
                        &i.GraphChannel.Outpoint,
×
2250
                        &i.GraphChannel.Capacity,
×
2251
                        &i.GraphChannel.BitcoinKey1,
×
2252
                        &i.GraphChannel.BitcoinKey2,
×
2253
                        &i.GraphChannel.Node1Signature,
×
2254
                        &i.GraphChannel.Node2Signature,
×
2255
                        &i.GraphChannel.Bitcoin1Signature,
×
2256
                        &i.GraphChannel.Bitcoin2Signature,
×
2257
                        &i.Node1Pubkey,
×
2258
                        &i.Node2Pubkey,
×
2259
                        &i.Policy1ID,
×
2260
                        &i.Policy1NodeID,
×
2261
                        &i.Policy1Version,
×
2262
                        &i.Policy1Timelock,
×
2263
                        &i.Policy1FeePpm,
×
2264
                        &i.Policy1BaseFeeMsat,
×
2265
                        &i.Policy1MinHtlcMsat,
×
2266
                        &i.Policy1MaxHtlcMsat,
×
2267
                        &i.Policy1LastUpdate,
×
2268
                        &i.Policy1Disabled,
×
2269
                        &i.Policy1InboundBaseFeeMsat,
×
2270
                        &i.Policy1InboundFeeRateMilliMsat,
×
2271
                        &i.Policy1MessageFlags,
×
2272
                        &i.Policy1ChannelFlags,
×
2273
                        &i.Policy1Signature,
×
2274
                        &i.Policy2ID,
×
2275
                        &i.Policy2NodeID,
×
2276
                        &i.Policy2Version,
×
2277
                        &i.Policy2Timelock,
×
2278
                        &i.Policy2FeePpm,
×
2279
                        &i.Policy2BaseFeeMsat,
×
2280
                        &i.Policy2MinHtlcMsat,
×
2281
                        &i.Policy2MaxHtlcMsat,
×
2282
                        &i.Policy2LastUpdate,
×
2283
                        &i.Policy2Disabled,
×
2284
                        &i.Policy2InboundBaseFeeMsat,
×
2285
                        &i.Policy2InboundFeeRateMilliMsat,
×
2286
                        &i.Policy2MessageFlags,
×
2287
                        &i.Policy2ChannelFlags,
×
2288
                        &i.Policy2Signature,
×
2289
                ); err != nil {
×
2290
                        return nil, err
×
2291
                }
×
2292
                items = append(items, i)
×
2293
        }
2294
        if err := rows.Close(); err != nil {
×
2295
                return nil, err
×
2296
        }
×
2297
        if err := rows.Err(); err != nil {
×
2298
                return nil, err
×
2299
        }
×
2300
        return items, nil
×
2301
}
2302

2303
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
2304
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
2305
FROM graph_channels c
2306
WHERE c.version = $1 AND c.id > $2
2307
ORDER BY c.id
2308
LIMIT $3
2309
`
2310

2311
type ListChannelsPaginatedParams struct {
2312
        Version int16
2313
        ID      int64
2314
        Limit   int32
2315
}
2316

2317
type ListChannelsPaginatedRow struct {
2318
        ID          int64
2319
        BitcoinKey1 []byte
2320
        BitcoinKey2 []byte
2321
        Outpoint    string
2322
}
2323

2324
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
2325
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
2326
        if err != nil {
×
2327
                return nil, err
×
2328
        }
×
2329
        defer rows.Close()
×
2330
        var items []ListChannelsPaginatedRow
×
2331
        for rows.Next() {
×
2332
                var i ListChannelsPaginatedRow
×
2333
                if err := rows.Scan(
×
2334
                        &i.ID,
×
2335
                        &i.BitcoinKey1,
×
2336
                        &i.BitcoinKey2,
×
2337
                        &i.Outpoint,
×
2338
                ); err != nil {
×
2339
                        return nil, err
×
2340
                }
×
2341
                items = append(items, i)
×
2342
        }
2343
        if err := rows.Close(); err != nil {
×
2344
                return nil, err
×
2345
        }
×
2346
        if err := rows.Err(); err != nil {
×
2347
                return nil, err
×
2348
        }
×
2349
        return items, nil
×
2350
}
2351

2352
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
2353
SELECT
2354
    c.id as id,
2355
    c.scid as scid,
2356
    c.capacity AS capacity,
2357

2358
    -- Join node pubkeys
2359
    n1.pub_key AS node1_pubkey,
2360
    n2.pub_key AS node2_pubkey,
2361

2362
    -- Node 1 policy
2363
    cp1.timelock AS policy_1_timelock,
2364
    cp1.fee_ppm AS policy_1_fee_ppm,
2365
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2366
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2367
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2368
    cp1.disabled AS policy_1_disabled,
2369
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2370
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2371
    cp1.message_flags AS policy1_message_flags,
2372
    cp1.channel_flags AS policy1_channel_flags,
2373

2374
    -- Node 2 policy
2375
    cp2.timelock AS policy_2_timelock,
2376
    cp2.fee_ppm AS policy_2_fee_ppm,
2377
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2378
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2379
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2380
    cp2.disabled AS policy_2_disabled,
2381
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2382
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2383
    cp2.message_flags AS policy2_message_flags,
2384
    cp2.channel_flags AS policy2_channel_flags
2385

2386
FROM graph_channels c
2387
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2388
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2389
LEFT JOIN graph_channel_policies cp1
2390
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2391
LEFT JOIN graph_channel_policies cp2
2392
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2393
WHERE c.version = $1 AND c.id > $2
2394
ORDER BY c.id
2395
LIMIT $3
2396
`
2397

2398
type ListChannelsWithPoliciesForCachePaginatedParams struct {
2399
        Version int16
2400
        ID      int64
2401
        Limit   int32
2402
}
2403

2404
type ListChannelsWithPoliciesForCachePaginatedRow struct {
2405
        ID                             int64
2406
        Scid                           []byte
2407
        Capacity                       sql.NullInt64
2408
        Node1Pubkey                    []byte
2409
        Node2Pubkey                    []byte
2410
        Policy1Timelock                sql.NullInt32
2411
        Policy1FeePpm                  sql.NullInt64
2412
        Policy1BaseFeeMsat             sql.NullInt64
2413
        Policy1MinHtlcMsat             sql.NullInt64
2414
        Policy1MaxHtlcMsat             sql.NullInt64
2415
        Policy1Disabled                sql.NullBool
2416
        Policy1InboundBaseFeeMsat      sql.NullInt64
2417
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2418
        Policy1MessageFlags            sql.NullInt16
2419
        Policy1ChannelFlags            sql.NullInt16
2420
        Policy2Timelock                sql.NullInt32
2421
        Policy2FeePpm                  sql.NullInt64
2422
        Policy2BaseFeeMsat             sql.NullInt64
2423
        Policy2MinHtlcMsat             sql.NullInt64
2424
        Policy2MaxHtlcMsat             sql.NullInt64
2425
        Policy2Disabled                sql.NullBool
2426
        Policy2InboundBaseFeeMsat      sql.NullInt64
2427
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2428
        Policy2MessageFlags            sql.NullInt16
2429
        Policy2ChannelFlags            sql.NullInt16
2430
}
2431

2432
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
2433
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
2434
        if err != nil {
×
2435
                return nil, err
×
2436
        }
×
2437
        defer rows.Close()
×
2438
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
2439
        for rows.Next() {
×
2440
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
2441
                if err := rows.Scan(
×
2442
                        &i.ID,
×
2443
                        &i.Scid,
×
2444
                        &i.Capacity,
×
2445
                        &i.Node1Pubkey,
×
2446
                        &i.Node2Pubkey,
×
2447
                        &i.Policy1Timelock,
×
2448
                        &i.Policy1FeePpm,
×
2449
                        &i.Policy1BaseFeeMsat,
×
2450
                        &i.Policy1MinHtlcMsat,
×
2451
                        &i.Policy1MaxHtlcMsat,
×
2452
                        &i.Policy1Disabled,
×
2453
                        &i.Policy1InboundBaseFeeMsat,
×
2454
                        &i.Policy1InboundFeeRateMilliMsat,
×
2455
                        &i.Policy1MessageFlags,
×
2456
                        &i.Policy1ChannelFlags,
×
2457
                        &i.Policy2Timelock,
×
2458
                        &i.Policy2FeePpm,
×
2459
                        &i.Policy2BaseFeeMsat,
×
2460
                        &i.Policy2MinHtlcMsat,
×
2461
                        &i.Policy2MaxHtlcMsat,
×
2462
                        &i.Policy2Disabled,
×
2463
                        &i.Policy2InboundBaseFeeMsat,
×
2464
                        &i.Policy2InboundFeeRateMilliMsat,
×
2465
                        &i.Policy2MessageFlags,
×
2466
                        &i.Policy2ChannelFlags,
×
2467
                ); err != nil {
×
2468
                        return nil, err
×
2469
                }
×
2470
                items = append(items, i)
×
2471
        }
2472
        if err := rows.Close(); err != nil {
×
2473
                return nil, err
×
2474
        }
×
2475
        if err := rows.Err(); err != nil {
×
2476
                return nil, err
×
2477
        }
×
2478
        return items, nil
×
2479
}
2480

2481
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
2482
SELECT
2483
    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,
2484

2485
    -- Join node pubkeys
2486
    n1.pub_key AS node1_pubkey,
2487
    n2.pub_key AS node2_pubkey,
2488

2489
    -- Node 1 policy
2490
    cp1.id AS policy_1_id,
2491
    cp1.node_id AS policy_1_node_id,
2492
    cp1.version AS policy_1_version,
2493
    cp1.timelock AS policy_1_timelock,
2494
    cp1.fee_ppm AS policy_1_fee_ppm,
2495
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2496
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2497
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2498
    cp1.last_update AS policy_1_last_update,
2499
    cp1.disabled AS policy_1_disabled,
2500
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2501
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2502
    cp1.message_flags AS policy1_message_flags,
2503
    cp1.channel_flags AS policy1_channel_flags,
2504
    cp1.signature AS policy_1_signature,
2505

2506
    -- Node 2 policy
2507
    cp2.id AS policy_2_id,
2508
    cp2.node_id AS policy_2_node_id,
2509
    cp2.version AS policy_2_version,
2510
    cp2.timelock AS policy_2_timelock,
2511
    cp2.fee_ppm AS policy_2_fee_ppm,
2512
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2513
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2514
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2515
    cp2.last_update AS policy_2_last_update,
2516
    cp2.disabled AS policy_2_disabled,
2517
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2518
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2519
    cp2.message_flags AS policy2_message_flags,
2520
    cp2.channel_flags AS policy2_channel_flags,
2521
    cp2.signature AS policy_2_signature
2522

2523
FROM graph_channels c
2524
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2525
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2526
LEFT JOIN graph_channel_policies cp1
2527
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2528
LEFT JOIN graph_channel_policies cp2
2529
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2530
WHERE c.version = $1 AND c.id > $2
2531
ORDER BY c.id
2532
LIMIT $3
2533
`
2534

2535
type ListChannelsWithPoliciesPaginatedParams struct {
2536
        Version int16
2537
        ID      int64
2538
        Limit   int32
2539
}
2540

2541
type ListChannelsWithPoliciesPaginatedRow struct {
2542
        GraphChannel                   GraphChannel
2543
        Node1Pubkey                    []byte
2544
        Node2Pubkey                    []byte
2545
        Policy1ID                      sql.NullInt64
2546
        Policy1NodeID                  sql.NullInt64
2547
        Policy1Version                 sql.NullInt16
2548
        Policy1Timelock                sql.NullInt32
2549
        Policy1FeePpm                  sql.NullInt64
2550
        Policy1BaseFeeMsat             sql.NullInt64
2551
        Policy1MinHtlcMsat             sql.NullInt64
2552
        Policy1MaxHtlcMsat             sql.NullInt64
2553
        Policy1LastUpdate              sql.NullInt64
2554
        Policy1Disabled                sql.NullBool
2555
        Policy1InboundBaseFeeMsat      sql.NullInt64
2556
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2557
        Policy1MessageFlags            sql.NullInt16
2558
        Policy1ChannelFlags            sql.NullInt16
2559
        Policy1Signature               []byte
2560
        Policy2ID                      sql.NullInt64
2561
        Policy2NodeID                  sql.NullInt64
2562
        Policy2Version                 sql.NullInt16
2563
        Policy2Timelock                sql.NullInt32
2564
        Policy2FeePpm                  sql.NullInt64
2565
        Policy2BaseFeeMsat             sql.NullInt64
2566
        Policy2MinHtlcMsat             sql.NullInt64
2567
        Policy2MaxHtlcMsat             sql.NullInt64
2568
        Policy2LastUpdate              sql.NullInt64
2569
        Policy2Disabled                sql.NullBool
2570
        Policy2InboundBaseFeeMsat      sql.NullInt64
2571
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2572
        Policy2MessageFlags            sql.NullInt16
2573
        Policy2ChannelFlags            sql.NullInt16
2574
        Policy2Signature               []byte
2575
}
2576

2577
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
2578
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
2579
        if err != nil {
×
2580
                return nil, err
×
2581
        }
×
2582
        defer rows.Close()
×
2583
        var items []ListChannelsWithPoliciesPaginatedRow
×
2584
        for rows.Next() {
×
2585
                var i ListChannelsWithPoliciesPaginatedRow
×
2586
                if err := rows.Scan(
×
2587
                        &i.GraphChannel.ID,
×
2588
                        &i.GraphChannel.Version,
×
2589
                        &i.GraphChannel.Scid,
×
2590
                        &i.GraphChannel.NodeID1,
×
2591
                        &i.GraphChannel.NodeID2,
×
2592
                        &i.GraphChannel.Outpoint,
×
2593
                        &i.GraphChannel.Capacity,
×
2594
                        &i.GraphChannel.BitcoinKey1,
×
2595
                        &i.GraphChannel.BitcoinKey2,
×
2596
                        &i.GraphChannel.Node1Signature,
×
2597
                        &i.GraphChannel.Node2Signature,
×
2598
                        &i.GraphChannel.Bitcoin1Signature,
×
2599
                        &i.GraphChannel.Bitcoin2Signature,
×
2600
                        &i.Node1Pubkey,
×
2601
                        &i.Node2Pubkey,
×
2602
                        &i.Policy1ID,
×
2603
                        &i.Policy1NodeID,
×
2604
                        &i.Policy1Version,
×
2605
                        &i.Policy1Timelock,
×
2606
                        &i.Policy1FeePpm,
×
2607
                        &i.Policy1BaseFeeMsat,
×
2608
                        &i.Policy1MinHtlcMsat,
×
2609
                        &i.Policy1MaxHtlcMsat,
×
2610
                        &i.Policy1LastUpdate,
×
2611
                        &i.Policy1Disabled,
×
2612
                        &i.Policy1InboundBaseFeeMsat,
×
2613
                        &i.Policy1InboundFeeRateMilliMsat,
×
2614
                        &i.Policy1MessageFlags,
×
2615
                        &i.Policy1ChannelFlags,
×
2616
                        &i.Policy1Signature,
×
2617
                        &i.Policy2ID,
×
2618
                        &i.Policy2NodeID,
×
2619
                        &i.Policy2Version,
×
2620
                        &i.Policy2Timelock,
×
2621
                        &i.Policy2FeePpm,
×
2622
                        &i.Policy2BaseFeeMsat,
×
2623
                        &i.Policy2MinHtlcMsat,
×
2624
                        &i.Policy2MaxHtlcMsat,
×
2625
                        &i.Policy2LastUpdate,
×
2626
                        &i.Policy2Disabled,
×
2627
                        &i.Policy2InboundBaseFeeMsat,
×
2628
                        &i.Policy2InboundFeeRateMilliMsat,
×
2629
                        &i.Policy2MessageFlags,
×
2630
                        &i.Policy2ChannelFlags,
×
2631
                        &i.Policy2Signature,
×
2632
                ); err != nil {
×
2633
                        return nil, err
×
2634
                }
×
2635
                items = append(items, i)
×
2636
        }
2637
        if err := rows.Close(); err != nil {
×
2638
                return nil, err
×
2639
        }
×
2640
        if err := rows.Err(); err != nil {
×
2641
                return nil, err
×
2642
        }
×
2643
        return items, nil
×
2644
}
2645

2646
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2647
SELECT id, pub_key
2648
FROM graph_nodes
2649
WHERE version = $1  AND id > $2
2650
ORDER BY id
2651
LIMIT $3
2652
`
2653

2654
type ListNodeIDsAndPubKeysParams struct {
2655
        Version int16
2656
        ID      int64
2657
        Limit   int32
2658
}
2659

2660
type ListNodeIDsAndPubKeysRow struct {
2661
        ID     int64
2662
        PubKey []byte
2663
}
2664

2665
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2666
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2667
        if err != nil {
×
2668
                return nil, err
×
2669
        }
×
2670
        defer rows.Close()
×
2671
        var items []ListNodeIDsAndPubKeysRow
×
2672
        for rows.Next() {
×
2673
                var i ListNodeIDsAndPubKeysRow
×
2674
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2675
                        return nil, err
×
2676
                }
×
2677
                items = append(items, i)
×
2678
        }
2679
        if err := rows.Close(); err != nil {
×
2680
                return nil, err
×
2681
        }
×
2682
        if err := rows.Err(); err != nil {
×
2683
                return nil, err
×
2684
        }
×
2685
        return items, nil
×
2686
}
2687

2688
const listNodesPaginated = `-- name: ListNodesPaginated :many
2689
SELECT id, version, pub_key, alias, last_update, color, signature
2690
FROM graph_nodes
2691
WHERE version = $1 AND id > $2
2692
ORDER BY id
2693
LIMIT $3
2694
`
2695

2696
type ListNodesPaginatedParams struct {
2697
        Version int16
2698
        ID      int64
2699
        Limit   int32
2700
}
2701

2702
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
2703
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2704
        if err != nil {
×
2705
                return nil, err
×
2706
        }
×
2707
        defer rows.Close()
×
2708
        var items []GraphNode
×
2709
        for rows.Next() {
×
2710
                var i GraphNode
×
2711
                if err := rows.Scan(
×
2712
                        &i.ID,
×
2713
                        &i.Version,
×
2714
                        &i.PubKey,
×
2715
                        &i.Alias,
×
2716
                        &i.LastUpdate,
×
2717
                        &i.Color,
×
2718
                        &i.Signature,
×
2719
                ); err != nil {
×
2720
                        return nil, err
×
2721
                }
×
2722
                items = append(items, i)
×
2723
        }
2724
        if err := rows.Close(); err != nil {
×
2725
                return nil, err
×
2726
        }
×
2727
        if err := rows.Err(); err != nil {
×
2728
                return nil, err
×
2729
        }
×
2730
        return items, nil
×
2731
}
2732

2733
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2734
/* ─────────────────────────────────────────────
2735
   graph_channel_policies table queries
2736
   ─────────────────────────────────────────────
2737
*/
2738

2739
INSERT INTO graph_channel_policies (
2740
    version, channel_id, node_id, timelock, fee_ppm,
2741
    base_fee_msat, min_htlc_msat, last_update, disabled,
2742
    max_htlc_msat, inbound_base_fee_msat,
2743
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2744
    signature
2745
) VALUES  (
2746
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2747
)
2748
ON CONFLICT (channel_id, node_id, version)
2749
    -- Update the following fields if a conflict occurs on channel_id,
2750
    -- node_id, and version.
2751
    DO UPDATE SET
2752
        timelock = EXCLUDED.timelock,
2753
        fee_ppm = EXCLUDED.fee_ppm,
2754
        base_fee_msat = EXCLUDED.base_fee_msat,
2755
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2756
        last_update = EXCLUDED.last_update,
2757
        disabled = EXCLUDED.disabled,
2758
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2759
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2760
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2761
        message_flags = EXCLUDED.message_flags,
2762
        channel_flags = EXCLUDED.channel_flags,
2763
        signature = EXCLUDED.signature
2764
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
2765
RETURNING id
2766
`
2767

2768
type UpsertEdgePolicyParams struct {
2769
        Version                 int16
2770
        ChannelID               int64
2771
        NodeID                  int64
2772
        Timelock                int32
2773
        FeePpm                  int64
2774
        BaseFeeMsat             int64
2775
        MinHtlcMsat             int64
2776
        LastUpdate              sql.NullInt64
2777
        Disabled                sql.NullBool
2778
        MaxHtlcMsat             sql.NullInt64
2779
        InboundBaseFeeMsat      sql.NullInt64
2780
        InboundFeeRateMilliMsat sql.NullInt64
2781
        MessageFlags            sql.NullInt16
2782
        ChannelFlags            sql.NullInt16
2783
        Signature               []byte
2784
}
2785

2786
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2787
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2788
                arg.Version,
×
2789
                arg.ChannelID,
×
2790
                arg.NodeID,
×
2791
                arg.Timelock,
×
2792
                arg.FeePpm,
×
2793
                arg.BaseFeeMsat,
×
2794
                arg.MinHtlcMsat,
×
2795
                arg.LastUpdate,
×
2796
                arg.Disabled,
×
2797
                arg.MaxHtlcMsat,
×
2798
                arg.InboundBaseFeeMsat,
×
2799
                arg.InboundFeeRateMilliMsat,
×
2800
                arg.MessageFlags,
×
2801
                arg.ChannelFlags,
×
2802
                arg.Signature,
×
2803
        )
×
2804
        var id int64
×
2805
        err := row.Scan(&id)
×
2806
        return id, err
×
2807
}
×
2808

2809
const upsertNode = `-- name: UpsertNode :one
2810
/* ─────────────────────────────────────────────
2811
   graph_nodes table queries
2812
   ───────────────────────────��─────────────────
2813
*/
2814

2815
INSERT INTO graph_nodes (
2816
    version, pub_key, alias, last_update, color, signature
2817
) VALUES (
2818
    $1, $2, $3, $4, $5, $6
2819
)
2820
ON CONFLICT (pub_key, version)
2821
    -- Update the following fields if a conflict occurs on pub_key
2822
    -- and version.
2823
    DO UPDATE SET
2824
        alias = EXCLUDED.alias,
2825
        last_update = EXCLUDED.last_update,
2826
        color = EXCLUDED.color,
2827
        signature = EXCLUDED.signature
2828
WHERE graph_nodes.last_update IS NULL
2829
    OR EXCLUDED.last_update > graph_nodes.last_update
2830
RETURNING id
2831
`
2832

2833
type UpsertNodeParams struct {
2834
        Version    int16
2835
        PubKey     []byte
2836
        Alias      sql.NullString
2837
        LastUpdate sql.NullInt64
2838
        Color      sql.NullString
2839
        Signature  []byte
2840
}
2841

2842
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2843
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2844
                arg.Version,
×
2845
                arg.PubKey,
×
2846
                arg.Alias,
×
2847
                arg.LastUpdate,
×
2848
                arg.Color,
×
2849
                arg.Signature,
×
2850
        )
×
2851
        var id int64
×
2852
        err := row.Scan(&id)
×
2853
        return id, err
×
2854
}
×
2855

2856
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2857
/* ─────────────────────────────────────────────
2858
   graph_node_extra_types table queries
2859
   ─────────────────────────────────────────────
2860
*/
2861

2862
INSERT INTO graph_node_extra_types (
2863
    node_id, type, value
2864
)
2865
VALUES ($1, $2, $3)
2866
ON CONFLICT (type, node_id)
2867
    -- Update the value if a conflict occurs on type
2868
    -- and node_id.
2869
    DO UPDATE SET value = EXCLUDED.value
2870
`
2871

2872
type UpsertNodeExtraTypeParams struct {
2873
        NodeID int64
2874
        Type   int64
2875
        Value  []byte
2876
}
2877

2878
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2879
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2880
        return err
×
2881
}
×
2882

2883
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2884
/* ───────────────────────────���─────────────────
2885
    graph_prune_log table queries
2886
    ─────────────────────────────────────────────
2887
*/
2888

2889
INSERT INTO graph_prune_log (
2890
    block_height, block_hash
2891
) VALUES (
2892
    $1, $2
2893
)
2894
ON CONFLICT(block_height) DO UPDATE SET
2895
    block_hash = EXCLUDED.block_hash
2896
`
2897

2898
type UpsertPruneLogEntryParams struct {
2899
        BlockHeight int64
2900
        BlockHash   []byte
2901
}
2902

2903
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2904
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2905
        return err
×
2906
}
×
2907

2908
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2909
/* ─────────────────────────────────────────────
2910
   graph_zombie_channels table queries
2911
   ─────────────────────────────────────────────
2912
*/
2913

2914
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
2915
VALUES ($1, $2, $3, $4)
2916
ON CONFLICT (scid, version)
2917
DO UPDATE SET
2918
    -- If a conflict exists for the SCID and version pair, then we
2919
    -- update the node keys.
2920
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
2921
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
2922
`
2923

2924
type UpsertZombieChannelParams struct {
2925
        Scid     []byte
2926
        Version  int16
2927
        NodeKey1 []byte
2928
        NodeKey2 []byte
2929
}
2930

2931
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2932
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2933
                arg.Scid,
×
2934
                arg.Version,
×
2935
                arg.NodeKey1,
×
2936
                arg.NodeKey2,
×
2937
        )
×
2938
        return err
×
2939
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc