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

lightningnetwork / lnd / 17994533969

25 Sep 2025 01:52AM UTC coverage: 66.626% (-0.03%) from 66.651%
17994533969

Pull #10128

github

web-flow
Merge 2b459bef3 into df46d1862
Pull Request #10128: multi: update ChanUpdatesInHorizon and NodeUpdatesInHorizon to return iterators (iter.Seq[T])

308 of 622 new or added lines in 7 files covered. (49.52%)

75 existing lines in 15 files now uncovered.

136757 of 205262 relevant lines covered (66.63%)

21384.62 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
  -- Pagination using compound cursor (max_update_time, id).
1147
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
1148
  AND (
1149
       (CASE
1150
           WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1151
               THEN COALESCE(cp1.last_update, 0)
1152
           ELSE COALESCE(cp2.last_update, 0)
1153
       END > COALESCE($4, -1))
1154
       OR 
1155
       (CASE
1156
           WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1157
               THEN COALESCE(cp1.last_update, 0)
1158
           ELSE COALESCE(cp2.last_update, 0)
1159
       END = COALESCE($4, -1) 
1160
       AND c.id > COALESCE($5, -1))
1161
  )
1162
ORDER BY
1163
    CASE
1164
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
1165
            THEN COALESCE(cp1.last_update, 0)
1166
        ELSE COALESCE(cp2.last_update, 0)
1167
    END ASC,
1168
    c.id ASC
1169
LIMIT COALESCE($6, 999999999)
1170
`
1171

1172
type GetChannelsByPolicyLastUpdateRangeParams struct {
1173
        Version        int16
1174
        StartTime      sql.NullInt64
1175
        EndTime        sql.NullInt64
1176
        LastUpdateTime sql.NullInt64
1177
        LastID         sql.NullInt64
1178
        MaxResults     interface{}
1179
}
1180

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

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

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

1316
type GetChannelsBySCIDRangeParams struct {
1317
        StartScid []byte
1318
        EndScid   []byte
1319
}
1320

1321
type GetChannelsBySCIDRangeRow struct {
1322
        GraphChannel GraphChannel
1323
        Node1PubKey  []byte
1324
        Node2PubKey  []byte
1325
}
1326

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

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

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

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

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

1418
type GetChannelsBySCIDWithPoliciesParams struct {
1419
        Version int16
1420
        Scids   [][]byte
1421
}
1422

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

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

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

1557
type GetChannelsBySCIDsParams struct {
1558
        Version int16
1559
        Scids   [][]byte
1560
}
1561

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

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

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

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

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

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

1685
type GetNodeAddressesRow struct {
1686
        Type    int16
1687
        Address string
1688
}
1689

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

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

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

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

1765
type GetNodeByPubKeyParams struct {
1766
        PubKey  []byte
1767
        Version int16
1768
}
1769

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

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

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

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

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

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

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

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

1902
type GetNodeFeaturesByPubKeyParams struct {
1903
        PubKey  []byte
1904
        Version int16
1905
}
1906

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

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

1937
type GetNodeIDByPubKeyParams struct {
1938
        PubKey  []byte
1939
        Version int16
1940
}
1941

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

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

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

1996
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1997
SELECT id, version, pub_key, alias, last_update, color, signature
1998
FROM graph_nodes
1999
WHERE last_update >= $1
2000
  AND last_update <= $2
2001
  -- Pagination: We use (last_update, pub_key) as a compound cursor.
2002
  -- This ensures stable ordering and allows us to resume from where we left off.
2003
  -- We use COALESCE with -1 as sentinel since timestamps are always positive.
2004
  AND (
2005
    -- Include rows with last_update greater than cursor (or all rows if cursor is -1)
2006
    last_update > COALESCE($3, -1)
2007
    OR 
2008
    -- For rows with same last_update, use pub_key as tiebreaker
2009
    (last_update = COALESCE($3, -1) 
2010
     AND pub_key > $4)
2011
  )
2012
  -- Optional filter for public nodes only
2013
  AND (
2014
    -- If only_public is false or not provided, include all nodes
2015
    COALESCE($5, FALSE) IS FALSE
2016
    OR 
2017
    -- For V1 protocol, a node is public if it has at least one public channel.
2018
    -- A public channel has bitcoin_1_signature set (channel announcement received).
2019
    EXISTS (
2020
      SELECT 1
2021
      FROM graph_channels c
2022
      WHERE c.version = 1
2023
        AND c.bitcoin_1_signature IS NOT NULL
2024
        AND (c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id)
2025
    )
2026
  )
2027
ORDER BY last_update ASC, pub_key ASC
2028
LIMIT COALESCE($6, 999999999)
2029
`
2030

2031
type GetNodesByLastUpdateRangeParams struct {
2032
        StartTime  sql.NullInt64
2033
        EndTime    sql.NullInt64
2034
        LastUpdate sql.NullInt64
2035
        LastPubKey []byte
2036
        OnlyPublic interface{}
2037
        MaxResults interface{}
2038
}
2039

2040
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error) {
×
NEW
2041
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange,
×
NEW
2042
                arg.StartTime,
×
NEW
2043
                arg.EndTime,
×
NEW
2044
                arg.LastUpdate,
×
NEW
2045
                arg.LastPubKey,
×
NEW
2046
                arg.OnlyPublic,
×
NEW
2047
                arg.MaxResults,
×
NEW
2048
        )
×
2049
        if err != nil {
×
2050
                return nil, err
×
2051
        }
×
2052
        defer rows.Close()
×
2053
        var items []GraphNode
×
2054
        for rows.Next() {
×
2055
                var i GraphNode
×
2056
                if err := rows.Scan(
×
2057
                        &i.ID,
×
2058
                        &i.Version,
×
2059
                        &i.PubKey,
×
2060
                        &i.Alias,
×
2061
                        &i.LastUpdate,
×
2062
                        &i.Color,
×
2063
                        &i.Signature,
×
2064
                ); err != nil {
×
2065
                        return nil, err
×
2066
                }
×
2067
                items = append(items, i)
×
2068
        }
2069
        if err := rows.Close(); err != nil {
×
2070
                return nil, err
×
2071
        }
×
2072
        if err := rows.Err(); err != nil {
×
2073
                return nil, err
×
2074
        }
×
2075
        return items, nil
×
2076
}
2077

2078
const getPruneEntriesForHeights = `-- name: GetPruneEntriesForHeights :many
2079
SELECT block_height, block_hash
2080
FROM graph_prune_log
2081
WHERE block_height
2082
   IN (/*SLICE:heights*/?)
2083
`
2084

2085
func (q *Queries) GetPruneEntriesForHeights(ctx context.Context, heights []int64) ([]GraphPruneLog, error) {
×
2086
        query := getPruneEntriesForHeights
×
2087
        var queryParams []interface{}
×
2088
        if len(heights) > 0 {
×
2089
                for _, v := range heights {
×
2090
                        queryParams = append(queryParams, v)
×
2091
                }
×
2092
                query = strings.Replace(query, "/*SLICE:heights*/?", makeQueryParams(len(queryParams), len(heights)), 1)
×
2093
        } else {
×
2094
                query = strings.Replace(query, "/*SLICE:heights*/?", "NULL", 1)
×
2095
        }
×
2096
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2097
        if err != nil {
×
2098
                return nil, err
×
2099
        }
×
2100
        defer rows.Close()
×
2101
        var items []GraphPruneLog
×
2102
        for rows.Next() {
×
2103
                var i GraphPruneLog
×
2104
                if err := rows.Scan(&i.BlockHeight, &i.BlockHash); err != nil {
×
2105
                        return nil, err
×
2106
                }
×
2107
                items = append(items, i)
×
2108
        }
2109
        if err := rows.Close(); err != nil {
×
2110
                return nil, err
×
2111
        }
×
2112
        if err := rows.Err(); err != nil {
×
2113
                return nil, err
×
2114
        }
×
2115
        return items, nil
×
2116
}
2117

2118
const getPruneHashByHeight = `-- name: GetPruneHashByHeight :one
2119
SELECT block_hash
2120
FROM graph_prune_log
2121
WHERE block_height = $1
2122
`
2123

2124
func (q *Queries) GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error) {
×
2125
        row := q.db.QueryRowContext(ctx, getPruneHashByHeight, blockHeight)
×
2126
        var block_hash []byte
×
2127
        err := row.Scan(&block_hash)
×
2128
        return block_hash, err
×
2129
}
×
2130

