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

lightningnetwork / lnd / 16629470050

30 Jul 2025 05:27PM UTC coverage: 67.181% (+0.1%) from 67.054%
16629470050

push

github

web-flow
Merge pull request #10113 from ellemouton/graphPerf2

[1] graph/db: add some SQL performance improvements

0 of 123 new or added lines in 2 files covered. (0.0%)

45 existing lines in 17 files now uncovered.

135567 of 201794 relevant lines covered (67.18%)

21670.7 hits per line

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

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

6
package sqlc
7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

714
UNION ALL
715

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1476
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1477
SELECT id, version, pub_key, alias, last_update, color, signature
1478
FROM graph_nodes
1479
WHERE pub_key = $1
1480
  AND version = $2
1481
`
1482

1483
type GetNodeByPubKeyParams struct {
1484
        PubKey  []byte
1485
        Version int16
1486
}
1487

1488
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1489
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1490
        var i GraphNode
×
1491
        err := row.Scan(
×
1492
                &i.ID,
×
1493
                &i.Version,
×
1494
                &i.PubKey,
×
1495
                &i.Alias,
×
1496
                &i.LastUpdate,
×
1497
                &i.Color,
×
1498
                &i.Signature,
×
1499
        )
×
1500
        return i, err
×
1501
}
×
1502

1503
const getNodeFeatures = `-- name: GetNodeFeatures :many
1504
SELECT node_id, feature_bit
1505
FROM graph_node_features
1506
WHERE node_id = $1
1507
`
1508

1509
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1510
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1511
        if err != nil {
×
1512
                return nil, err
×
1513
        }
×
1514
        defer rows.Close()
×
1515
        var items []GraphNodeFeature
×
1516
        for rows.Next() {
×
1517
                var i GraphNodeFeature
×
1518
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1519
                        return nil, err
×
1520
                }
×
1521
                items = append(items, i)
×
1522
        }
1523
        if err := rows.Close(); err != nil {
×
1524
                return nil, err
×
1525
        }
×
1526
        if err := rows.Err(); err != nil {
×
1527
                return nil, err
×
1528
        }
×
1529
        return items, nil
×
1530
}
1531

1532
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1533
SELECT f.feature_bit
1534
FROM graph_nodes n
1535
    JOIN graph_node_features f ON f.node_id = n.id
1536
WHERE n.pub_key = $1
1537
  AND n.version = $2
1538
`
1539

1540
type GetNodeFeaturesByPubKeyParams struct {
1541
        PubKey  []byte
1542
        Version int16
1543
}
1544

1545
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1546
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1547
        if err != nil {
×
1548
                return nil, err
×
1549
        }
×
1550
        defer rows.Close()
×
1551
        var items []int32
×
1552
        for rows.Next() {
×
1553
                var feature_bit int32
×
1554
                if err := rows.Scan(&feature_bit); err != nil {
×
1555
                        return nil, err
×
1556
                }
×
1557
                items = append(items, feature_bit)
×
1558
        }
1559
        if err := rows.Close(); err != nil {
×
1560
                return nil, err
×
1561
        }
×
1562
        if err := rows.Err(); err != nil {
×
1563
                return nil, err
×
1564
        }
×
1565
        return items, nil
×
1566
}
1567

1568
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1569
SELECT id
1570
FROM graph_nodes
1571
WHERE pub_key = $1
1572
  AND version = $2
1573
`
1574

1575
type GetNodeIDByPubKeyParams struct {
1576
        PubKey  []byte
1577
        Version int16
1578
}
1579

1580
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1581
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1582
        var id int64
×
1583
        err := row.Scan(&id)
×
1584
        return id, err
×
1585
}
×
1586

1587
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1588
SELECT id, version, pub_key, alias, last_update, color, signature
1589
FROM graph_nodes
1590
WHERE last_update >= $1
1591
  AND last_update < $2
1592
`
1593

1594
type GetNodesByLastUpdateRangeParams struct {
1595
        StartTime sql.NullInt64
1596
        EndTime   sql.NullInt64
1597
}
1598

1599
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
1600
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1601
        if err != nil {
×
1602
                return nil, err
×
1603
        }
×
1604
        defer rows.Close()
×
1605
        var items []GraphNode
×
1606
        for rows.Next() {
×
1607
                var i GraphNode
×
1608
                if err := rows.Scan(
×
1609
                        &i.ID,
×
1610
                        &i.Version,
×
1611
                        &i.PubKey,
×
1612
                        &i.Alias,
×
1613
                        &i.LastUpdate,
×
1614
                        &i.Color,
×
1615
                        &i.Signature,
×
1616
                ); err != nil {
×
1617
                        return nil, err
×
1618
                }
×
1619
                items = append(items, i)
×
1620
        }
1621
        if err := rows.Close(); err != nil {
×
1622
                return nil, err
×
1623
        }
×
1624
        if err := rows.Err(); err != nil {
×
1625
                return nil, err
×
1626
        }
×
1627
        return items, nil
×
1628
}
1629

1630
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
1631
SELECT block_hash
1632
FROM graph_prune_log
1633
WHERE block_height = $1
1634
`
1635

1636
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
1637
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
1638
        var block_hash []byte
×
1639
        err := row.Scan(&block_hash)
×
1640
        return block_hash, err
×
1641
}
×
1642

1643
const getPruneTip = `-- name: GetPruneTip :one
1644
SELECT block_height, block_hash
1645
FROM graph_prune_log
1646
ORDER BY block_height DESC
1647
LIMIT 1
1648
`
1649

1650
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
1651
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1652
        var i GraphPruneLog
×
1653
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1654
        return i, err
×
1655
}
×
1656

1657
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1658
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
1659
FROM graph_channels
1660
WHERE node_1_signature IS NOT NULL
1661
  AND scid >= $1
1662
  AND scid < $2
1663
`
1664

