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

lightningnetwork / lnd / 15997023090

01 Jul 2025 10:40AM UTC coverage: 55.469% (-2.3%) from 57.809%
15997023090

push

github

web-flow
Merge pull request #10010 from ellemouton/sqlGraphUpdates

graph/db: various misc updates

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

23617 existing lines in 280 files now uncovered.

108414 of 195451 relevant lines covered (55.47%)

22394.66 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
)
12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

145
const deleteChannel = `-- name: DeleteChannel :exec
146
DELETE FROM channels WHERE id = $1
147
`
148

149
func (q *Queries) DeleteChannel(ctx context.Context, id int64) error {
×
150
        _, err := q.db.ExecContext(ctx, deleteChannel, id)
×
151
        return err
×
152
}
×
153

154
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
155
DELETE FROM channel_policy_extra_types
156
WHERE channel_policy_id = $1
157
`
158

159
func (q *Queries) DeleteChannelPolicyExtraTypes(ctx context.Context, channelPolicyID int64) error {
×
160
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraTypes, channelPolicyID)
×
161
        return err
×
162
}
×
163

164
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
165
DELETE FROM node_extra_types
166
WHERE node_id = $1
167
  AND type = $2
168
`
169

170
type DeleteExtraNodeTypeParams struct {
171
        NodeID int64
172
        Type   int64
173
}
174

175
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
176
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
177
        return err
×
178
}
×
179

180
const deleteNode = `-- name: DeleteNode :exec
181
DELETE FROM nodes
182
WHERE id = $1
183
`
184

185
func (q *Queries) DeleteNode(ctx context.Context, id int64) error {
×
186
        _, err := q.db.ExecContext(ctx, deleteNode, id)
×
187
        return err
×
188
}
×
189

190
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
191
DELETE FROM node_addresses
192
WHERE node_id = $1
193
`
194

195
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
196
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
197
        return err
×
198
}
×
199

200
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
201
DELETE FROM nodes
202
WHERE pub_key = $1
203
  AND version = $2
204
`
205

206
type DeleteNodeByPubKeyParams struct {
207
        PubKey  []byte
208
        Version int16
209
}
210

211
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
212
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
213
}
×
214

215
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
216
DELETE FROM node_features
217
WHERE node_id = $1
218
  AND feature_bit = $2
219
`
220

221
type DeleteNodeFeatureParams struct {
222
        NodeID     int64
223
        FeatureBit int32
224
}
225

226
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
227
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
228
        return err
×
229
}
×
230

231
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
232
DELETE FROM prune_log
233
WHERE block_height >= $1
234
  AND block_height <= $2
235
`
236

237
type DeletePruneLogEntriesInRangeParams struct {
238
        StartHeight int64
239
        EndHeight   int64
240
}
241

242
func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error {
×
243
        _, err := q.db.ExecContext(ctx, deletePruneLogEntriesInRange, arg.StartHeight, arg.EndHeight)
×
244
        return err
×
245
}
×
246

247
const deleteUnconnectedNodes = `-- name: DeleteUnconnectedNodes :many
248
DELETE FROM nodes
249
WHERE
250
    -- Ignore any of our source nodes.
251
    NOT EXISTS (
252
        SELECT 1
253
        FROM source_nodes sn
254
        WHERE sn.node_id = nodes.id
255
    )
256
    -- Select all nodes that do not have any channels.
257
    AND NOT EXISTS (
258
        SELECT 1
259
        FROM channels c
260
        WHERE c.node_id_1 = nodes.id OR c.node_id_2 = nodes.id
261
) RETURNING pub_key
262
`
263

NEW
264
func (q *Queries) DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error) {
×
NEW
265
        rows, err := q.db.QueryContext(ctx, deleteUnconnectedNodes)
×
NEW
266
        if err != nil {
×
NEW
267
                return nil, err
×
NEW
268
        }
×
NEW
269
        defer rows.Close()
×
NEW
270
        var items [][]byte
×
NEW
271
        for rows.Next() {
×
NEW
272
                var pub_key []byte
×
NEW
273
                if err := rows.Scan(&pub_key); err != nil {
×
NEW
274
                        return nil, err
×
NEW
275
                }
×
NEW
276
                items = append(items, pub_key)
×
277
        }
NEW
278
        if err := rows.Close(); err != nil {
×
NEW
279
                return nil, err
×
NEW
280
        }
×
NEW
281
        if err := rows.Err(); err != nil {
×
NEW
282
                return nil, err
×
NEW
283
        }
×
NEW
284
        return items, nil
×
285
}
286

287
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
288
DELETE FROM zombie_channels
289
WHERE scid = $1
290
AND version = $2
291
`
292

293
type DeleteZombieChannelParams struct {
294
        Scid    []byte
295
        Version int16
296
}
297

298
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
299
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
300
}
×
301

302
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
303
SELECT
304
    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,
305
    n1.pub_key AS node1_pub_key,
306
    n2.pub_key AS node2_pub_key
307
FROM channels c
308
    JOIN nodes n1 ON c.node_id_1 = n1.id
309
    JOIN nodes n2 ON c.node_id_2 = n2.id
310
WHERE c.scid = $1
311
  AND c.version = $2
312
`
313

314
type GetChannelAndNodesBySCIDParams struct {
315
        Scid    []byte
316
        Version int16
317
}
318

319
type GetChannelAndNodesBySCIDRow struct {
320
        ID                int64
321
        Version           int16
322
        Scid              []byte
323
        NodeID1           int64
324
        NodeID2           int64
325
        Outpoint          string
326
        Capacity          sql.NullInt64
327
        BitcoinKey1       []byte
328
        BitcoinKey2       []byte
329
        Node1Signature    []byte
330
        Node2Signature    []byte
331
        Bitcoin1Signature []byte
332
        Bitcoin2Signature []byte
333
        Node1PubKey       []byte
334
        Node2PubKey       []byte
335
}
336

337
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
338
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
339
        var i GetChannelAndNodesBySCIDRow
×
340
        err := row.Scan(
×
341
                &i.ID,
×
342
                &i.Version,
×
343
                &i.Scid,
×
344
                &i.NodeID1,
×
345
                &i.NodeID2,
×
346
                &i.Outpoint,
×
347
                &i.Capacity,
×
348
                &i.BitcoinKey1,
×
349
                &i.BitcoinKey2,
×
350
                &i.Node1Signature,
×
351
                &i.Node2Signature,
×
352
                &i.Bitcoin1Signature,
×
353
                &i.Bitcoin2Signature,
×
354
                &i.Node1PubKey,
×
355
                &i.Node2PubKey,
×
356
        )
×
357
        return i, err
×
358
}
×
359

360
const getChannelByOutpoint = `-- name: GetChannelByOutpoint :one
361
SELECT
362
    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,
363
    n1.pub_key AS node1_pubkey,
364
    n2.pub_key AS node2_pubkey
365
FROM channels c
366
    JOIN nodes n1 ON c.node_id_1 = n1.id
367
    JOIN nodes n2 ON c.node_id_2 = n2.id
368
WHERE c.outpoint = $1
369
`
370

371
type GetChannelByOutpointRow struct {
372
        Channel     Channel
373
        Node1Pubkey []byte
374
        Node2Pubkey []byte
375
}
376

377
func (q *Queries) GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error) {
×
378
        row := q.db.QueryRowContext(ctx, getChannelByOutpoint, outpoint)
×
379
        var i GetChannelByOutpointRow
×
380
        err := row.Scan(
×
381
                &i.Channel.ID,
×
382
                &i.Channel.Version,
×
383
                &i.Channel.Scid,
×
384
                &i.Channel.NodeID1,
×
385
                &i.Channel.NodeID2,
×
386
                &i.Channel.Outpoint,
×
387
                &i.Channel.Capacity,
×
388
                &i.Channel.BitcoinKey1,
×
389
                &i.Channel.BitcoinKey2,
×
390
                &i.Channel.Node1Signature,
×
391
                &i.Channel.Node2Signature,
×
392
                &i.Channel.Bitcoin1Signature,
×
393
                &i.Channel.Bitcoin2Signature,
×
394
                &i.Node1Pubkey,
×
395
                &i.Node2Pubkey,
×
396
        )
×
397
        return i, err
×
398
}
×
399

400
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
401
SELECT
402
    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,
403

404
    n1.pub_key AS node1_pubkey,
405
    n2.pub_key AS node2_pubkey,
406

407
    -- Node 1 policy
408
    cp1.id AS policy_1_id,
409
    cp1.node_id AS policy_1_node_id,
410
    cp1.version AS policy_1_version,
411
    cp1.timelock AS policy_1_timelock,
412
    cp1.fee_ppm AS policy_1_fee_ppm,
413
    cp1.base_fee_msat AS policy_1_base_fee_msat,
414
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
415
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
416
    cp1.last_update AS policy_1_last_update,
417
    cp1.disabled AS policy_1_disabled,
418
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
419
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
420
    cp1.message_flags AS policy_1_message_flags,
421
    cp1.channel_flags AS policy_1_channel_flags,
422
    cp1.signature AS policy_1_signature,
423

424
    -- Node 2 policy
425
    cp2.id AS policy_2_id,
426
    cp2.node_id AS policy_2_node_id,
427
    cp2.version AS policy_2_version,
428
    cp2.timelock AS policy_2_timelock,
429
    cp2.fee_ppm AS policy_2_fee_ppm,
430
    cp2.base_fee_msat AS policy_2_base_fee_msat,
431
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
432
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
433
    cp2.last_update AS policy_2_last_update,
434
    cp2.disabled AS policy_2_disabled,
