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

lightningnetwork / lnd / 15875081702

25 Jun 2025 11:27AM UTC coverage: 67.62% (+10.9%) from 56.712%
15875081702

Pull #9971

github

web-flow
Merge daf6a0874 into 5d926b39a
Pull Request #9971: [16] graph/db: SQL closed SCIDs table and last few methods

2 of 178 new or added lines in 3 files covered. (1.12%)

113 existing lines in 4 files now uncovered.

135032 of 199691 relevant lines covered (67.62%)

21869.95 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

NEW
47
func (q *Queries) AddV1ChannelProof(ctx context.Context, arg AddV1ChannelProofParams) (sql.Result, error) {
×
NEW
48
        return q.db.ExecContext(ctx, addV1ChannelProof,
×
NEW
49
                arg.Scid,
×
NEW
50
                arg.Node1Signature,
×
NEW
51
                arg.Node2Signature,
×
NEW
52
                arg.Bitcoin1Signature,
×
NEW
53
                arg.Bitcoin2Signature,
×
NEW
54
        )
×
NEW
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.signature AS policy_1_signature,
381

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

406
type GetChannelByOutpointWithPoliciesParams struct {
407
        Outpoint string
408
        Version  int16
409
}
410

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

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

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

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

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

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

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

544
    -- Policy 2
545
    cp2.id AS policy2_id,
546
    cp2.node_id AS policy2_node_id,
547
    cp2.version AS policy2_version,
548
    cp2.timelock AS policy2_timelock,
549
    cp2.fee_ppm AS policy2_fee_ppm,
550
    cp2.base_fee_msat AS policy2_base_fee_msat,
551
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
552
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
553
    cp2.last_update AS policy2_last_update,
554
    cp2.disabled AS policy2_disabled,
555
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
556
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
557
    cp2.signature AS policy2_signature
558

559
FROM channels c
560
    JOIN nodes n1 ON c.node_id_1 = n1.id
561
    JOIN nodes n2 ON c.node_id_2 = n2.id
562
    LEFT JOIN channel_policies cp1
563
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
564
    LEFT JOIN channel_policies cp2
565
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
566
WHERE c.scid = $1
567
  AND c.version = $2
568
`
569

570
type GetChannelBySCIDWithPoliciesParams struct {
571
        Scid    []byte
572
        Version int16
573
}
574

575
type GetChannelBySCIDWithPoliciesRow struct {
576
        Channel                        Channel
577
        Node                           Node
578
        Node_2                         Node
579
        Policy1ID                      sql.NullInt64
580
        Policy1NodeID                  sql.NullInt64
581
        Policy1Version                 sql.NullInt16
582
        Policy1Timelock                sql.NullInt32
583
        Policy1FeePpm                  sql.NullInt64
584
        Policy1BaseFeeMsat             sql.NullInt64
585
        Policy1MinHtlcMsat             sql.NullInt64
586
        Policy1MaxHtlcMsat             sql.NullInt64
587
        Policy1LastUpdate              sql.NullInt64
588
        Policy1Disabled                sql.NullBool
589
        Policy1InboundBaseFeeMsat      sql.NullInt64
590
        Policy1InboundFeeRateMilliMsat sql.NullInt64
591
        Policy1Signature               []byte
592
        Policy2ID                      sql.NullInt64
593
        Policy2NodeID                  sql.NullInt64
594
        Policy2Version                 sql.NullInt16
595
        Policy2Timelock                sql.NullInt32
596
        Policy2FeePpm                  sql.NullInt64
597
        Policy2BaseFeeMsat             sql.NullInt64
598
        Policy2MinHtlcMsat             sql.NullInt64
599
        Policy2MaxHtlcMsat             sql.NullInt64
600
        Policy2LastUpdate              sql.NullInt64
601
        Policy2Disabled                sql.NullBool
602
        Policy2InboundBaseFeeMsat      sql.NullInt64
603
        Policy2InboundFeeRateMilliMsat sql.NullInt64
604
        Policy2Signature               []byte
605
}
606

607
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
608
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
609
        var i GetChannelBySCIDWithPoliciesRow
×
610
        err := row.Scan(
×
611
                &i.Channel.ID,
×
612
                &i.Channel.Version,
×
613
                &i.Channel.Scid,
×
614
                &i.Channel.NodeID1,
×
615
                &i.Channel.NodeID2,
×
616
                &i.Channel.Outpoint,
×
617
                &i.Channel.Capacity,
×
618
                &i.Channel.BitcoinKey1,
×
619
                &i.Channel.BitcoinKey2,
×
620
                &i.Channel.Node1Signature,
×
621
                &i.Channel.Node2Signature,
×
622
                &i.Channel.Bitcoin1Signature,
×
623
                &i.Channel.Bitcoin2Signature,
×
624
                &i.Node.ID,
×
625
                &i.Node.Version,
×
626
                &i.Node.PubKey,
×
627
                &i.Node.Alias,
×
628
                &i.Node.LastUpdate,
×
629
                &i.Node.Color,
×
630
                &i.Node.Signature,
×
631
                &i.Node_2.ID,
×
632
                &i.Node_2.Version,
×
633
                &i.Node_2.PubKey,
×
634
                &i.Node_2.Alias,
×
635
                &i.Node_2.LastUpdate,
×
636
                &i.Node_2.Color,
×
637
                &i.Node_2.Signature,
×
638
                &i.Policy1ID,
×
639
                &i.Policy1NodeID,
×
640
                &i.Policy1Version,
×
641
                &i.Policy1Timelock,
×
642
                &i.Policy1FeePpm,
×
643
                &i.Policy1BaseFeeMsat,
×
644
                &i.Policy1MinHtlcMsat,
×
645
                &i.Policy1MaxHtlcMsat,
×
646
                &i.Policy1LastUpdate,
×
647
                &i.Policy1Disabled,
×
648
                &i.Policy1InboundBaseFeeMsat,
×
649
                &i.Policy1InboundFeeRateMilliMsat,
×
650
                &i.Policy1Signature,
×
651
                &i.Policy2ID,
×
652
                &i.Policy2NodeID,
×
653
                &i.Policy2Version,
×
654
                &i.Policy2Timelock,
×
655
                &i.Policy2FeePpm,
×
656
                &i.Policy2BaseFeeMsat,
×
657
                &i.Policy2MinHtlcMsat,
×
658
                &i.Policy2MaxHtlcMsat,
×
659
                &i.Policy2LastUpdate,
×
660
                &i.Policy2Disabled,
×
661
                &i.Policy2InboundBaseFeeMsat,
×
662
                &i.Policy2InboundFeeRateMilliMsat,
×
663
                &i.Policy2Signature,
×
664
        )
×
665
        return i, err
×
666
}
×
667

668
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
669
SELECT
670
    cf.channel_id,
671
    true AS is_feature,
672
    cf.feature_bit AS feature_bit,
673
    NULL AS extra_key,
674
    NULL AS value
675
FROM channel_features cf
676
WHERE cf.channel_id = $1
677

678
UNION ALL
679

680
SELECT
681
    cet.channel_id,
682
    false AS is_feature,
683
    0 AS feature_bit,
684
    cet.type AS extra_key,
685
    cet.value AS value
686
FROM channel_extra_types cet
687
WHERE cet.channel_id = $1
688
`
689

690
type GetChannelFeaturesAndExtrasRow struct {
691
        ChannelID  int64
692
        IsFeature  bool
693
        FeatureBit int32
694
        ExtraKey   interface{}
695
        Value      interface{}
696
}
697

698
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
699
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
700
        if err != nil {
×
701
                return nil, err
×
702
        }
×
703
        defer rows.Close()
×
704
        var items []GetChannelFeaturesAndExtrasRow
×
705
        for rows.Next() {
×
706
                var i GetChannelFeaturesAndExtrasRow
×
707
                if err := rows.Scan(
×
708
                        &i.ChannelID,
×
709
                        &i.IsFeature,
×
710
                        &i.FeatureBit,
×
711
                        &i.ExtraKey,
×
712
                        &i.Value,
×
713
                ); err != nil {
×
714
                        return nil, err
×
715
                }
×
716
                items = append(items, i)
×
717
        }
718
        if err := rows.Close(); err != nil {
×
719
                return nil, err
×
720
        }
×
721
        if err := rows.Err(); err != nil {
×
722
                return nil, err
×
723
        }
×
724
        return items, nil
×
725
}
726

