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

lightningnetwork / lnd / 16986782393

15 Aug 2025 09:02AM UTC coverage: 66.662% (-0.1%) from 66.763%
16986782393

Pull #10161

github

web-flow
Merge 5c41339ab into 365f1788e
Pull Request #10161: graph/db+sqldb: Make the SQL migration retry-safe/idempotent

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

87 existing lines in 20 files now uncovered.

135935 of 203917 relevant lines covered (66.66%)

21459.21 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
    ON CONFLICT (channel_id, type)
134
    -- Update the value if a conflict occurs on channel_id and type.
135
    DO UPDATE SET value = EXCLUDED.value
136
`
137

138
type CreateChannelExtraTypeParams struct {
139
        ChannelID int64
140
        Type      int64
141
        Value     []byte
142
}
143

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

149
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
150
DELETE FROM graph_channel_policy_extra_types
151
WHERE channel_policy_id = $1
152
`
153

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

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

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

179
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
180
DELETE FROM graph_node_extra_types
181
WHERE node_id = $1
182
  AND type = $2
183
`
184

185
type DeleteExtraNodeTypeParams struct {
186
        NodeID int64
187
        Type   int64
188
}
189

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

195
const deleteNode = `-- name: DeleteNode :exec
196
DELETE FROM graph_nodes
197
WHERE id = $1
198
`
199

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

205
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
206
DELETE FROM graph_node_addresses
207
WHERE node_id = $1
208
`
209

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

215
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
216
DELETE FROM graph_nodes
217
WHERE pub_key = $1
218
  AND version = $2
219
`
220

221
type DeleteNodeByPubKeyParams struct {
222
        PubKey  []byte
223
        Version int16
224
}
225

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

230
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
231
DELETE FROM graph_node_features
232
WHERE node_id = $1
233
  AND feature_bit = $2
234
`
235

236
type DeleteNodeFeatureParams struct {
237
        NodeID     int64
238
        FeatureBit int32
239
}
240

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

246
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
247
DELETE FROM graph_prune_log
248
WHERE block_height >= $1
249
  AND block_height <= $2
250
`
251

252
type DeletePruneLogEntriesInRangeParams struct {
253
        StartHeight int64
254
        EndHeight   int64
255
}
256

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

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

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

302
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
303
DELETE FROM graph_zombie_channels
304
WHERE scid = $1
305
AND version = $2
306
`
307

308
type DeleteZombieChannelParams struct {
309
        Scid    []byte
310
        Version int16
311
}
312

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

317
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
318
SELECT
319
    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,
320
    n1.pub_key AS node1_pub_key,
321
    n2.pub_key AS node2_pub_key
322
FROM graph_channels c
323
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
324
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
325
WHERE c.scid = $1
326
  AND c.version = $2
327
`
328

329
type GetChannelAndNodesBySCIDParams struct {
330
        Scid    []byte
331
        Version int16
332
}
333

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

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

375
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
376
SELECT
377
    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,
378

379
    n1.pub_key AS node1_pubkey,
380
    n2.pub_key AS node2_pubkey,
381

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

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

425
type GetChannelByOutpointWithPoliciesParams struct {
426
        Outpoint string
427
        Version  int16
428
}
429

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

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

519
const getChannelBySCID = `-- name: GetChannelBySCID :one
520
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
521
WHERE scid = $1 AND version = $2
522
`
523

524
type GetChannelBySCIDParams struct {
525
        Scid    []byte
526
        Version int16
527
}
528

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

550
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
551
SELECT
552
    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,
553
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
554
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
555

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

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

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

601
type GetChannelBySCIDWithPoliciesParams struct {
602
        Scid    []byte
603
        Version int16
604
}
605

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

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

707
const getChannelExtrasBatch = `-- name: GetChannelExtrasBatch :many
708
SELECT
709
    channel_id,
710
    type,
711
    value
712
FROM graph_channel_extra_types
713
WHERE channel_id IN (/*SLICE:chan_ids*/?)
714
ORDER BY channel_id, type
715
`
716

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

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

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

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

800
type GetChannelPolicyByChannelAndNodeParams struct {
801
        ChannelID int64
802
        NodeID    int64
803
        Version   int16
804
}
805

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

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

840
type GetChannelPolicyExtraTypesBatchRow struct {
841
        PolicyID int64
842
        Type     int64
843
        Value    []byte
844
}
845

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

879
const getChannelsByIDs = `-- name: GetChannelsByIDs :many
880
SELECT
881
    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,
882

883
    -- Minimal node data.
884
    n1.id AS node1_id,
885
    n1.pub_key AS node1_pub_key,
886
    n2.id AS node2_id,
887
    n2.pub_key AS node2_pub_key,
888

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

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

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

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

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

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

1064
type GetChannelsByOutpointsRow struct {
1065
        GraphChannel GraphChannel
1066
        Node1Pubkey  []byte
1067
        Node2Pubkey  []byte
1068
}
1069

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

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

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

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

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

1180
type GetChannelsByPolicyLastUpdateRangeParams struct {
1181
        Version   int16
1182
        StartTime sql.NullInt64
1183
        EndTime   sql.NullInt64
1184
}
1185

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

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

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

1314
type GetChannelsBySCIDRangeParams struct {
1315
        StartScid []byte
1316
        EndScid   []byte
1317
}
1318

1319
type GetChannelsBySCIDRangeRow struct {
1320
        GraphChannel GraphChannel
1321
        Node1PubKey  []byte
1322
        Node2PubKey  []byte
1323
}
1324

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

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

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

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

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

1416
type GetChannelsBySCIDWithPoliciesParams struct {
1417
        Version int16
1418
        Scids   [][]byte
1419
}
1420

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

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

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

1555
type GetChannelsBySCIDsParams struct {
1556
        Version int16
1557
        Scids   [][]byte
1558
}
1559

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

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

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

1647
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1648
SELECT node_id, type, value
1649
FROM graph_node_extra_types
1650
WHERE node_id = $1
1651
`
1652

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

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

1683
type GetNodeAddressesRow struct {
1684
        Type    int16
1685
        Address string
1686
}
1687

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

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

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

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

1763
type GetNodeByPubKeyParams struct {
1764
        PubKey  []byte
1765
        Version int16
1766
}
1767

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

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

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

1823
const getNodeFeatures = `-- name: GetNodeFeatures :many
1824
SELECT node_id, feature_bit
1825
FROM graph_node_features
1826
WHERE node_id = $1
1827
`
1828

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

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

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

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

1900
type GetNodeFeaturesByPubKeyParams struct {
1901
        PubKey  []byte
1902
        Version int16
1903
}
1904

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

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

1935
type GetNodeIDByPubKeyParams struct {
1936
        PubKey  []byte
1937
        Version int16
1938
}
1939

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

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

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

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

2001
type GetNodesByLastUpdateRangeParams struct {
2002
        StartTime sql.NullInt64
2003
        EndTime   sql.NullInt64
2004
}
2005

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

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

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

2077
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
2078
SELECT block_hash
2079
FROM graph_prune_log
2080
WHERE block_height = $1
2081
`
2082

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

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

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

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

2112
type GetPublicV1ChannelsBySCIDParams struct {
2113
        StartScid []byte
2114
        EndScid   []byte
2115
}
2116

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

