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

lightningnetwork / lnd / 15973895448

30 Jun 2025 01:12PM UTC coverage: 67.627% (+0.05%) from 67.577%
15973895448

Pull #10007

github

web-flow
Merge a10fe7711 into 01dfee6f8
Pull Request #10007: graph/db: explicitly store bitfields for channel_update message & channel flags

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

40 existing lines in 12 files now uncovered.

135274 of 200031 relevant lines covered (67.63%)

21833.89 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 deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
248
DELETE FROM zombie_channels
249
WHERE scid = $1
250
AND version = $2
251
`
252

253
type DeleteZombieChannelParams struct {
254
        Scid    []byte
255
        Version int16
256
}
257

258
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
259
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
260
}
×
261

262
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
263
SELECT
264
    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,
265
    n1.pub_key AS node1_pub_key,
266
    n2.pub_key AS node2_pub_key
267
FROM channels c
268
    JOIN nodes n1 ON c.node_id_1 = n1.id
269
    JOIN nodes n2 ON c.node_id_2 = n2.id
270
WHERE c.scid = $1
271
  AND c.version = $2
272
`
273

274
type GetChannelAndNodesBySCIDParams struct {
275
        Scid    []byte
276
        Version int16
277
}
278

279
type GetChannelAndNodesBySCIDRow struct {
280
        ID                int64
281
        Version           int16
282
        Scid              []byte
283
        NodeID1           int64
284
        NodeID2           int64
285
        Outpoint          string
286
        Capacity          sql.NullInt64
287
        BitcoinKey1       []byte
288
        BitcoinKey2       []byte
289
        Node1Signature    []byte
290
        Node2Signature    []byte
291
        Bitcoin1Signature []byte
292
        Bitcoin2Signature []byte
293
        Node1PubKey       []byte
294
        Node2PubKey       []byte
295
}
296

297
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
298
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
299
        var i GetChannelAndNodesBySCIDRow
×
300
        err := row.Scan(
×
301
                &i.ID,
×
302
                &i.Version,
×
303
                &i.Scid,
×
304
                &i.NodeID1,
×
305
                &i.NodeID2,
×
306
                &i.Outpoint,
×
307
                &i.Capacity,
×
308
                &i.BitcoinKey1,
×
309
                &i.BitcoinKey2,
×
310
                &i.Node1Signature,
×
311
                &i.Node2Signature,
×
312
                &i.Bitcoin1Signature,
×
313
                &i.Bitcoin2Signature,
×
314
                &i.Node1PubKey,
×
315
                &i.Node2PubKey,
×
316
        )
×
317
        return i, err
×
318
}
×
319

320
const getChannelByOutpoint = `-- name: GetChannelByOutpoint :one
321
SELECT
322
    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,
323
    n1.pub_key AS node1_pubkey,
324
    n2.pub_key AS node2_pubkey
325
FROM channels c
326
    JOIN nodes n1 ON c.node_id_1 = n1.id
327
    JOIN nodes n2 ON c.node_id_2 = n2.id
328
WHERE c.outpoint = $1
329
`
330

331
type GetChannelByOutpointRow struct {
332
        Channel     Channel
333
        Node1Pubkey []byte
334
        Node2Pubkey []byte
335
}
336

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

360
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :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

364
    n1.pub_key AS node1_pubkey,
365
    n2.pub_key AS node2_pubkey,
366

367
    -- Node 1 policy
368
    cp1.id AS policy_1_id,
369
    cp1.node_id AS policy_1_node_id,
370
    cp1.version AS policy_1_version,
371
    cp1.timelock AS policy_1_timelock,
372
    cp1.fee_ppm AS policy_1_fee_ppm,
373
    cp1.base_fee_msat AS policy_1_base_fee_msat,
374
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
375
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
376
    cp1.last_update AS policy_1_last_update,
377
    cp1.disabled AS policy_1_disabled,
378
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
379
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
380
    cp1.message_flags AS policy_1_message_flags,
381
    cp1.channel_flags AS policy_1_channel_flags,
382
    cp1.signature AS policy_1_signature,
383

384
    -- Node 2 policy
385
    cp2.id AS policy_2_id,
386
    cp2.node_id AS policy_2_node_id,
387
    cp2.version AS policy_2_version,
388
    cp2.timelock AS policy_2_timelock,
389
    cp2.fee_ppm AS policy_2_fee_ppm,
390
    cp2.base_fee_msat AS policy_2_base_fee_msat,
391
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
392
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
393
    cp2.last_update AS policy_2_last_update,
394
    cp2.disabled AS policy_2_disabled,
395
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
396
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
397
    cp2.message_flags AS policy_2_message_flags,
398
    cp2.channel_flags AS policy_2_channel_flags,
399
    cp2.signature AS policy_2_signature
400
FROM channels c
401
    JOIN nodes n1 ON c.node_id_1 = n1.id
402
    JOIN nodes n2 ON c.node_id_2 = n2.id
403
    LEFT JOIN channel_policies cp1
404
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
405
    LEFT JOIN channel_policies cp2