727
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
728
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
729
FROM channel_policies
730
WHERE channel_id = $1
731
  AND node_id = $2
732
  AND version = $3
733
`
734

735
type GetChannelPolicyByChannelAndNodeParams struct {
736
        ChannelID int64
737
        NodeID    int64
738
        Version   int16
739
}
740

741
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) {
×
742
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
743
        var i ChannelPolicy
×
744
        err := row.Scan(
×
745
                &i.ID,
×
746
                &i.Version,
×
747
                &i.ChannelID,
×
748
                &i.NodeID,
×
749
                &i.Timelock,
×
750
                &i.FeePpm,
×
751
                &i.BaseFeeMsat,
×
752
                &i.MinHtlcMsat,
×
753
                &i.MaxHtlcMsat,
×
754
                &i.LastUpdate,
×
755
                &i.Disabled,
×
756
                &i.InboundBaseFeeMsat,
×
757
                &i.InboundFeeRateMilliMsat,
×
758
                &i.Signature,
×
759
        )
×
760
        return i, err
×
761
}
×
762

763
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
764
SELECT
765
    cp.id AS policy_id,
766
    cp.channel_id,
767
    cp.node_id,
768
    cpet.type,
769
    cpet.value
770
FROM channel_policies cp
771
JOIN channel_policy_extra_types cpet
772
ON cp.id = cpet.channel_policy_id
773
WHERE cp.id = $1 OR cp.id = $2
774
`
775

776
type GetChannelPolicyExtraTypesParams struct {
777
        ID   int64
778
        ID_2 int64
779
}
780

781
type GetChannelPolicyExtraTypesRow struct {
782
        PolicyID  int64
783
        ChannelID int64
784
        NodeID    int64
785
        Type      int64
786
        Value     []byte
787
}
788

789
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
790
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
791
        if err != nil {
×
792
                return nil, err
×
793
        }
×
794
        defer rows.Close()
×
795
        var items []GetChannelPolicyExtraTypesRow
×
796
        for rows.Next() {
×
797
                var i GetChannelPolicyExtraTypesRow
×
798
                if err := rows.Scan(
×
799
                        &i.PolicyID,
×
800
                        &i.ChannelID,
×
801
                        &i.NodeID,
×
802
                        &i.Type,
×
803
                        &i.Value,
×
804
                ); err != nil {
×
805
                        return nil, err
×
806
                }
×
807
                items = append(items, i)
×
808
        }
809
        if err := rows.Close(); err != nil {
×
810
                return nil, err
×
811
        }
×
812
        if err := rows.Err(); err != nil {
×
813
                return nil, err
×
814
        }
×
815
        return items, nil
×
816
}
817

818
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
819
SELECT
820
    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,
821
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
822
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
823

824
    -- Policy 1 (node_id_1)
825
    cp1.id AS policy1_id,
826
    cp1.node_id AS policy1_node_id,
827
    cp1.version AS policy1_version,
828
    cp1.timelock AS policy1_timelock,
829
    cp1.fee_ppm AS policy1_fee_ppm,
830
    cp1.base_fee_msat AS policy1_base_fee_msat,
831
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
832
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
833
    cp1.last_update AS policy1_last_update,
834
    cp1.disabled AS policy1_disabled,
835
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
836
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
837
    cp1.signature AS policy1_signature,
838

839
    -- Policy 2 (node_id_2)
840
    cp2.id AS policy2_id,
841
    cp2.node_id AS policy2_node_id,
842
    cp2.version AS policy2_version,
843
    cp2.timelock AS policy2_timelock,
844
    cp2.fee_ppm AS policy2_fee_ppm,
845
    cp2.base_fee_msat AS policy2_base_fee_msat,
846
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
847
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
848
    cp2.last_update AS policy2_last_update,
849
    cp2.disabled AS policy2_disabled,
850
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
851
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
852
    cp2.signature AS policy2_signature
853

854
FROM channels c
855
    JOIN nodes n1 ON c.node_id_1 = n1.id
856
    JOIN nodes n2 ON c.node_id_2 = n2.id
857
    LEFT JOIN channel_policies cp1
858
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
859
    LEFT JOIN channel_policies cp2
860
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
861
WHERE c.version = $1
862
  AND (
863
       (cp1.last_update >= $2 AND cp1.last_update < $3)
864
       OR
865
       (cp2.last_update >= $2 AND cp2.last_update < $3)
866
  )
867
ORDER BY
868
    CASE
869
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
870
            THEN COALESCE(cp1.last_update, 0)
871
        ELSE COALESCE(cp2.last_update, 0)
872
        END ASC