2154
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
2155
SELECT scid from graph_channels
2156
WHERE outpoint = $1 AND version = $2
2157
`
2158

2159
type GetSCIDByOutpointParams struct {
2160
        Outpoint string
2161
        Version  int16
2162
}
2163

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

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

2178
type GetSourceNodesByVersionRow struct {
2179
        NodeID int64
2180
        PubKey []byte
2181
}
2182

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

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

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

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

2250
type GetZombieChannelParams struct {
2251
        Scid    []byte
2252
        Version int16
2253
}
2254

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

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

2274
type GetZombieChannelsSCIDsParams struct {
2275
        Version int16
2276
        Scids   [][]byte
2277
}
2278

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

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

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

2333
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
2334
/* ─────────────────────────────────────────────
2335
   graph_channel_policy_extra_types table queries
2336
   ─────────────────────────────────────────────
2337
*/
2338

2339
INSERT INTO graph_channel_policy_extra_types (
2340
    channel_policy_id, type, value
2341
)
2342
VALUES ($1, $2, $3)
2343
ON CONFLICT (channel_policy_id, type)
2344
    -- If a conflict occurs on channel_policy_id and type, then we update the
2345
    -- value.
2346
    DO UPDATE SET value = EXCLUDED.value
2347
`
2348

2349
type InsertChanPolicyExtraTypeParams struct {
2350
        ChannelPolicyID int64
2351
        Type            int64
2352
        Value           []byte
2353
}
2354

2355
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
2356
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
2357
        return err
×
2358
}
×
2359

2360
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2361
/* ─────────────────────────────────────────────
2362
   graph_channel_features table queries
2363
   ─────────────────────────────────────────────
2364
*/
2365

2366
INSERT INTO graph_channel_features (
2367
    channel_id, feature_bit
2368
) VALUES (
2369
    $1, $2
2370
) ON CONFLICT (channel_id, feature_bit)
2371
    -- Do nothing if the channel_id and feature_bit already exist.
2372
    DO NOTHING
2373
`
2374

2375
type InsertChannelFeatureParams struct {
2376
        ChannelID  int64
2377
        FeatureBit int32
2378
}
2379

2380
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2381
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2382
        return err
×
2383
}
×
2384

2385
const insertChannelMig = `-- name: InsertChannelMig :one
2386
INSERT INTO graph_channels (
2387
    version, scid, node_id_1, node_id_2,
2388
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
2389
    node_1_signature, node_2_signature, bitcoin_1_signature,
2390
    bitcoin_2_signature
2391
) VALUES (
2392
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
2393
) ON CONFLICT (scid, version)
2394
    -- If a conflict occurs, we have already migrated this channel. However, we
2395
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2396
    -- otherwise, the "RETURNING id" part does not work.
2397
    DO UPDATE SET
2398
        node_id_1 = EXCLUDED.node_id_1,
2399
        node_id_2 = EXCLUDED.node_id_2,
2400
        outpoint = EXCLUDED.outpoint,
2401
        capacity = EXCLUDED.capacity,
2402
        bitcoin_key_1 = EXCLUDED.bitcoin_key_1,
2403
        bitcoin_key_2 = EXCLUDED.bitcoin_key_2,
2404
        node_1_signature = EXCLUDED.node_1_signature,
2405
        node_2_signature = EXCLUDED.node_2_signature,
2406
        bitcoin_1_signature = EXCLUDED.bitcoin_1_signature,
2407
        bitcoin_2_signature = EXCLUDED.bitcoin_2_signature
2408
RETURNING id
2409
`
2410

2411
type InsertChannelMigParams struct {
2412
        Version           int16
2413
        Scid              []byte
2414
        NodeID1           int64
2415
        NodeID2           int64
2416
        Outpoint          string
2417
        Capacity          sql.NullInt64
2418
        BitcoinKey1       []byte
2419
        BitcoinKey2       []byte
2420
        Node1Signature    []byte
2421
        Node2Signature    []byte
2422
        Bitcoin1Signature []byte
2423
        Bitcoin2Signature []byte
2424
}
2425

2426
// NOTE: This query is only meant to be used by the graph SQL migration since
2427
// for that migration, in order to be retry-safe, we don't want to error out if
2428
// we re-insert the same channel again (which would error if the normal
2429
// CreateChannel query is used because of the uniqueness constraint on the scid
2430
// and version columns).
NEW
2431
func (q *Queries) InsertChannelMig(ctx context.Context, arg InsertChannelMigParams) (int64, error) {
×
NEW
2432
        row := q.db.QueryRowContext(ctx, insertChannelMig,
×
NEW
2433
                arg.Version,
×
NEW
2434
                arg.Scid,
×
NEW
2435
                arg.NodeID1,
×
NEW
2436
                arg.NodeID2,
×
NEW
2437
                arg.Outpoint,
×
NEW
2438
                arg.Capacity,
×
NEW
2439
                arg.BitcoinKey1,
×
NEW
2440
                arg.BitcoinKey2,
×
NEW
2441
                arg.Node1Signature,
×
NEW
2442
                arg.Node2Signature,
×
NEW
2443
                arg.Bitcoin1Signature,
×
NEW
2444
                arg.Bitcoin2Signature,
×
NEW
2445
        )
×
NEW
2446
        var id int64
×
NEW
2447
        err := row.Scan(&id)
×
NEW
2448
        return id, err
×
NEW
2449
}
×
2450

2451
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2452
/* ─────────────────────────────────────────────
2453
   graph_closed_scid table queries
2454
   ────────────────────────────────────────────-
2455
*/
2456

2457
INSERT INTO graph_closed_scids (scid)
2458
VALUES ($1)
2459
ON CONFLICT (scid) DO NOTHING
2460
`
2461

2462
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2463
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2464
        return err
×
2465
}
×
2466

2467
const insertEdgePolicyMig = `-- name: InsertEdgePolicyMig :one
2468
INSERT INTO graph_channel_policies (
2469
    version, channel_id, node_id, timelock, fee_ppm,
2470
    base_fee_msat, min_htlc_msat, last_update, disabled,
2471
    max_htlc_msat, inbound_base_fee_msat,
2472
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2473
    signature
2474
) VALUES  (
2475
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2476
)
2477
ON CONFLICT (channel_id, node_id, version)
2478
    -- If a conflict occurs, we have already migrated this policy. However, we
2479
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2480
    -- otherwise, the "RETURNING id" part does not work.
2481
    DO UPDATE SET
2482
        timelock = EXCLUDED.timelock,
2483
        fee_ppm = EXCLUDED.fee_ppm,
2484
        base_fee_msat = EXCLUDED.base_fee_msat,
2485
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2486
        last_update = EXCLUDED.last_update,
2487
        disabled = EXCLUDED.disabled,
2488
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2489
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2490
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2491
        message_flags = EXCLUDED.message_flags,
2492
        channel_flags = EXCLUDED.channel_flags,
2493
        signature = EXCLUDED.signature
2494
RETURNING id
2495
`
2496

2497
type InsertEdgePolicyMigParams struct {
2498
        Version                 int16
2499
        ChannelID               int64
2500
        NodeID                  int64
2501
        Timelock                int32
2502
        FeePpm                  int64
2503
        BaseFeeMsat             int64
2504
        MinHtlcMsat             int64
2505
        LastUpdate              sql.NullInt64
2506
        Disabled                sql.NullBool
2507
        MaxHtlcMsat             sql.NullInt64
2508
        InboundBaseFeeMsat      sql.NullInt64
2509
        InboundFeeRateMilliMsat sql.NullInt64
2510
        MessageFlags            sql.NullInt16
2511
        ChannelFlags            sql.NullInt16
2512
        Signature               []byte
2513
}
2514

