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

lightningnetwork / lnd / 16643433757

31 Jul 2025 08:03AM UTC coverage: 67.044% (-0.03%) from 67.074%
16643433757

push

github

web-flow
Merge pull request #10116 from ellemouton/graphPerf4

[3] graph/db: batch-fetch channel & policy data

0 of 281 new or added lines in 3 files covered. (0.0%)

54 existing lines in 13 files now uncovered.

135555 of 202189 relevant lines covered (67.04%)

21624.12 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 getChannelExtrasBatch = `-- name: GetChannelExtrasBatch :many
705
SELECT
706
    channel_id,
707
    type,
708
    value
709
FROM graph_channel_extra_types
710
WHERE channel_id IN (/*SLICE:chan_ids*/?)
711
ORDER BY channel_id, type
712
`
713

NEW
714
func (q *Queries) GetChannelExtrasBatch(ctx context.Context, chanIds []int64) ([]GraphChannelExtraType, error) {
×
NEW
715
        query := getChannelExtrasBatch
×
NEW
716
        var queryParams []interface{}
×
NEW
717
        if len(chanIds) > 0 {
×
NEW
718
                for _, v := range chanIds {
×
NEW
719
                        queryParams = append(queryParams, v)
×
NEW
720
                }
×
NEW
721
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", makeQueryParams(len(queryParams), len(chanIds)), 1)
×
NEW
722
        } else {
×
NEW
723
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", "NULL", 1)
×
NEW
724
        }
×
NEW
725
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
NEW
726
        if err != nil {
×
NEW
727
                return nil, err
×
NEW
728
        }
×
NEW
729
        defer rows.Close()
×
NEW
730
        var items []GraphChannelExtraType
×
NEW
731
        for rows.Next() {
×
NEW
732
                var i GraphChannelExtraType
×
NEW
733
                if err := rows.Scan(&i.ChannelID, &i.Type, &i.Value); err != nil {
×
NEW
734
                        return nil, err
×
NEW
735
                }
×
NEW
736
                items = append(items, i)
×
737
        }
NEW
738
        if err := rows.Close(); err != nil {
×
NEW
739
                return nil, err
×
NEW
740
        }
×
NEW
741
        if err := rows.Err(); err != nil {
×
NEW
742
                return nil, err
×
NEW
743
        }
×
NEW
744
        return items, nil
×
745
}
746

747
const getChannelFeaturesBatch = `-- name: GetChannelFeaturesBatch :many
748
SELECT
749
    channel_id,
750
    feature_bit
751
FROM graph_channel_features
752
WHERE channel_id IN (/*SLICE:chan_ids*/?)
753
ORDER BY channel_id, feature_bit
754
`
755

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

789
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
790
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
791
FROM graph_channel_policies
792
WHERE channel_id = $1
793
  AND node_id = $2
794
  AND version = $3
795
`
796

797
type GetChannelPolicyByChannelAndNodeParams struct {
798
        ChannelID int64
799
        NodeID    int64
800
        Version   int16
801
}
802

803
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (GraphChannelPolicy, error) {
×
804
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
805
        var i GraphChannelPolicy
×
806
        err := row.Scan(
×
807
                &i.ID,
×
808
                &i.Version,
×
809
                &i.ChannelID,
×
810
                &i.NodeID,
×
811
                &i.Timelock,
×
812
                &i.FeePpm,
×
813
                &i.BaseFeeMsat,
×
814
                &i.MinHtlcMsat,
×
815
                &i.MaxHtlcMsat,
×
816
                &i.LastUpdate,
×
817
                &i.Disabled,
×
818
                &i.InboundBaseFeeMsat,
×
819
                &i.InboundFeeRateMilliMsat,
×
820
                &i.MessageFlags,
×
821
                &i.ChannelFlags,
×
822
                &i.Signature,
×
823
        )
×
824
        return i, err
×
825
}
×
826

827
const getChannelPolicyExtraTypesBatch = `-- name: GetChannelPolicyExtraTypesBatch :many
828
SELECT
829
    channel_policy_id as policy_id,
830
    type,
831
    value
832
FROM graph_channel_policy_extra_types
833
WHERE channel_policy_id IN (/*SLICE:policy_ids*/?)
834
ORDER BY channel_policy_id, type
835
`
836

837
type GetChannelPolicyExtraTypesBatchRow struct {
838
        PolicyID int64
839
        Type     int64
840
        Value    []byte
841
}
842

NEW
843
func (q *Queries) GetChannelPolicyExtraTypesBatch(ctx context.Context, policyIds []int64) ([]GetChannelPolicyExtraTypesBatchRow, error) {
×
NEW
844
        query := getChannelPolicyExtraTypesBatch
×
NEW
845
        var queryParams []interface{}
×
NEW
846
        if len(policyIds) > 0 {
×
NEW
847
                for _, v := range policyIds {
×
NEW
848
                        queryParams = append(queryParams, v)
×
NEW
849
                }
×
NEW
850
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", makeQueryParams(len(queryParams), len(policyIds)), 1)
×
NEW
851
        } else {
×
NEW
852
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", "NULL", 1)
×
NEW
853
        }
×
NEW
854
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
855
        if err != nil {
×
856
                return nil, err
×
857
        }
×
858
        defer rows.Close()
×
NEW
859
        var items []GetChannelPolicyExtraTypesBatchRow
×
860
        for rows.Next() {
×
NEW
861
                var i GetChannelPolicyExtraTypesBatchRow
×
NEW
862
                if err := rows.Scan(&i.PolicyID, &i.Type, &i.Value); err != nil {
×
863
                        return nil, err
×
864
                }
×
865
                items = append(items, i)
×
866
        }
867
        if err := rows.Close(); err != nil {
×
868
                return nil, err
×
869
        }
×
870
        if err := rows.Err(); err != nil {
×
871
                return nil, err
×
872
        }
×
873
        return items, nil
×
874
}
875

876
const getChannelsByOutpoints = `-- name: GetChannelsByOutpoints :many
877
SELECT
878
    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,
879
    n1.pub_key AS node1_pubkey,
880
    n2.pub_key AS node2_pubkey
881
FROM graph_channels c
882
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
883
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
884
WHERE c.outpoint IN
885
    (/*SLICE:outpoints*/?)
886
`
887

888
type GetChannelsByOutpointsRow struct {
889
        GraphChannel GraphChannel
890
        Node1Pubkey  []byte
891
        Node2Pubkey  []byte
892
}
893

894
func (q *Queries) GetChannelsByOutpoints(ctx context.Context, outpoints []string) ([]GetChannelsByOutpointsRow, error) {
×
895
        query := getChannelsByOutpoints
×
896
        var queryParams []interface{}
×
897
        if len(outpoints) > 0 {
×
898
                for _, v := range outpoints {
×
899
                        queryParams = append(queryParams, v)
×
900
                }
×
901
                query = strings.Replace(query, "/*SLICE:outpoints*/?", makeQueryParams(len(queryParams), len(outpoints)), 1)
×
902
        } else {
×
903
                query = strings.Replace(query, "/*SLICE:outpoints*/?", "NULL", 1)
×
904
        }
×
905
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
906
        if err != nil {
×
907
                return nil, err
×
908
        }
×
909
        defer rows.Close()
×
910
        var items []GetChannelsByOutpointsRow
×
911
        for rows.Next() {
×
912
                var i GetChannelsByOutpointsRow
×
913
                if err := rows.Scan(
×
914
                        &i.GraphChannel.ID,
×
915
                        &i.GraphChannel.Version,
×
916
                        &i.GraphChannel.Scid,
×
917
                        &i.GraphChannel.NodeID1,
×
918
                        &i.GraphChannel.NodeID2,
×
919
                        &i.GraphChannel.Outpoint,
×
920
                        &i.GraphChannel.Capacity,
×
921
                        &i.GraphChannel.BitcoinKey1,
×
922
                        &i.GraphChannel.BitcoinKey2,
×
923
                        &i.GraphChannel.Node1Signature,
×
924
                        &i.GraphChannel.Node2Signature,
×
925
                        &i.GraphChannel.Bitcoin1Signature,
×
926
                        &i.GraphChannel.Bitcoin2Signature,
×
927
                        &i.Node1Pubkey,
×
928
                        &i.Node2Pubkey,
×
929
                ); err != nil {
×
930
                        return nil, err
×
931
                }
×
932
                items = append(items, i)
×
933
        }
934
        if err := rows.Close(); err != nil {
×
935
                return nil, err
×
936
        }
×
937
        if err := rows.Err(); err != nil {
×
938
                return nil, err
×
939
        }
×
940
        return items, nil
×
941
}
942

943
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
944
SELECT
945
    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,
946
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
947
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
948

949
    -- Policy 1 (node_id_1)
950
    cp1.id AS policy1_id,
951
    cp1.node_id AS policy1_node_id,
952
    cp1.version AS policy1_version,
953
    cp1.timelock AS policy1_timelock,
954
    cp1.fee_ppm AS policy1_fee_ppm,
955
    cp1.base_fee_msat AS policy1_base_fee_msat,
956
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
957
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
958
    cp1.last_update AS policy1_last_update,
959
    cp1.disabled AS policy1_disabled,
960
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
961
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
962
    cp1.message_flags AS policy1_message_flags,
963
    cp1.channel_flags AS policy1_channel_flags,
964
    cp1.signature AS policy1_signature,
965

966
    -- Policy 2 (node_id_2)
967
    cp2.id AS policy2_id,
968
    cp2.node_id AS policy2_node_id,
969
    cp2.version AS policy2_version,
970
    cp2.timelock AS policy2_timelock,
971
    cp2.fee_ppm AS policy2_fee_ppm,
972
    cp2.base_fee_msat AS policy2_base_fee_msat,
973
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
974
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
975
    cp2.last_update AS policy2_last_update,
976
    cp2.disabled AS policy2_disabled,
977
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
978
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
979
    cp2.message_flags AS policy2_message_flags,
980
    cp2.channel_flags AS policy2_channel_flags,
981
    cp2.signature AS policy2_signature
982

983
FROM graph_channels c
984
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
985
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
986
    LEFT JOIN graph_channel_policies cp1
987
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
988
    LEFT JOIN graph_channel_policies cp2
989
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
990
WHERE c.version = $1
991
  AND (
992
       (cp1.last_update >= $2 AND cp1.last_update < $3)
993
       OR
994
       (cp2.last_update >= $2 AND cp2.last_update < $3)
995
  )
996
ORDER BY
997
    CASE
998
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
999
            THEN COALESCE(cp1.last_update, 0)
1000
        ELSE COALESCE(cp2.last_update, 0)
1001
        END ASC
1002
`
1003