406
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
407
WHERE c.outpoint = $1 AND c.version = $2
408
`
409

410
type GetChannelByOutpointWithPoliciesParams struct {
411
        Outpoint string
412
        Version  int16
413
}
414

415
type GetChannelByOutpointWithPoliciesRow struct {
416
        Channel                        Channel
417
        Node1Pubkey                    []byte
418
        Node2Pubkey                    []byte
419
        Policy1ID                      sql.NullInt64
420
        Policy1NodeID                  sql.NullInt64
421
        Policy1Version                 sql.NullInt16
422
        Policy1Timelock                sql.NullInt32
423
        Policy1FeePpm                  sql.NullInt64
424
        Policy1BaseFeeMsat             sql.NullInt64
425
        Policy1MinHtlcMsat             sql.NullInt64
426
        Policy1MaxHtlcMsat             sql.NullInt64
427
        Policy1LastUpdate              sql.NullInt64
428
        Policy1Disabled                sql.NullBool
429
        Policy1InboundBaseFeeMsat      sql.NullInt64
430
        Policy1InboundFeeRateMilliMsat sql.NullInt64
431
        Policy1MessageFlags            sql.NullInt16
432
        Policy1ChannelFlags            sql.NullInt16
433
        Policy1Signature               []byte
434
        Policy2ID                      sql.NullInt64
435
        Policy2NodeID                  sql.NullInt64
436
        Policy2Version                 sql.NullInt16
437
        Policy2Timelock                sql.NullInt32
438
        Policy2FeePpm                  sql.NullInt64
439
        Policy2BaseFeeMsat             sql.NullInt64
440
        Policy2MinHtlcMsat             sql.NullInt64
441
        Policy2MaxHtlcMsat             sql.NullInt64
442
        Policy2LastUpdate              sql.NullInt64
443
        Policy2Disabled                sql.NullBool
444
        Policy2InboundBaseFeeMsat      sql.NullInt64
445
        Policy2InboundFeeRateMilliMsat sql.NullInt64
446
        Policy2MessageFlags            sql.NullInt16
447
        Policy2ChannelFlags            sql.NullInt16
448
        Policy2Signature               []byte
449
}
450

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

504
const getChannelBySCID = `-- name: GetChannelBySCID :one
505
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
506
WHERE scid = $1 AND version = $2
507
`
508

509
type GetChannelBySCIDParams struct {
510
        Scid    []byte
511
        Version int16
512
}
513

514
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
515
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
516
        var i Channel
×
517
        err := row.Scan(
×
518
                &i.ID,
×
519
                &i.Version,
×
520
                &i.Scid,
×
521
                &i.NodeID1,
×
522
                &i.NodeID2,
×
523
                &i.Outpoint,
×
524
                &i.Capacity,
×
525
                &i.BitcoinKey1,
×
526
                &i.BitcoinKey2,
×
527
                &i.Node1Signature,
×
528
                &i.Node2Signature,
×
529
                &i.Bitcoin1Signature,
×
530
                &i.Bitcoin2Signature,
×
531
        )
×
532
        return i, err
×
533
}
×
534

535
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
536
SELECT
537
    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,
538
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
539
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
540

541
    -- Policy 1
542
    cp1.id AS policy1_id,
543
    cp1.node_id AS policy1_node_id,
544
    cp1.version AS policy1_version,
545
    cp1.timelock AS policy1_timelock,
546
    cp1.fee_ppm AS policy1_fee_ppm,
547
    cp1.base_fee_msat AS policy1_base_fee_msat,
548
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
549
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
550
    cp1.last_update AS policy1_last_update,
551
    cp1.disabled AS policy1_disabled,
552
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
553
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
554
    cp1.message_flags AS policy1_message_flags,
555
    cp1.channel_flags AS policy1_channel_flags,
556
    cp1.signature AS policy1_signature,
557

558
    -- Policy 2
559
    cp2.id AS policy2_id,
560
    cp2.node_id AS policy2_node_id,
561
    cp2.version AS policy2_version,
562
    cp2.timelock AS policy2_timelock,
563
    cp2.fee_ppm AS policy2_fee_ppm,
564
    cp2.base_fee_msat AS policy2_base_fee_msat,
565
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
566
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
567
    cp2.last_update AS policy2_last_update,
568
    cp2.disabled AS policy2_disabled,
569
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
570
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
571
    cp2.message_flags AS policy_2_message_flags,
572
    cp2.channel_flags AS policy_2_channel_flags,
573
    cp2.signature AS policy2_signature
574

575
FROM channels c
576
    JOIN nodes n1 ON c.node_id_1 = n1.id
577
    JOIN nodes n2 ON c.node_id_2 = n2.id
578
    LEFT JOIN channel_policies cp1
579
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
580
    LEFT JOIN channel_policies cp2
581
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
582
WHERE c.scid = $1
583
  AND c.version = $2
584
`
585

586
type GetChannelBySCIDWithPoliciesParams struct {
587
        Scid    []byte
588
        Version int16
589
}
590

591
type GetChannelBySCIDWithPoliciesRow struct {
592
        Channel                        Channel
593
        Node                           Node
594
        Node_2                         Node
595
        Policy1ID                      sql.NullInt64
596
        Policy1NodeID                  sql.NullInt64
597
        Policy1Version                 sql.NullInt16
598
        Policy1Timelock                sql.NullInt32
599
        Policy1FeePpm                  sql.NullInt64
600
        Policy1BaseFeeMsat             sql.NullInt64
601
        Policy1MinHtlcMsat             sql.NullInt64
602
        Policy1MaxHtlcMsat             sql.NullInt64
603
        Policy1LastUpdate              sql.NullInt64
604
        Policy1Disabled                sql.NullBool
605
        Policy1InboundBaseFeeMsat      sql.NullInt64
606
        Policy1InboundFeeRateMilliMsat sql.NullInt64
607
        Policy1MessageFlags            sql.NullInt16
608
        Policy1ChannelFlags            sql.NullInt16
609
        Policy1Signature               []byte
610
        Policy2ID                      sql.NullInt64
611
        Policy2NodeID                  sql.NullInt64
612
        Policy2Version                 sql.NullInt16
613
        Policy2Timelock                sql.NullInt32
614
        Policy2FeePpm                  sql.NullInt64
615
        Policy2BaseFeeMsat             sql.NullInt64
616
        Policy2MinHtlcMsat             sql.NullInt64
617
        Policy2MaxHtlcMsat             sql.NullInt64
618
        Policy2LastUpdate              sql.NullInt64
619
        Policy2Disabled                sql.NullBool
620
        Policy2InboundBaseFeeMsat      sql.NullInt64
621
        Policy2InboundFeeRateMilliMsat sql.NullInt64
622
        Policy2MessageFlags            sql.NullInt16
623
        Policy2ChannelFlags            sql.NullInt16
624
        Policy2Signature               []byte
625
}
626

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