2515
// NOTE: This query is only meant to be used by the graph SQL migration since
2516
// for that migration, in order to be retry-safe, we don't want to error out if
2517
// we re-insert the same policy (which would error if the normal
2518
// UpsertEdgePolicy query is used because of the constraint in that query that
2519
// requires a policy update to have a newer last_update than the existing one).
NEW
2520
func (q *Queries) InsertEdgePolicyMig(ctx context.Context, arg InsertEdgePolicyMigParams) (int64, error) {
×
NEW
2521
        row := q.db.QueryRowContext(ctx, insertEdgePolicyMig,
×
NEW
2522
                arg.Version,
×
NEW
2523
                arg.ChannelID,
×
NEW
2524
                arg.NodeID,
×
NEW
2525
                arg.Timelock,
×
NEW
2526
                arg.FeePpm,
×
NEW
2527
                arg.BaseFeeMsat,
×
NEW
2528
                arg.MinHtlcMsat,
×
NEW
2529
                arg.LastUpdate,
×
NEW
2530
                arg.Disabled,
×
NEW
2531
                arg.MaxHtlcMsat,
×
NEW
2532
                arg.InboundBaseFeeMsat,
×
NEW
2533
                arg.InboundFeeRateMilliMsat,
×
NEW
2534
                arg.MessageFlags,
×
NEW
2535
                arg.ChannelFlags,
×
NEW
2536
                arg.Signature,
×
NEW
2537
        )
×
NEW
2538
        var id int64
×
NEW
2539
        err := row.Scan(&id)
×
NEW
2540
        return id, err
×
NEW
2541
}
×
2542

2543
const insertNodeAddress = `-- name: InsertNodeAddress :exec
2544
/* ─────────────────────────────────────────────
2545
   graph_node_addresses table queries
2546
   ───────────────────────────────────��─────────
2547
*/
2548

2549
INSERT INTO graph_node_addresses (
2550
    node_id,
2551
    type,
2552
    address,
2553
    position
2554
) VALUES (
2555
    $1, $2, $3, $4
2556
) ON CONFLICT (node_id, type, position)
2557
    DO UPDATE SET address = EXCLUDED.address
2558
`
2559

2560
type InsertNodeAddressParams struct {
2561
        NodeID   int64
2562
        Type     int16
2563
        Address  string
2564
        Position int32
2565
}
2566

2567
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
2568
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
2569
                arg.NodeID,
×
2570
                arg.Type,
×
2571
                arg.Address,
×
2572
                arg.Position,
×
2573
        )
×
2574
        return err
×
2575
}
×
2576

2577
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2578
/* ─────────────────────────────────────────────
2579
   graph_node_features table queries
2580
   ─────────────────────────────────────────────
2581
*/
2582

2583
INSERT INTO graph_node_features (
2584
    node_id, feature_bit
2585
) VALUES (
2586
    $1, $2
2587
) ON CONFLICT (node_id, feature_bit)
2588
    -- Do nothing if the feature already exists for the node.
2589
    DO NOTHING
2590
`
2591

2592
type InsertNodeFeatureParams struct {
2593
        NodeID     int64
2594
        FeatureBit int32
2595
}
2596

2597
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2598
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2599
        return err
×
2600
}
×
2601

2602
const insertNodeMig = `-- name: InsertNodeMig :one
2603
/* ─────────────────────────────────────────────
2604
   Migration specific queries
2605

2606
   NOTE: once sqldbv2 is in place, these queries can be contained to a package
2607
   dedicated to the migration that requires it, and so we can then remove
2608
   it from the main set of "live" queries that the code-base has access to.
2609
   ────────────────────────────────────────────-
2610
*/
2611

2612
INSERT INTO graph_nodes (
2613
    version, pub_key, alias, last_update, color, signature
2614
) VALUES (
2615
    $1, $2, $3, $4, $5, $6
2616
)
2617
ON CONFLICT (pub_key, version)
2618
    -- If a conflict occurs, we have already migrated this node. However, we
2619
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2620
    -- otherwise, the "RETURNING id" part does not work.
2621
    DO UPDATE SET
2622
        alias = EXCLUDED.alias,
2623
        last_update = EXCLUDED.last_update,
2624
        color = EXCLUDED.color,
2625
        signature = EXCLUDED.signature
2626
RETURNING id
2627
`
2628

2629
type InsertNodeMigParams struct {
2630
        Version    int16
2631
        PubKey     []byte
2632
        Alias      sql.NullString
2633
        LastUpdate sql.NullInt64
2634
        Color      sql.NullString
2635
        Signature  []byte
2636
}
2637

2638
// NOTE: This query is only meant to be used by the graph SQL migration since
2639
// for that migration, in order to be retry-safe, we don't want to error out if
2640
// we re-insert the same node (which would error if the normal UpsertNode query
2641
// is used because of the constraint in that query that requires a node update
2642
// to have a newer last_update than the existing node).
NEW
2643
func (q *Queries) InsertNodeMig(ctx context.Context, arg InsertNodeMigParams) (int64, error) {
×
NEW
2644
        row := q.db.QueryRowContext(ctx, insertNodeMig,
×
NEW
2645
                arg.Version,
×
NEW
2646
                arg.PubKey,
×
NEW
2647
                arg.Alias,
×
NEW
2648
                arg.LastUpdate,
×
NEW
2649
                arg.Color,
×
NEW
2650
                arg.Signature,
×
NEW
2651
        )
×
NEW
2652
        var id int64
×
NEW
2653
        err := row.Scan(&id)
×
NEW
2654
        return id, err
×
NEW
2655
}
×
2656

2657
const isClosedChannel = `-- name: IsClosedChannel :one
2658
SELECT EXISTS (
2659
    SELECT 1
2660
    FROM graph_closed_scids
2661
    WHERE scid = $1
2662
)
2663
`
2664

2665
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2666
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2667
        var exists bool
×
2668
        err := row.Scan(&exists)
×
2669
        return exists, err
×
2670
}
×
2671

2672
const isPublicV1Node = `-- name: IsPublicV1Node :one
2673
SELECT EXISTS (
2674
    SELECT 1
2675
    FROM graph_channels c
2676
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
2677
    -- NOTE: we hard-code the version here since the clauses
2678
    -- here that determine if a node is public is specific
2679
    -- to the V1 gossip protocol. In V1, a node is public
2680
    -- if it has a public channel and a public channel is one
2681
    -- where we have the set of signatures of the channel
2682
    -- announcement. It is enough to just check that we have
2683
    -- one of the signatures since we only ever set them
2684
    -- together.
2685
    WHERE c.version = 1
2686
      AND c.bitcoin_1_signature IS NOT NULL
2687
      AND n.pub_key = $1
2688
)
2689
`
2690

2691
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2692
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2693
        var exists bool
×
2694
        err := row.Scan(&exists)
×
2695
        return exists, err
×
2696
}
×
2697

2698
const isZombieChannel = `-- name: IsZombieChannel :one
2699
SELECT EXISTS (
2700
    SELECT 1
2701
    FROM graph_zombie_channels
2702
    WHERE scid = $1
2703
    AND version = $2
2704
) AS is_zombie
2705
`
2706

2707
type IsZombieChannelParams struct {
2708
        Scid    []byte
2709
        Version int16
2710
}
2711

2712
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2713
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2714
        var is_zombie bool
×
2715
        err := row.Scan(&is_zombie)
×
2716
        return is_zombie, err
×
2717
}
×
2718

2719
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2720
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,
2721
    n1.pub_key AS node1_pubkey,
2722
    n2.pub_key AS node2_pubkey,
2723

2724
    -- Policy 1
2725
    -- TODO(elle): use sqlc.embed to embed policy structs
2726
    --  once this issue is resolved:
2727
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2728
    cp1.id AS policy1_id,
2729
    cp1.node_id AS policy1_node_id,
2730
    cp1.version AS policy1_version,
2731
    cp1.timelock AS policy1_timelock,
2732
    cp1.fee_ppm AS policy1_fee_ppm,
2733
    cp1.base_fee_msat AS policy1_base_fee_msat,
2734
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2735
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2736
    cp1.last_update AS policy1_last_update,
2737
    cp1.disabled AS policy1_disabled,
2738
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2739
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2740
    cp1.message_flags AS policy1_message_flags,
2741
    cp1.channel_flags AS policy1_channel_flags,
2742
    cp1.signature AS policy1_signature,
2743

2744
       -- Policy 2
2745
    cp2.id AS policy2_id,
2746
    cp2.node_id AS policy2_node_id,
2747
    cp2.version AS policy2_version,
2748
    cp2.timelock AS policy2_timelock,
2749
    cp2.fee_ppm AS policy2_fee_ppm,
2750
    cp2.base_fee_msat AS policy2_base_fee_msat,
2751
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2752
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2753
    cp2.last_update AS policy2_last_update,
2754
    cp2.disabled AS policy2_disabled,
2755
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2756
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2757
    cp2.message_flags AS policy2_message_flags,
2758
    cp2.channel_flags AS policy2_channel_flags,
2759
    cp2.signature AS policy2_signature
2760

2761
FROM graph_channels c
2762
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2763
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2764
    LEFT JOIN graph_channel_policies cp1
2765
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2766
    LEFT JOIN graph_channel_policies cp2
2767
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2768
WHERE c.version = $1
2769
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2770
`
2771

