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

lightningnetwork / lnd / 15606538456

12 Jun 2025 09:14AM UTC coverage: 67.414% (+9.1%) from 58.333%
15606538456

Pull #9932

github

web-flow
Merge 25e652669 into 35102e7c3
Pull Request #9932: [draft] graph/db+sqldb: graph store SQL implementation + migration

23 of 3319 new or added lines in 7 files covered. (0.69%)

39 existing lines in 8 files now uncovered.

134459 of 199453 relevant lines covered (67.41%)

21872.74 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 :exec
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 id = $1
36
`
37

38
type AddV1ChannelProofParams struct {
39
        ID                int64
40
        Node1Signature    []byte
41
        Node2Signature    []byte
42
        Bitcoin1Signature []byte
43
        Bitcoin2Signature []byte
44
}
45

NEW
46
func (q *Queries) AddV1ChannelProof(ctx context.Context, arg AddV1ChannelProofParams) error {
×
NEW
47
        _, err := q.db.ExecContext(ctx, addV1ChannelProof,
×
NEW
48
                arg.ID,
×
NEW
49
                arg.Node1Signature,
×
NEW
50
                arg.Node2Signature,
×
NEW
51
                arg.Bitcoin1Signature,
×
NEW
52
                arg.Bitcoin2Signature,
×
NEW
53
        )
×
NEW
54
        return err
×
NEW
55
}
×
56

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

NEW
63
func (q *Queries) CountZombieChannels(ctx context.Context, version int16) (int64, error) {
×
NEW
64
        row := q.db.QueryRowContext(ctx, countZombieChannels, version)
×
NEW
65
        var count int64
×
NEW
66
        err := row.Scan(&count)
×
NEW
67
        return count, err
×
NEW
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

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

154
const deleteChannelPolicyExtraType = `-- name: DeleteChannelPolicyExtraType :exec
155
DELETE FROM channel_policy_extra_types
156
WHERE channel_policy_id = $1
157
  AND type = $2
158
`
159

160
type DeleteChannelPolicyExtraTypeParams struct {
161
        ChannelPolicyID int64
162
        Type            int64
163
}
164

NEW
165
func (q *Queries) DeleteChannelPolicyExtraType(ctx context.Context, arg DeleteChannelPolicyExtraTypeParams) error {
×
NEW
166
        _, err := q.db.ExecContext(ctx, deleteChannelPolicyExtraType, arg.ChannelPolicyID, arg.Type)
×
NEW
167
        return err
×
NEW
168
}
×
169

170
const deleteExtraNodeType = `-- name: DeleteExtraNodeType :exec
171
DELETE FROM node_extra_types
172
WHERE node_id = $1
173
  AND type = $2
174
`
175

176
type DeleteExtraNodeTypeParams struct {
177
        NodeID int64
178
        Type   int64
179
}
180

181
func (q *Queries) DeleteExtraNodeType(ctx context.Context, arg DeleteExtraNodeTypeParams) error {
×
182
        _, err := q.db.ExecContext(ctx, deleteExtraNodeType, arg.NodeID, arg.Type)
×
183
        return err
×
184
}
×
185

186
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
187
DELETE FROM node_addresses
188
WHERE node_id = $1
189
`
190

191
func (q *Queries) DeleteNodeAddresses(ctx context.Context, nodeID int64) error {
×
192
        _, err := q.db.ExecContext(ctx, deleteNodeAddresses, nodeID)
×
193
        return err
×
194
}
×
195

196
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
197
DELETE FROM nodes
198
WHERE pub_key = $1
199
  AND version = $2
200
`
201

202
type DeleteNodeByPubKeyParams struct {
203
        PubKey  []byte
204
        Version int16
205
}
206

207
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
208
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
209
}
×
210

211
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
212
DELETE FROM node_features
213
WHERE node_id = $1
214
  AND feature_bit = $2
215
`
216

217
type DeleteNodeFeatureParams struct {
218
        NodeID     int64
219
        FeatureBit int32
220
}
221

222
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
223
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
224
        return err
×
225
}
×
226

227
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
228
DELETE FROM prune_log
229
WHERE block_height >= $1
230
  AND block_height <= $2
231
`
232

233
type DeletePruneLogEntriesInRangeParams struct {
234
        StartHeight int64
235
        EndHeight   int64
236
}
237

NEW
238
func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error {
×
NEW
239
        _, err := q.db.ExecContext(ctx, deletePruneLogEntriesInRange, arg.StartHeight, arg.EndHeight)
×
NEW
240
        return err
×
NEW
241
}
×
242

243
const deleteZombieChannel = `-- name: DeleteZombieChannel :exec
244
DELETE FROM zombie_channels
245
WHERE scid = $1
246
  AND version = $2
247
`
248

249
type DeleteZombieChannelParams struct {
250
        Scid    int64
251
        Version int16
252
}
253

NEW
254
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) error {
×
NEW
255
        _, err := q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
NEW
256
        return err
×
NEW
257
}
×
258

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

271
type GetChannelAndNodesBySCIDParams struct {
272
        Scid    []byte
273
        Version int16
274
}
275

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

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

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

328
type GetChannelByOutpointParams struct {
329
        Outpoint string
330
        Version  int16
331
}
332

333
type GetChannelByOutpointRow struct {
334
        ID                int64
335
        Version           int16
336
        Scid              []byte
337
        NodeID1           int64
338
        NodeID2           int64
339
        Outpoint          string
340
        Capacity          sql.NullInt64
341
        BitcoinKey1       []byte
342
        BitcoinKey2       []byte
343
        Node1Signature    []byte
344
        Node2Signature    []byte
345
        Bitcoin1Signature []byte
346
        Bitcoin2Signature []byte
347
        Node1Pubkey       []byte
348
        Node2Pubkey       []byte
349
}
350

NEW
351
func (q *Queries) GetChannelByOutpoint(ctx context.Context, arg GetChannelByOutpointParams) (GetChannelByOutpointRow, error) {
×
NEW
352
        row := q.db.QueryRowContext(ctx, getChannelByOutpoint, arg.Outpoint, arg.Version)
×
NEW
353
        var i GetChannelByOutpointRow
×
NEW
354
        err := row.Scan(
×
NEW
355
                &i.ID,
×
NEW
356
                &i.Version,
×
NEW
357
                &i.Scid,
×
NEW
358
                &i.NodeID1,
×
NEW
359
                &i.NodeID2,
×
NEW
360
                &i.Outpoint,
×
NEW
361
                &i.Capacity,
×
NEW
362
                &i.BitcoinKey1,
×
NEW
363
                &i.BitcoinKey2,
×
NEW
364
                &i.Node1Signature,
×
NEW
365
                &i.Node2Signature,
×
NEW
366
                &i.Bitcoin1Signature,
×
NEW
367
                &i.Bitcoin2Signature,
×
NEW
368
                &i.Node1Pubkey,
×
NEW
369
                &i.Node2Pubkey,
×
NEW
370
        )
×
NEW
371
        return i, err
×
NEW
372
}
×
373

374
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
375
SELECT
376
    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,
377

378
    n1.pub_key AS node1_pubkey,
379
    n2.pub_key AS node2_pubkey,
380

381
    -- Node 1 policy
382
    cp1.id AS policy_1_id,
383
    cp1.node_id AS policy_1_node_id,
384
    cp1.version AS policy_1_version,
385
    cp1.timelock AS policy_1_timelock,
386
    cp1.fee_ppm AS policy_1_fee_ppm,
387
    cp1.base_fee_msat AS policy_1_base_fee_msat,
388
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
389
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
390
    cp1.last_update AS policy_1_last_update,
391
    cp1.disabled AS policy_1_disabled,
392
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
393
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
394
    cp1.signature AS policy_1_signature,
395

396
    -- Node 2 policy
397
    cp2.id AS policy_2_id,
398
    cp2.node_id AS policy_2_node_id,
399
    cp2.version AS policy_2_version,
400
    cp2.timelock AS policy_2_timelock,
401
    cp2.fee_ppm AS policy_2_fee_ppm,
402
    cp2.base_fee_msat AS policy_2_base_fee_msat,
403
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
404
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
405
    cp2.last_update AS policy_2_last_update,
406
    cp2.disabled AS policy_2_disabled,
407
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
408
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
409
    cp2.signature AS policy_2_signature
410
FROM channels c
411
    JOIN nodes n1 ON c.node_id_1 = n1.id
412
    JOIN nodes n2 ON c.node_id_2 = n2.id
413
    LEFT JOIN channel_policies cp1
414
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
415
    LEFT JOIN channel_policies cp2
416
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
417
WHERE c.outpoint = $1 AND c.version = $2
418
`
419

420
type GetChannelByOutpointWithPoliciesParams struct {
421
        Outpoint string
422
        Version  int16
423
}
424

