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

lightningnetwork / lnd / 17370655067

01 Sep 2025 07:23AM UTC coverage: 66.678% (+9.4%) from 57.321%
17370655067

push

github

web-flow
Merge pull request #10161 from ellemouton/graphRetry

graph/db+sqldb: Make the SQL migration retry-safe/idempotent

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

19 existing lines in 7 files now uncovered.

136009 of 203980 relevant lines covered (66.68%)

21390.06 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 deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
124
DELETE FROM graph_channel_policy_extra_types
125
WHERE channel_policy_id = $1
126
`
127

128
func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error {
×
129
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraTypes, channelPolicyID)
×
130
        return err
×
131
}
×
132

133
const deleteChannels = `-- name: DeleteChannels :exec
134
DELETE FROM graph_channels
135
WHERE id IN (/*SLICE:ids*/?)
136
`
137

138
func (q *Queries) DeleteChannels(ctx context.Context, ids []int64) error {
×
139
        query := deleteChannels
×
140
        var queryParams []interface{}
×
141
        if len(ids) > 0 {
×
142
                for _, v := range ids {
×
143
                        queryParams = append(queryParams, v)
×
144
                }
×
145
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
146
        } else {
×
147
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
148
        }
×
149
        _, err := q.db.ExecContext(ctx, query, queryParams...)
×
150
        return err
×
151
}
152

153
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
154
DELETE FROM graph_node_extra_types
155
WHERE node_id = $1
156
  AND type = $2
157
`
158

159
type DeleteExtraNodeTypeParams struct {
160
        NodeID int64
161
        Type   int64
162
}
163

164
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
165
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
166
        return err
×
167
}
×
168

169
const deleteNode = `-- name: DeleteNode :exec
170
DELETE FROM graph_nodes
171
WHERE id = $1
172
`
173

174
func (q *Queries) DeleteNode(ctx context.Context, id int64) error {
×
175
        _, err := q.db.ExecContext(ctx, deleteNode, id)
×
176
        return err
×
177
}
×
178

179
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
180
DELETE FROM graph_node_addresses
181
WHERE node_id = $1
182
`
183

184
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
185
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
186
        return err
×
187
}
×
188

189
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
190
DELETE FROM graph_nodes
191
WHERE pub_key = $1
192
  AND version = $2
193
`
194

195
type DeleteNodeByPubKeyParams struct {
196
        PubKey  []byte
197
        Version int16
198
}
199

200
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
201
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
202
}
×
203

204
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
205
DELETE FROM graph_node_features
206
WHERE node_id = $1
207
  AND feature_bit = $2
208
`
209

210
type DeleteNodeFeatureParams struct {
211
        NodeID     int64
212
        FeatureBit int32
213
}
214

215
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
216
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
217
        return err
×
218
}
×
219

220
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
221
DELETE FROM graph_prune_log
222
WHERE block_height >= $1
223
  AND block_height <= $2
224
`
225

226
type DeletePruneLogEntriesInRangeParams struct {
227
        StartHeight int64
228
        EndHeight   int64
229
}
230

231
func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error {
×
232
        _, err := q.db.ExecContext(ctx, deletePruneLogEntriesInRange, arg.StartHeight, arg.EndHeight)
×
233
        return err
×
234
}
×
235

236
const deleteUnconnectedNodes = `-- name: DeleteUnconnectedNodes :many
237
DELETE FROM graph_nodes
238
WHERE
239
    -- Ignore any of our source nodes.
240
    NOT EXISTS (
241
        SELECT 1
242
        FROM graph_source_nodes sn
243
        WHERE sn.node_id = graph_nodes.id
244
    )
245
    -- Select all nodes that do not have any channels.
246
    AND NOT EXISTS (
247
        SELECT 1
248
        FROM graph_channels c
249
        WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id
250
) RETURNING pub_key
251
`
252

253
func (q *Queries) DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error) {
×
254
        rows, err := q.db.QueryContext(ctx, deleteUnconnectedNodes)
×
255
        if err != nil {
×
256
                return nil, err
×
257
        }
×
258
        defer rows.Close()
×
259
        var items [][]byte
×
260
        for rows.Next() {
×
261
                var pub_key []byte
×
262
                if err := rows.Scan(&pub_key); err != nil {
×
263
                        return nil, err
×
264
                }
×
265
                items = append(items, pub_key)
×
266
        }
267
        if err := rows.Close(); err != nil {
×
268
                return nil, err
×
269
        }
×
270
        if err := rows.Err(); err != nil {
×
271
                return nil, err
×
272
        }
×
273
        return items, nil
×
274
}
275

276
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
277
DELETE FROM graph_zombie_channels
278
WHERE scid = $1
279
AND version = $2
280
`
281

282
type DeleteZombieChannelParams struct {
283
        Scid    []byte
284
        Version int16
285
}
286

287
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
288
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
289
}
×
290

291
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
292
SELECT
293
    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,
294
    n1.pub_key AS node1_pub_key,
295
    n2.pub_key AS node2_pub_key
296
FROM graph_channels c
297
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
298
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
299
WHERE c.scid = $1
300
  AND c.version = $2
301
`
302

303
type GetChannelAndNodesBySCIDParams struct {
304
        Scid    []byte
305
        Version int16
306
}
307

308
type GetChannelAndNodesBySCIDRow struct {
309
        ID                int64
310
        Version           int16
311
        Scid              []byte
312
        NodeID1           int64
313
        NodeID2           int64
314
        Outpoint          string
315
        Capacity          sql.NullInt64
316
        BitcoinKey1       []byte
317
        BitcoinKey2       []byte
318
        Node1Signature    []byte
319
        Node2Signature    []byte
320
        Bitcoin1Signature []byte
321
        Bitcoin2Signature []byte
322
        Node1PubKey       []byte
323
        Node2PubKey       []byte
324
}
325

326
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
327
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
328
        var i GetChannelAndNodesBySCIDRow
×
329
        err := row.Scan(
×
330
                &i.ID,
×
331
                &i.Version,
×
332
                &i.Scid,
×
333
                &i.NodeID1,
×
334
                &i.NodeID2,
×
335
                &i.Outpoint,
×
336
                &i.Capacity,
×
337
                &i.BitcoinKey1,
×
338
                &i.BitcoinKey2,
×
339
                &i.Node1Signature,
×
340
                &i.Node2Signature,
×
341
                &i.Bitcoin1Signature,
×
342
                &i.Bitcoin2Signature,
×
343
                &i.Node1PubKey,
×
344
                &i.Node2PubKey,
×
345
        )
×
346
        return i, err
×
347
}
×
348

349
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
350
SELECT
351
    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,
352

353
    n1.pub_key AS node1_pubkey,
354
    n2.pub_key AS node2_pubkey,
355

356
    -- Node 1 policy
357
    cp1.id AS policy_1_id,
358
    cp1.node_id AS policy_1_node_id,
359
    cp1.version AS policy_1_version,
360
    cp1.timelock AS policy_1_timelock,
361
    cp1.fee_ppm AS policy_1_fee_ppm,
362
    cp1.base_fee_msat AS policy_1_base_fee_msat,
363
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
364
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
365
    cp1.last_update AS policy_1_last_update,
366
    cp1.disabled AS policy_1_disabled,
367
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
368
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
369
    cp1.message_flags AS policy_1_message_flags,
370
    cp1.channel_flags AS policy_1_channel_flags,
371
    cp1.signature AS policy_1_signature,
372

373
    -- Node 2 policy
374
    cp2.id AS policy_2_id,
375
    cp2.node_id AS policy_2_node_id,
376
    cp2.version AS policy_2_version,
377
    cp2.timelock AS policy_2_timelock,
378
    cp2.fee_ppm AS policy_2_fee_ppm,
379
    cp2.base_fee_msat AS policy_2_base_fee_msat,
380
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
381
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
382
    cp2.last_update AS policy_2_last_update,
383
    cp2.disabled AS policy_2_disabled,
384
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
385
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
386
    cp2.message_flags AS policy_2_message_flags,
387
    cp2.channel_flags AS policy_2_channel_flags,
388
    cp2.signature AS policy_2_signature
389
FROM graph_channels c
390
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
391
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
392
    LEFT JOIN graph_channel_policies cp1
393
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
394
    LEFT JOIN graph_channel_policies cp2
395
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
396
WHERE c.outpoint = $1 AND c.version = $2
397
`
398

399
type GetChannelByOutpointWithPoliciesParams struct {
400
        Outpoint string
401
        Version  int16
402
}
403

404
type GetChannelByOutpointWithPoliciesRow struct {
405
        GraphChannel                   GraphChannel
406
        Node1Pubkey                    []byte
407
        Node2Pubkey                    []byte
408
        Policy1ID                      sql.NullInt64
409
        Policy1NodeID                  sql.NullInt64
410
        Policy1Version                 sql.NullInt16
411
        Policy1Timelock                sql.NullInt32
412
        Policy1FeePpm                  sql.NullInt64
413
        Policy1BaseFeeMsat             sql.NullInt64
414
        Policy1MinHtlcMsat             sql.NullInt64
415
        Policy1MaxHtlcMsat             sql.NullInt64
416
        Policy1LastUpdate              sql.NullInt64
417
        Policy1Disabled                sql.NullBool
418
        Policy1InboundBaseFeeMsat      sql.NullInt64
419
        Policy1InboundFeeRateMilliMsat sql.NullInt64
420
        Policy1MessageFlags            sql.NullInt16
421
        Policy1ChannelFlags            sql.NullInt16
422
        Policy1Signature               []byte
423
        Policy2ID                      sql.NullInt64
424
        Policy2NodeID                  sql.NullInt64
425
        Policy2Version                 sql.NullInt16
426
        Policy2Timelock                sql.NullInt32
427
        Policy2FeePpm                  sql.NullInt64
428
        Policy2BaseFeeMsat             sql.NullInt64
429
        Policy2MinHtlcMsat             sql.NullInt64
430
        Policy2MaxHtlcMsat             sql.NullInt64
431
        Policy2LastUpdate              sql.NullInt64
432
        Policy2Disabled                sql.NullBool
433
        Policy2InboundBaseFeeMsat      sql.NullInt64
434
        Policy2InboundFeeRateMilliMsat sql.NullInt64
435
        Policy2MessageFlags            sql.NullInt16
436
        Policy2ChannelFlags            sql.NullInt16
437
        Policy2Signature               []byte
438
}
439

440
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
441
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
442
        var i GetChannelByOutpointWithPoliciesRow
×
443
        err := row.Scan(
×
444
                &i.GraphChannel.ID,
×
445
                &i.GraphChannel.Version,
×
446
                &i.GraphChannel.Scid,
×
447
                &i.GraphChannel.NodeID1,
×
448
                &i.GraphChannel.NodeID2,
×
449
                &i.GraphChannel.Outpoint,
×
450
                &i.GraphChannel.Capacity,
×
451
                &i.GraphChannel.BitcoinKey1,
×
452
                &i.GraphChannel.BitcoinKey2,
×
453
                &i.GraphChannel.Node1Signature,
×
454
                &i.GraphChannel.Node2Signature,
×
455
                &i.GraphChannel.Bitcoin1Signature,
×
456
                &i.GraphChannel.Bitcoin2Signature,
×
457
                &i.Node1Pubkey,
×
458
                &i.Node2Pubkey,
×
459
                &i.Policy1ID,
×
460
                &i.Policy1NodeID,
×
461
                &i.Policy1Version,
×
462
                &i.Policy1Timelock,
×
463
                &i.Policy1FeePpm,
×
464
                &i.Policy1BaseFeeMsat,
×
465
                &i.Policy1MinHtlcMsat,
×
466
                &i.Policy1MaxHtlcMsat,
×
467
                &i.Policy1LastUpdate,
×
468
                &i.Policy1Disabled,
×
469
                &i.Policy1InboundBaseFeeMsat,
×
470
                &i.Policy1InboundFeeRateMilliMsat,
×
471
                &i.Policy1MessageFlags,
×
472
                &i.Policy1ChannelFlags,
×
473
                &i.Policy1Signature,
×
474
                &i.Policy2ID,
×
475
                &i.Policy2NodeID,
×
476
                &i.Policy2Version,
×
477
                &i.Policy2Timelock,
×
478
                &i.Policy2FeePpm,
×
479
                &i.Policy2BaseFeeMsat,
×
480
                &i.Policy2MinHtlcMsat,
×
481
                &i.Policy2MaxHtlcMsat,
×
482
                &i.Policy2LastUpdate,
×
483
                &i.Policy2Disabled,
×
484
                &i.Policy2InboundBaseFeeMsat,
×
485
                &i.Policy2InboundFeeRateMilliMsat,
×
486
                &i.Policy2MessageFlags,
×
487
                &i.Policy2ChannelFlags,
×
488
                &i.Policy2Signature,
×
489
        )
×
490
        return i, err
×
491
}
×
492

493
const getChannelBySCID = `-- name: GetChannelBySCID :one
494
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
495
WHERE scid = $1 AND version = $2
496
`
497

498
type GetChannelBySCIDParams struct {
499
        Scid    []byte
500
        Version int16
501
}
502

503
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GraphChannel, error) {
×
504
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
505
        var i GraphChannel
×
506
        err := row.Scan(
×
507
                &i.ID,
×
508
                &i.Version,
×
509
                &i.Scid,
×
510
                &i.NodeID1,
×
511
                &i.NodeID2,
×
512
                &i.Outpoint,
×
513
                &i.Capacity,
×
514
                &i.BitcoinKey1,
×
515
                &i.BitcoinKey2,
×
516
                &i.Node1Signature,
×
517
                &i.Node2Signature,
×
518
                &i.Bitcoin1Signature,
×
519
                &i.Bitcoin2Signature,
×
520
        )
×
521
        return i, err
×
522
}
×
523

524
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
525
SELECT
526
    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,
527
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
528
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
529

530
    -- Policy 1
531
    cp1.id AS policy1_id,
532
    cp1.node_id AS policy1_node_id,
533
    cp1.version AS policy1_version,
534
    cp1.timelock AS policy1_timelock,
535
    cp1.fee_ppm AS policy1_fee_ppm,
536
    cp1.base_fee_msat AS policy1_base_fee_msat,
537
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
538
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
539
    cp1.last_update AS policy1_last_update,
540
    cp1.disabled AS policy1_disabled,
541
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
542
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
543
    cp1.message_flags AS policy1_message_flags,
544
    cp1.channel_flags AS policy1_channel_flags,
545
    cp1.signature AS policy1_signature,
546

547
    -- Policy 2
548
    cp2.id AS policy2_id,
549
    cp2.node_id AS policy2_node_id,
550
    cp2.version AS policy2_version,
551
    cp2.timelock AS policy2_timelock,
552
    cp2.fee_ppm AS policy2_fee_ppm,
553
    cp2.base_fee_msat AS policy2_base_fee_msat,
554
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
555
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
556
    cp2.last_update AS policy2_last_update,
557
    cp2.disabled AS policy2_disabled,
558
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
559
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
560
    cp2.message_flags AS policy_2_message_flags,
561
    cp2.channel_flags AS policy_2_channel_flags,
562
    cp2.signature AS policy2_signature
563

564
FROM graph_channels c
565
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
566
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
567
    LEFT JOIN graph_channel_policies cp1
568
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
569
    LEFT JOIN graph_channel_policies cp2
570
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
571
WHERE c.scid = $1
572
  AND c.version = $2
573
`
574

575
type GetChannelBySCIDWithPoliciesParams struct {
576
        Scid    []byte
577
        Version int16
578
}
579