2772
type ListChannelsByNodeIDParams struct {
2773
        Version int16
2774
        NodeID1 int64
2775
}
2776

2777
type ListChannelsByNodeIDRow struct {
2778
        GraphChannel                   GraphChannel
2779
        Node1Pubkey                    []byte
2780
        Node2Pubkey                    []byte
2781
        Policy1ID                      sql.NullInt64
2782
        Policy1NodeID                  sql.NullInt64
2783
        Policy1Version                 sql.NullInt16
2784
        Policy1Timelock                sql.NullInt32
2785
        Policy1FeePpm                  sql.NullInt64
2786
        Policy1BaseFeeMsat             sql.NullInt64
2787
        Policy1MinHtlcMsat             sql.NullInt64
2788
        Policy1MaxHtlcMsat             sql.NullInt64
2789
        Policy1LastUpdate              sql.NullInt64
2790
        Policy1Disabled                sql.NullBool
2791
        Policy1InboundBaseFeeMsat      sql.NullInt64
2792
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2793
        Policy1MessageFlags            sql.NullInt16
2794
        Policy1ChannelFlags            sql.NullInt16
2795
        Policy1Signature               []byte
2796
        Policy2ID                      sql.NullInt64
2797
        Policy2NodeID                  sql.NullInt64
2798
        Policy2Version                 sql.NullInt16
2799
        Policy2Timelock                sql.NullInt32
2800
        Policy2FeePpm                  sql.NullInt64
2801
        Policy2BaseFeeMsat             sql.NullInt64
2802
        Policy2MinHtlcMsat             sql.NullInt64
2803
        Policy2MaxHtlcMsat             sql.NullInt64
2804
        Policy2LastUpdate              sql.NullInt64
2805
        Policy2Disabled                sql.NullBool
2806
        Policy2InboundBaseFeeMsat      sql.NullInt64
2807
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2808
        Policy2MessageFlags            sql.NullInt16
2809
        Policy2ChannelFlags            sql.NullInt16
2810
        Policy2Signature               []byte
2811
}
2812

2813
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2814
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2815
        if err != nil {
×
2816
                return nil, err
×
2817
        }
×
2818
        defer rows.Close()
×
2819
        var items []ListChannelsByNodeIDRow
×
2820
        for rows.Next() {
×
2821
                var i ListChannelsByNodeIDRow
×
2822
                if err := rows.Scan(
×
2823
                        &i.GraphChannel.ID,
×
2824
                        &i.GraphChannel.Version,
×
2825
                        &i.GraphChannel.Scid,
×
2826
                        &i.GraphChannel.NodeID1,
×
2827
                        &i.GraphChannel.NodeID2,
×
2828
                        &i.GraphChannel.Outpoint,
×
2829
                        &i.GraphChannel.Capacity,
×
2830
                        &i.GraphChannel.BitcoinKey1,
×
2831
                        &i.GraphChannel.BitcoinKey2,
×
2832
                        &i.GraphChannel.Node1Signature,
×
2833
                        &i.GraphChannel.Node2Signature,
×
2834
                        &i.GraphChannel.Bitcoin1Signature,
×
2835
                        &i.GraphChannel.Bitcoin2Signature,
×
2836
                        &i.Node1Pubkey,
×
2837
                        &i.Node2Pubkey,
×
2838
                        &i.Policy1ID,
×
2839
                        &i.Policy1NodeID,
×
2840
                        &i.Policy1Version,
×
2841
                        &i.Policy1Timelock,
×
2842
                        &i.Policy1FeePpm,
×
2843
                        &i.Policy1BaseFeeMsat,
×
2844
                        &i.Policy1MinHtlcMsat,
×
2845
                        &i.Policy1MaxHtlcMsat,
×
2846
                        &i.Policy1LastUpdate,
×
2847
                        &i.Policy1Disabled,
×
2848
                        &i.Policy1InboundBaseFeeMsat,
×
2849
                        &i.Policy1InboundFeeRateMilliMsat,
×
2850
                        &i.Policy1MessageFlags,
×
2851
                        &i.Policy1ChannelFlags,
×
2852
                        &i.Policy1Signature,
×
2853
                        &i.Policy2ID,
×
2854
                        &i.Policy2NodeID,
×
2855
                        &i.Policy2Version,
×
2856
                        &i.Policy2Timelock,
×
2857
                        &i.Policy2FeePpm,
×
2858
                        &i.Policy2BaseFeeMsat,
×
2859
                        &i.Policy2MinHtlcMsat,
×
2860
                        &i.Policy2MaxHtlcMsat,
×
2861
                        &i.Policy2LastUpdate,
×
2862
                        &i.Policy2Disabled,
×
2863
                        &i.Policy2InboundBaseFeeMsat,
×
2864
                        &i.Policy2InboundFeeRateMilliMsat,
×
2865
                        &i.Policy2MessageFlags,
×
2866
                        &i.Policy2ChannelFlags,
×
2867
                        &i.Policy2Signature,
×
2868
                ); err != nil {
×
2869
                        return nil, err
×
2870
                }
×
2871
                items = append(items, i)
×
2872
        }
2873
        if err := rows.Close(); err != nil {
×
2874
                return nil, err
×
2875
        }
×
2876
        if err := rows.Err(); err != nil {
×
2877
                return nil, err
×
2878
        }
×
2879
        return items, nil
×
2880
}
2881

2882
const listChannelsForNodeIDs = `-- name: ListChannelsForNodeIDs :many
2883
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,
2884
       n1.pub_key AS node1_pubkey,
2885
       n2.pub_key AS node2_pubkey,
2886

2887
       -- Policy 1
2888
       -- TODO(elle): use sqlc.embed to embed policy structs
2889
       --  once this issue is resolved:
2890
       --  https://github.com/sqlc-dev/sqlc/issues/2997
2891
       cp1.id AS policy1_id,
2892
       cp1.node_id AS policy1_node_id,
2893
       cp1.version AS policy1_version,
2894
       cp1.timelock AS policy1_timelock,
2895
       cp1.fee_ppm AS policy1_fee_ppm,
2896
       cp1.base_fee_msat AS policy1_base_fee_msat,
2897
       cp1.min_htlc_msat AS policy1_min_htlc_msat,
2898
       cp1.max_htlc_msat AS policy1_max_htlc_msat,
2899
       cp1.last_update AS policy1_last_update,
2900
       cp1.disabled AS policy1_disabled,
2901
       cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2902
       cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2903
       cp1.message_flags AS policy1_message_flags,
2904
       cp1.channel_flags AS policy1_channel_flags,
2905
       cp1.signature AS policy1_signature,
2906

2907
       -- Policy 2
2908
       cp2.id AS policy2_id,
2909
       cp2.node_id AS policy2_node_id,
2910
       cp2.version AS policy2_version,
2911
       cp2.timelock AS policy2_timelock,
2912
       cp2.fee_ppm AS policy2_fee_ppm,
2913
       cp2.base_fee_msat AS policy2_base_fee_msat,
2914
       cp2.min_htlc_msat AS policy2_min_htlc_msat,
2915
       cp2.max_htlc_msat AS policy2_max_htlc_msat,
2916
       cp2.last_update AS policy2_last_update,
2917
       cp2.disabled AS policy2_disabled,
2918
       cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2919
       cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2920
       cp2.message_flags AS policy2_message_flags,
2921
       cp2.channel_flags AS policy2_channel_flags,
2922
       cp2.signature AS policy2_signature
2923

2924
FROM graph_channels c
2925
         JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2926
         JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2927
         LEFT JOIN graph_channel_policies cp1
2928
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2929
         LEFT JOIN graph_channel_policies cp2
2930
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2931
WHERE c.version = $1
2932
  AND (c.node_id_1 IN (/*SLICE:node1_ids*/?)
2933
   OR c.node_id_2 IN (/*SLICE:node2_ids*/?))
2934
`
2935

