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

lightningnetwork / lnd / 15872517631

25 Jun 2025 09:22AM UTC coverage: 67.648% (-0.2%) from 67.8%
15872517631

Pull #9939

github

web-flow
Merge e875183c4 into 33e6f2854
Pull Request #9939: [15] graph/db: SQL prune log

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

83 existing lines in 18 files now uncovered.

134987 of 199542 relevant lines covered (67.65%)

21930.35 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 countZombieChannels = `-- name: CountZombieChannels :one
30
SELECT COUNT(*)
31
FROM zombie_channels
32
WHERE version = $1
33
`
34

35
func (q *Queries) CountZombieChannels(ctx context.Context, version int16) (int64, error) {
×
36
        row := q.db.QueryRowContext(ctx, countZombieChannels, version)
×
37
        var count int64
×
38
        err := row.Scan(&count)
×
39
        return count, err
×
40
}
×
41

42
const createChannel = `-- name: CreateChannel :one
43
/* ─────────────────────────────────────────────
44
   channels table queries
45
   ─────────────────────────────────────────────
46
*/
47

48
INSERT INTO channels (
49
    version, scid, node_id_1, node_id_2,
50
    outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
51
    node_1_signature, node_2_signature, bitcoin_1_signature,
52
    bitcoin_2_signature
53
) VALUES (
54
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
55
)
56
RETURNING id
57
`
58

59
type CreateChannelParams struct {
60
        Version           int16
61
        Scid              []byte
62
        NodeID1           int64
63
        NodeID2           int64
64
        Outpoint          string
65
        Capacity          sql.NullInt64
66
        BitcoinKey1       []byte
67
        BitcoinKey2       []byte
68
        Node1Signature    []byte
69
        Node2Signature    []byte
70
        Bitcoin1Signature []byte
71
        Bitcoin2Signature []byte
72
}
73

74
func (q *Queries) CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error) {
×
75
        row := q.db.QueryRowContext(ctx, createChannel,
×
76
                arg.Version,
×
77
                arg.Scid,
×
78
                arg.NodeID1,
×
79
                arg.NodeID2,
×
80
                arg.Outpoint,
×
81
                arg.Capacity,
×
82
                arg.BitcoinKey1,
×
83
                arg.BitcoinKey2,
×
84
                arg.Node1Signature,
×
85
                arg.Node2Signature,
×
86
                arg.Bitcoin1Signature,
×
87
                arg.Bitcoin2Signature,
×
88
        )
×
89
        var id int64
×
90
        err := row.Scan(&id)
×
91
        return id, err
×
92
}
×
93

94
const createChannelExtraType = `-- name: CreateChannelExtraType :exec
95
/* ─────────────────────────────────────────────
96
   channel_extra_types table queries
97
   ─────────────────────────────────────────────
98
*/
99

100
INSERT INTO channel_extra_types (
101
    channel_id, type, value
102
)
103
VALUES ($1, $2, $3)
104
`
105

106
type CreateChannelExtraTypeParams struct {
107
        ChannelID int64
108
        Type      int64
109
        Value     []byte
110
}
111

112
func (q *Queries) CreateChannelExtraType(ctx context.Context, arg CreateChannelExtraTypeParams) error {
×
113
        _, err := q.db.ExecContext(ctx, createChannelExtraType, arg.ChannelID, arg.Type, arg.Value)
×
114
        return err
×
115
}
×
116

117
const deleteChannel = `-- name: DeleteChannel :exec
118
DELETE FROM channels WHERE id = $1
119
`
120

121
func (q *Queries) DeleteChannel(ctx context.Context, id int64) error {
×
122
        _, err := q.db.ExecContext(ctx, deleteChannel, id)
×
123
        return err
×
124
}
×
125

126
const deleteChannelPolicyExtraTypes = `-- name: DeleteChannelPolicyExtraTypes :exec
127
DELETE FROM channel_policy_extra_types
128
WHERE channel_policy_id = $1
129
`
130

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

136
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
137
DELETE FROM node_extra_types
138
WHERE node_id = $1
139
  AND type = $2
140
`
141

142
type DeleteExtraNodeTypeParams struct {
143
        NodeID int64
144
        Type   int64
145
}
146

147
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
148
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
149
        return err
×
150
}
×
151

152
const deleteNode = `-- name: DeleteNode :exec
153
DELETE FROM nodes
154
WHERE id = $1
155
`
156

NEW
157
func (q *Queries) DeleteNode(ctx context.Context, id int64) error {
×
NEW
158
        _, err := q.db.ExecContext(ctx, deleteNode, id)
×
NEW
159
        return err
×
NEW
160
}
×
161

162
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
163
DELETE FROM node_addresses
164
WHERE node_id = $1
165
`
166

167
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
168
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
169
        return err
×
170
}
×
171

172
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
173
DELETE FROM nodes
174
WHERE pub_key = $1
175
  AND version = $2
176
`
177

178
type DeleteNodeByPubKeyParams struct {
179
        PubKey  []byte
180
        Version int16
181
}
182

183
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
184
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
185
}
×
186

187
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
188
DELETE FROM node_features
189
WHERE node_id = $1
190
  AND feature_bit = $2
191
`
192

193
type DeleteNodeFeatureParams struct {
194
        NodeID     int64
195
        FeatureBit int32
196
}
197

198
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
199
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
200
        return err
×
201
}
×
202

203
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
204
DELETE FROM prune_log
205
WHERE block_height >= $1
206
  AND block_height <= $2
207
`
208

209
type DeletePruneLogEntriesInRangeParams struct {
210
        StartHeight int64
211
        EndHeight   int64
212
}
213

NEW
214
func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error {
×
NEW
215
        _, err := q.db.ExecContext(ctx, deletePruneLogEntriesInRange, arg.StartHeight, arg.EndHeight)
×
NEW
216
        return err
×
NEW
217
}
×
218

219
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
220
DELETE FROM zombie_channels
221
WHERE scid = $1
222
AND version = $2
223
`
224

225
type DeleteZombieChannelParams struct {
226
        Scid    []byte
227
        Version int16
228
}
229

230
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
231
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
232
}
×
233

234
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
235
SELECT
236
    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,
237
    n1.pub_key AS node1_pub_key,
238
    n2.pub_key AS node2_pub_key
239
FROM channels c
240
    JOIN nodes n1 ON c.node_id_1 = n1.id
241
    JOIN nodes n2 ON c.node_id_2 = n2.id
242
WHERE c.scid = $1
243
  AND c.version = $2
244
`
245

246
type GetChannelAndNodesBySCIDParams struct {
247
        Scid    []byte
248
        Version int16
249
}
250

251
type GetChannelAndNodesBySCIDRow struct {
252
        ID                int64
253
        Version           int16
254
        Scid              []byte
255
        NodeID1           int64
256
        NodeID2           int64
257
        Outpoint          string
258
        Capacity          sql.NullInt64
259
        BitcoinKey1       []byte
260
        BitcoinKey2       []byte
261
        Node1Signature    []byte
262
        Node2Signature    []byte
263
        Bitcoin1Signature []byte
264
        Bitcoin2Signature []byte
265
        Node1PubKey       []byte
266
        Node2PubKey       []byte
267
}
268

269
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
270
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
271
        var i GetChannelAndNodesBySCIDRow
×
272
        err := row.Scan(
×
273
                &i.ID,
×
274
                &i.Version,
×
275
                &i.Scid,
×
276
                &i.NodeID1,
×
277
                &i.NodeID2,
×
278
                &i.Outpoint,
×
279
                &i.Capacity,
×
280
                &i.BitcoinKey1,
×
281
                &i.BitcoinKey2,
×
282
                &i.Node1Signature,
×
283
                &i.Node2Signature,
×
284
                &i.Bitcoin1Signature,
×
285
                &i.Bitcoin2Signature,
×
286
                &i.Node1PubKey,
×
287
                &i.Node2PubKey,
×
288
        )
×
289
        return i, err
×
290
}
×
291

292
const getChannelByOutpoint = `-- name: GetChannelByOutpoint :one
293
SELECT
294
    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,
295
    n1.pub_key AS node1_pubkey,
296
    n2.pub_key AS node2_pubkey
297
FROM channels c
298
    JOIN nodes n1 ON c.node_id_1 = n1.id
299
    JOIN nodes n2 ON c.node_id_2 = n2.id