580
type GetChannelBySCIDWithPoliciesRow struct {
581
        GraphChannel                   GraphChannel
582
        GraphNode                      GraphNode
583
        GraphNode_2                    GraphNode
584
        Policy1ID                      sql.NullInt64
585
        Policy1NodeID                  sql.NullInt64
586
        Policy1Version                 sql.NullInt16
587
        Policy1Timelock                sql.NullInt32
588
        Policy1FeePpm                  sql.NullInt64
589
        Policy1BaseFeeMsat             sql.NullInt64
590
        Policy1MinHtlcMsat             sql.NullInt64
591
        Policy1MaxHtlcMsat             sql.NullInt64
592
        Policy1LastUpdate              sql.NullInt64
593
        Policy1Disabled                sql.NullBool
594
        Policy1InboundBaseFeeMsat      sql.NullInt64
595
        Policy1InboundFeeRateMilliMsat sql.NullInt64
596
        Policy1MessageFlags            sql.NullInt16
597
        Policy1ChannelFlags            sql.NullInt16
598
        Policy1Signature               []byte
599
        Policy2ID                      sql.NullInt64
600
        Policy2NodeID                  sql.NullInt64
601
        Policy2Version                 sql.NullInt16
602
        Policy2Timelock                sql.NullInt32
603
        Policy2FeePpm                  sql.NullInt64
604
        Policy2BaseFeeMsat             sql.NullInt64
605
        Policy2MinHtlcMsat             sql.NullInt64
606
        Policy2MaxHtlcMsat             sql.NullInt64
607
        Policy2LastUpdate              sql.NullInt64
608
        Policy2Disabled                sql.NullBool
609
        Policy2InboundBaseFeeMsat      sql.NullInt64
610
        Policy2InboundFeeRateMilliMsat sql.NullInt64
611
        Policy2MessageFlags            sql.NullInt16
612
        Policy2ChannelFlags            sql.NullInt16
613
        Policy2Signature               []byte
614
}
615

616
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
617
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
618
        var i GetChannelBySCIDWithPoliciesRow
×
619
        err := row.Scan(
×
620
                &i.GraphChannel.ID,
×
621
                &i.GraphChannel.Version,
×
622
                &i.GraphChannel.Scid,
×
623
                &i.GraphChannel.NodeID1,
×
624
                &i.GraphChannel.NodeID2,
×
625
                &i.GraphChannel.Outpoint,
×
626
                &i.GraphChannel.Capacity,
×
627
                &i.GraphChannel.BitcoinKey1,
×
628
                &i.GraphChannel.BitcoinKey2,
×
629
                &i.GraphChannel.Node1Signature,
×
630
                &i.GraphChannel.Node2Signature,
×
631
                &i.GraphChannel.Bitcoin1Signature,
×
632
                &i.GraphChannel.Bitcoin2Signature,
×
633
                &i.GraphNode.ID,
×
634
                &i.GraphNode.Version,
×
635
                &i.GraphNode.PubKey,
×
636
                &i.GraphNode.Alias,
×
637
                &i.GraphNode.LastUpdate,
×
638
                &i.GraphNode.Color,
×
639
                &i.GraphNode.Signature,
×
640
                &i.GraphNode_2.ID,
×
641
                &i.GraphNode_2.Version,
×
642
                &i.GraphNode_2.PubKey,
×
643
                &i.GraphNode_2.Alias,
×
644
                &i.GraphNode_2.LastUpdate,
×
645
                &i.GraphNode_2.Color,
×
646
                &i.GraphNode_2.Signature,
×
647
                &i.Policy1ID,
×
648
                &i.Policy1NodeID,
×
649
                &i.Policy1Version,
×
650
                &i.Policy1Timelock,
×
651
                &i.Policy1FeePpm,
×
652
                &i.Policy1BaseFeeMsat,
×
653
                &i.Policy1MinHtlcMsat,
×
654
                &i.Policy1MaxHtlcMsat,
×
655
                &i.Policy1LastUpdate,
×
656
                &i.Policy1Disabled,
×
657
                &i.Policy1InboundBaseFeeMsat,
×
658
                &i.Policy1InboundFeeRateMilliMsat,
×
659
                &i.Policy1MessageFlags,
×
660
                &i.Policy1ChannelFlags,
×
661
                &i.Policy1Signature,
×
662
                &i.Policy2ID,
×
663
                &i.Policy2NodeID,
×
664
                &i.Policy2Version,
×
665
                &i.Policy2Timelock,
×
666
                &i.Policy2FeePpm,
×
667
                &i.Policy2BaseFeeMsat,
×
668
                &i.Policy2MinHtlcMsat,
×
669
                &i.Policy2MaxHtlcMsat,
×
670
                &i.Policy2LastUpdate,
×
671
                &i.Policy2Disabled,
×
672
                &i.Policy2InboundBaseFeeMsat,
×
673
                &i.Policy2InboundFeeRateMilliMsat,
×
674
                &i.Policy2MessageFlags,
×
675
                &i.Policy2ChannelFlags,
×
676
                &i.Policy2Signature,
×
677
        )
×
678
        return i, err
×
679
}
×
680

681
const getChannelExtrasBatch = `-- name: GetChannelExtrasBatch :many
682
SELECT
683
    channel_id,
684
    type,
685
    value
686
FROM graph_channel_extra_types
687
WHERE channel_id IN (/*SLICE:chan_ids*/?)
688
ORDER BY channel_id, type
689
`
690

691
func (q *Queries) GetChannelExtrasBatch(ctx context.Context, chanIds []int64) ([]GraphChannelExtraType, error) {
×
692
        query := getChannelExtrasBatch
×
693
        var queryParams []interface{}
×
694
        if len(chanIds) > 0 {
×
695
                for _, v := range chanIds {
×
696
                        queryParams = append(queryParams, v)
×
697
                }
×
698
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", makeQueryParams(len(queryParams), len(chanIds)), 1)
×
699
        } else {
×
700
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", "NULL", 1)
×
701
        }
×
702
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
703
        if err != nil {
×
704
                return nil, err
×
705
        }
×
706
        defer rows.Close()
×
707
        var items []GraphChannelExtraType
×
708
        for rows.Next() {
×
709
                var i GraphChannelExtraType
×
710
                if err := rows.Scan(&i.ChannelID, &i.Type, &i.Value); err != nil {
×
711
                        return nil, err
×
712
                }
×
713
                items = append(items, i)
×
714
        }
715
        if err := rows.Close(); err != nil {
×
716
                return nil, err
×
717
        }
×
718
        if err := rows.Err(); err != nil {
×
719
                return nil, err
×
720
        }
×
721
        return items, nil
×
722
}
723

724
const getChannelFeaturesBatch = `-- name: GetChannelFeaturesBatch :many
725
SELECT
726
    channel_id,
727
    feature_bit
728
FROM graph_channel_features
729
WHERE channel_id IN (/*SLICE:chan_ids*/?)
730
ORDER BY channel_id, feature_bit
731
`
732

733
func (q *Queries) GetChannelFeaturesBatch(ctx context.Context, chanIds []int64) ([]GraphChannelFeature, error) {
×
734
        query := getChannelFeaturesBatch
×
735
        var queryParams []interface{}
×
736
        if len(chanIds) > 0 {
×
737
                for _, v := range chanIds {
×
738
                        queryParams = append(queryParams, v)
×
739
                }
×
740
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", makeQueryParams(len(queryParams), len(chanIds)), 1)
×
741
        } else {
×
742
                query = strings.Replace(query, "/*SLICE:chan_ids*/?", "NULL", 1)
×
743
        }
×
744
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
745
        if err != nil {
×
746
                return nil, err
×
747
        }
×
748
        defer rows.Close()
×
749
        var items []GraphChannelFeature
×
750
        for rows.Next() {
×
751
                var i GraphChannelFeature
×
752
                if err := rows.Scan(&i.ChannelID, &i.FeatureBit); err != nil {
×
753
                        return nil, err
×
754
                }
×
755
                items = append(items, i)
×
756
        }
757
        if err := rows.Close(); err != nil {
×
758
                return nil, err
×
759
        }
×
760
        if err := rows.Err(); err != nil {
×
761
                return nil, err
×
762
        }
×
763
        return items, nil
×
764
}
765

766
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
767
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
768
FROM graph_channel_policies
769
WHERE channel_id = $1
770
  AND node_id = $2
771
  AND version = $3
772
`
773

774
type GetChannelPolicyByChannelAndNodeParams struct {
775
        ChannelID int64
776
        NodeID    int64
777
        Version   int16
778
}
779

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

804
const getChannelPolicyExtraTypesBatch = `-- name: GetChannelPolicyExtraTypesBatch :many
805
SELECT
806
    channel_policy_id as policy_id,
807
    type,
808
    value
809
FROM graph_channel_policy_extra_types
810
WHERE channel_policy_id IN (/*SLICE:policy_ids*/?)
811
ORDER BY channel_policy_id, type
812
`
813

814
type GetChannelPolicyExtraTypesBatchRow struct {
815
        PolicyID int64
816
        Type     int64
817
        Value    []byte
818
}
819

820
func (q *Queries) GetChannelPolicyExtraTypesBatch(ctx context.Context, policyIds []int64) ([]GetChannelPolicyExtraTypesBatchRow, error) {
×
821
        query := getChannelPolicyExtraTypesBatch
×
822
        var queryParams []interface{}
×
823
        if len(policyIds) > 0 {
×
824
                for _, v := range policyIds {
×
825
                        queryParams = append(queryParams, v)
×
826
                }
×
827
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", makeQueryParams(len(queryParams), len(policyIds)), 1)
×
828
        } else {
×
829
                query = strings.Replace(query, "/*SLICE:policy_ids*/?", "NULL", 1)
×
830
        }
×
831
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
832
        if err != nil {
×
833
                return nil, err
×
834
        }
×
835
        defer rows.Close()
×
836
        var items []GetChannelPolicyExtraTypesBatchRow
×
837
        for rows.Next() {
×
838
                var i GetChannelPolicyExtraTypesBatchRow
×
839
                if err := rows.Scan(&i.PolicyID, &i.Type, &i.Value); err != nil {
×
840
                        return nil, err
×
841
                }
×
842
                items = append(items, i)
×
843
        }
844
        if err := rows.Close(); err != nil {
×
845
                return nil, err
×
846
        }
×
847
        if err := rows.Err(); err != nil {
×
848
                return nil, err
×
849
        }
×
850
        return items, nil
×
851
}
852

853
const getChannelsByIDs = `-- name: GetChannelsByIDs :many
854
SELECT
855
    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,
856

857
    -- Minimal node data.
858
    n1.id AS node1_id,
859
    n1.pub_key AS node1_pub_key,
860
    n2.id AS node2_id,
861
    n2.pub_key AS node2_pub_key,
862

863
    -- Policy 1
864
    cp1.id AS policy1_id,
865
    cp1.node_id AS policy1_node_id,
866
    cp1.version AS policy1_version,
867
    cp1.timelock AS policy1_timelock,
868
    cp1.fee_ppm AS policy1_fee_ppm,
869
    cp1.base_fee_msat AS policy1_base_fee_msat,
870
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
871
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
872
    cp1.last_update AS policy1_last_update,
873
    cp1.disabled AS policy1_disabled,
874
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
875
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
876
    cp1.message_flags AS policy1_message_flags,
877
    cp1.channel_flags AS policy1_channel_flags,
878
    cp1.signature AS policy1_signature,
879

880
    -- Policy 2
881
    cp2.id AS policy2_id,
882
    cp2.node_id AS policy2_node_id,
883
    cp2.version AS policy2_version,
884
    cp2.timelock AS policy2_timelock,
885
    cp2.fee_ppm AS policy2_fee_ppm,
886
    cp2.base_fee_msat AS policy2_base_fee_msat,
887
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
888
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
889
    cp2.last_update AS policy2_last_update,
890
    cp2.disabled AS policy2_disabled,
891
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
892
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
893
    cp2.message_flags AS policy2_message_flags,
894
    cp2.channel_flags AS policy2_channel_flags,
895
    cp2.signature AS policy2_signature
896

897
FROM graph_channels c
898
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
899
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
900
    LEFT JOIN graph_channel_policies cp1
901
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
902
    LEFT JOIN graph_channel_policies cp2
903
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
904
WHERE c.id IN (/*SLICE:ids*/?)
905
`
906

907
type GetChannelsByIDsRow struct {
908
        GraphChannel                   GraphChannel
909
        Node1ID                        int64
910
        Node1PubKey                    []byte
911
        Node2ID                        int64
912
        Node2PubKey                    []byte
913
        Policy1ID                      sql.NullInt64
914
        Policy1NodeID                  sql.NullInt64
915
        Policy1Version                 sql.NullInt16
916
        Policy1Timelock                sql.NullInt32
917
        Policy1FeePpm                  sql.NullInt64
918
        Policy1BaseFeeMsat             sql.NullInt64
919
        Policy1MinHtlcMsat             sql.NullInt64
920
        Policy1MaxHtlcMsat             sql.NullInt64
921
        Policy1LastUpdate              sql.NullInt64
922
        Policy1Disabled                sql.NullBool
923
        Policy1InboundBaseFeeMsat      sql.NullInt64
924
        Policy1InboundFeeRateMilliMsat sql.NullInt64
925
        Policy1MessageFlags            sql.NullInt16
926
        Policy1ChannelFlags            sql.NullInt16
927
        Policy1Signature               []byte
928
        Policy2ID                      sql.NullInt64
929
        Policy2NodeID                  sql.NullInt64
930
        Policy2Version                 sql.NullInt16
931
        Policy2Timelock                sql.NullInt32
932
        Policy2FeePpm                  sql.NullInt64
933
        Policy2BaseFeeMsat             sql.NullInt64
934
        Policy2MinHtlcMsat             sql.NullInt64
935
        Policy2MaxHtlcMsat             sql.NullInt64
936
        Policy2LastUpdate              sql.NullInt64
937
        Policy2Disabled                sql.NullBool
938
        Policy2InboundBaseFeeMsat      sql.NullInt64
939
        Policy2InboundFeeRateMilliMsat sql.NullInt64
940
        Policy2MessageFlags            sql.NullInt16
941
        Policy2ChannelFlags            sql.NullInt16
942
        Policy2Signature               []byte
943
}
944

945
func (q *Queries) GetChannelsByIDs(ctx context.Context, ids []int64) ([]GetChannelsByIDsRow, error) {
×
946
        query := getChannelsByIDs
×
947
        var queryParams []interface{}
×
948
        if len(ids) > 0 {
×
949
                for _, v := range ids {
×
950
                        queryParams = append(queryParams, v)
×
951
                }
×
952
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
953
        } else {
×
954
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
955
        }
×
956
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
957
        if err != nil {
×
958
                return nil, err
×
959
        }
×
960
        defer rows.Close()
×
961
        var items []GetChannelsByIDsRow
×
962
        for rows.Next() {
×
963
                var i GetChannelsByIDsRow
×
964
                if err := rows.Scan(
×
965
                        &i.GraphChannel.ID,
×
966
                        &i.GraphChannel.Version,
×
967
                        &i.GraphChannel.Scid,
×
968
                        &i.GraphChannel.NodeID1,
×
969
                        &i.GraphChannel.NodeID2,
×
970
                        &i.GraphChannel.Outpoint,
×
971
                        &i.GraphChannel.Capacity,
×
972
                        &i.GraphChannel.BitcoinKey1,
×
973
                        &i.GraphChannel.BitcoinKey2,
×
974
                        &i.GraphChannel.Node1Signature,
×
975
                        &i.GraphChannel.Node2Signature,
×
976
                        &i.GraphChannel.Bitcoin1Signature,
×
977
                        &i.GraphChannel.Bitcoin2Signature,
×
978
                        &i.Node1ID,
×
979
                        &i.Node1PubKey,
×
980
                        &i.Node2ID,
×
981
                        &i.Node2PubKey,
×
982
                        &i.Policy1ID,
×
983
                        &i.Policy1NodeID,
×
984
                        &i.Policy1Version,
×
985
                        &i.Policy1Timelock,
×
986
                        &i.Policy1FeePpm,
×
987
                        &i.Policy1BaseFeeMsat,
×
988
                        &i.Policy1MinHtlcMsat,
×
989
                        &i.Policy1MaxHtlcMsat,
×
990
                        &i.Policy1LastUpdate,
×
991
                        &i.Policy1Disabled,
×
992
                        &i.Policy1InboundBaseFeeMsat,
×
993
                        &i.Policy1InboundFeeRateMilliMsat,
×
994
                        &i.Policy1MessageFlags,
×
995
                        &i.Policy1ChannelFlags,
×
996
                        &i.Policy1Signature,
×
997
                        &i.Policy2ID,
×
998
                        &i.Policy2NodeID,
×
999
                        &i.Policy2Version,
×
1000
                        &i.Policy2Timelock,
×
1001
                        &i.Policy2FeePpm,
×
1002
                        &i.Policy2BaseFeeMsat,
×
1003
                        &i.Policy2MinHtlcMsat,
×
1004
                        &i.Policy2MaxHtlcMsat,
×
1005
                        &i.Policy2LastUpdate,
×
1006
                        &i.Policy2Disabled,
×
1007
                        &i.Policy2InboundBaseFeeMsat,
×
1008
                        &i.Policy2InboundFeeRateMilliMsat,
×
1009
                        &i.Policy2MessageFlags,
×
1010
                        &i.Policy2ChannelFlags,
×
1011
                        &i.Policy2Signature,
×
1012
                ); err != nil {
×
1013
                        return nil, err
×
1014
                }
×
1015
                items = append(items, i)
×
1016
        }
1017
        if err := rows.Close(); err != nil {
×
1018
                return nil, err
×
1019
        }
×
1020
        if err := rows.Err(); err != nil {
×
1021
                return nil, err
×
1022
        }
×
1023
        return items, nil
×
1024
}
1025

1026
const getChannelsByOutpoints = `-- name: GetChannelsByOutpoints :many
1027
SELECT
1028
    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,