435
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
436
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
437
    cp2.message_flags AS policy_2_message_flags,
438
    cp2.channel_flags AS policy_2_channel_flags,
439
    cp2.signature AS policy_2_signature
440
FROM channels c
441
    JOIN nodes n1 ON c.node_id_1 = n1.id
442
    JOIN nodes n2 ON c.node_id_2 = n2.id
443
    LEFT JOIN channel_policies cp1
444
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
445
    LEFT JOIN channel_policies cp2
446
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
447
WHERE c.outpoint = $1 AND c.version = $2
448
`
449

450
type GetChannelByOutpointWithPoliciesParams struct {
451
        Outpoint string
452
        Version  int16
453
}
454

455
type GetChannelByOutpointWithPoliciesRow struct {
456
        Channel                        Channel
457
        Node1Pubkey                    []byte
458
        Node2Pubkey                    []byte
459
        Policy1ID                      sql.NullInt64
460
        Policy1NodeID                  sql.NullInt64
461
        Policy1Version                 sql.NullInt16
462
        Policy1Timelock                sql.NullInt32
463
        Policy1FeePpm                  sql.NullInt64
464
        Policy1BaseFeeMsat             sql.NullInt64
465
        Policy1MinHtlcMsat             sql.NullInt64
466
        Policy1MaxHtlcMsat             sql.NullInt64
467
        Policy1LastUpdate              sql.NullInt64
468
        Policy1Disabled                sql.NullBool
469
        Policy1InboundBaseFeeMsat      sql.NullInt64
470
        Policy1InboundFeeRateMilliMsat sql.NullInt64
471
        Policy1MessageFlags            sql.NullInt16
472
        Policy1ChannelFlags            sql.NullInt16
473
        Policy1Signature               []byte
474
        Policy2ID                      sql.NullInt64
475
        Policy2NodeID                  sql.NullInt64
476
        Policy2Version                 sql.NullInt16
477
        Policy2Timelock                sql.NullInt32
478
        Policy2FeePpm                  sql.NullInt64
479
        Policy2BaseFeeMsat             sql.NullInt64
480
        Policy2MinHtlcMsat             sql.NullInt64
481
        Policy2MaxHtlcMsat             sql.NullInt64
482
        Policy2LastUpdate              sql.NullInt64
483
        Policy2Disabled                sql.NullBool
484
        Policy2InboundBaseFeeMsat      sql.NullInt64
485
        Policy2InboundFeeRateMilliMsat sql.NullInt64
486
        Policy2MessageFlags            sql.NullInt16
487
        Policy2ChannelFlags            sql.NullInt16
488
        Policy2Signature               []byte
489
}
490

491
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
492
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
493
        var i GetChannelByOutpointWithPoliciesRow
×
494
        err := row.Scan(
×
495
                &i.Channel.ID,
×
496
                &i.Channel.Version,
×
497
                &i.Channel.Scid,
×
498
                &i.Channel.NodeID1,
×
499
                &i.Channel.NodeID2,
×
500
                &i.Channel.Outpoint,
×
501
                &i.Channel.Capacity,
×
502
                &i.Channel.BitcoinKey1,
×
503
                &i.Channel.BitcoinKey2,
×
504
                &i.Channel.Node1Signature,
×
505
                &i.Channel.Node2Signature,
×
506
                &i.Channel.Bitcoin1Signature,
×
507
                &i.Channel.Bitcoin2Signature,
×
508
                &i.Node1Pubkey,
×
509
                &i.Node2Pubkey,
×
510
                &i.Policy1ID,
×
511
                &i.Policy1NodeID,
×
512
                &i.Policy1Version,
×
513
                &i.Policy1Timelock,
×
514
                &i.Policy1FeePpm,
×
515
                &i.Policy1BaseFeeMsat,
×
516
                &i.Policy1MinHtlcMsat,
×
517
                &i.Policy1MaxHtlcMsat,
×
518
                &i.Policy1LastUpdate,
×
519
                &i.Policy1Disabled,
×
520
                &i.Policy1InboundBaseFeeMsat,
×
521
                &i.Policy1InboundFeeRateMilliMsat,
×
522
                &i.Policy1MessageFlags,
×
523
                &i.Policy1ChannelFlags,
×
524
                &i.Policy1Signature,
×
525
                &i.Policy2ID,
×
526
                &i.Policy2NodeID,
×
527
                &i.Policy2Version,
×
528
                &i.Policy2Timelock,
×
529
                &i.Policy2FeePpm,
×
530
                &i.Policy2BaseFeeMsat,
×
531
                &i.Policy2MinHtlcMsat,
×
532
                &i.Policy2MaxHtlcMsat,
×
533
                &i.Policy2LastUpdate,
×
534
                &i.Policy2Disabled,
×
535
                &i.Policy2InboundBaseFeeMsat,
×
536
                &i.Policy2InboundFeeRateMilliMsat,
×
537
                &i.Policy2MessageFlags,
×
538
                &i.Policy2ChannelFlags,
×
539
                &i.Policy2Signature,
×
540
        )
×
541
        return i, err
×
542
}
×
543

544
const getChannelBySCID = `-- name: GetChannelBySCID :one
545
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 channels
546
WHERE scid = $1 AND version = $2
547
`
548

549
type GetChannelBySCIDParams struct {
550
        Scid    []byte
551
        Version int16
552
}
553

554
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
555
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
556
        var i Channel
×
557
        err := row.Scan(
×
558
                &i.ID,
×
559
                &i.Version,
×
560
                &i.Scid,
×
561
                &i.NodeID1,
×
562
                &i.NodeID2,
×
563
                &i.Outpoint,
×
564
                &i.Capacity,
×
565
                &i.BitcoinKey1,
×
566
                &i.BitcoinKey2,
×
567
                &i.Node1Signature,
×
568
                &i.Node2Signature,
×
569
                &i.Bitcoin1Signature,
×
570
                &i.Bitcoin2Signature,
×
571
        )
×
572
        return i, err
×
573
}
×
574

575
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
576
SELECT
577
    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,
578
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
579
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
580

581
    -- Policy 1
582
    cp1.id AS policy1_id,
583
    cp1.node_id AS policy1_node_id,
584
    cp1.version AS policy1_version,
585
    cp1.timelock AS policy1_timelock,
586
    cp1.fee_ppm AS policy1_fee_ppm,
587
    cp1.base_fee_msat AS policy1_base_fee_msat,
588
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
589
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
590
    cp1.last_update AS policy1_last_update,
591
    cp1.disabled AS policy1_disabled,
592
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
593
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
594
    cp1.message_flags AS policy1_message_flags,
595
    cp1.channel_flags AS policy1_channel_flags,
596
    cp1.signature AS policy1_signature,
597

598
    -- Policy 2
599
    cp2.id AS policy2_id,
600
    cp2.node_id AS policy2_node_id,
601
    cp2.version AS policy2_version,
602
    cp2.timelock AS policy2_timelock,
603
    cp2.fee_ppm AS policy2_fee_ppm,
604
    cp2.base_fee_msat AS policy2_base_fee_msat,
605
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
606
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
607
    cp2.last_update AS policy2_last_update,
608
    cp2.disabled AS policy2_disabled,
609
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
610
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
611
    cp2.message_flags AS policy_2_message_flags,
612
    cp2.channel_flags AS policy_2_channel_flags,
613
    cp2.signature AS policy2_signature
614

615
FROM channels c
616
    JOIN nodes n1 ON c.node_id_1 = n1.id
617
    JOIN nodes n2 ON c.node_id_2 = n2.id
618
    LEFT JOIN channel_policies cp1
619
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
620
    LEFT JOIN channel_policies cp2
621
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
622
WHERE c.scid = $1
623
  AND c.version = $2
624
`
625

626
type GetChannelBySCIDWithPoliciesParams struct {
627
        Scid    []byte
628
        Version int16
629
}
630

631
type GetChannelBySCIDWithPoliciesRow struct {
632
        Channel                        Channel
633
        Node                           Node
634
        Node_2                         Node
635
        Policy1ID                      sql.NullInt64
636
        Policy1NodeID                  sql.NullInt64
637
        Policy1Version                 sql.NullInt16
638
        Policy1Timelock                sql.NullInt32
639
        Policy1FeePpm                  sql.NullInt64
640
        Policy1BaseFeeMsat             sql.NullInt64
641
        Policy1MinHtlcMsat             sql.NullInt64
642
        Policy1MaxHtlcMsat             sql.NullInt64
643
        Policy1LastUpdate              sql.NullInt64
644
        Policy1Disabled                sql.NullBool
645
        Policy1InboundBaseFeeMsat      sql.NullInt64
646
        Policy1InboundFeeRateMilliMsat sql.NullInt64
647
        Policy1MessageFlags            sql.NullInt16
648
        Policy1ChannelFlags            sql.NullInt16
649
        Policy1Signature               []byte
650
        Policy2ID                      sql.NullInt64
651
        Policy2NodeID                  sql.NullInt64
652
        Policy2Version                 sql.NullInt16
653
        Policy2Timelock                sql.NullInt32
654
        Policy2FeePpm                  sql.NullInt64
655
        Policy2BaseFeeMsat             sql.NullInt64
656
        Policy2MinHtlcMsat             sql.NullInt64
657
        Policy2MaxHtlcMsat             sql.NullInt64
658
        Policy2LastUpdate              sql.NullInt64
659
        Policy2Disabled                sql.NullBool
660
        Policy2InboundBaseFeeMsat      sql.NullInt64
661
        Policy2InboundFeeRateMilliMsat sql.NullInt64
662
        Policy2MessageFlags            sql.NullInt16
663
        Policy2ChannelFlags            sql.NullInt16
664
        Policy2Signature               []byte
665
}
666