300
WHERE c.outpoint = $1
301
`
302

303
type GetChannelByOutpointRow struct {
304
        Channel     Channel
305
        Node1Pubkey []byte
306
        Node2Pubkey []byte
307
}
308

NEW
309
func (q *Queries) GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error) {
×
NEW
310
        row := q.db.QueryRowContext(ctx, getChannelByOutpoint, outpoint)
×
NEW
311
        var i GetChannelByOutpointRow
×
NEW
312
        err := row.Scan(
×
NEW
313
                &i.Channel.ID,
×
NEW
314
                &i.Channel.Version,
×
NEW
315
                &i.Channel.Scid,
×
NEW
316
                &i.Channel.NodeID1,
×
NEW
317
                &i.Channel.NodeID2,
×
NEW
318
                &i.Channel.Outpoint,
×
NEW
319
                &i.Channel.Capacity,
×
NEW
320
                &i.Channel.BitcoinKey1,
×
NEW
321
                &i.Channel.BitcoinKey2,
×
NEW
322
                &i.Channel.Node1Signature,
×
NEW
323
                &i.Channel.Node2Signature,
×
NEW
324
                &i.Channel.Bitcoin1Signature,
×
NEW
325
                &i.Channel.Bitcoin2Signature,
×
NEW
326
                &i.Node1Pubkey,
×
NEW
327
                &i.Node2Pubkey,
×
NEW
328
        )
×
NEW
329
        return i, err
×
NEW
330
}
×
331

332
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
333
SELECT
334
    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,
335

336
    n1.pub_key AS node1_pubkey,
337
    n2.pub_key AS node2_pubkey,
338

339
    -- Node 1 policy
340
    cp1.id AS policy_1_id,
341
    cp1.node_id AS policy_1_node_id,
342
    cp1.version AS policy_1_version,
343
    cp1.timelock AS policy_1_timelock,
344
    cp1.fee_ppm AS policy_1_fee_ppm,
345
    cp1.base_fee_msat AS policy_1_base_fee_msat,
346
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
347
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
348
    cp1.last_update AS policy_1_last_update,
349
    cp1.disabled AS policy_1_disabled,
350
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
351
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
352
    cp1.signature AS policy_1_signature,
353

354
    -- Node 2 policy
355
    cp2.id AS policy_2_id,
356
    cp2.node_id AS policy_2_node_id,
357
    cp2.version AS policy_2_version,
358
    cp2.timelock AS policy_2_timelock,
359
    cp2.fee_ppm AS policy_2_fee_ppm,
360
    cp2.base_fee_msat AS policy_2_base_fee_msat,
361
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
362
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
363
    cp2.last_update AS policy_2_last_update,
364
    cp2.disabled AS policy_2_disabled,
365
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
366
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
367
    cp2.signature AS policy_2_signature
368
FROM channels c
369
    JOIN nodes n1 ON c.node_id_1 = n1.id
370
    JOIN nodes n2 ON c.node_id_2 = n2.id
371
    LEFT JOIN channel_policies cp1
372
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
373
    LEFT JOIN channel_policies cp2
374
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
375
WHERE c.outpoint = $1 AND c.version = $2
376
`
377

378
type GetChannelByOutpointWithPoliciesParams struct {
379
        Outpoint string
380
        Version  int16
381
}
382

383
type GetChannelByOutpointWithPoliciesRow struct {
384
        Channel                        Channel
385
        Node1Pubkey                    []byte
386
        Node2Pubkey                    []byte
387
        Policy1ID                      sql.NullInt64
388
        Policy1NodeID                  sql.NullInt64
389
        Policy1Version                 sql.NullInt16
390
        Policy1Timelock                sql.NullInt32
391
        Policy1FeePpm                  sql.NullInt64
392
        Policy1BaseFeeMsat             sql.NullInt64
393
        Policy1MinHtlcMsat             sql.NullInt64
394
        Policy1MaxHtlcMsat             sql.NullInt64
395
        Policy1LastUpdate              sql.NullInt64
396
        Policy1Disabled                sql.NullBool
397
        Policy1InboundBaseFeeMsat      sql.NullInt64
398
        Policy1InboundFeeRateMilliMsat sql.NullInt64
399
        Policy1Signature               []byte
400
        Policy2ID                      sql.NullInt64
401
        Policy2NodeID                  sql.NullInt64
402
        Policy2Version                 sql.NullInt16
403
        Policy2Timelock                sql.NullInt32
404
        Policy2FeePpm                  sql.NullInt64
405
        Policy2BaseFeeMsat             sql.NullInt64
406
        Policy2MinHtlcMsat             sql.NullInt64
407
        Policy2MaxHtlcMsat             sql.NullInt64
408
        Policy2LastUpdate              sql.NullInt64
409
        Policy2Disabled                sql.NullBool
410
        Policy2InboundBaseFeeMsat      sql.NullInt64
411
        Policy2InboundFeeRateMilliMsat sql.NullInt64
412
        Policy2Signature               []byte
413
}
414

415
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
416
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
417
        var i GetChannelByOutpointWithPoliciesRow
×
418
        err := row.Scan(
×
419
                &i.Channel.ID,
×
420
                &i.Channel.Version,
×
421
                &i.Channel.Scid,
×
422
                &i.Channel.NodeID1,
×
423
                &i.Channel.NodeID2,
×
424
                &i.Channel.Outpoint,
×
425
                &i.Channel.Capacity,
×
426
                &i.Channel.BitcoinKey1,
×
427
                &i.Channel.BitcoinKey2,
×
428
                &i.Channel.Node1Signature,
×
429
                &i.Channel.Node2Signature,
×
430
                &i.Channel.Bitcoin1Signature,
×
431
                &i.Channel.Bitcoin2Signature,
×
432
                &i.Node1Pubkey,
×
433
                &i.Node2Pubkey,
×
434
                &i.Policy1ID,
×
435
                &i.Policy1NodeID,
×
436
                &i.Policy1Version,
×
437
                &i.Policy1Timelock,
×
438
                &i.Policy1FeePpm,
×
439
                &i.Policy1BaseFeeMsat,
×
440
                &i.Policy1MinHtlcMsat,
×
441
                &i.Policy1MaxHtlcMsat,
×
442
                &i.Policy1LastUpdate,
×
443
                &i.Policy1Disabled,
×
444
                &i.Policy1InboundBaseFeeMsat,
×
445
                &i.Policy1InboundFeeRateMilliMsat,
×
446
                &i.Policy1Signature,
×
447
                &i.Policy2ID,
×
448
                &i.Policy2NodeID,
×
449
                &i.Policy2Version,
×
450
                &i.Policy2Timelock,
×
451
                &i.Policy2FeePpm,
×
452
                &i.Policy2BaseFeeMsat,
×
453
                &i.Policy2MinHtlcMsat,
×
454
                &i.Policy2MaxHtlcMsat,
×
455
                &i.Policy2LastUpdate,
×
456
                &i.Policy2Disabled,
×
457
                &i.Policy2InboundBaseFeeMsat,
×
458
                &i.Policy2InboundFeeRateMilliMsat,
×
459
                &i.Policy2Signature,
×
460
        )
×
461
        return i, err
×
462
}
×
463

464
const getChannelBySCID = `-- name: GetChannelBySCID :one
465
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
466
WHERE scid = $1 AND version = $2
467
`
468

469
type GetChannelBySCIDParams struct {
470
        Scid    []byte
471
        Version int16
472
}
473

474
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
475
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
476
        var i Channel
×
477
        err := row.Scan(
×
478
                &i.ID,
×
479
                &i.Version,
×
480
                &i.Scid,
×
481
                &i.NodeID1,
×
482
                &i.NodeID2,
×
483
                &i.Outpoint,
×
484
                &i.Capacity,
×
485
                &i.BitcoinKey1,
×
486
                &i.BitcoinKey2,
×
487
                &i.Node1Signature,
×
488
                &i.Node2Signature,
×
489
                &i.Bitcoin1Signature,
×
490
                &i.Bitcoin2Signature,
×
491
        )
×
492
        return i, err
×
493
}
×
494

495
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
496
SELECT
497
    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,
498
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
499
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
500

501
    -- Policy 1
502
    cp1.id AS policy1_id,
503
    cp1.node_id AS policy1_node_id,
504
    cp1.version AS policy1_version,
505
    cp1.timelock AS policy1_timelock,
506
    cp1.fee_ppm AS policy1_fee_ppm,
507
    cp1.base_fee_msat AS policy1_base_fee_msat,
508
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
509
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
510
    cp1.last_update AS policy1_last_update,
511
    cp1.disabled AS policy1_disabled,
512
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
513
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
514
    cp1.signature AS policy1_signature,
515

516
    -- Policy 2
517
    cp2.id AS policy2_id,
518
    cp2.node_id AS policy2_node_id,
519
    cp2.version AS policy2_version,
520
    cp2.timelock AS policy2_timelock,
521
    cp2.fee_ppm AS policy2_fee_ppm,
522
    cp2.base_fee_msat AS policy2_base_fee_msat,
523
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
524
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
525
    cp2.last_update AS policy2_last_update,
526
    cp2.disabled AS policy2_disabled,
527
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
528
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
529
    cp2.signature AS policy2_signature
530

531
FROM channels c
532
    JOIN nodes n1 ON c.node_id_1 = n1.id
533
    JOIN nodes n2 ON c.node_id_2 = n2.id
534
    LEFT JOIN channel_policies cp1
535
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
536
    LEFT JOIN channel_policies cp2
537
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
538
WHERE c.scid = $1
539
  AND c.version = $2
