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

lightningnetwork / lnd / 16969463412

14 Aug 2025 03:23PM UTC coverage: 66.776% (-0.2%) from 66.929%
16969463412

push

github

web-flow
Merge pull request #10155 from ziggie1984/add-missing-invoice-settle-index

Add missing invoice index for native sql

135916 of 203540 relevant lines covered (66.78%)

21469.17 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

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

756
func (q *Queries) GetChannelFeaturesBatch(ctx context.Context, chanIds []int64) ([]GraphChannelFeature, error) {
×
757
        query := getChannelFeaturesBatch
×
758
        var queryParams []interface{}
×
759
        if len(chanIds) > 0 {
×
760
                for _, v := range chanIds {
×
761
                        queryParams = append(queryParams, v)
×
762
                }
×
763
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", makeQueryParams(len(queryParams), len(chanIds)), 1)
×
764
        } else {
×
765
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", "NULL", 1)
×
766
        }
×
767
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
768
        if err != nil {
×
769
                return nil, err
×
770
        }
×
771
        defer rows.Close()
×
772
        var items []GraphChannelFeature
×
773
        for rows.Next() {
×
774
                var i GraphChannelFeature
×
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

843
func (q *Queries) GetChannelPolicyExtraTypesBatch(ctx context.Context, policyIds []int64) ([]GetChannelPolicyExtraTypesBatchRow, error) {
×
844
        query := getChannelPolicyExtraTypesBatch
×
845
        var queryParams []interface{}
×
846
        if len(policyIds) > 0 {
×
847
                for _, v := range policyIds {
×
848
                        queryParams = append(queryParams, v)
×
849
                }
×
850
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", makeQueryParams(len(queryParams), len(policyIds)), 1)
×
851
        } else {
×
852
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", "NULL", 1)
×
853
        }
×
854
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
855
        if err != nil {
×
856
                return nil, err
×
857
        }
×
858
        defer rows.Close()
×
859
        var items []GetChannelPolicyExtraTypesBatchRow
×
860
        for rows.Next() {
×
861
                var i GetChannelPolicyExtraTypesBatchRow
×
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 getChannelsByIDs = `-- name: GetChannelsByIDs :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

880
    -- Minimal node data.
881
    n1.id AS node1_id,
882
    n1.pub_key AS node1_pub_key,
883
    n2.id AS node2_id,
884
    n2.pub_key AS node2_pub_key,
885

886
    -- Policy 1
887
    cp1.id AS policy1_id,
888
    cp1.node_id AS policy1_node_id,
889
    cp1.version AS policy1_version,
890
    cp1.timelock AS policy1_timelock,
891
    cp1.fee_ppm AS policy1_fee_ppm,
892
    cp1.base_fee_msat AS policy1_base_fee_msat,
893
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
894
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
895
    cp1.last_update AS policy1_last_update,
896
    cp1.disabled AS policy1_disabled,
897
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
898
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
899
    cp1.message_flags AS policy1_message_flags,
900
    cp1.channel_flags AS policy1_channel_flags,
901
    cp1.signature AS policy1_signature,
902

903
    -- Policy 2
904
    cp2.id AS policy2_id,
905
    cp2.node_id AS policy2_node_id,
906
    cp2.version AS policy2_version,
907
    cp2.timelock AS policy2_timelock,
908
    cp2.fee_ppm AS policy2_fee_ppm,
909
    cp2.base_fee_msat AS policy2_base_fee_msat,
910
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
911
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
912
    cp2.last_update AS policy2_last_update,
913
    cp2.disabled AS policy2_disabled,
914
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
915
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
916
    cp2.message_flags AS policy2_message_flags,
917
    cp2.channel_flags AS policy2_channel_flags,
918
    cp2.signature AS policy2_signature
919

920
FROM graph_channels c
921
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
922
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
923
    LEFT JOIN graph_channel_policies cp1
924
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
925
    LEFT JOIN graph_channel_policies cp2
926
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
927
WHERE c.id IN (/*SLICE:ids*/?)
928
`
929

930
type GetChannelsByIDsRow struct {
931
        GraphChannel                   GraphChannel
932
        Node1ID                        int64
933
        Node1PubKey                    []byte
934
        Node2ID                        int64
935
        Node2PubKey                    []byte
936
        Policy1ID                      sql.NullInt64
937
        Policy1NodeID                  sql.NullInt64
938
        Policy1Version                 sql.NullInt16
939
        Policy1Timelock                sql.NullInt32
940
        Policy1FeePpm                  sql.NullInt64
941
        Policy1BaseFeeMsat             sql.NullInt64
942
        Policy1MinHtlcMsat             sql.NullInt64
943
        Policy1MaxHtlcMsat             sql.NullInt64
944
        Policy1LastUpdate              sql.NullInt64
945
        Policy1Disabled                sql.NullBool
946
        Policy1InboundBaseFeeMsat      sql.NullInt64
947
        Policy1InboundFeeRateMilliMsat sql.NullInt64
948
        Policy1MessageFlags            sql.NullInt16
949
        Policy1ChannelFlags            sql.NullInt16
950
        Policy1Signature               []byte
951
        Policy2ID                      sql.NullInt64
952
        Policy2NodeID                  sql.NullInt64
953
        Policy2Version                 sql.NullInt16
954
        Policy2Timelock                sql.NullInt32
955
        Policy2FeePpm                  sql.NullInt64
956
        Policy2BaseFeeMsat             sql.NullInt64
957
        Policy2MinHtlcMsat             sql.NullInt64
958
        Policy2MaxHtlcMsat             sql.NullInt64
959
        Policy2LastUpdate              sql.NullInt64
960
        Policy2Disabled                sql.NullBool
961
        Policy2InboundBaseFeeMsat      sql.NullInt64
962
        Policy2InboundFeeRateMilliMsat sql.NullInt64
963
        Policy2MessageFlags            sql.NullInt16
964
        Policy2ChannelFlags            sql.NullInt16
965
        Policy2Signature               []byte
966
}
967

968
func (q *Queries) GetChannelsByIDs(ctx context.Context, ids []int64) ([]GetChannelsByIDsRow, error) {
×
969
        query := getChannelsByIDs
×
970
        var queryParams []interface{}
×
971
        if len(ids) > 0 {
×
972
                for _, v := range ids {
×
973
                        queryParams = append(queryParams, v)
×
974
                }
×
975
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
976
        } else {
×
977
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
978
        }
×
979
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
980
        if err != nil {
×
981
                return nil, err
×
982
        }
×
983
        defer rows.Close()
×
984
        var items []GetChannelsByIDsRow
×
985
        for rows.Next() {
×
986
                var i GetChannelsByIDsRow
×
987
                if err := rows.Scan(
×
988
                        &i.GraphChannel.ID,
×
989
                        &i.GraphChannel.Version,
×
990
                        &i.GraphChannel.Scid,
×
991
                        &i.GraphChannel.NodeID1,
×
992
                        &i.GraphChannel.NodeID2,
×
993
                        &i.GraphChannel.Outpoint,
×
994
                        &i.GraphChannel.Capacity,
×
995
                        &i.GraphChannel.BitcoinKey1,
×
996
                        &i.GraphChannel.BitcoinKey2,
×
997
                        &i.GraphChannel.Node1Signature,
×
998
                        &i.GraphChannel.Node2Signature,
×
999
                        &i.GraphChannel.Bitcoin1Signature,
×
1000
                        &i.GraphChannel.Bitcoin2Signature,
×
1001
                        &i.Node1ID,
×
1002
                        &i.Node1PubKey,
×
1003
                        &i.Node2ID,
×
1004
                        &i.Node2PubKey,
×
1005
                        &i.Policy1ID,
×
1006
                        &i.Policy1NodeID,
×
1007
                        &i.Policy1Version,
×
1008
                        &i.Policy1Timelock,
×
1009
                        &i.Policy1FeePpm,
×
1010
                        &i.Policy1BaseFeeMsat,
×
1011
                        &i.Policy1MinHtlcMsat,
×
1012
                        &i.Policy1MaxHtlcMsat,
×
1013
                        &i.Policy1LastUpdate,
×
1014
                        &i.Policy1Disabled,
×
1015
                        &i.Policy1InboundBaseFeeMsat,
×
1016
                        &i.Policy1InboundFeeRateMilliMsat,
×
1017
                        &i.Policy1MessageFlags,
×
1018
                        &i.Policy1ChannelFlags,
×
1019
                        &i.Policy1Signature,
×
1020
                        &i.Policy2ID,
×
1021
                        &i.Policy2NodeID,
×
1022
                        &i.Policy2Version,
×
1023
                        &i.Policy2Timelock,
×
1024
                        &i.Policy2FeePpm,
×
1025
                        &i.Policy2BaseFeeMsat,
×
1026
                        &i.Policy2MinHtlcMsat,
×
1027
                        &i.Policy2MaxHtlcMsat,
×
1028
                        &i.Policy2LastUpdate,
×
1029
                        &i.Policy2Disabled,
×
1030
                        &i.Policy2InboundBaseFeeMsat,
×
1031
                        &i.Policy2InboundFeeRateMilliMsat,
×
1032
                        &i.Policy2MessageFlags,
×
1033
                        &i.Policy2ChannelFlags,
×
1034
                        &i.Policy2Signature,
×
1035
                ); err != nil {
×
1036
                        return nil, err
×
1037
                }
×
1038
                items = append(items, i)
×
1039
        }
1040
        if err := rows.Close(); err != nil {
×
1041
                return nil, err
×
1042
        }
×
1043
        if err := rows.Err(); err != nil {
×
1044
                return nil, err
×
1045
        }
×
1046
        return items, nil
×
1047
}
1048

1049
const getChannelsByOutpoints = `-- name: GetChannelsByOutpoints :many
1050
SELECT
1051
    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,
1052
    n1.pub_key AS node1_pubkey,
1053
    n2.pub_key AS node2_pubkey
1054
FROM graph_channels c
1055
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1056
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1057
WHERE c.outpoint IN
1058
    (/*SLICE:outpoints*/?)
1059
`
1060

1061
type GetChannelsByOutpointsRow struct {
1062
        GraphChannel GraphChannel
1063
        Node1Pubkey  []byte
1064
        Node2Pubkey  []byte
1065
}
1066

1067
func (q *Queries) GetChannelsByOutpoints(ctx context.Context, outpoints []string) ([]GetChannelsByOutpointsRow, error) {
×
1068
        query := getChannelsByOutpoints
×
1069
        var queryParams []interface{}
×
1070
        if len(outpoints) > 0 {
×
1071
                for _, v := range outpoints {
×
1072
                        queryParams = append(queryParams, v)
×
1073
                }
×
1074
                query = strings.Replace(query, "/*SLICE:outpoints*/?", makeQueryParams(len(queryParams), len(outpoints)), 1)
×
1075
        } else {
×
1076
                query = strings.Replace(query, "/*SLICE:outpoints*/?", "NULL", 1)
×
1077
        }
×
1078
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1079
        if err != nil {
×
1080
                return nil, err
×
1081
        }
×
1082
        defer rows.Close()
×
1083
        var items []GetChannelsByOutpointsRow
×
1084
        for rows.Next() {
×
1085
                var i GetChannelsByOutpointsRow
×
1086
                if err := rows.Scan(
×
1087
                        &i.GraphChannel.ID,
×
1088
                        &i.GraphChannel.Version,
×
1089
                        &i.GraphChannel.Scid,
×
1090
                        &i.GraphChannel.NodeID1,
×
1091
                        &i.GraphChannel.NodeID2,
×
1092
                        &i.GraphChannel.Outpoint,
×
1093
                        &i.GraphChannel.Capacity,
×
1094
                        &i.GraphChannel.BitcoinKey1,
×
1095
                        &i.GraphChannel.BitcoinKey2,
×
1096
                        &i.GraphChannel.Node1Signature,
×
1097
                        &i.GraphChannel.Node2Signature,
×
1098
                        &i.GraphChannel.Bitcoin1Signature,
×
1099
                        &i.GraphChannel.Bitcoin2Signature,
×
1100
                        &i.Node1Pubkey,
×
1101
                        &i.Node2Pubkey,
×
1102
                ); err != nil {
×
1103
                        return nil, err
×
1104
                }
×
1105
                items = append(items, i)
×
1106
        }
1107
        if err := rows.Close(); err != nil {
×
1108
                return nil, err
×
1109
        }
×
1110
        if err := rows.Err(); err != nil {
×
1111
                return nil, err
×
1112
        }
×
1113
        return items, nil
×
1114
}
1115

1116
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
1117
SELECT
1118
    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,
1119
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1120
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1121

1122
    -- Policy 1 (node_id_1)
1123
    cp1.id AS policy1_id,
1124
    cp1.node_id AS policy1_node_id,
1125
    cp1.version AS policy1_version,
1126
    cp1.timelock AS policy1_timelock,
1127
    cp1.fee_ppm AS policy1_fee_ppm,
1128
    cp1.base_fee_msat AS policy1_base_fee_msat,
1129
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1130
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1131
    cp1.last_update AS policy1_last_update,
1132
    cp1.disabled AS policy1_disabled,
1133
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1134
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1135
    cp1.message_flags AS policy1_message_flags,
1136
    cp1.channel_flags AS policy1_channel_flags,
1137
    cp1.signature AS policy1_signature,
1138

1139
    -- Policy 2 (node_id_2)
1140
    cp2.id AS policy2_id,
1141
    cp2.node_id AS policy2_node_id,
1142
    cp2.version AS policy2_version,
1143
    cp2.timelock AS policy2_timelock,
1144
    cp2.fee_ppm AS policy2_fee_ppm,
1145
    cp2.base_fee_msat AS policy2_base_fee_msat,
1146
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1147
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1148
    cp2.last_update AS policy2_last_update,
1149
    cp2.disabled AS policy2_disabled,
1150
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1151
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1152
    cp2.message_flags AS policy2_message_flags,
1153
    cp2.channel_flags AS policy2_channel_flags,
1154
    cp2.signature AS policy2_signature
1155

1156
FROM graph_channels c
1157
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1158
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1159
    LEFT JOIN graph_channel_policies cp1
1160
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1161
    LEFT JOIN graph_channel_policies cp2
1162
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1163
WHERE c.version = $1
1164
  AND (
1165
       (cp1.last_update >= $2 AND cp1.last_update < $3)
1166
       OR
1167
       (cp2.last_update >= $2 AND cp2.last_update < $3)
1168
  )
1169
ORDER BY
1170
    CASE
1171
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1172
            THEN COALESCE(cp1.last_update, 0)
1173
        ELSE COALESCE(cp2.last_update, 0)
1174
        END ASC
1175
`
1176

1177
type GetChannelsByPolicyLastUpdateRangeParams struct {
1178
        Version   int16
1179
        StartTime sql.NullInt64
1180
        EndTime   sql.NullInt64
1181
}
1182

1183
type GetChannelsByPolicyLastUpdateRangeRow struct {
1184
        GraphChannel                   GraphChannel
1185
        GraphNode                      GraphNode
1186
        GraphNode_2                    GraphNode
1187
        Policy1ID                      sql.NullInt64
1188
        Policy1NodeID                  sql.NullInt64
1189
        Policy1Version                 sql.NullInt16
1190
        Policy1Timelock                sql.NullInt32
1191
        Policy1FeePpm                  sql.NullInt64
1192
        Policy1BaseFeeMsat             sql.NullInt64
1193
        Policy1MinHtlcMsat             sql.NullInt64
1194
        Policy1MaxHtlcMsat             sql.NullInt64
1195
        Policy1LastUpdate              sql.NullInt64
1196
        Policy1Disabled                sql.NullBool
1197
        Policy1InboundBaseFeeMsat      sql.NullInt64
1198
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1199
        Policy1MessageFlags            sql.NullInt16
1200
        Policy1ChannelFlags            sql.NullInt16
1201
        Policy1Signature               []byte
1202
        Policy2ID                      sql.NullInt64
1203
        Policy2NodeID                  sql.NullInt64
1204
        Policy2Version                 sql.NullInt16
1205
        Policy2Timelock                sql.NullInt32
1206
        Policy2FeePpm                  sql.NullInt64
1207
        Policy2BaseFeeMsat             sql.NullInt64
1208
        Policy2MinHtlcMsat             sql.NullInt64
1209
        Policy2MaxHtlcMsat             sql.NullInt64
1210
        Policy2LastUpdate              sql.NullInt64
1211
        Policy2Disabled                sql.NullBool
1212
        Policy2InboundBaseFeeMsat      sql.NullInt64
1213
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1214
        Policy2MessageFlags            sql.NullInt16
1215
        Policy2ChannelFlags            sql.NullInt16
1216
        Policy2Signature               []byte
1217
}
1218

1219
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
1220
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
1221
        if err != nil {
×
1222
                return nil, err
×
1223
        }
×
1224
        defer rows.Close()
×
1225
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
1226
        for rows.Next() {
×
1227
                var i GetChannelsByPolicyLastUpdateRangeRow
×
1228
                if err := rows.Scan(
×
1229
                        &i.GraphChannel.ID,
×
1230
                        &i.GraphChannel.Version,
×
1231
                        &i.GraphChannel.Scid,
×
1232
                        &i.GraphChannel.NodeID1,
×
1233
                        &i.GraphChannel.NodeID2,
×
1234
                        &i.GraphChannel.Outpoint,
×
1235
                        &i.GraphChannel.Capacity,
×
1236
                        &i.GraphChannel.BitcoinKey1,
×
1237
                        &i.GraphChannel.BitcoinKey2,
×
1238
                        &i.GraphChannel.Node1Signature,
×
1239
                        &i.GraphChannel.Node2Signature,
×
1240
                        &i.GraphChannel.Bitcoin1Signature,
×
1241
                        &i.GraphChannel.Bitcoin2Signature,
×
1242
                        &i.GraphNode.ID,
×
1243
                        &i.GraphNode.Version,
×
1244
                        &i.GraphNode.PubKey,
×
1245
                        &i.GraphNode.Alias,
×
1246
                        &i.GraphNode.LastUpdate,
×
1247
                        &i.GraphNode.Color,
×
1248
                        &i.GraphNode.Signature,
×
1249
                        &i.GraphNode_2.ID,
×
1250
                        &i.GraphNode_2.Version,
×
1251
                        &i.GraphNode_2.PubKey,
×
1252
                        &i.GraphNode_2.Alias,
×
1253
                        &i.GraphNode_2.LastUpdate,
×
1254
                        &i.GraphNode_2.Color,
×
1255
                        &i.GraphNode_2.Signature,
×
1256
                        &i.Policy1ID,
×
1257
                        &i.Policy1NodeID,
×
1258
                        &i.Policy1Version,
×
1259
                        &i.Policy1Timelock,
×
1260
                        &i.Policy1FeePpm,
×
1261
                        &i.Policy1BaseFeeMsat,
×
1262
                        &i.Policy1MinHtlcMsat,
×
1263
                        &i.Policy1MaxHtlcMsat,
×
1264
                        &i.Policy1LastUpdate,
×
1265
                        &i.Policy1Disabled,
×
1266
                        &i.Policy1InboundBaseFeeMsat,
×
1267
                        &i.Policy1InboundFeeRateMilliMsat,
×
1268
                        &i.Policy1MessageFlags,
×
1269
                        &i.Policy1ChannelFlags,
×
1270
                        &i.Policy1Signature,
×
1271
                        &i.Policy2ID,
×
1272
                        &i.Policy2NodeID,
×
1273
                        &i.Policy2Version,
×
1274
                        &i.Policy2Timelock,
×
1275
                        &i.Policy2FeePpm,
×
1276
                        &i.Policy2BaseFeeMsat,
×
1277
                        &i.Policy2MinHtlcMsat,
×
1278
                        &i.Policy2MaxHtlcMsat,
×
1279
                        &i.Policy2LastUpdate,
×
1280
                        &i.Policy2Disabled,
×
1281
                        &i.Policy2InboundBaseFeeMsat,
×
1282
                        &i.Policy2InboundFeeRateMilliMsat,
×
1283
                        &i.Policy2MessageFlags,
×
1284
                        &i.Policy2ChannelFlags,
×
1285
                        &i.Policy2Signature,
×
1286
                ); err != nil {
×
1287
                        return nil, err
×
1288
                }
×
1289
                items = append(items, i)
×
1290
        }
1291
        if err := rows.Close(); err != nil {
×
1292
                return nil, err
×
1293
        }
×
1294
        if err := rows.Err(); err != nil {
×
1295
                return nil, err
×
1296
        }
×
1297
        return items, nil
×
1298
}
1299

1300
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1301
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,
1302
    n1.pub_key AS node1_pub_key,
1303
    n2.pub_key AS node2_pub_key
1304
FROM graph_channels c
1305
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1306
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1307
WHERE scid >= $1
1308
  AND scid < $2
1309
`
1310

1311
type GetChannelsBySCIDRangeParams struct {
1312
        StartScid []byte
1313
        EndScid   []byte
1314
}
1315

1316
type GetChannelsBySCIDRangeRow struct {
1317
        GraphChannel GraphChannel
1318
        Node1PubKey  []byte
1319
        Node2PubKey  []byte
1320
}
1321

1322
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1323
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1324
        if err != nil {
×
1325
                return nil, err
×
1326
        }
×
1327
        defer rows.Close()
×
1328
        var items []GetChannelsBySCIDRangeRow
×
1329
        for rows.Next() {
×
1330
                var i GetChannelsBySCIDRangeRow
×
1331
                if err := rows.Scan(
×
1332
                        &i.GraphChannel.ID,
×
1333
                        &i.GraphChannel.Version,
×
1334
                        &i.GraphChannel.Scid,
×
1335
                        &i.GraphChannel.NodeID1,
×
1336
                        &i.GraphChannel.NodeID2,
×
1337
                        &i.GraphChannel.Outpoint,
×
1338
                        &i.GraphChannel.Capacity,
×
1339
                        &i.GraphChannel.BitcoinKey1,
×
1340
                        &i.GraphChannel.BitcoinKey2,
×
1341
                        &i.GraphChannel.Node1Signature,
×
1342
                        &i.GraphChannel.Node2Signature,
×
1343
                        &i.GraphChannel.Bitcoin1Signature,
×
1344
                        &i.GraphChannel.Bitcoin2Signature,
×
1345
                        &i.Node1PubKey,
×
1346
                        &i.Node2PubKey,
×
1347
                ); err != nil {
×
1348
                        return nil, err
×
1349
                }
×
1350
                items = append(items, i)
×
1351
        }
1352
        if err := rows.Close(); err != nil {
×
1353
                return nil, err
×
1354
        }
×
1355
        if err := rows.Err(); err != nil {
×
1356
                return nil, err
×
1357
        }
×
1358
        return items, nil
×
1359
}
1360

1361
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1362
SELECT
1363
    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,
1364
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1365
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1366

1367
    -- Policy 1
1368
    cp1.id AS policy1_id,
1369
    cp1.node_id AS policy1_node_id,
1370
    cp1.version AS policy1_version,
1371
    cp1.timelock AS policy1_timelock,
1372
    cp1.fee_ppm AS policy1_fee_ppm,
1373
    cp1.base_fee_msat AS policy1_base_fee_msat,
1374
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1375
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1376
    cp1.last_update AS policy1_last_update,
1377
    cp1.disabled AS policy1_disabled,
1378
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1379
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1380
    cp1.message_flags AS policy1_message_flags,
1381
    cp1.channel_flags AS policy1_channel_flags,
1382
    cp1.signature AS policy1_signature,
1383

1384
    -- Policy 2
1385
    cp2.id AS policy2_id,
1386
    cp2.node_id AS policy2_node_id,
1387
    cp2.version AS policy2_version,
1388
    cp2.timelock AS policy2_timelock,
1389
    cp2.fee_ppm AS policy2_fee_ppm,
1390
    cp2.base_fee_msat AS policy2_base_fee_msat,
1391
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1392
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1393
    cp2.last_update AS policy2_last_update,
1394
    cp2.disabled AS policy2_disabled,
1395
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1396
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1397
    cp2.message_flags AS policy_2_message_flags,
1398
    cp2.channel_flags AS policy_2_channel_flags,
1399
    cp2.signature AS policy2_signature
1400

1401
FROM graph_channels c
1402
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1403
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1404
    LEFT JOIN graph_channel_policies cp1
1405
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1406
    LEFT JOIN graph_channel_policies cp2
1407
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1408
WHERE
1409
    c.version = $1
1410
  AND c.scid IN (/*SLICE:scids*/?)
1411
`
1412

1413
type GetChannelsBySCIDWithPoliciesParams struct {
1414
        Version int16
1415
        Scids   [][]byte
1416
}
1417

1418
type GetChannelsBySCIDWithPoliciesRow struct {
1419
        GraphChannel                   GraphChannel
1420
        GraphNode                      GraphNode
1421
        GraphNode_2                    GraphNode
1422
        Policy1ID                      sql.NullInt64
1423
        Policy1NodeID                  sql.NullInt64
1424
        Policy1Version                 sql.NullInt16
1425
        Policy1Timelock                sql.NullInt32
1426
        Policy1FeePpm                  sql.NullInt64
1427
        Policy1BaseFeeMsat             sql.NullInt64
1428
        Policy1MinHtlcMsat             sql.NullInt64
1429
        Policy1MaxHtlcMsat             sql.NullInt64
1430
        Policy1LastUpdate              sql.NullInt64
1431
        Policy1Disabled                sql.NullBool
1432
        Policy1InboundBaseFeeMsat      sql.NullInt64
1433
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1434
        Policy1MessageFlags            sql.NullInt16
1435
        Policy1ChannelFlags            sql.NullInt16
1436
        Policy1Signature               []byte
1437
        Policy2ID                      sql.NullInt64
1438
        Policy2NodeID                  sql.NullInt64
1439
        Policy2Version                 sql.NullInt16
1440
        Policy2Timelock                sql.NullInt32
1441
        Policy2FeePpm                  sql.NullInt64
1442
        Policy2BaseFeeMsat             sql.NullInt64
1443
        Policy2MinHtlcMsat             sql.NullInt64
1444
        Policy2MaxHtlcMsat             sql.NullInt64
1445
        Policy2LastUpdate              sql.NullInt64
1446
        Policy2Disabled                sql.NullBool
1447
        Policy2InboundBaseFeeMsat      sql.NullInt64
1448
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1449
        Policy2MessageFlags            sql.NullInt16
1450
        Policy2ChannelFlags            sql.NullInt16
1451
        Policy2Signature               []byte
1452
}
1453

1454
func (q *Queries) GetChannelsBySCIDWithPolicies(ctx context.Context, arg GetChannelsBySCIDWithPoliciesParams) ([]GetChannelsBySCIDWithPoliciesRow, error) {
×
1455
        query := getChannelsBySCIDWithPolicies
×
1456
        var queryParams []interface{}
×
1457
        queryParams = append(queryParams, arg.Version)
×
1458
        if len(arg.Scids) > 0 {
×
1459
                for _, v := range arg.Scids {
×
1460
                        queryParams = append(queryParams, v)
×
1461
                }
×
1462
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1463
        } else {
×
1464
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1465
        }
×
1466
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1467
        if err != nil {
×
1468
                return nil, err
×
1469
        }
×
1470
        defer rows.Close()
×
1471
        var items []GetChannelsBySCIDWithPoliciesRow
×
1472
        for rows.Next() {
×
1473
                var i GetChannelsBySCIDWithPoliciesRow
×
1474
                if err := rows.Scan(
×
1475
                        &i.GraphChannel.ID,
×
1476
                        &i.GraphChannel.Version,
×
1477
                        &i.GraphChannel.Scid,
×
1478
                        &i.GraphChannel.NodeID1,
×
1479
                        &i.GraphChannel.NodeID2,
×
1480
                        &i.GraphChannel.Outpoint,
×
1481
                        &i.GraphChannel.Capacity,
×
1482
                        &i.GraphChannel.BitcoinKey1,
×
1483
                        &i.GraphChannel.BitcoinKey2,
×
1484
                        &i.GraphChannel.Node1Signature,
×
1485
                        &i.GraphChannel.Node2Signature,
×
1486
                        &i.GraphChannel.Bitcoin1Signature,
×
1487
                        &i.GraphChannel.Bitcoin2Signature,
×
1488
                        &i.GraphNode.ID,
×
1489
                        &i.GraphNode.Version,
×
1490
                        &i.GraphNode.PubKey,
×
1491
                        &i.GraphNode.Alias,
×
1492
                        &i.GraphNode.LastUpdate,
×
1493
                        &i.GraphNode.Color,
×
1494
                        &i.GraphNode.Signature,
×
1495
                        &i.GraphNode_2.ID,
×
1496
                        &i.GraphNode_2.Version,
×
1497
                        &i.GraphNode_2.PubKey,
×
1498
                        &i.GraphNode_2.Alias,
×
1499
                        &i.GraphNode_2.LastUpdate,
×
1500
                        &i.GraphNode_2.Color,
×
1501
                        &i.GraphNode_2.Signature,
×
1502
                        &i.Policy1ID,
×
1503
                        &i.Policy1NodeID,
×
1504
                        &i.Policy1Version,
×
1505
                        &i.Policy1Timelock,
×
1506
                        &i.Policy1FeePpm,
×
1507
                        &i.Policy1BaseFeeMsat,
×
1508
                        &i.Policy1MinHtlcMsat,
×
1509
                        &i.Policy1MaxHtlcMsat,
×
1510
                        &i.Policy1LastUpdate,
×
1511
                        &i.Policy1Disabled,
×
1512
                        &i.Policy1InboundBaseFeeMsat,
×
1513
                        &i.Policy1InboundFeeRateMilliMsat,
×
1514
                        &i.Policy1MessageFlags,
×
1515
                        &i.Policy1ChannelFlags,
×
1516
                        &i.Policy1Signature,
×
1517
                        &i.Policy2ID,
×
1518
                        &i.Policy2NodeID,
×
1519
                        &i.Policy2Version,
×
1520
                        &i.Policy2Timelock,
×
1521
                        &i.Policy2FeePpm,
×
1522
                        &i.Policy2BaseFeeMsat,
×
1523
                        &i.Policy2MinHtlcMsat,
×
1524
                        &i.Policy2MaxHtlcMsat,
×
1525
                        &i.Policy2LastUpdate,
×
1526
                        &i.Policy2Disabled,
×
1527
                        &i.Policy2InboundBaseFeeMsat,
×
1528
                        &i.Policy2InboundFeeRateMilliMsat,
×
1529
                        &i.Policy2MessageFlags,
×
1530
                        &i.Policy2ChannelFlags,
×
1531
                        &i.Policy2Signature,
×
1532
                ); err != nil {
×
1533
                        return nil, err
×
1534
                }
×
1535
                items = append(items, i)
×
1536
        }
1537
        if err := rows.Close(); err != nil {
×
1538
                return nil, err
×
1539
        }
×
1540
        if err := rows.Err(); err != nil {
×
1541
                return nil, err
×
1542
        }
×
1543
        return items, nil
×
1544
}
1545

1546
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1547
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
1548
WHERE version = $1
1549
  AND scid IN (/*SLICE:scids*/?)
1550
`
1551

1552
type GetChannelsBySCIDsParams struct {
1553
        Version int16
1554
        Scids   [][]byte
1555
}
1556

1557
func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error) {
×
1558
        query := getChannelsBySCIDs
×
1559
        var queryParams []interface{}
×
1560
        queryParams = append(queryParams, arg.Version)
×
1561
        if len(arg.Scids) > 0 {
×
1562
                for _, v := range arg.Scids {
×
1563
                        queryParams = append(queryParams, v)
×
1564
                }
×
1565
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1566
        } else {
×
1567
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1568
        }
×
1569
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1570
        if err != nil {
×
1571
                return nil, err
×
1572
        }
×
1573
        defer rows.Close()
×
1574
        var items []GraphChannel
×
1575
        for rows.Next() {
×
1576
                var i GraphChannel
×
1577
                if err := rows.Scan(
×
1578
                        &i.ID,
×
1579
                        &i.Version,
×
1580
                        &i.Scid,
×
1581
                        &i.NodeID1,
×
1582
                        &i.NodeID2,
×
1583
                        &i.Outpoint,
×
1584
                        &i.Capacity,
×
1585
                        &i.BitcoinKey1,
×
1586
                        &i.BitcoinKey2,
×
1587
                        &i.Node1Signature,
×
1588
                        &i.Node2Signature,
×
1589
                        &i.Bitcoin1Signature,
×
1590
                        &i.Bitcoin2Signature,
×
1591
                ); err != nil {
×
1592
                        return nil, err
×
1593
                }
×
1594
                items = append(items, i)
×
1595
        }
1596
        if err := rows.Close(); err != nil {
×
1597
                return nil, err
×
1598
        }
×
1599
        if err := rows.Err(); err != nil {
×
1600
                return nil, err
×
1601
        }
×
1602
        return items, nil
×
1603
}
1604

1605
const getClosedChannelsSCIDs = `-- name: GetClosedChannelsSCIDs :many
1606
SELECT scid
1607
FROM graph_closed_scids
1608
WHERE scid IN (/*SLICE:scids*/?)
1609
`
1610

1611
func (q *Queries) GetClosedChannelsSCIDs(ctx context.Context, scids [][]byte) ([][]byte, error) {
×
1612
        query := getClosedChannelsSCIDs
×
1613
        var queryParams []interface{}
×
1614
        if len(scids) > 0 {
×
1615
                for _, v := range scids {
×
1616
                        queryParams = append(queryParams, v)
×
1617
                }
×
1618
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(scids)), 1)
×
1619
        } else {
×
1620
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1621
        }
×
1622
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1623
        if err != nil {
×
1624
                return nil, err
×
1625
        }
×
1626
        defer rows.Close()
×
1627
        var items [][]byte
×
1628
        for rows.Next() {
×
1629
                var scid []byte
×
1630
                if err := rows.Scan(&scid); err != nil {
×
1631
                        return nil, err
×
1632
                }
×
1633
                items = append(items, scid)
×
1634
        }
1635
        if err := rows.Close(); err != nil {
×
1636
                return nil, err
×
1637
        }
×
1638
        if err := rows.Err(); err != nil {
×
1639
                return nil, err
×
1640
        }
×
1641
        return items, nil
×
1642
}
1643