667
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
668
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
669
        var i GetChannelBySCIDWithPoliciesRow
×
670
        err := row.Scan(
×
671
                &i.Channel.ID,
×
672
                &i.Channel.Version,
×
673
                &i.Channel.Scid,
×
674
                &i.Channel.NodeID1,
×
675
                &i.Channel.NodeID2,
×
676
                &i.Channel.Outpoint,
×
677
                &i.Channel.Capacity,
×
678
                &i.Channel.BitcoinKey1,
×
679
                &i.Channel.BitcoinKey2,
×
680
                &i.Channel.Node1Signature,
×
681
                &i.Channel.Node2Signature,
×
682
                &i.Channel.Bitcoin1Signature,
×
683
                &i.Channel.Bitcoin2Signature,
×
684
                &i.Node.ID,
×
685
                &i.Node.Version,
×
686
                &i.Node.PubKey,
×
687
                &i.Node.Alias,
×
688
                &i.Node.LastUpdate,
×
689
                &i.Node.Color,
×
690
                &i.Node.Signature,
×
691
                &i.Node_2.ID,
×
692
                &i.Node_2.Version,
×
693
                &i.Node_2.PubKey,
×
694
                &i.Node_2.Alias,
×
695
                &i.Node_2.LastUpdate,
×
696
                &i.Node_2.Color,
×
697
                &i.Node_2.Signature,
×
698
                &i.Policy1ID,
×
699
                &i.Policy1NodeID,
×
700
                &i.Policy1Version,
×
701
                &i.Policy1Timelock,
×
702
                &i.Policy1FeePpm,
×
703
                &i.Policy1BaseFeeMsat,
×
704
                &i.Policy1MinHtlcMsat,
×
705
                &i.Policy1MaxHtlcMsat,
×
706
                &i.Policy1LastUpdate,
×
707
                &i.Policy1Disabled,
×
708
                &i.Policy1InboundBaseFeeMsat,
×
709
                &i.Policy1InboundFeeRateMilliMsat,
×
710
                &i.Policy1MessageFlags,
×
711
                &i.Policy1ChannelFlags,
×
712
                &i.Policy1Signature,
×
713
                &i.Policy2ID,
×
714
                &i.Policy2NodeID,
×
715
                &i.Policy2Version,
×
716
                &i.Policy2Timelock,
×
717
                &i.Policy2FeePpm,
×
718
                &i.Policy2BaseFeeMsat,
×
719
                &i.Policy2MinHtlcMsat,
×
720
                &i.Policy2MaxHtlcMsat,
×
721
                &i.Policy2LastUpdate,
×
722
                &i.Policy2Disabled,
×
723
                &i.Policy2InboundBaseFeeMsat,
×
724
                &i.Policy2InboundFeeRateMilliMsat,
×
725
                &i.Policy2MessageFlags,
×
726
                &i.Policy2ChannelFlags,
×
727
                &i.Policy2Signature,
×
728
        )
×
729
        return i, err
×
730
}
×
731

732
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
733
SELECT
734
    cf.channel_id,
735
    true AS is_feature,
736
    cf.feature_bit AS feature_bit,
737
    NULL AS extra_key,
738
    NULL AS value
739
FROM channel_features cf
740
WHERE cf.channel_id = $1
741

742
UNION ALL
743

744
SELECT
745
    cet.channel_id,
746
    false AS is_feature,
747
    0 AS feature_bit,
748
    cet.type AS extra_key,
749
    cet.value AS value
750
FROM channel_extra_types cet
751
WHERE cet.channel_id = $1
752
`
753

754
type GetChannelFeaturesAndExtrasRow struct {
755
        ChannelID  int64
756
        IsFeature  bool
757
        FeatureBit int32
758
        ExtraKey   interface{}
759
        Value      interface{}
760
}
761

762
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
763
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
764
        if err != nil {
×
765
                return nil, err
×
766
        }
×
767
        defer rows.Close()
×
768
        var items []GetChannelFeaturesAndExtrasRow
×
769
        for rows.Next() {
×
770
                var i GetChannelFeaturesAndExtrasRow
×
771
                if err := rows.Scan(
×
772
                        &i.ChannelID,
×
773
                        &i.IsFeature,
×
774
                        &i.FeatureBit,
×
775
                        &i.ExtraKey,
×
776
                        &i.Value,
×
777
                ); err != nil {
×
778
                        return nil, err
×
779
                }
×
780
                items = append(items, i)
×
781
        }
782
        if err := rows.Close(); err != nil {
×
783
                return nil, err
×
784
        }
×
785
        if err := rows.Err(); err != nil {
×
786
                return nil, err
×
787
        }
×
788
        return items, nil
×
789
}
790

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

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

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

829
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
830
SELECT
831
    cp.id AS policy_id,
832
    cp.channel_id,
833
    cp.node_id,
834
    cpet.type,
835
    cpet.value
836
FROM channel_policies cp
837
JOIN channel_policy_extra_types cpet
838
ON cp.id = cpet.channel_policy_id
839
WHERE cp.id = $1 OR cp.id = $2
840
`
841

842
type GetChannelPolicyExtraTypesParams struct {
843
        ID   int64
844
        ID_2 int64
845
}
846

847
type GetChannelPolicyExtraTypesRow struct {
848
        PolicyID  int64
849
        ChannelID int64
850
        NodeID    int64
851
        Type      int64
852
        Value     []byte
853
}
854

855
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
856
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
857
        if err != nil {
×
858
                return nil, err
×
859
        }
×
860
        defer rows.Close()
×
861
        var items []GetChannelPolicyExtraTypesRow
×
862
        for rows.Next() {
×
863
                var i GetChannelPolicyExtraTypesRow
×
864
                if err := rows.Scan(
×
865
                        &i.PolicyID,
×
866
                        &i.ChannelID,
×
867
                        &i.NodeID,
×
868
                        &i.Type,
×
869
                        &i.Value,
×
870
                ); err != nil {
×
871
                        return nil, err
×
872
                }
×
873
                items = append(items, i)
×
874
        }
875
        if err := rows.Close(); err != nil {
×
876
                return nil, err
×
877
        }
×
878
        if err := rows.Err(); err != nil {
×
879
                return nil, err
×
880
        }
×
881
        return items, nil
×
882
}
883

884
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
885
SELECT
886
    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,
887
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
888
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
889

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

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

924
FROM channels c
925
    JOIN nodes n1 ON c.node_id_1 = n1.id
926
    JOIN nodes n2 ON c.node_id_2 = n2.id
927
    LEFT JOIN channel_policies cp1
928
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
929
    LEFT JOIN channel_policies cp2
930
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
931
WHERE c.version = $1
932
  AND (
933
       (cp1.last_update >= $2 AND cp1.last_update < $3)
934
       OR
935
       (cp2.last_update >= $2 AND cp2.last_update < $3)
936
  )
937
ORDER BY
938
    CASE
939
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
940
            THEN COALESCE(cp1.last_update, 0)
941
        ELSE COALESCE(cp2.last_update, 0)
942
        END ASC