2936
type ListChannelsForNodeIDsParams struct {
2937
        Version  int16
2938
        Node1Ids []int64
2939
        Node2Ids []int64
2940
}
2941

2942
type ListChannelsForNodeIDsRow struct {
2943
        GraphChannel                   GraphChannel
2944
        Node1Pubkey                    []byte
2945
        Node2Pubkey                    []byte
2946
        Policy1ID                      sql.NullInt64
2947
        Policy1NodeID                  sql.NullInt64
2948
        Policy1Version                 sql.NullInt16
2949
        Policy1Timelock                sql.NullInt32
2950
        Policy1FeePpm                  sql.NullInt64
2951
        Policy1BaseFeeMsat             sql.NullInt64
2952
        Policy1MinHtlcMsat             sql.NullInt64
2953
        Policy1MaxHtlcMsat             sql.NullInt64
2954
        Policy1LastUpdate              sql.NullInt64
2955
        Policy1Disabled                sql.NullBool
2956
        Policy1InboundBaseFeeMsat      sql.NullInt64
2957
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2958
        Policy1MessageFlags            sql.NullInt16
2959
        Policy1ChannelFlags            sql.NullInt16
2960
        Policy1Signature               []byte
2961
        Policy2ID                      sql.NullInt64
2962
        Policy2NodeID                  sql.NullInt64
2963
        Policy2Version                 sql.NullInt16
2964
        Policy2Timelock                sql.NullInt32
2965
        Policy2FeePpm                  sql.NullInt64
2966
        Policy2BaseFeeMsat             sql.NullInt64
2967
        Policy2MinHtlcMsat             sql.NullInt64
2968
        Policy2MaxHtlcMsat             sql.NullInt64
2969
        Policy2LastUpdate              sql.NullInt64
2970
        Policy2Disabled                sql.NullBool
2971
        Policy2InboundBaseFeeMsat      sql.NullInt64
2972
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2973
        Policy2MessageFlags            sql.NullInt16
2974
        Policy2ChannelFlags            sql.NullInt16
2975
        Policy2Signature               []byte
2976
}
2977

2978
func (q *Queries) ListChannelsForNodeIDs(ctx context.Context, arg ListChannelsForNodeIDsParams) ([]ListChannelsForNodeIDsRow, error) {
×
2979
        query := listChannelsForNodeIDs
×
2980
        var queryParams []interface{}
×
2981
        queryParams = append(queryParams, arg.Version)
×
2982
        if len(arg.Node1Ids) > 0 {
×
2983
                for _, v := range arg.Node1Ids {
×
2984
                        queryParams = append(queryParams, v)
×
2985
                }
×
2986
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", makeQueryParams(len(queryParams), len(arg.Node1Ids)), 1)
×
2987
        } else {
×
2988
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", "NULL", 1)
×
2989
        }
×
2990
        if len(arg.Node2Ids) > 0 {
×
2991
                for _, v := range arg.Node2Ids {
×
2992
                        queryParams = append(queryParams, v)
×
2993
                }
×
2994
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", makeQueryParams(len(queryParams), len(arg.Node2Ids)), 1)
×
2995
        } else {
×
2996
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", "NULL", 1)
×
2997
        }
×
2998
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2999
        if err != nil {
×
3000
                return nil, err
×
3001
        }
×
3002
        defer rows.Close()
×
3003
        var items []ListChannelsForNodeIDsRow
×
3004
        for rows.Next() {
×
3005
                var i ListChannelsForNodeIDsRow
×
3006
                if err := rows.Scan(
×
3007
                        &i.GraphChannel.ID,
×
3008
                        &i.GraphChannel.Version,
×
3009
                        &i.GraphChannel.Scid,
×
3010
                        &i.GraphChannel.NodeID1,
×
3011
                        &i.GraphChannel.NodeID2,
×
3012
                        &i.GraphChannel.Outpoint,
×
3013
                        &i.GraphChannel.Capacity,
×
3014
                        &i.GraphChannel.BitcoinKey1,
×
3015
                        &i.GraphChannel.BitcoinKey2,
×
3016
                        &i.GraphChannel.Node1Signature,
×
3017
                        &i.GraphChannel.Node2Signature,
×
3018
                        &i.GraphChannel.Bitcoin1Signature,
×
3019
                        &i.GraphChannel.Bitcoin2Signature,
×
3020
                        &i.Node1Pubkey,
×
3021
                        &i.Node2Pubkey,
×
3022
                        &i.Policy1ID,
×
3023
                        &i.Policy1NodeID,
×
3024
                        &i.Policy1Version,
×
3025
                        &i.Policy1Timelock,
×
3026
                        &i.Policy1FeePpm,
×
3027
                        &i.Policy1BaseFeeMsat,
×
3028
                        &i.Policy1MinHtlcMsat,
×
3029
                        &i.Policy1MaxHtlcMsat,
×
3030
                        &i.Policy1LastUpdate,
×
3031
                        &i.Policy1Disabled,
×
3032
                        &i.Policy1InboundBaseFeeMsat,
×
3033
                        &i.Policy1InboundFeeRateMilliMsat,
×
3034
                        &i.Policy1MessageFlags,
×
3035
                        &i.Policy1ChannelFlags,
×
3036
                        &i.Policy1Signature,
×
3037
                        &i.Policy2ID,
×
3038
                        &i.Policy2NodeID,
×
3039
                        &i.Policy2Version,
×
3040
                        &i.Policy2Timelock,
×
3041
                        &i.Policy2FeePpm,
×
3042
                        &i.Policy2BaseFeeMsat,
×
3043
                        &i.Policy2MinHtlcMsat,
×
3044
                        &i.Policy2MaxHtlcMsat,
×
3045
                        &i.Policy2LastUpdate,
×
3046
                        &i.Policy2Disabled,
×
3047
                        &i.Policy2InboundBaseFeeMsat,
×
3048
                        &i.Policy2InboundFeeRateMilliMsat,
×
3049
                        &i.Policy2MessageFlags,
×
3050
                        &i.Policy2ChannelFlags,
×
3051
                        &i.Policy2Signature,
×
3052
                ); err != nil {
×
3053
                        return nil, err
×
3054
                }
×
3055
                items = append(items, i)
×
3056
        }
3057
        if err := rows.Close(); err != nil {
×
3058
                return nil, err
×
3059
        }
×
3060
        if err := rows.Err(); err != nil {
×
3061
                return nil, err
×
3062
        }
×
3063
        return items, nil
×
3064
}
3065