540
`
541

542
type GetChannelBySCIDWithPoliciesParams struct {
543
        Scid    []byte
544
        Version int16
545
}
546

547
type GetChannelBySCIDWithPoliciesRow struct {
548
        Channel                        Channel
549
        Node                           Node
550
        Node_2                         Node
551
        Policy1ID                      sql.NullInt64
552
        Policy1NodeID                  sql.NullInt64
553
        Policy1Version                 sql.NullInt16
554
        Policy1Timelock                sql.NullInt32
555
        Policy1FeePpm                  sql.NullInt64
556
        Policy1BaseFeeMsat             sql.NullInt64
557
        Policy1MinHtlcMsat             sql.NullInt64
558
        Policy1MaxHtlcMsat             sql.NullInt64
559
        Policy1LastUpdate              sql.NullInt64
560
        Policy1Disabled                sql.NullBool
561
        Policy1InboundBaseFeeMsat      sql.NullInt64
562
        Policy1InboundFeeRateMilliMsat sql.NullInt64
563
        Policy1Signature               []byte
564
        Policy2ID                      sql.NullInt64
565
        Policy2NodeID                  sql.NullInt64
566
        Policy2Version                 sql.NullInt16
567
        Policy2Timelock                sql.NullInt32
568
        Policy2FeePpm                  sql.NullInt64
569
        Policy2BaseFeeMsat             sql.NullInt64
570
        Policy2MinHtlcMsat             sql.NullInt64
571
        Policy2MaxHtlcMsat             sql.NullInt64
572
        Policy2LastUpdate              sql.NullInt64
573
        Policy2Disabled                sql.NullBool
574
        Policy2InboundBaseFeeMsat      sql.NullInt64
575
        Policy2InboundFeeRateMilliMsat sql.NullInt64
576
        Policy2Signature               []byte
577
}
578

579
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
580
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
581
        var i GetChannelBySCIDWithPoliciesRow
×
582
        err := row.Scan(
×
583
                &i.Channel.ID,
×
584
                &i.Channel.Version,
×
585
                &i.Channel.Scid,
×
586
                &i.Channel.NodeID1,
×
587
                &i.Channel.NodeID2,
×
588
                &i.Channel.Outpoint,
×
589
                &i.Channel.Capacity,
×
590
                &i.Channel.BitcoinKey1,
×
591
                &i.Channel.BitcoinKey2,
×
592
                &i.Channel.Node1Signature,
×
593
                &i.Channel.Node2Signature,
×
594
                &i.Channel.Bitcoin1Signature,
×
595
                &i.Channel.Bitcoin2Signature,
×
596
                &i.Node.ID,
×
597
                &i.Node.Version,
×
598
                &i.Node.PubKey,
×
599
                &i.Node.Alias,
×
600
                &i.Node.LastUpdate,
×
601
                &i.Node.Color,
×
602
                &i.Node.Signature,
×
603
                &i.Node_2.ID,
×
604
                &i.Node_2.Version,
×
605
                &i.Node_2.PubKey,
×
606
                &i.Node_2.Alias,
×
607
                &i.Node_2.LastUpdate,
×
608
                &i.Node_2.Color,
×
609
                &i.Node_2.Signature,
×
610
                &i.Policy1ID,
×
611
                &i.Policy1NodeID,
×
612
                &i.Policy1Version,
×
613
                &i.Policy1Timelock,
×
614
                &i.Policy1FeePpm,
×
615
                &i.Policy1BaseFeeMsat,
×
616
                &i.Policy1MinHtlcMsat,
×
617
                &i.Policy1MaxHtlcMsat,
×
618
                &i.Policy1LastUpdate,
×
619
                &i.Policy1Disabled,
×
620
                &i.Policy1InboundBaseFeeMsat,
×
621
                &i.Policy1InboundFeeRateMilliMsat,
×
622
                &i.Policy1Signature,
×
623
                &i.Policy2ID,
×
624
                &i.Policy2NodeID,
×
625
                &i.Policy2Version,
×
626
                &i.Policy2Timelock,
×
627
                &i.Policy2FeePpm,
×
628
                &i.Policy2BaseFeeMsat,
×
629
                &i.Policy2MinHtlcMsat,
×
630
                &i.Policy2MaxHtlcMsat,
×
631
                &i.Policy2LastUpdate,
×
632
                &i.Policy2Disabled,
×
633
                &i.Policy2InboundBaseFeeMsat,
×
634
                &i.Policy2InboundFeeRateMilliMsat,
×
635
                &i.Policy2Signature,
×
636
        )
×
637
        return i, err
×
638
}
×
639

640
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
641
SELECT
642
    cf.channel_id,
643
    true AS is_feature,
644
    cf.feature_bit AS feature_bit,
645
    NULL AS extra_key,
646
    NULL AS value
647
FROM channel_features cf
648
WHERE cf.channel_id = $1
649

650
UNION ALL
651

652
SELECT
653
    cet.channel_id,
654
    false AS is_feature,
655
    0 AS feature_bit,
656
    cet.type AS extra_key,
657
    cet.value AS value
658
FROM channel_extra_types cet
659
WHERE cet.channel_id = $1
660
`
661

662
type GetChannelFeaturesAndExtrasRow struct {
663
        ChannelID  int64
664
        IsFeature  bool
665
        FeatureBit int32
666
        ExtraKey   interface{}
667
        Value      interface{}
668
}
669

670
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
671
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
672
        if err != nil {
×
673
                return nil, err
×
674
        }
×
675
        defer rows.Close()
×
676
        var items []GetChannelFeaturesAndExtrasRow
×
677
        for rows.Next() {
×
678
                var i GetChannelFeaturesAndExtrasRow
×
679
                if err := rows.Scan(
×
680
                        &i.ChannelID,
×
681
                        &i.IsFeature,
×
682
                        &i.FeatureBit,
×
683
                        &i.ExtraKey,
×
684
                        &i.Value,
×
685
                ); err != nil {
×
686
                        return nil, err
×
687
                }
×
688
                items = append(items, i)
×
689
        }
690
        if err := rows.Close(); err != nil {
×
691
                return nil, err
×
692
        }
×
693
        if err := rows.Err(); err != nil {
×
694
                return nil, err
×
695
        }
×
696
        return items, nil
×
697
}
698

699
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
700
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, signature
701
FROM channel_policies
702
WHERE channel_id = $1
703
  AND node_id = $2
704
  AND version = $3
705
`
706

707
type GetChannelPolicyByChannelAndNodeParams struct {
708
        ChannelID int64
709
        NodeID    int64
710
        Version   int16
711
}
712

713
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) {
×
714
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
715
        var i ChannelPolicy
×
716
        err := row.Scan(
×
717
                &i.ID,
×
718
                &i.Version,
×
719
                &i.ChannelID,
×
720
                &i.NodeID,
×
721
                &i.Timelock,
×
722
                &i.FeePpm,
×
723
                &i.BaseFeeMsat,
×
724
                &i.MinHtlcMsat,
×
725
                &i.MaxHtlcMsat,
×
726
                &i.LastUpdate,
×
727
                &i.Disabled,
×
728
                &i.InboundBaseFeeMsat,
×
729
                &i.InboundFeeRateMilliMsat,
×
730
                &i.Signature,
×
731
        )
×
732
        return i, err
×
733
}
×
734

735
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
736
SELECT
737
    cp.id AS policy_id,
738
    cp.channel_id,
739
    cp.node_id,
740
    cpet.type,
741
    cpet.value
742
FROM channel_policies cp
743
JOIN channel_policy_extra_types cpet
744
ON cp.id = cpet.channel_policy_id
745
WHERE cp.id = $1 OR cp.id = $2
746
`
747

748
type GetChannelPolicyExtraTypesParams struct {
749
        ID   int64
750
        ID_2 int64
751
}
752

753
type GetChannelPolicyExtraTypesRow struct {
754
        PolicyID  int64
755
        ChannelID int64
756
        NodeID    int64
757
        Type      int64
758
        Value     []byte
759
}
760

761
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
762
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
763
        if err != nil {
×
764
                return nil, err
×
765
        }
×
766
        defer rows.Close()
×
767
        var items []GetChannelPolicyExtraTypesRow
×
768
        for rows.Next() {
×
769
                var i GetChannelPolicyExtraTypesRow
×
770
                if err := rows.Scan(
×
771
                        &i.PolicyID,
×
772
                        &i.ChannelID,
×
773
                        &i.NodeID,
×
774
                        &i.Type,
×
775
                        &i.Value,
×
776
                ); err != nil {
×
777
                        return nil, err
×
778
                }
×
779
                items = append(items, i)
×
780
        }
781
        if err := rows.Close(); err != nil {
×
782
                return nil, err
×
783
        }
×
784
        if err := rows.Err(); err != nil {
×
785
                return nil, err
×
786
        }
×
787
        return items, nil
×
788
}
789

790
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
791
SELECT
792
    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,
793
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
794
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
795

796
    -- Policy 1 (node_id_1)
797
    cp1.id AS policy1_id,
798
    cp1.node_id AS policy1_node_id,
799
    cp1.version AS policy1_version,
800
    cp1.timelock AS policy1_timelock,
801
    cp1.fee_ppm AS policy1_fee_ppm,
802
    cp1.base_fee_msat AS policy1_base_fee_msat,
803
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
804
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
805
    cp1.last_update AS policy1_last_update,
806
    cp1.disabled AS policy1_disabled,
807
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
808
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
809
    cp1.signature AS policy1_signature,
810

811
    -- Policy 2 (node_id_2)
812
    cp2.id AS policy2_id,
813
    cp2.node_id AS policy2_node_id,
814
    cp2.version AS policy2_version,
815
    cp2.timelock AS policy2_timelock,
816
    cp2.fee_ppm AS policy2_fee_ppm,
817
    cp2.base_fee_msat AS policy2_base_fee_msat,
818
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
819
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
820
    cp2.last_update AS policy2_last_update,
821
    cp2.disabled AS policy2_disabled,
822
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
823
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
824
    cp2.signature AS policy2_signature
825

826
FROM channels c
827
    JOIN nodes n1 ON c.node_id_1 = n1.id
828
    JOIN nodes n2 ON c.node_id_2 = n2.id
829
    LEFT JOIN channel_policies cp1
830
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
831
    LEFT JOIN channel_policies cp2
832
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
833
WHERE c.version = $1
834
  AND (
835
       (cp1.last_update >= $2 AND cp1.last_update < $3)
836
       OR
837
       (cp2.last_update >= $2 AND cp2.last_update < $3)
838
  )
839
ORDER BY
840
    CASE
841
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
842
            THEN COALESCE(cp1.last_update, 0)
843
        ELSE COALESCE(cp2.last_update, 0)
844
        END ASC