425
type GetChannelByOutpointWithPoliciesRow struct {
426
        ID                             int64
427
        Version                        int16
428
        Scid                           []byte
429
        NodeID1                        int64
430
        NodeID2                        int64
431
        Outpoint                       string
432
        Capacity                       sql.NullInt64
433
        BitcoinKey1                    []byte
434
        BitcoinKey2                    []byte
435
        Node1Signature                 []byte
436
        Node2Signature                 []byte
437
        Bitcoin1Signature              []byte
438
        Bitcoin2Signature              []byte
439
        Node1Pubkey                    []byte
440
        Node2Pubkey                    []byte
441
        Policy1ID                      sql.NullInt64
442
        Policy1NodeID                  sql.NullInt64
443
        Policy1Version                 sql.NullInt16
444
        Policy1Timelock                sql.NullInt32
445
        Policy1FeePpm                  sql.NullInt64
446
        Policy1BaseFeeMsat             sql.NullInt64
447
        Policy1MinHtlcMsat             sql.NullInt64
448
        Policy1MaxHtlcMsat             sql.NullInt64
449
        Policy1LastUpdate              sql.NullInt64
450
        Policy1Disabled                sql.NullBool
451
        Policy1InboundBaseFeeMsat      sql.NullInt64
452
        Policy1InboundFeeRateMilliMsat sql.NullInt64
453
        Policy1Signature               []byte
454
        Policy2ID                      sql.NullInt64
455
        Policy2NodeID                  sql.NullInt64
456
        Policy2Version                 sql.NullInt16
457
        Policy2Timelock                sql.NullInt32
458
        Policy2FeePpm                  sql.NullInt64
459
        Policy2BaseFeeMsat             sql.NullInt64
460
        Policy2MinHtlcMsat             sql.NullInt64
461
        Policy2MaxHtlcMsat             sql.NullInt64
462
        Policy2LastUpdate              sql.NullInt64
463
        Policy2Disabled                sql.NullBool
464
        Policy2InboundBaseFeeMsat      sql.NullInt64
465
        Policy2InboundFeeRateMilliMsat sql.NullInt64
466
        Policy2Signature               []byte
467
}
468

NEW
469
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
NEW
470
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
NEW
471
        var i GetChannelByOutpointWithPoliciesRow
×
NEW
472
        err := row.Scan(
×
NEW
473
                &i.ID,
×
NEW
474
                &i.Version,
×
NEW
475
                &i.Scid,
×
NEW
476
                &i.NodeID1,
×
NEW
477
                &i.NodeID2,
×
NEW
478
                &i.Outpoint,
×
NEW
479
                &i.Capacity,
×
NEW
480
                &i.BitcoinKey1,
×
NEW
481
                &i.BitcoinKey2,
×
NEW
482
                &i.Node1Signature,
×
NEW
483
                &i.Node2Signature,
×
NEW
484
                &i.Bitcoin1Signature,
×
NEW
485
                &i.Bitcoin2Signature,
×
NEW
486
                &i.Node1Pubkey,
×
NEW
487
                &i.Node2Pubkey,
×
NEW
488
                &i.Policy1ID,
×
NEW
489
                &i.Policy1NodeID,
×
NEW
490
                &i.Policy1Version,
×
NEW
491
                &i.Policy1Timelock,
×
NEW
492
                &i.Policy1FeePpm,
×
NEW
493
                &i.Policy1BaseFeeMsat,
×
NEW
494
                &i.Policy1MinHtlcMsat,
×
NEW
495
                &i.Policy1MaxHtlcMsat,
×
NEW
496
                &i.Policy1LastUpdate,
×
NEW
497
                &i.Policy1Disabled,
×
NEW
498
                &i.Policy1InboundBaseFeeMsat,
×
NEW
499
                &i.Policy1InboundFeeRateMilliMsat,
×
NEW
500
                &i.Policy1Signature,
×
NEW
501
                &i.Policy2ID,
×
NEW
502
                &i.Policy2NodeID,
×
NEW
503
                &i.Policy2Version,
×
NEW
504
                &i.Policy2Timelock,
×
NEW
505
                &i.Policy2FeePpm,
×
NEW
506
                &i.Policy2BaseFeeMsat,
×
NEW
507
                &i.Policy2MinHtlcMsat,
×
NEW
508
                &i.Policy2MaxHtlcMsat,
×
NEW
509
                &i.Policy2LastUpdate,
×
NEW
510
                &i.Policy2Disabled,
×
NEW
511
                &i.Policy2InboundBaseFeeMsat,
×
NEW
512
                &i.Policy2InboundFeeRateMilliMsat,
×
NEW
513
                &i.Policy2Signature,
×
NEW
514
        )
×
NEW
515
        return i, err
×
NEW
516
}
×
517

518
const getChannelBySCID = `-- name: GetChannelBySCID :one
519
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
520
WHERE scid = $1 AND version = $2
521
`
522

523
type GetChannelBySCIDParams struct {
524
        Scid    []byte
525
        Version int16
526
}
527

528
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
529
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
530
        var i Channel
×
531
        err := row.Scan(
×
532
                &i.ID,
×
533
                &i.Version,
×
534
                &i.Scid,
×
535
                &i.NodeID1,
×
536
                &i.NodeID2,
×
537
                &i.Outpoint,
×
538
                &i.Capacity,
×
539
                &i.BitcoinKey1,
×
540
                &i.BitcoinKey2,
×
541
                &i.Node1Signature,
×
542
                &i.Node2Signature,
×
543
                &i.Bitcoin1Signature,
×
544
                &i.Bitcoin2Signature,
×
545
        )
×
546
        return i, err
×
547
}
×
548

549
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
550
SELECT
551
    -- Channel fields
552
    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,
553

554
    -- Node 1
555
    n1.id AS node1_id,
556
    n1.version AS node1_version,
557
    n1.pub_key AS node1_pub_key,
558
    n1.alias AS node1_alias,
559
    n1.last_update AS node1_last_update,
560
    n1.color AS node1_color,
561
    n1.signature AS node1_ann_signature,
562

563
    -- Node 2
564
    n2.id AS node2_id,
565
    n2.version AS node2_version,
566
    n2.pub_key AS node2_pub_key,
567
    n2.alias AS node2_alias,
568
    n2.last_update AS node2_last_update,
569
    n2.color AS node2_color,
570
    n2.signature AS node2_ann_signature,
571

572
    -- Policy 1
573
    cp1.id AS policy1_id,
574
    cp1.node_id AS policy1_node_id,
575
    cp1.version AS policy1_version,
576
    cp1.timelock AS policy1_timelock,
577
    cp1.fee_ppm AS policy1_fee_ppm,
578
    cp1.base_fee_msat AS policy1_base_fee_msat,
579
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
580
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
581
    cp1.last_update AS policy1_last_update,
582
    cp1.disabled AS policy1_disabled,
583
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
584
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
585
    cp1.signature AS policy1_signature,
586

587
    -- Policy 2
588
    cp2.id AS policy2_id,
589
    cp2.node_id AS policy2_node_id,
590
    cp2.version AS policy2_version,
591
    cp2.timelock AS policy2_timelock,
592
    cp2.fee_ppm AS policy2_fee_ppm,
593
    cp2.base_fee_msat AS policy2_base_fee_msat,
594
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
595
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
596
    cp2.last_update AS policy2_last_update,
597
    cp2.disabled AS policy2_disabled,
598
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
599
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
600
    cp2.signature AS policy2_signature
601

602
FROM channels c
603
    JOIN nodes n1 ON c.node_id_1 = n1.id
604
    JOIN nodes n2 ON c.node_id_2 = n2.id
605
    LEFT JOIN channel_policies cp1
606
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
607
    LEFT JOIN channel_policies cp2
608
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
609
WHERE c.scid = $1
610
  AND c.version = $2