3066
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
3067
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
3068
FROM graph_channels c
3069
WHERE c.version = $1 AND c.id > $2
3070
ORDER BY c.id
3071
LIMIT $3
3072
`
3073

3074
type ListChannelsPaginatedParams struct {
3075
        Version int16
3076
        ID      int64
3077
        Limit   int32
3078
}
3079

3080
type ListChannelsPaginatedRow struct {
3081
        ID          int64
3082
        BitcoinKey1 []byte
3083
        BitcoinKey2 []byte
3084
        Outpoint    string
3085
}
3086

3087
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
3088
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
3089
        if err != nil {
×
3090
                return nil, err
×
3091
        }
×
3092
        defer rows.Close()
×
3093
        var items []ListChannelsPaginatedRow
×
3094
        for rows.Next() {
×
3095
                var i ListChannelsPaginatedRow
×
3096
                if err := rows.Scan(
×
3097
                        &i.ID,
×
3098
                        &i.BitcoinKey1,
×
3099
                        &i.BitcoinKey2,
×
3100
                        &i.Outpoint,
×
3101
                ); err != nil {
×
3102
                        return nil, err
×
3103
                }
×
3104
                items = append(items, i)
×
3105
        }
3106
        if err := rows.Close(); err != nil {
×
3107
                return nil, err
×
3108
        }
×
3109
        if err := rows.Err(); err != nil {
×
3110
                return nil, err
×
3111
        }
×
3112
        return items, nil
×
3113
}
3114

3115
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
3116
SELECT
3117
    c.id as id,
3118
    c.scid as scid,
3119
    c.capacity AS capacity,
3120

3121
    -- Join node pubkeys
3122
    n1.pub_key AS node1_pubkey,
3123
    n2.pub_key AS node2_pubkey,
3124

3125
    -- Node 1 policy
3126
    cp1.timelock AS policy_1_timelock,
3127
    cp1.fee_ppm AS policy_1_fee_ppm,
3128
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3129
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3130
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3131
    cp1.disabled AS policy_1_disabled,
3132
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3133
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3134
    cp1.message_flags AS policy1_message_flags,
3135
    cp1.channel_flags AS policy1_channel_flags,
3136

3137
    -- Node 2 policy
3138
    cp2.timelock AS policy_2_timelock,
3139
    cp2.fee_ppm AS policy_2_fee_ppm,
3140
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3141
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3142
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3143
    cp2.disabled AS policy_2_disabled,
3144
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3145
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3146
    cp2.message_flags AS policy2_message_flags,
3147
    cp2.channel_flags AS policy2_channel_flags
3148

3149
FROM graph_channels c
3150
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3151
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3152
LEFT JOIN graph_channel_policies cp1
3153
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3154
LEFT JOIN graph_channel_policies cp2
3155
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3156
WHERE c.version = $1 AND c.id > $2
3157
ORDER BY c.id
3158
LIMIT $3
3159
`
3160

3161
type ListChannelsWithPoliciesForCachePaginatedParams struct {
3162
        Version int16
3163
        ID      int64
3164
        Limit   int32
3165
}
3166

3167
type ListChannelsWithPoliciesForCachePaginatedRow struct {
3168
        ID                             int64
3169
        Scid                           []byte
3170
        Capacity                       sql.NullInt64
3171
        Node1Pubkey                    []byte
3172
        Node2Pubkey                    []byte
3173
        Policy1Timelock                sql.NullInt32
3174
        Policy1FeePpm                  sql.NullInt64
3175
        Policy1BaseFeeMsat             sql.NullInt64
3176
        Policy1MinHtlcMsat             sql.NullInt64
3177
        Policy1MaxHtlcMsat             sql.NullInt64
3178
        Policy1Disabled                sql.NullBool
3179
        Policy1InboundBaseFeeMsat      sql.NullInt64
3180
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3181
        Policy1MessageFlags            sql.NullInt16
3182
        Policy1ChannelFlags            sql.NullInt16
3183
        Policy2Timelock                sql.NullInt32
3184
        Policy2FeePpm                  sql.NullInt64
3185
        Policy2BaseFeeMsat             sql.NullInt64
3186
        Policy2MinHtlcMsat             sql.NullInt64
3187
        Policy2MaxHtlcMsat             sql.NullInt64
3188
        Policy2Disabled                sql.NullBool
3189
        Policy2InboundBaseFeeMsat      sql.NullInt64
3190
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3191
        Policy2MessageFlags            sql.NullInt16
3192
        Policy2ChannelFlags            sql.NullInt16
3193
}
3194

3195
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
3196
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
3197
        if err != nil {
×
3198
                return nil, err
×
3199
        }
×
3200
        defer rows.Close()
×
3201
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
3202
        for rows.Next() {
×
3203
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
3204
                if err := rows.Scan(
×
3205
                        &i.ID,
×
3206
                        &i.Scid,
×
3207
                        &i.Capacity,
×
3208
                        &i.Node1Pubkey,
×
3209
                        &i.Node2Pubkey,
×
3210
                        &i.Policy1Timelock,
×
3211
                        &i.Policy1FeePpm,
×
3212
                        &i.Policy1BaseFeeMsat,
×
3213
                        &i.Policy1MinHtlcMsat,
×
3214
                        &i.Policy1MaxHtlcMsat,
×
3215
                        &i.Policy1Disabled,
×
3216
                        &i.Policy1InboundBaseFeeMsat,
×
3217
                        &i.Policy1InboundFeeRateMilliMsat,
×
3218
                        &i.Policy1MessageFlags,
×
3219
                        &i.Policy1ChannelFlags,
×
3220
                        &i.Policy2Timelock,
×
3221
                        &i.Policy2FeePpm,
×
3222
                        &i.Policy2BaseFeeMsat,
×
3223
                        &i.Policy2MinHtlcMsat,
×
3224
                        &i.Policy2MaxHtlcMsat,
×
3225
                        &i.Policy2Disabled,
×
3226
                        &i.Policy2InboundBaseFeeMsat,
×
3227
                        &i.Policy2InboundFeeRateMilliMsat,
×
3228
                        &i.Policy2MessageFlags,
×
3229
                        &i.Policy2ChannelFlags,
×
3230
                ); err != nil {
×
3231
                        return nil, err
×
3232
                }
×
3233
                items = append(items, i)
×
3234
        }
3235
        if err := rows.Close(); err != nil {
×
3236
                return nil, err
×
3237
        }
×
3238
        if err := rows.Err(); err != nil {
×
3239
                return nil, err
×
3240
        }
×
3241
        return items, nil
×
3242
}
3243

3244
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
3245
SELECT
3246
    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,
3247

3248
    -- Join node pubkeys
3249
    n1.pub_key AS node1_pubkey,
3250
    n2.pub_key AS node2_pubkey,
3251

3252
    -- Node 1 policy
3253
    cp1.id AS policy_1_id,
3254
    cp1.node_id AS policy_1_node_id,
3255
    cp1.version AS policy_1_version,
3256
    cp1.timelock AS policy_1_timelock,
3257
    cp1.fee_ppm AS policy_1_fee_ppm,
3258
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3259
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3260
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3261
    cp1.last_update AS policy_1_last_update,
3262
    cp1.disabled AS policy_1_disabled,
3263
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3264
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3265
    cp1.message_flags AS policy1_message_flags,
3266
    cp1.channel_flags AS policy1_channel_flags,
3267
    cp1.signature AS policy_1_signature,
3268

3269
    -- Node 2 policy
3270
    cp2.id AS policy_2_id,
3271
    cp2.node_id AS policy_2_node_id,
3272
    cp2.version AS policy_2_version,
3273
    cp2.timelock AS policy_2_timelock,
3274
    cp2.fee_ppm AS policy_2_fee_ppm,
3275
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3276
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3277
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3278
    cp2.last_update AS policy_2_last_update,