692
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
693
SELECT
694
    cf.channel_id,
695
    true AS is_feature,
696
    cf.feature_bit AS feature_bit,
697
    NULL AS extra_key,
698
    NULL AS value
699
FROM channel_features cf
700
WHERE cf.channel_id = $1
701

702
UNION ALL
703

704
SELECT
705
    cet.channel_id,
706
    false AS is_feature,
707
    0 AS feature_bit,
708
    cet.type AS extra_key,
709
    cet.value AS value
710
FROM channel_extra_types cet
711
WHERE cet.channel_id = $1
712
`
713

714
type GetChannelFeaturesAndExtrasRow struct {
715
        ChannelID  int64
716
        IsFeature  bool
717
        FeatureBit int32
718
        ExtraKey   interface{}
719
        Value      interface{}
720
}
721

722
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
723
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
724
        if err != nil {
×
725
                return nil, err
×
726
        }
×
727
        defer rows.Close()
×
728
        var items []GetChannelFeaturesAndExtrasRow
×
729
        for rows.Next() {
×
730
                var i GetChannelFeaturesAndExtrasRow
×
731
                if err := rows.Scan(
×
732
                        &i.ChannelID,
×
733
                        &i.IsFeature,
×
734
                        &i.FeatureBit,
×
735
                        &i.ExtraKey,
×
736
                        &i.Value,
×
737
                ); err != nil {
×
738
                        return nil, err
×
739
                }
×
740
                items = append(items, i)
×
741
        }
742
        if err := rows.Close(); err != nil {
×
743
                return nil, err
×
744
        }
×
745
        if err := rows.Err(); err != nil {
×
746
                return nil, err
×
747
        }
×
748
        return items, nil
×
749
}
750

751
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
752
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
753
FROM channel_policies
754
WHERE channel_id = $1
755
  AND node_id = $2
756
  AND version = $3
757
`
758

759
type GetChannelPolicyByChannelAndNodeParams struct {
760
        ChannelID int64
761
        NodeID    int64
762
        Version   int16
763
}
764

765
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) {
×
766
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
767
        var i ChannelPolicy
×
768
        err := row.Scan(
×
769
                &i.ID,
×
770
                &i.Version,
×
771
                &i.ChannelID,
×
772
                &i.NodeID,
×
773
                &i.Timelock,
×
774
                &i.FeePpm,
×
775
                &i.BaseFeeMsat,
×
776
                &i.MinHtlcMsat,
×
777
                &i.MaxHtlcMsat,
×
778
                &i.LastUpdate,
×
779
                &i.Disabled,
×
780
                &i.InboundBaseFeeMsat,
×
781
                &i.InboundFeeRateMilliMsat,
×
NEW
782
                &i.MessageFlags,
×
NEW
783
                &i.ChannelFlags,
×
784
                &i.Signature,
×
785
        )
×
786
        return i, err
×
787
}
×
788

789
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
790
SELECT
791
    cp.id AS policy_id,
792
    cp.channel_id,
793
    cp.node_id,
794
    cpet.type,
795
    cpet.value
796
FROM channel_policies cp
797
JOIN channel_policy_extra_types cpet
798
ON cp.id = cpet.channel_policy_id
799
WHERE cp.id = $1 OR cp.id = $2
800
`
801

802
type GetChannelPolicyExtraTypesParams struct {
803
        ID   int64
804
        ID_2 int64
805
}
806

807
type GetChannelPolicyExtraTypesRow struct {
808
        PolicyID  int64
809
        ChannelID int64
810
        NodeID    int64
811
        Type      int64
812
        Value     []byte
813
}
814

815
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
816
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
817
        if err != nil {
×
818
                return nil, err
×
819
        }
×
820
        defer rows.Close()
×
821
        var items []GetChannelPolicyExtraTypesRow
×
822
        for rows.Next() {
×
823
                var i GetChannelPolicyExtraTypesRow
×
824
                if err := rows.Scan(
×
825
                        &i.PolicyID,
×
826
                        &i.ChannelID,
×
827
                        &i.NodeID,
×
828
                        &i.Type,
×
829
                        &i.Value,
×
830
                ); err != nil {
×
831
                        return nil, err
×
832
                }
×
833
                items = append(items, i)
×
834
        }
835
        if err := rows.Close(); err != nil {
×
836
                return nil, err
×
837
        }
×
838
        if err := rows.Err(); err != nil {
×
839
                return nil, err
×
840
        }
×
841
        return items, nil
×
842
}
843

844
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
845
SELECT
846
    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,
847
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
848
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
849

850
    -- Policy 1 (node_id_1)
851
    cp1.id AS policy1_id,
852
    cp1.node_id AS policy1_node_id,
853
    cp1.version AS policy1_version,
854
    cp1.timelock AS policy1_timelock,
855
    cp1.fee_ppm AS policy1_fee_ppm,
856
    cp1.base_fee_msat AS policy1_base_fee_msat,
857
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
858
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
859
    cp1.last_update AS policy1_last_update,
860
    cp1.disabled AS policy1_disabled,
861
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
862
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
863
    cp1.message_flags AS policy1_message_flags,
864
    cp1.channel_flags AS policy1_channel_flags,
865
    cp1.signature AS policy1_signature,
866

867
    -- Policy 2 (node_id_2)
868
    cp2.id AS policy2_id,
869
    cp2.node_id AS policy2_node_id,
870
    cp2.version AS policy2_version,
871
    cp2.timelock AS policy2_timelock,
872
    cp2.fee_ppm AS policy2_fee_ppm,
873
    cp2.base_fee_msat AS policy2_base_fee_msat,
874
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
875
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
876
    cp2.last_update AS policy2_last_update,
877
    cp2.disabled AS policy2_disabled,
878
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
879
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
880
    cp2.message_flags AS policy2_message_flags,
881
    cp2.channel_flags AS policy2_channel_flags,
882
    cp2.signature AS policy2_signature
883

884
FROM channels c
885
    JOIN nodes n1 ON c.node_id_1 = n1.id
886
    JOIN nodes n2 ON c.node_id_2 = n2.id
887
    LEFT JOIN channel_policies cp1
888
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
889
    LEFT JOIN channel_policies cp2
890
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
891
WHERE c.version = $1
892
  AND (
893
       (cp1.last_update >= $2 AND cp1.last_update < $3)
894
       OR
895
       (cp2.last_update >= $2 AND cp2.last_update < $3)
896
  )
897
ORDER BY
898
    CASE
899
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
900
            THEN COALESCE(cp1.last_update, 0)
901
        ELSE COALESCE(cp2.last_update, 0)
902
        END ASC
903
`
904