873
`
874

875
type GetChannelsByPolicyLastUpdateRangeParams struct {
876
        Version   int16
877
        StartTime sql.NullInt64
878
        EndTime   sql.NullInt64
879
}
880

881
type GetChannelsByPolicyLastUpdateRangeRow struct {
882
        Channel                        Channel
883
        Node                           Node
884
        Node_2                         Node
885
        Policy1ID                      sql.NullInt64
886
        Policy1NodeID                  sql.NullInt64
887
        Policy1Version                 sql.NullInt16
888
        Policy1Timelock                sql.NullInt32
889
        Policy1FeePpm                  sql.NullInt64
890
        Policy1BaseFeeMsat             sql.NullInt64
891
        Policy1MinHtlcMsat             sql.NullInt64
892
        Policy1MaxHtlcMsat             sql.NullInt64
893
        Policy1LastUpdate              sql.NullInt64
894
        Policy1Disabled                sql.NullBool
895
        Policy1InboundBaseFeeMsat      sql.NullInt64
896
        Policy1InboundFeeRateMilliMsat sql.NullInt64
897
        Policy1Signature               []byte
898
        Policy2ID                      sql.NullInt64
899
        Policy2NodeID                  sql.NullInt64
900
        Policy2Version                 sql.NullInt16
901
        Policy2Timelock                sql.NullInt32
902
        Policy2FeePpm                  sql.NullInt64
903
        Policy2BaseFeeMsat             sql.NullInt64
904
        Policy2MinHtlcMsat             sql.NullInt64
905
        Policy2MaxHtlcMsat             sql.NullInt64
906
        Policy2LastUpdate              sql.NullInt64
907
        Policy2Disabled                sql.NullBool
908
        Policy2InboundBaseFeeMsat      sql.NullInt64
909
        Policy2InboundFeeRateMilliMsat sql.NullInt64
910
        Policy2Signature               []byte
911
}
912

913
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
914
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
915
        if err != nil {
×
916
                return nil, err
×
917
        }
×
918
        defer rows.Close()
×
919
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
920
        for rows.Next() {
×
921
                var i GetChannelsByPolicyLastUpdateRangeRow
×
922
                if err := rows.Scan(
×
923
                        &i.Channel.ID,
×
924
                        &i.Channel.Version,
×
925
                        &i.Channel.Scid,
×
926
                        &i.Channel.NodeID1,
×
927
                        &i.Channel.NodeID2,
×
928
                        &i.Channel.Outpoint,
×
929
                        &i.Channel.Capacity,
×
930
                        &i.Channel.BitcoinKey1,
×
931
                        &i.Channel.BitcoinKey2,
×
932
                        &i.Channel.Node1Signature,
×
933
                        &i.Channel.Node2Signature,
×
934
                        &i.Channel.Bitcoin1Signature,
×
935
                        &i.Channel.Bitcoin2Signature,
×
936
                        &i.Node.ID,
×
937
                        &i.Node.Version,
×
938
                        &i.Node.PubKey,
×
939
                        &i.Node.Alias,
×
940
                        &i.Node.LastUpdate,
×
941
                        &i.Node.Color,
×
942
                        &i.Node.Signature,
×
943
                        &i.Node_2.ID,
×
944
                        &i.Node_2.Version,
×
945
                        &i.Node_2.PubKey,
×
946
                        &i.Node_2.Alias,
×
947
                        &i.Node_2.LastUpdate,
×
948
                        &i.Node_2.Color,
×
949
                        &i.Node_2.Signature,
×
950
                        &i.Policy1ID,
×
951
                        &i.Policy1NodeID,
×
952
                        &i.Policy1Version,
×
953
                        &i.Policy1Timelock,
×
954
                        &i.Policy1FeePpm,
×
955
                        &i.Policy1BaseFeeMsat,
×
956
                        &i.Policy1MinHtlcMsat,
×
957
                        &i.Policy1MaxHtlcMsat,
×
958
                        &i.Policy1LastUpdate,
×
959
                        &i.Policy1Disabled,
×
960
                        &i.Policy1InboundBaseFeeMsat,
×
961
                        &i.Policy1InboundFeeRateMilliMsat,
×
962
                        &i.Policy1Signature,
×
963
                        &i.Policy2ID,
×
964
                        &i.Policy2NodeID,
×
965
                        &i.Policy2Version,
×
966
                        &i.Policy2Timelock,
×
967
                        &i.Policy2FeePpm,
×
968
                        &i.Policy2BaseFeeMsat,
×
969
                        &i.Policy2MinHtlcMsat,
×
970
                        &i.Policy2MaxHtlcMsat,
×
971
                        &i.Policy2LastUpdate,
×
972
                        &i.Policy2Disabled,
×
973
                        &i.Policy2InboundBaseFeeMsat,
×
974
                        &i.Policy2InboundFeeRateMilliMsat,
×
975
                        &i.Policy2Signature,
×
976
                ); err != nil {
×
977
                        return nil, err
×
978
                }
×
979
                items = append(items, i)
×
980
        }
981
        if err := rows.Close(); err != nil {
×
982
                return nil, err
×
983
        }
×
984
        if err := rows.Err(); err != nil {
×
985
                return nil, err
×
986
        }
×
987
        return items, nil
×
988
}
989

990
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
991
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,
992
    n1.pub_key AS node1_pub_key,
993
    n2.pub_key AS node2_pub_key
994
FROM channels c
995
    JOIN nodes n1 ON c.node_id_1 = n1.id
996
    JOIN nodes n2 ON c.node_id_2 = n2.id
997
WHERE scid >= $1
998
  AND scid < $2
999
`
1000

1001
type GetChannelsBySCIDRangeParams struct {
1002
        StartScid []byte
1003
        EndScid   []byte
1004
}
1005

1006
type GetChannelsBySCIDRangeRow struct {
1007
        Channel     Channel
1008
        Node1PubKey []byte
1009
        Node2PubKey []byte
1010
}
1011

1012
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
1013
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
1014
        if err != nil {
×
1015
                return nil, err
×
1016
        }
×
1017
        defer rows.Close()
×
1018
        var items []GetChannelsBySCIDRangeRow
×
1019
        for rows.Next() {
×
1020
                var i GetChannelsBySCIDRangeRow
×
1021
                if err := rows.Scan(
×
1022
                        &i.Channel.ID,
×
1023
                        &i.Channel.Version,
×
1024
                        &i.Channel.Scid,
×
1025
                        &i.Channel.NodeID1,
×
1026
                        &i.Channel.NodeID2,
×
1027
                        &i.Channel.Outpoint,
×
1028
                        &i.Channel.Capacity,
×
1029
                        &i.Channel.BitcoinKey1,
×
1030
                        &i.Channel.BitcoinKey2,
×
1031
                        &i.Channel.Node1Signature,
×
1032
                        &i.Channel.Node2Signature,
×
1033
                        &i.Channel.Bitcoin1Signature,
×
1034
                        &i.Channel.Bitcoin2Signature,
×
1035
                        &i.Node1PubKey,
×
1036
                        &i.Node2PubKey,
×
1037
                ); err != nil {
×
1038
                        return nil, err
×
1039
                }
×
1040
                items = append(items, i)
×
1041
        }
1042
        if err := rows.Close(); err != nil {
×
1043
                return nil, err
×
1044
        }
×
1045
        if err := rows.Err(); err != nil {
×
1046
                return nil, err
×
1047
        }
×
1048
        return items, nil
×
1049
}
1050

1051
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1052
SELECT node_id, type, value
1053
FROM node_extra_types
1054
WHERE node_id = $1
1055
`
1056

1057
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
1058
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
1059
        if err != nil {
×
1060
                return nil, err
×
1061
        }
×
1062
        defer rows.Close()
×
1063
        var items []NodeExtraType
×
1064
        for rows.Next() {
×
1065
                var i NodeExtraType
×
1066
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
1067
                        return nil, err
×
1068
                }
×
1069
                items = append(items, i)
×
1070
        }
1071
        if err := rows.Close(); err != nil {
×
1072
                return nil, err
×
1073
        }
×
1074
        if err := rows.Err(); err != nil {
×
1075
                return nil, err
×
1076
        }
×
1077
        return items, nil
×
1078
}
1079

1080
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
1081
SELECT a.type, a.address
1082
FROM nodes n
1083
LEFT JOIN node_addresses a ON a.node_id = n.id
1084
WHERE n.pub_key = $1 AND n.version = $2
1085
ORDER BY a.type ASC, a.position ASC
1086
`
1087

1088
type GetNodeAddressesByPubKeyParams struct {
1089
        PubKey  []byte
1090
        Version int16
1091
}
1092

1093
type GetNodeAddressesByPubKeyRow struct {
1094
        Type    sql.NullInt16
1095
        Address sql.NullString
1096
}
1097

1098
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
1099
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
1100
        if err != nil {
×
1101
                return nil, err
×
1102
        }
×
1103
        defer rows.Close()
×
1104
        var items []GetNodeAddressesByPubKeyRow
×
1105
        for rows.Next() {
×
1106
                var i GetNodeAddressesByPubKeyRow
×
1107
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
1108
                        return nil, err
×
1109
                }
×
1110
                items = append(items, i)
×
1111
        }
1112
        if err := rows.Close(); err != nil {
×
1113
                return nil, err
×
1114
        }
×
1115
        if err := rows.Err(); err != nil {
×
1116
                return nil, err
×
1117
        }
×
1118
        return items, nil
×
1119
}
1120

1121
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1122
SELECT id, version, pub_key, alias, last_update, color, signature
1123
FROM nodes
1124
WHERE pub_key = $1
1125
  AND version = $2