1004
type GetChannelsByPolicyLastUpdateRangeParams struct {
1005
        Version   int16
1006
        StartTime sql.NullInt64
1007
        EndTime   sql.NullInt64
1008
}
1009

1010
type GetChannelsByPolicyLastUpdateRangeRow struct {
1011
        GraphChannel                   GraphChannel
1012
        GraphNode                      GraphNode
1013
        GraphNode_2                    GraphNode
1014
        Policy1ID                      sql.NullInt64
1015
        Policy1NodeID                  sql.NullInt64
1016
        Policy1Version                 sql.NullInt16
1017
        Policy1Timelock                sql.NullInt32
1018
        Policy1FeePpm                  sql.NullInt64
1019
        Policy1BaseFeeMsat             sql.NullInt64
1020
        Policy1MinHtlcMsat             sql.NullInt64
1021
        Policy1MaxHtlcMsat             sql.NullInt64
1022
        Policy1LastUpdate              sql.NullInt64
1023
        Policy1Disabled                sql.NullBool
1024
        Policy1InboundBaseFeeMsat      sql.NullInt64
1025
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1026
        Policy1MessageFlags            sql.NullInt16
1027
        Policy1ChannelFlags            sql.NullInt16
1028
        Policy1Signature               []byte
1029
        Policy2ID                      sql.NullInt64
1030
        Policy2NodeID                  sql.NullInt64
1031
        Policy2Version                 sql.NullInt16
1032
        Policy2Timelock                sql.NullInt32
1033
        Policy2FeePpm                  sql.NullInt64
1034
        Policy2BaseFeeMsat             sql.NullInt64
1035
        Policy2MinHtlcMsat             sql.NullInt64
1036
        Policy2MaxHtlcMsat             sql.NullInt64
1037
        Policy2LastUpdate              sql.NullInt64
1038
        Policy2Disabled                sql.NullBool
1039
        Policy2InboundBaseFeeMsat      sql.NullInt64
1040
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1041
        Policy2MessageFlags            sql.NullInt16
1042
        Policy2ChannelFlags            sql.NullInt16
1043
        Policy2Signature               []byte
1044
}
1045

1046
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
1047
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
1048
        if err != nil {
×
1049
                return nil, err
×
1050
        }
×
1051
        defer rows.Close()
×
1052
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
1053
        for rows.Next() {
×
1054
                var i GetChannelsByPolicyLastUpdateRangeRow
×
1055
                if err := rows.Scan(
×
1056
                        &i.GraphChannel.ID,
×
1057
                        &i.GraphChannel.Version,
×
1058
                        &i.GraphChannel.Scid,
×
1059
                        &i.GraphChannel.NodeID1,
×
1060
                        &i.GraphChannel.NodeID2,
×
1061
                        &i.GraphChannel.Outpoint,
×
1062
                        &i.GraphChannel.Capacity,
×
1063
                        &i.GraphChannel.BitcoinKey1,
×
1064
                        &i.GraphChannel.BitcoinKey2,
×
1065
                        &i.GraphChannel.Node1Signature,
×
1066
                        &i.GraphChannel.Node2Signature,
×
1067
                        &i.GraphChannel.Bitcoin1Signature,
×
1068
                        &i.GraphChannel.Bitcoin2Signature,
×
1069
                        &i.GraphNode.ID,
×
1070
                        &i.GraphNode.Version,
×
1071
                        &i.GraphNode.PubKey,
×
1072
                        &i.GraphNode.Alias,
×
1073
                        &i.GraphNode.LastUpdate,
×
1074
                        &i.GraphNode.Color,
×
1075
                        &i.GraphNode.Signature,
×
1076
                        &i.GraphNode_2.ID,
×
1077
                        &i.GraphNode_2.Version,
×
1078
                        &i.GraphNode_2.PubKey,
×
1079
                        &i.GraphNode_2.Alias,
×
1080
                        &i.GraphNode_2.LastUpdate,
×
1081
                        &i.GraphNode_2.Color,
×
1082
                        &i.GraphNode_2.Signature,
×
1083
                        &i.Policy1ID,
×
1084
                        &i.Policy1NodeID,
×
1085
                        &i.Policy1Version,
×
1086
                        &i.Policy1Timelock,
×
1087
                        &i.Policy1FeePpm,
×
1088
                        &i.Policy1BaseFeeMsat,
×
1089
                        &i.Policy1MinHtlcMsat,
×
1090
                        &i.Policy1MaxHtlcMsat,
×
1091
                        &i.Policy1LastUpdate,
×
1092
                        &i.Policy1Disabled,
×
1093
                        &i.Policy1InboundBaseFeeMsat,
×
1094
                        &i.Policy1InboundFeeRateMilliMsat,
×
1095
                        &i.Policy1MessageFlags,
×
1096
                        &i.Policy1ChannelFlags,
×
1097
                        &i.Policy1Signature,
×
1098
                        &i.Policy2ID,
×
1099
                        &i.Policy2NodeID,
×
1100
                        &i.Policy2Version,
×
1101
                        &i.Policy2Timelock,
×
1102
                        &i.Policy2FeePpm,
×
1103
                        &i.Policy2BaseFeeMsat,
×
1104
                        &i.Policy2MinHtlcMsat,
×
1105
                        &i.Policy2MaxHtlcMsat,
×
1106
                        &i.Policy2LastUpdate,
×
1107
                        &i.Policy2Disabled,
×
1108
                        &i.Policy2InboundBaseFeeMsat,
×
1109
                        &i.Policy2InboundFeeRateMilliMsat,
×
1110
                        &i.Policy2MessageFlags,
×
1111
                        &i.Policy2ChannelFlags,
×
1112
                        &i.Policy2Signature,
×
1113
                ); err != nil {
×
1114
                        return nil, err
×
1115
                }
×
1116
                items = append(items, i)
×
1117
        }
1118
        if err := rows.Close(); err != nil {
×
1119
                return nil, err
×
1120
        }
×
1121
        if err := rows.Err(); err != nil {
×
1122
                return nil, err
×
1123
        }
×
1124
        return items, nil
×
1125
}
1126

1127
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1128
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,
1129
    n1.pub_key AS node1_pub_key,
1130
    n2.pub_key AS node2_pub_key
1131
FROM graph_channels c
1132
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1133
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1134
WHERE scid >= $1
1135
  AND scid < $2
1136
`
1137

1138
type GetChannelsBySCIDRangeParams struct {
1139
        StartScid []byte
1140
        EndScid   []byte
1141
}
1142

1143
type GetChannelsBySCIDRangeRow struct {
1144
        GraphChannel GraphChannel
1145
        Node1PubKey  []byte
1146
        Node2PubKey  []byte
1147
}
1148

1149
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1150
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1151
        if err != nil {
×
1152
                return nil, err
×
1153
        }
×
1154
        defer rows.Close()
×
1155
        var items []GetChannelsBySCIDRangeRow
×
1156
        for rows.Next() {
×
1157
                var i GetChannelsBySCIDRangeRow
×
1158
                if err := rows.Scan(
×
1159
                        &i.GraphChannel.ID,
×
1160
                        &i.GraphChannel.Version,
×
1161
                        &i.GraphChannel.Scid,
×
1162
                        &i.GraphChannel.NodeID1,
×
1163
                        &i.GraphChannel.NodeID2,
×
1164
                        &i.GraphChannel.Outpoint,
×
1165
                        &i.GraphChannel.Capacity,
×
1166
                        &i.GraphChannel.BitcoinKey1,
×
1167
                        &i.GraphChannel.BitcoinKey2,
×
1168
                        &i.GraphChannel.Node1Signature,
×
1169
                        &i.GraphChannel.Node2Signature,
×
1170
                        &i.GraphChannel.Bitcoin1Signature,
×
1171
                        &i.GraphChannel.Bitcoin2Signature,
×
1172
                        &i.Node1PubKey,
×
1173
                        &i.Node2PubKey,
×
1174
                ); err != nil {
×
1175
                        return nil, err
×
1176
                }
×
1177
                items = append(items, i)
×
1178
        }
1179
        if err := rows.Close(); err != nil {
×
1180
                return nil, err
×
1181
        }
×
1182
        if err := rows.Err(); err != nil {
×
1183
                return nil, err
×
1184
        }
×
1185
        return items, nil
×
1186
}
1187

1188
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1189
SELECT
1190
    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,
1191
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1192
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1193

1194
    -- Policy 1
1195
    cp1.id AS policy1_id,
1196
    cp1.node_id AS policy1_node_id,
1197
    cp1.version AS policy1_version,
1198
    cp1.timelock AS policy1_timelock,
1199
    cp1.fee_ppm AS policy1_fee_ppm,
1200
    cp1.base_fee_msat AS policy1_base_fee_msat,
1201
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1202
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1203
    cp1.last_update AS policy1_last_update,
1204
    cp1.disabled AS policy1_disabled,
1205
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1206
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1207
    cp1.message_flags AS policy1_message_flags,
1208
    cp1.channel_flags AS policy1_channel_flags,
1209
    cp1.signature AS policy1_signature,
1210

1211
    -- Policy 2
1212
    cp2.id AS policy2_id,
1213
    cp2.node_id AS policy2_node_id,
1214
    cp2.version AS policy2_version,
1215
    cp2.timelock AS policy2_timelock,
1216
    cp2.fee_ppm AS policy2_fee_ppm,
1217
    cp2.base_fee_msat AS policy2_base_fee_msat,
1218
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1219
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1220
    cp2.last_update AS policy2_last_update,
1221
    cp2.disabled AS policy2_disabled,
1222
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1223
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1224
    cp2.message_flags AS policy_2_message_flags,
1225
    cp2.channel_flags AS policy_2_channel_flags,
1226
    cp2.signature AS policy2_signature
1227

1228
FROM graph_channels c
1229
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1230
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1231
    LEFT JOIN graph_channel_policies cp1
1232
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1233
    LEFT JOIN graph_channel_policies cp2
1234
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1235
WHERE
1236
    c.version = $1
1237
  AND c.scid IN (/*SLICE:scids*/?)
1238
`
1239