3279
    cp2.disabled AS policy_2_disabled,
3280
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3281
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3282
    cp2.message_flags AS policy2_message_flags,
3283
    cp2.channel_flags AS policy2_channel_flags,
3284
    cp2.signature AS policy_2_signature
3285

3286
FROM graph_channels c
3287
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3288
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3289
LEFT JOIN graph_channel_policies cp1
3290
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3291
LEFT JOIN graph_channel_policies cp2
3292
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3293
WHERE c.version = $1 AND c.id > $2
3294
ORDER BY c.id
3295
LIMIT $3
3296
`
3297

3298
type ListChannelsWithPoliciesPaginatedParams struct {
3299
        Version int16
3300
        ID      int64
3301
        Limit   int32
3302
}
3303

3304
type ListChannelsWithPoliciesPaginatedRow struct {
3305
        GraphChannel                   GraphChannel
3306
        Node1Pubkey                    []byte
3307
        Node2Pubkey                    []byte
3308
        Policy1ID                      sql.NullInt64
3309
        Policy1NodeID                  sql.NullInt64
3310
        Policy1Version                 sql.NullInt16
3311
        Policy1Timelock                sql.NullInt32
3312
        Policy1FeePpm                  sql.NullInt64
3313
        Policy1BaseFeeMsat             sql.NullInt64
3314
        Policy1MinHtlcMsat             sql.NullInt64
3315
        Policy1MaxHtlcMsat             sql.NullInt64
3316
        Policy1LastUpdate              sql.NullInt64
3317
        Policy1Disabled                sql.NullBool
3318
        Policy1InboundBaseFeeMsat      sql.NullInt64
3319
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3320
        Policy1MessageFlags            sql.NullInt16
3321
        Policy1ChannelFlags            sql.NullInt16
3322
        Policy1Signature               []byte
3323
        Policy2ID                      sql.NullInt64
3324
        Policy2NodeID                  sql.NullInt64
3325
        Policy2Version                 sql.NullInt16
3326
        Policy2Timelock                sql.NullInt32
3327
        Policy2FeePpm                  sql.NullInt64
3328
        Policy2BaseFeeMsat             sql.NullInt64
3329
        Policy2MinHtlcMsat             sql.NullInt64
3330
        Policy2MaxHtlcMsat             sql.NullInt64
3331
        Policy2LastUpdate              sql.NullInt64
3332
        Policy2Disabled                sql.NullBool
3333
        Policy2InboundBaseFeeMsat      sql.NullInt64
3334
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3335
        Policy2MessageFlags            sql.NullInt16
3336
        Policy2ChannelFlags            sql.NullInt16
3337
        Policy2Signature               []byte
3338
}
3339

3340
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
3341
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
3342
        if err != nil {
×
3343
                return nil, err
×
3344
        }
×
3345
        defer rows.Close()
×
3346
        var items []ListChannelsWithPoliciesPaginatedRow
×
3347
        for rows.Next() {
×
3348
                var i ListChannelsWithPoliciesPaginatedRow
×
3349
                if err := rows.Scan(
×
3350
                        &i.GraphChannel.ID,
×
3351
                        &i.GraphChannel.Version,
×
3352
                        &i.GraphChannel.Scid,
×
3353
                        &i.GraphChannel.NodeID1,
×
3354
                        &i.GraphChannel.NodeID2,
×
3355
                        &i.GraphChannel.Outpoint,
×
3356
                        &i.GraphChannel.Capacity,
×
3357
                        &i.GraphChannel.BitcoinKey1,
×
3358
                        &i.GraphChannel.BitcoinKey2,
×
3359
                        &i.GraphChannel.Node1Signature,
×
3360
                        &i.GraphChannel.Node2Signature,
×
3361
                        &i.GraphChannel.Bitcoin1Signature,
×
3362
                        &i.GraphChannel.Bitcoin2Signature,
×
3363
                        &i.Node1Pubkey,
×
3364
                        &i.Node2Pubkey,
×
3365
                        &i.Policy1ID,
×
3366
                        &i.Policy1NodeID,
×
3367
                        &i.Policy1Version,
×
3368
                        &i.Policy1Timelock,
×
3369
                        &i.Policy1FeePpm,
×
3370
                        &i.Policy1BaseFeeMsat,
×
3371
                        &i.Policy1MinHtlcMsat,
×
3372
                        &i.Policy1MaxHtlcMsat,
×
3373
                        &i.Policy1LastUpdate,
×
3374
                        &i.Policy1Disabled,
×
3375
                        &i.Policy1InboundBaseFeeMsat,
×
3376
                        &i.Policy1InboundFeeRateMilliMsat,
×
3377
                        &i.Policy1MessageFlags,
×
3378
                        &i.Policy1ChannelFlags,
×
3379
                        &i.Policy1Signature,
×
3380
                        &i.Policy2ID,
×
3381
                        &i.Policy2NodeID,
×
3382
                        &i.Policy2Version,
×
3383
                        &i.Policy2Timelock,
×
3384
                        &i.Policy2FeePpm,
×
3385
                        &i.Policy2BaseFeeMsat,
×
3386
                        &i.Policy2MinHtlcMsat,
×
3387
                        &i.Policy2MaxHtlcMsat,
×
3388
                        &i.Policy2LastUpdate,
×
3389
                        &i.Policy2Disabled,
×
3390
                        &i.Policy2InboundBaseFeeMsat,
×
3391
                        &i.Policy2InboundFeeRateMilliMsat,
×
3392
                        &i.Policy2MessageFlags,
×
3393
                        &i.Policy2ChannelFlags,
×
3394
                        &i.Policy2Signature,
×
3395
                ); err != nil {
×
3396
                        return nil, err
×
3397
                }
×
3398
                items = append(items, i)
×
3399
        }
3400
        if err := rows.Close(); err != nil {
×
3401
                return nil, err
×
3402
        }
×
3403
        if err := rows.Err(); err != nil {
×
3404
                return nil, err
×
3405
        }
×
3406
        return items, nil
×
3407
}
3408

3409
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
3410
SELECT id, pub_key
3411
FROM graph_nodes
3412
WHERE version = $1  AND id > $2
3413
ORDER BY id
3414
LIMIT $3
3415
`
3416

3417
type ListNodeIDsAndPubKeysParams struct {
3418
        Version int16
3419
        ID      int64
3420
        Limit   int32
3421
}
3422

3423
type ListNodeIDsAndPubKeysRow struct {
3424
        ID     int64
3425
        PubKey []byte
3426
}
3427

3428
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
3429
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
3430
        if err != nil {
×
3431
                return nil, err
×
3432
        }
×
3433
        defer rows.Close()
×
3434
        var items []ListNodeIDsAndPubKeysRow
×
3435
        for rows.Next() {
×
3436
                var i ListNodeIDsAndPubKeysRow
×
3437
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
3438
                        return nil, err
×
3439
                }
×
3440
                items = append(items, i)
×
3441
        }
3442
        if err := rows.Close(); err != nil {
×
3443
                return nil, err
×
3444
        }
×
3445
        if err := rows.Err(); err != nil {
×
3446
                return nil, err
×
3447
        }
×
3448
        return items, nil
×
3449
}
3450

3451
const listNodesPaginated = `-- name: ListNodesPaginated :many
3452
SELECT id, version, pub_key, alias, last_update, color, signature
3453
FROM graph_nodes
3454
WHERE version = $1 AND id > $2
3455
ORDER BY id
3456
LIMIT $3
3457
`
3458

3459
type ListNodesPaginatedParams struct {
3460
        Version int16
3461
        ID      int64
3462
        Limit   int32
3463
}
3464

3465
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
3466
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
3467
        if err != nil {
×
3468
                return nil, err
×
3469
        }
×
3470
        defer rows.Close()