1644
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1645
SELECT node_id, type, value
1646
FROM graph_node_extra_types
1647
WHERE node_id = $1
1648
`
1649

1650
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) {
×
1651
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1652
        if err != nil {
×
1653
                return nil, err
×
1654
        }
×
1655
        defer rows.Close()
×
1656
        var items []GraphNodeExtraType
×
1657
        for rows.Next() {
×
1658
                var i GraphNodeExtraType
×
1659
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1660
                        return nil, err
×
1661
                }
×
1662
                items = append(items, i)
×
1663
        }
1664
        if err := rows.Close(); err != nil {
×
1665
                return nil, err
×
1666
        }
×
1667
        if err := rows.Err(); err != nil {
×
1668
                return nil, err
×
1669
        }
×
1670
        return items, nil
×
1671
}
1672

1673
const getNodeAddresses = `-- name: GetNodeAddresses :many
1674
SELECT type, address
1675
FROM graph_node_addresses
1676
WHERE node_id = $1
1677
ORDER BY type ASC, position ASC
1678
`
1679

1680
type GetNodeAddressesRow struct {
1681
        Type    int16
1682
        Address string
1683
}
1684

1685
func (q *Queries) GetNodeAddresses(ctx context.Context, nodeID int64) ([]GetNodeAddressesRow, error) {
×
1686
        rows, err := q.db.QueryContext(ctx, getNodeAddresses, nodeID)
×
1687
        if err != nil {
×
1688
                return nil, err
×
1689
        }
×
1690
        defer rows.Close()
×
1691
        var items []GetNodeAddressesRow
×
1692
        for rows.Next() {
×
1693
                var i GetNodeAddressesRow
×
1694
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1695
                        return nil, err
×
1696
                }
×
1697
                items = append(items, i)
×
1698
        }
1699
        if err := rows.Close(); err != nil {
×
1700
                return nil, err
×
1701
        }
×
1702
        if err := rows.Err(); err != nil {
×
1703
                return nil, err
×
1704
        }
×
1705
        return items, nil
×
1706
}
1707

1708
const getNodeAddressesBatch = `-- name: GetNodeAddressesBatch :many
1709
SELECT node_id, type, position, address
1710
FROM graph_node_addresses
1711
WHERE node_id IN (/*SLICE:ids*/?)
1712
ORDER BY node_id, type, position
1713
`
1714

1715
func (q *Queries) GetNodeAddressesBatch(ctx context.Context, ids []int64) ([]GraphNodeAddress, error) {
×
1716
        query := getNodeAddressesBatch
×
1717
        var queryParams []interface{}
×
1718
        if len(ids) > 0 {
×
1719
                for _, v := range ids {
×
1720
                        queryParams = append(queryParams, v)
×
1721
                }
×
1722
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1723
        } else {
×
1724
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1725
        }
×
1726
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1727
        if err != nil {
×
1728
                return nil, err
×
1729
        }
×
1730
        defer rows.Close()
×
1731
        var items []GraphNodeAddress
×
1732
        for rows.Next() {
×
1733
                var i GraphNodeAddress
×
1734
                if err := rows.Scan(
×
1735
                        &i.NodeID,
×
1736
                        &i.Type,
×
1737
                        &i.Position,
×
1738
                        &i.Address,
×
1739
                ); err != nil {
×
1740
                        return nil, err
×
1741
                }
×
1742
                items = append(items, i)
×
1743
        }
1744
        if err := rows.Close(); err != nil {
×
1745
                return nil, err
×
1746
        }
×
1747
        if err := rows.Err(); err != nil {
×
1748
                return nil, err
×
1749
        }
×
1750
        return items, nil
×
1751
}
1752

1753
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1754
SELECT id, version, pub_key, alias, last_update, color, signature
1755
FROM graph_nodes
1756
WHERE pub_key = $1
1757
  AND version = $2
1758
`
1759