1240
type GetChannelsBySCIDWithPoliciesParams struct {
1241
        Version int16
1242
        Scids   [][]byte
1243
}
1244

1245
type GetChannelsBySCIDWithPoliciesRow struct {
1246
        GraphChannel                   GraphChannel
1247
        GraphNode                      GraphNode
1248
        GraphNode_2                    GraphNode
1249
        Policy1ID                      sql.NullInt64
1250
        Policy1NodeID                  sql.NullInt64
1251
        Policy1Version                 sql.NullInt16
1252
        Policy1Timelock                sql.NullInt32
1253
        Policy1FeePpm                  sql.NullInt64
1254
        Policy1BaseFeeMsat             sql.NullInt64
1255
        Policy1MinHtlcMsat             sql.NullInt64
1256
        Policy1MaxHtlcMsat             sql.NullInt64
1257
        Policy1LastUpdate              sql.NullInt64
1258
        Policy1Disabled                sql.NullBool
1259
        Policy1InboundBaseFeeMsat      sql.NullInt64
1260
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1261
        Policy1MessageFlags            sql.NullInt16
1262
        Policy1ChannelFlags            sql.NullInt16
1263
        Policy1Signature               []byte
1264
        Policy2ID                      sql.NullInt64
1265
        Policy2NodeID                  sql.NullInt64
1266
        Policy2Version                 sql.NullInt16
1267
        Policy2Timelock                sql.NullInt32
1268
        Policy2FeePpm                  sql.NullInt64
1269
        Policy2BaseFeeMsat             sql.NullInt64
1270
        Policy2MinHtlcMsat             sql.NullInt64
1271
        Policy2MaxHtlcMsat             sql.NullInt64
1272
        Policy2LastUpdate              sql.NullInt64
1273
        Policy2Disabled                sql.NullBool
1274
        Policy2InboundBaseFeeMsat      sql.NullInt64
1275
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1276
        Policy2MessageFlags            sql.NullInt16
1277
        Policy2ChannelFlags            sql.NullInt16
1278
        Policy2Signature               []byte
1279
}
1280

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

1373
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1374
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
1375
WHERE version = $1
1376
  AND scid IN (/*SLICE:scids*/?)
1377
`
1378

1379
type GetChannelsBySCIDsParams struct {
1380
        Version int16
1381
        Scids   [][]byte
1382
}
1383

1384
func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error) {
×
1385
        query := getChannelsBySCIDs
×
1386
        var queryParams []interface{}
×
1387
        queryParams = append(queryParams, arg.Version)
×
1388
        if len(arg.Scids) > 0 {
×
1389
                for _, v := range arg.Scids {
×
1390
                        queryParams = append(queryParams, v)
×
1391
                }
×
1392
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1393
        } else {
×
1394
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1395
        }
×
1396
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1397
        if err != nil {
×
1398
                return nil, err
×
1399
        }
×
1400
        defer rows.Close()
×
1401
        var items []GraphChannel
×
1402
        for rows.Next() {
×
1403
                var i GraphChannel
×
1404
                if err := rows.Scan(
×
1405
                        &i.ID,
×
1406
                        &i.Version,
×
1407
                        &i.Scid,
×
1408
                        &i.NodeID1,
×
1409
                        &i.NodeID2,
×
1410
                        &i.Outpoint,
×
1411
                        &i.Capacity,
×
1412
                        &i.BitcoinKey1,
×
1413
                        &i.BitcoinKey2,
×
1414
                        &i.Node1Signature,
×
1415
                        &i.Node2Signature,
×
1416
                        &i.Bitcoin1Signature,
×
1417
                        &i.Bitcoin2Signature,
×
1418
                ); err != nil {
×
1419
                        return nil, err
×
1420
                }
×
1421
                items = append(items, i)
×
1422
        }
1423
        if err := rows.Close(); err != nil {
×
1424
                return nil, err
×
1425
        }
×
1426
        if err := rows.Err(); err != nil {
×
1427
                return nil, err
×
1428
        }
×
1429
        return items, nil
×
1430
}
1431

1432
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1433
SELECT node_id, type, value
1434
FROM graph_node_extra_types
1435
WHERE node_id = $1
1436
`
1437

1438
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) {
×
1439
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1440
        if err != nil {
×
1441
                return nil, err
×
1442
        }
×
1443
        defer rows.Close()
×
1444
        var items []GraphNodeExtraType
×
1445
        for rows.Next() {
×
1446
                var i GraphNodeExtraType
×
1447
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1448
                        return nil, err
×
1449
                }
×
1450
                items = append(items, i)
×
1451
        }
1452
        if err := rows.Close(); err != nil {
×
1453
                return nil, err
×
1454
        }
×
1455
        if err := rows.Err(); err != nil {
×
1456
                return nil, err
×
1457
        }
×
1458
        return items, nil
×
1459
}
1460

1461
const getNodeAddresses = `-- name: GetNodeAddresses :many
1462
SELECT type, address
1463
FROM graph_node_addresses
1464
WHERE node_id = $1
1465
ORDER BY type ASC, position ASC
1466
`
1467

1468
type GetNodeAddressesRow struct {
1469
        Type    int16
1470
        Address string
1471
}
1472

1473
func (q *Queries) GetNodeAddresses(ctx context.Context, nodeID int64) ([]GetNodeAddressesRow, error) {
×
1474
        rows, err := q.db.QueryContext(ctx, getNodeAddresses, nodeID)
×
1475
        if err != nil {
×
1476
                return nil, err
×
1477
        }
×
1478
        defer rows.Close()
×
1479
        var items []GetNodeAddressesRow
×
1480
        for rows.Next() {
×
1481
                var i GetNodeAddressesRow
×
1482
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1483
                        return nil, err
×
1484
                }
×
1485
                items = append(items, i)
×
1486
        }
1487
        if err := rows.Close(); err != nil {
×
1488
                return nil, err
×
1489
        }
×
1490
        if err := rows.Err(); err != nil {
×
1491
                return nil, err
×
1492
        }
×
1493
        return items, nil
×
1494
}
1495

1496
const getNodeAddressesBatch = `-- name: GetNodeAddressesBatch :many
1497
SELECT node_id, type, position, address
1498
FROM graph_node_addresses
1499
WHERE node_id IN (/*SLICE:ids*/?)
1500
ORDER BY node_id, type, position
1501
`
1502

1503
func (q *Queries) GetNodeAddressesBatch(ctx context.Context, ids []int64) ([]GraphNodeAddress, error) {
×
1504
        query := getNodeAddressesBatch
×
1505
        var queryParams []interface{}
×
1506
        if len(ids) > 0 {
×
1507
                for _, v := range ids {
×
1508
                        queryParams = append(queryParams, v)
×
1509
                }
×
1510
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1511
        } else {
×
1512
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1513
        }
×
1514
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1515
        if err != nil {
×
1516
                return nil, err
×
1517
        }
×
1518
        defer rows.Close()
×
1519
        var items []GraphNodeAddress
×
1520
        for rows.Next() {
×
1521
                var i GraphNodeAddress
×
1522
                if err := rows.Scan(
×
1523
                        &i.NodeID,
×
1524
                        &i.Type,
×
1525
                        &i.Position,
×
1526
                        &i.Address,
×
1527
                ); err != nil {
×
1528
                        return nil, err
×
1529
                }
×
1530
                items = append(items, i)
×
1531
        }
1532
        if err := rows.Close(); err != nil {
×
1533
                return nil, err
×
1534
        }
×
1535
        if err := rows.Err(); err != nil {
×
1536
                return nil, err
×
1537
        }
×
1538
        return items, nil
×
1539
}
1540

1541
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1542
SELECT id, version, pub_key, alias, last_update, color, signature
1543
FROM graph_nodes
1544
WHERE pub_key = $1
1545
  AND version = $2