905
type GetChannelsByPolicyLastUpdateRangeParams struct {
906
        Version   int16
907
        StartTime sql.NullInt64
908
        EndTime   sql.NullInt64
909
}
910

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

947
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
948
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
949
        if err != nil {
×
950
                return nil, err
×
951
        }
×
952
        defer rows.Close()
×
953
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
954
        for rows.Next() {
×
955
                var i GetChannelsByPolicyLastUpdateRangeRow
×
956
                if err := rows.Scan(
×
957
                        &i.Channel.ID,
×
958
                        &i.Channel.Version,
×
959
                        &i.Channel.Scid,
×
960
                        &i.Channel.NodeID1,
×
961
                        &i.Channel.NodeID2,
×
962
                        &i.Channel.Outpoint,
×
963
                        &i.Channel.Capacity,
×
964
                        &i.Channel.BitcoinKey1,
×
965
                        &i.Channel.BitcoinKey2,
×
966
                        &i.Channel.Node1Signature,
×
967
                        &i.Channel.Node2Signature,
×
968
                        &i.Channel.Bitcoin1Signature,
×
969
                        &i.Channel.Bitcoin2Signature,
×
970
                        &i.Node.ID,
×
971
                        &i.Node.Version,
×
972
                        &i.Node.PubKey,
×
973
                        &i.Node.Alias,
×
974
                        &i.Node.LastUpdate,
×
975
                        &i.Node.Color,
×
976
                        &i.Node.Signature,
×
977
                        &i.Node_2.ID,
×
978
                        &i.Node_2.Version,
×
979
                        &i.Node_2.PubKey,
×
980
                        &i.Node_2.Alias,
×
981
                        &i.Node_2.LastUpdate,
×
982
                        &i.Node_2.Color,
×
983
                        &i.Node_2.Signature,
×
984
                        &i.Policy1ID,
×
985
                        &i.Policy1NodeID,
×
986
                        &i.Policy1Version,
×
987
                        &i.Policy1Timelock,
×
988
                        &i.Policy1FeePpm,
×
989
                        &i.Policy1BaseFeeMsat,
×
990
                        &i.Policy1MinHtlcMsat,
×
991
                        &i.Policy1MaxHtlcMsat,
×
992
                        &i.Policy1LastUpdate,
×
993
                        &i.Policy1Disabled,
×
994
                        &i.Policy1InboundBaseFeeMsat,
×
995
                        &i.Policy1InboundFeeRateMilliMsat,
×
NEW
996
                        &i.Policy1MessageFlags,
×
NEW
997
                        &i.Policy1ChannelFlags,
×
998
                        &i.Policy1Signature,
×
999
                        &i.Policy2ID,
×
1000
                        &i.Policy2NodeID,
×
1001
                        &i.Policy2Version,
×
1002
                        &i.Policy2Timelock,
×
1003
                        &i.Policy2FeePpm,
×
1004
                        &i.Policy2BaseFeeMsat,
×
1005
                        &i.Policy2MinHtlcMsat,
×
1006
                        &i.Policy2MaxHtlcMsat,
×
1007
                        &i.Policy2LastUpdate,
×
1008
                        &i.Policy2Disabled,
×
1009
                        &i.Policy2InboundBaseFeeMsat,
×
1010
                        &i.Policy2InboundFeeRateMilliMsat,
×
NEW
1011
                        &i.Policy2MessageFlags,
×
NEW
1012
                        &i.Policy2ChannelFlags,
×
1013
                        &i.Policy2Signature,
×
1014
                ); err != nil {
×
1015
                        return nil, err
×
1016
                }
×
1017
                items = append(items, i)
×
1018
        }
1019
        if err := rows.Close(); err != nil {
×
1020
                return nil, err
×
1021
        }
×
1022
        if err := rows.Err(); err != nil {
×
1023
                return nil, err
×
1024
        }
×
1025
        return items, nil
×
1026
}
1027

1028
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1029
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,
1030
    n1.pub_key AS node1_pub_key,
1031
    n2.pub_key AS node2_pub_key
1032
FROM channels c
1033
    JOIN nodes n1 ON c.node_id_1 = n1.id
1034
    JOIN nodes n2 ON c.node_id_2 = n2.id
1035
WHERE scid >= $1
1036
  AND scid < $2