943
`
944

945
type GetChannelsByPolicyLastUpdateRangeParams struct {
946
        Version   int16
947
        StartTime sql.NullInt64
948
        EndTime   sql.NullInt64
949
}
950

951
type GetChannelsByPolicyLastUpdateRangeRow struct {
952
        Channel                        Channel
953
        Node                           Node
954
        Node_2                         Node
955
        Policy1ID                      sql.NullInt64
956
        Policy1NodeID                  sql.NullInt64
957
        Policy1Version                 sql.NullInt16
958
        Policy1Timelock                sql.NullInt32
959
        Policy1FeePpm                  sql.NullInt64
960
        Policy1BaseFeeMsat             sql.NullInt64
961
        Policy1MinHtlcMsat             sql.NullInt64
962
        Policy1MaxHtlcMsat             sql.NullInt64
963
        Policy1LastUpdate              sql.NullInt64
964
        Policy1Disabled                sql.NullBool
965
        Policy1InboundBaseFeeMsat      sql.NullInt64
966
        Policy1InboundFeeRateMilliMsat sql.NullInt64
967
        Policy1MessageFlags            sql.NullInt16
968
        Policy1ChannelFlags            sql.NullInt16
969
        Policy1Signature               []byte
970
        Policy2ID                      sql.NullInt64
971
        Policy2NodeID                  sql.NullInt64
972
        Policy2Version                 sql.NullInt16
973
        Policy2Timelock                sql.NullInt32
974
        Policy2FeePpm                  sql.NullInt64
975
        Policy2BaseFeeMsat             sql.NullInt64
976
        Policy2MinHtlcMsat             sql.NullInt64
977
        Policy2MaxHtlcMsat             sql.NullInt64
978
        Policy2LastUpdate              sql.NullInt64
979
        Policy2Disabled                sql.NullBool
980
        Policy2InboundBaseFeeMsat      sql.NullInt64
981
        Policy2InboundFeeRateMilliMsat sql.NullInt64
982
        Policy2MessageFlags            sql.NullInt16
983
        Policy2ChannelFlags            sql.NullInt16
984
        Policy2Signature               []byte
985
}
986

987
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
988
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
989
        if err != nil {
×
990
                return nil, err
×
991
        }
×
992
        defer rows.Close()
×
993
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
994
        for rows.Next() {
×
995
                var i GetChannelsByPolicyLastUpdateRangeRow
×
996
                if err := rows.Scan(
×
997
                        &i.Channel.ID,
×
998
                        &i.Channel.Version,
×
999
                        &i.Channel.Scid,
×
1000
                        &i.Channel.NodeID1,
×
1001
                        &i.Channel.NodeID2,
×
1002
                        &i.Channel.Outpoint,
×
1003
                        &i.Channel.Capacity,
×
1004
                        &i.Channel.BitcoinKey1,
×
1005
                        &i.Channel.BitcoinKey2,
×
1006
                        &i.Channel.Node1Signature,
×
1007
                        &i.Channel.Node2Signature,
×
1008
                        &i.Channel.Bitcoin1Signature,
×
1009
                        &i.Channel.Bitcoin2Signature,
×
1010
                        &i.Node.ID,
×
1011
                        &i.Node.Version,
×
1012
                        &i.Node.PubKey,
×
1013
                        &i.Node.Alias,
×
1014
                        &i.Node.LastUpdate,
×
1015
                        &i.Node.Color,
×
1016
                        &i.Node.Signature,
×
1017
                        &i.Node_2.ID,
×
1018
                        &i.Node_2.Version,
×
1019
                        &i.Node_2.PubKey,
×
1020
                        &i.Node_2.Alias,
×
1021
                        &i.Node_2.LastUpdate,
×
1022
                        &i.Node_2.Color,
×
1023
                        &i.Node_2.Signature,
×
1024
                        &i.Policy1ID,
×
1025
                        &i.Policy1NodeID,
×
1026
                        &i.Policy1Version,
×
1027
                        &i.Policy1Timelock,
×
1028
                        &i.Policy1FeePpm,
×
1029
                        &i.Policy1BaseFeeMsat,
×
1030
                        &i.Policy1MinHtlcMsat,
×
1031
                        &i.Policy1MaxHtlcMsat,
×
1032
                        &i.Policy1LastUpdate,
×
1033
                        &i.Policy1Disabled,
×
1034
                        &i.Policy1InboundBaseFeeMsat,
×
1035
                        &i.Policy1InboundFeeRateMilliMsat,
×
1036
                        &i.Policy1MessageFlags,
×
1037
                        &i.Policy1ChannelFlags,
×
1038
                        &i.Policy1Signature,
×
1039
                        &i.Policy2ID,
×
1040
                        &i.Policy2NodeID,
×
1041
                        &i.Policy2Version,
×
1042
                        &i.Policy2Timelock,
×
1043
                        &i.Policy2FeePpm,
×
1044
                        &i.Policy2BaseFeeMsat,
×
1045
                        &i.Policy2MinHtlcMsat,
×
1046
                        &i.Policy2MaxHtlcMsat,
×
1047
                        &i.Policy2LastUpdate,
×
1048
                        &i.Policy2Disabled,
×
1049
                        &i.Policy2InboundBaseFeeMsat,
×
1050
                        &i.Policy2InboundFeeRateMilliMsat,
×
1051
                        &i.Policy2MessageFlags,
×
1052
                        &i.Policy2ChannelFlags,
×
1053
                        &i.Policy2Signature,
×
1054
                ); err != nil {
×
1055
                        return nil, err
×
1056
                }
×
1057
                items = append(items, i)
×
1058
        }
1059
        if err := rows.Close(); err != nil {
×
1060
                return nil, err
×
1061
        }
×
1062
        if err := rows.Err(); err != nil {
×
1063
                return nil, err
×
1064
        }
×
1065
        return items, nil
×
1066
}
1067

1068
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1069
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,
1070
    n1.pub_key AS node1_pub_key,
1071
    n2.pub_key AS node2_pub_key
1072
FROM channels c
1073
    JOIN nodes n1 ON c.node_id_1 = n1.id
1074
    JOIN nodes n2 ON c.node_id_2 = n2.id
1075
WHERE scid >= $1
1076
  AND scid < $2
1077
`
1078

1079
type GetChannelsBySCIDRangeParams struct {
1080
        StartScid []byte
1081
        EndScid   []byte
1082
}
1083

1084
type GetChannelsBySCIDRangeRow struct {
1085
        Channel     Channel
1086
        Node1PubKey []byte
1087
        Node2PubKey []byte
1088
}
1089

1090
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1091
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1092
        if err != nil {
×
1093
                return nil, err
×
1094
        }
×
1095
        defer rows.Close()
×
1096
        var items []GetChannelsBySCIDRangeRow
×
1097
        for rows.Next() {
×
1098
                var i GetChannelsBySCIDRangeRow
×
1099
                if err := rows.Scan(
×
1100
                        &i.Channel.ID,
×
1101
                        &i.Channel.Version,
×
1102
                        &i.Channel.Scid,
×
1103
                        &i.Channel.NodeID1,
×
1104
                        &i.Channel.NodeID2,
×
1105
                        &i.Channel.Outpoint,
×
1106
                        &i.Channel.Capacity,
×
1107
                        &i.Channel.BitcoinKey1,
×
1108
                        &i.Channel.BitcoinKey2,
×
1109
                        &i.Channel.Node1Signature,
×
1110
                        &i.Channel.Node2Signature,
×
1111
                        &i.Channel.Bitcoin1Signature,
×
1112
                        &i.Channel.Bitcoin2Signature,
×
1113
                        &i.Node1PubKey,
×
1114
                        &i.Node2PubKey,
×
1115
                ); err != nil {
×
1116
                        return nil, err
×
1117
                }
×
1118
                items = append(items, i)
×
1119
        }
1120
        if err := rows.Close(); err != nil {
×
1121
                return nil, err
×
1122
        }
×
1123
        if err := rows.Err(); err != nil {
×
1124
                return nil, err
×
1125
        }
×
1126
        return items, nil
×
1127
}
1128

1129
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1130
SELECT node_id, type, value
1131
FROM node_extra_types
1132
WHERE node_id = $1
1133
`
1134

1135
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
1136
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1137
        if err != nil {
×
1138
                return nil, err
×
1139
        }
×
1140
        defer rows.Close()
×
1141
        var items []NodeExtraType
×
1142
        for rows.Next() {
×
1143
                var i NodeExtraType
×
1144
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1145
                        return nil, err
×
1146
                }
×
1147
                items = append(items, i)
×
1148
        }
1149
        if err := rows.Close(); err != nil {
×
1150
                return nil, err
×
1151
        }
×
1152
        if err := rows.Err(); err != nil {
×
1153
                return nil, err
×
1154
        }
×
1155
        return items, nil
×
1156
}
1157

1158
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
1159
SELECT a.type, a.address
1160
FROM nodes n
1161
LEFT JOIN node_addresses a ON a.node_id = n.id
1162
WHERE n.pub_key = $1 AND n.version = $2
1163
ORDER BY a.type ASC, a.position ASC
1164
`
1165

1166
type GetNodeAddressesByPubKeyParams struct {
1167
        PubKey  []byte
1168
        Version int16
1169
}
1170

1171
type GetNodeAddressesByPubKeyRow struct {
1172
        Type    sql.NullInt16
1173
        Address sql.NullString
1174
}
1175

1176
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
1177
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
1178
        if err != nil {
×
1179
                return nil, err
×
1180
        }
×
1181
        defer rows.Close()
×
1182
        var items []GetNodeAddressesByPubKeyRow
×
1183
        for rows.Next() {
×
1184
                var i GetNodeAddressesByPubKeyRow
×
1185
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1186
                        return nil, err
×
1187
                }
×
1188
                items = append(items, i)
×
1189
        }
1190
        if err := rows.Close(); err != nil {
×
1191
                return nil, err
×
1192
        }
×
1193
        if err := rows.Err(); err != nil {
×
1194
                return nil, err
×
1195
        }
×
1196
        return items, nil
×
1197
}
1198

1199
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1200
SELECT id, version, pub_key, alias, last_update, color, signature
1201
FROM nodes
1202
WHERE pub_key = $1
1203
  AND version = $2
1204
`
1205

1206
type GetNodeByPubKeyParams struct {
1207
        PubKey  []byte
1208
        Version int16
1209
}
1210

1211
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
1212
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1213
        var i Node
×
1214
        err := row.Scan(
×
1215
                &i.ID,
×
1216
                &i.Version,
×
1217
                &i.PubKey,
×
1218
                &i.Alias,
×
1219
                &i.LastUpdate,
×
1220
                &i.Color,
×
1221
                &i.Signature,
×
1222
        )
×
1223
        return i, err
×
1224
}
×
1225

1226
const getNodeFeatures = `-- name: GetNodeFeatures :many
1227
SELECT node_id, feature_bit
1228
FROM node_features
1229
WHERE node_id = $1
1230
`
1231

1232
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
1233
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1234
        if err != nil {
×
1235
                return nil, err
×
1236
        }
×
1237
        defer rows.Close()
×
1238
        var items []NodeFeature
×
1239
        for rows.Next() {
×
1240
                var i NodeFeature
×
1241
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1242
                        return nil, err
×
1243
                }
×
1244
                items = append(items, i)
×
1245
        }
1246
        if err := rows.Close(); err != nil {
×
1247
                return nil, err
×
1248
        }
×
1249
        if err := rows.Err(); err != nil {
×
1250
                return nil, err
×
1251
        }
×
1252
        return items, nil
×
1253
}
1254

1255
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1256
SELECT f.feature_bit
1257
FROM nodes n
1258
    JOIN node_features f ON f.node_id = n.id
1259
WHERE n.pub_key = $1
1260
  AND n.version = $2
1261
`
1262

1263
type GetNodeFeaturesByPubKeyParams struct {
1264
        PubKey  []byte
1265
        Version int16
1266
}
1267