1760
type GetNodeByPubKeyParams struct {
1761
        PubKey  []byte
1762
        Version int16
1763
}
1764

1765
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1766
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1767
        var i GraphNode
×
1768
        err := row.Scan(
×
1769
                &i.ID,
×
1770
                &i.Version,
×
1771
                &i.PubKey,
×
1772
                &i.Alias,
×
1773
                &i.LastUpdate,
×
1774
                &i.Color,
×
1775
                &i.Signature,
×
1776
        )
×
1777
        return i, err
×
1778
}
×
1779

1780
const getNodeExtraTypesBatch = `-- name: GetNodeExtraTypesBatch :many
1781
SELECT node_id, type, value
1782
FROM graph_node_extra_types
1783
WHERE node_id IN (/*SLICE:ids*/?)
1784
ORDER BY node_id, type
1785
`
1786

1787
func (q *Queries) GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]GraphNodeExtraType, error) {
×
1788
        query := getNodeExtraTypesBatch
×
1789
        var queryParams []interface{}
×
1790
        if len(ids) > 0 {
×
1791
                for _, v := range ids {
×
1792
                        queryParams = append(queryParams, v)
×
1793
                }
×
1794
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1795
        } else {
×
1796
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1797
        }
×
1798
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1799
        if err != nil {
×
1800
                return nil, err
×
1801
        }
×
1802
        defer rows.Close()
×
1803
        var items []GraphNodeExtraType
×
1804
        for rows.Next() {
×
1805
                var i GraphNodeExtraType
×
1806
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1807
                        return nil, err
×
1808
                }
×
1809
                items = append(items, i)
×
1810
        }