1546
`
1547

1548
type GetNodeByPubKeyParams struct {
1549
        PubKey  []byte
1550
        Version int16
1551
}
1552

1553
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1554
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1555
        var i GraphNode
×
1556
        err := row.Scan(
×
1557
                &i.ID,
×
1558
                &i.Version,
×
1559
                &i.PubKey,
×
1560
                &i.Alias,
×
1561
                &i.LastUpdate,
×
1562
                &i.Color,
×
1563
                &i.Signature,
×
1564
        )
×
1565
        return i, err
×
1566
}
×
1567

1568
const getNodeExtraTypesBatch = `-- name: GetNodeExtraTypesBatch :many
1569
SELECT node_id, type, value
1570
FROM graph_node_extra_types
1571
WHERE node_id IN (/*SLICE:ids*/?)
1572
ORDER BY node_id, type
1573
`
1574

1575
func (q *Queries) GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]GraphNodeExtraType, error) {
×
1576
        query := getNodeExtraTypesBatch
×
1577
        var queryParams []interface{}
×
1578
        if len(ids) > 0 {
×
1579
                for _, v := range ids {
×
1580
                        queryParams = append(queryParams, v)
×
1581
                }
×
1582
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1583
        } else {
×
1584
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1585
        }
×
1586
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1587
        if err != nil {
×
1588
                return nil, err
×
1589
        }
×
1590
        defer rows.Close()
×
1591
        var items []GraphNodeExtraType
×
1592
        for rows.Next() {
×
1593
                var i GraphNodeExtraType
×
1594
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1595
                        return nil, err
×
1596
                }
×
1597
                items = append(items, i)
×
1598
        }
1599
        if err := rows.Close(); err != nil {
×
1600
                return nil, err
×
1601
        }
×
1602
        if err := rows.Err(); err != nil {
×
1603
                return nil, err
×
1604
        }
×
1605
        return items, nil
×
1606
}
1607

1608
const getNodeFeatures = `-- name: GetNodeFeatures :many
1609
SELECT node_id, feature_bit
1610
FROM graph_node_features
1611
WHERE node_id = $1
1612
`
1613

1614
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1615
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1616
        if err != nil {
×
1617
                return nil, err
×
1618
        }
×
1619
        defer rows.Close()
×
1620
        var items []GraphNodeFeature
×
1621
        for rows.Next() {
×
1622
                var i GraphNodeFeature
×
1623
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1624
                        return nil, err
×
1625
                }
×
1626
                items = append(items, i)
×
1627
        }
1628
        if err := rows.Close(); err != nil {
×
1629
                return nil, err
×
1630
        }
×
1631
        if err := rows.Err(); err != nil {
×
1632
                return nil, err
×
1633
        }
×
1634
        return items, nil
×
1635
}
1636

1637
const getNodeFeaturesBatch = `-- name: GetNodeFeaturesBatch :many
1638
SELECT node_id, feature_bit
1639
FROM graph_node_features
1640
WHERE node_id IN (/*SLICE:ids*/?)
1641
ORDER BY node_id, feature_bit
1642
`
1643

1644
func (q *Queries) GetNodeFeaturesBatch(ctx context.Context, ids []int64) ([]GraphNodeFeature, error) {
×
1645
        query := getNodeFeaturesBatch
×
1646
        var queryParams []interface{}
×
1647
        if len(ids) > 0 {
×
1648
                for _, v := range ids {
×
1649
                        queryParams = append(queryParams, v)
×
1650
                }
×
1651
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1652
        } else {
×
1653
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1654
        }
×
1655
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1656
        if err != nil {
×
1657
                return nil, err
×
1658
        }
×
1659
        defer rows.Close()
×
1660
        var items []GraphNodeFeature
×
1661
        for rows.Next() {
×
1662
                var i GraphNodeFeature
×
1663
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1664
                        return nil, err
×
1665
                }
×
1666
                items = append(items, i)
×
1667
        }
1668
        if err := rows.Close(); err != nil {
×
1669
                return nil, err
×
1670
        }
×
1671
        if err := rows.Err(); err != nil {
×
1672
                return nil, err
×
1673
        }
×
1674
        return items, nil
×
1675
}
1676

1677
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1678
SELECT f.feature_bit
1679
FROM graph_nodes n
1680
    JOIN graph_node_features f ON f.node_id = n.id
1681
WHERE n.pub_key = $1
1682
  AND n.version = $2
1683
`
1684

1685
type GetNodeFeaturesByPubKeyParams struct {
1686
        PubKey  []byte
1687
        Version int16
1688
}
1689

1690
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1691
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1692
        if err != nil {
×
1693
                return nil, err
×
1694
        }
×
1695
        defer rows.Close()
×
1696
        var items []int32
×
1697
        for rows.Next() {
×
1698
                var feature_bit int32
×
1699
                if err := rows.Scan(&feature_bit); err != nil {
×
1700
                        return nil, err
×
1701
                }
×
1702
                items = append(items, feature_bit)
×
1703
        }
1704
        if err := rows.Close(); err != nil {
×
1705
                return nil, err
×
1706
        }
×
1707
        if err := rows.Err(); err != nil {
×
1708
                return nil, err
×
1709
        }
×
1710
        return items, nil
×
1711
}
1712

1713
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1714
SELECT id
1715
FROM graph_nodes
1716
WHERE pub_key = $1
1717
  AND version = $2
1718
`
1719

1720
type GetNodeIDByPubKeyParams struct {
1721
        PubKey  []byte
1722
        Version int16
1723
}
1724

1725
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1726
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1727
        var id int64
×
1728
        err := row.Scan(&id)
×
1729
        return id, err
×
1730
}
×
1731

1732
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1733
SELECT id, version, pub_key, alias, last_update, color, signature
1734
FROM graph_nodes
1735
WHERE last_update >= $1
1736
  AND last_update < $2
1737
`
1738

1739
type GetNodesByLastUpdateRangeParams struct {
1740
        StartTime sql.NullInt64
1741
        EndTime   sql.NullInt64
1742
}
1743

1744
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
1745
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1746
        if err != nil {
×
1747
                return nil, err
×
1748
        }
×
1749
        defer rows.Close()
×
1750
        var items []GraphNode
×
1751
        for rows.Next() {
×
1752
                var i GraphNode
×
1753
                if err := rows.Scan(
×
1754
                        &i.ID,
×
1755
                        &i.Version,
×
1756
                        &i.PubKey,
×
1757
                        &i.Alias,
×
1758
                        &i.LastUpdate,
×
1759
                        &i.Color,
×
1760
                        &i.Signature,
×
1761
                ); err != nil {
×
1762
                        return nil, err
×
1763
                }
×
1764
                items = append(items, i)
×
1765
        }
1766
        if err := rows.Close(); err != nil {
×
1767
                return nil, err
×
1768
        }
×
1769
        if err := rows.Err(); err != nil {
×
1770
                return nil, err
×
1771
        }
×
1772
        return items, nil
×
1773
}
1774

1775
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
1776
SELECT block_hash
1777
FROM graph_prune_log
1778
WHERE block_height = $1
1779
`
1780

1781
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
1782
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
1783
        var block_hash []byte
×
1784
        err := row.Scan(&block_hash)
×
1785
        return block_hash, err
×
1786
}
×
1787

1788
const getPruneTip = `-- name: GetPruneTip :one
1789
SELECT block_height, block_hash
1790
FROM graph_prune_log
1791
ORDER BY block_height DESC
1792
LIMIT 1
1793
`
1794

1795
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
1796
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1797
        var i GraphPruneLog
×
1798
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1799
        return i, err
×
1800
}
×
1801

1802
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1803
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
1804
FROM graph_channels
1805
WHERE node_1_signature IS NOT NULL
1806
  AND scid >= $1
1807
  AND scid < $2
1808
`
1809

1810
type GetPublicV1ChannelsBySCIDParams struct {
1811
        StartScid []byte
1812
        EndScid   []byte
1813
}
1814

1815
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
1816
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1817
        if err != nil {
×
1818
                return nil, err
×
1819
        }
×
1820
        defer rows.Close()
×
1821
        var items []GraphChannel
×
1822
        for rows.Next() {
×
1823
                var i GraphChannel
×
1824
                if err := rows.Scan(
×
1825
                        &i.ID,
×
1826
                        &i.Version,
×
1827
                        &i.Scid,
×
1828
                        &i.NodeID1,
×
1829
                        &i.NodeID2,
×
1830
                        &i.Outpoint,
×
1831
                        &i.Capacity,
×
1832
                        &i.BitcoinKey1,
×
1833
                        &i.BitcoinKey2,
×
1834
                        &i.Node1Signature,
×
1835
                        &i.Node2Signature,
×
1836
                        &i.Bitcoin1Signature,
×
1837
                        &i.Bitcoin2Signature,
×
1838
                ); err != nil {
×
1839
                        return nil, err
×
1840
                }
×
1841
                items = append(items, i)
×
1842
        }
1843
        if err := rows.Close(); err != nil {
×
1844
                return nil, err
×
1845
        }
×
1846
        if err := rows.Err(); err != nil {
×
1847
                return nil, err
×
1848
        }
×
1849
        return items, nil
×
1850
}
1851

1852
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1853
SELECT scid from graph_channels
1854
WHERE outpoint = $1 AND version = $2
1855
`
1856

1857
type GetSCIDByOutpointParams struct {
1858
        Outpoint string
1859
        Version  int16
1860
}
1861

1862
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1863
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1864
        var scid []byte
×
1865
        err := row.Scan(&scid)
×
1866
        return scid, err
×
1867
}
×
1868

1869
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1870
SELECT sn.node_id, n.pub_key
1871
FROM graph_source_nodes sn
1872
    JOIN graph_nodes n ON sn.node_id = n.id
1873
WHERE n.version = $1
1874
`
1875