2131
const getPruneTip = `-- name: GetPruneTip :one
2132
SELECT block_height, block_hash
2133
FROM graph_prune_log
2134
ORDER BY block_height DESC
2135
LIMIT 1
2136
`
2137

2138
func (q *Queries) GetPruneTip(ctx context.Context) (GraphPruneLog, error) {
×
2139
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
2140
        var i GraphPruneLog
×
2141
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
2142
        return i, err
×
2143
}
×
2144

2145
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
2146
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
2147
FROM graph_channels
2148
WHERE node_1_signature IS NOT NULL
2149
  AND scid >= $1
2150
  AND scid < $2
2151
`
2152

2153
type GetPublicV1ChannelsBySCIDParams struct {
2154
        StartScid []byte
2155
        EndScid   []byte
2156
}
2157

2158
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error) {
×
2159
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
2160
        if err != nil {
×
2161
                return nil, err
×
2162
        }
×
2163
        defer rows.Close()
×
2164
        var items []GraphChannel
×
2165
        for rows.Next() {
×
2166
                var i GraphChannel
×
2167
                if err := rows.Scan(
×
2168
                        &i.ID,
×
2169
                        &i.Version,
×
2170
                        &i.Scid,
×
2171
                        &i.NodeID1,
×
2172
                        &i.NodeID2,
×
2173
                        &i.Outpoint,
×
2174
                        &i.Capacity,
×
2175
                        &i.BitcoinKey1,
×
2176
                        &i.BitcoinKey2,
×
2177
                        &i.Node1Signature,
×
2178
                        &i.Node2Signature,
×
2179
                        &i.Bitcoin1Signature,
×
2180
                        &i.Bitcoin2Signature,
×
2181
                ); err != nil {
×
2182
                        return nil, err
×
2183
                }
×
2184
                items = append(items, i)
×
2185
        }
2186
        if err := rows.Close(); err != nil {
×
2187
                return nil, err
×
2188
        }
×
2189
        if err := rows.Err(); err != nil {
×
2190
                return nil, err
×
2191
        }
×
2192
        return items, nil
×
2193
}
2194

2195
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
2196
SELECT scid from graph_channels
2197
WHERE outpoint = $1 AND version = $2
2198
`
2199

2200
type GetSCIDByOutpointParams struct {
2201
        Outpoint string
2202
        Version  int16
2203
}
2204

2205
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
2206
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
2207
        var scid []byte
×
2208
        err := row.Scan(&scid)
×
2209
        return scid, err
×
2210
}
×
2211

2212
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
2213
SELECT sn.node_id, n.pub_key
2214
FROM graph_source_nodes sn
2215
    JOIN graph_nodes n ON sn.node_id = n.id
2216
WHERE n.version = $1
2217
`
2218

2219
type GetSourceNodesByVersionRow struct {
2220
        NodeID int64
2221
        PubKey []byte
2222
}
2223

2224
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
2225
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
2226
        if err != nil {
×
2227
                return nil, err
×
2228
        }
×
2229
        defer rows.Close()
×
2230
        var items []GetSourceNodesByVersionRow
×
2231
        for rows.Next() {
×
2232
                var i GetSourceNodesByVersionRow
×
2233
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
2234
                        return nil, err
×
2235
                }
×
2236
                items = append(items, i)
×
2237
        }
2238
        if err := rows.Close(); err != nil {
×
2239
                return nil, err
×
2240
        }
×
2241
        if err := rows.Err(); err != nil {
×
2242
                return nil, err
×
2243
        }
×
2244
        return items, nil
×
2245
}
2246

2247
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
2248
SELECT c.scid
2249
FROM graph_channels c
2250
    JOIN graph_channel_policies cp ON cp.channel_id = c.id
2251
WHERE cp.disabled = true
2252
AND c.version = 1
2253
GROUP BY c.scid
2254
HAVING COUNT(*) > 1
2255
`
2256

2257
// NOTE: this is V1 specific since for V1, disabled is a
2258
// simple, single boolean. The proposed V2 policy
2259
// structure will have a more complex disabled bit vector
2260
// and so the query for V2 may differ.
2261
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
2262
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
2263
        if err != nil {
×
2264
                return nil, err
×
2265
        }
×
2266
        defer rows.Close()
×
2267
        var items [][]byte
×
2268
        for rows.Next() {
×
2269
                var scid []byte
×
2270
                if err := rows.Scan(&scid); err != nil {
×
2271
                        return nil, err
×
2272
                }
×
2273
                items = append(items, scid)
×
2274
        }
2275
        if err := rows.Close(); err != nil {
×
2276
                return nil, err
×
2277
        }
×
2278
        if err := rows.Err(); err != nil {
×
2279
                return nil, err
×
2280
        }
×
2281
        return items, nil
×
2282
}
2283

2284
const getZombieChannel = `-- name: GetZombieChannel :one
2285
SELECT scid, version, node_key_1, node_key_2
2286
FROM graph_zombie_channels
2287
WHERE scid = $1
2288
AND version = $2
2289
`
2290

2291
type GetZombieChannelParams struct {
2292
        Scid    []byte
2293
        Version int16
2294
}
2295

2296
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error) {
×
2297
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
2298
        var i GraphZombieChannel
×
2299
        err := row.Scan(
×
2300
                &i.Scid,
×
2301
                &i.Version,
×
2302
                &i.NodeKey1,
×
2303
                &i.NodeKey2,
×
2304
        )
×
2305
        return i, err
×
2306
}
×
2307

2308
const getZombieChannelsSCIDs = `-- name: GetZombieChannelsSCIDs :many
2309
SELECT scid, version, node_key_1, node_key_2
2310
FROM graph_zombie_channels
2311
WHERE version = $1
2312
  AND scid IN (/*SLICE:scids*/?)
2313
`
2314

2315
type GetZombieChannelsSCIDsParams struct {
2316
        Version int16
2317
        Scids   [][]byte
2318
}
2319

2320
func (q *Queries) GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error) {
×
2321
        query := getZombieChannelsSCIDs
×
2322
        var queryParams []interface{}
×
2323
        queryParams = append(queryParams, arg.Version)
×
2324
        if len(arg.Scids) > 0 {
×
2325
                for _, v := range arg.Scids {
×
2326
                        queryParams = append(queryParams, v)
×
2327
                }
×
2328
                query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
×
2329
        } else {
×
2330
                query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
×
2331
        }
×
2332
        rows, err := q.db.QueryContext(ctx, query, queryParams...)
×
2333
        if err != nil {
×
2334
                return nil, err
×
2335
        }
×
2336
        defer rows.Close()
×
2337
        var items []GraphZombieChannel
×
2338
        for rows.Next() {
×
2339
                var i GraphZombieChannel
×
2340
                if err := rows.Scan(
×
2341
                        &i.Scid,
×
2342
                        &i.Version,
×
2343
                        &i.NodeKey1,
×
2344
                        &i.NodeKey2,
×
2345
                ); err != nil {
×
2346
                        return nil, err
×
2347
                }
×
2348
                items = append(items, i)
×
2349
        }
2350
        if err := rows.Close(); err != nil {
×
2351
                return nil, err
×
2352
        }
×
2353
        if err := rows.Err(); err != nil {
×
2354
                return nil, err
×
2355
        }
×
2356
        return items, nil
×
2357
}
2358

2359
const highestSCID = `-- name: HighestSCID :one
2360
SELECT scid
2361
FROM graph_channels
2362
WHERE version = $1
2363
ORDER BY scid DESC
2364
LIMIT 1
2365
`
2366

2367
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
2368
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
2369
        var scid []byte
×
2370
        err := row.Scan(&scid)
×
2371
        return scid, err
×
2372
}
×
2373

2374
const insertChannelFeature = `-- name: InsertChannelFeature :exec
2375
/* ─────────────────────────────────────────────
2376
   graph_channel_features table queries
2377
   ─────────────────────────────────────────────
2378
*/
2379

2380
INSERT INTO graph_channel_features (
2381
    channel_id, feature_bit
2382
) VALUES (
2383
    $1, $2
2384
) ON CONFLICT (channel_id, feature_bit)
2385
    -- Do nothing if the channel_id and feature_bit already exist.
2386
    DO NOTHING
2387
`
2388

2389
type InsertChannelFeatureParams struct {
2390
        ChannelID  int64
2391
        FeatureBit int32
2392
}
2393

2394
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
2395
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
2396
        return err
×
2397
}
×
2398