1126
`
1127

1128
type GetNodeByPubKeyParams struct {
1129
        PubKey  []byte
1130
        Version int16
1131
}
1132

1133
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
1134
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
1135
        var i Node
×
1136
        err := row.Scan(
×
1137
                &i.ID,
×
1138
                &i.Version,
×
1139
                &i.PubKey,
×
1140
                &i.Alias,
×
1141
                &i.LastUpdate,
×
1142
                &i.Color,
×
1143
                &i.Signature,
×
1144
        )
×
1145
        return i, err
×
1146
}
×
1147

1148
const getNodeFeatures = `-- name: GetNodeFeatures :many
1149
SELECT node_id, feature_bit
1150
FROM node_features
1151
WHERE node_id = $1
1152
`
1153

1154
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
1155
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1156
        if err != nil {
×
1157
                return nil, err
×
1158
        }
×
1159
        defer rows.Close()
×
1160
        var items []NodeFeature
×
1161
        for rows.Next() {
×
1162
                var i NodeFeature
×
1163
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1164
                        return nil, err
×
1165
                }
×
1166
                items = append(items, i)
×
1167
        }
1168
        if err := rows.Close(); err != nil {
×
1169
                return nil, err
×
1170
        }
×
1171
        if err := rows.Err(); err != nil {
×
1172
                return nil, err
×
1173
        }
×
1174
        return items, nil
×
1175
}
1176

1177
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1178
SELECT f.feature_bit
1179
FROM nodes n
1180
    JOIN node_features f ON f.node_id = n.id
1181
WHERE n.pub_key = $1
1182
  AND n.version = $2
1183
`
1184

1185
type GetNodeFeaturesByPubKeyParams struct {
1186
        PubKey  []byte
1187
        Version int16
1188
}
1189

1190
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1191
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1192
        if err != nil {
×
1193
                return nil, err
×
1194
        }
×
1195
        defer rows.Close()
×
1196
        var items []int32
×
1197
        for rows.Next() {
×
1198
                var feature_bit int32
×
1199
                if err := rows.Scan(&feature_bit); err != nil {
×
1200
                        return nil, err
×
1201
                }
×
1202
                items = append(items, feature_bit)
×
1203
        }
1204
        if err := rows.Close(); err != nil {
×
1205
                return nil, err
×
1206
        }
×
1207
        if err := rows.Err(); err != nil {
×
1208
                return nil, err
×
1209
        }
×
1210
        return items, nil
×
1211
}
1212

1213
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1214
SELECT id
1215
FROM nodes
1216
WHERE pub_key = $1
1217
  AND version = $2
1218
`
1219

1220
type GetNodeIDByPubKeyParams struct {
1221
        PubKey  []byte
1222
        Version int16
1223
}
1224

1225
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1226
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1227
        var id int64
×
1228
        err := row.Scan(&id)
×
1229
        return id, err
×
1230
}
×
1231

1232
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1233
SELECT id, version, pub_key, alias, last_update, color, signature
1234
FROM nodes
1235
WHERE last_update >= $1
1236
  AND last_update < $2
1237
`
1238

1239
type GetNodesByLastUpdateRangeParams struct {
1240
        StartTime sql.NullInt64
1241
        EndTime   sql.NullInt64
1242
}
1243

1244
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
1245
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1246
        if err != nil {
×
1247
                return nil, err
×
1248
        }
×
1249
        defer rows.Close()
×
1250
        var items []Node
×
1251
        for rows.Next() {
×
1252
                var i Node
×
1253
                if err := rows.Scan(
×
1254
                        &i.ID,
×
1255
                        &i.Version,
×
1256
                        &i.PubKey,
×
1257
                        &i.Alias,
×
1258
                        &i.LastUpdate,
×
1259
                        &i.Color,
×
1260
                        &i.Signature,
×
1261
                ); err != nil {
×
1262
                        return nil, err
×
1263
                }
×
1264
                items = append(items, i)
×
1265
        }
1266
        if err := rows.Close(); err != nil {
×
1267
                return nil, err
×
1268
        }
×
1269
        if err := rows.Err(); err != nil {
×
1270
                return nil, err
×
1271
        }
×
1272
        return items, nil
×
1273
}
1274

1275
const getPruneTip = `-- name: GetPruneTip :one
1276
SELECT block_height, block_hash
1277
FROM prune_log
1278
ORDER BY block_height DESC
1279
LIMIT 1
1280
`
1281

1282
func (q *Queries) GetPruneTip(ctx context.Context) (PruneLog, error) {
×
1283
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
1284
        var i PruneLog
×
1285
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
1286
        return i, err
×
1287
}
×
1288

1289
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1290
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
1291
FROM channels
1292
WHERE node_1_signature IS NOT NULL
1293
  AND scid >= $1
1294
  AND scid < $2
1295
`
1296

1297
type GetPublicV1ChannelsBySCIDParams struct {
1298
        StartScid []byte
1299
        EndScid   []byte
1300
}
1301

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

1339
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1340
SELECT scid from channels
1341
WHERE outpoint = $1 AND version = $2
1342
`
1343

1344
type GetSCIDByOutpointParams struct {
1345
        Outpoint string
1346
        Version  int16
1347
}
1348

1349
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
1350
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
1351
        var scid []byte
×
1352
        err := row.Scan(&scid)
×
1353
        return scid, err
×
1354
}
×
1355

1356
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1357
SELECT sn.node_id, n.pub_key
1358
FROM source_nodes sn
1359
    JOIN nodes n ON sn.node_id = n.id
1360
WHERE n.version = $1
1361
`
1362

1363
type GetSourceNodesByVersionRow struct {
1364
        NodeID int64
1365
        PubKey []byte
1366
}
1367

1368
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1369
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1370
        if err != nil {
×
1371
                return nil, err
×
1372
        }
×
1373
        defer rows.Close()
×
1374
        var items []GetSourceNodesByVersionRow
×
1375
        for rows.Next() {
×
1376
                var i GetSourceNodesByVersionRow
×
1377
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1378
                        return nil, err
×
1379
                }
×
1380
                items = append(items, i)
×
1381
        }
1382
        if err := rows.Close(); err != nil {
×
1383
                return nil, err
×
1384
        }
×
1385
        if err := rows.Err(); err != nil {
×
1386
                return nil, err
×
1387
        }
×
1388
        return items, nil
×
1389
}
1390

1391
const getUnconnectedNodes = `-- name: GetUnconnectedNodes :many
1392
SELECT n.id, n.pub_key
1393
FROM nodes n
1394
WHERE NOT EXISTS (
1395
    SELECT 1
1396
    FROM channels c
1397
    WHERE c.node_id_1 = n.id OR c.node_id_2 = n.id
1398
)
1399
AND NOT EXISTS (
1400
    SELECT 1
1401
    FROM source_nodes sn
1402
    WHERE sn.node_id = n.id
1403
)
1404
`
1405

1406
type GetUnconnectedNodesRow struct {
1407
        ID     int64
1408
        PubKey []byte
1409
}
1410

1411
// Select all nodes that do not have any channels.
1412
// Ignore any of our source nodes.
1413
func (q *Queries) GetUnconnectedNodes(ctx context.Context) ([]GetUnconnectedNodesRow, error) {
×
1414
        rows, err := q.db.QueryContext(ctx, getUnconnectedNodes)
×
1415
        if err != nil {
×
1416
                return nil, err
×
1417
        }
×
1418
        defer rows.Close()
×
1419
        var items []GetUnconnectedNodesRow
×
1420
        for rows.Next() {
×
1421
                var i GetUnconnectedNodesRow
×
1422
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
1423
                        return nil, err
×
1424
                }
×
1425
                items = append(items, i)
×
1426
        }
1427
        if err := rows.Close(); err != nil {
×
1428
                return nil, err
×
1429
        }
×
1430
        if err := rows.Err(); err != nil {
×
1431
                return nil, err
×
1432
        }
×
1433
        return items, nil
×
1434
}
1435

1436
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1437
SELECT c.scid
1438
FROM channels c
1439
    JOIN channel_policies cp ON cp.channel_id = c.id
1440
WHERE cp.disabled = true
1441
AND c.version = 1
1442
GROUP BY c.scid
1443
HAVING COUNT(*) > 1
1444
`
1445