1029
    n1.pub_key AS node1_pubkey,
1030
    n2.pub_key AS node2_pubkey
1031
FROM graph_channels c
1032
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1033
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1034
WHERE c.outpoint IN
1035
    (/*SLICE:outpoints*/?)
1036
`
1037

1038
type GetChannelsByOutpointsRow struct {
1039
        GraphChannel GraphChannel
1040
        Node1Pubkey  []byte
1041
        Node2Pubkey  []byte
1042
}
1043

1044
func (q *Queries) GetChannelsByOutpoints(ctx context.Context, outpoints []string) ([]GetChannelsByOutpointsRow, error) {
×
1045
        query := getChannelsByOutpoints
×
1046
        var queryParams []interface{}
×
1047
        if len(outpoints) > 0 {
×
1048
                for _, v := range outpoints {
×
1049
                        queryParams = append(queryParams, v)
×
1050
                }
×
1051
                query = strings.Replace(query, "/*SLICE:outpoints*/?", makeQueryParams(len(queryParams), len(outpoints)), 1)
×
1052
        } else {
×
1053
                query = strings.Replace(query, "/*SLICE:outpoints*/?", "NULL", 1)
×
1054
        }
×
1055
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1056
        if err != nil {
×
1057
                return nil, err
×
1058
        }
×
1059
        defer rows.Close()
×
1060
        var items []GetChannelsByOutpointsRow
×
1061
        for rows.Next() {
×
1062
                var i GetChannelsByOutpointsRow
×
1063
                if err := rows.Scan(
×
1064
                        &i.GraphChannel.ID,
×
1065
                        &i.GraphChannel.Version,
×
1066
                        &i.GraphChannel.Scid,
×
1067
                        &i.GraphChannel.NodeID1,
×
1068
                        &i.GraphChannel.NodeID2,
×
1069
                        &i.GraphChannel.Outpoint,
×
1070
                        &i.GraphChannel.Capacity,
×
1071
                        &i.GraphChannel.BitcoinKey1,
×
1072
                        &i.GraphChannel.BitcoinKey2,
×
1073
                        &i.GraphChannel.Node1Signature,
×
1074
                        &i.GraphChannel.Node2Signature,
×
1075
                        &i.GraphChannel.Bitcoin1Signature,
×
1076
                        &i.GraphChannel.Bitcoin2Signature,
×
1077
                        &i.Node1Pubkey,
×
1078
                        &i.Node2Pubkey,
×
1079
                ); err != nil {
×
1080
                        return nil, err
×
1081
                }
×
1082
                items = append(items, i)
×
1083
        }
1084
        if err := rows.Close(); err != nil {
×
1085
                return nil, err
×
1086
        }
×
1087
        if err := rows.Err(); err != nil {
×
1088
                return nil, err
×
1089
        }
×
1090
        return items, nil
×
1091
}
1092

1093
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
1094
SELECT
1095
    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,
1096
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1097
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1098

1099
    -- Policy 1 (node_id_1)
1100
    cp1.id AS policy1_id,
1101
    cp1.node_id AS policy1_node_id,
1102
    cp1.version AS policy1_version,
1103
    cp1.timelock AS policy1_timelock,
1104
    cp1.fee_ppm AS policy1_fee_ppm,
1105
    cp1.base_fee_msat AS policy1_base_fee_msat,
1106
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1107
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1108
    cp1.last_update AS policy1_last_update,
1109
    cp1.disabled AS policy1_disabled,
1110
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1111
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1112
    cp1.message_flags AS policy1_message_flags,
1113
    cp1.channel_flags AS policy1_channel_flags,
1114
    cp1.signature AS policy1_signature,
1115

1116
    -- Policy 2 (node_id_2)
1117
    cp2.id AS policy2_id,
1118
    cp2.node_id AS policy2_node_id,
1119
    cp2.version AS policy2_version,
1120
    cp2.timelock AS policy2_timelock,
1121
    cp2.fee_ppm AS policy2_fee_ppm,
1122
    cp2.base_fee_msat AS policy2_base_fee_msat,
1123
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1124
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1125
    cp2.last_update AS policy2_last_update,
1126
    cp2.disabled AS policy2_disabled,
1127
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1128
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1129
    cp2.message_flags AS policy2_message_flags,
1130
    cp2.channel_flags AS policy2_channel_flags,
1131
    cp2.signature AS policy2_signature
1132

1133
FROM graph_channels c
1134
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1135
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1136
    LEFT JOIN graph_channel_policies cp1
1137
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1138
    LEFT JOIN graph_channel_policies cp2
1139
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1140
WHERE c.version = $1
1141
  AND (
1142
       (cp1.last_update >= $2 AND cp1.last_update < $3)
1143
       OR
1144
       (cp2.last_update >= $2 AND cp2.last_update < $3)
1145
  )
1146
ORDER BY
1147
    CASE
1148
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1149
            THEN COALESCE(cp1.last_update, 0)
1150
        ELSE COALESCE(cp2.last_update, 0)
1151
        END ASC
1152
`
1153

1154
type GetChannelsByPolicyLastUpdateRangeParams struct {
1155
        Version   int16
1156
        StartTime sql.NullInt64
1157
        EndTime   sql.NullInt64
1158
}
1159

1160
type GetChannelsByPolicyLastUpdateRangeRow struct {
1161
        GraphChannel                   GraphChannel
1162
        GraphNode                      GraphNode
1163
        GraphNode_2                    GraphNode
1164
        Policy1ID                      sql.NullInt64
1165
        Policy1NodeID                  sql.NullInt64
1166
        Policy1Version                 sql.NullInt16
1167
        Policy1Timelock                sql.NullInt32
1168
        Policy1FeePpm                  sql.NullInt64
1169
        Policy1BaseFeeMsat             sql.NullInt64
1170
        Policy1MinHtlcMsat             sql.NullInt64
1171
        Policy1MaxHtlcMsat             sql.NullInt64
1172
        Policy1LastUpdate              sql.NullInt64
1173
        Policy1Disabled                sql.NullBool
1174
        Policy1InboundBaseFeeMsat      sql.NullInt64
1175
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1176
        Policy1MessageFlags            sql.NullInt16
1177
        Policy1ChannelFlags            sql.NullInt16
1178
        Policy1Signature               []byte
1179
        Policy2ID                      sql.NullInt64
1180
        Policy2NodeID                  sql.NullInt64
1181
        Policy2Version                 sql.NullInt16
1182
        Policy2Timelock                sql.NullInt32
1183
        Policy2FeePpm                  sql.NullInt64
1184
        Policy2BaseFeeMsat             sql.NullInt64
1185
        Policy2MinHtlcMsat             sql.NullInt64
1186
        Policy2MaxHtlcMsat             sql.NullInt64
1187
        Policy2LastUpdate              sql.NullInt64
1188
        Policy2Disabled                sql.NullBool
1189
        Policy2InboundBaseFeeMsat      sql.NullInt64
1190
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1191
        Policy2MessageFlags            sql.NullInt16
1192
        Policy2ChannelFlags            sql.NullInt16
1193
        Policy2Signature               []byte
1194
}
1195

1196
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
1197
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
1198
        if err != nil {
×
1199
                return nil, err
×
1200
        }
×
1201
        defer rows.Close()
×
1202
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
1203
        for rows.Next() {
×
1204
                var i GetChannelsByPolicyLastUpdateRangeRow
×
1205
                if err := rows.Scan(
×
1206
                        &i.GraphChannel.ID,
×
1207
                        &i.GraphChannel.Version,
×
1208
                        &i.GraphChannel.Scid,
×
1209
                        &i.GraphChannel.NodeID1,
×
1210
                        &i.GraphChannel.NodeID2,
×
1211
                        &i.GraphChannel.Outpoint,
×
1212
                        &i.GraphChannel.Capacity,
×
1213
                        &i.GraphChannel.BitcoinKey1,
×
1214
                        &i.GraphChannel.BitcoinKey2,
×
1215
                        &i.GraphChannel.Node1Signature,
×
1216
                        &i.GraphChannel.Node2Signature,
×
1217
                        &i.GraphChannel.Bitcoin1Signature,
×
1218
                        &i.GraphChannel.Bitcoin2Signature,
×
1219
                        &i.GraphNode.ID,
×
1220
                        &i.GraphNode.Version,
×
1221
                        &i.GraphNode.PubKey,
×
1222
                        &i.GraphNode.Alias,
×
1223
                        &i.GraphNode.LastUpdate,
×
1224
                        &i.GraphNode.Color,
×
1225
                        &i.GraphNode.Signature,
×
1226
                        &i.GraphNode_2.ID,
×
1227
                        &i.GraphNode_2.Version,
×
1228
                        &i.GraphNode_2.PubKey,
×
1229
                        &i.GraphNode_2.Alias,
×
1230
                        &i.GraphNode_2.LastUpdate,
×
1231
                        &i.GraphNode_2.Color,
×
1232
                        &i.GraphNode_2.Signature,
×
1233
                        &i.Policy1ID,
×
1234
                        &i.Policy1NodeID,
×
1235
                        &i.Policy1Version,
×
1236
                        &i.Policy1Timelock,
×
1237
                        &i.Policy1FeePpm,
×
1238
                        &i.Policy1BaseFeeMsat,
×
1239
                        &i.Policy1MinHtlcMsat,
×
1240
                        &i.Policy1MaxHtlcMsat,
×
1241
                        &i.Policy1LastUpdate,
×
1242
                        &i.Policy1Disabled,
×
1243
                        &i.Policy1InboundBaseFeeMsat,
×
1244
                        &i.Policy1InboundFeeRateMilliMsat,
×
1245
                        &i.Policy1MessageFlags,
×
1246
                        &i.Policy1ChannelFlags,
×
1247
                        &i.Policy1Signature,
×
1248
                        &i.Policy2ID,
×
1249
                        &i.Policy2NodeID,
×
1250
                        &i.Policy2Version,
×
1251
                        &i.Policy2Timelock,
×
1252
                        &i.Policy2FeePpm,
×
1253
                        &i.Policy2BaseFeeMsat,
×
1254
                        &i.Policy2MinHtlcMsat,
×
1255
                        &i.Policy2MaxHtlcMsat,
×
1256
                        &i.Policy2LastUpdate,
×
1257
                        &i.Policy2Disabled,
×
1258
                        &i.Policy2InboundBaseFeeMsat,
×
1259
                        &i.Policy2InboundFeeRateMilliMsat,
×
1260
                        &i.Policy2MessageFlags,
×
1261
                        &i.Policy2ChannelFlags,
×
1262
                        &i.Policy2Signature,
×
1263
                ); err != nil {
×
1264
                        return nil, err
×
1265
                }
×
1266
                items = append(items, i)
×
1267
        }
1268
        if err := rows.Close(); err != nil {
×
1269
                return nil, err
×
1270
        }
×
1271
        if err := rows.Err(); err != nil {
×
1272
                return nil, err
×
1273
        }
×
1274
        return items, nil
×
1275
}
1276

1277
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1278
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,
1279
    n1.pub_key AS node1_pub_key,
1280
    n2.pub_key AS node2_pub_key
1281
FROM graph_channels c
1282
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1283
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1284
WHERE scid >= $1
1285
  AND scid < $2
1286
`
1287

1288
type GetChannelsBySCIDRangeParams struct {
1289
        StartScid []byte
1290
        EndScid   []byte
1291
}
1292

1293
type GetChannelsBySCIDRangeRow struct {
1294
        GraphChannel GraphChannel
1295
        Node1PubKey  []byte
1296
        Node2PubKey  []byte
1297
}
1298

1299
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1300
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1301
        if err != nil {
×
1302
                return nil, err
×
1303
        }
×
1304
        defer rows.Close()
×
1305
        var items []GetChannelsBySCIDRangeRow
×
1306
        for rows.Next() {
×
1307
                var i GetChannelsBySCIDRangeRow
×
1308
                if err := rows.Scan(
×
1309
                        &i.GraphChannel.ID,
×
1310
                        &i.GraphChannel.Version,
×
1311
                        &i.GraphChannel.Scid,
×
1312
                        &i.GraphChannel.NodeID1,
×
1313
                        &i.GraphChannel.NodeID2,
×
1314
                        &i.GraphChannel.Outpoint,
×
1315
                        &i.GraphChannel.Capacity,
×
1316
                        &i.GraphChannel.BitcoinKey1,
×
1317
                        &i.GraphChannel.BitcoinKey2,
×
1318
                        &i.GraphChannel.Node1Signature,
×
1319
                        &i.GraphChannel.Node2Signature,
×
1320
                        &i.GraphChannel.Bitcoin1Signature,
×
1321
                        &i.GraphChannel.Bitcoin2Signature,
×
1322
                        &i.Node1PubKey,
×
1323
                        &i.Node2PubKey,
×
1324
                ); err != nil {
×
1325
                        return nil, err
×
1326
                }
×
1327
                items = append(items, i)
×
1328
        }
1329
        if err := rows.Close(); err != nil {
×
1330
                return nil, err
×
1331
        }
×
1332
        if err := rows.Err(); err != nil {
×
1333
                return nil, err
×
1334
        }
×
1335
        return items, nil
×
1336
}
1337

1338
const getChannelsBySCIDWithPolicies = `-- name: GetChannelsBySCIDWithPolicies :many
1339
SELECT
1340
    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,
1341
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
1342
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
1343

1344
    -- Policy 1
1345
    cp1.id AS policy1_id,
1346
    cp1.node_id AS policy1_node_id,
1347
    cp1.version AS policy1_version,
1348
    cp1.timelock AS policy1_timelock,
1349
    cp1.fee_ppm AS policy1_fee_ppm,
1350
    cp1.base_fee_msat AS policy1_base_fee_msat,
1351
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1352
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1353
    cp1.last_update AS policy1_last_update,
1354
    cp1.disabled AS policy1_disabled,
1355
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1356
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1357
    cp1.message_flags AS policy1_message_flags,
1358
    cp1.channel_flags AS policy1_channel_flags,
1359
    cp1.signature AS policy1_signature,
1360

1361
    -- Policy 2
1362
    cp2.id AS policy2_id,
1363
    cp2.node_id AS policy2_node_id,
1364
    cp2.version AS policy2_version,
1365
    cp2.timelock AS policy2_timelock,
1366
    cp2.fee_ppm AS policy2_fee_ppm,