2399
const insertChannelMig = `-- name: InsertChannelMig :one
2400
INSERT INTO graph_channels (
2401
    version, scid, node_id_1, node_id_2,
2402
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
2403
    node_1_signature, node_2_signature, bitcoin_1_signature,
2404
    bitcoin_2_signature
2405
) VALUES (
2406
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
2407
) ON CONFLICT (scid, version)
2408
    -- If a conflict occurs, we have already migrated this channel. However, we
2409
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2410
    -- otherwise, the "RETURNING id" part does not work.
2411
    DO UPDATE SET
2412
        node_id_1 = EXCLUDED.node_id_1,
2413
        node_id_2 = EXCLUDED.node_id_2,
2414
        outpoint = EXCLUDED.outpoint,
2415
        capacity = EXCLUDED.capacity,
2416
        bitcoin_key_1 = EXCLUDED.bitcoin_key_1,
2417
        bitcoin_key_2 = EXCLUDED.bitcoin_key_2,
2418
        node_1_signature = EXCLUDED.node_1_signature,
2419
        node_2_signature = EXCLUDED.node_2_signature,
2420
        bitcoin_1_signature = EXCLUDED.bitcoin_1_signature,
2421
        bitcoin_2_signature = EXCLUDED.bitcoin_2_signature
2422
RETURNING id
2423
`
2424

2425
type InsertChannelMigParams struct {
2426
        Version           int16
2427
        Scid              []byte
2428
        NodeID1           int64
2429
        NodeID2           int64
2430
        Outpoint          string
2431
        Capacity          sql.NullInt64
2432
        BitcoinKey1       []byte
2433
        BitcoinKey2       []byte
2434
        Node1Signature    []byte
2435
        Node2Signature    []byte
2436
        Bitcoin1Signature []byte
2437
        Bitcoin2Signature []byte
2438
}
2439

2440
// NOTE: This query is only meant to be used by the graph SQL migration since
2441
// for that migration, in order to be retry-safe, we don't want to error out if
2442
// we re-insert the same channel again (which would error if the normal
2443
// CreateChannel query is used because of the uniqueness constraint on the scid
2444
// and version columns).
2445
func (q *Queries) InsertChannelMig(ctx context.Context, arg InsertChannelMigParams) (int64, error) {
×
2446
        row := q.db.QueryRowContext(ctx, insertChannelMig,
×
2447
                arg.Version,
×
2448
                arg.Scid,
×
2449
                arg.NodeID1,
×
2450
                arg.NodeID2,
×
2451
                arg.Outpoint,
×
2452
                arg.Capacity,
×
2453
                arg.BitcoinKey1,
×
2454
                arg.BitcoinKey2,
×
2455
                arg.Node1Signature,
×
2456
                arg.Node2Signature,
×
2457
                arg.Bitcoin1Signature,
×
2458
                arg.Bitcoin2Signature,
×
2459
        )
×
2460
        var id int64
×
2461
        err := row.Scan(&id)
×
2462
        return id, err
×
2463
}
×
2464

2465
const insertClosedChannel = `-- name: InsertClosedChannel :exec
2466
/* ─────────────────────────────────────────────
2467
   graph_closed_scid table queries
2468
   ────────────────────────────────────────────-
2469
*/
2470

2471
INSERT INTO graph_closed_scids (scid)
2472
VALUES ($1)
2473
ON CONFLICT (scid) DO NOTHING
2474
`
2475

2476
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
2477
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
2478
        return err
×
2479
}
×
2480

2481
const insertEdgePolicyMig = `-- name: InsertEdgePolicyMig :one
2482
INSERT INTO graph_channel_policies (
2483
    version, channel_id, node_id, timelock, fee_ppm,
2484
    base_fee_msat, min_htlc_msat, last_update, disabled,
2485
    max_htlc_msat, inbound_base_fee_msat,
2486
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2487
    signature
2488
) VALUES  (
2489
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2490
)
2491
ON CONFLICT (channel_id, node_id, version)
2492
    -- If a conflict occurs, we have already migrated this policy. However, we
2493
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2494
    -- otherwise, the "RETURNING id" part does not work.
2495
    DO UPDATE SET
2496
        timelock = EXCLUDED.timelock,
2497
        fee_ppm = EXCLUDED.fee_ppm,
2498
        base_fee_msat = EXCLUDED.base_fee_msat,
2499
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2500
        last_update = EXCLUDED.last_update,
2501
        disabled = EXCLUDED.disabled,
2502
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2503
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2504
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2505
        message_flags = EXCLUDED.message_flags,
2506
        channel_flags = EXCLUDED.channel_flags,
2507
        signature = EXCLUDED.signature
2508
RETURNING id
2509
`
2510

2511
type InsertEdgePolicyMigParams struct {
2512
        Version                 int16
2513
        ChannelID               int64
2514
        NodeID                  int64
2515
        Timelock                int32
2516
        FeePpm                  int64
2517
        BaseFeeMsat             int64
2518
        MinHtlcMsat             int64
2519
        LastUpdate              sql.NullInt64
2520
        Disabled                sql.NullBool
2521
        MaxHtlcMsat             sql.NullInt64
2522
        InboundBaseFeeMsat      sql.NullInt64
2523
        InboundFeeRateMilliMsat sql.NullInt64
2524
        MessageFlags            sql.NullInt16
2525
        ChannelFlags            sql.NullInt16
2526
        Signature               []byte
2527
}
2528

2529
// NOTE: This query is only meant to be used by the graph SQL migration since
2530
// for that migration, in order to be retry-safe, we don't want to error out if
2531
// we re-insert the same policy (which would error if the normal
2532
// UpsertEdgePolicy query is used because of the constraint in that query that
2533
// requires a policy update to have a newer last_update than the existing one).
2534
func (q *Queries) InsertEdgePolicyMig(ctx context.Context, arg InsertEdgePolicyMigParams) (int64, error) {
×
2535
        row := q.db.QueryRowContext(ctx, insertEdgePolicyMig,
×
2536
                arg.Version,
×
2537
                arg.ChannelID,
×
2538
                arg.NodeID,
×
2539
                arg.Timelock,
×
2540
                arg.FeePpm,
×
2541
                arg.BaseFeeMsat,
×
2542
                arg.MinHtlcMsat,
×
2543
                arg.LastUpdate,
×
2544
                arg.Disabled,
×
2545
                arg.MaxHtlcMsat,
×
2546
                arg.InboundBaseFeeMsat,
×
2547
                arg.InboundFeeRateMilliMsat,
×
2548
                arg.MessageFlags,
×
2549
                arg.ChannelFlags,
×
2550
                arg.Signature,
×
2551
        )
×
2552
        var id int64
×
2553
        err := row.Scan(&id)
×
2554
        return id, err
×
2555
}
×
2556

2557
const insertNodeFeature = `-- name: InsertNodeFeature :exec
2558
/* ─────────────────────────────────────────────
2559
   graph_node_features table queries
2560
   ─────────────────────────────────────────────
2561
*/
2562

2563
INSERT INTO graph_node_features (
2564
    node_id, feature_bit
2565
) VALUES (
2566
    $1, $2
2567
) ON CONFLICT (node_id, feature_bit)
2568
    -- Do nothing if the feature already exists for the node.
2569
    DO NOTHING
2570
`
2571

2572
type InsertNodeFeatureParams struct {
2573
        NodeID     int64
2574
        FeatureBit int32
2575
}
2576

2577
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
2578
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
2579
        return err
×
2580
}
×
2581

2582
const insertNodeMig = `-- name: InsertNodeMig :one
2583
/* ─────────────────────────────────────────────
2584
   Migration specific queries
2585

2586
   NOTE: once sqldbv2 is in place, these queries can be contained to a package
2587
   dedicated to the migration that requires it, and so we can then remove
2588
   it from the main set of "live" queries that the code-base has access to.
2589
   ────────────────────────────────────────────-
2590
*/
2591

2592
INSERT INTO graph_nodes (
2593
    version, pub_key, alias, last_update, color, signature
2594
) VALUES (
2595
    $1, $2, $3, $4, $5, $6
2596
)
2597
ON CONFLICT (pub_key, version)
2598
    -- If a conflict occurs, we have already migrated this node. However, we
2599
    -- still need to do an "UPDATE SET" here instead of "DO NOTHING" because
2600
    -- otherwise, the "RETURNING id" part does not work.
2601
    DO UPDATE SET
2602
        alias = EXCLUDED.alias,
2603
        last_update = EXCLUDED.last_update,
2604
        color = EXCLUDED.color,
2605
        signature = EXCLUDED.signature
2606
RETURNING id
2607
`
2608