1665
type GetPublicV1ChannelsBySCIDParams struct {
1666
        StartScid []byte
1667
        EndScid   []byte
1668
}
1669

1670
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
1671
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1672
        if err != nil {
×
1673
                return nil, err
×
1674
        }
×
1675
        defer rows.Close()
×
1676
        var items []GraphChannel
×
1677
        for rows.Next() {
×
1678
                var i GraphChannel
×
1679
                if err := rows.Scan(
×
1680
                        &i.ID,
×
1681
                        &i.Version,
×
1682
                        &i.Scid,
×
1683
                        &i.NodeID1,
×
1684
                        &i.NodeID2,
×
1685
                        &i.Outpoint,
×
1686
                        &i.Capacity,
×
1687
                        &i.BitcoinKey1,
×
1688
                        &i.BitcoinKey2,
×
1689
                        &i.Node1Signature,
×
1690
                        &i.Node2Signature,
×
1691
                        &i.Bitcoin1Signature,
×
1692
                        &i.Bitcoin2Signature,
×
1693
                ); err != nil {
×
1694
                        return nil, err
×
1695
                }
×
1696
                items = append(items, i)
×
1697
        }
1698
        if err := rows.Close(); err != nil {
×
1699
                return nil, err
×
1700
        }
×
1701
        if err := rows.Err(); err != nil {
×
1702
                return nil, err
×
1703
        }
×
1704
        return items, nil
×
1705
}
1706

1707
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1708
SELECT scid from graph_channels
1709
WHERE outpoint = $1 AND version = $2
1710
`
1711

1712
type GetSCIDByOutpointParams struct {
1713
        Outpoint string
1714
        Version  int16
1715
}
1716

1717
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1718
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1719
        var scid []byte
×
1720
        err := row.Scan(&scid)
×
1721
        return scid, err
×
1722
}
×
1723

1724
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1725
SELECT sn.node_id, n.pub_key
1726
FROM graph_source_nodes sn
1727
    JOIN graph_nodes n ON sn.node_id = n.id
1728
WHERE n.version = $1
1729
`
1730

1731
type GetSourceNodesByVersionRow struct {
1732
        NodeID int64
1733
        PubKey []byte
1734
}
1735

1736
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1737
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1738
        if err != nil {
×
1739
                return nil, err
×
1740
        }
×
1741
        defer rows.Close()
×
1742
        var items []GetSourceNodesByVersionRow
×
1743
        for rows.Next() {
×
1744
                var i GetSourceNodesByVersionRow
×
1745
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1746
                        return nil, err
×
1747
                }
×
1748
                items = append(items, i)
×
1749
        }
1750
        if err := rows.Close(); err != nil {
×
1751
                return nil, err
×
1752
        }
×
1753
        if err := rows.Err(); err != nil {
×
1754
                return nil, err
×
1755
        }
×
1756
        return items, nil
×
1757
}
1758

1759
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1760
SELECT c.scid
1761
FROM graph_channels c
1762
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
1763
WHERE cp.disabled = true
1764
AND c.version = 1
1765
GROUP BY c.scid
1766
HAVING COUNT(*) > 1
1767
`
1768

1769
// NOTE: this is V1 specific since for V1, disabled is a
1770
// simple, single boolean. The proposed V2 policy
1771
// structure will have a more complex disabled bit vector
1772
// and so the query for V2 may differ.
1773
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1774
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1775
        if err != nil {
×
1776
                return nil, err
×
1777
        }
×
1778
        defer rows.Close()
×
1779
        var items [][]byte
×
1780
        for rows.Next() {
×
1781
                var scid []byte
×
1782
                if err := rows.Scan(&scid); err != nil {
×
1783
                        return nil, err
×
1784
                }
×
1785
                items = append(items, scid)
×
1786
        }
1787
        if err := rows.Close(); err != nil {
×
1788
                return nil, err
×
1789
        }
×
1790
        if err := rows.Err(); err != nil {
×
1791
                return nil, err
×
1792
        }
×
1793
        return items, nil
×
1794
}
1795

1796
const getZombieChannel = `-- name: GetZombieChannel :one
1797
SELECT scid, version, node_key_1, node_key_2
1798
FROM graph_zombie_channels
1799
WHERE scid = $1
1800
AND version = $2
1801
`
1802

1803
type GetZombieChannelParams struct {
1804
        Scid    []byte
1805
        Version int16
1806
}
1807

1808
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
1809
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1810
        var i GraphZombieChannel
×
1811
        err := row.Scan(
×
1812
                &i.Scid,
×
1813
                &i.Version,
×
1814
                &i.NodeKey1,
×
1815
                &i.NodeKey2,
×
1816
        )
×
1817
        return i, err
×
1818
}
×
1819

1820
const highestSCID = `-- name: HighestSCID :one
1821
SELECT scid
1822
FROM graph_channels
1823
WHERE version = $1
1824
ORDER BY scid DESC
1825
LIMIT 1
1826
`
1827

1828
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1829
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1830
        var scid []byte
×
1831
        err := row.Scan(&scid)
×
1832
        return scid, err
×
1833
}
×
1834

1835
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1836
/* ─────────────────────────────────────────────
1837
   graph_channel_policy_extra_types table queries
1838
   ─────────────────────────────────────────────
1839
*/
1840

1841
INSERT INTO graph_channel_policy_extra_types (
1842
    channel_policy_id, type, value
1843
)
1844
VALUES ($1, $2, $3)
1845
`
1846

1847
type InsertChanPolicyExtraTypeParams struct {
1848
        ChannelPolicyID int64
1849
        Type            int64
1850
        Value           []byte
1851
}
1852

1853
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1854
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1855
        return err
×
1856
}
×
1857

1858
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1859
/* ─────────────────────────────────────────────
1860
   graph_channel_features table queries
1861
   ─────────────────────────────────────────────
1862
*/
1863