611
`
612

613
type GetChannelBySCIDWithPoliciesParams struct {
614
        Scid    []byte
615
        Version int16
616
}
617

618
type GetChannelBySCIDWithPoliciesRow struct {
619
        ID                             int64
620
        Version                        int16
621
        Scid                           []byte
622
        NodeID1                        int64
623
        NodeID2                        int64
624
        Outpoint                       string
625
        Capacity                       sql.NullInt64
626
        BitcoinKey1                    []byte
627
        BitcoinKey2                    []byte
628
        Node1Signature                 []byte
629
        Node2Signature                 []byte
630
        Bitcoin1Signature              []byte
631
        Bitcoin2Signature              []byte
632
        Node1ID                        int64
633
        Node1Version                   int16
634
        Node1PubKey                    []byte
635
        Node1Alias                     sql.NullString
636
        Node1LastUpdate                sql.NullInt64
637
        Node1Color                     sql.NullString
638
        Node1AnnSignature              []byte
639
        Node2ID                        int64
640
        Node2Version                   int16
641
        Node2PubKey                    []byte
642
        Node2Alias                     sql.NullString
643
        Node2LastUpdate                sql.NullInt64
644
        Node2Color                     sql.NullString
645
        Node2AnnSignature              []byte
646
        Policy1ID                      sql.NullInt64
647
        Policy1NodeID                  sql.NullInt64
648
        Policy1Version                 sql.NullInt16
649
        Policy1Timelock                sql.NullInt32
650
        Policy1FeePpm                  sql.NullInt64
651
        Policy1BaseFeeMsat             sql.NullInt64
652
        Policy1MinHtlcMsat             sql.NullInt64
653
        Policy1MaxHtlcMsat             sql.NullInt64
654
        Policy1LastUpdate              sql.NullInt64
655
        Policy1Disabled                sql.NullBool
656
        Policy1InboundBaseFeeMsat      sql.NullInt64
657
        Policy1InboundFeeRateMilliMsat sql.NullInt64
658
        Policy1Signature               []byte
659
        Policy2ID                      sql.NullInt64
660
        Policy2NodeID                  sql.NullInt64
661
        Policy2Version                 sql.NullInt16
662
        Policy2Timelock                sql.NullInt32
663
        Policy2FeePpm                  sql.NullInt64
664
        Policy2BaseFeeMsat             sql.NullInt64
665
        Policy2MinHtlcMsat             sql.NullInt64
666
        Policy2MaxHtlcMsat             sql.NullInt64
667
        Policy2LastUpdate              sql.NullInt64
668
        Policy2Disabled                sql.NullBool
669
        Policy2InboundBaseFeeMsat      sql.NullInt64
670
        Policy2InboundFeeRateMilliMsat sql.NullInt64
671
        Policy2Signature               []byte
672
}
673

NEW
674
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
NEW
675
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
NEW
676
        var i GetChannelBySCIDWithPoliciesRow
×
NEW
677
        err := row.Scan(
×
NEW
678
                &i.ID,
×
NEW
679
                &i.Version,
×
NEW
680
                &i.Scid,
×
NEW
681
                &i.NodeID1,
×
NEW
682
                &i.NodeID2,
×
NEW
683
                &i.Outpoint,
×
NEW
684
                &i.Capacity,
×
NEW
685
                &i.BitcoinKey1,
×
NEW
686
                &i.BitcoinKey2,
×
NEW
687
                &i.Node1Signature,
×
NEW
688
                &i.Node2Signature,
×
NEW
689
                &i.Bitcoin1Signature,
×
NEW
690
                &i.Bitcoin2Signature,
×
NEW
691
                &i.Node1ID,
×
NEW
692
                &i.Node1Version,
×
NEW
693
                &i.Node1PubKey,
×
NEW
694
                &i.Node1Alias,
×
NEW
695
                &i.Node1LastUpdate,
×
NEW
696
                &i.Node1Color,
×
NEW
697
                &i.Node1AnnSignature,
×
NEW
698
                &i.Node2ID,
×
NEW
699
                &i.Node2Version,
×
NEW
700
                &i.Node2PubKey,
×
NEW
701
                &i.Node2Alias,
×
NEW
702
                &i.Node2LastUpdate,
×
NEW
703
                &i.Node2Color,
×
NEW
704
                &i.Node2AnnSignature,
×
NEW
705
                &i.Policy1ID,
×
NEW
706
                &i.Policy1NodeID,
×
NEW
707
                &i.Policy1Version,
×
NEW
708
                &i.Policy1Timelock,
×
NEW
709
                &i.Policy1FeePpm,
×
NEW
710
                &i.Policy1BaseFeeMsat,
×
NEW
711
                &i.Policy1MinHtlcMsat,
×
NEW
712
                &i.Policy1MaxHtlcMsat,
×
NEW
713
                &i.Policy1LastUpdate,
×
NEW
714
                &i.Policy1Disabled,
×
NEW
715
                &i.Policy1InboundBaseFeeMsat,
×
NEW
716
                &i.Policy1InboundFeeRateMilliMsat,
×
NEW
717
                &i.Policy1Signature,
×
NEW
718
                &i.Policy2ID,
×
NEW
719
                &i.Policy2NodeID,
×
NEW
720
                &i.Policy2Version,
×
NEW
721
                &i.Policy2Timelock,
×
NEW
722
                &i.Policy2FeePpm,
×
NEW
723
                &i.Policy2BaseFeeMsat,
×
NEW
724
                &i.Policy2MinHtlcMsat,
×
NEW
725
                &i.Policy2MaxHtlcMsat,
×
NEW
726
                &i.Policy2LastUpdate,
×
NEW
727
                &i.Policy2Disabled,
×
NEW
728
                &i.Policy2InboundBaseFeeMsat,
×
NEW
729
                &i.Policy2InboundFeeRateMilliMsat,
×
NEW
730
                &i.Policy2Signature,
×
NEW
731
        )
×
NEW
732
        return i, err
×
733
}
×
734

735
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
736
SELECT
737
    cf.channel_id,
738
    'feature' AS kind,
739
    CAST(cf.feature_bit AS TEXT) AS key,
740
    NULL AS value
741
FROM channel_features cf
742
WHERE cf.channel_id = $1
743

744
UNION ALL
745

746
SELECT
747
    cet.channel_id,
748
    'extra' AS kind,
749
    CAST(cet.type AS TEXT) AS key,
750
    cet.value
751
FROM channel_extra_types cet
752
WHERE cet.channel_id = $1
753
`
754

755
type GetChannelFeaturesAndExtrasRow struct {
756
        ChannelID int64
757
        Kind      string
758
        Key       string
759
        Value     interface{}
760
}
761

NEW
762
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
NEW
763
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
764
        if err != nil {
×
765
                return nil, err
×
766
        }
×
767
        defer rows.Close()
×
NEW
768
        var items []GetChannelFeaturesAndExtrasRow