1037
`
1038

1039
type GetChannelsBySCIDRangeParams struct {
1040
        StartScid []byte
1041
        EndScid   []byte
1042
}
1043

1044
type GetChannelsBySCIDRangeRow struct {
1045
        Channel     Channel
1046
        Node1PubKey []byte
1047
        Node2PubKey []byte
1048
}
1049

1050
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1051
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1052
        if err != nil {
×
1053
                return nil, err
×
1054
        }
×
1055
        defer rows.Close()
×
1056
        var items []GetChannelsBySCIDRangeRow
×
1057
        for rows.Next() {
×
1058
                var i GetChannelsBySCIDRangeRow
×
1059
                if err := rows.Scan(
×
1060
                        &i.Channel.ID,
×
1061
                        &i.Channel.Version,
×
1062
                        &i.Channel.Scid,
×
1063
                        &i.Channel.NodeID1,
×
1064
                        &i.Channel.NodeID2,
×
1065
                        &i.Channel.Outpoint,
×
1066
                        &i.Channel.Capacity,
×
1067
                        &i.Channel.BitcoinKey1,
×
1068
                        &i.Channel.BitcoinKey2,
×
1069
                        &i.Channel.Node1Signature,
×
1070
                        &i.Channel.Node2Signature,
×
1071
                        &i.Channel.Bitcoin1Signature,
×
1072
                        &i.Channel.Bitcoin2Signature,
×
1073
                        &i.Node1PubKey,
×
1074
                        &i.Node2PubKey,
×
1075
                ); err != nil {
×
1076
                        return nil, err
×
1077
                }
×
1078
                items = append(items, i)
×
1079
        }
1080
        if err := rows.Close(); err != nil {
×
1081
                return nil, err
×
1082
        }
×
1083
        if err := rows.Err(); err != nil {
×
1084
                return nil, err
×
1085
        }
×
1086
        return items, nil
×
1087
}
1088

1089
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1090
SELECT node_id, type, value
1091
FROM node_extra_types
1092
WHERE node_id = $1
1093
`
1094

1095
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
1096
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1097
        if err != nil {
×
1098
                return nil, err
×
1099
        }
×
1100
        defer rows.Close()
×
1101
        var items []NodeExtraType
×
1102
        for rows.Next() {
×
1103
                var i NodeExtraType
×
1104
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1105
                        return nil, err
×
1106
                }
×
1107
                items = append(items, i)
×
1108
        }
1109
        if err := rows.Close(); err != nil {
×
1110
                return nil, err
×
1111
        }
×
1112
        if err := rows.Err(); err != nil {
×
1113
                return nil, err
×
1114
        }
×
1115
        return items, nil
×
1116
}
1117

1118
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
1119
SELECT a.type, a.address
1120
FROM nodes n
1121
LEFT JOIN node_addresses a ON a.node_id = n.id
1122
WHERE n.pub_key = $1 AND n.version = $2
1123
ORDER BY a.type ASC, a.position ASC
1124
`
1125

1126
type GetNodeAddressesByPubKeyParams struct {
1127
        PubKey  []byte
1128
        Version int16
1129
}
1130

1131
type GetNodeAddressesByPubKeyRow struct {
1132
        Type    sql.NullInt16
1133
        Address sql.NullString
1134
}
1135

1136
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
1137
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
1138
        if err != nil {
×
1139
                return nil, err
×
1140
        }
×
1141
        defer rows.Close()
×
1142
        var items []GetNodeAddressesByPubKeyRow
×
1143
        for rows.Next() {
×
1144
                var i GetNodeAddressesByPubKeyRow
×
1145
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1146
                        return nil, err
×
1147
                }
×
1148
                items = append(items, i)
×
1149
        }
1150
        if err := rows.Close(); err != nil {
×
1151
                return nil, err
×
1152
        }
×
1153
        if err := rows.Err(); err != nil {
×
1154
                return nil, err
×
1155
        }
×
1156
        return items, nil
×
1157
}
1158

1159
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1160
SELECT id, version, pub_key, alias, last_update, color, signature
1161
FROM nodes
1162
WHERE pub_key = $1
1163
  AND version = $2
1164
`
1165

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

1171
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
1172
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1173
        var i Node
×
1174
        err := row.Scan(
×
1175
                &i.ID,
×
1176
                &i.Version,
×
1177
                &i.PubKey,
×
1178
                &i.Alias,
×
1179
                &i.LastUpdate,
×
1180
                &i.Color,
×
1181
                &i.Signature,
×
1182
        )
×
1183
        return i, err
×
1184
}
×
1185

1186
const getNodeFeatures = `-- name: GetNodeFeatures :many
1187
SELECT node_id, feature_bit
1188
FROM node_features
1189
WHERE node_id = $1
1190
`
1191

1192
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
1193
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1194
        if err != nil {
×
1195
                return nil, err
×
1196
        }
×
1197
        defer rows.Close()
×
1198
        var items []NodeFeature
×
1199
        for rows.Next() {
×
1200
                var i NodeFeature
×
1201
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1202
                        return nil, err
×
1203
                }
×
1204
                items = append(items, i)
×
1205
        }
1206
        if err := rows.Close(); err != nil {
×
1207
                return nil, err
×
1208
        }
×
1209
        if err := rows.Err(); err != nil {
×
1210
                return nil, err
×
1211
        }
×
1212
        return items, nil
×
1213
}
1214

1215
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1216
SELECT f.feature_bit
1217
FROM nodes n
1218
    JOIN node_features f ON f.node_id = n.id
1219
WHERE n.pub_key = $1
1220
  AND n.version = $2