1864
INSERT INTO graph_channel_features (
1865
    channel_id, feature_bit
1866
) VALUES (
1867
    $1, $2
1868
)
1869
`
1870

1871
type InsertChannelFeatureParams struct {
1872
        ChannelID  int64
1873
        FeatureBit int32
1874
}
1875

1876
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1877
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1878
        return err
×
1879
}
×
1880

1881
const insertClosedChannel = `-- name: InsertClosedChannel :exec
1882
/* ─────────────────────────────────────────────
1883
   graph_closed_scid table queries
1884
   ────────────────────────────────────────────-
1885
*/
1886

1887
INSERT INTO graph_closed_scids (scid)
1888
VALUES ($1)
1889
ON CONFLICT (scid) DO NOTHING
1890
`
1891

1892
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
1893
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
1894
        return err
×
1895
}
×
1896

1897
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1898
/* ─────────────────────────────────────────────
1899
   graph_node_addresses table queries
1900
   ───────────────────────────────────��─────────
1901
*/
1902

1903
INSERT INTO graph_node_addresses (
1904
    node_id,
1905
    type,
1906
    address,
1907
    position
1908
) VALUES (
1909
    $1, $2, $3, $4
1910
 )
1911
`
1912

1913
type InsertNodeAddressParams struct {
1914
        NodeID   int64
1915
        Type     int16
1916
        Address  string
1917
        Position int32
1918
}
1919

1920
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1921
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1922
                arg.NodeID,
×
1923
                arg.Type,
×
1924
                arg.Address,
×
1925
                arg.Position,
×
1926
        )
×
1927
        return err
×
1928
}
×
1929

1930
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1931
/* ─────────────────────────────────────────────
1932
   graph_node_features table queries
1933
   ─────────────────────────────────────────────
1934
*/
1935

1936
INSERT INTO graph_node_features (
1937
    node_id, feature_bit
1938
) VALUES (
1939
    $1, $2
1940
)
1941
`
1942

1943
type InsertNodeFeatureParams struct {
1944
        NodeID     int64
1945
        FeatureBit int32
1946
}
1947

1948
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1949
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1950
        return err
×
1951
}
×
1952

1953
const isClosedChannel = `-- name: IsClosedChannel :one
1954
SELECT EXISTS (
1955
    SELECT 1
1956
    FROM graph_closed_scids
1957
    WHERE scid = $1
1958
)
1959
`
1960

1961
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
1962
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
1963
        var exists bool
×
1964
        err := row.Scan(&exists)
×
1965
        return exists, err
×
1966
}
×
1967

1968
const isPublicV1Node = `-- name: IsPublicV1Node :one
1969
SELECT EXISTS (
1970
    SELECT 1
1971
    FROM graph_channels c
1972
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1973
    -- NOTE: we hard-code the version here since the clauses
1974
    -- here that determine if a node is public is specific
1975
    -- to the V1 gossip protocol. In V1, a node is public
1976
    -- if it has a public channel and a public channel is one
1977
    -- where we have the set of signatures of the channel
1978
    -- announcement. It is enough to just check that we have
1979
    -- one of the signatures since we only ever set them
1980
    -- together.
1981
    WHERE c.version = 1
1982
      AND c.bitcoin_1_signature IS NOT NULL
1983
      AND n.pub_key = $1
1984
)
1985
`
1986

1987
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
1988
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
1989
        var exists bool
×
1990
        err := row.Scan(&exists)
×
1991
        return exists, err
×
1992
}
×
1993

1994
const isZombieChannel = `-- name: IsZombieChannel :one
1995
SELECT EXISTS (
1996
    SELECT 1
1997
    FROM graph_zombie_channels
1998
    WHERE scid = $1
1999
    AND version = $2
2000
) AS is_zombie
2001
`
2002

2003
type IsZombieChannelParams struct {
2004
        Scid    []byte
2005
        Version int16
2006
}
2007

2008
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2009
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2010
        var is_zombie bool
×
2011
        err := row.Scan(&is_zombie)
×
2012
        return is_zombie, err
×
2013
}
×
2014

2015
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2016
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,
2017
    n1.pub_key AS node1_pubkey,
2018
    n2.pub_key AS node2_pubkey,
2019

2020
    -- Policy 1
2021
    -- TODO(elle): use sqlc.embed to embed policy structs
2022
    --  once this issue is resolved:
2023
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2024
    cp1.id AS policy1_id,
2025
    cp1.node_id AS policy1_node_id,
2026
    cp1.version AS policy1_version,
2027
    cp1.timelock AS policy1_timelock,
2028
    cp1.fee_ppm AS policy1_fee_ppm,
2029
    cp1.base_fee_msat AS policy1_base_fee_msat,
2030
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2031
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2032
    cp1.last_update AS policy1_last_update,
2033
    cp1.disabled AS policy1_disabled,
2034
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2035
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2036
    cp1.message_flags AS policy1_message_flags,
2037
    cp1.channel_flags AS policy1_channel_flags,
2038
    cp1.signature AS policy1_signature,
2039

2040
       -- Policy 2
2041
    cp2.id AS policy2_id,
2042
    cp2.node_id AS policy2_node_id,
2043
    cp2.version AS policy2_version,
2044
    cp2.timelock AS policy2_timelock,
2045
    cp2.fee_ppm AS policy2_fee_ppm,
2046
    cp2.base_fee_msat AS policy2_base_fee_msat,
2047
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2048
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2049
    cp2.last_update AS policy2_last_update,
2050
    cp2.disabled AS policy2_disabled,
2051
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2052
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2053
    cp2.message_flags AS policy2_message_flags,
2054
    cp2.channel_flags AS policy2_channel_flags,
2055
    cp2.signature AS policy2_signature
2056

2057
FROM graph_channels c
2058
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2059
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2060
    LEFT JOIN graph_channel_policies cp1
2061
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2062
    LEFT JOIN graph_channel_policies cp2
2063
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2064
WHERE c.version = $1
2065
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2066
`
2067