845
`
846

847
type GetChannelsByPolicyLastUpdateRangeParams struct {
848
        Version   int16
849
        StartTime sql.NullInt64
850
        EndTime   sql.NullInt64
851
}
852

853
type GetChannelsByPolicyLastUpdateRangeRow struct {
854
        Channel                        Channel
855
        Node                           Node
856
        Node_2                         Node
857
        Policy1ID                      sql.NullInt64
858
        Policy1NodeID                  sql.NullInt64
859
        Policy1Version                 sql.NullInt16
860
        Policy1Timelock                sql.NullInt32
861
        Policy1FeePpm                  sql.NullInt64
862
        Policy1BaseFeeMsat             sql.NullInt64
863
        Policy1MinHtlcMsat             sql.NullInt64
864
        Policy1MaxHtlcMsat             sql.NullInt64
865
        Policy1LastUpdate              sql.NullInt64
866
        Policy1Disabled                sql.NullBool
867
        Policy1InboundBaseFeeMsat      sql.NullInt64
868
        Policy1InboundFeeRateMilliMsat sql.NullInt64
869
        Policy1Signature               []byte
870
        Policy2ID                      sql.NullInt64
871
        Policy2NodeID                  sql.NullInt64
872
        Policy2Version                 sql.NullInt16
873
        Policy2Timelock                sql.NullInt32
874
        Policy2FeePpm                  sql.NullInt64
875
        Policy2BaseFeeMsat             sql.NullInt64
876
        Policy2MinHtlcMsat             sql.NullInt64
877
        Policy2MaxHtlcMsat             sql.NullInt64
878
        Policy2LastUpdate              sql.NullInt64
879
        Policy2Disabled                sql.NullBool
880
        Policy2InboundBaseFeeMsat      sql.NullInt64
881
        Policy2InboundFeeRateMilliMsat sql.NullInt64
882
        Policy2Signature               []byte
883
}
884

885
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
886
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
887
        if err != nil {
×
888
                return nil, err
×
889
        }
×
890
        defer rows.Close()
×
891
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
892
        for rows.Next() {
×
893
                var i GetChannelsByPolicyLastUpdateRangeRow
×
894
                if err := rows.Scan(
×
895
                        &i.Channel.ID,
×
896
                        &i.Channel.Version,
×
897
                        &i.Channel.Scid,
×
898
                        &i.Channel.NodeID1,
×
899
                        &i.Channel.NodeID2,
×
900
                        &i.Channel.Outpoint,
×
901
                        &i.Channel.Capacity,
×
902
                        &i.Channel.BitcoinKey1,
×
903
                        &i.Channel.BitcoinKey2,
×
904
                        &i.Channel.Node1Signature,
×
905
                        &i.Channel.Node2Signature,
×
906
                        &i.Channel.Bitcoin1Signature,
×
907
                        &i.Channel.Bitcoin2Signature,
×
908
                        &i.Node.ID,
×
909
                        &i.Node.Version,
×
910
                        &i.Node.PubKey,
×
911
                        &i.Node.Alias,
×
912
                        &i.Node.LastUpdate,
×
913
                        &i.Node.Color,
×
914
                        &i.Node.Signature,
×
915
                        &i.Node_2.ID,
×
916
                        &i.Node_2.Version,
×
917
                        &i.Node_2.PubKey,
×
918
                        &i.Node_2.Alias,
×
919
                        &i.Node_2.LastUpdate,
×
920
                        &i.Node_2.Color,
×
921
                        &i.Node_2.Signature,
×
922
                        &i.Policy1ID,
×
923
                        &i.Policy1NodeID,
×
924
                        &i.Policy1Version,
×
925
                        &i.Policy1Timelock,
×
926
                        &i.Policy1FeePpm,
×
927
                        &i.Policy1BaseFeeMsat,
×
928
                        &i.Policy1MinHtlcMsat,
×
929
                        &i.Policy1MaxHtlcMsat,
×
930
                        &i.Policy1LastUpdate,
×
931
                        &i.Policy1Disabled,
×
932
                        &i.Policy1InboundBaseFeeMsat,
×
933
                        &i.Policy1InboundFeeRateMilliMsat,
×
934
                        &i.Policy1Signature,
×
935
                        &i.Policy2ID,
×
936
                        &i.Policy2NodeID,
×
937
                        &i.Policy2Version,
×
938
                        &i.Policy2Timelock,
×
939
                        &i.Policy2FeePpm,
×
940
                        &i.Policy2BaseFeeMsat,
×
941
                        &i.Policy2MinHtlcMsat,
×
942
                        &i.Policy2MaxHtlcMsat,
×
943
                        &i.Policy2LastUpdate,
×
944
                        &i.Policy2Disabled,
×
945
                        &i.Policy2InboundBaseFeeMsat,
×
946
                        &i.Policy2InboundFeeRateMilliMsat,
×
947
                        &i.Policy2Signature,
×
948
                ); err != nil {
×
949
                        return nil, err
×
950
                }
×
951
                items = append(items, i)
×
952
        }
953
        if err := rows.Close(); err != nil {
×
954
                return nil, err
×
955
        }
×
956
        if err := rows.Err(); err != nil {
×
957
                return nil, err
×
958
        }
×
959
        return items, nil
×
960
}
961

962
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
963
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,
964
    n1.pub_key AS node1_pub_key,
965
    n2.pub_key AS node2_pub_key
966
FROM channels c
967
    JOIN nodes n1 ON c.node_id_1 = n1.id
968
    JOIN nodes n2 ON c.node_id_2 = n2.id
969
WHERE scid >= $1
970
  AND scid < $2
971
`
972

973
type GetChannelsBySCIDRangeParams struct {
974
        StartScid []byte
975
        EndScid   []byte
976
}
977

978
type GetChannelsBySCIDRangeRow struct {
979
        Channel     Channel
980
        Node1PubKey []byte
981
        Node2PubKey []byte
982
}
983

NEW
984
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
NEW
985
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
NEW
986
        if err != nil {
×
NEW
987
                return nil, err
×
NEW
988
        }
×
NEW
989
        defer rows.Close()
×
NEW
990
        var items []GetChannelsBySCIDRangeRow
×
NEW
991
        for rows.Next() {
×
NEW
992
                var i GetChannelsBySCIDRangeRow
×
NEW
993
                if err := rows.Scan(
×
NEW
994
                        &i.Channel.ID,
×
NEW
995
                        &i.Channel.Version,
×
NEW
996
                        &i.Channel.Scid,
×
NEW
997
                        &i.Channel.NodeID1,
×
NEW
998
                        &i.Channel.NodeID2,
×
NEW
999
                        &i.Channel.Outpoint,
×
NEW
1000
                        &i.Channel.Capacity,
×
NEW
1001
                        &i.Channel.BitcoinKey1,
×
NEW
1002
                        &i.Channel.BitcoinKey2,
×
NEW
1003
                        &i.Channel.Node1Signature,
×
NEW
1004
                        &i.Channel.Node2Signature,
×
NEW
1005
                        &i.Channel.Bitcoin1Signature,
×
NEW
1006
                        &i.Channel.Bitcoin2Signature,
×
NEW
1007
                        &i.Node1PubKey,
×
NEW
1008
                        &i.Node2PubKey,
×
NEW
1009
                ); err != nil {
×
NEW
1010
                        return nil, err
×
NEW
1011
                }
×
NEW
1012
                items = append(items, i)
×
1013
        }
NEW
1014
        if err := rows.Close(); err != nil {
×
NEW
1015
                return nil, err
×
NEW
1016
        }
×
NEW
1017
        if err := rows.Err(); err != nil {
×
NEW
1018
                return nil, err
×
NEW
1019
        }
×
NEW
1020
        return items, nil
×
1021
}
1022

1023
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1024
SELECT node_id, type, value
1025
FROM node_extra_types
1026
WHERE node_id = $1
1027
`
1028

1029
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
1030
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1031
        if err != nil {
×
1032
                return nil, err
×
1033
        }
×
1034
        defer rows.Close()
×
1035
        var items []NodeExtraType
×
1036
        for rows.Next() {
×
1037
                var i NodeExtraType
×
1038
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1039
                        return nil, err
×
1040
                }
×
1041
                items = append(items, i)
×
1042
        }
1043
        if err := rows.Close(); err != nil {
×
1044
                return nil, err
×
1045
        }
×
1046
        if err := rows.Err(); err != nil {
×
1047
                return nil, err
×
1048
        }
×
1049
        return items, nil
×
1050
}
1051

1052
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
1053
SELECT a.type, a.address
1054
FROM nodes n
1055
LEFT JOIN node_addresses a ON a.node_id = n.id
1056
WHERE n.pub_key = $1 AND n.version = $2
1057
ORDER BY a.type ASC, a.position ASC
1058
`
1059

1060
type GetNodeAddressesByPubKeyParams struct {
1061
        PubKey  []byte
1062
        Version int16
1063
}
1064

1065
type GetNodeAddressesByPubKeyRow struct {
1066
        Type    sql.NullInt16
1067
        Address sql.NullString
1068
}
1069

1070
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
1071
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
1072
        if err != nil {
×
1073
                return nil, err
×
1074
        }
×
1075
        defer rows.Close()
×
1076
        var items []GetNodeAddressesByPubKeyRow
×
1077
        for rows.Next() {
×
1078
                var i GetNodeAddressesByPubKeyRow
×
1079
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1080
                        return nil, err
×
1081
                }
×
1082
                items = append(items, i)
×
1083
        }
1084
        if err := rows.Close(); err != nil {
×
1085
                return nil, err
×
1086
        }
×
1087
        if err := rows.Err(); err != nil {
×
1088
                return nil, err
×
1089
        }
×
1090
        return items, nil
×
1091
}
1092

1093
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1094
SELECT id, version, pub_key, alias, last_update, color, signature
1095
FROM nodes
1096
WHERE pub_key = $1
1097
  AND version = $2