1876
type GetSourceNodesByVersionRow struct {
1877
        NodeID int64
1878
        PubKey []byte
1879
}
1880

1881
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1882
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1883
        if err != nil {
×
1884
                return nil, err
×
1885
        }
×
1886
        defer rows.Close()
×
1887
        var items []GetSourceNodesByVersionRow
×
1888
        for rows.Next() {
×
1889
                var i GetSourceNodesByVersionRow
×
1890
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1891
                        return nil, err
×
1892
                }
×
1893
                items = append(items, i)
×
1894
        }
1895
        if err := rows.Close(); err != nil {
×
1896
                return nil, err
×
1897
        }
×
1898
        if err := rows.Err(); err != nil {
×
1899
                return nil, err
×
1900
        }
×
1901
        return items, nil
×
1902
}
1903

1904
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1905
SELECT c.scid
1906
FROM graph_channels c
1907
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
1908
WHERE cp.disabled = true
1909
AND c.version = 1
1910
GROUP BY c.scid
1911
HAVING COUNT(*) > 1
1912
`
1913

1914
// NOTE: this is V1 specific since for V1, disabled is a
1915
// simple, single boolean. The proposed V2 policy
1916
// structure will have a more complex disabled bit vector
1917
// and so the query for V2 may differ.
1918
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1919
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1920
        if err != nil {
×
1921
                return nil, err
×
1922
        }
×
1923
        defer rows.Close()
×
1924
        var items [][]byte
×
1925
        for rows.Next() {
×
1926
                var scid []byte
×
1927
                if err := rows.Scan(&scid); err != nil {
×
1928
                        return nil, err
×
1929
                }
×
1930
                items = append(items, scid)
×
1931
        }
1932
        if err := rows.Close(); err != nil {
×
1933
                return nil, err
×
1934
        }
×
1935
        if err := rows.Err(); err != nil {
×
1936
                return nil, err
×
1937
        }
×
1938
        return items, nil
×
1939
}
1940

1941
const getZombieChannel = `-- name: GetZombieChannel :one
1942
SELECT scid, version, node_key_1, node_key_2
1943
FROM graph_zombie_channels
1944
WHERE scid = $1
1945
AND version = $2
1946
`
1947

1948
type GetZombieChannelParams struct {
1949
        Scid    []byte
1950
        Version int16
1951
}
1952

1953
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
1954
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1955
        var i GraphZombieChannel
×
1956
        err := row.Scan(
×
1957
                &i.Scid,
×
1958
                &i.Version,
×
1959
                &i.NodeKey1,
×
1960
                &i.NodeKey2,
×
1961
        )
×
1962
        return i, err
×
1963
}
×
1964

1965
const highestSCID = `-- name: HighestSCID :one
1966
SELECT scid
1967
FROM graph_channels
1968
WHERE version = $1
1969
ORDER BY scid DESC
1970
LIMIT 1
1971
`
1972

1973
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1974
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1975
        var scid []byte
×
1976
        err := row.Scan(&scid)
×
1977
        return scid, err
×
1978
}
×
1979

1980
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1981
/* ─────────────────────────────────────────────
1982
   graph_channel_policy_extra_types table queries
1983
   ─────────────────────────────────────────────
1984
*/
1985

1986
INSERT INTO graph_channel_policy_extra_types (
1987
    channel_policy_id, type, value
1988
)
1989
VALUES ($1, $2, $3)
1990
`
1991

1992
type InsertChanPolicyExtraTypeParams struct {
1993
        ChannelPolicyID int64
1994
        Type            int64
1995
        Value           []byte
1996
}
1997

1998
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1999
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
2000
        return err
×
2001
}
×
2002

2003
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2004
/* ─────────────────────────────────────────────
2005
   graph_channel_features table queries
2006
   ─────────────────────────────────────────────
2007
*/
2008

2009
INSERT INTO graph_channel_features (
2010
    channel_id, feature_bit
2011
) VALUES (
2012
    $1, $2
2013
)
2014
`
2015

2016
type InsertChannelFeatureParams struct {
2017
        ChannelID  int64
2018
        FeatureBit int32
2019
}
2020

2021
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2022
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2023
        return err
×
2024
}
×
2025

2026
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2027
/* ─────────────────────────────────────────────
2028
   graph_closed_scid table queries
2029
   ────────────────────────────────────────────-
2030
*/
2031

2032
INSERT INTO graph_closed_scids (scid)
2033
VALUES ($1)
2034
ON CONFLICT (scid) DO NOTHING
2035
`
2036

2037
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2038
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2039
        return err
×
2040
}
×
2041

2042
const insertNodeAddress = `-- name: InsertNodeAddress :exec
2043
/* ─────────────────────────────────────────────
2044
   graph_node_addresses table queries
2045
   ───────────────────────────────────��─────────
2046
*/
2047

2048
INSERT INTO graph_node_addresses (
2049
    node_id,
2050
    type,
2051
    address,
2052
    position
2053
) VALUES (
2054
    $1, $2, $3, $4
2055
 )
2056
`
2057

2058
type InsertNodeAddressParams struct {
2059
        NodeID   int64
2060
        Type     int16
2061
        Address  string
2062
        Position int32
2063
}
2064

2065
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
2066
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
2067
                arg.NodeID,
×
2068
                arg.Type,
×
2069
                arg.Address,
×
2070
                arg.Position,
×
2071
        )
×
2072
        return err
×
2073
}
×
2074

2075
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2076
/* ─────────────────────────────────────────────
2077
   graph_node_features table queries
2078
   ─────────────────────────────────────────────
2079
*/
2080

2081
INSERT INTO graph_node_features (
2082
    node_id, feature_bit
2083
) VALUES (
2084
    $1, $2
2085
)
2086
`
2087

2088
type InsertNodeFeatureParams struct {
2089
        NodeID     int64
2090
        FeatureBit int32
2091
}
2092

2093
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2094
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2095
        return err
×
2096
}
×
2097

2098
const isClosedChannel = `-- name: IsClosedChannel :one
2099
SELECT EXISTS (
2100
    SELECT 1
2101
    FROM graph_closed_scids
2102
    WHERE scid = $1
2103
)
2104
`
2105

2106
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2107
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2108
        var exists bool
×
2109
        err := row.Scan(&exists)
×
2110
        return exists, err
×
2111
}
×
2112

2113
const isPublicV1Node = `-- name: IsPublicV1Node :one
2114
SELECT EXISTS (
2115
    SELECT 1
2116
    FROM graph_channels c
2117
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
2118
    -- NOTE: we hard-code the version here since the clauses
2119
    -- here that determine if a node is public is specific
2120
    -- to the V1 gossip protocol. In V1, a node is public
2121
    -- if it has a public channel and a public channel is one
2122
    -- where we have the set of signatures of the channel
2123
    -- announcement. It is enough to just check that we have
2124
    -- one of the signatures since we only ever set them
2125
    -- together.
2126
    WHERE c.version = 1
2127
      AND c.bitcoin_1_signature IS NOT NULL
2128
      AND n.pub_key = $1
2129
)
2130
`
2131

2132
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2133
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2134
        var exists bool
×
2135
        err := row.Scan(&exists)
×
2136
        return exists, err
×
2137
}
×
2138

2139
const isZombieChannel = `-- name: IsZombieChannel :one
2140
SELECT EXISTS (
2141
    SELECT 1
2142
    FROM graph_zombie_channels
2143
    WHERE scid = $1
2144
    AND version = $2
2145
) AS is_zombie
2146
`
2147

2148
type IsZombieChannelParams struct {
2149
        Scid    []byte
2150
        Version int16
2151
}
2152

2153
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2154
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2155
        var is_zombie bool
×
2156
        err := row.Scan(&is_zombie)
×
2157
        return is_zombie, err
×
2158
}
×
2159

2160
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2161
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,
2162
    n1.pub_key AS node1_pubkey,
2163
    n2.pub_key AS node2_pubkey,
2164

2165
    -- Policy 1
2166
    -- TODO(elle): use sqlc.embed to embed policy structs
2167
    --  once this issue is resolved:
2168
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2169
    cp1.id AS policy1_id,
2170
    cp1.node_id AS policy1_node_id,
2171
    cp1.version AS policy1_version,
2172
    cp1.timelock AS policy1_timelock,
2173
    cp1.fee_ppm AS policy1_fee_ppm,
2174
    cp1.base_fee_msat AS policy1_base_fee_msat,
2175
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2176
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2177
    cp1.last_update AS policy1_last_update,
2178
    cp1.disabled AS policy1_disabled,
2179
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2180
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2181
    cp1.message_flags AS policy1_message_flags,
2182
    cp1.channel_flags AS policy1_channel_flags,
2183
    cp1.signature AS policy1_signature,
2184

2185
       -- Policy 2
2186
    cp2.id AS policy2_id,
2187
    cp2.node_id AS policy2_node_id,
2188
    cp2.version AS policy2_version,
2189
    cp2.timelock AS policy2_timelock,
2190
    cp2.fee_ppm AS policy2_fee_ppm,
2191
    cp2.base_fee_msat AS policy2_base_fee_msat,
2192
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2193
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2194
    cp2.last_update AS policy2_last_update,
2195
    cp2.disabled AS policy2_disabled,
2196
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2197
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2198
    cp2.message_flags AS policy2_message_flags,
2199
    cp2.channel_flags AS policy2_channel_flags,
2200
    cp2.signature AS policy2_signature
2201

2202
FROM graph_channels c
2203
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2204
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2205
    LEFT JOIN graph_channel_policies cp1
2206
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2207
    LEFT JOIN graph_channel_policies cp2
2208
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2209
WHERE c.version = $1
2210
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2211
`
2212