2068
type ListChannelsByNodeIDParams struct {
2069
        Version int16
2070
        NodeID1 int64
2071
}
2072

2073
type ListChannelsByNodeIDRow struct {
2074
        GraphChannel                   GraphChannel
2075
        Node1Pubkey                    []byte
2076
        Node2Pubkey                    []byte
2077
        Policy1ID                      sql.NullInt64
2078
        Policy1NodeID                  sql.NullInt64
2079
        Policy1Version                 sql.NullInt16
2080
        Policy1Timelock                sql.NullInt32
2081
        Policy1FeePpm                  sql.NullInt64
2082
        Policy1BaseFeeMsat             sql.NullInt64
2083
        Policy1MinHtlcMsat             sql.NullInt64
2084
        Policy1MaxHtlcMsat             sql.NullInt64
2085
        Policy1LastUpdate              sql.NullInt64
2086
        Policy1Disabled                sql.NullBool
2087
        Policy1InboundBaseFeeMsat      sql.NullInt64
2088
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2089
        Policy1MessageFlags            sql.NullInt16
2090
        Policy1ChannelFlags            sql.NullInt16
2091
        Policy1Signature               []byte
2092
        Policy2ID                      sql.NullInt64
2093
        Policy2NodeID                  sql.NullInt64
2094
        Policy2Version                 sql.NullInt16
2095
        Policy2Timelock                sql.NullInt32
2096
        Policy2FeePpm                  sql.NullInt64
2097
        Policy2BaseFeeMsat             sql.NullInt64
2098
        Policy2MinHtlcMsat             sql.NullInt64
2099
        Policy2MaxHtlcMsat             sql.NullInt64
2100
        Policy2LastUpdate              sql.NullInt64
2101
        Policy2Disabled                sql.NullBool
2102
        Policy2InboundBaseFeeMsat      sql.NullInt64
2103
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2104
        Policy2MessageFlags            sql.NullInt16
2105
        Policy2ChannelFlags            sql.NullInt16
2106
        Policy2Signature               []byte
2107
}
2108

2109
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2110
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2111
        if err != nil {
×
2112
                return nil, err
×
2113
        }
×
2114
        defer rows.Close()
×
2115
        var items []ListChannelsByNodeIDRow
×
2116
        for rows.Next() {
×
2117
                var i ListChannelsByNodeIDRow
×
2118
                if err := rows.Scan(
×
2119
                        &i.GraphChannel.ID,
×
2120
                        &i.GraphChannel.Version,
×
2121
                        &i.GraphChannel.Scid,
×
2122
                        &i.GraphChannel.NodeID1,
×
2123
                        &i.GraphChannel.NodeID2,
×
2124
                        &i.GraphChannel.Outpoint,
×
2125
                        &i.GraphChannel.Capacity,
×
2126
                        &i.GraphChannel.BitcoinKey1,
×
2127
                        &i.GraphChannel.BitcoinKey2,
×
2128
                        &i.GraphChannel.Node1Signature,
×
2129
                        &i.GraphChannel.Node2Signature,
×
2130
                        &i.GraphChannel.Bitcoin1Signature,
×
2131
                        &i.GraphChannel.Bitcoin2Signature,
×
2132
                        &i.Node1Pubkey,
×
2133
                        &i.Node2Pubkey,
×
2134
                        &i.Policy1ID,
×
2135
                        &i.Policy1NodeID,
×
2136
                        &i.Policy1Version,
×
2137
                        &i.Policy1Timelock,
×
2138
                        &i.Policy1FeePpm,
×
2139
                        &i.Policy1BaseFeeMsat,
×
2140
                        &i.Policy1MinHtlcMsat,
×
2141
                        &i.Policy1MaxHtlcMsat,
×
2142
                        &i.Policy1LastUpdate,
×
2143
                        &i.Policy1Disabled,
×
2144
                        &i.Policy1InboundBaseFeeMsat,
×
2145
                        &i.Policy1InboundFeeRateMilliMsat,
×
2146
                        &i.Policy1MessageFlags,
×
2147
                        &i.Policy1ChannelFlags,
×
2148
                        &i.Policy1Signature,
×
2149
                        &i.Policy2ID,
×
2150
                        &i.Policy2NodeID,
×
2151
                        &i.Policy2Version,
×
2152
                        &i.Policy2Timelock,
×
2153
                        &i.Policy2FeePpm,
×
2154
                        &i.Policy2BaseFeeMsat,
×
2155
                        &i.Policy2MinHtlcMsat,
×
2156
                        &i.Policy2MaxHtlcMsat,
×
2157
                        &i.Policy2LastUpdate,
×
2158
                        &i.Policy2Disabled,
×
2159
                        &i.Policy2InboundBaseFeeMsat,
×
2160
                        &i.Policy2InboundFeeRateMilliMsat,
×
2161
                        &i.Policy2MessageFlags,
×
2162
                        &i.Policy2ChannelFlags,
×
2163
                        &i.Policy2Signature,
×
2164
                ); err != nil {
×
2165
                        return nil, err
×
2166
                }
×
2167
                items = append(items, i)
×
2168
        }
2169
        if err := rows.Close(); err != nil {
×
2170
                return nil, err
×
2171
        }
×
2172
        if err := rows.Err(); err != nil {
×
2173
                return nil, err
×
2174
        }
×
2175
        return items, nil
×
2176
}
2177