1811
        if err := rows.Close(); err != nil {
×
1812
                return nil, err
×
1813
        }
×
1814
        if err := rows.Err(); err != nil {
×
1815
                return nil, err
×
1816
        }
×
1817
        return items, nil
×
1818
}
1819

1820
const getNodeFeatures = `-- name: GetNodeFeatures :many
1821
SELECT node_id, feature_bit
1822
FROM graph_node_features
1823
WHERE node_id = $1
1824
`
1825

1826
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1827
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1828
        if err != nil {
×
1829
                return nil, err
×
1830
        }
×
1831
        defer rows.Close()
×
1832
        var items []GraphNodeFeature
×
1833
        for rows.Next() {
×
1834
                var i GraphNodeFeature
×
1835
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1836
                        return nil, err
×
1837
                }
×
1838
                items = append(items, i)
×
1839
        }
1840
        if err := rows.Close(); err != nil {
×
1841
                return nil, err
×
1842
        }
×
1843
        if err := rows.Err(); err != nil {
×
1844
                return nil, err
×
1845
        }
×
1846
        return items, nil
×
1847
}
1848

1849
const getNodeFeaturesBatch = `-- name: GetNodeFeaturesBatch :many
1850
SELECT node_id, feature_bit
1851
FROM graph_node_features
1852
WHERE node_id IN (/*SLICE:ids*/?)
1853
ORDER BY node_id, feature_bit
1854
`
1855

1856
func (q *Queries) GetNodeFeaturesBatch(ctx context.Context, ids []int64) ([]GraphNodeFeature, error) {
×
1857
        query := getNodeFeaturesBatch
×
1858
        var queryParams []interface{}
×
1859
        if len(ids) > 0 {
×
1860
                for _, v := range ids {
×
1861
                        queryParams = append(queryParams, v)
×
1862
                }
×
1863
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1864
        } else {
×
1865
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1866
        }
×
1867
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1868
        if err != nil {
×
1869
                return nil, err
×
1870
        }
×
1871
        defer rows.Close()
×
1872
        var items []GraphNodeFeature
×
1873
        for rows.Next() {
×
1874
                var i GraphNodeFeature
×
1875
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1876
                        return nil, err
×
1877
                }
×
1878
                items = append(items, i)
×
1879
        }
1880
        if err := rows.Close(); err != nil {
×
1881
                return nil, err
×
1882
        }
×
1883
        if err := rows.Err(); err != nil {
×
1884
                return nil, err
×
1885
        }
×
1886
        return items, nil
×
1887
}
1888

1889
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1890
SELECT f.feature_bit
1891
FROM graph_nodes n
1892
    JOIN graph_node_features f ON f.node_id = n.id
1893
WHERE n.pub_key = $1
1894
  AND n.version = $2
1895
`
1896

1897
type GetNodeFeaturesByPubKeyParams struct {
1898
        PubKey  []byte
1899
        Version int16
1900
}
1901

1902
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1903
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1904
        if err != nil {
×
1905
                return nil, err
×
1906
        }
×
1907
        defer rows.Close()
×
1908
        var items []int32
×
1909
        for rows.Next() {
×
1910
                var feature_bit int32
×
1911
                if err := rows.Scan(&feature_bit); err != nil {
×
1912
                        return nil, err
×
1913
                }
×
1914
                items = append(items, feature_bit)
×
1915
        }
1916
        if err := rows.Close(); err != nil {
×
1917
                return nil, err
×
1918
        }
×
1919
        if err := rows.Err(); err != nil {
×
1920
                return nil, err
×
1921
        }
×
1922
        return items, nil
×
1923
}
1924

1925
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1926
SELECT id
1927
FROM graph_nodes
1928
WHERE pub_key = $1
1929
  AND version = $2
1930
`
1931

1932
type GetNodeIDByPubKeyParams struct {
1933
        PubKey  []byte
1934
        Version int16
1935
}
1936

1937
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1938
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1939
        var id int64
×
1940
        err := row.Scan(&id)
×
1941
        return id, err
×
1942
}
×
1943

1944
const getNodesByIDs = `-- name: GetNodesByIDs :many
1945
SELECT id, version, pub_key, alias, last_update, color, signature
1946
FROM graph_nodes
1947
WHERE id IN (/*SLICE:ids*/?)
1948
`
1949

1950
func (q *Queries) GetNodesByIDs(ctx context.Context, ids []int64) ([]GraphNode, error) {
×
1951
        query := getNodesByIDs
×
1952
        var queryParams []interface{}
×
1953
        if len(ids) > 0 {
×
1954
                for _, v := range ids {
×
1955
                        queryParams = append(queryParams, v)
×
1956
                }
×
1957
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1958
        } else {
×
1959
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1960
        }
×
1961
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1962
        if err != nil {
×
1963
                return nil, err
×
1964
        }
×
1965
        defer rows.Close()
×
1966
        var items []GraphNode
×
1967
        for rows.Next() {
×
1968
                var i GraphNode
×
1969
                if err := rows.Scan(
×
1970
                        &i.ID,
×
1971
                        &i.Version,
×
1972
                        &i.PubKey,
×
1973
                        &i.Alias,
×
1974
                        &i.LastUpdate,
×
1975
                        &i.Color,
×
1976
                        &i.Signature,
×
1977
                ); err != nil {
×
1978
                        return nil, err
×
1979
                }
×
1980
                items = append(items, i)
×
1981
        }
1982
        if err := rows.Close(); err != nil {
×
1983
                return nil, err
×
1984
        }
×
1985
        if err := rows.Err(); err != nil {
×
1986
                return nil, err
×
1987
        }
×
1988
        return items, nil
×
1989
}
1990

1991
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1992
SELECT id, version, pub_key, alias, last_update, color, signature
1993
FROM graph_nodes
1994
WHERE last_update >= $1
1995
  AND last_update < $2
1996
`
1997

1998
type GetNodesByLastUpdateRangeParams struct {
1999
        StartTime sql.NullInt64
2000
        EndTime   sql.NullInt64
2001
}
2002

2003
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
2004
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
2005
        if err != nil {
×
2006
                return nil, err
×
2007
        }
×
2008
        defer rows.Close()
×
2009
        var items []GraphNode
×
2010
        for rows.Next() {
×
2011
                var i GraphNode
×
2012
                if err := rows.Scan(
×
2013
                        &i.ID,
×
2014
                        &i.Version,
×
2015
                        &i.PubKey,
×
2016
                        &i.Alias,
×
2017
                        &i.LastUpdate,
×
2018
                        &i.Color,
×
2019
                        &i.Signature,
×
2020
                ); err != nil {
×
2021
                        return nil, err
×
2022
                }
×
2023
                items = append(items, i)
×
2024
        }
2025
        if err := rows.Close(); err != nil {
×
2026
                return nil, err
×
2027
        }
×
2028
        if err := rows.Err(); err != nil {
×
2029
                return nil, err
×
2030
        }
×
2031
        return items, nil
×
2032
}
2033

2034
const getPruneEntriesForHeights = `-- name: GetPruneEntriesForHeights :many
2035
SELECT block_height, block_hash
2036
FROM graph_prune_log
2037
WHERE block_height
2038
   IN (/*SLICE:heights*/?)