×
769
        for rows.Next() {
×
NEW
770
                var i GetChannelFeaturesAndExtrasRow
×
NEW
771
                if err := rows.Scan(
×
NEW
772
                        &i.ChannelID,
×
NEW
773
                        &i.Kind,
×
NEW
774
                        &i.Key,
×
NEW
775
                        &i.Value,
×
NEW
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 getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
791
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
792
FROM channel_policies
793
WHERE channel_id = $1
794
  AND node_id = $2
795
  AND version = $3
796
`
797

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

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

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

839
type GetChannelPolicyExtraTypesParams struct {
840
        ID   int64
841
        ID_2 int64
842
}
843

844
type GetChannelPolicyExtraTypesRow struct {
845
        PolicyID  int64
846
        ChannelID int64
847
        NodeID    int64
848
        Type      int64
849
        Value     []byte
850
}
851

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

881
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
882
SELECT
883
    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,
884

885
    -- Node1 (n1)
886
    n1.id AS node1_id,
887
    n1.version AS node1_version,
888
    n1.pub_key AS node1_pub_key,
889
    n1.alias AS node1_alias,
890
    n1.last_update AS node1_last_update,
891
    n1.color AS node1_color,
892
    n1.signature AS node1_ann_signature,
893

894
    -- Node2 (n2)
895
    n2.id AS node2_id,
896
    n2.version AS node2_version,
897
    n2.pub_key AS node2_pub_key,
898
    n2.alias AS node2_alias,
899
    n2.last_update AS node2_last_update,
900
    n2.color AS node2_color,
901
    n2.signature AS node2_ann_signature,
902

903
    -- Policy 1 (node_id_1)
904
    cp1.id AS policy1_id,
905
    cp1.node_id AS policy1_node_id,
906
    cp1.version AS policy1_version,
907
    cp1.timelock AS policy1_timelock,
908
    cp1.fee_ppm AS policy1_fee_ppm,
909
    cp1.base_fee_msat AS policy1_base_fee_msat,
910
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
911
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
912
    cp1.last_update AS policy1_last_update,
913
    cp1.disabled AS policy1_disabled,
914
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
915
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
916
    cp1.signature AS policy1_signature,
917

918
    -- Policy 2 (node_id_2)
919
    cp2.id AS policy2_id,
920
    cp2.node_id AS policy2_node_id,
921
    cp2.version AS policy2_version,
922
    cp2.timelock AS policy2_timelock,
923
    cp2.fee_ppm AS policy2_fee_ppm,
924
    cp2.base_fee_msat AS policy2_base_fee_msat,
925
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
926
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
927
    cp2.last_update AS policy2_last_update,
928
    cp2.disabled AS policy2_disabled,
929
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
930
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
931
    cp2.signature AS policy2_signature
932

933
FROM channels c
934
    JOIN nodes n1 ON c.node_id_1 = n1.id
935
    JOIN nodes n2 ON c.node_id_2 = n2.id
936
    LEFT JOIN channel_policies cp1
937
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
938
    LEFT JOIN channel_policies cp2
939
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
940
WHERE c.version = $1
941
  AND (cp1.last_update >= $2 AND cp1.last_update < $3
942
    OR cp2.last_update >= $2 AND cp2.last_update < $3)
943
ORDER BY
944
    CASE
945
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
946
            THEN COALESCE(cp1.last_update, 0)
947
        ELSE COALESCE(cp2.last_update, 0)
948
        END ASC
949
`
950

951
type GetChannelsByPolicyLastUpdateRangeParams struct {
952
        Version   int16
953
        StartTime sql.NullInt64
954
        EndTime   sql.NullInt64
955
}
956

957
type GetChannelsByPolicyLastUpdateRangeRow struct {
958
        ID                             int64
959
        Version                        int16
960
        Scid                           []byte
961
        NodeID1                        int64
962
        NodeID2                        int64
963
        Outpoint                       string
964
        Capacity                       sql.NullInt64
965
        BitcoinKey1                    []byte
966
        BitcoinKey2                    []byte
967
        Node1Signature                 []byte
968
        Node2Signature                 []byte
969
        Bitcoin1Signature              []byte
970
        Bitcoin2Signature              []byte
971
        Node1ID                        int64
972
        Node1Version                   int16
973
        Node1PubKey                    []byte
974
        Node1Alias                     sql.NullString
975
        Node1LastUpdate                sql.NullInt64
976
        Node1Color                     sql.NullString
977
        Node1AnnSignature              []byte
978
        Node2ID                        int64
979
        Node2Version                   int16
980
        Node2PubKey                    []byte
981
        Node2Alias                     sql.NullString
982
        Node2LastUpdate                sql.NullInt64
983
        Node2Color                     sql.NullString
984
        Node2AnnSignature              []byte
985
        Policy1ID                      sql.NullInt64
986
        Policy1NodeID                  sql.NullInt64
987
        Policy1Version                 sql.NullInt16
988
        Policy1Timelock                sql.NullInt32
989
        Policy1FeePpm                  sql.NullInt64
990
        Policy1BaseFeeMsat             sql.NullInt64
991
        Policy1MinHtlcMsat             sql.NullInt64
992
        Policy1MaxHtlcMsat             sql.NullInt64
993
        Policy1LastUpdate              sql.NullInt64
994
        Policy1Disabled                sql.NullBool
995
        Policy1InboundBaseFeeMsat      sql.NullInt64
996
        Policy1InboundFeeRateMilliMsat sql.NullInt64
997
        Policy1Signature               []byte
998
        Policy2ID                      sql.NullInt64
999
        Policy2NodeID                  sql.NullInt64
1000
        Policy2Version                 sql.NullInt16
1001
        Policy2Timelock                sql.NullInt32
1002
        Policy2FeePpm                  sql.NullInt64
1003
        Policy2BaseFeeMsat             sql.NullInt64
1004
        Policy2MinHtlcMsat             sql.NullInt64
1005
        Policy2MaxHtlcMsat             sql.NullInt64
1006
        Policy2LastUpdate              sql.NullInt64
1007
        Policy2Disabled                sql.NullBool
1008
        Policy2InboundBaseFeeMsat      sql.NullInt64
1009
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1010
        Policy2Signature               []byte
1011
}
1012

NEW
1013
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
NEW
1014
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
NEW
1015
        if err != nil {
×
NEW
1016
                return nil, err
×
NEW
1017
        }
×
NEW
1018
        defer rows.Close()
×
NEW
1019
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
NEW
1020
        for rows.Next() {
×
NEW
1021
                var i GetChannelsByPolicyLastUpdateRangeRow
×
NEW
1022
                if err := rows.Scan(
×
NEW
1023
                        &i.ID,
×
NEW
1024
                        &i.Version,
×
NEW
1025
                        &i.Scid,
×
NEW
1026
                        &i.NodeID1,
×
NEW
1027
                        &i.NodeID2,
×
NEW
1028
                        &i.Outpoint,
×
NEW
1029
                        &i.Capacity,
×
NEW
1030
                        &i.BitcoinKey1,
×
NEW
1031
                        &i.BitcoinKey2,
×
NEW
1032
                        &i.Node1Signature,
×
NEW
1033
                        &i.Node2Signature,
×
NEW
1034
                        &i.Bitcoin1Signature,
×
NEW
1035
                        &i.Bitcoin2Signature,
×
NEW
1036
                        &i.Node1ID,
×
NEW
1037
                        &i.Node1Version,
×
NEW
1038
                        &i.Node1PubKey,
×
NEW
1039
                        &i.Node1Alias,
×
NEW
1040
                        &i.Node1LastUpdate,
×
NEW
1041
                        &i.Node1Color,
×
NEW
1042
                        &i.Node1AnnSignature,
×
NEW
1043
                        &i.Node2ID,
×
NEW
1044
                        &i.Node2Version,
×
NEW
1045
                        &i.Node2PubKey,
×
NEW
1046
                        &i.Node2Alias,
×
NEW
1047
                        &i.Node2LastUpdate,
×
NEW
1048
                        &i.Node2Color,
×
NEW
1049
                        &i.Node2AnnSignature,
×
NEW
1050
                        &i.Policy1ID,
×
NEW
1051
                        &i.Policy1NodeID,
×
NEW
1052
                        &i.Policy1Version,
×
NEW
1053
                        &i.Policy1Timelock,
×
NEW
1054
                        &i.Policy1FeePpm,
×
NEW
1055
                        &i.Policy1BaseFeeMsat,
×
NEW
1056
                        &i.Policy1MinHtlcMsat,
×
NEW
1057
                        &i.Policy1MaxHtlcMsat,
×
NEW
1058
                        &i.Policy1LastUpdate,
×
NEW
1059
                        &i.Policy1Disabled,
×
NEW
1060
                        &i.Policy1InboundBaseFeeMsat,
×
NEW
1061
                        &i.Policy1InboundFeeRateMilliMsat,
×
NEW
1062
                        &i.Policy1Signature,
×
NEW
1063
                        &i.Policy2ID,
×
NEW
1064
                        &i.Policy2NodeID,
×
NEW
1065
                        &i.Policy2Version,
×
NEW
1066
                        &i.Policy2Timelock,
×
NEW
1067
                        &i.Policy2FeePpm,
×
NEW
1068
                        &i.Policy2BaseFeeMsat,
×
NEW
1069
                        &i.Policy2MinHtlcMsat,
×
NEW
1070
                        &i.Policy2MaxHtlcMsat,
×
NEW
1071
                        &i.Policy2LastUpdate,
×
NEW
1072
                        &i.Policy2Disabled,
×
NEW
1073
                        &i.Policy2InboundBaseFeeMsat,
×
NEW
1074
                        &i.Policy2InboundFeeRateMilliMsat,
×
NEW
1075
                        &i.Policy2Signature,
×
NEW
1076
                ); err != nil {
×
NEW
1077
                        return nil, err
×
NEW
1078
                }
×
NEW
1079
                items = append(items, i)
×
1080
        }
NEW
1081
        if err := rows.Close(); err != nil {
×
NEW
1082
                return nil, err
×
NEW
1083
        }
×
NEW
1084
        if err := rows.Err(); err != nil {
×
NEW
1085
                return nil, err
×
NEW
1086
        }
×
NEW
1087
        return items, nil
×
1088
}
1089

1090
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
1091
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,
1092
    n1.pub_key AS node1_pub_key,
1093
    n2.pub_key AS node2_pub_key
1094
FROM channels c
1095
    JOIN nodes n1 ON c.node_id_1 = n1.id
1096
    JOIN nodes n2 ON c.node_id_2 = n2.id
1097
WHERE scid >= $1
1098
  AND scid < $2
1099
`
1100

1101
type GetChannelsBySCIDRangeParams struct {
1102
        StartScid []byte
1103
        EndScid   []byte
1104
}
1105

1106
type GetChannelsBySCIDRangeRow struct {
1107
        ID                int64
1108
        Version           int16
1109
        Scid              []byte
1110
        NodeID1           int64
1111
        NodeID2           int64
1112
        Outpoint          string
1113
        Capacity          sql.NullInt64
1114
        BitcoinKey1       []byte
1115
        BitcoinKey2       []byte
1116
        Node1Signature    []byte
1117
        Node2Signature    []byte
1118
        Bitcoin1Signature []byte
1119
        Bitcoin2Signature []byte
1120
        Node1PubKey       []byte
1121
        Node2PubKey       []byte
1122
}
1123

NEW
1124
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
×
NEW
1125
        rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
×
NEW
1126
        if err != nil {
×
NEW
1127
                return nil, err
×
NEW
1128
        }
×
NEW
1129
        defer rows.Close()
×
NEW
1130
        var items []GetChannelsBySCIDRangeRow
×
NEW
1131
        for rows.Next() {
×
NEW
1132
                var i GetChannelsBySCIDRangeRow
×
NEW
1133
                if err := rows.Scan(
×
NEW
1134
                        &i.ID,
×
NEW
1135
                        &i.Version,
×
NEW
1136
                        &i.Scid,
×
NEW
1137
                        &i.NodeID1,
×
NEW
1138
                        &i.NodeID2,
×
NEW
1139
                        &i.Outpoint,
×
NEW
1140
                        &i.Capacity,
×
NEW
1141
                        &i.BitcoinKey1,
×
NEW
1142
                        &i.BitcoinKey2,
×
NEW
1143
                        &i.Node1Signature,
×
NEW
1144
                        &i.Node2Signature,
×
NEW
1145
                        &i.Bitcoin1Signature,
×
NEW
1146
                        &i.Bitcoin2Signature,
×
NEW
1147
                        &i.Node1PubKey,
×
NEW
1148
                        &i.Node2PubKey,
×
NEW
1149
                ); err != nil {
×
NEW
1150
                        return nil, err
×
NEW
1151
                }
×
NEW
1152
                items = append(items, i)
×
1153
        }
NEW
1154
        if err := rows.Close(); err != nil {
×
NEW
1155
                return nil, err
×
NEW
1156
        }
×
NEW
1157
        if err := rows.Err(); err != nil {
×
NEW
1158
                return nil, err
×
NEW
1159
        }
×
NEW
1160
        return items, nil
×
1161
}
1162

1163
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
1164
SELECT node_id, type, value
1165
FROM node_extra_types
1166
WHERE node_id = $1
1167
`
1168

NEW
1169
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
NEW
1170
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
NEW
1171
        if err != nil {
×
NEW
1172
                return nil, err
×
NEW
1173
        }
×
NEW
1174
        defer rows.Close()
×
NEW
1175
        var items []NodeExtraType
×
NEW
1176
        for rows.Next() {
×
NEW
1177
                var i NodeExtraType
×
NEW
1178
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
NEW
1179
                        return nil, err
×
NEW
1180
                }
×
NEW
1181
                items = append(items, i)
×
1182
        }
NEW
1183
        if err := rows.Close(); err != nil {
×
NEW
1184
                return nil, err
×
NEW
1185
        }
×
NEW
1186
        if err := rows.Err(); err != nil {
×
NEW
1187
                return nil, err
×
NEW
1188
        }
×
NEW
1189
        return items, nil
×
1190
}
1191