1367
    cp2.base_fee_msat AS policy2_base_fee_msat,
1368
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1369
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1370
    cp2.last_update AS policy2_last_update,
1371
    cp2.disabled AS policy2_disabled,
1372
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1373
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1374
    cp2.message_flags AS policy_2_message_flags,
1375
    cp2.channel_flags AS policy_2_channel_flags,
1376
    cp2.signature AS policy2_signature
1377

1378
FROM graph_channels c
1379
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
1380
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
1381
    LEFT JOIN graph_channel_policies cp1
1382
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1383
    LEFT JOIN graph_channel_policies cp2
1384
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1385
WHERE
1386
    c.version = $1
1387
  AND c.scid IN (/*SLICE:scids*/?)
1388
`
1389

1390
type GetChannelsBySCIDWithPoliciesParams struct {
1391
        Version int16
1392
        Scids   [][]byte
1393
}
1394

1395
type GetChannelsBySCIDWithPoliciesRow struct {
1396
        GraphChannel                   GraphChannel
1397
        GraphNode                      GraphNode
1398
        GraphNode_2                    GraphNode
1399
        Policy1ID                      sql.NullInt64
1400
        Policy1NodeID                  sql.NullInt64
1401
        Policy1Version                 sql.NullInt16
1402
        Policy1Timelock                sql.NullInt32
1403
        Policy1FeePpm                  sql.NullInt64
1404
        Policy1BaseFeeMsat             sql.NullInt64
1405
        Policy1MinHtlcMsat             sql.NullInt64
1406
        Policy1MaxHtlcMsat             sql.NullInt64
1407
        Policy1LastUpdate              sql.NullInt64
1408
        Policy1Disabled                sql.NullBool
1409
        Policy1InboundBaseFeeMsat      sql.NullInt64
1410
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1411
        Policy1MessageFlags            sql.NullInt16
1412
        Policy1ChannelFlags            sql.NullInt16
1413
        Policy1Signature               []byte
1414
        Policy2ID                      sql.NullInt64
1415
        Policy2NodeID                  sql.NullInt64
1416
        Policy2Version                 sql.NullInt16
1417
        Policy2Timelock                sql.NullInt32
1418
        Policy2FeePpm                  sql.NullInt64
1419
        Policy2BaseFeeMsat             sql.NullInt64
1420
        Policy2MinHtlcMsat             sql.NullInt64
1421
        Policy2MaxHtlcMsat             sql.NullInt64
1422
        Policy2LastUpdate              sql.NullInt64
1423
        Policy2Disabled                sql.NullBool
1424
        Policy2InboundBaseFeeMsat      sql.NullInt64
1425
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1426
        Policy2MessageFlags            sql.NullInt16
1427
        Policy2ChannelFlags            sql.NullInt16
1428
        Policy2Signature               []byte
1429
}
1430

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

1523
const getChannelsBySCIDs = `-- name: GetChannelsBySCIDs :many
1524
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
1525
WHERE version = $1
1526
  AND scid IN (/*SLICE:scids*/?)
1527
`
1528

1529
type GetChannelsBySCIDsParams struct {
1530
        Version int16
1531
        Scids   [][]byte
1532
}
1533

1534
func (q *Queries) GetChannelsBySCIDs(ctx context.Context, arg GetChannelsBySCIDsParams) ([]GraphChannel, error) {
×
1535
        query := getChannelsBySCIDs
×
1536
        var queryParams []interface{}
×
1537
        queryParams = append(queryParams, arg.Version)
×
1538
        if len(arg.Scids) > 0 {
×
1539
                for _, v := range arg.Scids {
×
1540
                        queryParams = append(queryParams, v)
×
1541
                }
×
1542
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
1543
        } else {
×
1544
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1545
        }
×
1546
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1547
        if err != nil {
×
1548
                return nil, err
×
1549
        }
×
1550
        defer rows.Close()
×
1551
        var items []GraphChannel
×
1552
        for rows.Next() {
×
1553
                var i GraphChannel
×
1554
                if err := rows.Scan(
×
1555
                        &i.ID,
×
1556
                        &i.Version,
×
1557
                        &i.Scid,
×
1558
                        &i.NodeID1,
×
1559
                        &i.NodeID2,
×
1560
                        &i.Outpoint,
×
1561
                        &i.Capacity,
×
1562
                        &i.BitcoinKey1,
×
1563
                        &i.BitcoinKey2,
×
1564
                        &i.Node1Signature,
×
1565
                        &i.Node2Signature,
×
1566
                        &i.Bitcoin1Signature,
×
1567
                        &i.Bitcoin2Signature,
×
1568
                ); err != nil {
×
1569
                        return nil, err
×
1570
                }
×
1571
                items = append(items, i)
×
1572
        }
1573
        if err := rows.Close(); err != nil {
×
1574
                return nil, err
×
1575
        }
×
1576
        if err := rows.Err(); err != nil {
×
1577
                return nil, err
×
1578
        }
×
1579
        return items, nil
×
1580
}
1581

1582
const getClosedChannelsSCIDs = `-- name: GetClosedChannelsSCIDs :many
1583
SELECT scid
1584
FROM graph_closed_scids
1585
WHERE scid IN (/*SLICE:scids*/?)
1586
`
1587

1588
func (q *Queries) GetClosedChannelsSCIDs(ctx context.Context, scids [][]byte) ([][]byte, error) {
×
1589
        query := getClosedChannelsSCIDs
×
1590
        var queryParams []interface{}
×
1591
        if len(scids) > 0 {
×
1592
                for _, v := range scids {
×
1593
                        queryParams = append(queryParams, v)
×
1594
                }
×
1595
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(scids)), 1)
×
1596
        } else {
×
1597
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
1598
        }
×
1599
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1600
        if err != nil {
×
1601
                return nil, err
×
1602
        }
×
1603
        defer rows.Close()
×
1604
        var items [][]byte
×
1605
        for rows.Next() {
×
1606
                var scid []byte
×
1607
                if err := rows.Scan(&scid); err != nil {
×
1608
                        return nil, err
×
1609
                }
×
1610
                items = append(items, scid)
×
1611
        }
1612
        if err := rows.Close(); err != nil {
×
1613
                return nil, err
×
1614
        }
×
1615
        if err := rows.Err(); err != nil {
×
1616
                return nil, err
×
1617
        }
×
1618
        return items, nil
×
1619
}
1620

1621
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1622
SELECT node_id, type, value
1623
FROM graph_node_extra_types
1624
WHERE node_id = $1
1625
`
1626

1627
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error) {
×
1628
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1629
        if err != nil {
×
1630
                return nil, err
×
1631
        }
×
1632
        defer rows.Close()
×
1633
        var items []GraphNodeExtraType
×
1634
        for rows.Next() {
×
1635
                var i GraphNodeExtraType
×
1636
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1637
                        return nil, err
×
1638
                }
×
1639
                items = append(items, i)
×
1640
        }
1641
        if err := rows.Close(); err != nil {
×
1642
                return nil, err
×
1643
        }
×
1644
        if err := rows.Err(); err != nil {
×
1645
                return nil, err
×
1646
        }
×
1647
        return items, nil
×
1648
}
1649

1650
const getNodeAddresses = `-- name: GetNodeAddresses :many
1651
SELECT type, address
1652
FROM graph_node_addresses
1653
WHERE node_id = $1
1654
ORDER BY type ASC, position ASC
1655
`
1656

1657
type GetNodeAddressesRow struct {
1658
        Type    int16
1659
        Address string
1660
}
1661

1662
func (q *Queries) GetNodeAddresses(ctx context.Context, nodeID int64) ([]GetNodeAddressesRow, error) {
×
1663
        rows, err := q.db.QueryContext(ctx, getNodeAddresses, nodeID)
×
1664
        if err != nil {
×
1665
                return nil, err
×
1666
        }
×
1667
        defer rows.Close()
×
1668
        var items []GetNodeAddressesRow
×
1669
        for rows.Next() {
×
1670
                var i GetNodeAddressesRow
×
1671
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1672
                        return nil, err
×
1673
                }
×
1674
                items = append(items, i)
×
1675
        }
1676
        if err := rows.Close(); err != nil {
×
1677
                return nil, err
×
1678
        }
×
1679
        if err := rows.Err(); err != nil {
×
1680
                return nil, err
×
1681
        }
×
1682
        return items, nil
×
1683
}
1684

1685
const getNodeAddressesBatch = `-- name: GetNodeAddressesBatch :many
1686
SELECT node_id, type, position, address
1687
FROM graph_node_addresses
1688
WHERE node_id IN (/*SLICE:ids*/?)
1689
ORDER BY node_id, type, position
1690
`
1691

1692
func (q *Queries) GetNodeAddressesBatch(ctx context.Context, ids []int64) ([]GraphNodeAddress, error) {
×
1693
        query := getNodeAddressesBatch
×
1694
        var queryParams []interface{}
×
1695
        if len(ids) > 0 {
×
1696
                for _, v := range ids {
×
1697
                        queryParams = append(queryParams, v)
×
1698
                }
×
1699
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1700
        } else {
×
1701
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1702
        }
×
1703
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1704
        if err != nil {
×
1705
                return nil, err
×
1706
        }
×
1707
        defer rows.Close()
×
1708
        var items []GraphNodeAddress
×
1709
        for rows.Next() {
×
1710
                var i GraphNodeAddress
×
1711
                if err := rows.Scan(
×
1712
                        &i.NodeID,
×
1713
                        &i.Type,
×
1714
                        &i.Position,
×
1715
                        &i.Address,
×
1716
                ); err != nil {
×
1717
                        return nil, err
×
1718
                }
×
1719
                items = append(items, i)
×
1720
        }
1721
        if err := rows.Close(); err != nil {
×
1722
                return nil, err
×
1723
        }
×
1724
        if err := rows.Err(); err != nil {
×
1725
                return nil, err
×
1726
        }
×
1727
        return items, nil
×
1728
}
1729

1730
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1731
SELECT id, version, pub_key, alias, last_update, color, signature
1732
FROM graph_nodes
1733
WHERE pub_key = $1
1734
  AND version = $2
1735
`
1736

1737
type GetNodeByPubKeyParams struct {
1738
        PubKey  []byte
1739
        Version int16
1740
}
1741

1742
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error) {
×
1743
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1744
        var i GraphNode
×
1745
        err := row.Scan(
×
1746
                &i.ID,
×
1747
                &i.Version,
×
1748
                &i.PubKey,
×
1749
                &i.Alias,
×
1750
                &i.LastUpdate,
×
1751
                &i.Color,
×
1752
                &i.Signature,
×
1753
        )
×
1754
        return i, err
×
1755
}
×
1756

1757
const getNodeExtraTypesBatch = `-- name: GetNodeExtraTypesBatch :many
1758
SELECT node_id, type, value
1759
FROM graph_node_extra_types
1760
WHERE node_id IN (/*SLICE:ids*/?)
1761
ORDER BY node_id, type
1762
`
1763

1764
func (q *Queries) GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]GraphNodeExtraType, error) {
×
1765
        query := getNodeExtraTypesBatch
×
1766
        var queryParams []interface{}
×
1767
        if len(ids) > 0 {
×
1768
                for _, v := range ids {
×
1769
                        queryParams = append(queryParams, v)
×
1770
                }
×
1771
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1772
        } else {
×
1773
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1774
        }
×
1775
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1776
        if err != nil {
×
1777
                return nil, err
×
1778
        }
×
1779
        defer rows.Close()
×
1780
        var items []GraphNodeExtraType
×
1781
        for rows.Next() {
×
1782
                var i GraphNodeExtraType
×
1783
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1784
                        return nil, err
×
1785
                }
×
1786
                items = append(items, i)
×
1787
        }
1788
        if err := rows.Close(); err != nil {
×
1789
                return nil, err
×
1790
        }
×
1791
        if err := rows.Err(); err != nil {
×
1792
                return nil, err
×
1793
        }
×
1794
        return items, nil
×
1795
}
1796

1797
const getNodeFeatures = `-- name: GetNodeFeatures :many
1798
SELECT node_id, feature_bit
1799
FROM graph_node_features
1800
WHERE node_id = $1
1801
`
1802

1803
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error) {
×
1804
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1805
        if err != nil {
×
1806
                return nil, err
×
1807
        }
×
1808
        defer rows.Close()
×
1809
        var items []GraphNodeFeature
×
1810
        for rows.Next() {
×
1811
                var i GraphNodeFeature
×
1812
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1813
                        return nil, err
×
1814
                }
×
1815
                items = append(items, i)
×
1816
        }
1817
        if err := rows.Close(); err != nil {
×
1818
                return nil, err
×
1819
        }
×
1820
        if err := rows.Err(); err != nil {
×
1821
                return nil, err
×
1822
        }
×
1823
        return items, nil
×
1824
}
1825

1826
const getNodeFeaturesBatch = `-- name: GetNodeFeaturesBatch :many
1827
SELECT node_id, feature_bit
1828
FROM graph_node_features
1829
WHERE node_id IN (/*SLICE:ids*/?)
1830
ORDER BY node_id, feature_bit
1831
`
1832

1833
func (q *Queries) GetNodeFeaturesBatch(ctx context.Context, ids []int64) ([]GraphNodeFeature, error) {
×
1834
        query := getNodeFeaturesBatch
×
1835
        var queryParams []interface{}
×
1836
        if len(ids) > 0 {
×
1837
                for _, v := range ids {
×
1838
                        queryParams = append(queryParams, v)
×
1839
                }
×
1840
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1841
        } else {
×
1842
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1843
        }
×
1844
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1845
        if err != nil {
×
1846
                return nil, err
×
1847
        }
×
1848
        defer rows.Close()
×
1849
        var items []GraphNodeFeature
×
1850
        for rows.Next() {
×
1851
                var i GraphNodeFeature
×
1852
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1853
                        return nil, err
×
1854
                }
×
1855
                items = append(items, i)
×
1856
        }
1857
        if err := rows.Close(); err != nil {
×
1858
                return nil, err
×
1859
        }
×
1860
        if err := rows.Err(); err != nil {
×
1861
                return nil, err
×
1862
        }
×
1863
        return items, nil
×
1864
}
1865

1866
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1867
SELECT f.feature_bit
1868
FROM graph_nodes n
1869
    JOIN graph_node_features f ON f.node_id = n.id
1870
WHERE n.pub_key = $1
1871
  AND n.version = $2
1872
`
1873

1874
type GetNodeFeaturesByPubKeyParams struct {
1875
        PubKey  []byte
1876
        Version int16
1877
}
1878

1879
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1880
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1881
        if err != nil {
×
1882
                return nil, err
×
1883
        }
×
1884
        defer rows.Close()
×
1885
        var items []int32
×
1886
        for rows.Next() {
×
1887
                var feature_bit int32
×
1888
                if err := rows.Scan(&feature_bit); err != nil {
×
1889
                        return nil, err
×
1890
                }
×
1891
                items = append(items, feature_bit)
×
1892
        }
1893
        if err := rows.Close(); err != nil {
×
1894
                return nil, err
×
1895
        }
×
1896
        if err := rows.Err(); err != nil {
×
1897
                return nil, err
×
1898
        }
×
1899
        return items, nil
×
1900
}
1901

1902
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1903
SELECT id
1904
FROM graph_nodes
1905
WHERE pub_key = $1
1906
  AND version = $2