2609
type InsertNodeMigParams struct {
2610
        Version    int16
2611
        PubKey     []byte
2612
        Alias      sql.NullString
2613
        LastUpdate sql.NullInt64
2614
        Color      sql.NullString
2615
        Signature  []byte
2616
}
2617

2618
// NOTE: This query is only meant to be used by the graph SQL migration since
2619
// for that migration, in order to be retry-safe, we don't want to error out if
2620
// we re-insert the same node (which would error if the normal UpsertNode query
2621
// is used because of the constraint in that query that requires a node update
2622
// to have a newer last_update than the existing node).
2623
func (q *Queries) InsertNodeMig(ctx context.Context, arg InsertNodeMigParams) (int64, error) {
×
2624
        row := q.db.QueryRowContext(ctx, insertNodeMig,
×
2625
                arg.Version,
×
2626
                arg.PubKey,
×
2627
                arg.Alias,
×
2628
                arg.LastUpdate,
×
2629
                arg.Color,
×
2630
                arg.Signature,
×
2631
        )
×
2632
        var id int64
×
2633
        err := row.Scan(&id)
×
2634
        return id, err
×
2635
}
×
2636

2637
const isClosedChannel = `-- name: IsClosedChannel :one
2638
SELECT EXISTS (
2639
    SELECT 1
2640
    FROM graph_closed_scids
2641
    WHERE scid = $1
2642
)
2643
`
2644

2645
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
2646
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
2647
        var exists bool
×
2648
        err := row.Scan(&exists)
×
2649
        return exists, err
×
2650
}
×
2651

2652
const isPublicV1Node = `-- name: IsPublicV1Node :one
2653
SELECT EXISTS (
2654
    SELECT 1
2655
    FROM graph_channels c
2656
    JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
2657
    -- NOTE: we hard-code the version here since the clauses
2658
    -- here that determine if a node is public is specific
2659
    -- to the V1 gossip protocol. In V1, a node is public
2660
    -- if it has a public channel and a public channel is one
2661
    -- where we have the set of signatures of the channel
2662
    -- announcement. It is enough to just check that we have
2663
    -- one of the signatures since we only ever set them
2664
    -- together.
2665
    WHERE c.version = 1
2666
      AND c.bitcoin_1_signature IS NOT NULL
2667
      AND n.pub_key = $1
2668
)
2669
`
2670

2671
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
2672
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
2673
        var exists bool
×
2674
        err := row.Scan(&exists)
×
2675
        return exists, err
×
2676
}
×
2677

2678
const isZombieChannel = `-- name: IsZombieChannel :one
2679
SELECT EXISTS (
2680
    SELECT 1
2681
    FROM graph_zombie_channels
2682
    WHERE scid = $1
2683
    AND version = $2
2684
) AS is_zombie
2685
`
2686

2687
type IsZombieChannelParams struct {
2688
        Scid    []byte
2689
        Version int16
2690
}
2691

2692
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
2693
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
2694
        var is_zombie bool
×
2695
        err := row.Scan(&is_zombie)
×
2696
        return is_zombie, err
×
2697
}
×
2698

2699
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
2700
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,
2701
    n1.pub_key AS node1_pubkey,
2702
    n2.pub_key AS node2_pubkey,
2703

2704
    -- Policy 1
2705
    -- TODO(elle): use sqlc.embed to embed policy structs
2706
    --  once this issue is resolved:
2707
    --  https://github.com/sqlc-dev/sqlc/issues/2997
2708
    cp1.id AS policy1_id,
2709
    cp1.node_id AS policy1_node_id,
2710
    cp1.version AS policy1_version,
2711
    cp1.timelock AS policy1_timelock,
2712
    cp1.fee_ppm AS policy1_fee_ppm,
2713
    cp1.base_fee_msat AS policy1_base_fee_msat,
2714
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
2715
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
2716
    cp1.last_update AS policy1_last_update,
2717
    cp1.disabled AS policy1_disabled,
2718
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2719
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2720
    cp1.message_flags AS policy1_message_flags,
2721
    cp1.channel_flags AS policy1_channel_flags,
2722
    cp1.signature AS policy1_signature,
2723

2724
       -- Policy 2
2725
    cp2.id AS policy2_id,
2726
    cp2.node_id AS policy2_node_id,
2727
    cp2.version AS policy2_version,
2728
    cp2.timelock AS policy2_timelock,
2729
    cp2.fee_ppm AS policy2_fee_ppm,
2730
    cp2.base_fee_msat AS policy2_base_fee_msat,
2731
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
2732
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
2733
    cp2.last_update AS policy2_last_update,
2734
    cp2.disabled AS policy2_disabled,
2735
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2736
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2737
    cp2.message_flags AS policy2_message_flags,
2738
    cp2.channel_flags AS policy2_channel_flags,
2739
    cp2.signature AS policy2_signature
2740

2741
FROM graph_channels c
2742
    JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2743
    JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2744
    LEFT JOIN graph_channel_policies cp1
2745
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2746
    LEFT JOIN graph_channel_policies cp2
2747
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2748
WHERE c.version = $1
2749
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
2750
`
2751

2752
type ListChannelsByNodeIDParams struct {
2753
        Version int16
2754
        NodeID1 int64
2755
}
2756

2757
type ListChannelsByNodeIDRow struct {
2758
        GraphChannel                   GraphChannel
2759
        Node1Pubkey                    []byte
2760
        Node2Pubkey                    []byte
2761
        Policy1ID                      sql.NullInt64
2762
        Policy1NodeID                  sql.NullInt64
2763
        Policy1Version                 sql.NullInt16
2764
        Policy1Timelock                sql.NullInt32
2765
        Policy1FeePpm                  sql.NullInt64
2766
        Policy1BaseFeeMsat             sql.NullInt64
2767
        Policy1MinHtlcMsat             sql.NullInt64
2768
        Policy1MaxHtlcMsat             sql.NullInt64
2769
        Policy1LastUpdate              sql.NullInt64
2770
        Policy1Disabled                sql.NullBool
2771
        Policy1InboundBaseFeeMsat      sql.NullInt64
2772
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2773
        Policy1MessageFlags            sql.NullInt16
2774
        Policy1ChannelFlags            sql.NullInt16
2775
        Policy1Signature               []byte
2776
        Policy2ID                      sql.NullInt64
2777
        Policy2NodeID                  sql.NullInt64
2778
        Policy2Version                 sql.NullInt16
2779
        Policy2Timelock                sql.NullInt32
2780
        Policy2FeePpm                  sql.NullInt64
2781
        Policy2BaseFeeMsat             sql.NullInt64
2782
        Policy2MinHtlcMsat             sql.NullInt64
2783
        Policy2MaxHtlcMsat             sql.NullInt64
2784
        Policy2LastUpdate              sql.NullInt64
2785
        Policy2Disabled                sql.NullBool
2786
        Policy2InboundBaseFeeMsat      sql.NullInt64
2787
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2788
        Policy2MessageFlags            sql.NullInt16
2789
        Policy2ChannelFlags            sql.NullInt16
2790
        Policy2Signature               []byte
2791
}
2792

2793
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
2794
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
2795
        if err != nil {
×
2796
                return nil, err
×
2797
        }
×
2798
        defer rows.Close()
×
2799
        var items []ListChannelsByNodeIDRow
×
2800
        for rows.Next() {
×
2801
                var i ListChannelsByNodeIDRow
×
2802
                if err := rows.Scan(
×
2803
                        &i.GraphChannel.ID,
×
2804
                        &i.GraphChannel.Version,
×
2805
                        &i.GraphChannel.Scid,
×
2806
                        &i.GraphChannel.NodeID1,
×
2807
                        &i.GraphChannel.NodeID2,
×
2808
                        &i.GraphChannel.Outpoint,
×
2809
                        &i.GraphChannel.Capacity,
×
2810
                        &i.GraphChannel.BitcoinKey1,
×
2811
                        &i.GraphChannel.BitcoinKey2,
×
2812
                        &i.GraphChannel.Node1Signature,
×
2813
                        &i.GraphChannel.Node2Signature,
×
2814
                        &i.GraphChannel.Bitcoin1Signature,
×
2815
                        &i.GraphChannel.Bitcoin2Signature,
×
2816
                        &i.Node1Pubkey,
×
2817
                        &i.Node2Pubkey,
×
2818
                        &i.Policy1ID,
×
2819
                        &i.Policy1NodeID,
×
2820
                        &i.Policy1Version,
×
2821
                        &i.Policy1Timelock,
×
2822
                        &i.Policy1FeePpm,
×
2823
                        &i.Policy1BaseFeeMsat,
×
2824
                        &i.Policy1MinHtlcMsat,
×
2825
                        &i.Policy1MaxHtlcMsat,
×
2826
                        &i.Policy1LastUpdate,
×
2827
                        &i.Policy1Disabled,
×
2828
                        &i.Policy1InboundBaseFeeMsat,
×
2829
                        &i.Policy1InboundFeeRateMilliMsat,
×
2830
                        &i.Policy1MessageFlags,
×
2831
                        &i.Policy1ChannelFlags,
×
2832
                        &i.Policy1Signature,
×
2833
                        &i.Policy2ID,
×
2834
                        &i.Policy2NodeID,
×
2835
                        &i.Policy2Version,
×
2836
                        &i.Policy2Timelock,
×
2837
                        &i.Policy2FeePpm,
×
2838
                        &i.Policy2BaseFeeMsat,
×
2839
                        &i.Policy2MinHtlcMsat,
×
2840
                        &i.Policy2MaxHtlcMsat,
×
2841
                        &i.Policy2LastUpdate,
×
2842
                        &i.Policy2Disabled,
×
2843
                        &i.Policy2InboundBaseFeeMsat,
×
2844
                        &i.Policy2InboundFeeRateMilliMsat,
×
2845
                        &i.Policy2MessageFlags,
×
2846
                        &i.Policy2ChannelFlags,
×
2847
                        &i.Policy2Signature,
×
2848
                ); err != nil {
×
2849
                        return nil, err
×
2850
                }
×
2851
                items = append(items, i)
×
2852
        }
2853
        if err := rows.Close(); err != nil {
×
2854
                return nil, err
×
2855
        }
×
2856
        if err := rows.Err(); err != nil {
×
2857
                return nil, err
×
2858
        }
×
2859
        return items, nil
×
2860
}
2861

2862
const listChannelsForNodeIDs = `-- name: ListChannelsForNodeIDs :many
2863
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,
2864
       n1.pub_key AS node1_pubkey,