2178
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
2179
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
2180
FROM graph_channels c
2181
WHERE c.version = $1 AND c.id > $2
2182
ORDER BY c.id
2183
LIMIT $3
2184
`
2185

2186
type ListChannelsPaginatedParams struct {
2187
        Version int16
2188
        ID      int64
2189
        Limit   int32
2190
}
2191

2192
type ListChannelsPaginatedRow struct {
2193
        ID          int64
2194
        BitcoinKey1 []byte
2195
        BitcoinKey2 []byte
2196
        Outpoint    string
2197
}
2198

2199
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
2200
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
2201
        if err != nil {
×
2202
                return nil, err
×
2203
        }
×
2204
        defer rows.Close()
×
2205
        var items []ListChannelsPaginatedRow
×
2206
        for rows.Next() {
×
2207
                var i ListChannelsPaginatedRow
×
2208
                if err := rows.Scan(
×
2209
                        &i.ID,
×
2210
                        &i.BitcoinKey1,
×
2211
                        &i.BitcoinKey2,
×
2212
                        &i.Outpoint,
×
2213
                ); err != nil {
×
2214
                        return nil, err
×
2215
                }
×
2216
                items = append(items, i)
×
2217
        }
2218
        if err := rows.Close(); err != nil {
×
2219
                return nil, err
×
2220
        }
×
2221
        if err := rows.Err(); err != nil {
×
2222
                return nil, err
×
2223
        }
×
2224
        return items, nil
×
2225
}
2226

2227
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
2228
SELECT
2229
    c.id as id,
2230
    c.scid as scid,
2231
    c.capacity AS capacity,
2232

2233
    -- Join node pubkeys
2234
    n1.pub_key AS node1_pubkey,
2235
    n2.pub_key AS node2_pubkey,
2236

2237
    -- Node 1 policy
2238
    cp1.timelock AS policy_1_timelock,
2239
    cp1.fee_ppm AS policy_1_fee_ppm,
2240
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2241
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2242
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2243
    cp1.disabled AS policy_1_disabled,
2244
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2245
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2246
    cp1.message_flags AS policy1_message_flags,
2247
    cp1.channel_flags AS policy1_channel_flags,
2248

2249
    -- Node 2 policy
2250
    cp2.timelock AS policy_2_timelock,
2251
    cp2.fee_ppm AS policy_2_fee_ppm,
2252
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2253
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2254
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2255
    cp2.disabled AS policy_2_disabled,
2256
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2257
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2258
    cp2.message_flags AS policy2_message_flags,
2259
    cp2.channel_flags AS policy2_channel_flags
2260

2261
FROM graph_channels c
2262
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2263
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2264
LEFT JOIN graph_channel_policies cp1
2265
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2266
LEFT JOIN graph_channel_policies cp2
2267
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2268
WHERE c.version = $1 AND c.id > $2
2269
ORDER BY c.id
2270
LIMIT $3
2271
`
2272

2273
type ListChannelsWithPoliciesForCachePaginatedParams struct {
2274
        Version int16
2275
        ID      int64
2276
        Limit   int32
2277
}
2278

2279
type ListChannelsWithPoliciesForCachePaginatedRow struct {
2280
        ID                             int64
2281
        Scid                           []byte
2282
        Capacity                       sql.NullInt64
2283
        Node1Pubkey                    []byte
2284
        Node2Pubkey                    []byte
2285
        Policy1Timelock                sql.NullInt32
2286
        Policy1FeePpm                  sql.NullInt64
2287
        Policy1BaseFeeMsat             sql.NullInt64
2288
        Policy1MinHtlcMsat             sql.NullInt64
2289
        Policy1MaxHtlcMsat             sql.NullInt64
2290
        Policy1Disabled                sql.NullBool
2291
        Policy1InboundBaseFeeMsat      sql.NullInt64
2292
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2293
        Policy1MessageFlags            sql.NullInt16
2294
        Policy1ChannelFlags            sql.NullInt16
2295
        Policy2Timelock                sql.NullInt32
2296
        Policy2FeePpm                  sql.NullInt64
2297
        Policy2BaseFeeMsat             sql.NullInt64
2298
        Policy2MinHtlcMsat             sql.NullInt64
2299
        Policy2MaxHtlcMsat             sql.NullInt64
2300
        Policy2Disabled                sql.NullBool
2301
        Policy2InboundBaseFeeMsat      sql.NullInt64
2302
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2303
        Policy2MessageFlags            sql.NullInt16
2304
        Policy2ChannelFlags            sql.NullInt16
2305
}
2306

NEW
2307
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
NEW
2308
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
NEW
2309
        if err != nil {
×
NEW
2310
                return nil, err
×
NEW
2311
        }
×
NEW
2312
        defer rows.Close()
×
NEW
2313
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
NEW
2314
        for rows.Next() {
×
NEW
2315
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
NEW
2316
                if err := rows.Scan(
×
NEW
2317
                        &i.ID,
×
NEW
2318
                        &i.Scid,
×
NEW
2319
                        &i.Capacity,
×
NEW
2320
                        &i.Node1Pubkey,
×
NEW
2321
                        &i.Node2Pubkey,
×
NEW
2322
                        &i.Policy1Timelock,
×
NEW
2323
                        &i.Policy1FeePpm,
×
NEW
2324
                        &i.Policy1BaseFeeMsat,
×
NEW
2325
                        &i.Policy1MinHtlcMsat,
×
NEW
2326
                        &i.Policy1MaxHtlcMsat,
×
NEW
2327
                        &i.Policy1Disabled,
×
NEW
2328
                        &i.Policy1InboundBaseFeeMsat,
×
NEW
2329
                        &i.Policy1InboundFeeRateMilliMsat,
×
NEW
2330
                        &i.Policy1MessageFlags,
×
NEW
2331
                        &i.Policy1ChannelFlags,
×
NEW
2332
                        &i.Policy2Timelock,
×
NEW
2333
                        &i.Policy2FeePpm,
×
NEW
2334
                        &i.Policy2BaseFeeMsat,
×
NEW
2335
                        &i.Policy2MinHtlcMsat,
×
NEW
2336
                        &i.Policy2MaxHtlcMsat,
×
NEW
2337
                        &i.Policy2Disabled,
×
NEW
2338
                        &i.Policy2InboundBaseFeeMsat,
×
NEW
2339
                        &i.Policy2InboundFeeRateMilliMsat,
×
NEW
2340
                        &i.Policy2MessageFlags,
×
NEW
2341
                        &i.Policy2ChannelFlags,
×
NEW
2342
                ); err != nil {
×
NEW
2343
                        return nil, err
×
NEW
2344
                }
×
NEW
2345
                items = append(items, i)
×
2346
        }