1098
`
1099

1100
type GetNodeByPubKeyParams struct {
1101
        PubKey  []byte
1102
        Version int16
1103
}
1104

1105
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
1106
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1107
        var i Node
×
1108
        err := row.Scan(
×
1109
                &i.ID,
×
1110
                &i.Version,
×
1111
                &i.PubKey,
×
1112
                &i.Alias,
×
1113
                &i.LastUpdate,
×
1114
                &i.Color,
×
1115
                &i.Signature,
×
1116
        )
×
1117
        return i, err
×
1118
}
×
1119

1120
const getNodeFeatures = `-- name: GetNodeFeatures :many
1121
SELECT node_id, feature_bit
1122
FROM node_features
1123
WHERE node_id = $1
1124
`
1125

1126
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
1127
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1128
        if err != nil {
×
1129
                return nil, err
×
1130
        }
×
1131
        defer rows.Close()
×
1132
        var items []NodeFeature
×
1133
        for rows.Next() {
×
1134
                var i NodeFeature
×
1135
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1136
                        return nil, err
×
1137
                }
×
1138
                items = append(items, i)
×
1139
        }
1140
        if err := rows.Close(); err != nil {
×
1141
                return nil, err
×
1142
        }
×
1143
        if err := rows.Err(); err != nil {
×
1144
                return nil, err
×
1145
        }
×
1146
        return items, nil
×
1147
}
1148

1149
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1150
SELECT f.feature_bit
1151
FROM nodes n
1152
    JOIN node_features f ON f.node_id = n.id
1153
WHERE n.pub_key = $1
1154
  AND n.version = $2
1155
`
1156

1157
type GetNodeFeaturesByPubKeyParams struct {
1158
        PubKey  []byte
1159
        Version int16
1160
}
1161

1162
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1163
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1164
        if err != nil {
×
1165
                return nil, err
×
1166
        }
×
1167
        defer rows.Close()
×
1168
        var items []int32
×
1169
        for rows.Next() {
×
1170
                var feature_bit int32
×
1171
                if err := rows.Scan(&feature_bit); err != nil {
×
1172
                        return nil, err
×
1173
                }
×
1174
                items = append(items, feature_bit)
×
1175
        }
1176
        if err := rows.Close(); err != nil {
×
1177
                return nil, err
×
1178
        }
×
1179
        if err := rows.Err(); err != nil {
×
1180
                return nil, err
×
1181
        }
×
1182
        return items, nil
×
1183
}
1184

1185
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1186
SELECT id
1187
FROM nodes
1188
WHERE pub_key = $1
1189
  AND version = $2
1190
`
1191

1192
type GetNodeIDByPubKeyParams struct {
1193
        PubKey  []byte
1194
        Version int16
1195
}
1196

1197
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1198
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1199
        var id int64
×
1200
        err := row.Scan(&id)
×
1201
        return id, err
×
1202
}
×
1203

1204
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1205
SELECT id, version, pub_key, alias, last_update, color, signature
1206
FROM nodes
1207
WHERE last_update >= $1
1208
  AND last_update < $2
1209
`
1210

1211
type GetNodesByLastUpdateRangeParams struct {
1212
        StartTime sql.NullInt64
1213
        EndTime   sql.NullInt64
1214
}
1215

1216
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
1217
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1218
        if err != nil {
×
1219
                return nil, err
×
1220
        }
×
1221
        defer rows.Close()
×
1222
        var items []Node
×
1223
        for rows.Next() {
×
1224
                var i Node
×
1225
                if err := rows.Scan(
×
1226
                        &i.ID,
×
1227
                        &i.Version,
×
1228
                        &i.PubKey,
×
1229
                        &i.Alias,
×
1230
                        &i.LastUpdate,
×
1231
                        &i.Color,
×
1232
                        &i.Signature,
×
1233
                ); err != nil {
×
1234
                        return nil, err
×
1235
                }
×
1236
                items = append(items, i)
×
1237
        }
1238
        if err := rows.Close(); err != nil {
×
1239
                return nil, err
×
1240
        }
×
1241
        if err := rows.Err(); err != nil {
×
1242
                return nil, err
×
1243
        }
×
1244
        return items, nil
×
1245
}
1246

1247
const getPruneTip = `-- name: GetPruneTip :one
1248
SELECT block_height, block_hash
1249
FROM prune_log
1250
ORDER BY block_height DESC
1251
LIMIT 1
1252
`
1253

NEW
1254
func (q *Queries) GetPruneTip(ctx context.Context) (PruneLog, error) {
×
NEW
1255
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
NEW
1256
        var i PruneLog
×
NEW
1257
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
NEW
1258
        return i, err
×
NEW
1259
}
×
1260

1261
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1262
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
1263
FROM channels
1264
WHERE node_1_signature IS NOT NULL
1265
  AND scid >= $1
1266
  AND scid < $2
1267
`
1268

1269
type GetPublicV1ChannelsBySCIDParams struct {
1270
        StartScid []byte
1271
        EndScid   []byte
1272
}
1273

1274
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
×
1275
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1276
        if err != nil {
×
1277
                return nil, err
×
1278
        }
×
1279
        defer rows.Close()
×
1280
        var items []Channel
×
1281
        for rows.Next() {
×
1282
                var i Channel
×
1283
                if err := rows.Scan(
×
1284
                        &i.ID,
×
1285
                        &i.Version,
×
1286
                        &i.Scid,
×
1287
                        &i.NodeID1,
×
1288
                        &i.NodeID2,
×
1289
                        &i.Outpoint,
×
1290
                        &i.Capacity,
×
1291
                        &i.BitcoinKey1,
×
1292
                        &i.BitcoinKey2,
×
1293
                        &i.Node1Signature,
×
1294
                        &i.Node2Signature,
×
1295
                        &i.Bitcoin1Signature,
×
1296
                        &i.Bitcoin2Signature,
×
1297
                ); err != nil {
×
1298
                        return nil, err
×
1299
                }
×
1300
                items = append(items, i)
×
1301
        }
1302
        if err := rows.Close(); err != nil {
×
1303
                return nil, err
×
1304
        }
×
1305
        if err := rows.Err(); err != nil {
×
1306
                return nil, err
×
1307
        }
×
1308
        return items, nil
×
1309
}
1310

1311
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1312
SELECT scid from channels
1313
WHERE outpoint = $1 AND version = $2
1314
`
1315

1316
type GetSCIDByOutpointParams struct {
1317
        Outpoint string
1318
        Version  int16
1319
}
1320

1321
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1322
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1323
        var scid []byte
×
1324
        err := row.Scan(&scid)
×
1325
        return scid, err
×
1326
}
×
1327

1328
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1329
SELECT sn.node_id, n.pub_key
1330
FROM source_nodes sn
1331
    JOIN nodes n ON sn.node_id = n.id
1332
WHERE n.version = $1
1333
`
1334

1335
type GetSourceNodesByVersionRow struct {
1336
        NodeID int64
1337
        PubKey []byte
1338
}
1339

1340
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1341
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1342
        if err != nil {
×
1343
                return nil, err
×
1344
        }
×
1345
        defer rows.Close()
×
1346
        var items []GetSourceNodesByVersionRow
×
1347
        for rows.Next() {
×
1348
                var i GetSourceNodesByVersionRow
×
1349
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1350
                        return nil, err
×
1351
                }
×
1352
                items = append(items, i)
×
1353
        }
1354
        if err := rows.Close(); err != nil {
×
1355
                return nil, err
×
1356
        }
×
1357
        if err := rows.Err(); err != nil {
×
1358
                return nil, err
×
1359
        }
×
1360
        return items, nil
×
1361
}
1362

1363
const getUnconnectedNodes = `-- name: GetUnconnectedNodes :many
1364
SELECT n.id, n.pub_key
1365
FROM nodes n
1366
WHERE NOT EXISTS (
1367
    SELECT 1
1368
    FROM channels c
1369
    WHERE c.node_id_1 = n.id OR c.node_id_2 = n.id
1370
)
1371
AND NOT EXISTS (
1372
    SELECT 1
1373
    FROM source_nodes sn
1374
    WHERE sn.node_id = n.id
1375
)
1376
`
1377

1378
type GetUnconnectedNodesRow struct {
1379
        ID     int64
1380
        PubKey []byte
1381
}
1382

1383
// Select all nodes that do not have any channels.
1384
// Ignore any of our source nodes.
NEW
1385
func (q *Queries) GetUnconnectedNodes(ctx context.Context) ([]GetUnconnectedNodesRow, error) {
×
NEW
1386
        rows, err := q.db.QueryContext(ctx, getUnconnectedNodes)
×
NEW
1387
        if err != nil {
×
NEW
1388
                return nil, err
×
NEW
1389
        }
×
NEW
1390
        defer rows.Close()
×
NEW
1391
        var items []GetUnconnectedNodesRow
×
NEW
1392
        for rows.Next() {
×
NEW
1393
                var i GetUnconnectedNodesRow
×
NEW
1394
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
NEW
1395
                        return nil, err
×
NEW
1396
                }
×
NEW
1397
                items = append(items, i)
×
1398
        }
NEW
1399
        if err := rows.Close(); err != nil {
×
NEW
1400
                return nil, err
×
NEW
1401
        }
×
NEW
1402
        if err := rows.Err(); err != nil {
×
NEW
1403
                return nil, err
×
NEW
1404
        }
×
NEW
1405
        return items, nil
×
1406
}
1407

1408
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1409
SELECT c.scid
1410
FROM channels c
1411
    JOIN channel_policies cp ON cp.channel_id = c.id
1412
WHERE cp.disabled = true
1413
AND c.version = 1
1414
GROUP BY c.scid
1415
HAVING COUNT(*) > 1
1416
`
1417

1418
// NOTE: this is V1 specific since for V1, disabled is a
1419
// simple, single boolean. The proposed V2 policy
1420
// structure will have a more complex disabled bit vector
1421
// and so the query for V2 may differ.
1422
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1423
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1424
        if err != nil {
×
1425
                return nil, err
×
1426
        }
×
1427
        defer rows.Close()
×
1428
        var items [][]byte