2865
       n2.pub_key AS node2_pubkey,
2866

2867
       -- Policy 1
2868
       -- TODO(elle): use sqlc.embed to embed policy structs
2869
       --  once this issue is resolved:
2870
       --  https://github.com/sqlc-dev/sqlc/issues/2997
2871
       cp1.id AS policy1_id,
2872
       cp1.node_id AS policy1_node_id,
2873
       cp1.version AS policy1_version,
2874
       cp1.timelock AS policy1_timelock,
2875
       cp1.fee_ppm AS policy1_fee_ppm,
2876
       cp1.base_fee_msat AS policy1_base_fee_msat,
2877
       cp1.min_htlc_msat AS policy1_min_htlc_msat,
2878
       cp1.max_htlc_msat AS policy1_max_htlc_msat,
2879
       cp1.last_update AS policy1_last_update,
2880
       cp1.disabled AS policy1_disabled,
2881
       cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
2882
       cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
2883
       cp1.message_flags AS policy1_message_flags,
2884
       cp1.channel_flags AS policy1_channel_flags,
2885
       cp1.signature AS policy1_signature,
2886

2887
       -- Policy 2
2888
       cp2.id AS policy2_id,
2889
       cp2.node_id AS policy2_node_id,
2890
       cp2.version AS policy2_version,
2891
       cp2.timelock AS policy2_timelock,
2892
       cp2.fee_ppm AS policy2_fee_ppm,
2893
       cp2.base_fee_msat AS policy2_base_fee_msat,
2894
       cp2.min_htlc_msat AS policy2_min_htlc_msat,
2895
       cp2.max_htlc_msat AS policy2_max_htlc_msat,
2896
       cp2.last_update AS policy2_last_update,
2897
       cp2.disabled AS policy2_disabled,
2898
       cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
2899
       cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
2900
       cp2.message_flags AS policy2_message_flags,
2901
       cp2.channel_flags AS policy2_channel_flags,
2902
       cp2.signature AS policy2_signature
2903

2904
FROM graph_channels c
2905
         JOIN graph_nodes n1 ON c.node_id_1 = n1.id
2906
         JOIN graph_nodes n2 ON c.node_id_2 = n2.id
2907
         LEFT JOIN graph_channel_policies cp1
2908
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
2909
         LEFT JOIN graph_channel_policies cp2
2910
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
2911
WHERE c.version = $1
2912
  AND (c.node_id_1 IN (/*SLICE:node1_ids*/?)
2913
   OR c.node_id_2 IN (/*SLICE:node2_ids*/?))
2914
`
2915

2916
type ListChannelsForNodeIDsParams struct {
2917
        Version  int16
2918
        Node1Ids []int64
2919
        Node2Ids []int64
2920
}
2921

2922
type ListChannelsForNodeIDsRow struct {
2923
        GraphChannel                   GraphChannel
2924
        Node1Pubkey                    []byte
2925
        Node2Pubkey                    []byte
2926
        Policy1ID                      sql.NullInt64
2927
        Policy1NodeID                  sql.NullInt64
2928
        Policy1Version                 sql.NullInt16
2929
        Policy1Timelock                sql.NullInt32
2930
        Policy1FeePpm                  sql.NullInt64
2931
        Policy1BaseFeeMsat             sql.NullInt64
2932
        Policy1MinHtlcMsat             sql.NullInt64
2933
        Policy1MaxHtlcMsat             sql.NullInt64
2934
        Policy1LastUpdate              sql.NullInt64
2935
        Policy1Disabled                sql.NullBool
2936
        Policy1InboundBaseFeeMsat      sql.NullInt64
2937
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2938
        Policy1MessageFlags            sql.NullInt16
2939
        Policy1ChannelFlags            sql.NullInt16
2940
        Policy1Signature               []byte
2941
        Policy2ID                      sql.NullInt64
2942
        Policy2NodeID                  sql.NullInt64
2943
        Policy2Version                 sql.NullInt16
2944
        Policy2Timelock                sql.NullInt32
2945
        Policy2FeePpm                  sql.NullInt64
2946
        Policy2BaseFeeMsat             sql.NullInt64
2947
        Policy2MinHtlcMsat             sql.NullInt64
2948
        Policy2MaxHtlcMsat             sql.NullInt64
2949
        Policy2LastUpdate              sql.NullInt64
2950
        Policy2Disabled                sql.NullBool
2951
        Policy2InboundBaseFeeMsat      sql.NullInt64
2952
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2953
        Policy2MessageFlags            sql.NullInt16
2954
        Policy2ChannelFlags            sql.NullInt16
2955
        Policy2Signature               []byte
2956
}
2957

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

3046
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
3047
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
3048
FROM graph_channels c
3049
WHERE c.version = $1 AND c.id > $2
3050
ORDER BY c.id
3051
LIMIT $3
3052
`
3053

3054
type ListChannelsPaginatedParams struct {
3055
        Version int16
3056
        ID      int64
3057
        Limit   int32
3058
}
3059

3060
type ListChannelsPaginatedRow struct {
3061
        ID          int64
3062
        BitcoinKey1 []byte
3063
        BitcoinKey2 []byte
3064
        Outpoint    string
3065
}
3066

3067
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
3068
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
3069
        if err != nil {
×
3070
                return nil, err
×
3071
        }
×
3072
        defer rows.Close()
×
3073
        var items []ListChannelsPaginatedRow
×
3074
        for rows.Next() {
×
3075
                var i ListChannelsPaginatedRow
×
3076
                if err := rows.Scan(
×
3077
                        &i.ID,
×
3078
                        &i.BitcoinKey1,
×
3079
                        &i.BitcoinKey2,
×
3080
                        &i.Outpoint,
×
3081
                ); err != nil {
×
3082
                        return nil, err
×
3083
                }
×
3084
                items = append(items, i)
×
3085
        }
3086
        if err := rows.Close(); err != nil {
×
3087
                return nil, err
×
3088
        }
×
3089
        if err := rows.Err(); err != nil {
×
3090
                return nil, err
×
3091
        }
×
3092
        return items, nil
×
3093
}
3094