1268
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1269
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1270
        if err != nil {
×
1271
                return nil, err
×
1272
        }
×
1273
        defer rows.Close()
×
1274
        var items []int32
×
1275
        for rows.Next() {
×
1276
                var feature_bit int32
×
1277
                if err := rows.Scan(&feature_bit); err != nil {
×
1278
                        return nil, err
×
1279
                }
×
1280
                items = append(items, feature_bit)
×
1281
        }
1282
        if err := rows.Close(); err != nil {
×
1283
                return nil, err
×
1284
        }
×
1285
        if err := rows.Err(); err != nil {
×
1286
                return nil, err
×
1287
        }
×
1288
        return items, nil
×
1289
}
1290

1291
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1292
SELECT id
1293
FROM nodes
1294
WHERE pub_key = $1
1295
  AND version = $2
1296
`
1297

1298
type GetNodeIDByPubKeyParams struct {
1299
        PubKey  []byte
1300
        Version int16
1301
}
1302

1303
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1304
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1305
        var id int64
×
1306
        err := row.Scan(&id)
×
1307
        return id, err
×
1308
}
×
1309

1310
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1311
SELECT id, version, pub_key, alias, last_update, color, signature
1312
FROM nodes
1313
WHERE last_update >= $1
1314
  AND last_update < $2
1315
`
1316

1317
type GetNodesByLastUpdateRangeParams struct {
1318
        StartTime sql.NullInt64
1319
        EndTime   sql.NullInt64
1320
}
1321

1322
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
1323
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1324
        if err != nil {
×
1325
                return nil, err
×
1326
        }
×
1327
        defer rows.Close()
×
1328
        var items []Node
×
1329
        for rows.Next() {
×
1330
                var i Node
×
1331
                if err := rows.Scan(
×
1332
                        &i.ID,
×
1333
                        &i.Version,
×
1334
                        &i.PubKey,
×
1335
                        &i.Alias,
×
1336
                        &i.LastUpdate,
×
1337
                        &i.Color,
×
1338
                        &i.Signature,
×
1339
                ); err != nil {
×
1340
                        return nil, err
×
1341
                }
×
1342
                items = append(items, i)
×
1343
        }
1344
        if err := rows.Close(); err != nil {
×
1345
                return nil, err
×
1346
        }
×
1347
        if err := rows.Err(); err != nil {
×
1348
                return nil, err
×
1349
        }
×
1350
        return items, nil
×
1351
}
1352

1353
const getPruneTip = `-- name: GetPruneTip :one
1354
SELECT block_height, block_hash
1355
FROM prune_log
1356
ORDER BY block_height DESC
1357
LIMIT 1
1358
`
1359

1360
func (q *Queries) GetPruneTip(ctx context.Context) (PruneLog, error) {
×
1361
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1362
        var i PruneLog
×
1363
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1364
        return i, err
×
1365
}
×
1366

1367
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1368
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
1369
FROM channels
1370
WHERE node_1_signature IS NOT NULL
1371
  AND scid >= $1
1372
  AND scid < $2
1373
`
1374

1375
type GetPublicV1ChannelsBySCIDParams struct {
1376
        StartScid []byte
1377
        EndScid   []byte
1378
}
1379

1380
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
×
1381
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1382
        if err != nil {
×
1383
                return nil, err
×
1384
        }
×
1385
        defer rows.Close()
×
1386
        var items []Channel
×
1387
        for rows.Next() {
×
1388
                var i Channel
×
1389
                if err := rows.Scan(
×
1390
                        &i.ID,
×
1391
                        &i.Version,
×
1392
                        &i.Scid,
×
1393
                        &i.NodeID1,
×
1394
                        &i.NodeID2,
×
1395
                        &i.Outpoint,
×
1396
                        &i.Capacity,
×
1397
                        &i.BitcoinKey1,
×
1398
                        &i.BitcoinKey2,
×
1399
                        &i.Node1Signature,
×
1400
                        &i.Node2Signature,
×
1401
                        &i.Bitcoin1Signature,
×
1402
                        &i.Bitcoin2Signature,
×
1403
                ); err != nil {
×
1404
                        return nil, err
×
1405
                }
×
1406
                items = append(items, i)
×
1407
        }
1408
        if err := rows.Close(); err != nil {
×
1409
                return nil, err
×
1410
        }
×
1411
        if err := rows.Err(); err != nil {
×
1412
                return nil, err
×
1413
        }
×
1414
        return items, nil
×
1415
}
1416

1417
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1418
SELECT scid from channels
1419
WHERE outpoint = $1 AND version = $2
1420
`
1421

1422
type GetSCIDByOutpointParams struct {
1423
        Outpoint string
1424
        Version  int16
1425
}
1426

1427
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1428
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1429
        var scid []byte
×
1430
        err := row.Scan(&scid)
×
1431
        return scid, err
×
1432
}
×
1433

1434
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1435
SELECT sn.node_id, n.pub_key
1436
FROM source_nodes sn
1437
    JOIN nodes n ON sn.node_id = n.id
1438
WHERE n.version = $1
1439
`
1440

1441
type GetSourceNodesByVersionRow struct {
1442
        NodeID int64
1443
        PubKey []byte
1444
}
1445

1446
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1447
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1448
        if err != nil {
×
1449
                return nil, err
×
1450
        }
×
1451
        defer rows.Close()
×
1452
        var items []GetSourceNodesByVersionRow
×
1453
        for rows.Next() {
×
1454
                var i GetSourceNodesByVersionRow
×
1455
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1456
                        return nil, err
×
1457
                }
×
1458
                items = append(items, i)
×
1459
        }
1460
        if err := rows.Close(); err != nil {
×
1461
                return nil, err
×
1462
        }
×
1463
        if err := rows.Err(); err != nil {
×
1464
                return nil, err
×
1465
        }
×
1466
        return items, nil
×
1467
}
1468

1469
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1470
SELECT c.scid
1471
FROM channels c
1472
    JOIN channel_policies cp ON cp.channel_id = c.id
1473
WHERE cp.disabled = true
1474
AND c.version = 1
1475
GROUP BY c.scid
1476
HAVING COUNT(*) > 1
1477
`
1478

1479
// NOTE: this is V1 specific since for V1, disabled is a
1480
// simple, single boolean. The proposed V2 policy
1481
// structure will have a more complex disabled bit vector
1482
// and so the query for V2 may differ.
1483
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1484
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1485
        if err != nil {
×
1486
                return nil, err
×
1487
        }
×
1488
        defer rows.Close()
×
1489
        var items [][]byte
×
1490
        for rows.Next() {
×
1491
                var scid []byte
×
1492
                if err := rows.Scan(&scid); err != nil {
×
1493
                        return nil, err
×
1494
                }
×
1495
                items = append(items, scid)
×
1496
        }
1497
        if err := rows.Close(); err != nil {
×
1498
                return nil, err
×
1499
        }
×
1500
        if err := rows.Err(); err != nil {
×
1501
                return nil, err
×
1502
        }
×
1503
        return items, nil
×
1504
}
1505

1506
const getZombieChannel = `-- name: GetZombieChannel :one
1507
SELECT scid, version, node_key_1, node_key_2
1508
FROM zombie_channels
1509
WHERE scid = $1
1510
AND version = $2
1511
`
1512

1513
type GetZombieChannelParams struct {
1514
        Scid    []byte
1515
        Version int16
1516
}
1517

1518
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) {
×
1519
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1520
        var i ZombieChannel
×
1521
        err := row.Scan(
×
1522
                &i.Scid,
×
1523
                &i.Version,
×
1524
                &i.NodeKey1,
×
1525
                &i.NodeKey2,
×
1526
        )
×
1527
        return i, err
×
1528
}
×
1529

1530
const highestSCID = `-- name: HighestSCID :one
1531
SELECT scid
1532
FROM channels
1533
WHERE version = $1
1534
ORDER BY scid DESC
1535
LIMIT 1
1536
`
1537

1538
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1539
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1540
        var scid []byte
×
1541
        err := row.Scan(&scid)
×
1542
        return scid, err
×
1543
}
×
1544

1545
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1546
/* ─────────────────────────────────────────────
1547
   channel_policy_extra_types table queries
1548
   ─────────────────────────────────────────────
1549
*/
1550

1551
INSERT INTO channel_policy_extra_types (
1552
    channel_policy_id, type, value
1553
)
1554
VALUES ($1, $2, $3)
1555
`
1556

1557
type InsertChanPolicyExtraTypeParams struct {
1558
        ChannelPolicyID int64
1559
        Type            int64
1560
        Value           []byte
1561
}
1562

1563
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1564
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1565
        return err
×
1566
}
×
1567

1568
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1569
/* ─────────────────────────────────────────────
1570
   channel_features table queries
1571
   ─────────────────────────────────────────────
1572
*/
1573

1574
INSERT INTO channel_features (
1575
    channel_id, feature_bit
1576
) VALUES (
1577
    $1, $2
1578
)
1579
`
1580

1581
type InsertChannelFeatureParams struct {
1582
        ChannelID  int64
1583
        FeatureBit int32
1584
}
1585

1586
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1587
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1588
        return err
×
1589
}
×
1590

1591
const insertClosedChannel = `-- name: InsertClosedChannel :exec
1592
/* ─────────────────────────────────────────────
1593
   closed_scid table queries
1594
   ────────────────────────────────────────────-
1595
*/
1596

1597
INSERT INTO closed_scids (scid)
1598
VALUES ($1)
1599
ON CONFLICT (scid) DO NOTHING
1600
`
1601