1192
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
1193
SELECT a.type, a.address
1194
FROM nodes n
1195
LEFT JOIN node_addresses a ON a.node_id = n.id
1196
WHERE n.pub_key = $1 AND n.version = $2
1197
ORDER BY a.type ASC, a.position ASC
1198
`
1199

1200
type GetNodeAddressesByPubKeyParams struct {
1201
        PubKey  []byte
1202
        Version int16
1203
}
1204

1205
type GetNodeAddressesByPubKeyRow struct {
1206
        Type    sql.NullInt16
1207
        Address sql.NullString
1208
}
1209

NEW
1210
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
NEW
1211
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
NEW
1212
        if err != nil {
×
NEW
1213
                return nil, err
×
NEW
1214
        }
×
NEW
1215
        defer rows.Close()
×
NEW
1216
        var items []GetNodeAddressesByPubKeyRow
×
NEW
1217
        for rows.Next() {
×
NEW
1218
                var i GetNodeAddressesByPubKeyRow
×
NEW
1219
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
NEW
1220
                        return nil, err
×
NEW
1221
                }
×
NEW
1222
                items = append(items, i)
×
1223
        }
NEW
1224
        if err := rows.Close(); err != nil {
×
NEW
1225
                return nil, err
×
NEW
1226
        }
×
NEW
1227
        if err := rows.Err(); err != nil {
×
NEW
1228
                return nil, err
×
NEW
1229
        }
×
NEW
1230
        return items, nil
×
1231
}
1232

1233
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
1234
SELECT id, version, pub_key, alias, last_update, color, signature
1235
FROM nodes
1236
WHERE pub_key = $1
1237
  AND version = $2
1238
`
1239

1240
type GetNodeByPubKeyParams struct {
1241
        PubKey  []byte
1242
        Version int16
1243
}
1244

NEW
1245
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
NEW
1246
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
NEW
1247
        var i Node
×
NEW
1248
        err := row.Scan(
×
NEW
1249
                &i.ID,
×
NEW
1250
                &i.Version,
×
NEW
1251
                &i.PubKey,
×
NEW
1252
                &i.Alias,
×
NEW
1253
                &i.LastUpdate,
×
NEW
1254
                &i.Color,
×
NEW
1255
                &i.Signature,
×
NEW
1256
        )
×
NEW
1257
        return i, err
×
NEW
1258
}
×
1259

1260
const getNodeFeatures = `-- name: GetNodeFeatures :many
1261
SELECT node_id, feature_bit
1262
FROM node_features
1263
WHERE node_id = $1
1264
`
1265

NEW
1266
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
NEW
1267
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
NEW
1268
        if err != nil {
×
NEW
1269
                return nil, err
×
NEW
1270
        }
×
NEW
1271
        defer rows.Close()
×
NEW
1272
        var items []NodeFeature
×
NEW
1273
        for rows.Next() {
×
NEW
1274
                var i NodeFeature
×
NEW
1275
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
NEW
1276
                        return nil, err
×
NEW
1277
                }
×
NEW
1278
                items = append(items, i)
×
1279
        }
NEW
1280
        if err := rows.Close(); err != nil {
×
NEW
1281
                return nil, err
×
NEW
1282
        }
×
NEW
1283
        if err := rows.Err(); err != nil {
×
NEW
1284
                return nil, err
×
NEW
1285
        }
×
NEW
1286
        return items, nil
×
1287
}
1288

1289
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1290
SELECT f.feature_bit
1291
FROM nodes n
1292
    JOIN node_features f ON f.node_id = n.id
1293
WHERE n.pub_key = $1
1294
  AND n.version = $2
1295
`
1296

1297
type GetNodeFeaturesByPubKeyParams struct {
1298
        PubKey  []byte
1299
        Version int16
1300
}
1301

1302
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1303
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1304
        if err != nil {
×
1305
                return nil, err
×
1306
        }
×
1307
        defer rows.Close()
×
1308
        var items []int32
×
1309
        for rows.Next() {
×
1310
                var feature_bit int32
×
1311
                if err := rows.Scan(&feature_bit); err != nil {
×
1312
                        return nil, err
×
1313
                }
×
1314
                items = append(items, feature_bit)
×
1315
        }
1316
        if err := rows.Close(); err != nil {
×
1317
                return nil, err
×
1318
        }
×
1319
        if err := rows.Err(); err != nil {
×
1320
                return nil, err
×
1321
        }
×
1322
        return items, nil
×
1323
}
1324

1325
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1326
SELECT id, version, pub_key, alias, last_update, color, signature
1327
FROM nodes
1328
WHERE last_update >= $1
1329
  AND last_update < $2
1330
`
1331

1332
type GetNodesByLastUpdateRangeParams struct {
1333
        StartTime sql.NullInt64
1334
        EndTime   sql.NullInt64
1335
}
1336

1337
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
1338
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1339
        if err != nil {
×
1340
                return nil, err
×
1341
        }
×
1342
        defer rows.Close()
×
1343
        var items []Node
×
1344
        for rows.Next() {
×
1345
                var i Node
×
1346
                if err := rows.Scan(
×
1347
                        &i.ID,
×
1348
                        &i.Version,
×
1349
                        &i.PubKey,
×
1350
                        &i.Alias,
×
1351
                        &i.LastUpdate,
×
1352
                        &i.Color,
×
1353
                        &i.Signature,
×
1354
                ); err != nil {
×
1355
                        return nil, err
×
1356
                }
×
1357
                items = append(items, i)
×
1358
        }
1359
        if err := rows.Close(); err != nil {
×
1360
                return nil, err
×
1361
        }
×
1362
        if err := rows.Err(); err != nil {
×
1363
                return nil, err
×
1364
        }
×
1365
        return items, nil
×
1366
}
1367

1368
const getPruneTip = `-- name: GetPruneTip :one
1369
SELECT block_height, block_hash
1370
FROM prune_log
1371
ORDER BY block_height DESC
1372
LIMIT 1
1373
`
1374

NEW
1375
func (q *Queries) GetPruneTip(ctx context.Context) (PruneLog, error) {
×
NEW
1376
        row := q.db.QueryRowContext(ctx, getPruneTip)
×
NEW
1377
        var i PruneLog
×
NEW
1378
        err := row.Scan(&i.BlockHeight, &i.BlockHash)
×
NEW
1379
        return i, err
×
NEW
1380
}
×
1381

1382
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1383
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
1384
FROM channels
1385
WHERE node_1_signature IS NOT NULL
1386
  AND scid >= $1
1387
  AND scid < $2
1388
`
1389

1390
type GetPublicV1ChannelsBySCIDParams struct {
1391
        StartScid []byte
1392
        EndScid   []byte
1393
}
1394

NEW
1395
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
×
NEW
1396
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
NEW
1397
        if err != nil {
×
NEW
1398
                return nil, err
×
NEW
1399
        }
×
NEW
1400
        defer rows.Close()
×
NEW
1401
        var items []Channel
×
NEW
1402
        for rows.Next() {
×
NEW
1403
                var i Channel
×
NEW
1404
                if err := rows.Scan(
×
NEW
1405
                        &i.ID,
×
NEW
1406
                        &i.Version,
×
NEW
1407
                        &i.Scid,
×
NEW
1408
                        &i.NodeID1,
×
NEW
1409
                        &i.NodeID2,
×
NEW
1410
                        &i.Outpoint,
×
NEW
1411
                        &i.Capacity,
×
NEW
1412
                        &i.BitcoinKey1,
×
NEW
1413
                        &i.BitcoinKey2,
×
NEW
1414
                        &i.Node1Signature,
×
NEW
1415
                        &i.Node2Signature,
×
NEW
1416
                        &i.Bitcoin1Signature,
×
NEW
1417
                        &i.Bitcoin2Signature,
×
NEW
1418
                ); err != nil {
×
NEW
1419
                        return nil, err
×
NEW
1420
                }
×
NEW
1421
                items = append(items, i)
×
1422
        }
NEW
1423
        if err := rows.Close(); err != nil {
×
NEW
1424
                return nil, err
×
NEW
1425
        }
×
NEW
1426
        if err := rows.Err(); err != nil {
×
NEW
1427
                return nil, err
×
NEW
1428
        }
×
NEW
1429
        return items, nil
×
1430
}
1431

1432
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1433
SELECT scid from channels
1434
WHERE outpoint = $1 AND version = $2
1435
`
1436

1437
type GetSCIDByOutpointParams struct {
1438
        Outpoint string
1439
        Version  int16
1440
}
1441

NEW
1442
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
NEW
1443
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
NEW
1444
        var scid []byte
×
NEW
1445
        err := row.Scan(&scid)
×
NEW
1446
        return scid, err
×
NEW
1447
}
×
1448

1449
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1450
SELECT sn.node_id, n.pub_key
1451
FROM source_nodes sn
1452
    JOIN nodes n ON sn.node_id = n.id