×
1429
        for rows.Next() {
×
1430
                var scid []byte
×
1431
                if err := rows.Scan(&scid); err != nil {
×
1432
                        return nil, err
×
1433
                }
×
1434
                items = append(items, scid)
×
1435
        }
1436
        if err := rows.Close(); err != nil {
×
1437
                return nil, err
×
1438
        }
×
1439
        if err := rows.Err(); err != nil {
×
1440
                return nil, err
×
1441
        }
×
1442
        return items, nil
×
1443
}
1444

1445
const getZombieChannel = `-- name: GetZombieChannel :one
1446
SELECT scid, version, node_key_1, node_key_2
1447
FROM zombie_channels
1448
WHERE scid = $1
1449
AND version = $2
1450
`
1451

1452
type GetZombieChannelParams struct {
1453
        Scid    []byte
1454
        Version int16
1455
}
1456

1457
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) {
×
1458
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1459
        var i ZombieChannel
×
1460
        err := row.Scan(
×
1461
                &i.Scid,
×
1462
                &i.Version,
×
1463
                &i.NodeKey1,
×
1464
                &i.NodeKey2,
×
1465
        )
×
1466
        return i, err
×
1467
}
×
1468

1469
const highestSCID = `-- name: HighestSCID :one
1470
SELECT scid
1471
FROM channels
1472
WHERE version = $1
1473
ORDER BY scid DESC
1474
LIMIT 1
1475
`
1476

1477
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1478
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1479
        var scid []byte
×
1480
        err := row.Scan(&scid)
×
1481
        return scid, err
×
1482
}
×
1483

1484
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1485
/* ─────────────────────────────────────────────
1486
   channel_policy_extra_types table queries
1487
   ─────────────────────────────────────────────
1488
*/
1489

1490
INSERT INTO channel_policy_extra_types (
1491
    channel_policy_id, type, value
1492
)
1493
VALUES ($1, $2, $3)
1494
`
1495

1496
type InsertChanPolicyExtraTypeParams struct {
1497
        ChannelPolicyID int64
1498
        Type            int64
1499
        Value           []byte
1500
}
1501

1502
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1503
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1504
        return err
×
1505
}
×
1506

1507
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1508
/* ─────────────────────────────────────────────
1509
   channel_features table queries
1510
   ─────────────────────────────────────────────
1511
*/
1512

1513
INSERT INTO channel_features (
1514
    channel_id, feature_bit
1515
) VALUES (
1516
    $1, $2
1517
)
1518
`
1519

1520
type InsertChannelFeatureParams struct {
1521
        ChannelID  int64
1522
        FeatureBit int32
1523
}
1524

1525
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1526
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1527
        return err
×
1528
}
×
1529

1530
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1531
/* ─────────────────────────────────────────────
1532
   node_addresses table queries
1533
   ─────────────────────────────────────────────
1534
*/
1535

1536
INSERT INTO node_addresses (
1537
    node_id,
1538
    type,
1539
    address,
1540
    position
1541
) VALUES (
1542
    $1, $2, $3, $4
1543
 )
1544
`
1545

1546
type InsertNodeAddressParams struct {
1547
        NodeID   int64
1548
        Type     int16
1549
        Address  string
1550
        Position int32
1551
}
1552

1553
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1554
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1555
                arg.NodeID,
×
1556
                arg.Type,
×
1557
                arg.Address,
×
1558
                arg.Position,
×
1559
        )
×
1560
        return err
×
1561
}
×
1562

1563
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1564
/* ─────────────────────────────────────────────
1565
   node_features table queries
1566
   ─────────────────────────────────────────────
1567
*/
1568

1569
INSERT INTO node_features (
1570
    node_id, feature_bit
1571
) VALUES (
1572
    $1, $2
1573
)
1574
`
1575

1576
type InsertNodeFeatureParams struct {
1577
        NodeID     int64
1578
        FeatureBit int32
1579
}
1580

1581
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1582
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1583
        return err
×
1584
}
×
1585

1586
const isPublicV1Node = `-- name: IsPublicV1Node :one
1587
SELECT EXISTS (
1588
    SELECT 1
1589
    FROM channels c
1590
    JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1591
    -- NOTE: we hard-code the version here since the clauses
1592
    -- here that determine if a node is public is specific
1593
    -- to the V1 gossip protocol. In V1, a node is public
1594
    -- if it has a public channel and a public channel is one
1595
    -- where we have the set of signatures of the channel
1596
    -- announcement. It is enough to just check that we have
1597
    -- one of the signatures since we only ever set them
1598
    -- together.
1599
    WHERE c.version = 1
1600
      AND c.bitcoin_1_signature IS NOT NULL
1601
      AND n.pub_key = $1
1602
)
1603
`
1604

1605
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
1606
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
1607
        var exists bool
×
1608
        err := row.Scan(&exists)
×
1609
        return exists, err
×
1610
}
×
1611

1612
const isZombieChannel = `-- name: IsZombieChannel :one
1613
SELECT EXISTS (
1614
    SELECT 1
1615
    FROM zombie_channels
1616
    WHERE scid = $1
1617
    AND version = $2
1618
) AS is_zombie
1619
`
1620

1621
type IsZombieChannelParams struct {
1622
        Scid    []byte
1623
        Version int16
1624
}
1625

1626
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
1627
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
1628
        var is_zombie bool
×
1629
        err := row.Scan(&is_zombie)
×
1630
        return is_zombie, err
×
1631
}
×
1632

1633
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1634
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,
1635
    n1.pub_key AS node1_pubkey,
1636
    n2.pub_key AS node2_pubkey,
1637

1638
    -- Policy 1
1639
    -- TODO(elle): use sqlc.embed to embed policy structs
1640
    --  once this issue is resolved:
1641
    --  https://github.com/sqlc-dev/sqlc/issues/2997
1642
    cp1.id AS policy1_id,
1643
    cp1.node_id AS policy1_node_id,
1644
    cp1.version AS policy1_version,
1645
    cp1.timelock AS policy1_timelock,
1646
    cp1.fee_ppm AS policy1_fee_ppm,
1647
    cp1.base_fee_msat AS policy1_base_fee_msat,
1648
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1649
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1650
    cp1.last_update AS policy1_last_update,
1651
    cp1.disabled AS policy1_disabled,
1652
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1653
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1654
    cp1.signature AS policy1_signature,
1655

1656
       -- Policy 2
1657
    cp2.id AS policy2_id,
1658
    cp2.node_id AS policy2_node_id,
1659
    cp2.version AS policy2_version,
1660
    cp2.timelock AS policy2_timelock,
1661
    cp2.fee_ppm AS policy2_fee_ppm,
1662
    cp2.base_fee_msat AS policy2_base_fee_msat,
1663
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1664
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1665
    cp2.last_update AS policy2_last_update,
1666
    cp2.disabled AS policy2_disabled,
1667
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1668
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1669
    cp2.signature AS policy2_signature
1670

1671
FROM channels c
1672
    JOIN nodes n1 ON c.node_id_1 = n1.id
1673
    JOIN nodes n2 ON c.node_id_2 = n2.id
1674
    LEFT JOIN channel_policies cp1
1675
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1676
    LEFT JOIN channel_policies cp2
1677
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1678
WHERE c.version = $1
1679
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1680
`
1681

1682
type ListChannelsByNodeIDParams struct {
1683
        Version int16
1684
        NodeID1 int64
1685
}
1686

1687
type ListChannelsByNodeIDRow struct {
1688
        Channel                        Channel
1689
        Node1Pubkey                    []byte
1690
        Node2Pubkey                    []byte
1691
        Policy1ID                      sql.NullInt64
1692
        Policy1NodeID                  sql.NullInt64
1693
        Policy1Version                 sql.NullInt16
1694
        Policy1Timelock                sql.NullInt32
1695
        Policy1FeePpm                  sql.NullInt64
1696
        Policy1BaseFeeMsat             sql.NullInt64
1697
        Policy1MinHtlcMsat             sql.NullInt64
1698
        Policy1MaxHtlcMsat             sql.NullInt64
1699
        Policy1LastUpdate              sql.NullInt64
1700
        Policy1Disabled                sql.NullBool
1701
        Policy1InboundBaseFeeMsat      sql.NullInt64
1702
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1703
        Policy1Signature               []byte
1704
        Policy2ID                      sql.NullInt64
1705
        Policy2NodeID                  sql.NullInt64
1706
        Policy2Version                 sql.NullInt16
1707
        Policy2Timelock                sql.NullInt32
1708
        Policy2FeePpm                  sql.NullInt64
1709
        Policy2BaseFeeMsat             sql.NullInt64
1710
        Policy2MinHtlcMsat             sql.NullInt64
1711
        Policy2MaxHtlcMsat             sql.NullInt64
1712
        Policy2LastUpdate              sql.NullInt64
1713
        Policy2Disabled                sql.NullBool
1714
        Policy2InboundBaseFeeMsat      sql.NullInt64
1715
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1716
        Policy2Signature               []byte
1717
}
1718

1719
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
1720
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
1721
        if err != nil {
×
1722
                return nil, err
×
1723
        }
×
1724
        defer rows.Close()
×
1725
        var items []ListChannelsByNodeIDRow
×
1726
        for rows.Next() {
×
1727
                var i ListChannelsByNodeIDRow
×
1728
                if err := rows.Scan(
×
1729
                        &i.Channel.ID,
×
1730
                        &i.Channel.Version,
×
1731
                        &i.Channel.Scid,
×
1732
                        &i.Channel.NodeID1,
×
1733
                        &i.Channel.NodeID2,
×
1734
                        &i.Channel.Outpoint,
×
1735
                        &i.Channel.Capacity,
×
1736
                        &i.Channel.BitcoinKey1,
×
1737
                        &i.Channel.BitcoinKey2,
×
1738
                        &i.Channel.Node1Signature,
×
1739
                        &i.Channel.Node2Signature,
×
1740
                        &i.Channel.Bitcoin1Signature,
×
1741
                        &i.Channel.Bitcoin2Signature,
×
1742
                        &i.Node1Pubkey,
×
1743
                        &i.Node2Pubkey,
×
1744
                        &i.Policy1ID,
×
1745
                        &i.Policy1NodeID,
×
1746
                        &i.Policy1Version,
×
1747
                        &i.Policy1Timelock,
×
1748
                        &i.Policy1FeePpm,
×
1749
                        &i.Policy1BaseFeeMsat,
×
1750
                        &i.Policy1MinHtlcMsat,
×
1751
                        &i.Policy1MaxHtlcMsat,
×
1752
                        &i.Policy1LastUpdate,
×
1753
                        &i.Policy1Disabled,
×
1754
                        &i.Policy1InboundBaseFeeMsat,
×
1755
                        &i.Policy1InboundFeeRateMilliMsat,
×
1756
                        &i.Policy1Signature,
×
1757
                        &i.Policy2ID,
×
1758
                        &i.Policy2NodeID,
×
1759
                        &i.Policy2Version,
×
1760
                        &i.Policy2Timelock,
×
1761
                        &i.Policy2FeePpm,
×
1762
                        &i.Policy2BaseFeeMsat,
×
1763
                        &i.Policy2MinHtlcMsat,
×
1764
                        &i.Policy2MaxHtlcMsat,
×
1765
                        &i.Policy2LastUpdate,
×
1766
                        &i.Policy2Disabled,
×
1767
                        &i.Policy2InboundBaseFeeMsat,
×
1768
                        &i.Policy2InboundFeeRateMilliMsat,
×
1769
                        &i.Policy2Signature,
×
1770
                ); err != nil {
×
1771
                        return nil, err
×
1772
                }
×
1773
                items = append(items, i)
×
1774
        }
1775
        if err := rows.Close(); err != nil {
×
1776
                return nil, err
×
1777
        }
×
1778
        if err := rows.Err(); err != nil {
×
1779
                return nil, err
×
1780
        }
×
1781
        return items, nil
×
1782
}
1783

1784
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
1785
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
1786
FROM channels c
1787
WHERE c.version = $1 AND c.id > $2
1788
ORDER BY c.id
1789
LIMIT $3
1790
`
1791