×
3471
        var items []GraphNode
×
3472
        for rows.Next() {
×
3473
                var i GraphNode
×
3474
                if err := rows.Scan(
×
3475
                        &i.ID,
×
3476
                        &i.Version,
×
3477
                        &i.PubKey,
×
3478
                        &i.Alias,
×
3479
                        &i.LastUpdate,
×
3480
                        &i.Color,
×
3481
                        &i.Signature,
×
3482
                ); err != nil {
×
3483
                        return nil, err
×
3484
                }
×
3485
                items = append(items, i)
×
3486
        }
3487
        if err := rows.Close(); err != nil {
×
3488
                return nil, err
×
3489
        }
×
3490
        if err := rows.Err(); err != nil {
×
3491
                return nil, err
×
3492
        }
×
3493
        return items, nil
×
3494
}
3495

3496
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
3497
/* ─────────────────────────────────────────────
3498
   graph_channel_policies table queries
3499
   ─────────────────────────────────────────────
3500
*/
3501

3502
INSERT INTO graph_channel_policies (
3503
    version, channel_id, node_id, timelock, fee_ppm,
3504
    base_fee_msat, min_htlc_msat, last_update, disabled,
3505
    max_htlc_msat, inbound_base_fee_msat,
3506
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
3507
    signature
3508
) VALUES  (
3509
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
3510
)
3511
ON CONFLICT (channel_id, node_id, version)
3512
    -- Update the following fields if a conflict occurs on channel_id,
3513
    -- node_id, and version.
3514
    DO UPDATE SET
3515
        timelock = EXCLUDED.timelock,
3516
        fee_ppm = EXCLUDED.fee_ppm,
3517
        base_fee_msat = EXCLUDED.base_fee_msat,
3518
        min_htlc_msat = EXCLUDED.min_htlc_msat,
3519
        last_update = EXCLUDED.last_update,
3520
        disabled = EXCLUDED.disabled,
3521
        max_htlc_msat = EXCLUDED.max_htlc_msat,
3522
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
3523
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
3524
        message_flags = EXCLUDED.message_flags,
3525
        channel_flags = EXCLUDED.channel_flags,
3526
        signature = EXCLUDED.signature
3527
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
3528
RETURNING id
3529
`
3530

3531
type UpsertEdgePolicyParams struct {
3532
        Version                 int16
3533
        ChannelID               int64
3534
        NodeID                  int64
3535
        Timelock                int32
3536
        FeePpm                  int64
3537
        BaseFeeMsat             int64
3538
        MinHtlcMsat             int64
3539
        LastUpdate              sql.NullInt64
3540
        Disabled                sql.NullBool
3541
        MaxHtlcMsat             sql.NullInt64
3542
        InboundBaseFeeMsat      sql.NullInt64
3543
        InboundFeeRateMilliMsat sql.NullInt64
3544
        MessageFlags            sql.NullInt16
3545
        ChannelFlags            sql.NullInt16
3546
        Signature               []byte
3547
}
3548

3549
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
3550
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
3551
                arg.Version,
×
3552
                arg.ChannelID,
×
3553
                arg.NodeID,
×
3554
                arg.Timelock,
×
3555
                arg.FeePpm,
×
3556
                arg.BaseFeeMsat,
×
3557
                arg.MinHtlcMsat,
×
3558
                arg.LastUpdate,
×
3559
                arg.Disabled,
×
3560
                arg.MaxHtlcMsat,
×
3561
                arg.InboundBaseFeeMsat,
×
3562
                arg.InboundFeeRateMilliMsat,
×
3563
                arg.MessageFlags,
×
3564
                arg.ChannelFlags,
×
3565
                arg.Signature,
×
3566
        )
×
3567
        var id int64
×
3568
        err := row.Scan(&id)
×
3569
        return id, err
×
3570
}
×
3571

3572
const upsertNode = `-- name: UpsertNode :one
3573
/* ─────────────────────────────────────────────
3574
   graph_nodes table queries
3575
   ───────────────────────────��─────────────────
3576
*/
3577

3578
INSERT INTO graph_nodes (
3579
    version, pub_key, alias, last_update, color, signature
3580
) VALUES (
3581
    $1, $2, $3, $4, $5, $6
3582
)
3583
ON CONFLICT (pub_key, version)
3584
    -- Update the following fields if a conflict occurs on pub_key
3585
    -- and version.
3586
    DO UPDATE SET
3587
        alias = EXCLUDED.alias,
3588
        last_update = EXCLUDED.last_update,
3589
        color = EXCLUDED.color,
3590
        signature = EXCLUDED.signature
3591
WHERE graph_nodes.last_update IS NULL
3592
    OR EXCLUDED.last_update > graph_nodes.last_update
3593
RETURNING id
3594
`
3595

3596
type UpsertNodeParams struct {
3597
        Version    int16
3598
        PubKey     []byte
3599
        Alias      sql.NullString
3600
        LastUpdate sql.NullInt64
3601
        Color      sql.NullString
3602
        Signature  []byte
3603
}
3604

3605
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
3606
        row := q.db.QueryRowContext(ctx, upsertNode,
×
3607
                arg.Version,
×
3608
                arg.PubKey,
×
3609
                arg.Alias,
×
3610
                arg.LastUpdate,
×
3611
                arg.Color,
×
3612
                arg.Signature,
×
3613
        )
×
3614
        var id int64
×
3615
        err := row.Scan(&id)
×
3616
        return id, err
×
3617
}
×
3618

3619
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
3620
/* ─────────────────────────────────────────────
3621
   graph_node_extra_types table queries
3622
   ─────────────────────────────────────────────
3623
*/
3624

3625
INSERT INTO graph_node_extra_types (
3626
    node_id, type, value
3627
)
3628
VALUES ($1, $2, $3)
3629
ON CONFLICT (type, node_id)
3630
    -- Update the value if a conflict occurs on type
3631
    -- and node_id.
3632
    DO UPDATE SET value = EXCLUDED.value
3633
`
3634

3635
type UpsertNodeExtraTypeParams struct {
3636
        NodeID int64
3637
        Type   int64
3638
        Value  []byte
3639
}
3640

3641
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
3642
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
3643
        return err
×
3644
}
×
3645

3646
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
3647
/* ───────────────────────────���─────────────────
3648
    graph_prune_log table queries
3649
    ─────────────────────────────────────────────
3650
*/
3651

3652
INSERT INTO graph_prune_log (
3653
    block_height, block_hash
3654
) VALUES (
3655
    $1, $2
3656
)
3657
ON CONFLICT(block_height) DO UPDATE SET
3658
    block_hash = EXCLUDED.block_hash
3659
`
3660

3661
type UpsertPruneLogEntryParams struct {
3662
        BlockHeight int64
3663
        BlockHash   []byte
3664
}
3665

3666
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
3667
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
3668
        return err
×
3669
}
×
3670

3671
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
3672
/* ─────────────────────────────────────────────
3673
   graph_zombie_channels table queries
3674
   ─────────────────────────────────────────────
3675
*/
3676

3677
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
3678
VALUES ($1, $2, $3, $4)
3679
ON CONFLICT (scid, version)
3680
DO UPDATE SET
3681
    -- If a conflict exists for the SCID and version pair, then we
3682
    -- update the node keys.
3683
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
3684
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
3685
`
3686

3687
type UpsertZombieChannelParams struct {
3688
        Scid     []byte
3689
        Version  int16
3690
        NodeKey1 []byte
3691
        NodeKey2 []byte
3692
}
3693

3694
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
3695
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
3696
                arg.Scid,
×
3697
                arg.Version,
×
3698
                arg.NodeKey1,
×
3699
                arg.NodeKey2,
×
3700
        )
×
3701
        return err
×
3702
}
×
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