1907
`
1908

1909
type GetNodeIDByPubKeyParams struct {
1910
        PubKey  []byte
1911
        Version int16
1912
}
1913

1914
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1915
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1916
        var id int64
×
1917
        err := row.Scan(&id)
×
1918
        return id, err
×
1919
}
×
1920

1921
const getNodesByIDs = `-- name: GetNodesByIDs :many
1922
SELECT id, version, pub_key, alias, last_update, color, signature
1923
FROM graph_nodes
1924
WHERE id IN (/*SLICE:ids*/?)
1925
`
1926

1927
func (q *Queries) GetNodesByIDs(ctx context.Context, ids []int64) ([]GraphNode, error) {
×
1928
        query := getNodesByIDs
×
1929
        var queryParams []interface{}
×
1930
        if len(ids) > 0 {
×
1931
                for _, v := range ids {
×
1932
                        queryParams = append(queryParams, v)
×
1933
                }
×
1934
                query = strings.Replace(query, "/*SLICE:ids*/?", makeQueryParams(len(queryParams), len(ids)), 1)
×
1935
        } else {
×
1936
                query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
×
1937
        }
×
1938
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
1939
        if err != nil {
×
1940
                return nil, err
×
1941
        }
×
1942
        defer rows.Close()
×
1943
        var items []GraphNode
×
1944
        for rows.Next() {
×
1945
                var i GraphNode
×
1946
                if err := rows.Scan(
×
1947
                        &i.ID,
×
1948
                        &i.Version,
×
1949
                        &i.PubKey,
×
1950
                        &i.Alias,
×
1951
                        &i.LastUpdate,
×
1952
                        &i.Color,
×
1953
                        &i.Signature,
×
1954
                ); err != nil {
×
1955
                        return nil, err
×
1956
                }
×
1957
                items = append(items, i)
×
1958
        }
1959
        if err := rows.Close(); err != nil {
×
1960
                return nil, err
×
1961
        }
×
1962
        if err := rows.Err(); err != nil {
×
1963
                return nil, err
×
1964
        }
×
1965
        return items, nil
×
1966
}
1967

1968
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1969
SELECT id, version, pub_key, alias, last_update, color, signature
1970
FROM graph_nodes
1971
WHERE last_update >= $1
1972
  AND last_update < $2
1973
`
1974

1975
type GetNodesByLastUpdateRangeParams struct {
1976
        StartTime sql.NullInt64
1977
        EndTime   sql.NullInt64
1978
}
1979

1980
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
1981
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1982
        if err != nil {
×
1983
                return nil, err
×
1984
        }
×
1985
        defer rows.Close()
×
1986
        var items []GraphNode
×
1987
        for rows.Next() {
×
1988
                var i GraphNode
×
1989
                if err := rows.Scan(
×
1990
                        &i.ID,
×
1991
                        &i.Version,
×
1992
                        &i.PubKey,
×
1993
                        &i.Alias,
×
1994
                        &i.LastUpdate,
×
1995
                        &i.Color,
×
1996
                        &i.Signature,
×
1997
                ); err != nil {
×
1998
                        return nil, err
×
1999
                }
×
2000
                items = append(items, i)
×
2001
        }
2002
        if err := rows.Close(); err != nil {
×
2003
                return nil, err
×
2004
        }
×
2005
        if err := rows.Err(); err != nil {
×
2006
                return nil, err
×
2007
        }
×
2008
        return items, nil
×
2009
}
2010

2011
const getPruneEntriesForHeights = `-- name: GetPruneEntriesForHeights :many
2012
SELECT block_height, block_hash
2013
FROM graph_prune_log
2014
WHERE block_height
2015
   IN (/*SLICE:heights*/?)
2016
`
2017

2018
func (q *Queries) GetPruneEntriesForHeights(ctx context.Context, heights []int64) ([]GraphPruneLog, error) {
×
2019
        query := getPruneEntriesForHeights
×
2020
        var queryParams []interface{}
×
2021
        if len(heights) > 0 {
×
2022
                for _, v := range heights {
×
2023
                        queryParams = append(queryParams, v)
×
2024
                }
×
2025
                query = strings.Replace(query, "/*SLICE:heights*/?", makeQueryParams(len(queryParams), len(heights)), 1)
×
2026
        } else {
×
2027
                query = strings.Replace(query, "/*SLICE:heights*/?", "NULL", 1)
×
2028
        }
×
2029
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2030
        if err != nil {
×
2031
                return nil, err
×
2032
        }
×
2033
        defer rows.Close()
×
2034
        var items []GraphPruneLog
×
2035
        for rows.Next() {
×
2036
                var i GraphPruneLog
×
2037
                if err := rows.Scan(&i.BlockHeight, &i.BlockHash); err != nil {
×
2038
                        return nil, err
×
2039
                }
×
2040
                items = append(items, i)
×
2041
        }
2042
        if err := rows.Close(); err != nil {
×
2043
                return nil, err
×
2044
        }
×
2045
        if err := rows.Err(); err != nil {
×
2046
                return nil, err
×
2047
        }
×
2048
        return items, nil
×
2049
}
2050

2051
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
2052
SELECT block_hash
2053
FROM graph_prune_log
2054
WHERE block_height = $1
2055
`
2056

2057
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
2058
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
2059
        var block_hash []byte
×
2060
        err := row.Scan(&block_hash)
×
2061
        return block_hash, err
×
2062
}
×
2063

2064
const getPruneTip = `-- name: GetPruneTip :one
2065
SELECT block_height, block_hash
2066
FROM graph_prune_log
2067
ORDER BY block_height DESC
2068
LIMIT 1
2069
`
2070

2071
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
2072
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
2073
        var i GraphPruneLog
×
2074
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
2075
        return i, err
×
2076
}
×
2077

2078
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
2079
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
2080
FROM graph_channels
2081
WHERE node_1_signature IS NOT NULL
2082
  AND scid >= $1
2083
  AND scid < $2
2084
`
2085

2086
type GetPublicV1ChannelsBySCIDParams struct {
2087
        StartScid []byte
2088
        EndScid   []byte
2089
}
2090

2091
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
2092
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
2093
        if err != nil {
×
2094
                return nil, err
×
2095
        }
×
2096
        defer rows.Close()
×
2097
        var items []GraphChannel
×
2098
        for rows.Next() {
×
2099
                var i GraphChannel
×
2100
                if err := rows.Scan(
×
2101
                        &i.ID,
×
2102
                        &i.Version,
×
2103
                        &i.Scid,
×
2104
                        &i.NodeID1,
×
2105
                        &i.NodeID2,
×
2106
                        &i.Outpoint,
×
2107
                        &i.Capacity,
×
2108
                        &i.BitcoinKey1,
×
2109
                        &i.BitcoinKey2,
×
2110
                        &i.Node1Signature,
×
2111
                        &i.Node2Signature,
×
2112
                        &i.Bitcoin1Signature,
×
2113
                        &i.Bitcoin2Signature,
×
2114
                ); err != nil {
×
2115
                        return nil, err
×
2116
                }
×
2117
                items = append(items, i)
×
2118
        }
2119
        if err := rows.Close(); err != nil {
×
2120
                return nil, err
×
2121
        }
×
2122
        if err := rows.Err(); err != nil {
×
2123
                return nil, err
×
2124
        }
×
2125
        return items, nil
×
2126
}
2127

2128
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
2129
SELECT scid from graph_channels
2130
WHERE outpoint = $1 AND version = $2
2131
`
2132

2133
type GetSCIDByOutpointParams struct {
2134
        Outpoint string
2135
        Version  int16
2136
}
2137

2138
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
2139
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
2140
        var scid []byte
×
2141
        err := row.Scan(&scid)
×
2142
        return scid, err
×
2143
}
×
2144

2145
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
2146
SELECT sn.node_id, n.pub_key
2147
FROM graph_source_nodes sn
2148
    JOIN graph_nodes n ON sn.node_id = n.id
2149
WHERE n.version = $1
2150
`
2151

2152
type GetSourceNodesByVersionRow struct {
2153
        NodeID int64
2154
        PubKey []byte
2155
}
2156

2157
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
2158
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
2159
        if err != nil {
×
2160
                return nil, err
×
2161
        }
×
2162
        defer rows.Close()
×
2163
        var items []GetSourceNodesByVersionRow
×
2164
        for rows.Next() {
×
2165
                var i GetSourceNodesByVersionRow
×
2166
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
2167
                        return nil, err
×
2168
                }
×
2169
                items = append(items, i)
×
2170
        }
2171
        if err := rows.Close(); err != nil {
×
2172
                return nil, err
×
2173
        }
×
2174
        if err := rows.Err(); err != nil {
×
2175
                return nil, err
×
2176
        }
×
2177
        return items, nil
×
2178
}
2179

2180
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
2181
SELECT c.scid
2182
FROM graph_channels c
2183
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2184
WHERE cp.disabled = true
2185
AND c.version = 1
2186
GROUP BY c.scid
2187
HAVING COUNT(*) > 1
2188
`
2189

2190
// NOTE: this is V1 specific since for V1, disabled is a
2191
// simple, single boolean. The proposed V2 policy
2192
// structure will have a more complex disabled bit vector
2193
// and so the query for V2 may differ.
2194
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2195
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
2196
        if err != nil {
×
2197
                return nil, err
×
2198
        }
×
2199
        defer rows.Close()
×
2200
        var items [][]byte
×
2201
        for rows.Next() {
×
2202
                var scid []byte
×
2203
                if err := rows.Scan(&scid); err != nil {
×
2204
                        return nil, err
×
2205
                }
×
2206
                items = append(items, scid)
×
2207
        }
2208
        if err := rows.Close(); err != nil {
×
2209
                return nil, err
×
2210
        }
×
2211
        if err := rows.Err(); err != nil {
×
2212
                return nil, err
×
2213
        }
×
2214
        return items, nil
×
2215
}
2216

2217
const getZombieChannel = `-- name: GetZombieChannel :one
2218
SELECT scid, version, node_key_1, node_key_2
2219
FROM graph_zombie_channels
2220
WHERE scid = $1
2221
AND version = $2
2222
`
2223

2224
type GetZombieChannelParams struct {
2225
        Scid    []byte
2226
        Version int16
2227
}
2228

2229
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
2230
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
2231
        var i GraphZombieChannel
×
2232
        err := row.Scan(
×
2233
                &i.Scid,
×
2234
                &i.Version,
×
2235
                &i.NodeKey1,
×
2236
                &i.NodeKey2,
×
2237
        )
×
2238
        return i, err
×
2239
}
×
2240

2241
const getZombieChannelsSCIDs = `-- name: GetZombieChannelsSCIDs :many
2242
SELECT scid, version, node_key_1, node_key_2
2243
FROM graph_zombie_channels
2244
WHERE version = $1
2245
  AND scid IN (/*SLICE:scids*/?)
2246
`
2247

2248
type GetZombieChannelsSCIDsParams struct {
2249
        Version int16
2250
        Scids   [][]byte
2251
}
2252

2253
func (q *Queries) GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error) {
×
2254
        query := getZombieChannelsSCIDs
×
2255
        var queryParams []interface{}
×
2256
        queryParams = append(queryParams, arg.Version)
×
2257
        if len(arg.Scids) > 0 {
×
2258
                for _, v := range arg.Scids {
×
2259
                        queryParams = append(queryParams, v)
×
2260
                }
×
2261
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
2262
        } else {
×
2263
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
2264
        }
×
2265
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2266
        if err != nil {
×
2267
                return nil, err
×
2268
        }
×
2269
        defer rows.Close()
×
2270
        var items []GraphZombieChannel
×
2271
        for rows.Next() {
×
2272
                var i GraphZombieChannel
×
2273
                if err := rows.Scan(
×
2274
                        &i.Scid,
×
2275
                        &i.Version,
×
2276
                        &i.NodeKey1,
×
2277
                        &i.NodeKey2,
×
2278
                ); err != nil {
×
2279
                        return nil, err
×
2280
                }
×
2281
                items = append(items, i)
×
2282
        }
2283
        if err := rows.Close(); err != nil {
×
2284
                return nil, err
×
2285
        }
×
2286
        if err := rows.Err(); err != nil {
×
2287
                return nil, err
×
2288
        }
×
2289
        return items, nil
×
2290
}
2291

2292
const highestSCID = `-- name: HighestSCID :one
2293
SELECT scid
2294
FROM graph_channels
2295
WHERE version = $1
2296
ORDER BY scid DESC
2297
LIMIT 1
2298
`
2299

2300
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
2301
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
2302
        var scid []byte
×
2303
        err := row.Scan(&scid)
×
2304
        return scid, err
×
2305
}
×
2306

2307
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2308
/* ─────────────────────────────────────────────
2309
   graph_channel_features table queries
2310
   ─────────────────────────────────────────────
2311
*/
2312

2313
INSERT INTO graph_channel_features (
2314
    channel_id, feature_bit
2315
) VALUES (
2316
    $1, $2
2317
) ON CONFLICT (channel_id, feature_bit)
2318
    -- Do nothing if the channel_id and feature_bit already exist.
2319
    DO NOTHING
2320
`
2321

2322
type InsertChannelFeatureParams struct {
2323
        ChannelID  int64
2324
        FeatureBit int32
2325
}
2326

2327
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2328
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2329
        return err
×
2330
}
×
2331

2332
const insertChannelMig = `-- name: InsertChannelMig :one
2333
INSERT INTO graph_channels (
2334
    version, scid, node_id_1, node_id_2,
2335
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
2336
    node_1_signature, node_2_signature, bitcoin_1_signature,
2337
    bitcoin_2_signature
2338
) VALUES (
2339
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
2340
) ON CONFLICT (scid, version)
2341
    -- If a conflict occurs, we have already migrated this channel. However, we
2342
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2343
    -- otherwise, the "RETURNING id" part does not work.
2344
    DO UPDATE SET
2345
        node_id_1 = EXCLUDED.node_id_1,
2346
        node_id_2 = EXCLUDED.node_id_2,
2347
        outpoint = EXCLUDED.outpoint,
2348
        capacity = EXCLUDED.capacity,
2349
        bitcoin_key_1 = EXCLUDED.bitcoin_key_1,
2350
        bitcoin_key_2 = EXCLUDED.bitcoin_key_2,
2351
        node_1_signature = EXCLUDED.node_1_signature,
2352
        node_2_signature = EXCLUDED.node_2_signature,
2353
        bitcoin_1_signature = EXCLUDED.bitcoin_1_signature,
2354
        bitcoin_2_signature = EXCLUDED.bitcoin_2_signature
2355
RETURNING id
2356
`
2357

2358
type InsertChannelMigParams struct {
2359
        Version           int16
2360
        Scid              []byte
2361
        NodeID1           int64
2362
        NodeID2           int64
2363
        Outpoint          string
2364
        Capacity          sql.NullInt64
2365
        BitcoinKey1       []byte
2366
        BitcoinKey2       []byte
2367
        Node1Signature    []byte
2368
        Node2Signature    []byte
2369
        Bitcoin1Signature []byte
2370
        Bitcoin2Signature []byte
2371
}
2372

2373
// NOTE: This query is only meant to be used by the graph SQL migration since
2374
// for that migration, in order to be retry-safe, we don't want to error out if
2375
// we re-insert the same channel again (which would error if the normal
2376
// CreateChannel query is used because of the uniqueness constraint on the scid
2377
// and version columns).
NEW
2378
func (q *Queries) InsertChannelMig(ctx context.Context, arg InsertChannelMigParams) (int64, error) {
×
NEW
2379
        row := q.db.QueryRowContext(ctx, insertChannelMig,
×
NEW
2380
                arg.Version,
×
NEW
2381
                arg.Scid,
×
NEW
2382
                arg.NodeID1,
×
NEW
2383
                arg.NodeID2,
×
NEW
2384
                arg.Outpoint,
×
NEW
2385
                arg.Capacity,
×
NEW
2386
                arg.BitcoinKey1,
×
NEW
2387
                arg.BitcoinKey2,
×
NEW
2388
                arg.Node1Signature,
×
NEW
2389
                arg.Node2Signature,
×
NEW
2390
                arg.Bitcoin1Signature,
×
NEW
2391
                arg.Bitcoin2Signature,
×
NEW
2392
        )
×
NEW
2393
        var id int64
×
NEW
2394
        err := row.Scan(&id)
×
NEW
2395
        return id, err
×
NEW
2396
}
×
2397

2398
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2399
/* ─────────────────────────────────────────────
2400
   graph_closed_scid table queries
2401
   ────────────────────────────────────────────-
2402
*/
2403