1453
WHERE n.version = $1
1454
`
1455

1456
type GetSourceNodesByVersionRow struct {
1457
        NodeID int64
1458
        PubKey []byte
1459
}
1460

1461
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1462
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1463
        if err != nil {
×
1464
                return nil, err
×
1465
        }
×
1466
        defer rows.Close()
×
1467
        var items []GetSourceNodesByVersionRow
×
1468
        for rows.Next() {
×
1469
                var i GetSourceNodesByVersionRow
×
1470
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1471
                        return nil, err
×
1472
                }
×
1473
                items = append(items, i)
×
1474
        }
1475
        if err := rows.Close(); err != nil {
×
1476
                return nil, err
×
1477
        }
×
1478
        if err := rows.Err(); err != nil {
×
1479
                return nil, err
×
1480
        }
×
1481
        return items, nil
×
1482
}
1483

1484
const getUnconnectedNodes = `-- name: GetUnconnectedNodes :many
1485
SELECT n.id, n.pub_key
1486
FROM nodes n
1487
WHERE NOT EXISTS (SELECT 1
1488
    FROM channels c
1489
    WHERE c.node_id_1 = n.id
1490
    OR c.node_id_2 = n.id
1491
)
1492
`
1493

1494
type GetUnconnectedNodesRow struct {
1495
        ID     int64
1496
        PubKey []byte
1497
}
1498

NEW
1499
func (q *Queries) GetUnconnectedNodes(ctx context.Context) ([]GetUnconnectedNodesRow, error) {
×
NEW
1500
        rows, err := q.db.QueryContext(ctx, getUnconnectedNodes)
×
NEW
1501
        if err != nil {
×
NEW
1502
                return nil, err
×
NEW
1503
        }
×
NEW
1504
        defer rows.Close()
×
NEW
1505
        var items []GetUnconnectedNodesRow
×
NEW
1506
        for rows.Next() {
×
NEW
1507
                var i GetUnconnectedNodesRow
×
NEW
1508
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
NEW
1509
                        return nil, err
×
NEW
1510
                }
×
NEW
1511
                items = append(items, i)
×
1512
        }
NEW
1513
        if err := rows.Close(); err != nil {
×
NEW
1514
                return nil, err
×
NEW
1515
        }
×
NEW
1516
        if err := rows.Err(); err != nil {
×
NEW
1517
                return nil, err
×
NEW
1518
        }
×
NEW
1519
        return items, nil
×
1520
}
1521

1522
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1523
SELECT c.scid
1524
FROM channels c
1525
    JOIN channel_policies cp ON cp.channel_id = c.id
1526
WHERE cp.disabled = true
1527
GROUP BY c.scid
1528
HAVING COUNT(*) > 1
1529
`
1530

NEW
1531
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
NEW
1532
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
NEW
1533
        if err != nil {
×
NEW
1534
                return nil, err
×
NEW
1535
        }
×
NEW
1536
        defer rows.Close()
×
NEW
1537
        var items [][]byte
×
NEW
1538
        for rows.Next() {
×
NEW
1539
                var scid []byte
×
NEW
1540
                if err := rows.Scan(&scid); err != nil {
×
NEW
1541
                        return nil, err
×
NEW
1542
                }
×
NEW
1543
                items = append(items, scid)
×
1544
        }
NEW
1545
        if err := rows.Close(); err != nil {
×
NEW
1546
                return nil, err
×
NEW
1547
        }
×
NEW
1548
        if err := rows.Err(); err != nil {
×
NEW
1549
                return nil, err
×
NEW
1550
        }
×
NEW
1551
        return items, nil
×
1552
}
1553

1554
const getZombieChannel = `-- name: GetZombieChannel :one
1555
SELECT scid, version, node_key_1, node_key_2
1556
FROM zombie_channels
1557
WHERE scid = $1
1558
  AND version = $2
1559
`
1560

1561
type GetZombieChannelParams struct {
1562
        Scid    int64
1563
        Version int16
1564
}
1565

NEW
1566
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) {
×
NEW
1567
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
NEW
1568
        var i ZombieChannel
×
NEW
1569
        err := row.Scan(
×
NEW
1570
                &i.Scid,
×
NEW
1571
                &i.Version,
×
NEW
1572
                &i.NodeKey1,
×
NEW
1573
                &i.NodeKey2,
×
NEW
1574
        )
×
NEW
1575
        return i, err
×
NEW
1576
}
×
1577

1578
const highestSCID = `-- name: HighestSCID :one
1579
SELECT scid
1580
FROM channels
1581
WHERE version = $1
1582
ORDER BY scid DESC
1583
LIMIT 1
1584
`
1585

1586
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1587
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1588
        var scid []byte
×
1589
        err := row.Scan(&scid)
×
1590
        return scid, err
×
1591
}
×
1592

1593
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1594
/* ─────────────────────────────────────────────
1595
   channel_features table queries
1596
   ─────────────────────────────────────────────
1597
*/
1598

1599
INSERT INTO channel_features (
1600
    channel_id, feature_bit
1601
) VALUES (
1602
    $1, $2
1603
)
1604
`
1605

1606
type InsertChannelFeatureParams struct {
1607
        ChannelID  int64
1608
        FeatureBit int32
1609
}
1610

1611
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1612
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1613
        return err
×
1614
}
×
1615

1616
const insertClosedChannel = `-- name: InsertClosedChannel :exec
1617
/* ─────────────────────────────────────────────
1618
   closed_scid table queries
1619
   ────────────────────────────────────────────-
1620
*/
1621

1622
INSERT INTO closed_scids (scid)
1623
VALUES ($1)
1624
ON CONFLICT (scid) DO NOTHING
1625
`
1626

NEW
1627
func (q *Queries) InsertClosedChannel(ctx context.Context, scid []byte) error {
×
NEW
1628
        _, err := q.db.ExecContext(ctx, insertClosedChannel, scid)
×
NEW
1629
        return err
×
NEW
1630
}
×
1631

1632
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1633
/* ─────────────────────────────────────────────
1634
   node_addresses table queries
1635
   ─────────────────────────────────────────────
1636
*/
1637

1638
INSERT INTO node_addresses (
1639
    node_id,
1640
    type,
1641
    address,
1642
    position
1643
) VALUES (
1644
    $1, $2, $3, $4
1645
 )
1646
`
1647

1648
type InsertNodeAddressParams struct {
1649
        NodeID   int64
1650
        Type     int16
1651
        Address  string
1652
        Position int32
1653
}
1654

1655
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1656
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1657
                arg.NodeID,
×
1658
                arg.Type,
×
1659
                arg.Address,
×
1660
                arg.Position,
×
1661
        )
×
1662
        return err
×
1663
}
×
1664

1665
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1666
/* ─────────────────────────────────────────────
1667
   node_features table queries
1668
   ─────────────────────────────────────────────
1669
*/
1670

1671
INSERT INTO node_features (
1672
    node_id, feature_bit
1673
) VALUES (
1674
    $1, $2
1675
)
1676
`
1677

1678
type InsertNodeFeatureParams struct {
1679
        NodeID     int64
1680
        FeatureBit int32
1681
}
1682

1683
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1684
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1685
        return err
×
1686
}
×
1687

1688
const isClosedChannel = `-- name: IsClosedChannel :one
1689
SELECT EXISTS (
1690
    SELECT 1
1691
    FROM closed_scids
1692
    WHERE scid = $1
1693
)
1694
`
1695

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

1703
const isPublicV1Node = `-- name: IsPublicV1Node :one
1704
SELECT EXISTS (
1705
    SELECT 1
1706
    FROM channels c
1707
    JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1708
    WHERE c.version = 1
1709
      AND c.bitcoin_1_signature IS NOT NULL
1710
      AND n.pub_key = $1
1711
)
1712
`
1713

NEW
1714
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
NEW
1715
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
NEW
1716
        var exists bool
×
NEW
1717
        err := row.Scan(&exists)
×
NEW
1718
        return exists, err
×
NEW
1719
}
×
1720

1721
const isZombieChannel = `-- name: IsZombieChannel :one
1722
SELECT EXISTS (
1723
    SELECT 1
1724
    FROM zombie_channels
1725
    WHERE scid = $1
1726
    AND version = $2
1727
) AS is_zombie
1728
`
1729

1730
type IsZombieChannelParams struct {
1731
        Scid    int64
1732
        Version int16
1733
}
1734

NEW
1735
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
NEW
1736
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
NEW
1737
        var is_zombie bool
×
NEW
1738
        err := row.Scan(&is_zombie)
×
NEW
1739
        return is_zombie, err
×
NEW
1740
}
×
1741

1742
const listAllChannels = `-- name: ListAllChannels :many
1743
SELECT
1744
    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,
1745

1746
    -- Join node pubkeys
1747
    n1.pub_key AS node1_pubkey,
1748
    n2.pub_key AS node2_pubkey,
1749

1750
    -- Node 1 policy
1751
    cp1.id AS policy_1_id,
1752
    cp1.node_id AS policy_1_node_id,
1753
    cp1.version AS policy_1_version,
1754
    cp1.timelock AS policy_1_timelock,
1755
    cp1.fee_ppm AS policy_1_fee_ppm,
1756
    cp1.base_fee_msat AS policy_1_base_fee_msat,
1757
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
1758
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
1759
    cp1.last_update AS policy_1_last_update,
1760
    cp1.disabled AS policy_1_disabled,
1761
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1762
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1763
    cp1.signature AS policy_1_signature,
1764

1765
    -- Node 2 policy
1766
    cp2.id AS policy_2_id,
1767
    cp2.node_id AS policy_2_node_id,
1768
    cp2.version AS policy_2_version,
1769
    cp2.timelock AS policy_2_timelock,
1770
    cp2.fee_ppm AS policy_2_fee_ppm,
1771
    cp2.base_fee_msat AS policy_2_base_fee_msat,
1772
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
1773
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
1774
    cp2.last_update AS policy_2_last_update,
1775
    cp2.disabled AS policy_2_disabled,
1776
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1777
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1778
    cp2.signature AS policy_2_signature
1779

1780
FROM channels c
1781
         JOIN nodes n1 ON c.node_id_1 = n1.id
1782
         JOIN nodes n2 ON c.node_id_2 = n2.id
1783
         LEFT JOIN channel_policies cp1
1784
                   ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1785
         LEFT JOIN channel_policies cp2
1786
                   ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1787