2213
type ListChannelsByNodeIDParams struct {
2214
        Version int16
2215
        NodeID1 int64
2216
}
2217

2218
type ListChannelsByNodeIDRow struct {
2219
        GraphChannel                   GraphChannel
2220
        Node1Pubkey                    []byte
2221
        Node2Pubkey                    []byte
2222
        Policy1ID                      sql.NullInt64
2223
        Policy1NodeID                  sql.NullInt64
2224
        Policy1Version                 sql.NullInt16
2225
        Policy1Timelock                sql.NullInt32
2226
        Policy1FeePpm                  sql.NullInt64
2227
        Policy1BaseFeeMsat             sql.NullInt64
2228
        Policy1MinHtlcMsat             sql.NullInt64
2229
        Policy1MaxHtlcMsat             sql.NullInt64
2230
        Policy1LastUpdate              sql.NullInt64
2231
        Policy1Disabled                sql.NullBool
2232
        Policy1InboundBaseFeeMsat      sql.NullInt64
2233
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2234
        Policy1MessageFlags            sql.NullInt16
2235
        Policy1ChannelFlags            sql.NullInt16
2236
        Policy1Signature               []byte
2237
        Policy2ID                      sql.NullInt64
2238
        Policy2NodeID                  sql.NullInt64
2239
        Policy2Version                 sql.NullInt16
2240
        Policy2Timelock                sql.NullInt32
2241
        Policy2FeePpm                  sql.NullInt64
2242
        Policy2BaseFeeMsat             sql.NullInt64
2243
        Policy2MinHtlcMsat             sql.NullInt64
2244
        Policy2MaxHtlcMsat             sql.NullInt64
2245
        Policy2LastUpdate              sql.NullInt64
2246
        Policy2Disabled                sql.NullBool
2247
        Policy2InboundBaseFeeMsat      sql.NullInt64
2248
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2249
        Policy2MessageFlags            sql.NullInt16
2250
        Policy2ChannelFlags            sql.NullInt16
2251
        Policy2Signature               []byte
2252
}
2253

2254
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2255
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2256
        if err != nil {
×
2257
                return nil, err
×
2258
        }
×
2259
        defer rows.Close()
×
2260
        var items []ListChannelsByNodeIDRow
×
2261
        for rows.Next() {
×
2262
                var i ListChannelsByNodeIDRow
×
2263
                if err := rows.Scan(
×
2264
                        &i.GraphChannel.ID,
×
2265
                        &i.GraphChannel.Version,
×
2266
                        &i.GraphChannel.Scid,
×
2267
                        &i.GraphChannel.NodeID1,
×
2268
                        &i.GraphChannel.NodeID2,
×
2269
                        &i.GraphChannel.Outpoint,
×
2270
                        &i.GraphChannel.Capacity,
×
2271
                        &i.GraphChannel.BitcoinKey1,
×
2272
                        &i.GraphChannel.BitcoinKey2,
×
2273
                        &i.GraphChannel.Node1Signature,
×
2274
                        &i.GraphChannel.Node2Signature,
×
2275
                        &i.GraphChannel.Bitcoin1Signature,
×
2276
                        &i.GraphChannel.Bitcoin2Signature,
×
2277
                        &i.Node1Pubkey,
×
2278
                        &i.Node2Pubkey,
×
2279
                        &i.Policy1ID,
×
2280
                        &i.Policy1NodeID,
×
2281
                        &i.Policy1Version,
×
2282
                        &i.Policy1Timelock,
×
2283
                        &i.Policy1FeePpm,
×
2284
                        &i.Policy1BaseFeeMsat,
×
2285
                        &i.Policy1MinHtlcMsat,
×
2286
                        &i.Policy1MaxHtlcMsat,
×
2287
                        &i.Policy1LastUpdate,
×
2288
                        &i.Policy1Disabled,
×
2289
                        &i.Policy1InboundBaseFeeMsat,
×
2290
                        &i.Policy1InboundFeeRateMilliMsat,
×
2291
                        &i.Policy1MessageFlags,
×
2292
                        &i.Policy1ChannelFlags,
×
2293
                        &i.Policy1Signature,
×
2294
                        &i.Policy2ID,
×
2295
                        &i.Policy2NodeID,
×
2296
                        &i.Policy2Version,
×
2297
                        &i.Policy2Timelock,
×
2298
                        &i.Policy2FeePpm,
×
2299
                        &i.Policy2BaseFeeMsat,
×
2300
                        &i.Policy2MinHtlcMsat,
×
2301
                        &i.Policy2MaxHtlcMsat,
×
2302
                        &i.Policy2LastUpdate,
×
2303
                        &i.Policy2Disabled,
×
2304
                        &i.Policy2InboundBaseFeeMsat,
×
2305
                        &i.Policy2InboundFeeRateMilliMsat,
×
2306
                        &i.Policy2MessageFlags,
×
2307
                        &i.Policy2ChannelFlags,
×
2308
                        &i.Policy2Signature,
×
2309
                ); err != nil {
×
2310
                        return nil, err
×
2311
                }
×
2312
                items = append(items, i)
×
2313
        }
2314
        if err := rows.Close(); err != nil {
×
2315
                return nil, err
×
2316
        }
×
2317
        if err := rows.Err(); err != nil {
×
2318
                return nil, err
×
2319
        }
×
2320
        return items, nil
×
2321
}
2322

2323
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
2324
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
2325
FROM graph_channels c
2326
WHERE c.version = $1 AND c.id > $2
2327
ORDER BY c.id
2328
LIMIT $3
2329
`
2330

2331
type ListChannelsPaginatedParams struct {
2332
        Version int16
2333
        ID      int64
2334
        Limit   int32
2335
}
2336

2337
type ListChannelsPaginatedRow struct {
2338
        ID          int64
2339
        BitcoinKey1 []byte
2340
        BitcoinKey2 []byte
2341
        Outpoint    string
2342
}
2343

2344
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
2345
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
2346
        if err != nil {
×
2347
                return nil, err
×
2348
        }
×
2349
        defer rows.Close()
×
2350
        var items []ListChannelsPaginatedRow
×
2351
        for rows.Next() {
×
2352
                var i ListChannelsPaginatedRow
×
2353
                if err := rows.Scan(
×
2354
                        &i.ID,
×
2355
                        &i.BitcoinKey1,
×
2356
                        &i.BitcoinKey2,
×
2357
                        &i.Outpoint,
×
2358
                ); err != nil {
×
2359
                        return nil, err
×
2360
                }
×
2361
                items = append(items, i)
×
2362
        }
2363
        if err := rows.Close(); err != nil {
×
2364
                return nil, err
×
2365
        }
×
2366
        if err := rows.Err(); err != nil {
×
2367
                return nil, err
×
2368
        }
×
2369
        return items, nil
×
2370
}
2371

2372
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
2373
SELECT
2374
    c.id as id,
2375
    c.scid as scid,
2376
    c.capacity AS capacity,
2377

2378
    -- Join node pubkeys
2379
    n1.pub_key AS node1_pubkey,
2380
    n2.pub_key AS node2_pubkey,
2381

2382
    -- Node 1 policy
2383
    cp1.timelock AS policy_1_timelock,
2384
    cp1.fee_ppm AS policy_1_fee_ppm,
2385
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2386
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2387
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2388
    cp1.disabled AS policy_1_disabled,
2389
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2390
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2391
    cp1.message_flags AS policy1_message_flags,
2392
    cp1.channel_flags AS policy1_channel_flags,
2393

2394
    -- Node 2 policy
2395
    cp2.timelock AS policy_2_timelock,
2396
    cp2.fee_ppm AS policy_2_fee_ppm,
2397
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2398
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2399
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2400
    cp2.disabled AS policy_2_disabled,
2401
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2402
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2403
    cp2.message_flags AS policy2_message_flags,
2404
    cp2.channel_flags AS policy2_channel_flags
2405

2406
FROM graph_channels c
2407
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2408
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2409
LEFT JOIN graph_channel_policies cp1
2410
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2411
LEFT JOIN graph_channel_policies cp2
2412
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2413
WHERE c.version = $1 AND c.id > $2
2414
ORDER BY c.id
2415
LIMIT $3
2416
`
2417

2418
type ListChannelsWithPoliciesForCachePaginatedParams struct {
2419
        Version int16
2420
        ID      int64
2421
        Limit   int32
2422
}
2423

2424
type ListChannelsWithPoliciesForCachePaginatedRow struct {
2425
        ID                             int64
2426
        Scid                           []byte
2427
        Capacity                       sql.NullInt64
2428
        Node1Pubkey                    []byte
2429
        Node2Pubkey                    []byte
2430
        Policy1Timelock                sql.NullInt32
2431
        Policy1FeePpm                  sql.NullInt64
2432
        Policy1BaseFeeMsat             sql.NullInt64
2433
        Policy1MinHtlcMsat             sql.NullInt64
2434
        Policy1MaxHtlcMsat             sql.NullInt64
2435
        Policy1Disabled                sql.NullBool
2436
        Policy1InboundBaseFeeMsat      sql.NullInt64
2437
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2438
        Policy1MessageFlags            sql.NullInt16
2439
        Policy1ChannelFlags            sql.NullInt16
2440
        Policy2Timelock                sql.NullInt32
2441
        Policy2FeePpm                  sql.NullInt64
2442
        Policy2BaseFeeMsat             sql.NullInt64
2443
        Policy2MinHtlcMsat             sql.NullInt64
2444
        Policy2MaxHtlcMsat             sql.NullInt64
2445
        Policy2Disabled                sql.NullBool
2446
        Policy2InboundBaseFeeMsat      sql.NullInt64
2447
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2448
        Policy2MessageFlags            sql.NullInt16
2449
        Policy2ChannelFlags            sql.NullInt16
2450
}
2451