2404
INSERT INTO graph_closed_scids (scid)
2405
VALUES ($1)
2406
ON CONFLICT (scid) DO NOTHING
2407
`
2408

2409
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2410
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2411
        return err
×
2412
}
×
2413

2414
const insertEdgePolicyMig = `-- name: InsertEdgePolicyMig :one
2415
INSERT INTO graph_channel_policies (
2416
    version, channel_id, node_id, timelock, fee_ppm,
2417
    base_fee_msat, min_htlc_msat, last_update, disabled,
2418
    max_htlc_msat, inbound_base_fee_msat,
2419
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2420
    signature
2421
) VALUES  (
2422
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2423
)
2424
ON CONFLICT (channel_id, node_id, version)
2425
    -- If a conflict occurs, we have already migrated this policy. However, we
2426
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2427
    -- otherwise, the "RETURNING id" part does not work.
2428
    DO UPDATE SET
2429
        timelock = EXCLUDED.timelock,
2430
        fee_ppm = EXCLUDED.fee_ppm,
2431
        base_fee_msat = EXCLUDED.base_fee_msat,
2432
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2433
        last_update = EXCLUDED.last_update,
2434
        disabled = EXCLUDED.disabled,
2435
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2436
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2437
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2438
        message_flags = EXCLUDED.message_flags,
2439
        channel_flags = EXCLUDED.channel_flags,
2440
        signature = EXCLUDED.signature
2441
RETURNING id
2442
`
2443

2444
type InsertEdgePolicyMigParams struct {
2445
        Version                 int16
2446
        ChannelID               int64
2447
        NodeID                  int64
2448
        Timelock                int32
2449
        FeePpm                  int64
2450
        BaseFeeMsat             int64
2451
        MinHtlcMsat             int64
2452
        LastUpdate              sql.NullInt64
2453
        Disabled                sql.NullBool
2454
        MaxHtlcMsat             sql.NullInt64
2455
        InboundBaseFeeMsat      sql.NullInt64
2456
        InboundFeeRateMilliMsat sql.NullInt64
2457
        MessageFlags            sql.NullInt16
2458
        ChannelFlags            sql.NullInt16
2459
        Signature               []byte
2460
}
2461

2462
// NOTE: This query is only meant to be used by the graph SQL migration since
2463
// for that migration, in order to be retry-safe, we don't want to error out if
2464
// we re-insert the same policy (which would error if the normal
2465
// UpsertEdgePolicy query is used because of the constraint in that query that
2466
// requires a policy update to have a newer last_update than the existing one).
NEW
2467
func (q *Queries) InsertEdgePolicyMig(ctx context.Context, arg InsertEdgePolicyMigParams) (int64, error) {
×
NEW
2468
        row := q.db.QueryRowContext(ctx, insertEdgePolicyMig,
×
NEW
2469
                arg.Version,
×
NEW
2470
                arg.ChannelID,
×
2471
                arg.NodeID,
×
NEW
2472
                arg.Timelock,
×
NEW
2473
                arg.FeePpm,
×
NEW
2474
                arg.BaseFeeMsat,
×
NEW
2475
                arg.MinHtlcMsat,
×
NEW
2476
                arg.LastUpdate,
×
NEW
2477
                arg.Disabled,
×
NEW
2478
                arg.MaxHtlcMsat,
×
NEW
2479
                arg.InboundBaseFeeMsat,
×
NEW
2480
                arg.InboundFeeRateMilliMsat,
×
NEW
2481
                arg.MessageFlags,
×
NEW
2482
                arg.ChannelFlags,
×
NEW
2483
                arg.Signature,
×
2484
        )
×
NEW
2485
        var id int64
×
NEW
2486
        err := row.Scan(&id)
×
NEW
2487
        return id, err
×
2488
}
×
2489

2490
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2491
/* ─────────────────────────────────────────────
2492
   graph_node_features table queries
2493
   ─────────────────────────────────────────────
2494
*/
2495

2496
INSERT INTO graph_node_features (
2497
    node_id, feature_bit
2498
) VALUES (
2499
    $1, $2
2500
) ON CONFLICT (node_id, feature_bit)
2501
    -- Do nothing if the feature already exists for the node.
2502
    DO NOTHING
2503
`
2504

2505
type InsertNodeFeatureParams struct {
2506
        NodeID     int64
2507
        FeatureBit int32
2508
}
2509

2510
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2511
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2512
        return err
×
2513
}
×
2514

2515
const insertNodeMig = `-- name: InsertNodeMig :one
2516
/* ─────────────────────────────────────────────
2517
   Migration specific queries
2518

2519
   NOTE: once sqldbv2 is in place, these queries can be contained to a package
2520
   dedicated to the migration that requires it, and so we can then remove
2521
   it from the main set of "live" queries that the code-base has access to.
2522
   ────────────────────────────────────────────-
2523
*/
2524

2525
INSERT INTO graph_nodes (
2526
    version, pub_key, alias, last_update, color, signature
2527
) VALUES (
2528
    $1, $2, $3, $4, $5, $6
2529
)
2530
ON CONFLICT (pub_key, version)
2531
    -- If a conflict occurs, we have already migrated this node. However, we
2532
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2533
    -- otherwise, the "RETURNING id" part does not work.
2534
    DO UPDATE SET
2535
        alias = EXCLUDED.alias,
2536
        last_update = EXCLUDED.last_update,
2537
        color = EXCLUDED.color,
2538
        signature = EXCLUDED.signature
2539
RETURNING id
2540
`
2541

2542
type InsertNodeMigParams struct {
2543
        Version    int16
2544
        PubKey     []byte
2545
        Alias      sql.NullString
2546
        LastUpdate sql.NullInt64
2547
        Color      sql.NullString
2548
        Signature  []byte
2549
}
2550

2551
// NOTE: This query is only meant to be used by the graph SQL migration since
2552
// for that migration, in order to be retry-safe, we don't want to error out if
2553
// we re-insert the same node (which would error if the normal UpsertNode query
2554
// is used because of the constraint in that query that requires a node update
2555
// to have a newer last_update than the existing node).
NEW
2556
func (q *Queries) InsertNodeMig(ctx context.Context, arg InsertNodeMigParams) (int64, error) {
×
NEW
2557
        row := q.db.QueryRowContext(ctx, insertNodeMig,
×
NEW
2558
                arg.Version,
×
NEW
2559
                arg.PubKey,
×
NEW
2560
                arg.Alias,
×
NEW
2561
                arg.LastUpdate,
×
NEW
2562
                arg.Color,
×
NEW
2563
                arg.Signature,
×
NEW
2564
        )
×
NEW
2565
        var id int64
×
NEW
2566
        err := row.Scan(&id)
×
NEW
2567
        return id, err
×
NEW
2568
}
×
2569

2570
const isClosedChannel = `-- name: IsClosedChannel :one
2571
SELECT EXISTS (
2572
    SELECT 1
2573
    FROM graph_closed_scids
2574
    WHERE scid = $1
2575
)
2576
`
2577

2578
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2579
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2580
        var exists bool
×
2581
        err := row.Scan(&exists)
×
2582
        return exists, err
×
2583
}
×
2584

2585
const isPublicV1Node = `-- name: IsPublicV1Node :one
2586
SELECT EXISTS (
2587
    SELECT 1
2588
    FROM graph_channels c
2589
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
2590
    -- NOTE: we hard-code the version here since the clauses
2591
    -- here that determine if a node is public is specific
2592
    -- to the V1 gossip protocol. In V1, a node is public
2593
    -- if it has a public channel and a public channel is one
2594
    -- where we have the set of signatures of the channel
2595
    -- announcement. It is enough to just check that we have
2596
    -- one of the signatures since we only ever set them
2597
    -- together.
2598
    WHERE c.version = 1
2599
      AND c.bitcoin_1_signature IS NOT NULL
2600
      AND n.pub_key = $1
2601
)
2602
`
2603

2604
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2605
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2606
        var exists bool
×
2607
        err := row.Scan(&exists)
×
2608
        return exists, err
×
2609
}
×
2610

2611
const isZombieChannel = `-- name: IsZombieChannel :one
2612
SELECT EXISTS (
2613
    SELECT 1
2614
    FROM graph_zombie_channels
2615
    WHERE scid = $1
2616
    AND version = $2
2617
) AS is_zombie
2618
`
2619

2620
type IsZombieChannelParams struct {
2621
        Scid    []byte
2622
        Version int16
2623
}
2624

2625
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2626
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2627
        var is_zombie bool
×
2628
        err := row.Scan(&is_zombie)
×
2629
        return is_zombie, err
×
2630
}
×
2631

2632
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2633
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,
2634
    n1.pub_key AS node1_pubkey,
2635
    n2.pub_key AS node2_pubkey,
2636

2637
    -- Policy 1
2638
    -- TODO(elle): use sqlc.embed to embed policy structs
2639
    --  once this issue is resolved:
2640
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2641
    cp1.id AS policy1_id,
2642
    cp1.node_id AS policy1_node_id,
2643
    cp1.version AS policy1_version,
2644
    cp1.timelock AS policy1_timelock,
2645
    cp1.fee_ppm AS policy1_fee_ppm,
2646
    cp1.base_fee_msat AS policy1_base_fee_msat,
2647
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2648
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2649
    cp1.last_update AS policy1_last_update,
2650
    cp1.disabled AS policy1_disabled,
2651
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2652
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2653
    cp1.message_flags AS policy1_message_flags,
2654
    cp1.channel_flags AS policy1_channel_flags,
2655
    cp1.signature AS policy1_signature,
2656

2657
       -- Policy 2
2658
    cp2.id AS policy2_id,
2659
    cp2.node_id AS policy2_node_id,
2660
    cp2.version AS policy2_version,
2661
    cp2.timelock AS policy2_timelock,
2662
    cp2.fee_ppm AS policy2_fee_ppm,
2663
    cp2.base_fee_msat AS policy2_base_fee_msat,
2664
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2665
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2666
    cp2.last_update AS policy2_last_update,
2667
    cp2.disabled AS policy2_disabled,
2668
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2669
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2670
    cp2.message_flags AS policy2_message_flags,
2671
    cp2.channel_flags AS policy2_channel_flags,
2672
    cp2.signature AS policy2_signature
2673

2674
FROM graph_channels c
2675
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2676
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2677
    LEFT JOIN graph_channel_policies cp1
2678
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2679
    LEFT JOIN graph_channel_policies cp2
2680
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2681
WHERE c.version = $1
2682
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2683
`
2684

2685
type ListChannelsByNodeIDParams struct {
2686
        Version int16
2687
        NodeID1 int64
2688
}
2689

2690
type ListChannelsByNodeIDRow struct {
2691
        GraphChannel                   GraphChannel
2692
        Node1Pubkey                    []byte
2693
        Node2Pubkey                    []byte
2694
        Policy1ID                      sql.NullInt64
2695
        Policy1NodeID                  sql.NullInt64
2696
        Policy1Version                 sql.NullInt16
2697
        Policy1Timelock                sql.NullInt32
2698
        Policy1FeePpm                  sql.NullInt64
2699
        Policy1BaseFeeMsat             sql.NullInt64
2700
        Policy1MinHtlcMsat             sql.NullInt64
2701
        Policy1MaxHtlcMsat             sql.NullInt64
2702
        Policy1LastUpdate              sql.NullInt64
2703
        Policy1Disabled                sql.NullBool
2704
        Policy1InboundBaseFeeMsat      sql.NullInt64
2705
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2706
        Policy1MessageFlags            sql.NullInt16
2707
        Policy1ChannelFlags            sql.NullInt16
2708
        Policy1Signature               []byte
2709
        Policy2ID                      sql.NullInt64
2710
        Policy2NodeID                  sql.NullInt64
2711
        Policy2Version                 sql.NullInt16
2712
        Policy2Timelock                sql.NullInt32
2713
        Policy2FeePpm                  sql.NullInt64
2714
        Policy2BaseFeeMsat             sql.NullInt64
2715
        Policy2MinHtlcMsat             sql.NullInt64
2716
        Policy2MaxHtlcMsat             sql.NullInt64
2717
        Policy2LastUpdate              sql.NullInt64
2718
        Policy2Disabled                sql.NullBool
2719
        Policy2InboundBaseFeeMsat      sql.NullInt64
2720
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2721
        Policy2MessageFlags            sql.NullInt16
2722
        Policy2ChannelFlags            sql.NullInt16
2723
        Policy2Signature               []byte
2724
}
2725

2726
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2727
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2728
        if err != nil {
×
2729
                return nil, err
×
2730
        }
×
2731
        defer rows.Close()
×
2732
        var items []ListChannelsByNodeIDRow
×
2733
        for rows.Next() {
×
2734
                var i ListChannelsByNodeIDRow
×
2735
                if err := rows.Scan(
×
2736
                        &i.GraphChannel.ID,
×
2737
                        &i.GraphChannel.Version,
×
2738
                        &i.GraphChannel.Scid,
×
2739
                        &i.GraphChannel.NodeID1,
×
2740
                        &i.GraphChannel.NodeID2,
×
2741
                        &i.GraphChannel.Outpoint,
×
2742
                        &i.GraphChannel.Capacity,
×
2743
                        &i.GraphChannel.BitcoinKey1,
×
2744
                        &i.GraphChannel.BitcoinKey2,
×
2745
                        &i.GraphChannel.Node1Signature,
×
2746
                        &i.GraphChannel.Node2Signature,
×
2747
                        &i.GraphChannel.Bitcoin1Signature,
×
2748
                        &i.GraphChannel.Bitcoin2Signature,
×
2749
                        &i.Node1Pubkey,
×
2750
                        &i.Node2Pubkey,
×
2751
                        &i.Policy1ID,
×
2752
                        &i.Policy1NodeID,
×
2753
                        &i.Policy1Version,
×
2754
                        &i.Policy1Timelock,
×
2755
                        &i.Policy1FeePpm,
×
2756
                        &i.Policy1BaseFeeMsat,
×
2757
                        &i.Policy1MinHtlcMsat,
×
2758
                        &i.Policy1MaxHtlcMsat,
×
2759
                        &i.Policy1LastUpdate,
×
2760
                        &i.Policy1Disabled,
×
2761
                        &i.Policy1InboundBaseFeeMsat,
×
2762
                        &i.Policy1InboundFeeRateMilliMsat,
×
2763
                        &i.Policy1MessageFlags,
×
2764
                        &i.Policy1ChannelFlags,
×
2765
                        &i.Policy1Signature,
×
2766
                        &i.Policy2ID,
×
2767
                        &i.Policy2NodeID,
×
2768
                        &i.Policy2Version,
×
2769
                        &i.Policy2Timelock,
×
2770
                        &i.Policy2FeePpm,
×
2771
                        &i.Policy2BaseFeeMsat,
×
2772
                        &i.Policy2MinHtlcMsat,
×
2773
                        &i.Policy2MaxHtlcMsat,
×
2774
                        &i.Policy2LastUpdate,
×
2775
                        &i.Policy2Disabled,
×
2776
                        &i.Policy2InboundBaseFeeMsat,
×
2777
                        &i.Policy2InboundFeeRateMilliMsat,
×
2778
                        &i.Policy2MessageFlags,
×
2779
                        &i.Policy2ChannelFlags,
×
2780
                        &i.Policy2Signature,
×
2781
                ); err != nil {
×
2782
                        return nil, err
×
2783
                }
×
2784
                items = append(items, i)
×
2785
        }
2786
        if err := rows.Close(); err != nil {
×
2787
                return nil, err
×
2788
        }
×
2789
        if err := rows.Err(); err != nil {
×
2790
                return nil, err
×
2791
        }
×
2792
        return items, nil
×
2793
}
2794

2795
const listChannelsForNodeIDs = `-- name: ListChannelsForNodeIDs :many
2796
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,
2797
       n1.pub_key AS node1_pubkey,
2798
       n2.pub_key AS node2_pubkey,
2799

2800
       -- Policy 1
2801
       -- TODO(elle): use sqlc.embed to embed policy structs
2802
       --  once this issue is resolved:
2803
       --  https://github.com/sqlc-dev/sqlc/issues/2997
2804
       cp1.id AS policy1_id,
2805
       cp1.node_id AS policy1_node_id,
2806
       cp1.version AS policy1_version,
2807
       cp1.timelock AS policy1_timelock,
2808
       cp1.fee_ppm AS policy1_fee_ppm,
2809
       cp1.base_fee_msat AS policy1_base_fee_msat,
2810
       cp1.min_htlc_msat AS policy1_min_htlc_msat,
2811
       cp1.max_htlc_msat AS policy1_max_htlc_msat,
2812
       cp1.last_update AS policy1_last_update,
2813
       cp1.disabled AS policy1_disabled,
2814
       cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2815
       cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2816
       cp1.message_flags AS policy1_message_flags,
2817
       cp1.channel_flags AS policy1_channel_flags,
2818
       cp1.signature AS policy1_signature,
2819

2820
       -- Policy 2
2821
       cp2.id AS policy2_id,
2822
       cp2.node_id AS policy2_node_id,
2823
       cp2.version AS policy2_version,
2824
       cp2.timelock AS policy2_timelock,
2825
       cp2.fee_ppm AS policy2_fee_ppm,
2826
       cp2.base_fee_msat AS policy2_base_fee_msat,
2827
       cp2.min_htlc_msat AS policy2_min_htlc_msat,
2828
       cp2.max_htlc_msat AS policy2_max_htlc_msat,
2829
       cp2.last_update AS policy2_last_update,
2830
       cp2.disabled AS policy2_disabled,
2831
       cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2832
       cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2833
       cp2.message_flags AS policy2_message_flags,
2834
       cp2.channel_flags AS policy2_channel_flags,
2835
       cp2.signature AS policy2_signature
2836

2837
FROM graph_channels c
2838
         JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2839
         JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2840
         LEFT JOIN graph_channel_policies cp1
2841
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2842
         LEFT JOIN graph_channel_policies cp2
2843
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2844
WHERE c.version = $1
2845
  AND (c.node_id_1 IN (/*SLICE:node1_ids*/?)
2846
   OR c.node_id_2 IN (/*SLICE:node2_ids*/?))
2847
`
2848

2849
type ListChannelsForNodeIDsParams struct {
2850
        Version  int16
2851
        Node1Ids []int64
2852
        Node2Ids []int64
2853
}
2854

2855
type ListChannelsForNodeIDsRow struct {
2856
        GraphChannel                   GraphChannel
2857
        Node1Pubkey                    []byte
2858
        Node2Pubkey                    []byte
2859
        Policy1ID                      sql.NullInt64
2860
        Policy1NodeID                  sql.NullInt64
2861
        Policy1Version                 sql.NullInt16
2862
        Policy1Timelock                sql.NullInt32
2863
        Policy1FeePpm                  sql.NullInt64
2864
        Policy1BaseFeeMsat             sql.NullInt64
2865
        Policy1MinHtlcMsat             sql.NullInt64
2866
        Policy1MaxHtlcMsat             sql.NullInt64
2867
        Policy1LastUpdate              sql.NullInt64
2868
        Policy1Disabled                sql.NullBool
2869
        Policy1InboundBaseFeeMsat      sql.NullInt64
2870
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2871
        Policy1MessageFlags            sql.NullInt16
2872
        Policy1ChannelFlags            sql.NullInt16
2873
        Policy1Signature               []byte
2874
        Policy2ID                      sql.NullInt64
2875
        Policy2NodeID                  sql.NullInt64
2876
        Policy2Version                 sql.NullInt16
2877
        Policy2Timelock                sql.NullInt32
2878
        Policy2FeePpm                  sql.NullInt64
2879
        Policy2BaseFeeMsat             sql.NullInt64
2880
        Policy2MinHtlcMsat             sql.NullInt64
2881
        Policy2MaxHtlcMsat             sql.NullInt64
2882
        Policy2LastUpdate              sql.NullInt64
2883
        Policy2Disabled                sql.NullBool
2884
        Policy2InboundBaseFeeMsat      sql.NullInt64
2885
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2886
        Policy2MessageFlags            sql.NullInt16
2887
        Policy2ChannelFlags            sql.NullInt16
2888
        Policy2Signature               []byte
2889
}
2890

2891
func (q *Queries) ListChannelsForNodeIDs(ctx context.Context, arg ListChannelsForNodeIDsParams) ([]ListChannelsForNodeIDsRow, error) {
×
2892
        query := listChannelsForNodeIDs
×
2893
        var queryParams []interface{}
×
2894
        queryParams = append(queryParams, arg.Version)
×
2895
        if len(arg.Node1Ids) > 0 {
×
2896
                for _, v := range arg.Node1Ids {
×
2897
                        queryParams = append(queryParams, v)
×
2898
                }
×
2899
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", makeQueryParams(len(queryParams), len(arg.Node1Ids)), 1)
×
2900
        } else {
×
2901
                query = strings.Replace(query, "/*SLICE:node1_ids*/?", "NULL", 1)
×
2902
        }
×
2903
        if len(arg.Node2Ids) > 0 {
×
2904
                for _, v := range arg.Node2Ids {
×
2905
                        queryParams = append(queryParams, v)
×
2906
                }
×
2907
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", makeQueryParams(len(queryParams), len(arg.Node2Ids)), 1)
×
2908
        } else {
×
2909
                query = strings.Replace(query, "/*SLICE:node2_ids*/?", "NULL", 1)
×
2910
        }
×
2911
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2912
        if err != nil {
×
2913
                return nil, err
×
2914
        }
×
2915
        defer rows.Close()
×
2916
        var items []ListChannelsForNodeIDsRow
×
2917
        for rows.Next() {
×
2918
                var i ListChannelsForNodeIDsRow
×
2919
                if err := rows.Scan(
×
2920
                        &i.GraphChannel.ID,
×
2921
                        &i.GraphChannel.Version,
×
2922
                        &i.GraphChannel.Scid,
×
2923
                        &i.GraphChannel.NodeID1,
×
2924
                        &i.GraphChannel.NodeID2,
×
2925
                        &i.GraphChannel.Outpoint,
×
2926
                        &i.GraphChannel.Capacity,
×
2927
                        &i.GraphChannel.BitcoinKey1,
×
2928
                        &i.GraphChannel.BitcoinKey2,
×
2929
                        &i.GraphChannel.Node1Signature,
×
2930
                        &i.GraphChannel.Node2Signature,
×
2931
                        &i.GraphChannel.Bitcoin1Signature,
×
2932
                        &i.GraphChannel.Bitcoin2Signature,
×
2933
                        &i.Node1Pubkey,
×
2934
                        &i.Node2Pubkey,
×
2935
                        &i.Policy1ID,
×
2936
                        &i.Policy1NodeID,
×
2937
                        &i.Policy1Version,
×
2938
                        &i.Policy1Timelock,
×
2939
                        &i.Policy1FeePpm,
×
2940
                        &i.Policy1BaseFeeMsat,
×
2941
                        &i.Policy1MinHtlcMsat,
×
2942
                        &i.Policy1MaxHtlcMsat,
×
2943
                        &i.Policy1LastUpdate,
×
2944
                        &i.Policy1Disabled,
×
2945
                        &i.Policy1InboundBaseFeeMsat,
×
2946
                        &i.Policy1InboundFeeRateMilliMsat,
×
2947
                        &i.Policy1MessageFlags,
×
2948
                        &i.Policy1ChannelFlags,
×
2949
                        &i.Policy1Signature,
×
2950
                        &i.Policy2ID,
×
2951
                        &i.Policy2NodeID,
×
2952
                        &i.Policy2Version,
×
2953
                        &i.Policy2Timelock,
×
2954
                        &i.Policy2FeePpm,
×
2955
                        &i.Policy2BaseFeeMsat,
×
2956
                        &i.Policy2MinHtlcMsat,
×
2957
                        &i.Policy2MaxHtlcMsat,
×
2958
                        &i.Policy2LastUpdate,
×
2959
                        &i.Policy2Disabled,
×
2960
                        &i.Policy2InboundBaseFeeMsat,
×
2961
                        &i.Policy2InboundFeeRateMilliMsat,
×
2962
                        &i.Policy2MessageFlags,
×
2963
                        &i.Policy2ChannelFlags,
×
2964
                        &i.Policy2Signature,
×
2965
                ); err != nil {
×
2966
                        return nil, err
×
2967
                }
×
2968
                items = append(items, i)
×
2969
        }
2970
        if err := rows.Close(); err != nil {
×
2971
                return nil, err
×
2972
        }
×
2973
        if err := rows.Err(); err != nil {
×
2974
                return nil, err
×
2975
        }
×
2976
        return items, nil
×
2977
}
2978

2979
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
2980
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
2981
FROM graph_channels c
2982
WHERE c.version = $1 AND c.id > $2
2983
ORDER BY c.id
2984
LIMIT $3
2985
`
2986

2987
type ListChannelsPaginatedParams struct {
2988
        Version int16
2989
        ID      int64
2990
        Limit   int32
2991
}
2992

2993
type ListChannelsPaginatedRow struct {
2994
        ID          int64
2995
        BitcoinKey1 []byte
2996
        BitcoinKey2 []byte
2997
        Outpoint    string
2998
}
2999

3000
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
3001
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
3002
        if err != nil {
×
3003
                return nil, err
×
3004
        }
×
3005
        defer rows.Close()
×
3006
        var items []ListChannelsPaginatedRow
×
3007
        for rows.Next() {
×
3008
                var i ListChannelsPaginatedRow
×
3009
                if err := rows.Scan(
×
3010
                        &i.ID,
×
3011
                        &i.BitcoinKey1,
×
3012
                        &i.BitcoinKey2,
×
3013
                        &i.Outpoint,
×
3014
                ); err != nil {
×
3015
                        return nil, err
×
3016
                }
×
3017
                items = append(items, i)
×
3018
        }
3019
        if err := rows.Close(); err != nil {
×
3020
                return nil, err
×
3021
        }
×
3022
        if err := rows.Err(); err != nil {
×
3023
                return nil, err
×
3024
        }
×
3025
        return items, nil
×
3026
}
3027

3028
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
3029
SELECT
3030
    c.id as id,
3031
    c.scid as scid,
3032
    c.capacity AS capacity,
3033

3034
    -- Join node pubkeys
3035
    n1.pub_key AS node1_pubkey,
3036
    n2.pub_key AS node2_pubkey,
3037

3038
    -- Node 1 policy
3039
    cp1.timelock AS policy_1_timelock,
3040
    cp1.fee_ppm AS policy_1_fee_ppm,
3041
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3042
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3043
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3044
    cp1.disabled AS policy_1_disabled,
3045
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3046
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3047
    cp1.message_flags AS policy1_message_flags,
3048
    cp1.channel_flags AS policy1_channel_flags,
3049

3050
    -- Node 2 policy
3051
    cp2.timelock AS policy_2_timelock,
3052
    cp2.fee_ppm AS policy_2_fee_ppm,
3053
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3054
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3055
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3056
    cp2.disabled AS policy_2_disabled,
3057
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3058
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3059
    cp2.message_flags AS policy2_message_flags,
3060
    cp2.channel_flags AS policy2_channel_flags
3061

3062
FROM graph_channels c
3063
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3064
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3065
LEFT JOIN graph_channel_policies cp1
3066
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3067
LEFT JOIN graph_channel_policies cp2
3068
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3069
WHERE c.version = $1 AND c.id > $2
3070
ORDER BY c.id
3071
LIMIT $3
3072
`
3073

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

3080
type ListChannelsWithPoliciesForCachePaginatedRow struct {
3081
        ID                             int64
3082
        Scid                           []byte
3083
        Capacity                       sql.NullInt64
3084
        Node1Pubkey                    []byte
3085
        Node2Pubkey                    []byte
3086
        Policy1Timelock                sql.NullInt32
3087
        Policy1FeePpm                  sql.NullInt64
3088
        Policy1BaseFeeMsat             sql.NullInt64
3089
        Policy1MinHtlcMsat             sql.NullInt64
3090
        Policy1MaxHtlcMsat             sql.NullInt64
3091
        Policy1Disabled                sql.NullBool
3092
        Policy1InboundBaseFeeMsat      sql.NullInt64
3093
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3094
        Policy1MessageFlags            sql.NullInt16
3095
        Policy1ChannelFlags            sql.NullInt16
3096
        Policy2Timelock                sql.NullInt32
3097
        Policy2FeePpm                  sql.NullInt64
3098
        Policy2BaseFeeMsat             sql.NullInt64
3099
        Policy2MinHtlcMsat             sql.NullInt64
3100
        Policy2MaxHtlcMsat             sql.NullInt64
3101
        Policy2Disabled                sql.NullBool
3102
        Policy2InboundBaseFeeMsat      sql.NullInt64
3103
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3104
        Policy2MessageFlags            sql.NullInt16
3105
        Policy2ChannelFlags            sql.NullInt16
3106
}
3107

3108
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
3109
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
3110
        if err != nil {
×
3111
                return nil, err
×
3112
        }
×
3113
        defer rows.Close()
×
3114
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
3115
        for rows.Next() {
×
3116
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
3117
                if err := rows.Scan(
×
3118
                        &i.ID,
×
3119
                        &i.Scid,
×
3120
                        &i.Capacity,
×
3121
                        &i.Node1Pubkey,
×
3122
                        &i.Node2Pubkey,
×
3123
                        &i.Policy1Timelock,
×
3124
                        &i.Policy1FeePpm,
×
3125
                        &i.Policy1BaseFeeMsat,
×
3126
                        &i.Policy1MinHtlcMsat,
×
3127
                        &i.Policy1MaxHtlcMsat,
×
3128
                        &i.Policy1Disabled,
×
3129
                        &i.Policy1InboundBaseFeeMsat,
×
3130
                        &i.Policy1InboundFeeRateMilliMsat,
×
3131
                        &i.Policy1MessageFlags,
×
3132
                        &i.Policy1ChannelFlags,
×
3133
                        &i.Policy2Timelock,
×
3134
                        &i.Policy2FeePpm,
×
3135
                        &i.Policy2BaseFeeMsat,
×
3136
                        &i.Policy2MinHtlcMsat,
×
3137
                        &i.Policy2MaxHtlcMsat,
×
3138
                        &i.Policy2Disabled,
×
3139
                        &i.Policy2InboundBaseFeeMsat,
×
3140
                        &i.Policy2InboundFeeRateMilliMsat,
×
3141
                        &i.Policy2MessageFlags,
×
3142
                        &i.Policy2ChannelFlags,
×
3143
                ); err != nil {
×
3144
                        return nil, err
×
3145
                }
×
3146
                items = append(items, i)
×
3147
        }
3148
        if err := rows.Close(); err != nil {
×
3149
                return nil, err
×
3150
        }
×
3151
        if err := rows.Err(); err != nil {
×
3152
                return nil, err
×
3153
        }
×
3154
        return items, nil
×
3155
}
3156

3157
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
3158
SELECT
3159
    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,
3160

3161
    -- Join node pubkeys
3162
    n1.pub_key AS node1_pubkey,
3163
    n2.pub_key AS node2_pubkey,
3164

3165
    -- Node 1 policy
3166
    cp1.id AS policy_1_id,
3167
    cp1.node_id AS policy_1_node_id,
3168
    cp1.version AS policy_1_version,
3169
    cp1.timelock AS policy_1_timelock,
3170
    cp1.fee_ppm AS policy_1_fee_ppm,
3171
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3172
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3173
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3174
    cp1.last_update AS policy_1_last_update,
3175
    cp1.disabled AS policy_1_disabled,
3176
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3177
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3178
    cp1.message_flags AS policy1_message_flags,
3179
    cp1.channel_flags AS policy1_channel_flags,
3180
    cp1.signature AS policy_1_signature,
3181

3182
    -- Node 2 policy
3183
    cp2.id AS policy_2_id,
3184
    cp2.node_id AS policy_2_node_id,
3185
    cp2.version AS policy_2_version,
3186
    cp2.timelock AS policy_2_timelock,
3187
    cp2.fee_ppm AS policy_2_fee_ppm,
3188
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3189
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3190
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3191
    cp2.last_update AS policy_2_last_update,
3192
    cp2.disabled AS policy_2_disabled,
3193
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3194
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3195
    cp2.message_flags AS policy2_message_flags,
3196
    cp2.channel_flags AS policy2_channel_flags,
3197
    cp2.signature AS policy_2_signature
3198

3199
FROM graph_channels c
3200
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3201
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3202
LEFT JOIN graph_channel_policies cp1
3203
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3204
LEFT JOIN graph_channel_policies cp2
3205
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3206
WHERE c.version = $1 AND c.id > $2
3207
ORDER BY c.id
3208
LIMIT $3
3209
`
3210