NEW
2347
        if err := rows.Close(); err != nil {
×
NEW
2348
                return nil, err
×
NEW
2349
        }
×
NEW
2350
        if err := rows.Err(); err != nil {
×
NEW
2351
                return nil, err
×
NEW
2352
        }
×
NEW
2353
        return items, nil
×
2354
}
2355

2356
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
2357
SELECT
2358
    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,
2359

2360
    -- Join node pubkeys
2361
    n1.pub_key AS node1_pubkey,
2362
    n2.pub_key AS node2_pubkey,
2363

2364
    -- Node 1 policy
2365
    cp1.id AS policy_1_id,
2366
    cp1.node_id AS policy_1_node_id,
2367
    cp1.version AS policy_1_version,
2368
    cp1.timelock AS policy_1_timelock,
2369
    cp1.fee_ppm AS policy_1_fee_ppm,
2370
    cp1.base_fee_msat AS policy_1_base_fee_msat,
2371
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
2372
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
2373
    cp1.last_update AS policy_1_last_update,
2374
    cp1.disabled AS policy_1_disabled,
2375
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2376
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2377
    cp1.message_flags AS policy1_message_flags,
2378
    cp1.channel_flags AS policy1_channel_flags,
2379
    cp1.signature AS policy_1_signature,
2380

2381
    -- Node 2 policy
2382
    cp2.id AS policy_2_id,
2383
    cp2.node_id AS policy_2_node_id,
2384
    cp2.version AS policy_2_version,
2385
    cp2.timelock AS policy_2_timelock,
2386
    cp2.fee_ppm AS policy_2_fee_ppm,
2387
    cp2.base_fee_msat AS policy_2_base_fee_msat,
2388
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
2389
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
2390
    cp2.last_update AS policy_2_last_update,
2391
    cp2.disabled AS policy_2_disabled,
2392
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2393
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2394
    cp2.message_flags AS policy2_message_flags,
2395
    cp2.channel_flags AS policy2_channel_flags,
2396
    cp2.signature AS policy_2_signature
2397

2398
FROM graph_channels c
2399
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2400
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2401
LEFT JOIN graph_channel_policies cp1
2402
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2403
LEFT JOIN graph_channel_policies cp2
2404
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2405
WHERE c.version = $1 AND c.id > $2
2406
ORDER BY c.id
2407
LIMIT $3
2408
`
2409

2410
type ListChannelsWithPoliciesPaginatedParams struct {
2411
        Version int16
2412
        ID      int64
2413
        Limit   int32
2414
}
2415

2416
type ListChannelsWithPoliciesPaginatedRow struct {
2417
        GraphChannel                   GraphChannel
2418
        Node1Pubkey                    []byte
2419
        Node2Pubkey                    []byte
2420
        Policy1ID                      sql.NullInt64
2421
        Policy1NodeID                  sql.NullInt64
2422
        Policy1Version                 sql.NullInt16
2423
        Policy1Timelock                sql.NullInt32
2424
        Policy1FeePpm                  sql.NullInt64
2425
        Policy1BaseFeeMsat             sql.NullInt64
2426
        Policy1MinHtlcMsat             sql.NullInt64
2427
        Policy1MaxHtlcMsat             sql.NullInt64
2428
        Policy1LastUpdate              sql.NullInt64
2429
        Policy1Disabled                sql.NullBool
2430
        Policy1InboundBaseFeeMsat      sql.NullInt64
2431
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2432
        Policy1MessageFlags            sql.NullInt16
2433
        Policy1ChannelFlags            sql.NullInt16
2434
        Policy1Signature               []byte
2435
        Policy2ID                      sql.NullInt64
2436
        Policy2NodeID                  sql.NullInt64
2437
        Policy2Version                 sql.NullInt16
2438
        Policy2Timelock                sql.NullInt32
2439
        Policy2FeePpm                  sql.NullInt64
2440
        Policy2BaseFeeMsat             sql.NullInt64
2441
        Policy2MinHtlcMsat             sql.NullInt64
2442
        Policy2MaxHtlcMsat             sql.NullInt64
2443
        Policy2LastUpdate              sql.NullInt64
2444
        Policy2Disabled                sql.NullBool
2445
        Policy2InboundBaseFeeMsat      sql.NullInt64
2446
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2447
        Policy2MessageFlags            sql.NullInt16
2448
        Policy2ChannelFlags            sql.NullInt16
2449
        Policy2Signature               []byte
2450
}
2451

2452
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
2453
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
2454
        if err != nil {
×
2455
                return nil, err
×
2456
        }
×
2457
        defer rows.Close()
×
2458
        var items []ListChannelsWithPoliciesPaginatedRow
×
2459
        for rows.Next() {
×
2460
                var i ListChannelsWithPoliciesPaginatedRow
×
2461
                if err := rows.Scan(
×
2462
                        &i.GraphChannel.ID,
×
2463
                        &i.GraphChannel.Version,
×
2464
                        &i.GraphChannel.Scid,
×
2465
                        &i.GraphChannel.NodeID1,
×
2466
                        &i.GraphChannel.NodeID2,
×
2467
                        &i.GraphChannel.Outpoint,
×
2468
                        &i.GraphChannel.Capacity,
×
2469
                        &i.GraphChannel.BitcoinKey1,
×
2470
                        &i.GraphChannel.BitcoinKey2,
×
2471
                        &i.GraphChannel.Node1Signature,
×
2472
                        &i.GraphChannel.Node2Signature,
×
2473
                        &i.GraphChannel.Bitcoin1Signature,
×
2474
                        &i.GraphChannel.Bitcoin2Signature,
×
2475
                        &i.Node1Pubkey,
×
2476
                        &i.Node2Pubkey,
×
2477
                        &i.Policy1ID,
×
2478
                        &i.Policy1NodeID,
×
2479
                        &i.Policy1Version,
×
2480
                        &i.Policy1Timelock,
×
2481
                        &i.Policy1FeePpm,
×
2482
                        &i.Policy1BaseFeeMsat,
×
2483
                        &i.Policy1MinHtlcMsat,
×
2484
                        &i.Policy1MaxHtlcMsat,
×
2485
                        &i.Policy1LastUpdate,
×
2486
                        &i.Policy1Disabled,
×
2487
                        &i.Policy1InboundBaseFeeMsat,
×
2488
                        &i.Policy1InboundFeeRateMilliMsat,
×
2489
                        &i.Policy1MessageFlags,
×
2490
                        &i.Policy1ChannelFlags,
×
2491
                        &i.Policy1Signature,
×
2492
                        &i.Policy2ID,
×
2493
                        &i.Policy2NodeID,
×
2494
                        &i.Policy2Version,
×
2495
                        &i.Policy2Timelock,
×
2496
                        &i.Policy2FeePpm,
×
2497
                        &i.Policy2BaseFeeMsat,
×
2498
                        &i.Policy2MinHtlcMsat,
×
2499
                        &i.Policy2MaxHtlcMsat,
×
2500
                        &i.Policy2LastUpdate,
×
2501
                        &i.Policy2Disabled,
×
2502
                        &i.Policy2InboundBaseFeeMsat,
×
2503
                        &i.Policy2InboundFeeRateMilliMsat,
×
2504
                        &i.Policy2MessageFlags,
×
2505
                        &i.Policy2ChannelFlags,
×
2506
                        &i.Policy2Signature,
×
2507
                ); err != nil {
×
2508
                        return nil, err
×
2509
                }
×
2510
                items = append(items, i)
×
2511
        }
2512
        if err := rows.Close(); err != nil {
×
2513
                return nil, err
×
2514
        }
×
2515
        if err := rows.Err(); err != nil {
×
2516
                return nil, err
×
2517
        }
×
2518
        return items, nil
×
2519
}
2520

2521
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2522
SELECT id, pub_key
2523
FROM graph_nodes
2524
WHERE version = $1  AND id > $2
2525
ORDER BY id
2526
LIMIT $3
2527
`
2528