2452
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
2453
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
2454
        if err != nil {
×
2455
                return nil, err
×
2456
        }
×
2457
        defer rows.Close()
×
2458
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
2459
        for rows.Next() {
×
2460
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
2461
                if err := rows.Scan(
×
2462
                        &i.ID,
×
2463
                        &i.Scid,
×
2464
                        &i.Capacity,
×
2465
                        &i.Node1Pubkey,
×
2466
                        &i.Node2Pubkey,
×
2467
                        &i.Policy1Timelock,
×
2468
                        &i.Policy1FeePpm,
×
2469
                        &i.Policy1BaseFeeMsat,
×
2470
                        &i.Policy1MinHtlcMsat,
×
2471
                        &i.Policy1MaxHtlcMsat,
×
2472
                        &i.Policy1Disabled,
×
2473
                        &i.Policy1InboundBaseFeeMsat,
×
2474
                        &i.Policy1InboundFeeRateMilliMsat,
×
2475
                        &i.Policy1MessageFlags,
×
2476
                        &i.Policy1ChannelFlags,
×
2477
                        &i.Policy2Timelock,
×
2478
                        &i.Policy2FeePpm,
×
2479
                        &i.Policy2BaseFeeMsat,
×
2480
                        &i.Policy2MinHtlcMsat,
×
2481
                        &i.Policy2MaxHtlcMsat,
×
2482
                        &i.Policy2Disabled,
×
2483
                        &i.Policy2InboundBaseFeeMsat,
×
2484
                        &i.Policy2InboundFeeRateMilliMsat,
×
2485
                        &i.Policy2MessageFlags,
×
2486
                        &i.Policy2ChannelFlags,
×
2487
                ); err != nil {
×
2488
                        return nil, err
×
2489
                }
×
2490
                items = append(items, i)
×
2491
        }
2492
        if err := rows.Close(); err != nil {
×
2493
                return nil, err
×
2494
        }
×
2495
        if err := rows.Err(); err != nil {
×
2496
                return nil, err
×
2497
        }
×
2498
        return items, nil
×
2499
}
2500

2501
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
2502
SELECT
2503
    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,
2504

2505
    -- Join node pubkeys
2506
    n1.pub_key AS node1_pubkey,
2507
    n2.pub_key AS node2_pubkey,
2508

2509
    -- Node 1 policy
2510
    cp1.id AS policy_1_id,
2511
    cp1.node_id AS policy_1_node_id,
2512
    cp1.version AS policy_1_version,
2513
    cp1.timelock AS policy_1_timelock,
2514
    cp1.fee_ppm AS policy_1_fee_ppm,
2515
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2516
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2517
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2518
    cp1.last_update AS policy_1_last_update,
2519
    cp1.disabled AS policy_1_disabled,
2520
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2521
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2522
    cp1.message_flags AS policy1_message_flags,
2523
    cp1.channel_flags AS policy1_channel_flags,
2524
    cp1.signature AS policy_1_signature,
2525

2526
    -- Node 2 policy
2527
    cp2.id AS policy_2_id,
2528
    cp2.node_id AS policy_2_node_id,
2529
    cp2.version AS policy_2_version,
2530
    cp2.timelock AS policy_2_timelock,
2531
    cp2.fee_ppm AS policy_2_fee_ppm,
2532
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2533
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2534
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2535
    cp2.last_update AS policy_2_last_update,
2536
    cp2.disabled AS policy_2_disabled,
2537
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2538
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2539
    cp2.message_flags AS policy2_message_flags,
2540
    cp2.channel_flags AS policy2_channel_flags,
2541
    cp2.signature AS policy_2_signature
2542

2543
FROM graph_channels c
2544
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2545
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2546
LEFT JOIN graph_channel_policies cp1
2547
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2548
LEFT JOIN graph_channel_policies cp2
2549
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2550
WHERE c.version = $1 AND c.id > $2
2551
ORDER BY c.id
2552
LIMIT $3
2553
`
2554

2555
type ListChannelsWithPoliciesPaginatedParams struct {
2556
        Version int16
2557
        ID      int64
2558
        Limit   int32
2559
}
2560

2561
type ListChannelsWithPoliciesPaginatedRow struct {
2562
        GraphChannel                   GraphChannel
2563
        Node1Pubkey                    []byte
2564
        Node2Pubkey                    []byte
2565
        Policy1ID                      sql.NullInt64
2566
        Policy1NodeID                  sql.NullInt64
2567
        Policy1Version                 sql.NullInt16
2568
        Policy1Timelock                sql.NullInt32
2569
        Policy1FeePpm                  sql.NullInt64
2570
        Policy1BaseFeeMsat             sql.NullInt64
2571
        Policy1MinHtlcMsat             sql.NullInt64
2572
        Policy1MaxHtlcMsat             sql.NullInt64
2573
        Policy1LastUpdate              sql.NullInt64
2574
        Policy1Disabled                sql.NullBool
2575
        Policy1InboundBaseFeeMsat      sql.NullInt64
2576
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2577
        Policy1MessageFlags            sql.NullInt16
2578
        Policy1ChannelFlags            sql.NullInt16
2579
        Policy1Signature               []byte
2580
        Policy2ID                      sql.NullInt64
2581
        Policy2NodeID                  sql.NullInt64
2582
        Policy2Version                 sql.NullInt16
2583
        Policy2Timelock                sql.NullInt32
2584
        Policy2FeePpm                  sql.NullInt64
2585
        Policy2BaseFeeMsat             sql.NullInt64
2586
        Policy2MinHtlcMsat             sql.NullInt64
2587
        Policy2MaxHtlcMsat             sql.NullInt64
2588
        Policy2LastUpdate              sql.NullInt64
2589
        Policy2Disabled                sql.NullBool
2590
        Policy2InboundBaseFeeMsat      sql.NullInt64
2591
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2592
        Policy2MessageFlags            sql.NullInt16
2593
        Policy2ChannelFlags            sql.NullInt16
2594
        Policy2Signature               []byte
2595
}
2596

2597
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
2598
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
2599
        if err != nil {
×
2600
                return nil, err
×
2601
        }
×
2602
        defer rows.Close()
×
2603
        var items []ListChannelsWithPoliciesPaginatedRow
×
2604
        for rows.Next() {
×
2605
                var i ListChannelsWithPoliciesPaginatedRow
×
2606
                if err := rows.Scan(
×
2607
                        &i.GraphChannel.ID,
×
2608
                        &i.GraphChannel.Version,
×
2609
                        &i.GraphChannel.Scid,
×
2610
                        &i.GraphChannel.NodeID1,
×
2611
                        &i.GraphChannel.NodeID2,
×
2612
                        &i.GraphChannel.Outpoint,
×
2613
                        &i.GraphChannel.Capacity,
×
2614
                        &i.GraphChannel.BitcoinKey1,
×
2615
                        &i.GraphChannel.BitcoinKey2,
×
2616
                        &i.GraphChannel.Node1Signature,
×
2617
                        &i.GraphChannel.Node2Signature,
×
2618
                        &i.GraphChannel.Bitcoin1Signature,
×
2619
                        &i.GraphChannel.Bitcoin2Signature,
×
2620
                        &i.Node1Pubkey,
×
2621
                        &i.Node2Pubkey,
×
2622
                        &i.Policy1ID,
×
2623
                        &i.Policy1NodeID,
×
2624
                        &i.Policy1Version,
×
2625
                        &i.Policy1Timelock,
×
2626
                        &i.Policy1FeePpm,
×
2627
                        &i.Policy1BaseFeeMsat,
×
2628
                        &i.Policy1MinHtlcMsat,
×
2629
                        &i.Policy1MaxHtlcMsat,
×
2630
                        &i.Policy1LastUpdate,
×
2631
                        &i.Policy1Disabled,
×
2632
                        &i.Policy1InboundBaseFeeMsat,
×
2633
                        &i.Policy1InboundFeeRateMilliMsat,
×
2634
                        &i.Policy1MessageFlags,
×
2635
                        &i.Policy1ChannelFlags,
×
2636
                        &i.Policy1Signature,
×
2637
                        &i.Policy2ID,
×
2638
                        &i.Policy2NodeID,
×
2639
                        &i.Policy2Version,
×
2640
                        &i.Policy2Timelock,
×
2641
                        &i.Policy2FeePpm,
×
2642
                        &i.Policy2BaseFeeMsat,
×
2643
                        &i.Policy2MinHtlcMsat,
×
2644
                        &i.Policy2MaxHtlcMsat,
×
2645
                        &i.Policy2LastUpdate,
×
2646
                        &i.Policy2Disabled,
×
2647
                        &i.Policy2InboundBaseFeeMsat,
×
2648
                        &i.Policy2InboundFeeRateMilliMsat,
×
2649
                        &i.Policy2MessageFlags,
×
2650
                        &i.Policy2ChannelFlags,
×
2651
                        &i.Policy2Signature,
×
2652
                ); err != nil {
×
2653
                        return nil, err
×
2654
                }
×
2655
                items = append(items, i)
×
2656
        }
2657
        if err := rows.Close(); err != nil {
×
2658
                return nil, err
×
2659
        }
×
2660
        if err := rows.Err(); err != nil {
×
2661
                return nil, err
×
2662
        }
×
2663
        return items, nil
×
2664
}
2665

2666
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2667
SELECT id, pub_key
2668
FROM graph_nodes
2669
WHERE version = $1  AND id > $2
2670
ORDER BY id
2671
LIMIT $3
2672
`
2673