2039
`
2040

2041
func (q *Queries) GetPruneEntriesForHeights(ctx context.Context, heights []int64) ([]GraphPruneLog, error) {
×
2042
        query := getPruneEntriesForHeights
×
2043
        var queryParams []interface{}
×
2044
        if len(heights) > 0 {
×
2045
                for _, v := range heights {
×
2046
                        queryParams = append(queryParams, v)
×
2047
                }
×
2048
                query = strings.Replace(query, "/*SLICE:heights*/?", makeQueryParams(len(queryParams), len(heights)), 1)
×
2049
        } else {
×
2050
                query = strings.Replace(query, "/*SLICE:heights*/?", "NULL", 1)
×
2051
        }
×
2052
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2053
        if err != nil {
×
2054
                return nil, err
×
2055
        }
×
2056
        defer rows.Close()
×
2057
        var items []GraphPruneLog
×
2058
        for rows.Next() {
×
2059
                var i GraphPruneLog
×
2060
                if err := rows.Scan(&i.BlockHeight, &i.BlockHash); err != nil {
×
2061
                        return nil, err
×
2062
                }
×
2063
                items = append(items, i)
×
2064
        }
2065
        if err := rows.Close(); err != nil {
×
2066
                return nil, err
×
2067
        }
×
2068
        if err := rows.Err(); err != nil {
×
2069
                return nil, err
×
2070
        }
×
2071
        return items, nil
×
2072
}
2073

2074
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
2075
SELECT block_hash
2076
FROM graph_prune_log
2077
WHERE block_height = $1
2078
`
2079

2080
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
2081
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
2082
        var block_hash []byte
×
2083
        err := row.Scan(&block_hash)
×
2084
        return block_hash, err
×
2085
}
×
2086

2087
const getPruneTip = `-- name: GetPruneTip :one
2088
SELECT block_height, block_hash
2089
FROM graph_prune_log
2090
ORDER BY block_height DESC
2091
LIMIT 1
2092
`
2093

2094
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
2095
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
2096
        var i GraphPruneLog
×
2097
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
2098
        return i, err
×
2099
}
×
2100

2101
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
2102
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
2103
FROM graph_channels
2104
WHERE node_1_signature IS NOT NULL
2105
  AND scid >= $1
2106
  AND scid < $2
2107
`
2108

2109
type GetPublicV1ChannelsBySCIDParams struct {
2110
        StartScid []byte
2111
        EndScid   []byte
2112
}
2113

2114
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
2115
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
2116
        if err != nil {
×
2117
                return nil, err
×
2118
        }
×
2119
        defer rows.Close()
×
2120
        var items []GraphChannel
×
2121
        for rows.Next() {
×
2122
                var i GraphChannel
×
2123
                if err := rows.Scan(
×
2124
                        &i.ID,
×
2125
                        &i.Version,
×
2126
                        &i.Scid,
×
2127
                        &i.NodeID1,
×
2128
                        &i.NodeID2,
×
2129
                        &i.Outpoint,
×
2130
                        &i.Capacity,
×
2131
                        &i.BitcoinKey1,
×
2132
                        &i.BitcoinKey2,
×
2133
                        &i.Node1Signature,
×
2134
                        &i.Node2Signature,
×
2135
                        &i.Bitcoin1Signature,
×
2136
                        &i.Bitcoin2Signature,
×
2137
                ); err != nil {
×
2138
                        return nil, err
×
2139
                }
×
2140
                items = append(items, i)
×
2141
        }
2142
        if err := rows.Close(); err != nil {
×
2143
                return nil, err
×
2144
        }
×
2145
        if err := rows.Err(); err != nil {
×
2146
                return nil, err
×
2147
        }
×
2148
        return items, nil
×
2149
}
2150

2151
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
2152
SELECT scid from graph_channels
2153
WHERE outpoint = $1 AND version = $2
2154
`
2155

2156
type GetSCIDByOutpointParams struct {
2157
        Outpoint string
2158
        Version  int16
2159
}
2160

2161
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
2162
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
2163
        var scid []byte
×
2164
        err := row.Scan(&scid)
×
2165
        return scid, err
×
2166
}
×
2167

2168
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
2169
SELECT sn.node_id, n.pub_key
2170
FROM graph_source_nodes sn
2171
    JOIN graph_nodes n ON sn.node_id = n.id
2172
WHERE n.version = $1
2173
`
2174

2175
type GetSourceNodesByVersionRow struct {
2176
        NodeID int64
2177
        PubKey []byte
2178
}
2179

2180
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
2181
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
2182
        if err != nil {
×
2183
                return nil, err
×
2184
        }
×
2185
        defer rows.Close()
×
2186
        var items []GetSourceNodesByVersionRow
×
2187
        for rows.Next() {
×
2188
                var i GetSourceNodesByVersionRow
×
2189
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
2190
                        return nil, err
×
2191
                }
×
2192
                items = append(items, i)
×
2193
        }
2194
        if err := rows.Close(); err != nil {
×
2195
                return nil, err
×
2196
        }
×
2197
        if err := rows.Err(); err != nil {
×
2198
                return nil, err
×
2199
        }
×
2200
        return items, nil
×
2201
}
2202

2203
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
2204
SELECT c.scid
2205
FROM graph_channels c
2206
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2207
WHERE cp.disabled = true
2208
AND c.version = 1
2209
GROUP BY c.scid
2210
HAVING COUNT(*) > 1
2211
`
2212

2213
// NOTE: this is V1 specific since for V1, disabled is a
2214
// simple, single boolean. The proposed V2 policy
2215
// structure will have a more complex disabled bit vector
2216
// and so the query for V2 may differ.
2217
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2218
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
2219
        if err != nil {
×
2220
                return nil, err
×
2221
        }
×
2222
        defer rows.Close()
×
2223
        var items [][]byte
×
2224
        for rows.Next() {
×
2225
                var scid []byte
×
2226
                if err := rows.Scan(&scid); err != nil {
×
2227
                        return nil, err
×
2228
                }
×
2229
                items = append(items, scid)
×
2230
        }
2231
        if err := rows.Close(); err != nil {
×
2232
                return nil, err
×
2233
        }
×
2234
        if err := rows.Err(); err != nil {
×
2235
                return nil, err
×
2236
        }
×
2237
        return items, nil
×
2238
}
2239

2240
const getZombieChannel = `-- name: GetZombieChannel :one
2241
SELECT scid, version, node_key_1, node_key_2
2242
FROM graph_zombie_channels
2243
WHERE scid = $1
2244
AND version = $2
2245
`
2246

2247
type GetZombieChannelParams struct {
2248
        Scid    []byte
2249
        Version int16
2250
}
2251

2252
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
2253
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
2254
        var i GraphZombieChannel
×
2255
        err := row.Scan(
×
2256
                &i.Scid,
×
2257
                &i.Version,
×
2258
                &i.NodeKey1,
×
2259
                &i.NodeKey2,
×
2260
        )
×
2261
        return i, err
×
2262
}
×
2263

2264
const getZombieChannelsSCIDs = `-- name: GetZombieChannelsSCIDs :many
2265
SELECT scid, version, node_key_1, node_key_2
2266
FROM graph_zombie_channels
2267
WHERE version = $1
2268
  AND scid IN (/*SLICE:scids*/?)
2269
`
2270

2271
type GetZombieChannelsSCIDsParams struct {
2272
        Version int16
2273
        Scids   [][]byte
2274
}
2275

2276
func (q *Queries) GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error) {
×
2277
        query := getZombieChannelsSCIDs
×
2278
        var queryParams []interface{}
×
2279
        queryParams = append(queryParams, arg.Version)
×
2280
        if len(arg.Scids) > 0 {
×
2281
                for _, v := range arg.Scids {
×
2282
                        queryParams = append(queryParams, v)
×
2283
                }
×
2284
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
2285
        } else {
×
2286
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
2287
        }
×
2288
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2289
        if err != nil {
×
2290
                return nil, err
×
2291
        }
×
2292
        defer rows.Close()
×
2293
        var items []GraphZombieChannel
×
2294
        for rows.Next() {
×
2295
                var i GraphZombieChannel
×
2296
                if err := rows.Scan(
×
2297
                        &i.Scid,
×
2298
                        &i.Version,
×
2299
                        &i.NodeKey1,
×
2300
                        &i.NodeKey2,
×
2301
                ); err != nil {
×
2302
                        return nil, err
×
2303
                }
×
2304
                items = append(items, i)
×
2305
        }
2306
        if err := rows.Close(); err != nil {
×
2307
                return nil, err
×
2308
        }
×
2309
        if err := rows.Err(); err != nil {
×
2310
                return nil, err
×
2311
        }
×
2312
        return items, nil
×
2313
}
2314

2315
const highestSCID = `-- name: HighestSCID :one
2316
SELECT scid
2317
FROM graph_channels
2318
WHERE version = $1
2319
ORDER BY scid DESC
2320
LIMIT 1
2321
`
2322

2323
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
2324
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
2325
        var scid []byte
×
2326
        err := row.Scan(&scid)
×
2327
        return scid, err
×
2328
}
×
2329

2330
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
2331
/* ─────────────────────────────────────────────
2332
   graph_channel_policy_extra_types table queries
2333
   ─────────────────────────────────────────────
2334
*/
2335

2336
INSERT INTO graph_channel_policy_extra_types (
2337
    channel_policy_id, type, value
2338
)
2339
VALUES ($1, $2, $3)
2340
`
2341

2342
type InsertChanPolicyExtraTypeParams struct {
2343
        ChannelPolicyID int64
2344
        Type            int64
2345
        Value           []byte
2346
}
2347

2348
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
2349
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
2350
        return err
×
2351
}
×
2352

2353
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2354
/* ─────────────────────────────────────────────
2355
   graph_channel_features table queries
2356
   ─────────────────────────────────────────────
2357
*/
2358

2359
INSERT INTO graph_channel_features (
2360
    channel_id, feature_bit
2361
) VALUES (
2362
    $1, $2
2363
)
2364
`
2365

2366
type InsertChannelFeatureParams struct {
2367
        ChannelID  int64
2368
        FeatureBit int32
2369
}
2370

2371
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2372
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2373
        return err
×
2374
}
×
2375

2376
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2377
/* ─────────────────────────────────────────────
2378
   graph_closed_scid table queries
2379
   ────────────────────────────────────────────-
2380
*/
2381

2382
INSERT INTO graph_closed_scids (scid)
2383
VALUES ($1)
2384
ON CONFLICT (scid) DO NOTHING
2385
`
2386

2387
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2388
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2389
        return err
×
2390
}
×
2391

2392
const insertNodeAddress = `-- name: InsertNodeAddress :exec
2393
/* ─────────────────────────────────────────────
2394
   graph_node_addresses table queries
2395
   ───────────────────────────────────��─────────
2396
*/
2397

2398
INSERT INTO graph_node_addresses (
2399
    node_id,
2400
    type,
2401
    address,
2402
    position
2403
) VALUES (
2404
    $1, $2, $3, $4
2405
 )
2406
`
2407

2408
type InsertNodeAddressParams struct {
2409
        NodeID   int64
2410
        Type     int16
2411
        Address  string
2412
        Position int32
2413
}
2414

2415
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
2416
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
2417
                arg.NodeID,
×
2418
                arg.Type,
×
2419
                arg.Address,
×
2420
                arg.Position,
×
2421
        )
×
2422
        return err
×
2423
}
×
2424

2425
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2426
/* ─────────────────────────────────────────────
2427
   graph_node_features table queries
2428
   ─────────────────────────────────────────────
2429
*/
2430

2431
INSERT INTO graph_node_features (
2432
    node_id, feature_bit
2433
) VALUES (
2434
    $1, $2
2435
)
2436
`
2437

2438
type InsertNodeFeatureParams struct {
2439
        NodeID     int64
2440
        FeatureBit int32
2441
}
2442

2443
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2444
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2445
        return err
×
2446
}
×
2447

2448
const isClosedChannel = `-- name: IsClosedChannel :one
2449
SELECT EXISTS (
2450
    SELECT 1
2451
    FROM graph_closed_scids
2452
    WHERE scid = $1
2453
)
2454
`
2455

2456
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2457
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2458
        var exists bool