3095
const listChannelsWithPoliciesForCachePaginated = `-- name: ListChannelsWithPoliciesForCachePaginated :many
3096
SELECT
3097
    c.id as id,
3098
    c.scid as scid,
3099
    c.capacity AS capacity,
3100

3101
    -- Join node pubkeys
3102
    n1.pub_key AS node1_pubkey,
3103
    n2.pub_key AS node2_pubkey,
3104

3105
    -- Node 1 policy
3106
    cp1.timelock AS policy_1_timelock,
3107
    cp1.fee_ppm AS policy_1_fee_ppm,
3108
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3109
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3110
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3111
    cp1.disabled AS policy_1_disabled,
3112
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3113
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3114
    cp1.message_flags AS policy1_message_flags,
3115
    cp1.channel_flags AS policy1_channel_flags,
3116

3117
    -- Node 2 policy
3118
    cp2.timelock AS policy_2_timelock,
3119
    cp2.fee_ppm AS policy_2_fee_ppm,
3120
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3121
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3122
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3123
    cp2.disabled AS policy_2_disabled,
3124
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3125
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3126
    cp2.message_flags AS policy2_message_flags,
3127
    cp2.channel_flags AS policy2_channel_flags
3128

3129
FROM graph_channels c
3130
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3131
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3132
LEFT JOIN graph_channel_policies cp1
3133
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3134
LEFT JOIN graph_channel_policies cp2
3135
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3136
WHERE c.version = $1 AND c.id > $2
3137
ORDER BY c.id
3138
LIMIT $3
3139
`
3140

3141
type ListChannelsWithPoliciesForCachePaginatedParams struct {
3142
        Version int16
3143
        ID      int64
3144
        Limit   int32
3145
}
3146

3147
type ListChannelsWithPoliciesForCachePaginatedRow struct {
3148
        ID                             int64
3149
        Scid                           []byte
3150
        Capacity                       sql.NullInt64
3151
        Node1Pubkey                    []byte
3152
        Node2Pubkey                    []byte
3153
        Policy1Timelock                sql.NullInt32
3154
        Policy1FeePpm                  sql.NullInt64
3155
        Policy1BaseFeeMsat             sql.NullInt64
3156
        Policy1MinHtlcMsat             sql.NullInt64
3157
        Policy1MaxHtlcMsat             sql.NullInt64
3158
        Policy1Disabled                sql.NullBool
3159
        Policy1InboundBaseFeeMsat      sql.NullInt64
3160
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3161
        Policy1MessageFlags            sql.NullInt16
3162
        Policy1ChannelFlags            sql.NullInt16
3163
        Policy2Timelock                sql.NullInt32
3164
        Policy2FeePpm                  sql.NullInt64
3165
        Policy2BaseFeeMsat             sql.NullInt64
3166
        Policy2MinHtlcMsat             sql.NullInt64
3167
        Policy2MaxHtlcMsat             sql.NullInt64
3168
        Policy2Disabled                sql.NullBool
3169
        Policy2InboundBaseFeeMsat      sql.NullInt64
3170
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3171
        Policy2MessageFlags            sql.NullInt16
3172
        Policy2ChannelFlags            sql.NullInt16
3173
}
3174

3175
func (q *Queries) ListChannelsWithPoliciesForCachePaginated(ctx context.Context, arg ListChannelsWithPoliciesForCachePaginatedParams) ([]ListChannelsWithPoliciesForCachePaginatedRow, error) {
×
3176
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesForCachePaginated, arg.Version, arg.ID, arg.Limit)
×
3177
        if err != nil {
×
3178
                return nil, err
×
3179
        }
×
3180
        defer rows.Close()
×
3181
        var items []ListChannelsWithPoliciesForCachePaginatedRow
×
3182
        for rows.Next() {
×
3183
                var i ListChannelsWithPoliciesForCachePaginatedRow
×
3184
                if err := rows.Scan(
×
3185
                        &i.ID,
×
3186
                        &i.Scid,
×
3187
                        &i.Capacity,
×
3188
                        &i.Node1Pubkey,
×
3189
                        &i.Node2Pubkey,
×
3190
                        &i.Policy1Timelock,
×
3191
                        &i.Policy1FeePpm,
×
3192
                        &i.Policy1BaseFeeMsat,
×
3193
                        &i.Policy1MinHtlcMsat,
×
3194
                        &i.Policy1MaxHtlcMsat,
×
3195
                        &i.Policy1Disabled,
×
3196
                        &i.Policy1InboundBaseFeeMsat,
×
3197
                        &i.Policy1InboundFeeRateMilliMsat,
×
3198
                        &i.Policy1MessageFlags,
×
3199
                        &i.Policy1ChannelFlags,
×
3200
                        &i.Policy2Timelock,
×
3201
                        &i.Policy2FeePpm,
×
3202
                        &i.Policy2BaseFeeMsat,
×
3203
                        &i.Policy2MinHtlcMsat,
×
3204
                        &i.Policy2MaxHtlcMsat,
×
3205
                        &i.Policy2Disabled,
×
3206
                        &i.Policy2InboundBaseFeeMsat,
×
3207
                        &i.Policy2InboundFeeRateMilliMsat,
×
3208
                        &i.Policy2MessageFlags,
×
3209
                        &i.Policy2ChannelFlags,
×
3210
                ); err != nil {
×
3211
                        return nil, err
×
3212
                }
×
3213
                items = append(items, i)
×
3214
        }
3215
        if err := rows.Close(); err != nil {
×
3216
                return nil, err
×
3217
        }
×
3218
        if err := rows.Err(); err != nil {
×
3219
                return nil, err
×
3220
        }
×
3221
        return items, nil
×
3222
}
3223

3224
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
3225
SELECT
3226
    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,
3227

3228
    -- Join node pubkeys
3229
    n1.pub_key AS node1_pubkey,
3230
    n2.pub_key AS node2_pubkey,
3231

3232
    -- Node 1 policy
3233
    cp1.id AS policy_1_id,
3234
    cp1.node_id AS policy_1_node_id,
3235
    cp1.version AS policy_1_version,
3236
    cp1.timelock AS policy_1_timelock,
3237
    cp1.fee_ppm AS policy_1_fee_ppm,
3238
    cp1.base_fee_msat AS policy_1_base_fee_msat,
3239
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
3240
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
3241
    cp1.last_update AS policy_1_last_update,
3242
    cp1.disabled AS policy_1_disabled,
3243
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
3244
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
3245
    cp1.message_flags AS policy1_message_flags,
3246
    cp1.channel_flags AS policy1_channel_flags,
3247
    cp1.signature AS policy_1_signature,
3248

3249
    -- Node 2 policy
3250
    cp2.id AS policy_2_id,
3251
    cp2.node_id AS policy_2_node_id,
3252
    cp2.version AS policy_2_version,
3253
    cp2.timelock AS policy_2_timelock,
3254
    cp2.fee_ppm AS policy_2_fee_ppm,
3255
    cp2.base_fee_msat AS policy_2_base_fee_msat,
3256
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
3257
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
3258
    cp2.last_update AS policy_2_last_update,
3259
    cp2.disabled AS policy_2_disabled,
3260
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
3261
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
3262
    cp2.message_flags AS policy2_message_flags,
3263
    cp2.channel_flags AS policy2_channel_flags,
3264
    cp2.signature AS policy_2_signature
3265