1602
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
1603
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
1604
        return err
×
1605
}
×
1606

1607
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1608
/* ─────────────────────────────────────────────
1609
   node_addresses table queries
1610
   ─────────────────────────────────────────────
1611
*/
1612

1613
INSERT INTO node_addresses (
1614
    node_id,
1615
    type,
1616
    address,
1617
    position
1618
) VALUES (
1619
    $1, $2, $3, $4
1620
 )
1621
`
1622

1623
type InsertNodeAddressParams struct {
1624
        NodeID   int64
1625
        Type     int16
1626
        Address  string
1627
        Position int32
1628
}
1629

1630
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1631
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1632
                arg.NodeID,
×
1633
                arg.Type,
×
1634
                arg.Address,
×
1635
                arg.Position,
×
1636
        )
×
1637
        return err
×
1638
}
×
1639

1640
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1641
/* ─────────────────────────────────────────────
1642
   node_features table queries
1643
   ─────────────────────────────────────────────
1644
*/
1645

1646
INSERT INTO node_features (
1647
    node_id, feature_bit
1648
) VALUES (
1649
    $1, $2
1650
)
1651
`
1652

1653
type InsertNodeFeatureParams struct {
1654
        NodeID     int64
1655
        FeatureBit int32
1656
}
1657

1658
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1659
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1660
        return err
×
1661
}
×
1662

1663
const isClosedChannel = `-- name: IsClosedChannel :one
1664
SELECT EXISTS (
1665
    SELECT 1
1666
    FROM closed_scids
1667
    WHERE scid = $1
1668
)
1669
`
1670

1671
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
1672
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
1673
        var exists bool
×
1674
        err := row.Scan(&exists)
×
1675
        return exists, err
×
1676
}
×
1677

1678
const isPublicV1Node = `-- name: IsPublicV1Node :one
1679
SELECT EXISTS (
1680
    SELECT 1
1681
    FROM channels c
1682
    JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1683
    -- NOTE: we hard-code the version here since the clauses
1684
    -- here that determine if a node is public is specific
1685
    -- to the V1 gossip protocol. In V1, a node is public
1686
    -- if it has a public channel and a public channel is one
1687
    -- where we have the set of signatures of the channel
1688
    -- announcement. It is enough to just check that we have
1689
    -- one of the signatures since we only ever set them
1690
    -- together.
1691
    WHERE c.version = 1
1692
      AND c.bitcoin_1_signature IS NOT NULL
1693
      AND n.pub_key = $1
1694
)
1695
`
1696

1697
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
1698
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
1699
        var exists bool
×
1700
        err := row.Scan(&exists)
×
1701
        return exists, err
×
1702
}
×
1703

1704
const isZombieChannel = `-- name: IsZombieChannel :one
1705
SELECT EXISTS (
1706
    SELECT 1
1707
    FROM zombie_channels
1708
    WHERE scid = $1
1709
    AND version = $2
1710
) AS is_zombie
1711
`
1712

1713
type IsZombieChannelParams struct {
1714
        Scid    []byte
1715
        Version int16
1716
}
1717

1718
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
1719
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
1720
        var is_zombie bool
×
1721
        err := row.Scan(&is_zombie)
×
1722
        return is_zombie, err
×
1723
}
×
1724

1725
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1726
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,
1727
    n1.pub_key AS node1_pubkey,
1728
    n2.pub_key AS node2_pubkey,
1729

1730
    -- Policy 1
1731
    -- TODO(elle): use sqlc.embed to embed policy structs
1732
    --  once this issue is resolved:
1733
    --  https://github.com/sqlc-dev/sqlc/issues/2997
1734
    cp1.id AS policy1_id,
1735
    cp1.node_id AS policy1_node_id,
1736
    cp1.version AS policy1_version,
1737
    cp1.timelock AS policy1_timelock,
1738
    cp1.fee_ppm AS policy1_fee_ppm,
1739
    cp1.base_fee_msat AS policy1_base_fee_msat,
1740
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1741
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1742
    cp1.last_update AS policy1_last_update,
1743
    cp1.disabled AS policy1_disabled,
1744
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1745
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1746
    cp1.message_flags AS policy1_message_flags,
1747
    cp1.channel_flags AS policy1_channel_flags,
1748
    cp1.signature AS policy1_signature,
1749

1750
       -- Policy 2
1751
    cp2.id AS policy2_id,
1752
    cp2.node_id AS policy2_node_id,
1753
    cp2.version AS policy2_version,
1754
    cp2.timelock AS policy2_timelock,
1755
    cp2.fee_ppm AS policy2_fee_ppm,
1756
    cp2.base_fee_msat AS policy2_base_fee_msat,
1757
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1758
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1759
    cp2.last_update AS policy2_last_update,
1760
    cp2.disabled AS policy2_disabled,
1761
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1762
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1763
    cp2.message_flags AS policy2_message_flags,
1764
    cp2.channel_flags AS policy2_channel_flags,
1765
    cp2.signature AS policy2_signature
1766

1767
FROM channels c
1768
    JOIN nodes n1 ON c.node_id_1 = n1.id
1769
    JOIN nodes n2 ON c.node_id_2 = n2.id
1770
    LEFT JOIN channel_policies cp1
1771
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1772
    LEFT JOIN channel_policies cp2
1773
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1774
WHERE c.version = $1
1775
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1776
`
1777

1778
type ListChannelsByNodeIDParams struct {
1779
        Version int16
1780
        NodeID1 int64
1781
}
1782

1783
type ListChannelsByNodeIDRow struct {
1784
        Channel                        Channel
1785
        Node1Pubkey                    []byte
1786
        Node2Pubkey                    []byte
1787
        Policy1ID                      sql.NullInt64
1788
        Policy1NodeID                  sql.NullInt64
1789
        Policy1Version                 sql.NullInt16
1790
        Policy1Timelock                sql.NullInt32
1791
        Policy1FeePpm                  sql.NullInt64
1792
        Policy1BaseFeeMsat             sql.NullInt64
1793
        Policy1MinHtlcMsat             sql.NullInt64
1794
        Policy1MaxHtlcMsat             sql.NullInt64
1795
        Policy1LastUpdate              sql.NullInt64
1796
        Policy1Disabled                sql.NullBool
1797
        Policy1InboundBaseFeeMsat      sql.NullInt64
1798
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1799
        Policy1MessageFlags            sql.NullInt16
1800
        Policy1ChannelFlags            sql.NullInt16
1801
        Policy1Signature               []byte
1802
        Policy2ID                      sql.NullInt64
1803
        Policy2NodeID                  sql.NullInt64
1804
        Policy2Version                 sql.NullInt16
1805
        Policy2Timelock                sql.NullInt32
1806
        Policy2FeePpm                  sql.NullInt64
1807
        Policy2BaseFeeMsat             sql.NullInt64
1808
        Policy2MinHtlcMsat             sql.NullInt64
1809
        Policy2MaxHtlcMsat             sql.NullInt64
1810
        Policy2LastUpdate              sql.NullInt64
1811
        Policy2Disabled                sql.NullBool
1812
        Policy2InboundBaseFeeMsat      sql.NullInt64
1813
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1814
        Policy2MessageFlags            sql.NullInt16
1815
        Policy2ChannelFlags            sql.NullInt16
1816
        Policy2Signature               []byte
1817
}
1818

1819
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
1820
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
1821
        if err != nil {
×
1822
                return nil, err
×
1823
        }
×
1824
        defer rows.Close()
×
1825
        var items []ListChannelsByNodeIDRow
×
1826
        for rows.Next() {
×
1827
                var i ListChannelsByNodeIDRow
×
1828
                if err := rows.Scan(
×
1829
                        &i.Channel.ID,
×
1830
                        &i.Channel.Version,
×
1831
                        &i.Channel.Scid,
×
1832
                        &i.Channel.NodeID1,
×
1833
                        &i.Channel.NodeID2,
×
1834
                        &i.Channel.Outpoint,
×
1835
                        &i.Channel.Capacity,
×
1836
                        &i.Channel.BitcoinKey1,
×
1837
                        &i.Channel.BitcoinKey2,
×
1838
                        &i.Channel.Node1Signature,
×
1839
                        &i.Channel.Node2Signature,
×
1840
                        &i.Channel.Bitcoin1Signature,
×
1841
                        &i.Channel.Bitcoin2Signature,
×
1842
                        &i.Node1Pubkey,
×
1843
                        &i.Node2Pubkey,
×
1844
                        &i.Policy1ID,
×
1845
                        &i.Policy1NodeID,
×
1846
                        &i.Policy1Version,
×
1847
                        &i.Policy1Timelock,
×
1848
                        &i.Policy1FeePpm,
×
1849
                        &i.Policy1BaseFeeMsat,
×
1850
                        &i.Policy1MinHtlcMsat,
×
1851
                        &i.Policy1MaxHtlcMsat,
×
1852
                        &i.Policy1LastUpdate,
×
1853
                        &i.Policy1Disabled,
×
1854
                        &i.Policy1InboundBaseFeeMsat,
×
1855
                        &i.Policy1InboundFeeRateMilliMsat,
×
1856
                        &i.Policy1MessageFlags,
×
1857
                        &i.Policy1ChannelFlags,
×
1858
                        &i.Policy1Signature,
×
1859
                        &i.Policy2ID,
×
1860
                        &i.Policy2NodeID,
×
1861
                        &i.Policy2Version,
×
1862
                        &i.Policy2Timelock,
×
1863
                        &i.Policy2FeePpm,
×
1864
                        &i.Policy2BaseFeeMsat,
×
1865
                        &i.Policy2MinHtlcMsat,
×
1866
                        &i.Policy2MaxHtlcMsat,
×
1867
                        &i.Policy2LastUpdate,
×
1868
                        &i.Policy2Disabled,
×
1869
                        &i.Policy2InboundBaseFeeMsat,
×
1870
                        &i.Policy2InboundFeeRateMilliMsat,
×
1871
                        &i.Policy2MessageFlags,
×
1872
                        &i.Policy2ChannelFlags,
×
1873
                        &i.Policy2Signature,
×
1874
                ); err != nil {
×
1875
                        return nil, err
×
1876
                }
×
1877
                items = append(items, i)
×
1878
        }
1879
        if err := rows.Close(); err != nil {
×
1880
                return nil, err
×
1881
        }
×
1882
        if err := rows.Err(); err != nil {
×
1883
                return nil, err
×
1884
        }
×
1885
        return items, nil
×
1886
}
1887

1888
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
1889
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
1890
FROM channels c
1891
WHERE c.version = $1 AND c.id > $2
1892
ORDER BY c.id
1893
LIMIT $3
1894
`
1895