×
2459
        err := row.Scan(&exists)
×
2460
        return exists, err
×
2461
}
×
2462

2463
const isPublicV1Node = `-- name: IsPublicV1Node :one
2464
SELECT EXISTS (
2465
    SELECT 1
2466
    FROM graph_channels c
2467
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
2468
    -- NOTE: we hard-code the version here since the clauses
2469
    -- here that determine if a node is public is specific
2470
    -- to the V1 gossip protocol. In V1, a node is public
2471
    -- if it has a public channel and a public channel is one
2472
    -- where we have the set of signatures of the channel
2473
    -- announcement. It is enough to just check that we have
2474
    -- one of the signatures since we only ever set them
2475
    -- together.
2476
    WHERE c.version = 1
2477
      AND c.bitcoin_1_signature IS NOT NULL
2478
      AND n.pub_key = $1
2479
)
2480
`
2481

2482
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2483
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2484
        var exists bool
×
2485
        err := row.Scan(&exists)
×
2486
        return exists, err
×
2487
}
×
2488

2489
const isZombieChannel = `-- name: IsZombieChannel :one
2490
SELECT EXISTS (
2491
    SELECT 1
2492
    FROM graph_zombie_channels
2493
    WHERE scid = $1
2494
    AND version = $2
2495
) AS is_zombie
2496
`
2497

2498
type IsZombieChannelParams struct {
2499
        Scid    []byte
2500
        Version int16
2501
}
2502

2503
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2504
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2505
        var is_zombie bool
×
2506
        err := row.Scan(&is_zombie)
×
2507
        return is_zombie, err
×
2508
}
×
2509

2510
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2511
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,
2512
    n1.pub_key AS node1_pubkey,
2513
    n2.pub_key AS node2_pubkey,
2514

2515
    -- Policy 1
2516
    -- TODO(elle): use sqlc.embed to embed policy structs
2517
    --  once this issue is resolved:
2518
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2519
    cp1.id AS policy1_id,
2520
    cp1.node_id AS policy1_node_id,
2521
    cp1.version AS policy1_version,
2522
    cp1.timelock AS policy1_timelock,
2523
    cp1.fee_ppm AS policy1_fee_ppm,
2524
    cp1.base_fee_msat AS policy1_base_fee_msat,
2525
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2526
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2527
    cp1.last_update AS policy1_last_update,
2528
    cp1.disabled AS policy1_disabled,
2529
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2530
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2531
    cp1.message_flags AS policy1_message_flags,
2532
    cp1.channel_flags AS policy1_channel_flags,
2533
    cp1.signature AS policy1_signature,
2534

2535
       -- Policy 2
2536
    cp2.id AS policy2_id,
2537
    cp2.node_id AS policy2_node_id,
2538
    cp2.version AS policy2_version,
2539
    cp2.timelock AS policy2_timelock,
2540
    cp2.fee_ppm AS policy2_fee_ppm,
2541
    cp2.base_fee_msat AS policy2_base_fee_msat,
2542
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2543
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2544
    cp2.last_update AS policy2_last_update,
2545
    cp2.disabled AS policy2_disabled,
2546
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2547
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2548
    cp2.message_flags AS policy2_message_flags,
2549
    cp2.channel_flags AS policy2_channel_flags,
2550
    cp2.signature AS policy2_signature
2551

2552
FROM graph_channels c
2553
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2554
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2555
    LEFT JOIN graph_channel_policies cp1
2556
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2557
    LEFT JOIN graph_channel_policies cp2
2558
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2559
WHERE c.version = $1
2560
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2561
`
2562

2563
type ListChannelsByNodeIDParams struct {
2564
        Version int16
2565
        NodeID1 int64
2566
}
2567

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

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

2673
const listChannelsForNodeIDs = `-- name: ListChannelsForNodeIDs :many
2674
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,
2675
       n1.pub_key AS node1_pubkey,
2676
       n2.pub_key AS node2_pubkey,
2677

2678
       -- Policy 1
2679
       -- TODO(elle): use sqlc.embed to embed policy structs
2680
       --  once this issue is resolved:
2681
       --  https://github.com/sqlc-dev/sqlc/issues/2997
2682
       cp1.id AS policy1_id,
2683
       cp1.node_id AS policy1_node_id,
2684
       cp1.version AS policy1_version,
2685
       cp1.timelock AS policy1_timelock,
2686
       cp1.fee_ppm AS policy1_fee_ppm,
2687
       cp1.base_fee_msat AS policy1_base_fee_msat,
2688
       cp1.min_htlc_msat AS policy1_min_htlc_msat,
2689
       cp1.max_htlc_msat AS policy1_max_htlc_msat,
2690
       cp1.last_update AS policy1_last_update,
2691
       cp1.disabled AS policy1_disabled,
2692
       cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2693
       cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2694
       cp1.message_flags AS policy1_message_flags,
2695
       cp1.channel_flags AS policy1_channel_flags,
2696
       cp1.signature AS policy1_signature,
2697

2698
       -- Policy 2
2699
       cp2.id AS policy2_id,
2700
       cp2.node_id AS policy2_node_id,
2701
       cp2.version AS policy2_version,
2702
       cp2.timelock AS policy2_timelock,
2703
       cp2.fee_ppm AS policy2_fee_ppm,
2704
       cp2.base_fee_msat AS policy2_base_fee_msat,
2705
       cp2.min_htlc_msat AS policy2_min_htlc_msat,
2706
       cp2.max_htlc_msat AS policy2_max_htlc_msat,
2707
       cp2.last_update AS policy2_last_update,
2708
       cp2.disabled AS policy2_disabled,
2709
       cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2710
       cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2711
       cp2.message_flags AS policy2_message_flags,
2712
       cp2.channel_flags AS policy2_channel_flags,
2713
       cp2.signature AS policy2_signature
2714

2715
FROM graph_channels c
2716
         JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2717
         JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2718
         LEFT JOIN graph_channel_policies cp1
2719
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2720
         LEFT JOIN graph_channel_policies cp2
2721
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2722
WHERE c.version = $1
2723
  AND (c.node_id_1 IN (/*SLICE:node1_ids*/?)
2724
   OR c.node_id_2 IN (/*SLICE:node2_ids*/?))
2725
`
2726

2727
type ListChannelsForNodeIDsParams struct {
2728
        Version  int16
2729
        Node1Ids []int64
2730
        Node2Ids []int64
2731
}
2732

2733
type ListChannelsForNodeIDsRow struct {
2734
        GraphChannel                   GraphChannel
2735
        Node1Pubkey                    []byte
2736
        Node2Pubkey                    []byte
2737
        Policy1ID                      sql.NullInt64
2738
        Policy1NodeID                  sql.NullInt64
2739
        Policy1Version                 sql.NullInt16
2740
        Policy1Timelock                sql.NullInt32
2741
        Policy1FeePpm                  sql.NullInt64
2742
        Policy1BaseFeeMsat             sql.NullInt64
2743
        Policy1MinHtlcMsat             sql.NullInt64
2744
        Policy1MaxHtlcMsat             sql.NullInt64
2745
        Policy1LastUpdate              sql.NullInt64
2746
        Policy1Disabled                sql.NullBool
2747
        Policy1InboundBaseFeeMsat      sql.NullInt64
2748
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2749
        Policy1MessageFlags            sql.NullInt16
2750
        Policy1ChannelFlags            sql.NullInt16
2751
        Policy1Signature               []byte
2752
        Policy2ID                      sql.NullInt64
2753
        Policy2NodeID                  sql.NullInt64
2754
        Policy2Version                 sql.NullInt16
2755
        Policy2Timelock                sql.NullInt32
2756
        Policy2FeePpm                  sql.NullInt64
2757
        Policy2BaseFeeMsat             sql.NullInt64
2758
        Policy2MinHtlcMsat             sql.NullInt64
2759
        Policy2MaxHtlcMsat             sql.NullInt64
2760
        Policy2LastUpdate              sql.NullInt64
2761
        Policy2Disabled                sql.NullBool
2762
        Policy2InboundBaseFeeMsat      sql.NullInt64
2763
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2764
        Policy2MessageFlags            sql.NullInt16
2765
        Policy2ChannelFlags            sql.NullInt16
2766
        Policy2Signature               []byte
2767
}
2768

2769
func (q *Queries) ListChannelsForNodeIDs(ctx context.Context, arg ListChannelsForNodeIDsParams) ([]ListChannelsForNodeIDsRow, error) {
×
2770
        query := listChannelsForNodeIDs
×
2771
        var queryParams []interface{}
×
2772
        queryParams = append(queryParams, arg.Version)
×
2773
        if len(arg.Node1Ids) > 0 {
×
2774
                for _, v := range arg.Node1Ids {
×
2775
                        queryParams = append(queryParams, v)
×
2776
                }
×
2777
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", makeQueryParams(len(queryParams), len(arg.Node1Ids)), 1)
×
2778
        } else {
×
2779
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", "NULL", 1)
×
2780
        }
×
2781
        if len(arg.Node2Ids) > 0 {
×
2782
                for _, v := range arg.Node2Ids {
×
2783
                        queryParams = append(queryParams, v)
×
2784
                }
×
2785
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", makeQueryParams(len(queryParams), len(arg.Node2Ids)), 1)
×
2786
        } else {
×
2787
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", "NULL", 1)
×
2788
        }
×
2789
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2790
        if err != nil {
×
2791
                return nil, err
×
2792
        }
×
2793
        defer rows.Close()
×
2794
        var items []ListChannelsForNodeIDsRow
×
2795
        for rows.Next() {
×
2796
                var i ListChannelsForNodeIDsRow
×
2797
                if err := rows.Scan(
×
2798
                        &i.GraphChannel.ID,
×
2799
                        &i.GraphChannel.Version,
×
2800
                        &i.GraphChannel.Scid,
×
2801
                        &i.GraphChannel.NodeID1,
×
2802
                        &i.GraphChannel.NodeID2,
×
2803
                        &i.GraphChannel.Outpoint,
×
2804
                        &i.GraphChannel.Capacity,
×
2805
                        &i.GraphChannel.BitcoinKey1,
×
2806
                        &i.GraphChannel.BitcoinKey2,
×
2807
                        &i.GraphChannel.Node1Signature,
×
2808
                        &i.GraphChannel.Node2Signature,
×
2809
                        &i.GraphChannel.Bitcoin1Signature,
×
2810
                        &i.GraphChannel.Bitcoin2Signature,
×
2811
                        &i.Node1Pubkey,
×
2812
                        &i.Node2Pubkey,
×
2813
                        &i.Policy1ID,
×
2814
                        &i.Policy1NodeID,
×
2815
                        &i.Policy1Version,
×
2816
                        &i.Policy1Timelock,
×
2817
                        &i.Policy1FeePpm,
×
2818
                        &i.Policy1BaseFeeMsat,
×
2819
                        &i.Policy1MinHtlcMsat,
×
2820
                        &i.Policy1MaxHtlcMsat,
×
2821
                        &i.Policy1LastUpdate,
×
2822
                        &i.Policy1Disabled,
×
2823
                        &i.Policy1InboundBaseFeeMsat,
×
2824
                        &i.Policy1InboundFeeRateMilliMsat,
×
2825
                        &i.Policy1MessageFlags,
×
2826
                        &i.Policy1ChannelFlags,
×
2827
                        &i.Policy1Signature,
×
2828
                        &i.Policy2ID,
×
2829
                        &i.Policy2NodeID,
×
2830
                        &i.Policy2Version,
×
2831
                        &i.Policy2Timelock,
×
2832
                        &i.Policy2FeePpm,
×
2833
                        &i.Policy2BaseFeeMsat,
×
2834
                        &i.Policy2MinHtlcMsat,
×
2835
                        &i.Policy2MaxHtlcMsat,
×
2836
                        &i.Policy2LastUpdate,
×
2837
                        &i.Policy2Disabled,
×
2838
                        &i.Policy2InboundBaseFeeMsat,
×
2839
                        &i.Policy2InboundFeeRateMilliMsat,
×
2840
                        &i.Policy2MessageFlags,
×
2841
                        &i.Policy2ChannelFlags,
×
2842
                        &i.Policy2Signature,
×
2843
                ); err != nil {
×
2844
                        return nil, err
×
2845
                }
×
2846
                items = append(items, i)
×
2847
        }
2848
        if err := rows.Close(); err != nil {
×
2849
                return nil, err
×
2850
        }
×
2851
        if err := rows.Err(); err != nil {
×
2852
                return nil, err
×
2853
        }
×
2854
        return items, nil
×
2855
}
2856

2857
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
2858
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
2859
FROM graph_channels c
2860
WHERE c.version = $1 AND c.id > $2
2861
ORDER BY c.id
2862
LIMIT $3
2863
`
2864