3266
FROM graph_channels c
3267
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
3268
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
3269
LEFT JOIN graph_channel_policies cp1
3270
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
3271
LEFT JOIN graph_channel_policies cp2
3272
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
3273
WHERE c.version = $1 AND c.id > $2
3274
ORDER BY c.id
3275
LIMIT $3
3276
`
3277

3278
type ListChannelsWithPoliciesPaginatedParams struct {
3279
        Version int16
3280
        ID      int64
3281
        Limit   int32
3282
}
3283

3284
type ListChannelsWithPoliciesPaginatedRow struct {
3285
        GraphChannel                   GraphChannel
3286
        Node1Pubkey                    []byte
3287
        Node2Pubkey                    []byte
3288
        Policy1ID                      sql.NullInt64
3289
        Policy1NodeID                  sql.NullInt64
3290
        Policy1Version                 sql.NullInt16
3291
        Policy1Timelock                sql.NullInt32
3292
        Policy1FeePpm                  sql.NullInt64
3293
        Policy1BaseFeeMsat             sql.NullInt64
3294
        Policy1MinHtlcMsat             sql.NullInt64
3295
        Policy1MaxHtlcMsat             sql.NullInt64
3296
        Policy1LastUpdate              sql.NullInt64
3297
        Policy1Disabled                sql.NullBool
3298
        Policy1InboundBaseFeeMsat      sql.NullInt64
3299
        Policy1InboundFeeRateMilliMsat sql.NullInt64
3300
        Policy1MessageFlags            sql.NullInt16
3301
        Policy1ChannelFlags            sql.NullInt16
3302
        Policy1Signature               []byte
3303
        Policy2ID                      sql.NullInt64
3304
        Policy2NodeID                  sql.NullInt64
3305
        Policy2Version                 sql.NullInt16
3306
        Policy2Timelock                sql.NullInt32
3307
        Policy2FeePpm                  sql.NullInt64
3308
        Policy2BaseFeeMsat             sql.NullInt64
3309
        Policy2MinHtlcMsat             sql.NullInt64
3310
        Policy2MaxHtlcMsat             sql.NullInt64
3311
        Policy2LastUpdate              sql.NullInt64
3312
        Policy2Disabled                sql.NullBool
3313
        Policy2InboundBaseFeeMsat      sql.NullInt64
3314
        Policy2InboundFeeRateMilliMsat sql.NullInt64
3315
        Policy2MessageFlags            sql.NullInt16
3316
        Policy2ChannelFlags            sql.NullInt16
3317
        Policy2Signature               []byte
3318
}
3319

3320
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
3321
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
3322
        if err != nil {
×
3323
                return nil, err
×
3324
        }
×
3325
        defer rows.Close()
×
3326
        var items []ListChannelsWithPoliciesPaginatedRow
×
3327
        for rows.Next() {
×
3328
                var i ListChannelsWithPoliciesPaginatedRow
×
3329
                if err := rows.Scan(
×
3330
                        &i.GraphChannel.ID,
×
3331
                        &i.GraphChannel.Version,
×
3332
                        &i.GraphChannel.Scid,
×
3333
                        &i.GraphChannel.NodeID1,
×
3334
                        &i.GraphChannel.NodeID2,
×
3335
                        &i.GraphChannel.Outpoint,
×
3336
                        &i.GraphChannel.Capacity,
×
3337
                        &i.GraphChannel.BitcoinKey1,
×
3338
                        &i.GraphChannel.BitcoinKey2,
×
3339
                        &i.GraphChannel.Node1Signature,
×
3340
                        &i.GraphChannel.Node2Signature,
×
3341
                        &i.GraphChannel.Bitcoin1Signature,
×
3342
                        &i.GraphChannel.Bitcoin2Signature,
×
3343
                        &i.Node1Pubkey,
×
3344
                        &i.Node2Pubkey,
×
3345
                        &i.Policy1ID,
×
3346
                        &i.Policy1NodeID,
×
3347
                        &i.Policy1Version,
×
3348
                        &i.Policy1Timelock,
×
3349
                        &i.Policy1FeePpm,
×
3350
                        &i.Policy1BaseFeeMsat,
×
3351
                        &i.Policy1MinHtlcMsat,
×
3352
                        &i.Policy1MaxHtlcMsat,
×
3353
                        &i.Policy1LastUpdate,
×
3354
                        &i.Policy1Disabled,
×
3355
                        &i.Policy1InboundBaseFeeMsat,
×
3356
                        &i.Policy1InboundFeeRateMilliMsat,
×
3357
                        &i.Policy1MessageFlags,
×
3358
                        &i.Policy1ChannelFlags,
×
3359
                        &i.Policy1Signature,
×
3360
                        &i.Policy2ID,
×
3361
                        &i.Policy2NodeID,
×
3362
                        &i.Policy2Version,
×
3363
                        &i.Policy2Timelock,
×
3364
                        &i.Policy2FeePpm,
×
3365
                        &i.Policy2BaseFeeMsat,
×
3366
                        &i.Policy2MinHtlcMsat,
×
3367
                        &i.Policy2MaxHtlcMsat,
×
3368
                        &i.Policy2LastUpdate,
×
3369
                        &i.Policy2Disabled,
×
3370
                        &i.Policy2InboundBaseFeeMsat,
×
3371
                        &i.Policy2InboundFeeRateMilliMsat,
×
3372
                        &i.Policy2MessageFlags,
×
3373
                        &i.Policy2ChannelFlags,
×
3374
                        &i.Policy2Signature,
×
3375
                ); err != nil {
×
3376
                        return nil, err
×
3377
                }
×
3378
                items = append(items, i)
×
3379
        }
3380
        if err := rows.Close(); err != nil {
×
3381
                return nil, err
×
3382
        }
×
3383
        if err := rows.Err(); err != nil {
×
3384
                return nil, err
×
3385
        }
×
3386
        return items, nil
×
3387
}
3388

3389
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
3390
SELECT id, pub_key
3391
FROM graph_nodes
3392
WHERE version = $1  AND id > $2
3393
ORDER BY id
3394
LIMIT $3
3395
`
3396

3397
type ListNodeIDsAndPubKeysParams struct {
3398
        Version int16
3399
        ID      int64
3400
        Limit   int32
3401
}
3402

3403
type ListNodeIDsAndPubKeysRow struct {
3404
        ID     int64
3405
        PubKey []byte
3406
}
3407

3408
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
3409
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
3410
        if err != nil {
×
3411
                return nil, err
×
3412
        }
×
3413
        defer rows.Close()
×
3414
        var items []ListNodeIDsAndPubKeysRow
×
3415
        for rows.Next() {
×
3416
                var i ListNodeIDsAndPubKeysRow
×
3417
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
3418
                        return nil, err
×
3419
                }
×
3420
                items = append(items, i)
×
3421
        }
3422
        if err := rows.Close(); err != nil {
×
3423
                return nil, err
×
3424
        }
×
3425
        if err := rows.Err(); err != nil {
×
3426
                return nil, err
×
3427
        }
×
3428
        return items, nil
×
3429
}
3430

3431
const listNodesPaginated = `-- name: ListNodesPaginated :many
3432
SELECT id, version, pub_key, alias, last_update, color, signature
3433
FROM graph_nodes
3434
WHERE version = $1 AND id > $2
3435
ORDER BY id
3436
LIMIT $3
3437
`
3438

3439
type ListNodesPaginatedParams struct {
3440
        Version int16
3441
        ID      int64
3442
        Limit   int32
3443
}
3444

3445
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error) {
×
3446
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
3447
        if err != nil {
×
3448
                return nil, err
×
3449
        }
×
3450
        defer rows.Close()
×
3451
        var items []GraphNode
×
3452
        for rows.Next() {
×
3453
                var i GraphNode
×
3454
                if err := rows.Scan(
×
3455
                        &i.ID,
×
3456
                        &i.Version,
×
3457
                        &i.PubKey,
×
3458
                        &i.Alias,
×
3459
                        &i.LastUpdate,
×
3460
                        &i.Color,
×
3461
                        &i.Signature,
×
3462
                ); err != nil {
×
3463
                        return nil, err
×
3464
                }
×
3465
                items = append(items, i)
×
3466
        }
3467
        if err := rows.Close(); err != nil {
×
3468
                return nil, err
×
3469
        }
×
3470
        if err := rows.Err(); err != nil {
×
3471
                return nil, err
×
3472
        }
×
3473
        return items, nil
×
3474
}
3475

3476
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
3477
/* ─────────────────────────────────────────────
3478
   graph_channel_policy_extra_types table queries
3479
   ─────────────────────────────────────────────
3480
*/
3481

3482
INSERT INTO graph_channel_policy_extra_types (
3483
    channel_policy_id, type, value
3484
)
3485
VALUES ($1, $2, $3)
3486
ON CONFLICT (channel_policy_id, type)
3487
    -- If a conflict occurs on channel_policy_id and type, then we update the
3488
    -- value.
3489
    DO UPDATE SET value = EXCLUDED.value
3490
`
3491

3492
type UpsertChanPolicyExtraTypeParams struct {
3493
        ChannelPolicyID int64
3494
        Type            int64
3495
        Value           []byte
3496
}
3497

3498
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
3499
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
3500
        return err
×
3501
}
×
3502

3503
const upsertChannelExtraType = `-- name: UpsertChannelExtraType :exec
3504
/* ─────────────────────────────────────────────
3505
   graph_channel_extra_types table queries
3506
   ─────────────────────────────────────────────
3507
*/
3508

3509
INSERT INTO graph_channel_extra_types (
3510
    channel_id, type, value
3511
)
3512
VALUES ($1, $2, $3)
3513
    ON CONFLICT (channel_id, type)
3514
    -- Update the value if a conflict occurs on channel_id and type.
3515
    DO UPDATE SET value = EXCLUDED.value