1896
type ListChannelsPaginatedParams struct {
1897
        Version int16
1898
        ID      int64
1899
        Limit   int32
1900
}
1901

1902
type ListChannelsPaginatedRow struct {
1903
        ID          int64
1904
        BitcoinKey1 []byte
1905
        BitcoinKey2 []byte
1906
        Outpoint    string
1907
}
1908

1909
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
1910
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
1911
        if err != nil {
×
1912
                return nil, err
×
1913
        }
×
1914
        defer rows.Close()
×
1915
        var items []ListChannelsPaginatedRow
×
1916
        for rows.Next() {
×
1917
                var i ListChannelsPaginatedRow
×
1918
                if err := rows.Scan(
×
1919
                        &i.ID,
×
1920
                        &i.BitcoinKey1,
×
1921
                        &i.BitcoinKey2,
×
1922
                        &i.Outpoint,
×
1923
                ); err != nil {
×
1924
                        return nil, err
×
1925
                }
×
1926
                items = append(items, i)
×
1927
        }
1928
        if err := rows.Close(); err != nil {
×
1929
                return nil, err
×
1930
        }
×
1931
        if err := rows.Err(); err != nil {
×
1932
                return nil, err
×
1933
        }
×
1934
        return items, nil
×
1935
}
1936

1937
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
1938
SELECT
1939
    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,
1940

1941
    -- Join node pubkeys
1942
    n1.pub_key AS node1_pubkey,
1943
    n2.pub_key AS node2_pubkey,
1944

1945
    -- Node 1 policy
1946
    cp1.id AS policy_1_id,
1947
    cp1.node_id AS policy_1_node_id,
1948
    cp1.version AS policy_1_version,
1949
    cp1.timelock AS policy_1_timelock,
1950
    cp1.fee_ppm AS policy_1_fee_ppm,
1951
    cp1.base_fee_msat AS policy_1_base_fee_msat,
1952
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
1953
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
1954
    cp1.last_update AS policy_1_last_update,
1955
    cp1.disabled AS policy_1_disabled,
1956
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1957
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1958
    cp1.message_flags AS policy1_message_flags,
1959
    cp1.channel_flags AS policy1_channel_flags,
1960
    cp1.signature AS policy_1_signature,
1961

1962
    -- Node 2 policy
1963
    cp2.id AS policy_2_id,
1964
    cp2.node_id AS policy_2_node_id,
1965
    cp2.version AS policy_2_version,
1966
    cp2.timelock AS policy_2_timelock,
1967
    cp2.fee_ppm AS policy_2_fee_ppm,
1968
    cp2.base_fee_msat AS policy_2_base_fee_msat,
1969
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
1970
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
1971
    cp2.last_update AS policy_2_last_update,
1972
    cp2.disabled AS policy_2_disabled,
1973
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1974
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1975
    cp2.message_flags AS policy2_message_flags,
1976
    cp2.channel_flags AS policy2_channel_flags,
1977
    cp2.signature AS policy_2_signature
1978

1979
FROM channels c
1980
JOIN nodes n1 ON c.node_id_1 = n1.id
1981
JOIN nodes n2 ON c.node_id_2 = n2.id
1982
LEFT JOIN channel_policies cp1
1983
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1984
LEFT JOIN channel_policies cp2
1985
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1986
WHERE c.version = $1 AND c.id > $2
1987
ORDER BY c.id
1988
LIMIT $3
1989
`
1990

1991
type ListChannelsWithPoliciesPaginatedParams struct {
1992
        Version int16
1993
        ID      int64
1994
        Limit   int32
1995
}
1996

1997
type ListChannelsWithPoliciesPaginatedRow struct {
1998
        Channel                        Channel
1999
        Node1Pubkey                    []byte
2000
        Node2Pubkey                    []byte
2001
        Policy1ID                      sql.NullInt64
2002
        Policy1NodeID                  sql.NullInt64
2003
        Policy1Version                 sql.NullInt16
2004
        Policy1Timelock                sql.NullInt32
2005
        Policy1FeePpm                  sql.NullInt64
2006
        Policy1BaseFeeMsat             sql.NullInt64
2007
        Policy1MinHtlcMsat             sql.NullInt64
2008
        Policy1MaxHtlcMsat             sql.NullInt64
2009
        Policy1LastUpdate              sql.NullInt64
2010
        Policy1Disabled                sql.NullBool
2011
        Policy1InboundBaseFeeMsat      sql.NullInt64
2012
        Policy1InboundFeeRateMilliMsat sql.NullInt64
2013
        Policy1MessageFlags            sql.NullInt16
2014
        Policy1ChannelFlags            sql.NullInt16
2015
        Policy1Signature               []byte
2016
        Policy2ID                      sql.NullInt64
2017
        Policy2NodeID                  sql.NullInt64
2018
        Policy2Version                 sql.NullInt16
2019
        Policy2Timelock                sql.NullInt32
2020
        Policy2FeePpm                  sql.NullInt64
2021
        Policy2BaseFeeMsat             sql.NullInt64
2022
        Policy2MinHtlcMsat             sql.NullInt64
2023
        Policy2MaxHtlcMsat             sql.NullInt64
2024
        Policy2LastUpdate              sql.NullInt64
2025
        Policy2Disabled                sql.NullBool
2026
        Policy2InboundBaseFeeMsat      sql.NullInt64
2027
        Policy2InboundFeeRateMilliMsat sql.NullInt64
2028
        Policy2MessageFlags            sql.NullInt16
2029
        Policy2ChannelFlags            sql.NullInt16
2030
        Policy2Signature               []byte
2031
}
2032

2033
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
2034
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
2035
        if err != nil {
×
2036
                return nil, err
×
2037
        }
×
2038
        defer rows.Close()
×
2039
        var items []ListChannelsWithPoliciesPaginatedRow
×
2040
        for rows.Next() {
×
2041
                var i ListChannelsWithPoliciesPaginatedRow
×
2042
                if err := rows.Scan(
×
2043
                        &i.Channel.ID,
×
2044
                        &i.Channel.Version,
×
2045
                        &i.Channel.Scid,
×
2046
                        &i.Channel.NodeID1,
×
2047
                        &i.Channel.NodeID2,
×
2048
                        &i.Channel.Outpoint,
×
2049
                        &i.Channel.Capacity,
×
2050
                        &i.Channel.BitcoinKey1,
×
2051
                        &i.Channel.BitcoinKey2,
×
2052
                        &i.Channel.Node1Signature,
×
2053
                        &i.Channel.Node2Signature,
×
2054
                        &i.Channel.Bitcoin1Signature,
×
2055
                        &i.Channel.Bitcoin2Signature,
×
2056
                        &i.Node1Pubkey,
×
2057
                        &i.Node2Pubkey,
×
2058
                        &i.Policy1ID,
×
2059
                        &i.Policy1NodeID,
×
2060
                        &i.Policy1Version,
×
2061
                        &i.Policy1Timelock,
×
2062
                        &i.Policy1FeePpm,
×
2063
                        &i.Policy1BaseFeeMsat,
×
2064
                        &i.Policy1MinHtlcMsat,
×
2065
                        &i.Policy1MaxHtlcMsat,
×
2066
                        &i.Policy1LastUpdate,
×
2067
                        &i.Policy1Disabled,
×
2068
                        &i.Policy1InboundBaseFeeMsat,
×
2069
                        &i.Policy1InboundFeeRateMilliMsat,
×
2070
                        &i.Policy1MessageFlags,
×
2071
                        &i.Policy1ChannelFlags,
×
2072
                        &i.Policy1Signature,
×
2073
                        &i.Policy2ID,
×
2074
                        &i.Policy2NodeID,
×
2075
                        &i.Policy2Version,
×
2076
                        &i.Policy2Timelock,
×
2077
                        &i.Policy2FeePpm,
×
2078
                        &i.Policy2BaseFeeMsat,
×
2079
                        &i.Policy2MinHtlcMsat,
×
2080
                        &i.Policy2MaxHtlcMsat,
×
2081
                        &i.Policy2LastUpdate,
×
2082
                        &i.Policy2Disabled,
×
2083
                        &i.Policy2InboundBaseFeeMsat,
×
2084
                        &i.Policy2InboundFeeRateMilliMsat,
×
2085
                        &i.Policy2MessageFlags,
×
2086
                        &i.Policy2ChannelFlags,
×
2087
                        &i.Policy2Signature,
×
2088
                ); err != nil {
×
2089
                        return nil, err
×
2090
                }
×
2091
                items = append(items, i)
×
2092
        }
2093
        if err := rows.Close(); err != nil {
×
2094
                return nil, err
×
2095
        }
×
2096
        if err := rows.Err(); err != nil {
×
2097
                return nil, err
×
2098
        }
×
2099
        return items, nil
×
2100
}
2101

2102
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2103
SELECT id, pub_key
2104
FROM nodes
2105
WHERE version = $1  AND id > $2
2106
ORDER BY id
2107
LIMIT $3
2108
`
2109