1221
`
1222

1223
type GetNodeFeaturesByPubKeyParams struct {
1224
        PubKey  []byte
1225
        Version int16
1226
}
1227

1228
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1229
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1230
        if err != nil {
×
1231
                return nil, err
×
1232
        }
×
1233
        defer rows.Close()
×
1234
        var items []int32
×
1235
        for rows.Next() {
×
1236
                var feature_bit int32
×
1237
                if err := rows.Scan(&feature_bit); err != nil {
×
1238
                        return nil, err
×
1239
                }
×
1240
                items = append(items, feature_bit)
×
1241
        }
1242
        if err := rows.Close(); err != nil {
×
1243
                return nil, err
×
1244
        }
×
1245
        if err := rows.Err(); err != nil {
×
1246
                return nil, err
×
1247
        }
×
1248
        return items, nil
×
1249
}
1250

1251
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1252
SELECT id
1253
FROM nodes
1254
WHERE pub_key = $1
1255
  AND version = $2
1256
`
1257

1258
type GetNodeIDByPubKeyParams struct {
1259
        PubKey  []byte
1260
        Version int16
1261
}
1262

1263
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1264
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1265
        var id int64
×
1266
        err := row.Scan(&id)
×
1267
        return id, err
×
1268
}
×
1269

1270
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1271
SELECT id, version, pub_key, alias, last_update, color, signature
1272
FROM nodes
1273
WHERE last_update >= $1
1274
  AND last_update < $2
1275
`
1276

1277
type GetNodesByLastUpdateRangeParams struct {
1278
        StartTime sql.NullInt64
1279
        EndTime   sql.NullInt64
1280
}
1281

1282
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
1283
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1284
        if err != nil {
×
1285
                return nil, err
×
1286
        }
×
1287
        defer rows.Close()
×
1288
        var items []Node
×
1289
        for rows.Next() {
×
1290
                var i Node
×
1291
                if err := rows.Scan(
×
1292
                        &i.ID,
×
1293
                        &i.Version,
×
1294
                        &i.PubKey,
×
1295
                        &i.Alias,
×
1296
                        &i.LastUpdate,
×
1297
                        &i.Color,
×
1298
                        &i.Signature,
×
1299
                ); err != nil {
×
1300
                        return nil, err
×
1301
                }
×
1302
                items = append(items, i)
×
1303
        }
1304
        if err := rows.Close(); err != nil {
×
1305
                return nil, err
×
1306
        }
×
1307
        if err := rows.Err(); err != nil {
×
1308
                return nil, err
×
1309
        }
×
1310
        return items, nil
×
1311
}
1312

1313
const getPruneTip = `-- name: GetPruneTip :one
1314
SELECT block_height, block_hash
1315
FROM prune_log
1316
ORDER BY block_height DESC
1317
LIMIT 1
1318
`
1319

1320
func (q *Queries) GetPruneTip(ctx context.Context) (PruneLog, error) {
×
1321
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1322
        var i PruneLog
×
1323
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1324
        return i, err
×
1325
}
×
1326

1327
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1328
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
1329
FROM channels
1330
WHERE node_1_signature IS NOT NULL
1331
  AND scid >= $1
1332
  AND scid < $2
1333
`
1334

1335
type GetPublicV1ChannelsBySCIDParams struct {
1336
        StartScid []byte
1337
        EndScid   []byte
1338
}
1339

1340
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
×
1341
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1342
        if err != nil {
×
1343
                return nil, err
×
1344
        }
×
1345
        defer rows.Close()
×
1346
        var items []Channel
×
1347
        for rows.Next() {
×
1348
                var i Channel
×
1349
                if err := rows.Scan(
×
1350
                        &i.ID,
×
1351
                        &i.Version,
×
1352
                        &i.Scid,
×
1353
                        &i.NodeID1,
×
1354
                        &i.NodeID2,
×
1355
                        &i.Outpoint,
×
1356
                        &i.Capacity,
×
1357
                        &i.BitcoinKey1,
×
1358
                        &i.BitcoinKey2,
×
1359
                        &i.Node1Signature,
×
1360
                        &i.Node2Signature,
×
1361
                        &i.Bitcoin1Signature,
×
1362
                        &i.Bitcoin2Signature,
×
1363
                ); err != nil {
×
1364
                        return nil, err
×
1365
                }
×
1366
                items = append(items, i)
×
1367
        }
1368
        if err := rows.Close(); err != nil {
×
1369
                return nil, err
×
1370
        }
×
1371
        if err := rows.Err(); err != nil {
×
1372
                return nil, err
×
1373
        }
×
1374
        return items, nil
×
1375
}
1376

1377
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1378
SELECT scid from channels
1379
WHERE outpoint = $1 AND version = $2
1380
`
1381

1382
type GetSCIDByOutpointParams struct {
1383
        Outpoint string
1384
        Version  int16
1385
}
1386

1387
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1388
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1389
        var scid []byte
×
1390
        err := row.Scan(&scid)
×
1391
        return scid, err
×
1392
}
×
1393

1394
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1395
SELECT sn.node_id, n.pub_key
1396
FROM source_nodes sn
1397
    JOIN nodes n ON sn.node_id = n.id
1398
WHERE n.version = $1
1399
`
1400

1401
type GetSourceNodesByVersionRow struct {
1402
        NodeID int64
1403
        PubKey []byte
1404
}
1405

1406
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1407
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1408
        if err != nil {
×
1409
                return nil, err
×
1410
        }
×
1411
        defer rows.Close()
×
1412
        var items []GetSourceNodesByVersionRow
×
1413
        for rows.Next() {
×
1414
                var i GetSourceNodesByVersionRow
×
1415
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1416
                        return nil, err
×
1417
                }
×
1418
                items = append(items, i)
×
1419
        }
1420
        if err := rows.Close(); err != nil {
×
1421
                return nil, err
×
1422
        }
×
1423
        if err := rows.Err(); err != nil {
×
1424
                return nil, err
×
1425
        }
×
1426
        return items, nil
×
1427
}
1428