3516
`
3517

3518
type UpsertChannelExtraTypeParams struct {
3519
        ChannelID int64
3520
        Type      int64
3521
        Value     []byte
3522
}
3523

3524
func (q *Queries) UpsertChannelExtraType(ctx context.Context, arg UpsertChannelExtraTypeParams) error {
×
3525
        _, err := q.db.ExecContext(ctx, upsertChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
3526
        return err
×
3527
}
×
3528

3529
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
3530
/* ─────────────────────────────────────────────
3531
   graph_channel_policies table queries
3532
   ─────────────────────────────────────────────
3533
*/
3534

3535
INSERT INTO graph_channel_policies (
3536
    version, channel_id, node_id, timelock, fee_ppm,
3537
    base_fee_msat, min_htlc_msat, last_update, disabled,
3538
    max_htlc_msat, inbound_base_fee_msat,
3539
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
3540
    signature
3541
) VALUES  (
3542
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
3543
)
3544
ON CONFLICT (channel_id, node_id, version)
3545
    -- Update the following fields if a conflict occurs on channel_id,
3546
    -- node_id, and version.
3547
    DO UPDATE SET
3548
        timelock = EXCLUDED.timelock,
3549
        fee_ppm = EXCLUDED.fee_ppm,
3550
        base_fee_msat = EXCLUDED.base_fee_msat,
3551
        min_htlc_msat = EXCLUDED.min_htlc_msat,
3552
        last_update = EXCLUDED.last_update,
3553
        disabled = EXCLUDED.disabled,
3554
        max_htlc_msat = EXCLUDED.max_htlc_msat,
3555
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
3556
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
3557
        message_flags = EXCLUDED.message_flags,
3558
        channel_flags = EXCLUDED.channel_flags,
3559
        signature = EXCLUDED.signature
3560
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
3561
RETURNING id
3562
`
3563

3564
type UpsertEdgePolicyParams struct {
3565
        Version                 int16
3566
        ChannelID               int64
3567
        NodeID                  int64
3568
        Timelock                int32
3569
        FeePpm                  int64
3570
        BaseFeeMsat             int64
3571
        MinHtlcMsat             int64
3572
        LastUpdate              sql.NullInt64
3573
        Disabled                sql.NullBool
3574
        MaxHtlcMsat             sql.NullInt64
3575
        InboundBaseFeeMsat      sql.NullInt64
3576
        InboundFeeRateMilliMsat sql.NullInt64
3577
        MessageFlags            sql.NullInt16
3578
        ChannelFlags            sql.NullInt16
3579
        Signature               []byte
3580
}
3581

3582
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
3583
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
3584
                arg.Version,
×
3585
                arg.ChannelID,
×
3586
                arg.NodeID,
×
3587
                arg.Timelock,
×
3588
                arg.FeePpm,
×
3589
                arg.BaseFeeMsat,
×
3590
                arg.MinHtlcMsat,
×
3591
                arg.LastUpdate,
×
3592
                arg.Disabled,
×
3593
                arg.MaxHtlcMsat,
×
3594
                arg.InboundBaseFeeMsat,
×
3595
                arg.InboundFeeRateMilliMsat,
×
3596
                arg.MessageFlags,
×
3597
                arg.ChannelFlags,
×
3598
                arg.Signature,
×
3599
        )
×
3600
        var id int64
×
3601
        err := row.Scan(&id)
×
3602
        return id, err
×
3603
}
×
3604

3605
const upsertNode = `-- name: UpsertNode :one
3606
/* ─────────────────────────────────────────────
3607
   graph_nodes table queries
3608
   ───────────────────────────��─────────────────
3609
*/
3610

3611
INSERT INTO graph_nodes (
3612
    version, pub_key, alias, last_update, color, signature
3613
) VALUES (
3614
    $1, $2, $3, $4, $5, $6
3615
)
3616
ON CONFLICT (pub_key, version)
3617
    -- Update the following fields if a conflict occurs on pub_key
3618
    -- and version.
3619
    DO UPDATE SET
3620
        alias = EXCLUDED.alias,
3621
        last_update = EXCLUDED.last_update,
3622
        color = EXCLUDED.color,
3623
        signature = EXCLUDED.signature
3624
WHERE graph_nodes.last_update IS NULL
3625
    OR EXCLUDED.last_update > graph_nodes.last_update
3626
RETURNING id
3627
`
3628

3629
type UpsertNodeParams struct {
3630
        Version    int16
3631
        PubKey     []byte
3632
        Alias      sql.NullString
3633
        LastUpdate sql.NullInt64
3634
        Color      sql.NullString
3635
        Signature  []byte
3636
}
3637

3638
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
3639
        row := q.db.QueryRowContext(ctx, upsertNode,
×
3640
                arg.Version,
×
3641
                arg.PubKey,
×
3642
                arg.Alias,
×
3643
                arg.LastUpdate,
×
3644
                arg.Color,
×
3645
                arg.Signature,
×
3646
        )
×
3647
        var id int64
×
3648
        err := row.Scan(&id)
×
3649
        return id, err
×
3650
}
×
3651

3652
const upsertNodeAddress = `-- name: UpsertNodeAddress :exec
3653
/* ─────────────────────────────────────────────
3654
   graph_node_addresses table queries
3655
   ───────────────────────────────────��─────────
3656
*/
3657

3658
INSERT INTO graph_node_addresses (
3659
    node_id,
3660
    type,
3661
    address,
3662
    position
3663
) VALUES (
3664
    $1, $2, $3, $4
3665
) ON CONFLICT (node_id, type, position)
3666
    DO UPDATE SET address = EXCLUDED.address
3667
`
3668

3669
type UpsertNodeAddressParams struct {
3670
        NodeID   int64
3671
        Type     int16
3672
        Address  string
3673
        Position int32
3674
}
3675

3676
func (q *Queries) UpsertNodeAddress(ctx context.Context, arg UpsertNodeAddressParams) error {
×
3677
        _, err := q.db.ExecContext(ctx, upsertNodeAddress,
×
3678
                arg.NodeID,
×
3679
                arg.Type,
×
3680
                arg.Address,
×
3681
                arg.Position,
×
3682
        )
×
3683
        return err
×
3684
}
×
3685

3686
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
3687
/* ─────────────────────────────────────────────
3688
   graph_node_extra_types table queries
3689
   ─────────────────────────────────────────────
3690
*/
3691

3692
INSERT INTO graph_node_extra_types (
3693
    node_id, type, value
3694
)
3695
VALUES ($1, $2, $3)
3696
ON CONFLICT (type, node_id)
3697
    -- Update the value if a conflict occurs on type
3698
    -- and node_id.
3699
    DO UPDATE SET value = EXCLUDED.value
3700
`
3701

3702
type UpsertNodeExtraTypeParams struct {
3703
        NodeID int64
3704
        Type   int64
3705
        Value  []byte
3706
}
3707

3708
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
3709
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
3710
        return err
×
3711
}
×
3712

3713
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
3714
/* ───────────────────────────���─────────────────
3715
    graph_prune_log table queries
3716
    ─────────────────────────────────────────────
3717
*/
3718

3719
INSERT INTO graph_prune_log (
3720
    block_height, block_hash
3721
) VALUES (
3722
    $1, $2
3723
)
3724
ON CONFLICT(block_height) DO UPDATE SET
3725
    block_hash = EXCLUDED.block_hash
3726
`
3727

3728
type UpsertPruneLogEntryParams struct {
3729
        BlockHeight int64
3730
        BlockHash   []byte
3731
}
3732

3733
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
3734
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
3735
        return err
×
3736
}
×
3737

3738
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
3739
/* ─────────────────────────────────────────────
3740
   graph_zombie_channels table queries
3741
   ─────────────────────────────────────────────
3742
*/
3743

3744
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
3745
VALUES ($1, $2, $3, $4)
3746
ON CONFLICT (scid, version)
3747
DO UPDATE SET
3748
    -- If a conflict exists for the SCID and version pair, then we
3749
    -- update the node keys.
3750
    node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
3751
    node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2)
3752
`
3753

3754
type UpsertZombieChannelParams struct {
3755
        Scid     []byte
3756
        Version  int16
3757
        NodeKey1 []byte
3758
        NodeKey2 []byte
3759
}
3760

3761
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
3762
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
3763
                arg.Scid,
×
3764
                arg.Version,
×
3765
                arg.NodeKey1,
×
3766
                arg.NodeKey2,
×
3767
        )
×
3768
        return err
×
3769
}
×
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