2674
type ListNodeIDsAndPubKeysParams struct {
2675
        Version int16
2676
        ID      int64
2677
        Limit   int32
2678
}
2679

2680
type ListNodeIDsAndPubKeysRow struct {
2681
        ID     int64
2682
        PubKey []byte
2683
}
2684

2685
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2686
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2687
        if err != nil {
×
2688
                return nil, err
×
2689
        }
×
2690
        defer rows.Close()
×
2691
        var items []ListNodeIDsAndPubKeysRow
×
2692
        for rows.Next() {
×
2693
                var i ListNodeIDsAndPubKeysRow
×
2694
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2695
                        return nil, err
×
2696
                }
×
2697
                items = append(items, i)
×
2698
        }
2699
        if err := rows.Close(); err != nil {
×
2700
                return nil, err
×
2701
        }
×
2702
        if err := rows.Err(); err != nil {
×
2703
                return nil, err
×
2704
        }
×
2705
        return items, nil
×
2706
}
2707

2708
const listNodesPaginated = `-- name: ListNodesPaginated :many
2709
SELECT id, version, pub_key, alias, last_update, color, signature
2710
FROM graph_nodes
2711
WHERE version = $1 AND id > $2
2712
ORDER BY id
2713
LIMIT $3
2714
`
2715

2716
type ListNodesPaginatedParams struct {
2717
        Version int16
2718
        ID      int64
2719
        Limit   int32
2720
}
2721

2722
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
2723
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2724
        if err != nil {
×
2725
                return nil, err
×
2726
        }
×
2727
        defer rows.Close()
×
2728
        var items []GraphNode
×
2729
        for rows.Next() {
×
2730
                var i GraphNode
×
2731
                if err := rows.Scan(
×
2732
                        &i.ID,
×
2733
                        &i.Version,
×
2734
                        &i.PubKey,
×
2735
                        &i.Alias,
×
2736
                        &i.LastUpdate,
×
2737
                        &i.Color,
×
2738
                        &i.Signature,
×
2739
                ); err != nil {
×
2740
                        return nil, err
×
2741
                }
×
2742
                items = append(items, i)
×
2743
        }
2744
        if err := rows.Close(); err != nil {
×
2745
                return nil, err
×
2746
        }
×
2747
        if err := rows.Err(); err != nil {
×
2748
                return nil, err
×
2749
        }
×
2750
        return items, nil
×
2751
}
2752

2753
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2754
/* ─────────────────────────────────────────────
2755
   graph_channel_policies table queries
2756
   ─────────────────────────────────────────────
2757
*/
2758

2759
INSERT INTO graph_channel_policies (
2760
    version, channel_id, node_id, timelock, fee_ppm,
2761
    base_fee_msat, min_htlc_msat, last_update, disabled,
2762
    max_htlc_msat, inbound_base_fee_msat,
2763
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2764
    signature
2765
) VALUES  (
2766
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2767
)
2768
ON CONFLICT (channel_id, node_id, version)
2769
    -- Update the following fields if a conflict occurs on channel_id,
2770
    -- node_id, and version.
2771
    DO UPDATE SET
2772
        timelock = EXCLUDED.timelock,
2773
        fee_ppm = EXCLUDED.fee_ppm,
2774
        base_fee_msat = EXCLUDED.base_fee_msat,
2775
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2776
        last_update = EXCLUDED.last_update,
2777
        disabled = EXCLUDED.disabled,
2778
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2779
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2780
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2781
        message_flags = EXCLUDED.message_flags,
2782
        channel_flags = EXCLUDED.channel_flags,
2783
        signature = EXCLUDED.signature
2784
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
2785
RETURNING id
2786
`
2787

2788
type UpsertEdgePolicyParams struct {
2789
        Version                 int16
2790
        ChannelID               int64
2791
        NodeID                  int64
2792
        Timelock                int32
2793
        FeePpm                  int64
2794
        BaseFeeMsat             int64
2795
        MinHtlcMsat             int64
2796
        LastUpdate              sql.NullInt64
2797
        Disabled                sql.NullBool
2798
        MaxHtlcMsat             sql.NullInt64
2799
        InboundBaseFeeMsat      sql.NullInt64
2800
        InboundFeeRateMilliMsat sql.NullInt64
2801
        MessageFlags            sql.NullInt16
2802
        ChannelFlags            sql.NullInt16
2803
        Signature               []byte
2804
}
2805

2806
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2807
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2808
                arg.Version,
×
2809
                arg.ChannelID,
×
2810
                arg.NodeID,
×
2811
                arg.Timelock,
×
2812
                arg.FeePpm,
×
2813
                arg.BaseFeeMsat,
×
2814
                arg.MinHtlcMsat,
×
2815
                arg.LastUpdate,
×
2816
                arg.Disabled,
×
2817
                arg.MaxHtlcMsat,
×
2818
                arg.InboundBaseFeeMsat,
×
2819
                arg.InboundFeeRateMilliMsat,
×
2820
                arg.MessageFlags,
×
2821
                arg.ChannelFlags,
×
2822
                arg.Signature,
×
2823
        )
×
2824
        var id int64
×
2825
        err := row.Scan(&id)
×
2826
        return id, err
×
2827
}
×
2828

2829
const upsertNode = `-- name: UpsertNode :one
2830
/* ─────────────────────────────────────────────
2831
   graph_nodes table queries
2832
   ───────────────────────────��─────────────────
2833
*/
2834

2835
INSERT INTO graph_nodes (
2836
    version, pub_key, alias, last_update, color, signature
2837
) VALUES (
2838
    $1, $2, $3, $4, $5, $6
2839
)
2840
ON CONFLICT (pub_key, version)
2841
    -- Update the following fields if a conflict occurs on pub_key
2842
    -- and version.
2843
    DO UPDATE SET
2844
        alias = EXCLUDED.alias,
2845
        last_update = EXCLUDED.last_update,
2846
        color = EXCLUDED.color,
2847
        signature = EXCLUDED.signature
2848
WHERE graph_nodes.last_update IS NULL
2849
    OR EXCLUDED.last_update > graph_nodes.last_update
2850
RETURNING id
2851
`
2852

2853
type UpsertNodeParams struct {
2854
        Version    int16
2855
        PubKey     []byte
2856
        Alias      sql.NullString
2857
        LastUpdate sql.NullInt64
2858
        Color      sql.NullString
2859
        Signature  []byte
2860
}
2861

2862
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2863
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2864
                arg.Version,
×
2865
                arg.PubKey,
×
2866
                arg.Alias,
×
2867
                arg.LastUpdate,
×
2868
                arg.Color,
×
2869
                arg.Signature,
×
2870
        )
×
2871
        var id int64
×
2872
        err := row.Scan(&id)
×
2873
        return id, err
×
2874
}
×
2875

2876
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2877
/* ─────────────────────────────────────────────
2878
   graph_node_extra_types table queries
2879
   ─────────────────────────────────────────────
2880
*/
2881

2882
INSERT INTO graph_node_extra_types (
2883
    node_id, type, value
2884
)
2885
VALUES ($1, $2, $3)
2886
ON CONFLICT (type, node_id)
2887
    -- Update the value if a conflict occurs on type
2888
    -- and node_id.
2889
    DO UPDATE SET value = EXCLUDED.value
2890
`
2891

2892
type UpsertNodeExtraTypeParams struct {
2893
        NodeID int64
2894
        Type   int64
2895
        Value  []byte
2896
}
2897

2898
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2899
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2900
        return err
×
2901
}
×
2902

2903
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2904
/* ───────────────────────────���─────────────────
2905
    graph_prune_log table queries
2906
    ─────────────────────────────────────────────
2907
*/
2908

2909
INSERT INTO graph_prune_log (
2910
    block_height, block_hash
2911
) VALUES (
2912
    $1, $2
2913
)
2914
ON CONFLICT(block_height) DO UPDATE SET
2915
    block_hash = EXCLUDED.block_hash
2916
`
2917

2918
type UpsertPruneLogEntryParams struct {
2919
        BlockHeight int64
2920
        BlockHash   []byte
2921
}
2922

2923
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2924
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2925
        return err
×
2926
}
×
2927

2928
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2929
/* ─────────────────────────────────────────────
2930
   graph_zombie_channels table queries
2931
   ─────────────────────────────────────────────
2932
*/
2933

2934
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
2935
VALUES ($1, $2, $3, $4)
2936
ON CONFLICT (scid, version)
2937
DO UPDATE SET
2938
    -- If a conflict exists for the SCID and version pair, then we
2939
    -- update the node keys.
2940
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
2941
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
2942
`
2943

2944
type UpsertZombieChannelParams struct {
2945
        Scid     []byte
2946
        Version  int16
2947
        NodeKey1 []byte
2948
        NodeKey2 []byte
2949
}
2950

2951
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2952
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2953
                arg.Scid,
×
2954
                arg.Version,
×
2955
                arg.NodeKey1,
×
2956
                arg.NodeKey2,
×
2957
        )
×
2958
        return err
×
2959
}
×
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