2865
type ListChannelsPaginatedParams struct {
2866
        Version int16
2867
        ID      int64
2868
        Limit   int32
2869
}
2870

2871
type ListChannelsPaginatedRow struct {
2872
        ID          int64
2873
        BitcoinKey1 []byte
2874
        BitcoinKey2 []byte
2875
        Outpoint    string
2876
}
2877

2878
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
2879
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
2880
        if err != nil {
×
2881
                return nil, err
×
2882
        }
×
2883
        defer rows.Close()
×
2884
        var items []ListChannelsPaginatedRow
×
2885
        for rows.Next() {
×
2886
                var i ListChannelsPaginatedRow
×
2887
                if err := rows.Scan(
×
2888
                        &i.ID,
×
2889
                        &i.BitcoinKey1,
×
2890
                        &i.BitcoinKey2,
×
2891
                        &i.Outpoint,
×
2892
                ); err != nil {
×
2893
                        return nil, err
×
2894
                }
×
2895
                items = append(items, i)
×
2896
        }
2897
        if err := rows.Close(); err != nil {
×
2898
                return nil, err
×
2899
        }
×
2900
        if err := rows.Err(); err != nil {
×
2901
                return nil, err
×
2902
        }
×
2903
        return items, nil
×
2904
}
2905

2906
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
2907
SELECT
2908
    c.id as id,
2909
    c.scid as scid,
2910
    c.capacity AS capacity,
2911

2912
    -- Join node pubkeys
2913
    n1.pub_key AS node1_pubkey,
2914
    n2.pub_key AS node2_pubkey,
2915

2916
    -- Node 1 policy
2917
    cp1.timelock AS policy_1_timelock,
2918
    cp1.fee_ppm AS policy_1_fee_ppm,
2919
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2920
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2921
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2922
    cp1.disabled AS policy_1_disabled,
2923
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2924
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2925
    cp1.message_flags AS policy1_message_flags,
2926
    cp1.channel_flags AS policy1_channel_flags,
2927

2928
    -- Node 2 policy
2929
    cp2.timelock AS policy_2_timelock,
2930
    cp2.fee_ppm AS policy_2_fee_ppm,
2931
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2932
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2933
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2934
    cp2.disabled AS policy_2_disabled,
2935
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2936
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2937
    cp2.message_flags AS policy2_message_flags,
2938
    cp2.channel_flags AS policy2_channel_flags
2939

2940
FROM graph_channels c
2941
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2942
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2943
LEFT JOIN graph_channel_policies cp1
2944
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2945
LEFT JOIN graph_channel_policies cp2
2946
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2947
WHERE c.version = $1 AND c.id > $2
2948
ORDER BY c.id
2949
LIMIT $3
2950
`
2951

2952
type ListChannelsWithPoliciesForCachePaginatedParams struct {
2953
        Version int16
2954
        ID      int64
2955
        Limit   int32
2956
}
2957

2958
type ListChannelsWithPoliciesForCachePaginatedRow struct {
2959
        ID                             int64
2960
        Scid                           []byte
2961
        Capacity                       sql.NullInt64
2962
        Node1Pubkey                    []byte
2963
        Node2Pubkey                    []byte
2964
        Policy1Timelock                sql.NullInt32
2965
        Policy1FeePpm                  sql.NullInt64
2966
        Policy1BaseFeeMsat             sql.NullInt64
2967
        Policy1MinHtlcMsat             sql.NullInt64
2968
        Policy1MaxHtlcMsat             sql.NullInt64
2969
        Policy1Disabled                sql.NullBool
2970
        Policy1InboundBaseFeeMsat      sql.NullInt64
2971
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2972
        Policy1MessageFlags            sql.NullInt16
2973
        Policy1ChannelFlags            sql.NullInt16
2974
        Policy2Timelock                sql.NullInt32
2975
        Policy2FeePpm                  sql.NullInt64
2976
        Policy2BaseFeeMsat             sql.NullInt64
2977
        Policy2MinHtlcMsat             sql.NullInt64
2978
        Policy2MaxHtlcMsat             sql.NullInt64
2979
        Policy2Disabled                sql.NullBool
2980
        Policy2InboundBaseFeeMsat      sql.NullInt64
2981
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2982
        Policy2MessageFlags            sql.NullInt16
2983
        Policy2ChannelFlags            sql.NullInt16
2984
}
2985

2986
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
2987
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
2988
        if err != nil {
×
2989
                return nil, err
×
2990
        }
×
2991
        defer rows.Close()
×
2992
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
2993
        for rows.Next() {
×
2994
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
2995
                if err := rows.Scan(
×
2996
                        &i.ID,
×
2997
                        &i.Scid,
×
2998
                        &i.Capacity,
×
2999
                        &i.Node1Pubkey,
×
3000
                        &i.Node2Pubkey,
×
3001
                        &i.Policy1Timelock,
×
3002
                        &i.Policy1FeePpm,
×
3003
                        &i.Policy1BaseFeeMsat,
×
3004
                        &i.Policy1MinHtlcMsat,
×
3005
                        &i.Policy1MaxHtlcMsat,
×
3006
                        &i.Policy1Disabled,
×
3007
                        &i.Policy1InboundBaseFeeMsat,
×
3008
                        &i.Policy1InboundFeeRateMilliMsat,
×
3009
                        &i.Policy1MessageFlags,
×
3010
                        &i.Policy1ChannelFlags,
×
3011
                        &i.Policy2Timelock,
×
3012
                        &i.Policy2FeePpm,
×
3013
                        &i.Policy2BaseFeeMsat,
×
3014
                        &i.Policy2MinHtlcMsat,
×
3015
                        &i.Policy2MaxHtlcMsat,
×
3016
                        &i.Policy2Disabled,
×
3017
                        &i.Policy2InboundBaseFeeMsat,
×
3018
                        &i.Policy2InboundFeeRateMilliMsat,
×
3019
                        &i.Policy2MessageFlags,
×
3020
                        &i.Policy2ChannelFlags,
×
3021
                ); err != nil {
×
3022
                        return nil, err
×
3023
                }
×
3024
                items = append(items, i)
×
3025
        }
3026
        if err := rows.Close(); err != nil {
×
3027
                return nil, err
×
3028
        }
×
3029
        if err := rows.Err(); err != nil {
×
3030
                return nil, err
×
3031
        }
×
3032
        return items, nil
×
3033
}
3034

3035
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
3036
SELECT
3037
    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,
3038

3039
    -- Join node pubkeys
3040
    n1.pub_key AS node1_pubkey,
3041
    n2.pub_key AS node2_pubkey,
3042

3043
    -- Node 1 policy
3044
    cp1.id AS policy_1_id,
3045
    cp1.node_id AS policy_1_node_id,
3046
    cp1.version AS policy_1_version,
3047
    cp1.timelock AS policy_1_timelock,
3048
    cp1.fee_ppm AS policy_1_fee_ppm,
3049
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3050
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3051
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3052
    cp1.last_update AS policy_1_last_update,
3053
    cp1.disabled AS policy_1_disabled,
3054
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3055
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3056
    cp1.message_flags AS policy1_message_flags,
3057
    cp1.channel_flags AS policy1_channel_flags,
3058
    cp1.signature AS policy_1_signature,
3059

3060
    -- Node 2 policy
3061
    cp2.id AS policy_2_id,
3062
    cp2.node_id AS policy_2_node_id,
3063
    cp2.version AS policy_2_version,
3064
    cp2.timelock AS policy_2_timelock,
3065
    cp2.fee_ppm AS policy_2_fee_ppm,
3066
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3067
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3068
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3069
    cp2.last_update AS policy_2_last_update,
3070
    cp2.disabled AS policy_2_disabled,
3071
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3072
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3073
    cp2.message_flags AS policy2_message_flags,
3074
    cp2.channel_flags AS policy2_channel_flags,
3075
    cp2.signature AS policy_2_signature
3076

3077
FROM graph_channels c
3078
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3079
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3080
LEFT JOIN graph_channel_policies cp1
3081
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3082
LEFT JOIN graph_channel_policies cp2
3083
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3084
WHERE c.version = $1 AND c.id > $2
3085
ORDER BY c.id
3086
LIMIT $3
3087
`
3088

3089
type ListChannelsWithPoliciesPaginatedParams struct {
3090
        Version int16
3091
        ID      int64
3092
        Limit   int32
3093
}
3094

3095
type ListChannelsWithPoliciesPaginatedRow struct {
3096
        GraphChannel                   GraphChannel
3097
        Node1Pubkey                    []byte
3098
        Node2Pubkey                    []byte
3099
        Policy1ID                      sql.NullInt64
3100
        Policy1NodeID                  sql.NullInt64
3101
        Policy1Version                 sql.NullInt16
3102
        Policy1Timelock                sql.NullInt32
3103
        Policy1FeePpm                  sql.NullInt64
3104
        Policy1BaseFeeMsat             sql.NullInt64
3105
        Policy1MinHtlcMsat             sql.NullInt64
3106
        Policy1MaxHtlcMsat             sql.NullInt64
3107
        Policy1LastUpdate              sql.NullInt64
3108
        Policy1Disabled                sql.NullBool
3109
        Policy1InboundBaseFeeMsat      sql.NullInt64
3110
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3111
        Policy1MessageFlags            sql.NullInt16
3112
        Policy1ChannelFlags            sql.NullInt16
3113
        Policy1Signature               []byte
3114
        Policy2ID                      sql.NullInt64
3115
        Policy2NodeID                  sql.NullInt64
3116
        Policy2Version                 sql.NullInt16
3117
        Policy2Timelock                sql.NullInt32
3118
        Policy2FeePpm                  sql.NullInt64
3119
        Policy2BaseFeeMsat             sql.NullInt64
3120
        Policy2MinHtlcMsat             sql.NullInt64
3121
        Policy2MaxHtlcMsat             sql.NullInt64
3122
        Policy2LastUpdate              sql.NullInt64
3123
        Policy2Disabled                sql.NullBool
3124
        Policy2InboundBaseFeeMsat      sql.NullInt64
3125
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3126
        Policy2MessageFlags            sql.NullInt16
3127
        Policy2ChannelFlags            sql.NullInt16
3128
        Policy2Signature               []byte
3129
}
3130

3131
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
3132
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
3133
        if err != nil {
×
3134
                return nil, err
×
3135
        }
×
3136
        defer rows.Close()
×
3137
        var items []ListChannelsWithPoliciesPaginatedRow