1429
const getUnconnectedNodes = `-- name: GetUnconnectedNodes :many
1430
SELECT n.id, n.pub_key
1431
FROM nodes n
1432
WHERE NOT EXISTS (
1433
    SELECT 1
1434
    FROM channels c
1435
    WHERE c.node_id_1 = n.id OR c.node_id_2 = n.id
1436
)
1437
AND NOT EXISTS (
1438
    SELECT 1
1439
    FROM source_nodes sn
1440
    WHERE sn.node_id = n.id
1441
)
1442
`
1443

1444
type GetUnconnectedNodesRow struct {
1445
        ID     int64
1446
        PubKey []byte
1447
}
1448

1449
// Select all nodes that do not have any channels.
1450
// Ignore any of our source nodes.
1451
func (q *Queries) GetUnconnectedNodes(ctx context.Context) ([]GetUnconnectedNodesRow, error) {
×
1452
        rows, err := q.db.QueryContext(ctx, getUnconnectedNodes)
×
1453
        if err != nil {
×
1454
                return nil, err
×
1455
        }
×
1456
        defer rows.Close()
×
1457
        var items []GetUnconnectedNodesRow
×
1458
        for rows.Next() {
×
1459
                var i GetUnconnectedNodesRow
×
1460
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
1461
                        return nil, err
×
1462
                }
×
1463
                items = append(items, i)
×
1464
        }
1465
        if err := rows.Close(); err != nil {
×
1466
                return nil, err
×
1467
        }
×
1468
        if err := rows.Err(); err != nil {
×
1469
                return nil, err
×
1470
        }
×
1471
        return items, nil
×
1472
}
1473

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

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

1511
const getZombieChannel = `-- name: GetZombieChannel :one
1512
SELECT scid, version, node_key_1, node_key_2
1513
FROM zombie_channels
1514
WHERE scid = $1
1515
AND version = $2
1516
`
1517

1518
type GetZombieChannelParams struct {
1519
        Scid    []byte
1520
        Version int16
1521
}
1522

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

1535
const highestSCID = `-- name: HighestSCID :one
1536
SELECT scid
1537
FROM channels
1538
WHERE version = $1
1539
ORDER BY scid DESC
1540
LIMIT 1
1541
`
1542

1543
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1544
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1545
        var scid []byte
×
1546
        err := row.Scan(&scid)
×
1547
        return scid, err
×
1548
}
×
1549

1550
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1551
/* ─────────────────────────────────────────────
1552
   channel_policy_extra_types table queries
1553
   ─────────────────────────────────────────────
1554
*/
1555

1556
INSERT INTO channel_policy_extra_types (
1557
    channel_policy_id, type, value
1558
)
1559
VALUES ($1, $2, $3)
1560
`
1561

1562
type InsertChanPolicyExtraTypeParams struct {
1563
        ChannelPolicyID int64
1564
        Type            int64
1565
        Value           []byte
1566
}
1567

1568
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1569
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1570
        return err
×
1571
}
×
1572

1573
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1574
/* ─────────────────────────────────────────────
1575
   channel_features table queries
1576
   ─────────────────────────────────────────────
1577
*/
1578

1579
INSERT INTO channel_features (
1580
    channel_id, feature_bit
1581
) VALUES (
1582
    $1, $2
1583
)
1584
`
1585

1586
type InsertChannelFeatureParams struct {
1587
        ChannelID  int64
1588
        FeatureBit int32
1589
}
1590

1591
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1592
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1593
        return err
×
1594
}
×
1595

1596
const insertClosedChannel = `-- name: InsertClosedChannel :exec
1597
/* ─────────────────────────────────────────────
1598
   closed_scid table queries
1599
   ────────────────────────────────────────────-
1600
*/
1601

1602
INSERT INTO closed_scids (scid)
1603
VALUES ($1)
1604
ON CONFLICT (scid) DO NOTHING
1605
`
1606

1607
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
1608
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
1609
        return err
×
1610
}
×
1611

1612
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1613
/* ─────────────────────────────────────────────
1614
   node_addresses table queries
1615
   ─────────────────────────────────────────────
1616
*/
1617

1618
INSERT INTO node_addresses (
1619
    node_id,
1620
    type,
1621
    address,
1622
    position
1623
) VALUES (
1624
    $1, $2, $3, $4
1625
 )
1626
`
1627

1628
type InsertNodeAddressParams struct {
1629
        NodeID   int64
1630
        Type     int16
1631
        Address  string
1632
        Position int32
1633
}
1634

1635
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1636
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1637
                arg.NodeID,
×
1638
                arg.Type,
×
1639
                arg.Address,
×
1640
                arg.Position,
×
1641
        )
×
1642
        return err
×
1643
}
×
1644

1645
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1646
/* ─────────────────────────────────────────────
1647
   node_features table queries
1648
   ─────────────────────────────────────────────
1649
*/
1650

1651
INSERT INTO node_features (
1652
    node_id, feature_bit
1653
) VALUES (
1654
    $1, $2
1655
)
1656
`
1657

1658
type InsertNodeFeatureParams struct {
1659
        NodeID     int64
1660
        FeatureBit int32
1661
}
1662

1663
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1664
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1665
        return err
×
1666
}
×
1667

1668
const isClosedChannel = `-- name: IsClosedChannel :one
1669
SELECT EXISTS (
1670
    SELECT 1
1671
    FROM closed_scids
1672
    WHERE scid = $1
1673
)
1674
`
1675

1676
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
1677
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
1678
        var exists bool
×
1679
        err := row.Scan(&exists)
×
1680
        return exists, err
×
1681
}
×
1682

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

1702
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
1703
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
1704
        var exists bool
×
1705
        err := row.Scan(&exists)
×
1706
        return exists, err
×
1707
}
×
1708

1709
const isZombieChannel = `-- name: IsZombieChannel :one
1710
SELECT EXISTS (
1711
    SELECT 1
1712
    FROM zombie_channels
1713
    WHERE scid = $1
1714
    AND version = $2
1715
) AS is_zombie
1716
`
1717