1446
// NOTE: this is V1 specific since for V1, disabled is a
1447
// simple, single boolean. The proposed V2 policy
1448
// structure will have a more complex disabled bit vector
1449
// and so the query for V2 may differ.
1450
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
1451
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
1452
        if err != nil {
×
1453
                return nil, err
×
1454
        }
×
1455
        defer rows.Close()
×
1456
        var items [][]byte
×
1457
        for rows.Next() {
×
1458
                var scid []byte
×
1459
                if err := rows.Scan(&scid); err != nil {
×
1460
                        return nil, err
×
1461
                }
×
1462
                items = append(items, scid)
×
1463
        }
1464
        if err := rows.Close(); err != nil {
×
1465
                return nil, err
×
1466
        }
×
1467
        if err := rows.Err(); err != nil {
×
1468
                return nil, err
×
1469
        }
×
1470
        return items, nil
×
1471
}
1472

1473
const getZombieChannel = `-- name: GetZombieChannel :one
1474
SELECT scid, version, node_key_1, node_key_2
1475
FROM zombie_channels
1476
WHERE scid = $1
1477
AND version = $2
1478
`
1479

1480
type GetZombieChannelParams struct {
1481
        Scid    []byte
1482
        Version int16
1483
}
1484

1485
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) {
×
1486
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1487
        var i ZombieChannel
×
1488
        err := row.Scan(
×
1489
                &i.Scid,
×
1490
                &i.Version,
×
1491
                &i.NodeKey1,
×
1492
                &i.NodeKey2,
×
1493
        )
×
1494
        return i, err
×
1495
}
×
1496

1497
const highestSCID = `-- name: HighestSCID :one
1498
SELECT scid
1499
FROM channels
1500
WHERE version = $1
1501
ORDER BY scid DESC
1502
LIMIT 1
1503
`
1504

1505
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1506
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1507
        var scid []byte
×
1508
        err := row.Scan(&scid)
×
1509
        return scid, err
×
1510
}
×
1511

1512
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1513
/* ─────────────────────────────────────────────
1514
   channel_policy_extra_types table queries
1515
   ─────────────────────────────────────────────
1516
*/
1517

1518
INSERT INTO channel_policy_extra_types (
1519
    channel_policy_id, type, value
1520
)
1521
VALUES ($1, $2, $3)
1522
`
1523

1524
type InsertChanPolicyExtraTypeParams struct {
1525
        ChannelPolicyID int64
1526
        Type            int64
1527
        Value           []byte
1528
}
1529

1530
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1531
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1532
        return err
×
1533
}
×
1534

1535
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1536
/* ─────────────────────────────────────────────
1537
   channel_features table queries
1538
   ─────────────────────────────────────────────
1539
*/
1540

1541
INSERT INTO channel_features (
1542
    channel_id, feature_bit
1543
) VALUES (
1544
    $1, $2
1545
)
1546
`
1547

1548
type InsertChannelFeatureParams struct {
1549
        ChannelID  int64
1550
        FeatureBit int32
1551
}
1552

1553
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1554
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1555
        return err
×
1556
}
×
1557

1558
const insertClosedChannel = `-- name: InsertClosedChannel :exec
1559
/* ─────────────────────────────────────────────
1560
   closed_scid table queries
1561
   ────────────────────────────────────────────-
1562
*/
1563

1564
INSERT INTO closed_scids (scid)
1565
VALUES ($1)
1566
ON CONFLICT (scid) DO NOTHING
1567
`
1568

NEW
1569
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
NEW
1570
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
NEW
1571
        return err
×
NEW
1572
}
×
1573

1574
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1575
/* ─────────────────────────────────────────────
1576
   node_addresses table queries
1577
   ─────────────────────────────────────────────
1578
*/
1579

1580
INSERT INTO node_addresses (
1581
    node_id,
1582
    type,
1583
    address,
1584
    position
1585
) VALUES (
1586
    $1, $2, $3, $4
1587
 )
1588
`
1589

1590
type InsertNodeAddressParams struct {
1591
        NodeID   int64
1592
        Type     int16
1593
        Address  string
1594
        Position int32
1595
}
1596

1597
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1598
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1599
                arg.NodeID,
×
1600
                arg.Type,
×
1601
                arg.Address,
×
1602
                arg.Position,
×
1603
        )
×
1604
        return err
×
1605
}
×
1606

1607
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1608
/* ─────────────────────────────────────────────
1609
   node_features table queries
1610
   ─────────────────────────────────────────────
1611
*/
1612

1613
INSERT INTO node_features (
1614
    node_id, feature_bit
1615
) VALUES (
1616
    $1, $2
1617
)
1618
`
1619

1620
type InsertNodeFeatureParams struct {
1621
        NodeID     int64
1622
        FeatureBit int32
1623
}
1624

1625
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1626
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1627
        return err
×
1628
}
×
1629

1630
const isClosedChannel = `-- name: IsClosedChannel :one
1631
SELECT EXISTS (
1632
    SELECT 1
1633
    FROM closed_scids
1634
    WHERE scid = $1
1635
)
1636
`
1637

NEW
1638
func (q *Queries) IsClosedChannel(ctx context.Context, scid []byte) (bool, error) {
×
NEW
1639
        row := q.db.QueryRowContext(ctx, isClosedChannel, scid)
×
NEW
1640
        var exists bool
×
NEW
1641
        err := row.Scan(&exists)
×
NEW
1642
        return exists, err
×
NEW
1643
}
×
1644

1645
const isPublicV1Node = `-- name: IsPublicV1Node :one
1646
SELECT EXISTS (
1647
    SELECT 1
1648
    FROM channels c
1649
    JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1650
    -- NOTE: we hard-code the version here since the clauses
1651
    -- here that determine if a node is public is specific
1652
    -- to the V1 gossip protocol. In V1, a node is public
1653
    -- if it has a public channel and a public channel is one
1654
    -- where we have the set of signatures of the channel
1655
    -- announcement. It is enough to just check that we have
1656
    -- one of the signatures since we only ever set them
1657
    -- together.
1658
    WHERE c.version = 1
1659
      AND c.bitcoin_1_signature IS NOT NULL
1660
      AND n.pub_key = $1
1661
)
1662
`
1663

1664
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
1665
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
1666
        var exists bool
×
1667
        err := row.Scan(&exists)
×
1668
        return exists, err
×
1669
}
×
1670

1671
const isZombieChannel = `-- name: IsZombieChannel :one
1672
SELECT EXISTS (
1673
    SELECT 1
1674
    FROM zombie_channels
1675
    WHERE scid = $1
1676
    AND version = $2
1677
) AS is_zombie
1678
`
1679

1680
type IsZombieChannelParams struct {
1681
        Scid    []byte
1682
        Version int16
1683
}
1684

1685
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
1686
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
1687
        var is_zombie bool
×
1688
        err := row.Scan(&is_zombie)
×
1689
        return is_zombie, err
×
1690
}
×
1691

1692
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1693
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,
1694
    n1.pub_key AS node1_pubkey,
1695
    n2.pub_key AS node2_pubkey,
1696

1697
    -- Policy 1
1698
    -- TODO(elle): use sqlc.embed to embed policy structs
1699
    --  once this issue is resolved:
1700
    --  https://github.com/sqlc-dev/sqlc/issues/2997
1701
    cp1.id AS policy1_id,
1702
    cp1.node_id AS policy1_node_id,
1703
    cp1.version AS policy1_version,
1704
    cp1.timelock AS policy1_timelock,
1705
    cp1.fee_ppm AS policy1_fee_ppm,
1706
    cp1.base_fee_msat AS policy1_base_fee_msat,
1707
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1708
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1709
    cp1.last_update AS policy1_last_update,