×
3138
        for rows.Next() {
×
3139
                var i ListChannelsWithPoliciesPaginatedRow
×
3140
                if err := rows.Scan(
×
3141
                        &i.GraphChannel.ID,
×
3142
                        &i.GraphChannel.Version,
×
3143
                        &i.GraphChannel.Scid,
×
3144
                        &i.GraphChannel.NodeID1,
×
3145
                        &i.GraphChannel.NodeID2,
×
3146
                        &i.GraphChannel.Outpoint,
×
3147
                        &i.GraphChannel.Capacity,
×
3148
                        &i.GraphChannel.BitcoinKey1,
×
3149
                        &i.GraphChannel.BitcoinKey2,
×
3150
                        &i.GraphChannel.Node1Signature,
×
3151
                        &i.GraphChannel.Node2Signature,
×
3152
                        &i.GraphChannel.Bitcoin1Signature,
×
3153
                        &i.GraphChannel.Bitcoin2Signature,
×
3154
                        &i.Node1Pubkey,
×
3155
                        &i.Node2Pubkey,
×
3156
                        &i.Policy1ID,
×
3157
                        &i.Policy1NodeID,
×
3158
                        &i.Policy1Version,
×
3159
                        &i.Policy1Timelock,
×
3160
                        &i.Policy1FeePpm,
×
3161
                        &i.Policy1BaseFeeMsat,
×
3162
                        &i.Policy1MinHtlcMsat,
×
3163
                        &i.Policy1MaxHtlcMsat,
×
3164
                        &i.Policy1LastUpdate,
×
3165
                        &i.Policy1Disabled,
×
3166
                        &i.Policy1InboundBaseFeeMsat,
×
3167
                        &i.Policy1InboundFeeRateMilliMsat,
×
3168
                        &i.Policy1MessageFlags,
×
3169
                        &i.Policy1ChannelFlags,
×
3170
                        &i.Policy1Signature,
×
3171
                        &i.Policy2ID,
×
3172
                        &i.Policy2NodeID,
×
3173
                        &i.Policy2Version,
×
3174
                        &i.Policy2Timelock,
×
3175
                        &i.Policy2FeePpm,
×
3176
                        &i.Policy2BaseFeeMsat,
×
3177
                        &i.Policy2MinHtlcMsat,
×
3178
                        &i.Policy2MaxHtlcMsat,
×
3179
                        &i.Policy2LastUpdate,
×
3180
                        &i.Policy2Disabled,
×
3181
                        &i.Policy2InboundBaseFeeMsat,
×
3182
                        &i.Policy2InboundFeeRateMilliMsat,
×
3183
                        &i.Policy2MessageFlags,
×
3184
                        &i.Policy2ChannelFlags,
×
3185
                        &i.Policy2Signature,
×
3186
                ); err != nil {
×
3187
                        return nil, err
×
3188
                }
×
3189
                items = append(items, i)
×
3190
        }
3191
        if err := rows.Close(); err != nil {
×
3192
                return nil, err
×
3193
        }
×
3194
        if err := rows.Err(); err != nil {
×
3195
                return nil, err
×
3196
        }
×
3197
        return items, nil
×
3198
}
3199

3200
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
3201
SELECT id, pub_key
3202
FROM graph_nodes
3203
WHERE version = $1  AND id > $2
3204
ORDER BY id
3205
LIMIT $3
3206
`
3207

3208
type ListNodeIDsAndPubKeysParams struct {
3209
        Version int16
3210
        ID      int64
3211
        Limit   int32
3212
}
3213

3214
type ListNodeIDsAndPubKeysRow struct {
3215
        ID     int64
3216
        PubKey []byte
3217
}
3218

3219
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
3220
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
3221
        if err != nil {
×
3222
                return nil, err
×
3223
        }
×
3224
        defer rows.Close()
×
3225
        var items []ListNodeIDsAndPubKeysRow
×
3226
        for rows.Next() {
×
3227
                var i ListNodeIDsAndPubKeysRow
×
3228
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
3229
                        return nil, err
×
3230
                }
×
3231
                items = append(items, i)
×
3232
        }
3233
        if err := rows.Close(); err != nil {
×
3234
                return nil, err
×
3235
        }
×
3236
        if err := rows.Err(); err != nil {
×
3237
                return nil, err
×
3238
        }
×
3239
        return items, nil
×
3240
}
3241

3242
const listNodesPaginated = `-- name: ListNodesPaginated :many
3243
SELECT id, version, pub_key, alias, last_update, color, signature
3244
FROM graph_nodes
3245
WHERE version = $1 AND id > $2
3246
ORDER BY id
3247
LIMIT $3
3248
`
3249

3250
type ListNodesPaginatedParams struct {
3251
        Version int16
3252
        ID      int64
3253
        Limit   int32
3254
}
3255

3256
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
3257
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
3258
        if err != nil {
×
3259
                return nil, err
×
3260
        }
×
3261
        defer rows.Close()
×
3262
        var items []GraphNode
×
3263
        for rows.Next() {
×
3264
                var i GraphNode
×
3265
                if err := rows.Scan(
×
3266
                        &i.ID,
×
3267
                        &i.Version,
×
3268
                        &i.PubKey,
×
3269
                        &i.Alias,
×
3270
                        &i.LastUpdate,
×
3271
                        &i.Color,
×
3272
                        &i.Signature,
×
3273
                ); err != nil {
×
3274
                        return nil, err
×
3275
                }
×
3276
                items = append(items, i)
×
3277
        }
3278
        if err := rows.Close(); err != nil {
×
3279
                return nil, err
×
3280
        }
×
3281
        if err := rows.Err(); err != nil {
×
3282
                return nil, err
×
3283
        }
×
3284
        return items, nil
×
3285
}
3286

3287
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
3288
/* ─────────────────────────────────────────────
3289
   graph_channel_policies table queries
3290
   ─────────────────────────────────────────────
3291
*/
3292

3293
INSERT INTO graph_channel_policies (
3294
    version, channel_id, node_id, timelock, fee_ppm,
3295
    base_fee_msat, min_htlc_msat, last_update, disabled,
3296
    max_htlc_msat, inbound_base_fee_msat,
3297
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
3298
    signature
3299
) VALUES  (
3300
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
3301
)
3302
ON CONFLICT (channel_id, node_id, version)
3303
    -- Update the following fields if a conflict occurs on channel_id,
3304
    -- node_id, and version.
3305
    DO UPDATE SET
3306
        timelock = EXCLUDED.timelock,
3307
        fee_ppm = EXCLUDED.fee_ppm,
3308
        base_fee_msat = EXCLUDED.base_fee_msat,
3309
        min_htlc_msat = EXCLUDED.min_htlc_msat,
3310
        last_update = EXCLUDED.last_update,
3311
        disabled = EXCLUDED.disabled,
3312
        max_htlc_msat = EXCLUDED.max_htlc_msat,
3313
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
3314
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
3315
        message_flags = EXCLUDED.message_flags,
3316
        channel_flags = EXCLUDED.channel_flags,
3317
        signature = EXCLUDED.signature
3318
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
3319
RETURNING id
3320
`
3321

3322
type UpsertEdgePolicyParams struct {
3323
        Version                 int16
3324
        ChannelID               int64
3325
        NodeID                  int64
3326
        Timelock                int32
3327
        FeePpm                  int64
3328
        BaseFeeMsat             int64
3329
        MinHtlcMsat             int64
3330
        LastUpdate              sql.NullInt64
3331
        Disabled                sql.NullBool
3332
        MaxHtlcMsat             sql.NullInt64
3333
        InboundBaseFeeMsat      sql.NullInt64
3334
        InboundFeeRateMilliMsat sql.NullInt64
3335
        MessageFlags            sql.NullInt16
3336
        ChannelFlags            sql.NullInt16
3337
        Signature               []byte
3338
}
3339

3340
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
3341
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
3342
                arg.Version,
×
3343
                arg.ChannelID,
×
3344
                arg.NodeID,
×
3345
                arg.Timelock,
×
3346
                arg.FeePpm,
×
3347
                arg.BaseFeeMsat,
×
3348
                arg.MinHtlcMsat,
×
3349
                arg.LastUpdate,
×
3350
                arg.Disabled,
×
3351
                arg.MaxHtlcMsat,
×
3352
                arg.InboundBaseFeeMsat,
×
3353
                arg.InboundFeeRateMilliMsat,
×
3354
                arg.MessageFlags,
×
3355
                arg.ChannelFlags,
×
3356
                arg.Signature,
×
3357
        )
×
3358
        var id int64
×
3359
        err := row.Scan(&id)
×
3360
        return id, err
×
3361
}
×
3362

3363
const upsertNode = `-- name: UpsertNode :one
3364
/* ─────────────────────────────────────────────
3365
   graph_nodes table queries
3366
   ───────────────────────────��─────────────────
3367
*/
3368

3369
INSERT INTO graph_nodes (
3370
    version, pub_key, alias, last_update, color, signature
3371
) VALUES (
3372
    $1, $2, $3, $4, $5, $6
3373
)
3374
ON CONFLICT (pub_key, version)
3375
    -- Update the following fields if a conflict occurs on pub_key
3376
    -- and version.
3377
    DO UPDATE SET
3378
        alias = EXCLUDED.alias,
3379
        last_update = EXCLUDED.last_update,
3380
        color = EXCLUDED.color,
3381
        signature = EXCLUDED.signature
3382
WHERE graph_nodes.last_update IS NULL
3383
    OR EXCLUDED.last_update > graph_nodes.last_update
3384
RETURNING id
3385
`
3386

3387
type UpsertNodeParams struct {
3388
        Version    int16
3389
        PubKey     []byte
3390
        Alias      sql.NullString
3391
        LastUpdate sql.NullInt64
3392
        Color      sql.NullString
3393
        Signature  []byte
3394
}
3395

3396
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
3397
        row := q.db.QueryRowContext(ctx, upsertNode,
×
3398
                arg.Version,
×
3399
                arg.PubKey,
×
3400
                arg.Alias,
×
3401
                arg.LastUpdate,
×
3402
                arg.Color,
×
3403
                arg.Signature,
×
3404
        )
×
3405
        var id int64
×
3406
        err := row.Scan(&id)
×
3407
        return id, err
×
3408
}
×
3409

3410
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
3411
/* ─────────────────────────────────────────────
3412
   graph_node_extra_types table queries
3413
   ─────────────────────────────────────────────
3414
*/
3415

3416
INSERT INTO graph_node_extra_types (
3417
    node_id, type, value
3418
)
3419
VALUES ($1, $2, $3)
3420
ON CONFLICT (type, node_id)
3421
    -- Update the value if a conflict occurs on type
3422
    -- and node_id.
3423
    DO UPDATE SET value = EXCLUDED.value
3424
`
3425

3426
type UpsertNodeExtraTypeParams struct {
3427
        NodeID int64
3428
        Type   int64
3429
        Value  []byte
3430
}
3431

3432
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
3433
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
3434
        return err
×
3435
}
×
3436

3437
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
3438
/* ───────────────────────────���─────────────────
3439
    graph_prune_log table queries
3440
    ─────────────────────────────────────────────
3441
*/
3442

3443
INSERT INTO graph_prune_log (
3444
    block_height, block_hash
3445
) VALUES (
3446
    $1, $2
3447
)
3448
ON CONFLICT(block_height) DO UPDATE SET
3449
    block_hash = EXCLUDED.block_hash
3450
`
3451

3452
type UpsertPruneLogEntryParams struct {
3453
        BlockHeight int64
3454
        BlockHash   []byte
3455
}
3456

3457
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
3458
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
3459
        return err
×
3460
}
×
3461

3462
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
3463
/* ─────────────────────────────────────────────
3464
   graph_zombie_channels table queries
3465
   ─────────────────────────────────────────────
3466
*/
3467

3468
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
3469
VALUES ($1, $2, $3, $4)
3470
ON CONFLICT (scid, version)
3471
DO UPDATE SET
3472
    -- If a conflict exists for the SCID and version pair, then we
3473
    -- update the node keys.
3474
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
3475
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
3476
`
3477

3478
type UpsertZombieChannelParams struct {
3479
        Scid     []byte
3480
        Version  int16
3481
        NodeKey1 []byte
3482
        NodeKey2 []byte
3483
}
3484

3485
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
3486
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
3487
                arg.Scid,
×
3488
                arg.Version,
×
3489
                arg.NodeKey1,
×
3490
                arg.NodeKey2,
×
3491
        )
×
3492
        return err
×
3493
}
×
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