2529
type ListNodeIDsAndPubKeysParams struct {
2530
        Version int16
2531
        ID      int64
2532
        Limit   int32
2533
}
2534

2535
type ListNodeIDsAndPubKeysRow struct {
2536
        ID     int64
2537
        PubKey []byte
2538
}
2539

2540
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2541
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2542
        if err != nil {
×
2543
                return nil, err
×
2544
        }
×
2545
        defer rows.Close()
×
2546
        var items []ListNodeIDsAndPubKeysRow
×
2547
        for rows.Next() {
×
2548
                var i ListNodeIDsAndPubKeysRow
×
2549
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2550
                        return nil, err
×
2551
                }
×
2552
                items = append(items, i)
×
2553
        }
2554
        if err := rows.Close(); err != nil {
×
2555
                return nil, err
×
2556
        }
×
2557
        if err := rows.Err(); err != nil {
×
2558
                return nil, err
×
2559
        }
×
2560
        return items, nil
×
2561
}
2562

2563
const listNodesPaginated = `-- name: ListNodesPaginated :many
2564
SELECT id, version, pub_key, alias, last_update, color, signature
2565
FROM graph_nodes
2566
WHERE version = $1 AND id > $2
2567
ORDER BY id
2568
LIMIT $3
2569
`
2570

2571
type ListNodesPaginatedParams struct {
2572
        Version int16
2573
        ID      int64
2574
        Limit   int32
2575
}
2576

2577
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
2578
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2579
        if err != nil {
×
2580
                return nil, err
×
2581
        }
×
2582
        defer rows.Close()
×
2583
        var items []GraphNode
×
2584
        for rows.Next() {
×
2585
                var i GraphNode
×
2586
                if err := rows.Scan(
×
2587
                        &i.ID,
×
2588
                        &i.Version,
×
2589
                        &i.PubKey,
×
2590
                        &i.Alias,
×
2591
                        &i.LastUpdate,
×
2592
                        &i.Color,
×
2593
                        &i.Signature,
×
2594
                ); err != nil {
×
2595
                        return nil, err
×
2596
                }
×
2597
                items = append(items, i)
×
2598
        }
2599
        if err := rows.Close(); err != nil {
×
2600
                return nil, err
×
2601
        }
×
2602
        if err := rows.Err(); err != nil {
×
2603
                return nil, err
×
2604
        }
×
2605
        return items, nil
×
2606
}
2607

2608
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2609
/* ─────────────────────────────────────────────
2610
   graph_channel_policies table queries
2611
   ─────────────────────────────────────────────
2612
*/
2613

2614
INSERT INTO graph_channel_policies (
2615
    version, channel_id, node_id, timelock, fee_ppm,
2616
    base_fee_msat, min_htlc_msat, last_update, disabled,
2617
    max_htlc_msat, inbound_base_fee_msat,
2618
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2619
    signature
2620
) VALUES  (
2621
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2622
)
2623
ON CONFLICT (channel_id, node_id, version)
2624
    -- Update the following fields if a conflict occurs on channel_id,
2625
    -- node_id, and version.
2626
    DO UPDATE SET
2627
        timelock = EXCLUDED.timelock,
2628
        fee_ppm = EXCLUDED.fee_ppm,