1710
    cp1.disabled AS policy1_disabled,
1711
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1712
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1713
    cp1.signature AS policy1_signature,
1714

1715
       -- Policy 2
1716
    cp2.id AS policy2_id,
1717
    cp2.node_id AS policy2_node_id,
1718
    cp2.version AS policy2_version,
1719
    cp2.timelock AS policy2_timelock,
1720
    cp2.fee_ppm AS policy2_fee_ppm,
1721
    cp2.base_fee_msat AS policy2_base_fee_msat,
1722
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1723
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1724
    cp2.last_update AS policy2_last_update,
1725
    cp2.disabled AS policy2_disabled,
1726
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1727
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1728
    cp2.signature AS policy2_signature
1729

1730
FROM channels c
1731
    JOIN nodes n1 ON c.node_id_1 = n1.id
1732
    JOIN nodes n2 ON c.node_id_2 = n2.id
1733
    LEFT JOIN channel_policies cp1
1734
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1735
    LEFT JOIN channel_policies cp2
1736
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1737
WHERE c.version = $1
1738
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1739
`
1740

1741
type ListChannelsByNodeIDParams struct {
1742
        Version int16
1743
        NodeID1 int64
1744
}
1745

1746
type ListChannelsByNodeIDRow struct {
1747
        Channel                        Channel
1748
        Node1Pubkey                    []byte
1749
        Node2Pubkey                    []byte
1750
        Policy1ID                      sql.NullInt64
1751
        Policy1NodeID                  sql.NullInt64
1752
        Policy1Version                 sql.NullInt16
1753
        Policy1Timelock                sql.NullInt32
1754
        Policy1FeePpm                  sql.NullInt64
1755
        Policy1BaseFeeMsat             sql.NullInt64
1756
        Policy1MinHtlcMsat             sql.NullInt64
1757
        Policy1MaxHtlcMsat             sql.NullInt64
1758
        Policy1LastUpdate              sql.NullInt64
1759
        Policy1Disabled                sql.NullBool
1760
        Policy1InboundBaseFeeMsat      sql.NullInt64
1761
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1762
        Policy1Signature               []byte
1763
        Policy2ID                      sql.NullInt64
1764
        Policy2NodeID                  sql.NullInt64
1765
        Policy2Version                 sql.NullInt16
1766
        Policy2Timelock                sql.NullInt32
1767
        Policy2FeePpm                  sql.NullInt64
1768
        Policy2BaseFeeMsat             sql.NullInt64
1769
        Policy2MinHtlcMsat             sql.NullInt64
1770
        Policy2MaxHtlcMsat             sql.NullInt64
1771
        Policy2LastUpdate              sql.NullInt64
1772
        Policy2Disabled                sql.NullBool
1773
        Policy2InboundBaseFeeMsat      sql.NullInt64
1774
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1775
        Policy2Signature               []byte
1776
}
1777

1778
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
1779
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
1780
        if err != nil {
×
1781
                return nil, err
×
1782
        }
×
1783
        defer rows.Close()
×
1784
        var items []ListChannelsByNodeIDRow
×
1785
        for rows.Next() {
×
1786
                var i ListChannelsByNodeIDRow
×
1787
                if err := rows.Scan(
×
1788
                        &i.Channel.ID,
×
1789
                        &i.Channel.Version,
×
1790
                        &i.Channel.Scid,
×
1791
                        &i.Channel.NodeID1,
×
1792
                        &i.Channel.NodeID2,
×
1793
                        &i.Channel.Outpoint,
×
1794
                        &i.Channel.Capacity,
×
1795
                        &i.Channel.BitcoinKey1,
×
1796
                        &i.Channel.BitcoinKey2,
×
1797
                        &i.Channel.Node1Signature,
×
1798
                        &i.Channel.Node2Signature,
×
1799
                        &i.Channel.Bitcoin1Signature,
×
1800
                        &i.Channel.Bitcoin2Signature,
×
1801
                        &i.Node1Pubkey,
×
1802
                        &i.Node2Pubkey,
×
1803
                        &i.Policy1ID,
×
1804
                        &i.Policy1NodeID,
×
1805
                        &i.Policy1Version,
×
1806
                        &i.Policy1Timelock,
×
1807
                        &i.Policy1FeePpm,
×
1808
                        &i.Policy1BaseFeeMsat,
×
1809
                        &i.Policy1MinHtlcMsat,
×
1810
                        &i.Policy1MaxHtlcMsat,
×
1811
                        &i.Policy1LastUpdate,
×
1812
                        &i.Policy1Disabled,
×
1813
                        &i.Policy1InboundBaseFeeMsat,
×
1814
                        &i.Policy1InboundFeeRateMilliMsat,
×
1815
                        &i.Policy1Signature,
×
1816
                        &i.Policy2ID,
×
1817
                        &i.Policy2NodeID,
×
1818
                        &i.Policy2Version,
×
1819
                        &i.Policy2Timelock,
×
1820
                        &i.Policy2FeePpm,
×
1821
                        &i.Policy2BaseFeeMsat,
×
1822
                        &i.Policy2MinHtlcMsat,
×
1823
                        &i.Policy2MaxHtlcMsat,
×
1824
                        &i.Policy2LastUpdate,
×
1825
                        &i.Policy2Disabled,
×
1826
                        &i.Policy2InboundBaseFeeMsat,
×
1827
                        &i.Policy2InboundFeeRateMilliMsat,
×
1828
                        &i.Policy2Signature,
×
1829
                ); err != nil {
×
1830
                        return nil, err
×
1831
                }
×
1832
                items = append(items, i)
×
1833
        }
1834
        if err := rows.Close(); err != nil {
×
1835
                return nil, err
×
1836
        }
×
1837
        if err := rows.Err(); err != nil {
×
1838
                return nil, err
×
1839
        }
×
1840
        return items, nil
×
1841
}
1842

1843
const listChannelsPaginated = `-- name: ListChannelsPaginated :many
1844
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
1845
FROM channels c
1846
WHERE c.version = $1 AND c.id > $2
1847
ORDER BY c.id
1848
LIMIT $3
1849
`
1850

1851
type ListChannelsPaginatedParams struct {
1852
        Version int16
1853
        ID      int64
1854
        Limit   int32
1855
}
1856

1857
type ListChannelsPaginatedRow struct {
1858
        ID          int64
1859
        BitcoinKey1 []byte
1860
        BitcoinKey2 []byte
1861
        Outpoint    string
1862
}
1863

1864
func (q *Queries) ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error) {
×
1865
        rows, err := q.db.QueryContext(ctx, listChannelsPaginated, arg.Version, arg.ID, arg.Limit)
×
1866
        if err != nil {
×
1867
                return nil, err
×
1868
        }
×
1869
        defer rows.Close()
×
1870
        var items []ListChannelsPaginatedRow
×
1871
        for rows.Next() {
×
1872
                var i ListChannelsPaginatedRow
×
1873
                if err := rows.Scan(
×
1874
                        &i.ID,
×
1875
                        &i.BitcoinKey1,
×
1876
                        &i.BitcoinKey2,
×
1877
                        &i.Outpoint,
×
1878
                ); err != nil {
×
1879
                        return nil, err
×
1880
                }
×
1881
                items = append(items, i)
×
1882
        }
1883
        if err := rows.Close(); err != nil {
×
1884
                return nil, err
×
1885
        }
×
1886
        if err := rows.Err(); err != nil {
×
1887
                return nil, err
×
1888
        }
×
1889
        return items, nil
×
1890
}
1891

1892
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
1893
SELECT
1894
    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,
1895

1896
    -- Join node pubkeys
1897
    n1.pub_key AS node1_pubkey,
1898
    n2.pub_key AS node2_pubkey,
1899

1900
    -- Node 1 policy
1901
    cp1.id AS policy_1_id,
1902
    cp1.node_id AS policy_1_node_id,
1903
    cp1.version AS policy_1_version,
1904
    cp1.timelock AS policy_1_timelock,
1905
    cp1.fee_ppm AS policy_1_fee_ppm,
1906
    cp1.base_fee_msat AS policy_1_base_fee_msat,
1907
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
1908
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
1909
    cp1.last_update AS policy_1_last_update,
1910
    cp1.disabled AS policy_1_disabled,
1911
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1912
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1913
    cp1.signature AS policy_1_signature,
1914

1915
    -- Node 2 policy
1916
    cp2.id AS policy_2_id,
1917
    cp2.node_id AS policy_2_node_id,
1918
    cp2.version AS policy_2_version,
1919
    cp2.timelock AS policy_2_timelock,
1920
    cp2.fee_ppm AS policy_2_fee_ppm,
1921
    cp2.base_fee_msat AS policy_2_base_fee_msat,
1922
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
1923
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
1924
    cp2.last_update AS policy_2_last_update,
1925
    cp2.disabled AS policy_2_disabled,
1926
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1927
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1928
    cp2.signature AS policy_2_signature
1929

1930
FROM channels c
1931
JOIN nodes n1 ON c.node_id_1 = n1.id
1932
JOIN nodes n2 ON c.node_id_2 = n2.id
1933
LEFT JOIN channel_policies cp1
1934
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1935
LEFT JOIN channel_policies cp2
1936
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1937
WHERE c.version = $1 AND c.id > $2
1938
ORDER BY c.id
1939
LIMIT $3
1940
`
1941