WHERE c.version = $1
1788
`
1789

1790
type ListAllChannelsRow struct {
1791
        ID                             int64
1792
        Version                        int16
1793
        Scid                           []byte
1794
        NodeID1                        int64
1795
        NodeID2                        int64
1796
        Outpoint                       string
1797
        Capacity                       sql.NullInt64
1798
        BitcoinKey1                    []byte
1799
        BitcoinKey2                    []byte
1800
        Node1Signature                 []byte
1801
        Node2Signature                 []byte
1802
        Bitcoin1Signature              []byte
1803
        Bitcoin2Signature              []byte
1804
        Node1Pubkey                    []byte
1805
        Node2Pubkey                    []byte
1806
        Policy1ID                      sql.NullInt64
1807
        Policy1NodeID                  sql.NullInt64
1808
        Policy1Version                 sql.NullInt16
1809
        Policy1Timelock                sql.NullInt32
1810
        Policy1FeePpm                  sql.NullInt64
1811
        Policy1BaseFeeMsat             sql.NullInt64
1812
        Policy1MinHtlcMsat             sql.NullInt64
1813
        Policy1MaxHtlcMsat             sql.NullInt64
1814
        Policy1LastUpdate              sql.NullInt64
1815
        Policy1Disabled                sql.NullBool
1816
        Policy1InboundBaseFeeMsat      sql.NullInt64
1817
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1818
        Policy1Signature               []byte
1819
        Policy2ID                      sql.NullInt64
1820
        Policy2NodeID                  sql.NullInt64
1821
        Policy2Version                 sql.NullInt16
1822
        Policy2Timelock                sql.NullInt32
1823
        Policy2FeePpm                  sql.NullInt64
1824
        Policy2BaseFeeMsat             sql.NullInt64
1825
        Policy2MinHtlcMsat             sql.NullInt64
1826
        Policy2MaxHtlcMsat             sql.NullInt64
1827
        Policy2LastUpdate              sql.NullInt64
1828
        Policy2Disabled                sql.NullBool
1829
        Policy2InboundBaseFeeMsat      sql.NullInt64
1830
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1831
        Policy2Signature               []byte
1832
}
1833

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

1899
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1900
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,
1901
    n1.pub_key AS node1_pubkey,
1902
    n2.pub_key AS node2_pubkey,
1903

1904
    -- Policy 1
1905
    cp1.id AS policy1_id,
1906
    cp1.node_id AS policy1_node_id,
1907
    cp1.version AS policy1_version,
1908
    cp1.timelock AS policy1_timelock,
1909
    cp1.fee_ppm AS policy1_fee_ppm,
1910
    cp1.base_fee_msat AS policy1_base_fee_msat,
1911
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1912
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1913
    cp1.last_update AS policy1_last_update,
1914
    cp1.disabled AS policy1_disabled,
1915
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1916
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1917
    cp1.signature AS policy1_signature,
1918

1919
    -- Policy 2
1920
    cp2.id AS policy2_id,
1921
    cp2.node_id AS policy2_node_id,
1922
    cp2.version AS policy2_version,
1923
    cp2.timelock AS policy2_timelock,
1924
    cp2.fee_ppm AS policy2_fee_ppm,
1925
    cp2.base_fee_msat AS policy2_base_fee_msat,
1926
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1927
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1928
    cp2.last_update AS policy2_last_update,
1929
    cp2.disabled AS policy2_disabled,
1930
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1931
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1932
    cp2.signature AS policy2_signature
1933

1934
FROM channels c
1935
JOIN nodes n1 ON c.node_id_1 = n1.id
1936
JOIN nodes n2 ON c.node_id_2 = n2.id
1937
LEFT JOIN channel_policies cp1
1938
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1939
LEFT JOIN channel_policies cp2
1940
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1941
WHERE c.version = $1
1942
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1943
`
1944

1945
type ListChannelsByNodeIDParams struct {
1946
        Version int16
1947
        NodeID1 int64
1948
}
1949

1950
type ListChannelsByNodeIDRow struct {
1951
        ID                             int64
1952
        Version                        int16
1953
        Scid                           []byte
1954
        NodeID1                        int64
1955
        NodeID2                        int64
1956
        Outpoint                       string
1957
        Capacity                       sql.NullInt64
1958
        BitcoinKey1                    []byte
1959
        BitcoinKey2                    []byte
1960
        Node1Signature                 []byte
1961
        Node2Signature                 []byte
1962
        Bitcoin1Signature              []byte
1963
        Bitcoin2Signature              []byte
1964
        Node1Pubkey                    []byte
1965
        Node2Pubkey                    []byte
1966
        Policy1ID                      sql.NullInt64
1967
        Policy1NodeID                  sql.NullInt64
1968
        Policy1Version                 sql.NullInt16
1969
        Policy1Timelock                sql.NullInt32
1970
        Policy1FeePpm                  sql.NullInt64
1971
        Policy1BaseFeeMsat             sql.NullInt64
1972
        Policy1MinHtlcMsat             sql.NullInt64
1973
        Policy1MaxHtlcMsat             sql.NullInt64
1974
        Policy1LastUpdate              sql.NullInt64
1975
        Policy1Disabled                sql.NullBool
1976
        Policy1InboundBaseFeeMsat      sql.NullInt64
1977
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1978
        Policy1Signature               []byte
1979
        Policy2ID                      sql.NullInt64
1980
        Policy2NodeID                  sql.NullInt64
1981
        Policy2Version                 sql.NullInt16
1982
        Policy2Timelock                sql.NullInt32
1983
        Policy2FeePpm                  sql.NullInt64
1984
        Policy2BaseFeeMsat             sql.NullInt64
1985
        Policy2MinHtlcMsat             sql.NullInt64
1986
        Policy2MaxHtlcMsat             sql.NullInt64
1987
        Policy2LastUpdate              sql.NullInt64
1988
        Policy2Disabled                sql.NullBool
1989
        Policy2InboundBaseFeeMsat      sql.NullInt64
1990
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1991
        Policy2Signature               []byte
1992
}
1993

NEW
1994
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
NEW
1995
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
NEW
1996
        if err != nil {
×
NEW
1997
                return nil, err
×
NEW
1998
        }
×
NEW
1999
        defer rows.Close()
×
NEW
2000
        var items []ListChannelsByNodeIDRow
×
NEW
2001
        for rows.Next() {
×
NEW
2002
                var i ListChannelsByNodeIDRow
×
NEW
2003
                if err := rows.Scan(
×
NEW
2004
                        &i.ID,
×
NEW
2005
                        &i.Version,
×
NEW
2006
                        &i.Scid,
×
NEW
2007
                        &i.NodeID1,
×
NEW
2008
                        &i.NodeID2,
×
NEW
2009
                        &i.Outpoint,
×
NEW
2010
                        &i.Capacity,
×
NEW
2011
                        &i.BitcoinKey1,
×
NEW
2012
                        &i.BitcoinKey2,
×
NEW
2013
                        &i.Node1Signature,
×
NEW
2014
                        &i.Node2Signature,
×
NEW
2015
                        &i.Bitcoin1Signature,
×
NEW
2016
                        &i.Bitcoin2Signature,
×
NEW
2017
                        &i.Node1Pubkey,
×
NEW
2018
                        &i.Node2Pubkey,
×
NEW
2019
                        &i.Policy1ID,
×
NEW
2020
                        &i.Policy1NodeID,
×
NEW
2021
                        &i.Policy1Version,
×
NEW
2022
                        &i.Policy1Timelock,
×
NEW
2023
                        &i.Policy1FeePpm,
×
NEW
2024
                        &i.Policy1BaseFeeMsat,
×
NEW
2025
                        &i.Policy1MinHtlcMsat,
×
NEW
2026
                        &i.Policy1MaxHtlcMsat,
×
NEW
2027
                        &i.Policy1LastUpdate,
×
NEW
2028
                        &i.Policy1Disabled,
×
NEW
2029
                        &i.Policy1InboundBaseFeeMsat,
×
NEW
2030
                        &i.Policy1InboundFeeRateMilliMsat,
×
NEW
2031
                        &i.Policy1Signature,
×
NEW
2032
                        &i.Policy2ID,
×
NEW
2033
                        &i.Policy2NodeID,
×
NEW
2034
                        &i.Policy2Version,
×
NEW
2035
                        &i.Policy2Timelock,
×
NEW
2036
                        &i.Policy2FeePpm,
×
NEW
2037
                        &i.Policy2BaseFeeMsat,
×
NEW
2038
                        &i.Policy2MinHtlcMsat,
×
NEW
2039
                        &i.Policy2MaxHtlcMsat,
×
NEW
2040
                        &i.Policy2LastUpdate,
×
NEW
2041
                        &i.Policy2Disabled,
×
NEW
2042
                        &i.Policy2InboundBaseFeeMsat,
×
NEW
2043
                        &i.Policy2InboundFeeRateMilliMsat,
×
NEW
2044
                        &i.Policy2Signature,
×
NEW
2045
                ); err != nil {
×
NEW
2046
                        return nil, err
×
NEW
2047
                }
×
NEW
2048
                items = append(items, i)
×
2049
        }
NEW
2050
        if err := rows.Close(); err != nil {
×
NEW
2051
                return nil, err
×
NEW
2052
        }
×
NEW
2053
        if err := rows.Err(); err != nil {
×
NEW
2054
                return nil, err
×
NEW
2055
        }
×
NEW
2056
        return items, nil
×
2057
}
2058