1792
type ListChannelsPaginatedParams struct {
1793
        Version int16
1794
        ID      int64
1795
        Limit   int32
1796
}
1797

1798
type ListChannelsPaginatedRow struct {
1799
        ID          int64
1800
        BitcoinKey1 []byte
1801
        BitcoinKey2 []byte
1802
        Outpoint    string
1803
}
1804

NEW
1805
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
NEW
1806
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
NEW
1807
        if err != nil {
×
NEW
1808
                return nil, err
×
NEW
1809
        }
×
NEW
1810
        defer rows.Close()
×
NEW
1811
        var items []ListChannelsPaginatedRow
×
NEW
1812
        for rows.Next() {
×
NEW
1813
                var i ListChannelsPaginatedRow
×
NEW
1814
                if err := rows.Scan(
×
NEW
1815
                        &i.ID,
×
NEW
1816
                        &i.BitcoinKey1,
×
NEW
1817
                        &i.BitcoinKey2,
×
NEW
1818
                        &i.Outpoint,
×
NEW
1819
                ); err != nil {
×
NEW
1820
                        return nil, err
×
NEW
1821
                }
×
NEW
1822
                items = append(items, i)
×
1823
        }
NEW
1824
        if err := rows.Close(); err != nil {
×
NEW
1825
                return nil, err
×
NEW
1826
        }
×
NEW
1827
        if err := rows.Err(); err != nil {
×
NEW
1828
                return nil, err
×
NEW
1829
        }
×
NEW
1830
        return items, nil
×
1831
}
1832

1833
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
1834
SELECT
1835
    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,
1836

1837
    -- Join node pubkeys
1838
    n1.pub_key AS node1_pubkey,
1839
    n2.pub_key AS node2_pubkey,
1840

1841
    -- Node 1 policy
1842
    cp1.id AS policy_1_id,
1843
    cp1.node_id AS policy_1_node_id,
1844
    cp1.version AS policy_1_version,
1845
    cp1.timelock AS policy_1_timelock,
1846
    cp1.fee_ppm AS policy_1_fee_ppm,
1847
    cp1.base_fee_msat AS policy_1_base_fee_msat,
1848
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
1849
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
1850
    cp1.last_update AS policy_1_last_update,
1851
    cp1.disabled AS policy_1_disabled,
1852
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1853
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1854
    cp1.signature AS policy_1_signature,
1855

1856
    -- Node 2 policy
1857
    cp2.id AS policy_2_id,
1858
    cp2.node_id AS policy_2_node_id,
1859
    cp2.version AS policy_2_version,
1860
    cp2.timelock AS policy_2_timelock,
1861
    cp2.fee_ppm AS policy_2_fee_ppm,
1862
    cp2.base_fee_msat AS policy_2_base_fee_msat,
1863
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
1864
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
1865
    cp2.last_update AS policy_2_last_update,
1866
    cp2.disabled AS policy_2_disabled,
1867
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1868
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1869
    cp2.signature AS policy_2_signature
1870

1871
FROM channels c
1872
JOIN nodes n1 ON c.node_id_1 = n1.id
1873
JOIN nodes n2 ON c.node_id_2 = n2.id
1874
LEFT JOIN channel_policies cp1
1875
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1876
LEFT JOIN channel_policies cp2
1877
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1878
WHERE c.version = $1 AND c.id > $2
1879
ORDER BY c.id
1880
LIMIT $3
1881
`
1882

1883
type ListChannelsWithPoliciesPaginatedParams struct {
1884
        Version int16
1885
        ID      int64
1886
        Limit   int32
1887
}
1888

1889
type ListChannelsWithPoliciesPaginatedRow struct {
1890
        Channel                        Channel
1891
        Node1Pubkey                    []byte
1892
        Node2Pubkey                    []byte
1893
        Policy1ID                      sql.NullInt64
1894
        Policy1NodeID                  sql.NullInt64
1895
        Policy1Version                 sql.NullInt16
1896
        Policy1Timelock                sql.NullInt32
1897
        Policy1FeePpm                  sql.NullInt64
1898
        Policy1BaseFeeMsat             sql.NullInt64
1899
        Policy1MinHtlcMsat             sql.NullInt64
1900
        Policy1MaxHtlcMsat             sql.NullInt64
1901
        Policy1LastUpdate              sql.NullInt64
1902
        Policy1Disabled                sql.NullBool
1903
        Policy1InboundBaseFeeMsat      sql.NullInt64
1904
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1905
        Policy1Signature               []byte
1906
        Policy2ID                      sql.NullInt64
1907
        Policy2NodeID                  sql.NullInt64
1908
        Policy2Version                 sql.NullInt16
1909
        Policy2Timelock                sql.NullInt32
1910
        Policy2FeePpm                  sql.NullInt64
1911
        Policy2BaseFeeMsat             sql.NullInt64
1912
        Policy2MinHtlcMsat             sql.NullInt64
1913
        Policy2MaxHtlcMsat             sql.NullInt64
1914
        Policy2LastUpdate              sql.NullInt64
1915
        Policy2Disabled                sql.NullBool
1916
        Policy2InboundBaseFeeMsat      sql.NullInt64
1917
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1918
        Policy2Signature               []byte
1919
}
1920

1921
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
1922
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
1923
        if err != nil {
×
1924
                return nil, err
×
1925
        }
×
1926
        defer rows.Close()
×
1927
        var items []ListChannelsWithPoliciesPaginatedRow
×
1928
        for rows.Next() {
×
1929
                var i ListChannelsWithPoliciesPaginatedRow
×
1930
                if err := rows.Scan(
×
1931
                        &i.Channel.ID,
×
1932
                        &i.Channel.Version,
×
1933
                        &i.Channel.Scid,
×
1934
                        &i.Channel.NodeID1,
×
1935
                        &i.Channel.NodeID2,
×
1936
                        &i.Channel.Outpoint,
×
1937
                        &i.Channel.Capacity,
×
1938
                        &i.Channel.BitcoinKey1,
×
1939
                        &i.Channel.BitcoinKey2,
×
1940
                        &i.Channel.Node1Signature,
×
1941
                        &i.Channel.Node2Signature,
×
1942
                        &i.Channel.Bitcoin1Signature,
×
1943
                        &i.Channel.Bitcoin2Signature,
×
1944
                        &i.Node1Pubkey,
×
1945
                        &i.Node2Pubkey,
×
1946
                        &i.Policy1ID,
×
1947
                        &i.Policy1NodeID,
×
1948
                        &i.Policy1Version,
×
1949
                        &i.Policy1Timelock,
×
1950
                        &i.Policy1FeePpm,
×
1951
                        &i.Policy1BaseFeeMsat,
×
1952
                        &i.Policy1MinHtlcMsat,
×
1953
                        &i.Policy1MaxHtlcMsat,
×
1954
                        &i.Policy1LastUpdate,
×
1955
                        &i.Policy1Disabled,
×
1956
                        &i.Policy1InboundBaseFeeMsat,
×
1957
                        &i.Policy1InboundFeeRateMilliMsat,
×
1958
                        &i.Policy1Signature,
×
1959
                        &i.Policy2ID,
×
1960
                        &i.Policy2NodeID,
×
1961
                        &i.Policy2Version,
×
1962
                        &i.Policy2Timelock,
×
1963
                        &i.Policy2FeePpm,
×
1964
                        &i.Policy2BaseFeeMsat,
×
1965
                        &i.Policy2MinHtlcMsat,
×
1966
                        &i.Policy2MaxHtlcMsat,
×
1967
                        &i.Policy2LastUpdate,
×
1968
                        &i.Policy2Disabled,
×
1969
                        &i.Policy2InboundBaseFeeMsat,
×
1970
                        &i.Policy2InboundFeeRateMilliMsat,
×
1971
                        &i.Policy2Signature,
×
1972
                ); err != nil {
×
1973
                        return nil, err
×
1974
                }
×
1975
                items = append(items, i)
×
1976
        }
1977
        if err := rows.Close(); err != nil {
×
1978
                return nil, err
×
1979
        }
×
1980
        if err := rows.Err(); err != nil {
×
1981
                return nil, err
×
1982
        }
×
1983
        return items, nil
×
1984
}
1985

1986
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
1987
SELECT id, pub_key
1988
FROM nodes
1989
WHERE version = $1  AND id > $2
1990
ORDER BY id
1991
LIMIT $3
1992
`
1993