2629
        base_fee_msat = EXCLUDED.base_fee_msat,
2630
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2631
        last_update = EXCLUDED.last_update,
2632
        disabled = EXCLUDED.disabled,
2633
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2634
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2635
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2636
        message_flags = EXCLUDED.message_flags,
2637
        channel_flags = EXCLUDED.channel_flags,
2638
        signature = EXCLUDED.signature
2639
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
2640
RETURNING id
2641
`
2642

2643
type UpsertEdgePolicyParams struct {
2644
        Version                 int16
2645
        ChannelID               int64
2646
        NodeID                  int64
2647
        Timelock                int32
2648
        FeePpm                  int64
2649
        BaseFeeMsat             int64
2650
        MinHtlcMsat             int64
2651
        LastUpdate              sql.NullInt64
2652
        Disabled                sql.NullBool
2653
        MaxHtlcMsat             sql.NullInt64
2654
        InboundBaseFeeMsat      sql.NullInt64
2655
        InboundFeeRateMilliMsat sql.NullInt64
2656
        MessageFlags            sql.NullInt16
2657
        ChannelFlags            sql.NullInt16
2658
        Signature               []byte
2659
}
2660

2661
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2662
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2663
                arg.Version,
×
2664
                arg.ChannelID,
×
2665
                arg.NodeID,
×
2666
                arg.Timelock,
×
2667
                arg.FeePpm,
×
2668
                arg.BaseFeeMsat,
×
2669
                arg.MinHtlcMsat,
×
2670
                arg.LastUpdate,
×
2671
                arg.Disabled,
×
2672
                arg.MaxHtlcMsat,
×
2673
                arg.InboundBaseFeeMsat,
×
2674
                arg.InboundFeeRateMilliMsat,
×
2675
                arg.MessageFlags,
×
2676
                arg.ChannelFlags,
×
2677
                arg.Signature,
×
2678
        )
×
2679
        var id int64
×
2680
        err := row.Scan(&id)
×
2681
        return id, err
×
2682
}
×
2683

2684
const upsertNode = `-- name: UpsertNode :one
2685
/* ─────────────────────────────────────────────
2686
   graph_nodes table queries
2687
   ───────────────────────────��─────────────────
2688
*/
2689

2690
INSERT INTO graph_nodes (
2691
    version, pub_key, alias, last_update, color, signature
2692
) VALUES (
2693
    $1, $2, $3, $4, $5, $6
2694
)
2695
ON CONFLICT (pub_key, version)
2696
    -- Update the following fields if a conflict occurs on pub_key
2697
    -- and version.
2698
    DO UPDATE SET
2699
        alias = EXCLUDED.alias,
2700
        last_update = EXCLUDED.last_update,
2701
        color = EXCLUDED.color,
2702
        signature = EXCLUDED.signature
2703
WHERE graph_nodes.last_update IS NULL
2704
    OR EXCLUDED.last_update > graph_nodes.last_update
2705
RETURNING id
2706
`
2707

2708
type UpsertNodeParams struct {
2709
        Version    int16
2710
        PubKey     []byte
2711
        Alias      sql.NullString
2712
        LastUpdate sql.NullInt64
2713
        Color      sql.NullString
2714
        Signature  []byte
2715
}
2716

2717
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2718
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2719
                arg.Version,
×
2720
                arg.PubKey,
×
2721
                arg.Alias,
×
2722
                arg.LastUpdate,
×
2723
                arg.Color,
×
2724
                arg.Signature,
×
2725
        )
×
2726
        var id int64
×
2727
        err := row.Scan(&id)
×
2728
        return id, err
×
2729
}
×
2730

2731
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2732
/* ─────────────────────────────────────────────
2733
   graph_node_extra_types table queries
2734
   ─────────────────────────────────────────────
2735
*/
2736

2737
INSERT INTO graph_node_extra_types (
2738
    node_id, type, value
2739
)
2740
VALUES ($1, $2, $3)
2741
ON CONFLICT (type, node_id)
2742
    -- Update the value if a conflict occurs on type
2743
    -- and node_id.
2744
    DO UPDATE SET value = EXCLUDED.value
2745
`
2746

2747
type UpsertNodeExtraTypeParams struct {
2748
        NodeID int64
2749
        Type   int64
2750
        Value  []byte
2751
}
2752

2753
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2754
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2755
        return err
×
2756
}
×
2757

2758
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2759
/* ───────────────────────────���─────────────────
2760
    graph_prune_log table queries
2761
    ─────────────────────────────────────────────
2762
*/
2763

2764
INSERT INTO graph_prune_log (
2765
    block_height, block_hash
2766
) VALUES (
2767
    $1, $2
2768
)
2769
ON CONFLICT(block_height) DO UPDATE SET
2770
    block_hash = EXCLUDED.block_hash
2771
`
2772

2773
type UpsertPruneLogEntryParams struct {
2774
        BlockHeight int64
2775
        BlockHash   []byte
2776
}
2777

2778
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2779
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2780
        return err
×
2781
}
×
2782

2783
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2784
/* ─────────────────────────────────────────────
2785
   graph_zombie_channels table queries
2786
   ─────────────────────────────────────────────
2787
*/
2788

2789
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
2790
VALUES ($1, $2, $3, $4)
2791
ON CONFLICT (scid, version)
2792
DO UPDATE SET
2793
    -- If a conflict exists for the SCID and version pair, then we
2794
    -- update the node keys.
2795
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
2796
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
2797
`
2798

2799
type UpsertZombieChannelParams struct {
2800
        Scid     []byte
2801
        Version  int16
2802
        NodeKey1 []byte
2803
        NodeKey2 []byte
2804
}
2805

2806
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2807
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2808
                arg.Scid,
×
2809
                arg.Version,
×
2810
                arg.NodeKey1,
×
2811
                arg.NodeKey2,
×
2812
        )
×
2813
        return err
×
2814
}
×
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