2110
type ListNodeIDsAndPubKeysParams struct {
2111
        Version int16
2112
        ID      int64
2113
        Limit   int32
2114
}
2115

2116
type ListNodeIDsAndPubKeysRow struct {
2117
        ID     int64
2118
        PubKey []byte
2119
}
2120

2121
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2122
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2123
        if err != nil {
×
2124
                return nil, err
×
2125
        }
×
2126
        defer rows.Close()
×
2127
        var items []ListNodeIDsAndPubKeysRow
×
2128
        for rows.Next() {
×
2129
                var i ListNodeIDsAndPubKeysRow
×
2130
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2131
                        return nil, err
×
2132
                }
×
2133
                items = append(items, i)
×
2134
        }
2135
        if err := rows.Close(); err != nil {
×
2136
                return nil, err
×
2137
        }
×
2138
        if err := rows.Err(); err != nil {
×
2139
                return nil, err
×
2140
        }
×
2141
        return items, nil
×
2142
}
2143

2144
const listNodesPaginated = `-- name: ListNodesPaginated :many
2145
SELECT id, version, pub_key, alias, last_update, color, signature
2146
FROM nodes
2147
WHERE version = $1 AND id > $2
2148
ORDER BY id
2149
LIMIT $3
2150
`
2151

2152
type ListNodesPaginatedParams struct {
2153
        Version int16
2154
        ID      int64
2155
        Limit   int32
2156
}
2157

2158
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) {
×
2159
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2160
        if err != nil {
×
2161
                return nil, err
×
2162
        }
×
2163
        defer rows.Close()
×
2164
        var items []Node
×
2165
        for rows.Next() {
×
2166
                var i Node
×
2167
                if err := rows.Scan(
×
2168
                        &i.ID,
×
2169
                        &i.Version,
×
2170
                        &i.PubKey,
×
2171
                        &i.Alias,
×
2172
                        &i.LastUpdate,
×
2173
                        &i.Color,
×
2174
                        &i.Signature,
×
2175
                ); err != nil {
×
2176
                        return nil, err
×
2177
                }
×
2178
                items = append(items, i)
×
2179
        }
2180
        if err := rows.Close(); err != nil {
×
2181
                return nil, err
×
2182
        }
×
2183
        if err := rows.Err(); err != nil {
×
2184
                return nil, err
×
2185
        }
×
2186
        return items, nil
×
2187
}
2188

2189
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2190
/* ─────────────────────────────────────────────
2191
   channel_policies table queries
2192
   ─────────────────────────────────────────────
2193
*/
2194

2195
INSERT INTO channel_policies (
2196
    version, channel_id, node_id, timelock, fee_ppm,
2197
    base_fee_msat, min_htlc_msat, last_update, disabled,
2198
    max_htlc_msat, inbound_base_fee_msat,
2199
    inbound_fee_rate_milli_msat, message_flags, channel_flags,
2200
    signature
2201
) VALUES  (
2202
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
2203
)
2204
ON CONFLICT (channel_id, node_id, version)
2205
    -- Update the following fields if a conflict occurs on channel_id,
2206
    -- node_id, and version.
2207
    DO UPDATE SET
2208
        timelock = EXCLUDED.timelock,
2209
        fee_ppm = EXCLUDED.fee_ppm,
2210
        base_fee_msat = EXCLUDED.base_fee_msat,
2211
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2212
        last_update = EXCLUDED.last_update,
2213
        disabled = EXCLUDED.disabled,
2214
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2215
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2216
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2217
        message_flags = EXCLUDED.message_flags,
2218
        channel_flags = EXCLUDED.channel_flags,
2219
        signature = EXCLUDED.signature
2220
WHERE EXCLUDED.last_update > channel_policies.last_update
2221
RETURNING id
2222
`
2223

2224
type UpsertEdgePolicyParams struct {
2225
        Version                 int16
2226
        ChannelID               int64
2227
        NodeID                  int64
2228
        Timelock                int32
2229
        FeePpm                  int64
2230
        BaseFeeMsat             int64
2231
        MinHtlcMsat             int64
2232
        LastUpdate              sql.NullInt64
2233
        Disabled                sql.NullBool
2234
        MaxHtlcMsat             sql.NullInt64
2235
        InboundBaseFeeMsat      sql.NullInt64
2236
        InboundFeeRateMilliMsat sql.NullInt64
2237
        MessageFlags            sql.NullInt16
2238
        ChannelFlags            sql.NullInt16
2239
        Signature               []byte
2240
}
2241

2242
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2243
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2244
                arg.Version,
×
2245
                arg.ChannelID,
×
2246
                arg.NodeID,
×
2247
                arg.Timelock,
×
2248
                arg.FeePpm,
×
2249
                arg.BaseFeeMsat,
×
2250
                arg.MinHtlcMsat,
×
2251
                arg.LastUpdate,
×
2252
                arg.Disabled,
×
2253
                arg.MaxHtlcMsat,
×
2254
                arg.InboundBaseFeeMsat,
×
2255
                arg.InboundFeeRateMilliMsat,
×
2256
                arg.MessageFlags,
×
2257
                arg.ChannelFlags,
×
2258
                arg.Signature,
×
2259
        )
×
2260
        var id int64
×
2261
        err := row.Scan(&id)
×
2262
        return id, err
×
2263
}
×
2264

2265
const upsertNode = `-- name: UpsertNode :one
2266
/* ─────────────────────────────────────────────
2267
   nodes table queries
2268
   ─────────────────────────────────────────────
2269
*/
2270

2271
INSERT INTO nodes (
2272
    version, pub_key, alias, last_update, color, signature
2273
) VALUES (
2274
    $1, $2, $3, $4, $5, $6
2275
)
2276
ON CONFLICT (pub_key, version)
2277
    -- Update the following fields if a conflict occurs on pub_key
2278
    -- and version.
2279
    DO UPDATE SET
2280
        alias = EXCLUDED.alias,
2281
        last_update = EXCLUDED.last_update,
2282
        color = EXCLUDED.color,
2283
        signature = EXCLUDED.signature
2284
WHERE nodes.last_update IS NULL
2285
    OR EXCLUDED.last_update > nodes.last_update
2286
RETURNING id
2287
`
2288

2289
type UpsertNodeParams struct {
2290
        Version    int16
2291
        PubKey     []byte
2292
        Alias      sql.NullString
2293
        LastUpdate sql.NullInt64
2294
        Color      sql.NullString
2295
        Signature  []byte
2296
}
2297

2298
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2299
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2300
                arg.Version,
×
2301
                arg.PubKey,
×
2302
                arg.Alias,
×
2303
                arg.LastUpdate,
×
2304
                arg.Color,
×
2305
                arg.Signature,
×
2306
        )
×
2307
        var id int64
×
2308
        err := row.Scan(&id)
×
2309
        return id, err
×
2310
}
×
2311

2312
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2313
/* ─────────────────────────────────────────────
2314
   node_extra_types table queries
2315
   ─────────────────────────────────────────────
2316
*/
2317

2318
INSERT INTO node_extra_types (
2319
    node_id, type, value
2320
)
2321
VALUES ($1, $2, $3)
2322
ON CONFLICT (type, node_id)
2323
    -- Update the value if a conflict occurs on type
2324
    -- and node_id.
2325
    DO UPDATE SET value = EXCLUDED.value
2326
`
2327

2328
type UpsertNodeExtraTypeParams struct {
2329
        NodeID int64
2330
        Type   int64
2331
        Value  []byte
2332
}
2333

2334
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2335
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2336
        return err
×
2337
}
×
2338

2339
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2340
/* ─────────────────────────────────────────────
2341
    prune_log table queries
2342
    ─────────────────────────────────────────────
2343
*/
2344

2345
INSERT INTO prune_log (
2346
    block_height, block_hash
2347
) VALUES (
2348
    $1, $2
2349
)
2350
ON CONFLICT(block_height) DO UPDATE SET
2351
    block_hash = EXCLUDED.block_hash
2352
`
2353

2354
type UpsertPruneLogEntryParams struct {
2355
        BlockHeight int64
2356
        BlockHash   []byte
2357
}
2358

2359
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2360
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2361
        return err
×
2362
}
×
2363

2364
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2365
/* ─────────────────────────────────────────────
2366
   zombie_channels table queries
2367
   ─────────────────────────────────────────────
2368
*/
2369

2370
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
2371
VALUES ($1, $2, $3, $4)
2372
ON CONFLICT (scid, version)
2373
DO UPDATE SET
2374
    -- If a conflict exists for the SCID and version pair, then we
2375
    -- update the node keys.
2376
    node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
2377
    node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2)
2378
`
2379

2380
type UpsertZombieChannelParams struct {
2381
        Scid     []byte
2382
        Version  int16
2383
        NodeKey1 []byte
2384
        NodeKey2 []byte
2385
}
2386

2387
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2388
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2389
                arg.Scid,
×
2390
                arg.Version,
×
2391
                arg.NodeKey1,
×
2392
                arg.NodeKey2,
×
2393
        )
×
2394
        return err
×
2395
}
×
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