1994
type ListNodeIDsAndPubKeysParams struct {
1995
        Version int16
1996
        ID      int64
1997
        Limit   int32
1998
}
1999

2000
type ListNodeIDsAndPubKeysRow struct {
2001
        ID     int64
2002
        PubKey []byte
2003
}
2004

2005
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2006
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2007
        if err != nil {
×
2008
                return nil, err
×
2009
        }
×
2010
        defer rows.Close()
×
2011
        var items []ListNodeIDsAndPubKeysRow
×
2012
        for rows.Next() {
×
2013
                var i ListNodeIDsAndPubKeysRow
×
2014
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2015
                        return nil, err
×
2016
                }
×
2017
                items = append(items, i)
×
2018
        }
2019
        if err := rows.Close(); err != nil {
×
2020
                return nil, err
×
2021
        }
×
2022
        if err := rows.Err(); err != nil {
×
2023
                return nil, err
×
2024
        }
×
2025
        return items, nil
×
2026
}
2027

2028
const listNodesPaginated = `-- name: ListNodesPaginated :many
2029
SELECT id, version, pub_key, alias, last_update, color, signature
2030
FROM nodes
2031
WHERE version = $1 AND id > $2
2032
ORDER BY id
2033
LIMIT $3
2034
`
2035

2036
type ListNodesPaginatedParams struct {
2037
        Version int16
2038
        ID      int64
2039
        Limit   int32
2040
}
2041

2042
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) {
×
2043
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2044
        if err != nil {
×
2045
                return nil, err
×
2046
        }
×
2047
        defer rows.Close()
×
2048
        var items []Node
×
2049
        for rows.Next() {
×
2050
                var i Node
×
2051
                if err := rows.Scan(
×
2052
                        &i.ID,
×
2053
                        &i.Version,
×
2054
                        &i.PubKey,
×
2055
                        &i.Alias,
×
2056
                        &i.LastUpdate,
×
2057
                        &i.Color,
×
2058
                        &i.Signature,
×
2059
                ); err != nil {
×
2060
                        return nil, err
×
2061
                }
×
2062
                items = append(items, i)
×
2063
        }
2064
        if err := rows.Close(); err != nil {
×
2065
                return nil, err
×
2066
        }
×
2067
        if err := rows.Err(); err != nil {
×
2068
                return nil, err
×
2069
        }
×
2070
        return items, nil
×
2071
}
2072

2073
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2074
/* ─────────────────────────────────────────────
2075
   channel_policies table queries
2076
   ─────────────────────────────────────────────
2077
*/
2078

2079
INSERT INTO channel_policies (
2080
    version, channel_id, node_id, timelock, fee_ppm,
2081
    base_fee_msat, min_htlc_msat, last_update, disabled,
2082
    max_htlc_msat, inbound_base_fee_msat,
2083
    inbound_fee_rate_milli_msat, signature
2084
) VALUES  (
2085
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
2086
)
2087
ON CONFLICT (channel_id, node_id, version)
2088
    -- Update the following fields if a conflict occurs on channel_id,
2089
    -- node_id, and version.
2090
    DO UPDATE SET
2091
        timelock = EXCLUDED.timelock,
2092
        fee_ppm = EXCLUDED.fee_ppm,
2093
        base_fee_msat = EXCLUDED.base_fee_msat,
2094
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2095
        last_update = EXCLUDED.last_update,
2096
        disabled = EXCLUDED.disabled,
2097
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2098
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2099
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2100
        signature = EXCLUDED.signature
2101
WHERE EXCLUDED.last_update > channel_policies.last_update
2102
RETURNING id
2103
`
2104

2105
type UpsertEdgePolicyParams struct {
2106
        Version                 int16
2107
        ChannelID               int64
2108
        NodeID                  int64
2109
        Timelock                int32
2110
        FeePpm                  int64
2111
        BaseFeeMsat             int64
2112
        MinHtlcMsat             int64
2113
        LastUpdate              sql.NullInt64
2114
        Disabled                sql.NullBool
2115
        MaxHtlcMsat             sql.NullInt64
2116
        InboundBaseFeeMsat      sql.NullInt64
2117
        InboundFeeRateMilliMsat sql.NullInt64
2118
        Signature               []byte
2119
}
2120

2121
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2122
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2123
                arg.Version,
×
2124
                arg.ChannelID,
×
2125
                arg.NodeID,
×
2126
                arg.Timelock,
×
2127
                arg.FeePpm,
×
2128
                arg.BaseFeeMsat,
×
2129
                arg.MinHtlcMsat,
×
2130
                arg.LastUpdate,
×
2131
                arg.Disabled,
×
2132
                arg.MaxHtlcMsat,
×
2133
                arg.InboundBaseFeeMsat,
×
2134
                arg.InboundFeeRateMilliMsat,
×
2135
                arg.Signature,
×
2136
        )
×
2137
        var id int64
×
2138
        err := row.Scan(&id)
×
2139
        return id, err
×
2140
}
×
2141

2142
const upsertNode = `-- name: UpsertNode :one
2143
/* ─────────────────────────────────────────────
2144
   nodes table queries
2145
   ─────────────────────────────────────────────
2146
*/
2147

2148
INSERT INTO nodes (
2149
    version, pub_key, alias, last_update, color, signature
2150
) VALUES (
2151
    $1, $2, $3, $4, $5, $6
2152
)
2153
ON CONFLICT (pub_key, version)
2154
    -- Update the following fields if a conflict occurs on pub_key
2155
    -- and version.
2156
    DO UPDATE SET
2157
        alias = EXCLUDED.alias,
2158
        last_update = EXCLUDED.last_update,
2159
        color = EXCLUDED.color,
2160
        signature = EXCLUDED.signature
2161
WHERE nodes.last_update IS NULL
2162
    OR EXCLUDED.last_update > nodes.last_update
2163
RETURNING id
2164
`
2165

2166
type UpsertNodeParams struct {
2167
        Version    int16
2168
        PubKey     []byte
2169
        Alias      sql.NullString
2170
        LastUpdate sql.NullInt64
2171
        Color      sql.NullString
2172
        Signature  []byte
2173
}
2174

2175
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2176
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2177
                arg.Version,
×
2178
                arg.PubKey,
×
2179
                arg.Alias,
×
2180
                arg.LastUpdate,
×
2181
                arg.Color,
×
2182
                arg.Signature,
×
2183
        )
×
2184
        var id int64
×
2185
        err := row.Scan(&id)
×
2186
        return id, err
×
2187
}
×
2188

2189
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2190
/* ─────────────────────────────────────────────
2191
   node_extra_types table queries
2192
   ─────────────────────────────────────────────
2193
*/
2194

2195
INSERT INTO node_extra_types (
2196
    node_id, type, value
2197
)
2198
VALUES ($1, $2, $3)
2199
ON CONFLICT (type, node_id)
2200
    -- Update the value if a conflict occurs on type
2201
    -- and node_id.
2202
    DO UPDATE SET value = EXCLUDED.value
2203
`
2204

2205
type UpsertNodeExtraTypeParams struct {
2206
        NodeID int64
2207
        Type   int64
2208
        Value  []byte
2209
}
2210

2211
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2212
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2213
        return err
×
2214
}
×
2215

2216
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2217
/* ─────────────────────────────────────────────
2218
    prune_log table queries
2219
    ─────────────────────────────────────────────
2220
*/
2221

2222
INSERT INTO prune_log (
2223
    block_height, block_hash
2224
) VALUES (
2225
    $1, $2
2226
)
2227
ON CONFLICT(block_height) DO UPDATE SET
2228
    block_hash = EXCLUDED.block_hash
2229
`
2230

2231
type UpsertPruneLogEntryParams struct {
2232
        BlockHeight int64
2233
        BlockHash   []byte
2234
}
2235

NEW
2236
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
NEW
2237
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
NEW
2238
        return err
×
NEW
2239
}
×
2240

2241
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2242
/* ─────────────────────────────────────────────
2243
   zombie_channels table queries
2244
   ─────────────────────────────────────────────
2245
*/
2246

2247
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
2248
VALUES ($1, $2, $3, $4)
2249
ON CONFLICT (scid, version)
2250
DO UPDATE SET
2251
    -- If a conflict exists for the SCID and version pair, then we
2252
    -- update the node keys.
2253
    node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
2254
    node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2)
2255
`
2256

2257
type UpsertZombieChannelParams struct {
2258
        Scid     []byte
2259
        Version  int16
2260
        NodeKey1 []byte
2261
        NodeKey2 []byte
2262
}
2263

2264
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2265
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2266
                arg.Scid,
×
2267
                arg.Version,
×
2268
                arg.NodeKey1,
×
2269
                arg.NodeKey2,
×
2270
        )
×
2271
        return err
×
2272
}
×
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