3211
type ListChannelsWithPoliciesPaginatedParams struct {
3212
        Version int16
3213
        ID      int64
3214
        Limit   int32
3215
}
3216

3217
type ListChannelsWithPoliciesPaginatedRow struct {
3218
        GraphChannel                   GraphChannel
3219
        Node1Pubkey                    []byte
3220
        Node2Pubkey                    []byte
3221
        Policy1ID                      sql.NullInt64
3222
        Policy1NodeID                  sql.NullInt64
3223
        Policy1Version                 sql.NullInt16
3224
        Policy1Timelock                sql.NullInt32
3225
        Policy1FeePpm                  sql.NullInt64
3226
        Policy1BaseFeeMsat             sql.NullInt64
3227
        Policy1MinHtlcMsat             sql.NullInt64
3228
        Policy1MaxHtlcMsat             sql.NullInt64
3229
        Policy1LastUpdate              sql.NullInt64
3230
        Policy1Disabled                sql.NullBool
3231
        Policy1InboundBaseFeeMsat      sql.NullInt64
3232
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3233
        Policy1MessageFlags            sql.NullInt16
3234
        Policy1ChannelFlags            sql.NullInt16
3235
        Policy1Signature               []byte
3236
        Policy2ID                      sql.NullInt64
3237
        Policy2NodeID                  sql.NullInt64
3238
        Policy2Version                 sql.NullInt16
3239
        Policy2Timelock                sql.NullInt32
3240
        Policy2FeePpm                  sql.NullInt64
3241
        Policy2BaseFeeMsat             sql.NullInt64
3242
        Policy2MinHtlcMsat             sql.NullInt64
3243
        Policy2MaxHtlcMsat             sql.NullInt64
3244
        Policy2LastUpdate              sql.NullInt64
3245
        Policy2Disabled                sql.NullBool
3246
        Policy2InboundBaseFeeMsat      sql.NullInt64
3247
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3248
        Policy2MessageFlags            sql.NullInt16
3249
        Policy2ChannelFlags            sql.NullInt16
3250
        Policy2Signature               []byte
3251
}
3252

3253
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
3254
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
3255
        if err != nil {
×
3256
                return nil, err
×
3257
        }
×
3258
        defer rows.Close()
×
3259
        var items []ListChannelsWithPoliciesPaginatedRow
×
3260
        for rows.Next() {
×
3261
                var i ListChannelsWithPoliciesPaginatedRow
×
3262
                if err := rows.Scan(
×
3263
                        &i.GraphChannel.ID,
×
3264
                        &i.GraphChannel.Version,
×
3265
                        &i.GraphChannel.Scid,
×
3266
                        &i.GraphChannel.NodeID1,
×
3267
                        &i.GraphChannel.NodeID2,
×
3268
                        &i.GraphChannel.Outpoint,
×
3269
                        &i.GraphChannel.Capacity,
×
3270
                        &i.GraphChannel.BitcoinKey1,
×
3271
                        &i.GraphChannel.BitcoinKey2,
×
3272
                        &i.GraphChannel.Node1Signature,
×
3273
                        &i.GraphChannel.Node2Signature,
×
3274
                        &i.GraphChannel.Bitcoin1Signature,
×
3275
                        &i.GraphChannel.Bitcoin2Signature,
×
3276
                        &i.Node1Pubkey,
×
3277
                        &i.Node2Pubkey,
×
3278
                        &i.Policy1ID,
×
3279
                        &i.Policy1NodeID,
×
3280
                        &i.Policy1Version,
×
3281
                        &i.Policy1Timelock,
×
3282
                        &i.Policy1FeePpm,
×
3283
                        &i.Policy1BaseFeeMsat,
×
3284
                        &i.Policy1MinHtlcMsat,
×
3285
                        &i.Policy1MaxHtlcMsat,
×
3286
                        &i.Policy1LastUpdate,
×
3287
                        &i.Policy1Disabled,
×
3288
                        &i.Policy1InboundBaseFeeMsat,
×
3289
                        &i.Policy1InboundFeeRateMilliMsat,
×
3290
                        &i.Policy1MessageFlags,
×
3291
                        &i.Policy1ChannelFlags,
×
3292
                        &i.Policy1Signature,
×
3293
                        &i.Policy2ID,
×
3294
                        &i.Policy2NodeID,
×
3295
                        &i.Policy2Version,
×
3296
                        &i.Policy2Timelock,
×
3297
                        &i.Policy2FeePpm,
×
3298
                        &i.Policy2BaseFeeMsat,
×
3299
                        &i.Policy2MinHtlcMsat,
×
3300
                        &i.Policy2MaxHtlcMsat,
×
3301
                        &i.Policy2LastUpdate,
×
3302
                        &i.Policy2Disabled,
×
3303
                        &i.Policy2InboundBaseFeeMsat,
×
3304
                        &i.Policy2InboundFeeRateMilliMsat,
×
3305
                        &i.Policy2MessageFlags,
×
3306
                        &i.Policy2ChannelFlags,
×
3307
                        &i.Policy2Signature,
×
3308
                ); err != nil {
×
3309
                        return nil, err
×
3310
                }
×
3311
                items = append(items, i)
×
3312
        }
3313
        if err := rows.Close(); err != nil {
×
3314
                return nil, err
×
3315
        }
×
3316
        if err := rows.Err(); err != nil {
×
3317
                return nil, err
×
3318
        }
×
3319
        return items, nil
×
3320
}
3321

3322
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
3323
SELECT id, pub_key
3324
FROM graph_nodes
3325
WHERE version = $1  AND id > $2
3326
ORDER BY id
3327
LIMIT $3
3328
`
3329

3330
type ListNodeIDsAndPubKeysParams struct {
3331
        Version int16
3332
        ID      int64
3333
        Limit   int32
3334
}
3335

3336
type ListNodeIDsAndPubKeysRow struct {
3337
        ID     int64
3338
        PubKey []byte
3339
}
3340

3341
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
3342
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
3343
        if err != nil {
×
3344
                return nil, err
×
3345
        }
×
3346
        defer rows.Close()
×
3347
        var items []ListNodeIDsAndPubKeysRow
×
3348
        for rows.Next() {
×
3349
                var i ListNodeIDsAndPubKeysRow
×
3350
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
3351
                        return nil, err
×
3352
                }
×
3353
                items = append(items, i)
×
3354
        }
3355
        if err := rows.Close(); err != nil {
×
3356
                return nil, err
×
3357
        }
×
3358
        if err := rows.Err(); err != nil {
×
3359
                return nil, err
×
3360
        }
×
3361
        return items, nil
×
3362
}
3363

3364
const listNodesPaginated = `-- name: ListNodesPaginated :many
3365
SELECT id, version, pub_key, alias, last_update, color, signature
3366
FROM graph_nodes
3367
WHERE version = $1 AND id > $2
3368
ORDER BY id
3369
LIMIT $3
3370
`
3371

3372
type ListNodesPaginatedParams struct {
3373
        Version int16
3374
        ID      int64
3375
        Limit   int32
3376
}
3377

3378
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
3379
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
3380
        if err != nil {
×
3381
                return nil, err
×
3382
        }
×
3383
        defer rows.Close()
×
3384
        var items []GraphNode
×
3385
        for rows.Next() {
×
3386
                var i GraphNode
×
3387
                if err := rows.Scan(
×
3388
                        &i.ID,
×
3389
                        &i.Version,
×
3390
                        &i.PubKey,
×
3391
                        &i.Alias,
×
3392
                        &i.LastUpdate,
×
3393
                        &i.Color,
×
3394
                        &i.Signature,
×
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 upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
3410
/* ─────────────────────────────────────────────
3411
   graph_channel_policy_extra_types table queries
3412
   ─────────────────────────────────────────────
3413
*/
3414

3415
INSERT INTO graph_channel_policy_extra_types (
3416
    channel_policy_id, type, value
3417
)
3418
VALUES ($1, $2, $3)
3419
ON CONFLICT (channel_policy_id, type)
3420
    -- If a conflict occurs on channel_policy_id and type, then we update the
3421
    -- value.
3422
    DO UPDATE SET value = EXCLUDED.value
3423
`
3424

3425
type UpsertChanPolicyExtraTypeParams struct {
3426
        ChannelPolicyID int64
3427
        Type            int64
3428
        Value           []byte
3429
}
3430

NEW
3431
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
NEW
3432
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
NEW
3433
        return err
×
NEW
3434
}
×
3435

3436
const upsertChannelExtraType = `-- name: UpsertChannelExtraType :exec
3437
/* ─────────────────────────────────────────────
3438
   graph_channel_extra_types table queries
3439
   ─────────────────────────────────────────────
3440
*/
3441

3442
INSERT INTO graph_channel_extra_types (
3443
    channel_id, type, value
3444
)
3445
VALUES ($1, $2, $3)
3446
    ON CONFLICT (channel_id, type)
3447
    -- Update the value if a conflict occurs on channel_id and type.
3448
    DO UPDATE SET value = EXCLUDED.value
3449
`
3450

3451
type UpsertChannelExtraTypeParams struct {
3452
        ChannelID int64
3453
        Type      int64
3454
        Value     []byte
3455
}
3456

NEW
3457
func (q *Queries) UpsertChannelExtraType(ctx context.Context, arg UpsertChannelExtraTypeParams) error {
×
NEW
3458
        _, err := q.db.ExecContext(ctx, upsertChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
NEW
3459
        return err
×
NEW
3460
}
×
3461

3462
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
3463
/* ─────────────────────────────────────────────
3464
   graph_channel_policies table queries
3465
   ─────────────────────────────────────────────
3466
*/
3467

3468
INSERT INTO graph_channel_policies (
3469
    version, channel_id, node_id, timelock, fee_ppm,
3470
    base_fee_msat, min_htlc_msat, last_update, disabled,
3471
    max_htlc_msat, inbound_base_fee_msat,
3472
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
3473
    signature
3474
) VALUES  (
3475
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
3476
)
3477
ON CONFLICT (channel_id, node_id, version)
3478
    -- Update the following fields if a conflict occurs on channel_id,
3479
    -- node_id, and version.
3480
    DO UPDATE SET
3481
        timelock = EXCLUDED.timelock,
3482
        fee_ppm = EXCLUDED.fee_ppm,
3483
        base_fee_msat = EXCLUDED.base_fee_msat,
3484
        min_htlc_msat = EXCLUDED.min_htlc_msat,
3485
        last_update = EXCLUDED.last_update,
3486
        disabled = EXCLUDED.disabled,
3487
        max_htlc_msat = EXCLUDED.max_htlc_msat,
3488
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
3489
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
3490
        message_flags = EXCLUDED.message_flags,
3491
        channel_flags = EXCLUDED.channel_flags,
3492
        signature = EXCLUDED.signature
3493
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
3494
RETURNING id
3495
`
3496

3497
type UpsertEdgePolicyParams struct {
3498
        Version                 int16
3499
        ChannelID               int64
3500
        NodeID                  int64
3501
        Timelock                int32
3502
        FeePpm                  int64
3503
        BaseFeeMsat             int64
3504
        MinHtlcMsat             int64
3505
        LastUpdate              sql.NullInt64
3506
        Disabled                sql.NullBool
3507
        MaxHtlcMsat             sql.NullInt64
3508
        InboundBaseFeeMsat      sql.NullInt64
3509
        InboundFeeRateMilliMsat sql.NullInt64
3510
        MessageFlags            sql.NullInt16
3511
        ChannelFlags            sql.NullInt16
3512
        Signature               []byte
3513
}
3514

3515
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
3516
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
3517
                arg.Version,
×
3518
                arg.ChannelID,
×
3519
                arg.NodeID,
×
3520
                arg.Timelock,
×
3521
                arg.FeePpm,
×
3522
                arg.BaseFeeMsat,
×
3523
                arg.MinHtlcMsat,
×
3524
                arg.LastUpdate,
×
3525
                arg.Disabled,
×
3526
                arg.MaxHtlcMsat,
×
3527
                arg.InboundBaseFeeMsat,
×
3528
                arg.InboundFeeRateMilliMsat,
×
3529
                arg.MessageFlags,
×
3530
                arg.ChannelFlags,
×
3531
                arg.Signature,
×
3532
        )
×
3533
        var id int64
×
3534
        err := row.Scan(&id)
×
3535
        return id, err
×
3536
}
×
3537

3538
const upsertNode = `-- name: UpsertNode :one
3539
/* ─────────────────────────────────────────────
3540
   graph_nodes table queries
3541
   ───────────────────────────��─────────────────
3542
*/
3543

3544
INSERT INTO graph_nodes (
3545
    version, pub_key, alias, last_update, color, signature
3546
) VALUES (
3547
    $1, $2, $3, $4, $5, $6
3548
)
3549
ON CONFLICT (pub_key, version)
3550
    -- Update the following fields if a conflict occurs on pub_key
3551
    -- and version.
3552
    DO UPDATE SET
3553
        alias = EXCLUDED.alias,
3554
        last_update = EXCLUDED.last_update,
3555
        color = EXCLUDED.color,
3556
        signature = EXCLUDED.signature
3557
WHERE graph_nodes.last_update IS NULL
3558
    OR EXCLUDED.last_update > graph_nodes.last_update
3559
RETURNING id
3560
`
3561

3562
type UpsertNodeParams struct {
3563
        Version    int16
3564
        PubKey     []byte
3565
        Alias      sql.NullString
3566
        LastUpdate sql.NullInt64
3567
        Color      sql.NullString
3568
        Signature  []byte
3569
}
3570

3571
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
3572
        row := q.db.QueryRowContext(ctx, upsertNode,
×
3573
                arg.Version,
×
3574
                arg.PubKey,
×
3575
                arg.Alias,
×
3576
                arg.LastUpdate,
×
3577
                arg.Color,
×
3578
                arg.Signature,
×
3579
        )
×
3580
        var id int64
×
3581
        err := row.Scan(&id)
×
3582
        return id, err
×
3583
}
×
3584

3585
const upsertNodeAddress = `-- name: UpsertNodeAddress :exec
3586
/* ─────────────────────────────────────────────
3587
   graph_node_addresses table queries
3588
   ───────────────────────────────────��─────────
3589
*/
3590

3591
INSERT INTO graph_node_addresses (
3592
    node_id,
3593
    type,
3594
    address,
3595
    position
3596
) VALUES (
3597
    $1, $2, $3, $4
3598
) ON CONFLICT (node_id, type, position)
3599
    DO UPDATE SET address = EXCLUDED.address
3600
`
3601

3602
type UpsertNodeAddressParams struct {
3603
        NodeID   int64
3604
        Type     int16
3605
        Address  string
3606
        Position int32
3607
}
3608

NEW
3609
func (q *Queries) UpsertNodeAddress(ctx context.Context, arg UpsertNodeAddressParams) error {
×
NEW
3610
        _, err := q.db.ExecContext(ctx, upsertNodeAddress,
×
NEW
3611
                arg.NodeID,
×
NEW
3612
                arg.Type,
×
NEW
3613
                arg.Address,
×
NEW
3614
                arg.Position,
×
NEW
3615
        )
×
NEW
3616
        return err
×
NEW
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