1942
type ListChannelsWithPoliciesPaginatedParams struct {
1943
        Version int16
1944
        ID      int64
1945
        Limit   int32
1946
}
1947

1948
type ListChannelsWithPoliciesPaginatedRow struct {
1949
        Channel                        Channel
1950
        Node1Pubkey                    []byte
1951
        Node2Pubkey                    []byte
1952
        Policy1ID                      sql.NullInt64
1953
        Policy1NodeID                  sql.NullInt64
1954
        Policy1Version                 sql.NullInt16
1955
        Policy1Timelock                sql.NullInt32
1956
        Policy1FeePpm                  sql.NullInt64
1957
        Policy1BaseFeeMsat             sql.NullInt64
1958
        Policy1MinHtlcMsat             sql.NullInt64
1959
        Policy1MaxHtlcMsat             sql.NullInt64
1960
        Policy1LastUpdate              sql.NullInt64
1961
        Policy1Disabled                sql.NullBool
1962
        Policy1InboundBaseFeeMsat      sql.NullInt64
1963
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1964
        Policy1Signature               []byte
1965
        Policy2ID                      sql.NullInt64
1966
        Policy2NodeID                  sql.NullInt64
1967
        Policy2Version                 sql.NullInt16
1968
        Policy2Timelock                sql.NullInt32
1969
        Policy2FeePpm                  sql.NullInt64
1970
        Policy2BaseFeeMsat             sql.NullInt64
1971
        Policy2MinHtlcMsat             sql.NullInt64
1972
        Policy2MaxHtlcMsat             sql.NullInt64
1973
        Policy2LastUpdate              sql.NullInt64
1974
        Policy2Disabled                sql.NullBool
1975
        Policy2InboundBaseFeeMsat      sql.NullInt64
1976
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1977
        Policy2Signature               []byte
1978
}
1979

1980
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
1981
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
1982
        if err != nil {
×
1983
                return nil, err
×
1984
        }
×
1985
        defer rows.Close()
×
1986
        var items []ListChannelsWithPoliciesPaginatedRow
×
1987
        for rows.Next() {
×
1988
                var i ListChannelsWithPoliciesPaginatedRow
×
1989
                if err := rows.Scan(
×
1990
                        &i.Channel.ID,
×
1991
                        &i.Channel.Version,
×
1992
                        &i.Channel.Scid,
×
1993
                        &i.Channel.NodeID1,
×
1994
                        &i.Channel.NodeID2,
×
1995
                        &i.Channel.Outpoint,
×
1996
                        &i.Channel.Capacity,
×
1997
                        &i.Channel.BitcoinKey1,
×
1998
                        &i.Channel.BitcoinKey2,
×
1999
                        &i.Channel.Node1Signature,
×
2000
                        &i.Channel.Node2Signature,
×
2001
                        &i.Channel.Bitcoin1Signature,
×
2002
                        &i.Channel.Bitcoin2Signature,
×
2003
                        &i.Node1Pubkey,
×
2004
                        &i.Node2Pubkey,
×
2005
                        &i.Policy1ID,
×
2006
                        &i.Policy1NodeID,
×
2007
                        &i.Policy1Version,
×
2008
                        &i.Policy1Timelock,
×
2009
                        &i.Policy1FeePpm,
×
2010
                        &i.Policy1BaseFeeMsat,
×
2011
                        &i.Policy1MinHtlcMsat,
×
2012
                        &i.Policy1MaxHtlcMsat,
×
2013
                        &i.Policy1LastUpdate,
×
2014
                        &i.Policy1Disabled,
×
2015
                        &i.Policy1InboundBaseFeeMsat,
×
2016
                        &i.Policy1InboundFeeRateMilliMsat,
×
2017
                        &i.Policy1Signature,
×
2018
                        &i.Policy2ID,
×
2019
                        &i.Policy2NodeID,
×
2020
                        &i.Policy2Version,
×
2021
                        &i.Policy2Timelock,
×
2022
                        &i.Policy2FeePpm,
×
2023
                        &i.Policy2BaseFeeMsat,
×
2024
                        &i.Policy2MinHtlcMsat,
×
2025
                        &i.Policy2MaxHtlcMsat,
×
2026
                        &i.Policy2LastUpdate,
×
2027
                        &i.Policy2Disabled,
×
2028
                        &i.Policy2InboundBaseFeeMsat,
×
2029
                        &i.Policy2InboundFeeRateMilliMsat,
×
2030
                        &i.Policy2Signature,
×
2031
                ); err != nil {
×
2032
                        return nil, err
×
2033
                }
×
2034
                items = append(items, i)
×
2035
        }
2036
        if err := rows.Close(); err != nil {
×
2037
                return nil, err
×
2038
        }
×
2039
        if err := rows.Err(); err != nil {
×
2040
                return nil, err
×
2041
        }
×
2042
        return items, nil
×
2043
}
2044