1718
type IsZombieChannelParams struct {
1719
        Scid    []byte
1720
        Version int16
1721
}
1722

1723
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
1724
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
1725
        var is_zombie bool
×
1726
        err := row.Scan(&is_zombie)
×
1727
        return is_zombie, err
×
1728
}
×
1729

1730
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1731
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,
1732
    n1.pub_key AS node1_pubkey,
1733
    n2.pub_key AS node2_pubkey,
1734

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

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

1772
FROM channels c
1773
    JOIN nodes n1 ON c.node_id_1 = n1.id
1774
    JOIN nodes n2 ON c.node_id_2 = n2.id
1775
    LEFT JOIN channel_policies cp1
1776
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1777
    LEFT JOIN channel_policies cp2
1778
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1779
WHERE c.version = $1
1780
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1781
`
1782

1783
type ListChannelsByNodeIDParams struct {
1784
        Version int16
1785
        NodeID1 int64
1786
}
1787

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

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

1893
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
1894
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
1895
FROM channels c
1896
WHERE c.version = $1 AND c.id > $2
1897
ORDER BY c.id
1898
LIMIT $3
1899
`
1900

1901
type ListChannelsPaginatedParams struct {
1902
        Version int16
1903
        ID      int64
1904
        Limit   int32
1905
}
1906

1907
type ListChannelsPaginatedRow struct {
1908
        ID          int64
1909
        BitcoinKey1 []byte
1910
        BitcoinKey2 []byte
1911
        Outpoint    string
1912
}
1913

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

1942
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
1943
SELECT
1944
    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,
1945

1946
    -- Join node pubkeys
1947
    n1.pub_key AS node1_pubkey,
1948
    n2.pub_key AS node2_pubkey,
1949

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

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

1984
FROM channels c
1985
JOIN nodes n1 ON c.node_id_1 = n1.id
1986
JOIN nodes n2 ON c.node_id_2 = n2.id
1987
LEFT JOIN channel_policies cp1
1988
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1989
LEFT JOIN channel_policies cp2
1990
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1991
WHERE c.version = $1 AND c.id > $2
1992
ORDER BY c.id
1993
LIMIT $3
1994
`
1995

1996
type ListChannelsWithPoliciesPaginatedParams struct {
1997
        Version int16
1998
        ID      int64
1999
        Limit   int32
2000
}
2001

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

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

2107
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2108
SELECT id, pub_key
2109
FROM nodes
2110
WHERE version = $1  AND id > $2
2111
ORDER BY id
2112
LIMIT $3
2113
`
2114

2115
type ListNodeIDsAndPubKeysParams struct {
2116
        Version int16
2117
        ID      int64
2118
        Limit   int32
2119
}
2120

2121
type ListNodeIDsAndPubKeysRow struct {
2122
        ID     int64
2123
        PubKey []byte
2124
}
2125

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

2149
const listNodesPaginated = `-- name: ListNodesPaginated :many
2150
SELECT id, version, pub_key, alias, last_update, color, signature
2151
FROM nodes
2152
WHERE version = $1 AND id > $2
2153
ORDER BY id
2154
LIMIT $3
2155
`
2156

2157
type ListNodesPaginatedParams struct {
2158
        Version int16
2159
        ID      int64
2160
        Limit   int32
2161
}
2162

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

2194
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2195
/* ─────────────────────────────────────────────
2196
   channel_policies table queries
2197
   ─────────────────────────────────────────────
2198
*/
2199

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

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

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

2270
const upsertNode = `-- name: UpsertNode :one
2271
/* ─────────────────────────────────────────────
2272
   nodes table queries
2273
   ─────────────────────────────────────────────
2274
*/
2275

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

2294
type UpsertNodeParams struct {
2295
        Version    int16
2296
        PubKey     []byte
2297
        Alias      sql.NullString
2298
        LastUpdate sql.NullInt64
2299
        Color      sql.NullString
2300
        Signature  []byte
2301
}
2302

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

2317
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2318
/* ─────────────────────────────────────────────
2319
   node_extra_types table queries
2320
   ─────────────────────────────────────────────
2321
*/
2322

2323
INSERT INTO node_extra_types (
2324
    node_id, type, value
2325
)
2326
VALUES ($1, $2, $3)
2327
ON CONFLICT (type, node_id)
2328
    -- Update the value if a conflict occurs on type
2329
    -- and node_id.
2330
    DO UPDATE SET value = EXCLUDED.value
2331
`
2332

2333
type UpsertNodeExtraTypeParams struct {
2334
        NodeID int64
2335
        Type   int64
2336
        Value  []byte
2337
}
2338

2339
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2340
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2341
        return err
×
2342
}
×
2343

2344
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2345
/* ─────────────────────────────────────────────
2346
    prune_log table queries
2347
    ─────────────────────────────────────────────
2348
*/
2349

2350
INSERT INTO prune_log (
2351
    block_height, block_hash
2352
) VALUES (
2353
    $1, $2
2354
)
2355
ON CONFLICT(block_height) DO UPDATE SET
2356
    block_hash = EXCLUDED.block_hash
2357
`
2358

2359
type UpsertPruneLogEntryParams struct {
2360
        BlockHeight int64
2361
        BlockHash   []byte
2362
}
2363

2364
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2365
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2366
        return err
×
2367
}
×
2368

2369
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2370
/* ─────────────────────────────────────────────
2371
   zombie_channels table queries
2372
   ─────────────────────────────────────────────
2373
*/
2374

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

2385
type UpsertZombieChannelParams struct {
2386
        Scid     []byte
2387
        Version  int16
2388
        NodeKey1 []byte
2389
        NodeKey2 []byte
2390
}
2391

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