2059
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
2060
SELECT id, pub_key
2061
FROM nodes
2062
WHERE version = $1
2063
`
2064

2065
type ListNodeIDsAndPubKeysRow struct {
2066
        ID     int64
2067
        PubKey []byte
2068
}
2069

NEW
2070
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, version int16) ([]ListNodeIDsAndPubKeysRow, error) {
×
NEW
2071
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, version)
×
NEW
2072
        if err != nil {
×
NEW
2073
                return nil, err
×
NEW
2074
        }
×
NEW
2075
        defer rows.Close()
×
NEW
2076
        var items []ListNodeIDsAndPubKeysRow
×
NEW
2077
        for rows.Next() {
×
NEW
2078
                var i ListNodeIDsAndPubKeysRow
×
NEW
2079
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
NEW
2080
                        return nil, err
×
NEW
2081
                }
×
NEW
2082
                items = append(items, i)
×
2083
        }
NEW
2084
        if err := rows.Close(); err != nil {
×
NEW
2085
                return nil, err
×
NEW
2086
        }
×
NEW
2087
        if err := rows.Err(); err != nil {
×
NEW
2088
                return nil, err
×
NEW
2089
        }
×
NEW
2090
        return items, nil
×
2091
}
2092

2093
const listNodes = `-- name: ListNodes :many
2094
SELECT id, version, pub_key, alias, last_update, color, signature
2095
FROM nodes
2096
WHERE version = $1
2097
`
2098

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

2130
const upsertChanPolicyExtraType = `-- name: UpsertChanPolicyExtraType :exec
2131
/* ─────────────────────────────────────────────
2132
   channel_policy_extra_types table queries
2133
   ─────────────────────────────────────────────
2134
*/
2135

2136
INSERT INTO channel_policy_extra_types (
2137
    channel_policy_id, type, value
2138
)
2139
VALUES ($1, $2, $3)
2140
ON CONFLICT (type, channel_policy_id)
2141
    -- Update the value if a conflict occurs on type
2142
    -- and node_id.
2143
    DO UPDATE SET value = EXCLUDED.value
2144
`
2145

2146
type UpsertChanPolicyExtraTypeParams struct {
2147
        ChannelPolicyID int64
2148
        Type            int64
2149
        Value           []byte
2150
}
2151

NEW
2152
func (q *Queries) UpsertChanPolicyExtraType(ctx context.Context, arg UpsertChanPolicyExtraTypeParams) error {
×
NEW
2153
        _, err := q.db.ExecContext(ctx, upsertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
NEW
2154
        return err
×
NEW
2155
}
×
2156

2157
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
2158
/* ─────────────────────────────────────────────
2159
   channel_policies table queries
2160
   ─────────────────────────────────────────────
2161
*/
2162

2163
INSERT INTO channel_policies (
2164
    version, channel_id, node_id, timelock, fee_ppm,
2165
    base_fee_msat, min_htlc_msat, last_update, disabled,
2166
    max_htlc_msat, inbound_base_fee_msat,
2167
    inbound_fee_rate_milli_msat, signature
2168
) VALUES  (
2169
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
2170
)
2171
ON CONFLICT (channel_id, node_id, version)
2172
    -- Update the following fields if a conflict occurs on channel_id,
2173
    -- node_id, and version.
2174
    DO UPDATE SET
2175
        timelock = EXCLUDED.timelock,
2176
        fee_ppm = EXCLUDED.fee_ppm,
2177
        base_fee_msat = EXCLUDED.base_fee_msat,
2178
        min_htlc_msat = EXCLUDED.min_htlc_msat,
2179
        last_update = EXCLUDED.last_update,
2180
        disabled = EXCLUDED.disabled,
2181
        max_htlc_msat = EXCLUDED.max_htlc_msat,
2182
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
2183
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
2184
        signature = EXCLUDED.signature
2185
WHERE EXCLUDED.last_update > channel_policies.last_update
2186
RETURNING id
2187
`
2188

2189
type UpsertEdgePolicyParams struct {
2190
        Version                 int16
2191
        ChannelID               int64
2192
        NodeID                  int64
2193
        Timelock                int32
2194
        FeePpm                  int64
2195
        BaseFeeMsat             int64
2196
        MinHtlcMsat             int64
2197
        LastUpdate              sql.NullInt64
2198
        Disabled                sql.NullBool
2199
        MaxHtlcMsat             sql.NullInt64
2200
        InboundBaseFeeMsat      sql.NullInt64
2201
        InboundFeeRateMilliMsat sql.NullInt64
2202
        Signature               []byte
2203
}
2204

NEW
2205
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
NEW
2206
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
NEW
2207
                arg.Version,
×
NEW
2208
                arg.ChannelID,
×
NEW
2209
                arg.NodeID,
×
NEW
2210
                arg.Timelock,
×
NEW
2211
                arg.FeePpm,
×
NEW
2212
                arg.BaseFeeMsat,
×
NEW
2213
                arg.MinHtlcMsat,
×
NEW
2214
                arg.LastUpdate,
×
NEW
2215
                arg.Disabled,
×
NEW
2216
                arg.MaxHtlcMsat,
×
NEW
2217
                arg.InboundBaseFeeMsat,
×
NEW
2218
                arg.InboundFeeRateMilliMsat,
×
NEW
2219
                arg.Signature,
×
NEW
2220
        )
×
NEW
2221
        var id int64
×
NEW
2222
        err := row.Scan(&id)
×
NEW
2223
        return id, err
×
NEW
2224
}
×
2225

2226
const upsertNode = `-- name: UpsertNode :one
2227
/* ─────────────────────────────────────────────
2228
   nodes table queries
2229
   ─────────────────────────────────────────────
2230
*/
2231

2232
INSERT INTO nodes (
2233
    version, pub_key, alias, last_update, color, signature
2234
) VALUES (
2235
    $1, $2, $3, $4, $5, $6
2236
)
2237
ON CONFLICT (pub_key, version)
2238
    -- Update the following fields if a conflict occurs on pub_key
2239
    -- and version.
2240
    DO UPDATE SET
2241
        alias = EXCLUDED.alias,
2242
        last_update = EXCLUDED.last_update,
2243
        color = EXCLUDED.color,
2244
        signature = EXCLUDED.signature
2245
WHERE nodes.last_update IS NULL
2246
    OR EXCLUDED.last_update > nodes.last_update
2247
RETURNING id
2248
`
2249

2250
type UpsertNodeParams struct {
2251
        Version    int16
2252
        PubKey     []byte
2253
        Alias      sql.NullString
2254
        LastUpdate sql.NullInt64
2255
        Color      sql.NullString
2256
        Signature  []byte
2257
}
2258

2259
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
2260
        row := q.db.QueryRowContext(ctx, upsertNode,
×
2261
                arg.Version,
×
2262
                arg.PubKey,
×
2263
                arg.Alias,
×
2264
                arg.LastUpdate,
×
2265
                arg.Color,
×
2266
                arg.Signature,
×
2267
        )
×
2268
        var id int64
×
2269
        err := row.Scan(&id)
×
2270
        return id, err
×
2271
}
×
2272

2273
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
2274
/* ─────────────────────────────────────────────
2275
   node_extra_types table queries
2276
   ─────────────────────────────────────────────
2277
*/
2278

2279
INSERT INTO node_extra_types (
2280
    node_id, type, value
2281
)
2282
VALUES ($1, $2, $3)
2283
ON CONFLICT (type, node_id)
2284
    -- Update the value if a conflict occurs on type
2285
    -- and node_id.
2286
    DO UPDATE SET value = EXCLUDED.value
2287
`
2288

2289
type UpsertNodeExtraTypeParams struct {
2290
        NodeID int64
2291
        Type   int64
2292
        Value  []byte
2293
}
2294

2295
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
2296
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
2297
        return err
×
2298
}
×
2299

2300
const upsertPruneLogEntry = `-- name: UpsertPruneLogEntry :exec
2301
/* ─────────────────────────────────────────────
2302
    prune_log table queries
2303
    ─────────────────────────────────────────────
2304
*/
2305

2306
INSERT INTO prune_log (
2307
    block_height, block_hash
2308
) VALUES (
2309
    $1, $2
2310
)
2311
ON CONFLICT(block_height) DO UPDATE SET
2312
    block_hash = EXCLUDED.block_hash
2313
`
2314

2315
type UpsertPruneLogEntryParams struct {
2316
        BlockHeight int64
2317
        BlockHash   []byte
2318
}
2319

NEW
2320
func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEntryParams) error {
×
NEW
2321
        _, err := q.db.ExecContext(ctx, upsertPruneLogEntry, arg.BlockHeight, arg.BlockHash)
×
NEW
2322
        return err
×
NEW
2323
}
×
2324

2325
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
2326
/* ─────────────────────────────────────────────
2327
   zombie_channels table queries
2328
   ─────────────────────────────────────────────
2329
*/
2330

2331
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
2332
VALUES ($1, $2, $3, $4)
2333
ON CONFLICT (scid, version)
2334
    DO UPDATE SET
2335
        node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
2336
        node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2)
2337
`
2338

2339
type UpsertZombieChannelParams struct {
2340
        Scid     int64
2341
        Version  int16
2342
        NodeKey1 []byte
2343
        NodeKey2 []byte
2344
}
2345

NEW
2346
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
NEW
2347
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
NEW
2348
                arg.Scid,
×
NEW
2349
                arg.Version,
×
NEW
2350
                arg.NodeKey1,
×
NEW
2351
                arg.NodeKey2,
×
NEW
2352
        )
×
NEW
2353
        return err
×
NEW
2354
}
×
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