2045
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2046
SELECT id, pub_key
2047
FROM nodes
2048
WHERE version = $1  AND id > $2
2049
ORDER BY id
2050
LIMIT $3
2051
`
2052

2053
type ListNodeIDsAndPubKeysParams struct {
2054
        Version int16
2055
        ID      int64
2056
        Limit   int32
2057
}
2058

2059
type ListNodeIDsAndPubKeysRow struct {
2060
        ID     int64
2061
        PubKey []byte
2062
}
2063

2064
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
2065
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
2066
        if err != nil {
×
2067
                return nil, err
×
2068
        }
×
2069
        defer rows.Close()
×
2070
        var items []ListNodeIDsAndPubKeysRow
×
2071
        for rows.Next() {
×
2072
                var i ListNodeIDsAndPubKeysRow
×
2073
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
2074
                        return nil, err
×
2075
                }
×
2076
                items = append(items, i)
×
2077
        }
2078
        if err := rows.Close(); err != nil {
×
2079
                return nil, err
×
2080
        }
×
2081
        if err := rows.Err(); err != nil {
×
2082
                return nil, err
×
2083
        }
×
2084
        return items, nil
×
2085
}
2086

2087
const listNodesPaginated = `-- name: ListNodesPaginated :many
2088
SELECT id, version, pub_key, alias, last_update, color, signature
2089
FROM nodes
2090
WHERE version = $1 AND id > $2
2091
ORDER BY id
2092
LIMIT $3
2093
`
2094

2095
type ListNodesPaginatedParams struct {
2096
        Version int16
2097
        ID      int64
2098
        Limit   int32
2099
}
2100

2101
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) {
×
2102
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
2103
        if err != nil {
×
2104
                return nil, err
×
2105
        }
×
2106
        defer rows.Close()
×
2107
        var items []Node
×
2108
        for rows.Next() {
×
2109
                var i Node
×
2110
                if err := rows.Scan(
×
2111
                        &i.ID,
×
2112
                        &i.Version,
×
2113
                        &i.PubKey,
×
2114
                        &i.Alias,
×
2115
                        &i.LastUpdate,
×
2116
                        &i.Color,
×
2117
                        &i.Signature,
×
2118
                ); err != nil {
×
2119
                        return nil, err
×
2120
                }
×
2121
                items = append(items, i)
×
2122
        }
2123
        if err := rows.Close(); err != nil {
×
2124
                return nil, err
×
2125
        }
×
2126
        if err := rows.Err(); err != nil {
×
2127
                return nil, err
×
2128
        }
×
2129
        return items, nil
×
2130
}
2131

2132
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2133
/* ─────────────────────────────────────────────
2134
   channel_policies table queries
2135
   ─────────────────────────────────────────────
2136
*/
2137

2138
INSERT INTO channel_policies (
2139
    version, channel_id, node_id, timelock, fee_ppm,
2140
    base_fee_msat, min_htlc_msat, last_update, disabled,
2141
    max_htlc_msat, inbound_base_fee_msat,
2142
    inbound_fee_rate_milli_msat, signature
2143
) VALUES  (
2144
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
2145
)
2146
ON CONFLICT (channel_id, node_id, version)
2147
    -- Update the following fields if a conflict occurs on channel_id,
2148
    -- node_id, and version.
2149
    DO UPDATE SET
2150
        timelock = EXCLUDED.timelock,
2151
        fee_ppm = EXCLUDED.fee_ppm,
2152
        base_fee_msat = EXCLUDED.base_fee_msat,
2153
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2154
        last_update = EXCLUDED.last_update,
2155
        disabled = EXCLUDED.disabled,
2156
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2157
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2158
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2159
        signature = EXCLUDED.signature
2160
WHERE EXCLUDED.last_update > channel_policies.last_update
2161
RETURNING id
2162
`
2163

2164
type UpsertEdgePolicyParams struct {
2165
        Version                 int16
2166
        ChannelID               int64
2167
        NodeID                  int64
2168
        Timelock                int32
2169
        FeePpm                  int64
2170
        BaseFeeMsat             int64
2171
        MinHtlcMsat             int64
2172
        LastUpdate              sql.NullInt64
2173
        Disabled                sql.NullBool
2174
        MaxHtlcMsat             sql.NullInt64
2175
        InboundBaseFeeMsat      sql.NullInt64
2176
        InboundFeeRateMilliMsat sql.NullInt64
2177
        Signature               []byte
2178
}
2179

2180
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
2181
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
2182
                arg.Version,
×
2183
                arg.ChannelID,
×
2184
                arg.NodeID,
×
2185
                arg.Timelock,
×
2186
                arg.FeePpm,
×
2187
                arg.BaseFeeMsat,
×
2188
                arg.MinHtlcMsat,
×
2189
                arg.LastUpdate,
×
2190
                arg.Disabled,
×
2191
                arg.MaxHtlcMsat,
×
2192
                arg.InboundBaseFeeMsat,
×
2193
                arg.InboundFeeRateMilliMsat,
×
2194
                arg.Signature,
×
2195
        )
×
2196
        var id int64
×
2197
        err := row.Scan(&id)
×
2198
        return id, err
×
2199
}
×
2200

2201
const upsertNode = `-- name: UpsertNode :one
2202
/* ─────────────────────────────────────────────
2203
   nodes table queries
2204
   ─────────────────────────────────────────────
2205
*/
2206

2207
INSERT INTO nodes (
2208
    version, pub_key, alias, last_update, color, signature
2209
) VALUES (
2210
    $1, $2, $3, $4, $5, $6
2211
)
2212
ON CONFLICT (pub_key, version)
2213
    -- Update the following fields if a conflict occurs on pub_key
2214
    -- and version.
2215
    DO UPDATE SET
2216
        alias = EXCLUDED.alias,
2217
        last_update = EXCLUDED.last_update,
2218
        color = EXCLUDED.color,
2219
        signature = EXCLUDED.signature
2220
WHERE nodes.last_update IS NULL
2221
    OR EXCLUDED.last_update > nodes.last_update
2222
RETURNING id
2223
`
2224

2225
type UpsertNodeParams struct {
2226
        Version    int16
2227
        PubKey     []byte
2228
        Alias      sql.NullString
2229
        LastUpdate sql.NullInt64
2230
        Color      sql.NullString
2231
        Signature  []byte
2232
}
2233

2234
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2235
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2236
                arg.Version,
×
2237
                arg.PubKey,
×
2238
                arg.Alias,
×
2239
                arg.LastUpdate,
×
2240
                arg.Color,
×
2241
                arg.Signature,
×
2242
        )
×
2243
        var id int64
×
2244
        err := row.Scan(&id)
×
2245
        return id, err
×
2246
}
×
2247

2248
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2249
/* ─────────────────────────────────────────────
2250
   node_extra_types table queries
2251
   ─────────────────────────────────────────────
2252
*/
2253

2254
INSERT INTO node_extra_types (
2255
    node_id, type, value
2256
)
2257
VALUES ($1, $2, $3)
2258
ON CONFLICT (type, node_id)
2259
    -- Update the value if a conflict occurs on type
2260
    -- and node_id.
2261
    DO UPDATE SET value = EXCLUDED.value
2262
`
2263

2264
type UpsertNodeExtraTypeParams struct {
2265
        NodeID int64
2266
        Type   int64
2267
        Value  []byte
2268
}
2269

2270
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2271
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2272
        return err
×
2273
}
×
2274

2275
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2276
/* ─────────────────────────────────────────────
2277
    prune_log table queries
2278
    ─────────────────────────────────────────────
2279
*/
2280

2281
INSERT INTO prune_log (
2282
    block_height, block_hash
2283
) VALUES (
2284
    $1, $2
2285
)
2286
ON CONFLICT(block_height) DO UPDATE SET
2287
    block_hash = EXCLUDED.block_hash
2288
`
2289

2290
type UpsertPruneLogEntryParams struct {
2291
        BlockHeight int64
2292
        BlockHash   []byte
2293
}
2294

2295
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
2296
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
2297
        return err
×
2298
}
×
2299

2300
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2301
/* ─────────────────────────────────────────────
2302
   zombie_channels table queries
2303
   ─────────────────────────────────────────────
2304
*/
2305

2306
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
2307
VALUES ($1, $2, $3, $4)
2308
ON CONFLICT (scid, version)
2309
DO UPDATE SET
2310
    -- If a conflict exists for the SCID and version pair, then we
2311
    -- update the node keys.
2312
    node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
2313
    node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2)
2314
`
2315

2316
type UpsertZombieChannelParams struct {
2317
        Scid     []byte
2318
        Version  int16
2319
        NodeKey1 []byte
2320
        NodeKey2 []byte
2321
}
2322

2323
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2324
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2325
                arg.Scid,
×
2326
                arg.Version,
×
2327
                arg.NodeKey1,
×
2328
                arg.NodeKey2,
×
2329
        )
×
2330
        return err
×
2331
}
×
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