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

lightningnetwork / lnd / 15870115464

25 Jun 2025 07:28AM UTC coverage: 67.8% (-0.2%) from 67.978%
15870115464

push

github

web-flow
Merge pull request #9938 from ellemouton/graphSQL14

[14] graph/db: implement more SQLStore methods

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

57 existing lines in 17 files now uncovered.

135024 of 199149 relevant lines covered (67.8%)

21969.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sqldb/sqlc/graph.sql.go
1
// Code generated by sqlc. DO NOT EDIT.
2
// versions:
3
//   sqlc v1.29.0
4
// source: graph.sql
5

6
package sqlc
7

8
import (
9
        "context"
10
        "database/sql"
11
)
12

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

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

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

29
const countZombieChannels = `-- name: CountZombieChannels :one
30
SELECT COUNT(*)
31
FROM zombie_channels
32
WHERE version = $1
33
`
34

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

152
const deleteNodeAddresses = `-- name: DeleteNodeAddresses :exec
153
DELETE FROM node_addresses
154
WHERE node_id = $1
155
`
156

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

162
const deleteNodeByPubKey = `-- name: DeleteNodeByPubKey :execresult
163
DELETE FROM nodes
164
WHERE pub_key = $1
165
  AND version = $2
166
`
167

168
type DeleteNodeByPubKeyParams struct {
169
        PubKey  []byte
170
        Version int16
171
}
172

173
func (q *Queries) DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error) {
×
174
        return q.db.ExecContext(ctx, deleteNodeByPubKey, arg.PubKey, arg.Version)
×
175
}
×
176

177
const deleteNodeFeature = `-- name: DeleteNodeFeature :exec
178
DELETE FROM node_features
179
WHERE node_id = $1
180
  AND feature_bit = $2
181
`
182

183
type DeleteNodeFeatureParams struct {
184
        NodeID     int64
185
        FeatureBit int32
186
}
187

188
func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error {
×
189
        _, err := q.db.ExecContext(ctx, deleteNodeFeature, arg.NodeID, arg.FeatureBit)
×
190
        return err
×
191
}
×
192

193
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
194
DELETE FROM zombie_channels
195
WHERE scid = $1
196
AND version = $2
197
`
198

199
type DeleteZombieChannelParams struct {
200
        Scid    []byte
201
        Version int16
202
}
203

204
func (q *Queries) DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error) {
×
205
        return q.db.ExecContext(ctx, deleteZombieChannel, arg.Scid, arg.Version)
×
206
}
×
207

208
const getChannelAndNodesBySCID = `-- name: GetChannelAndNodesBySCID :one
209
SELECT
210
    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,
211
    n1.pub_key AS node1_pub_key,
212
    n2.pub_key AS node2_pub_key
213
FROM channels c
214
    JOIN nodes n1 ON c.node_id_1 = n1.id
215
    JOIN nodes n2 ON c.node_id_2 = n2.id
216
WHERE c.scid = $1
217
  AND c.version = $2
218
`
219

220
type GetChannelAndNodesBySCIDParams struct {
221
        Scid    []byte
222
        Version int16
223
}
224

225
type GetChannelAndNodesBySCIDRow struct {
226
        ID                int64
227
        Version           int16
228
        Scid              []byte
229
        NodeID1           int64
230
        NodeID2           int64
231
        Outpoint          string
232
        Capacity          sql.NullInt64
233
        BitcoinKey1       []byte
234
        BitcoinKey2       []byte
235
        Node1Signature    []byte
236
        Node2Signature    []byte
237
        Bitcoin1Signature []byte
238
        Bitcoin2Signature []byte
239
        Node1PubKey       []byte
240
        Node2PubKey       []byte
241
}
242

243
func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error) {
×
244
        row := q.db.QueryRowContext(ctx, getChannelAndNodesBySCID, arg.Scid, arg.Version)
×
245
        var i GetChannelAndNodesBySCIDRow
×
246
        err := row.Scan(
×
247
                &i.ID,
×
248
                &i.Version,
×
249
                &i.Scid,
×
250
                &i.NodeID1,
×
251
                &i.NodeID2,
×
252
                &i.Outpoint,
×
253
                &i.Capacity,
×
254
                &i.BitcoinKey1,
×
255
                &i.BitcoinKey2,
×
256
                &i.Node1Signature,
×
257
                &i.Node2Signature,
×
258
                &i.Bitcoin1Signature,
×
259
                &i.Bitcoin2Signature,
×
260
                &i.Node1PubKey,
×
261
                &i.Node2PubKey,
×
262
        )
×
263
        return i, err
×
264
}
×
265

266
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
267
SELECT
268
    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,
269

270
    n1.pub_key AS node1_pubkey,
271
    n2.pub_key AS node2_pubkey,
272

273
    -- Node 1 policy
274
    cp1.id AS policy_1_id,
275
    cp1.node_id AS policy_1_node_id,
276
    cp1.version AS policy_1_version,
277
    cp1.timelock AS policy_1_timelock,
278
    cp1.fee_ppm AS policy_1_fee_ppm,
279
    cp1.base_fee_msat AS policy_1_base_fee_msat,
280
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
281
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
282
    cp1.last_update AS policy_1_last_update,
283
    cp1.disabled AS policy_1_disabled,
284
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
285
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
286
    cp1.signature AS policy_1_signature,
287

288
    -- Node 2 policy
289
    cp2.id AS policy_2_id,
290
    cp2.node_id AS policy_2_node_id,
291
    cp2.version AS policy_2_version,
292
    cp2.timelock AS policy_2_timelock,
293
    cp2.fee_ppm AS policy_2_fee_ppm,
294
    cp2.base_fee_msat AS policy_2_base_fee_msat,
295
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
296
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
297
    cp2.last_update AS policy_2_last_update,
298
    cp2.disabled AS policy_2_disabled,
299
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
300
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
301
    cp2.signature AS policy_2_signature
302
FROM channels c
303
    JOIN nodes n1 ON c.node_id_1 = n1.id
304
    JOIN nodes n2 ON c.node_id_2 = n2.id
305
    LEFT JOIN channel_policies cp1
306
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
307
    LEFT JOIN channel_policies cp2
308
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
309
WHERE c.outpoint = $1 AND c.version = $2
310
`
311

312
type GetChannelByOutpointWithPoliciesParams struct {
313
        Outpoint string
314
        Version  int16
315
}
316

317
type GetChannelByOutpointWithPoliciesRow struct {
318
        Channel                        Channel
319
        Node1Pubkey                    []byte
320
        Node2Pubkey                    []byte
321
        Policy1ID                      sql.NullInt64
322
        Policy1NodeID                  sql.NullInt64
323
        Policy1Version                 sql.NullInt16
324
        Policy1Timelock                sql.NullInt32
325
        Policy1FeePpm                  sql.NullInt64
326
        Policy1BaseFeeMsat             sql.NullInt64
327
        Policy1MinHtlcMsat             sql.NullInt64
328
        Policy1MaxHtlcMsat             sql.NullInt64
329
        Policy1LastUpdate              sql.NullInt64
330
        Policy1Disabled                sql.NullBool
331
        Policy1InboundBaseFeeMsat      sql.NullInt64
332
        Policy1InboundFeeRateMilliMsat sql.NullInt64
333
        Policy1Signature               []byte
334
        Policy2ID                      sql.NullInt64
335
        Policy2NodeID                  sql.NullInt64
336
        Policy2Version                 sql.NullInt16
337
        Policy2Timelock                sql.NullInt32
338
        Policy2FeePpm                  sql.NullInt64
339
        Policy2BaseFeeMsat             sql.NullInt64
340
        Policy2MinHtlcMsat             sql.NullInt64
341
        Policy2MaxHtlcMsat             sql.NullInt64
342
        Policy2LastUpdate              sql.NullInt64
343
        Policy2Disabled                sql.NullBool
344
        Policy2InboundBaseFeeMsat      sql.NullInt64
345
        Policy2InboundFeeRateMilliMsat sql.NullInt64
346
        Policy2Signature               []byte
347
}
348

NEW
349
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
×
NEW
350
        row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
×
NEW
351
        var i GetChannelByOutpointWithPoliciesRow
×
NEW
352
        err := row.Scan(
×
NEW
353
                &i.Channel.ID,
×
NEW
354
                &i.Channel.Version,
×
NEW
355
                &i.Channel.Scid,
×
NEW
356
                &i.Channel.NodeID1,
×
NEW
357
                &i.Channel.NodeID2,
×
NEW
358
                &i.Channel.Outpoint,
×
NEW
359
                &i.Channel.Capacity,
×
NEW
360
                &i.Channel.BitcoinKey1,
×
NEW
361
                &i.Channel.BitcoinKey2,
×
NEW
362
                &i.Channel.Node1Signature,
×
NEW
363
                &i.Channel.Node2Signature,
×
NEW
364
                &i.Channel.Bitcoin1Signature,
×
NEW
365
                &i.Channel.Bitcoin2Signature,
×
NEW
366
                &i.Node1Pubkey,
×
NEW
367
                &i.Node2Pubkey,
×
NEW
368
                &i.Policy1ID,
×
NEW
369
                &i.Policy1NodeID,
×
NEW
370
                &i.Policy1Version,
×
NEW
371
                &i.Policy1Timelock,
×
NEW
372
                &i.Policy1FeePpm,
×
NEW
373
                &i.Policy1BaseFeeMsat,
×
NEW
374
                &i.Policy1MinHtlcMsat,
×
NEW
375
                &i.Policy1MaxHtlcMsat,
×
NEW
376
                &i.Policy1LastUpdate,
×
NEW
377
                &i.Policy1Disabled,
×
NEW
378
                &i.Policy1InboundBaseFeeMsat,
×
NEW
379
                &i.Policy1InboundFeeRateMilliMsat,
×
NEW
380
                &i.Policy1Signature,
×
NEW
381
                &i.Policy2ID,
×
NEW
382
                &i.Policy2NodeID,
×
NEW
383
                &i.Policy2Version,
×
NEW
384
                &i.Policy2Timelock,
×
NEW
385
                &i.Policy2FeePpm,
×
NEW
386
                &i.Policy2BaseFeeMsat,
×
NEW
387
                &i.Policy2MinHtlcMsat,
×
NEW
388
                &i.Policy2MaxHtlcMsat,
×
NEW
389
                &i.Policy2LastUpdate,
×
NEW
390
                &i.Policy2Disabled,
×
NEW
391
                &i.Policy2InboundBaseFeeMsat,
×
NEW
392
                &i.Policy2InboundFeeRateMilliMsat,
×
NEW
393
                &i.Policy2Signature,
×
NEW
394
        )
×
NEW
395
        return i, err
×
NEW
396
}
×
397

398
const getChannelBySCID = `-- name: GetChannelBySCID :one
399
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
400
WHERE scid = $1 AND version = $2
401
`
402

403
type GetChannelBySCIDParams struct {
404
        Scid    []byte
405
        Version int16
406
}
407

408
func (q *Queries) GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error) {
×
409
        row := q.db.QueryRowContext(ctx, getChannelBySCID, arg.Scid, arg.Version)
×
410
        var i Channel
×
411
        err := row.Scan(
×
412
                &i.ID,
×
413
                &i.Version,
×
414
                &i.Scid,
×
415
                &i.NodeID1,
×
416
                &i.NodeID2,
×
417
                &i.Outpoint,
×
418
                &i.Capacity,
×
419
                &i.BitcoinKey1,
×
420
                &i.BitcoinKey2,
×
421
                &i.Node1Signature,
×
422
                &i.Node2Signature,
×
423
                &i.Bitcoin1Signature,
×
424
                &i.Bitcoin2Signature,
×
425
        )
×
426
        return i, err
×
427
}
×
428

429
const getChannelBySCIDWithPolicies = `-- name: GetChannelBySCIDWithPolicies :one
430
SELECT
431
    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,
432
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
433
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
434

435
    -- Policy 1
436
    cp1.id AS policy1_id,
437
    cp1.node_id AS policy1_node_id,
438
    cp1.version AS policy1_version,
439
    cp1.timelock AS policy1_timelock,
440
    cp1.fee_ppm AS policy1_fee_ppm,
441
    cp1.base_fee_msat AS policy1_base_fee_msat,
442
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
443
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
444
    cp1.last_update AS policy1_last_update,
445
    cp1.disabled AS policy1_disabled,
446
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
447
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
448
    cp1.signature AS policy1_signature,
449

450
    -- Policy 2
451
    cp2.id AS policy2_id,
452
    cp2.node_id AS policy2_node_id,
453
    cp2.version AS policy2_version,
454
    cp2.timelock AS policy2_timelock,
455
    cp2.fee_ppm AS policy2_fee_ppm,
456
    cp2.base_fee_msat AS policy2_base_fee_msat,
457
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
458
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
459
    cp2.last_update AS policy2_last_update,
460
    cp2.disabled AS policy2_disabled,
461
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
462
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
463
    cp2.signature AS policy2_signature
464

465
FROM channels c
466
    JOIN nodes n1 ON c.node_id_1 = n1.id
467
    JOIN nodes n2 ON c.node_id_2 = n2.id
468
    LEFT JOIN channel_policies cp1
469
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
470
    LEFT JOIN channel_policies cp2
471
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
472
WHERE c.scid = $1
473
  AND c.version = $2
474
`
475

476
type GetChannelBySCIDWithPoliciesParams struct {
477
        Scid    []byte
478
        Version int16
479
}
480

481
type GetChannelBySCIDWithPoliciesRow struct {
482
        Channel                        Channel
483
        Node                           Node
484
        Node_2                         Node
485
        Policy1ID                      sql.NullInt64
486
        Policy1NodeID                  sql.NullInt64
487
        Policy1Version                 sql.NullInt16
488
        Policy1Timelock                sql.NullInt32
489
        Policy1FeePpm                  sql.NullInt64
490
        Policy1BaseFeeMsat             sql.NullInt64
491
        Policy1MinHtlcMsat             sql.NullInt64
492
        Policy1MaxHtlcMsat             sql.NullInt64
493
        Policy1LastUpdate              sql.NullInt64
494
        Policy1Disabled                sql.NullBool
495
        Policy1InboundBaseFeeMsat      sql.NullInt64
496
        Policy1InboundFeeRateMilliMsat sql.NullInt64
497
        Policy1Signature               []byte
498
        Policy2ID                      sql.NullInt64
499
        Policy2NodeID                  sql.NullInt64
500
        Policy2Version                 sql.NullInt16
501
        Policy2Timelock                sql.NullInt32
502
        Policy2FeePpm                  sql.NullInt64
503
        Policy2BaseFeeMsat             sql.NullInt64
504
        Policy2MinHtlcMsat             sql.NullInt64
505
        Policy2MaxHtlcMsat             sql.NullInt64
506
        Policy2LastUpdate              sql.NullInt64
507
        Policy2Disabled                sql.NullBool
508
        Policy2InboundBaseFeeMsat      sql.NullInt64
509
        Policy2InboundFeeRateMilliMsat sql.NullInt64
510
        Policy2Signature               []byte
511
}
512

513
func (q *Queries) GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error) {
×
514
        row := q.db.QueryRowContext(ctx, getChannelBySCIDWithPolicies, arg.Scid, arg.Version)
×
515
        var i GetChannelBySCIDWithPoliciesRow
×
516
        err := row.Scan(
×
517
                &i.Channel.ID,
×
518
                &i.Channel.Version,
×
519
                &i.Channel.Scid,
×
520
                &i.Channel.NodeID1,
×
521
                &i.Channel.NodeID2,
×
522
                &i.Channel.Outpoint,
×
523
                &i.Channel.Capacity,
×
524
                &i.Channel.BitcoinKey1,
×
525
                &i.Channel.BitcoinKey2,
×
526
                &i.Channel.Node1Signature,
×
527
                &i.Channel.Node2Signature,
×
528
                &i.Channel.Bitcoin1Signature,
×
529
                &i.Channel.Bitcoin2Signature,
×
530
                &i.Node.ID,
×
531
                &i.Node.Version,
×
532
                &i.Node.PubKey,
×
533
                &i.Node.Alias,
×
534
                &i.Node.LastUpdate,
×
535
                &i.Node.Color,
×
536
                &i.Node.Signature,
×
537
                &i.Node_2.ID,
×
538
                &i.Node_2.Version,
×
539
                &i.Node_2.PubKey,
×
540
                &i.Node_2.Alias,
×
541
                &i.Node_2.LastUpdate,
×
542
                &i.Node_2.Color,
×
543
                &i.Node_2.Signature,
×
544
                &i.Policy1ID,
×
545
                &i.Policy1NodeID,
×
546
                &i.Policy1Version,
×
547
                &i.Policy1Timelock,
×
548
                &i.Policy1FeePpm,
×
549
                &i.Policy1BaseFeeMsat,
×
550
                &i.Policy1MinHtlcMsat,
×
551
                &i.Policy1MaxHtlcMsat,
×
552
                &i.Policy1LastUpdate,
×
553
                &i.Policy1Disabled,
×
554
                &i.Policy1InboundBaseFeeMsat,
×
555
                &i.Policy1InboundFeeRateMilliMsat,
×
556
                &i.Policy1Signature,
×
557
                &i.Policy2ID,
×
558
                &i.Policy2NodeID,
×
559
                &i.Policy2Version,
×
560
                &i.Policy2Timelock,
×
561
                &i.Policy2FeePpm,
×
562
                &i.Policy2BaseFeeMsat,
×
563
                &i.Policy2MinHtlcMsat,
×
564
                &i.Policy2MaxHtlcMsat,
×
565
                &i.Policy2LastUpdate,
×
566
                &i.Policy2Disabled,
×
567
                &i.Policy2InboundBaseFeeMsat,
×
568
                &i.Policy2InboundFeeRateMilliMsat,
×
569
                &i.Policy2Signature,
×
570
        )
×
571
        return i, err
×
572
}
×
573

574
const getChannelFeaturesAndExtras = `-- name: GetChannelFeaturesAndExtras :many
575
SELECT
576
    cf.channel_id,
577
    true AS is_feature,
578
    cf.feature_bit AS feature_bit,
579
    NULL AS extra_key,
580
    NULL AS value
581
FROM channel_features cf
582
WHERE cf.channel_id = $1
583

584
UNION ALL
585

586
SELECT
587
    cet.channel_id,
588
    false AS is_feature,
589
    0 AS feature_bit,
590
    cet.type AS extra_key,
591
    cet.value AS value
592
FROM channel_extra_types cet
593
WHERE cet.channel_id = $1
594
`
595

596
type GetChannelFeaturesAndExtrasRow struct {
597
        ChannelID  int64
598
        IsFeature  bool
599
        FeatureBit int32
600
        ExtraKey   interface{}
601
        Value      interface{}
602
}
603

604
func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error) {
×
605
        rows, err := q.db.QueryContext(ctx, getChannelFeaturesAndExtras, channelID)
×
606
        if err != nil {
×
607
                return nil, err
×
608
        }
×
609
        defer rows.Close()
×
610
        var items []GetChannelFeaturesAndExtrasRow
×
611
        for rows.Next() {
×
612
                var i GetChannelFeaturesAndExtrasRow
×
613
                if err := rows.Scan(
×
614
                        &i.ChannelID,
×
615
                        &i.IsFeature,
×
616
                        &i.FeatureBit,
×
617
                        &i.ExtraKey,
×
618
                        &i.Value,
×
619
                ); err != nil {
×
620
                        return nil, err
×
621
                }
×
622
                items = append(items, i)
×
623
        }
624
        if err := rows.Close(); err != nil {
×
625
                return nil, err
×
626
        }
×
627
        if err := rows.Err(); err != nil {
×
628
                return nil, err
×
629
        }
×
630
        return items, nil
×
631
}
632

633
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
634
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
635
FROM channel_policies
636
WHERE channel_id = $1
637
  AND node_id = $2
638
  AND version = $3
639
`
640

641
type GetChannelPolicyByChannelAndNodeParams struct {
642
        ChannelID int64
643
        NodeID    int64
644
        Version   int16
645
}
646

647
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) {
×
648
        row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
×
649
        var i ChannelPolicy
×
650
        err := row.Scan(
×
651
                &i.ID,
×
652
                &i.Version,
×
653
                &i.ChannelID,
×
654
                &i.NodeID,
×
655
                &i.Timelock,
×
656
                &i.FeePpm,
×
657
                &i.BaseFeeMsat,
×
658
                &i.MinHtlcMsat,
×
659
                &i.MaxHtlcMsat,
×
660
                &i.LastUpdate,
×
661
                &i.Disabled,
×
662
                &i.InboundBaseFeeMsat,
×
663
                &i.InboundFeeRateMilliMsat,
×
664
                &i.Signature,
×
665
        )
×
666
        return i, err
×
667
}
×
668

669
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
670
SELECT
671
    cp.id AS policy_id,
672
    cp.channel_id,
673
    cp.node_id,
674
    cpet.type,
675
    cpet.value
676
FROM channel_policies cp
677
JOIN channel_policy_extra_types cpet
678
ON cp.id = cpet.channel_policy_id
679
WHERE cp.id = $1 OR cp.id = $2
680
`
681

682
type GetChannelPolicyExtraTypesParams struct {
683
        ID   int64
684
        ID_2 int64
685
}
686

687
type GetChannelPolicyExtraTypesRow struct {
688
        PolicyID  int64
689
        ChannelID int64
690
        NodeID    int64
691
        Type      int64
692
        Value     []byte
693
}
694

695
func (q *Queries) GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error) {
×
696
        rows, err := q.db.QueryContext(ctx, getChannelPolicyExtraTypes, arg.ID, arg.ID_2)
×
697
        if err != nil {
×
698
                return nil, err
×
699
        }
×
700
        defer rows.Close()
×
701
        var items []GetChannelPolicyExtraTypesRow
×
702
        for rows.Next() {
×
703
                var i GetChannelPolicyExtraTypesRow
×
704
                if err := rows.Scan(
×
705
                        &i.PolicyID,
×
706
                        &i.ChannelID,
×
707
                        &i.NodeID,
×
708
                        &i.Type,
×
709
                        &i.Value,
×
710
                ); err != nil {
×
711
                        return nil, err
×
712
                }
×
713
                items = append(items, i)
×
714
        }
715
        if err := rows.Close(); err != nil {
×
716
                return nil, err
×
717
        }
×
718
        if err := rows.Err(); err != nil {
×
719
                return nil, err
×
720
        }
×
721
        return items, nil
×
722
}
723

724
const getChannelsByPolicyLastUpdateRange = `-- name: GetChannelsByPolicyLastUpdateRange :many
725
SELECT
726
    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,
727
    n1.id, n1.version, n1.pub_key, n1.alias, n1.last_update, n1.color, n1.signature,
728
    n2.id, n2.version, n2.pub_key, n2.alias, n2.last_update, n2.color, n2.signature,
729

730
    -- Policy 1 (node_id_1)
731
    cp1.id AS policy1_id,
732
    cp1.node_id AS policy1_node_id,
733
    cp1.version AS policy1_version,
734
    cp1.timelock AS policy1_timelock,
735
    cp1.fee_ppm AS policy1_fee_ppm,
736
    cp1.base_fee_msat AS policy1_base_fee_msat,
737
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
738
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
739
    cp1.last_update AS policy1_last_update,
740
    cp1.disabled AS policy1_disabled,
741
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
742
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
743
    cp1.signature AS policy1_signature,
744

745
    -- Policy 2 (node_id_2)
746
    cp2.id AS policy2_id,
747
    cp2.node_id AS policy2_node_id,
748
    cp2.version AS policy2_version,
749
    cp2.timelock AS policy2_timelock,
750
    cp2.fee_ppm AS policy2_fee_ppm,
751
    cp2.base_fee_msat AS policy2_base_fee_msat,
752
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
753
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
754
    cp2.last_update AS policy2_last_update,
755
    cp2.disabled AS policy2_disabled,
756
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
757
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
758
    cp2.signature AS policy2_signature
759

760
FROM channels c
761
    JOIN nodes n1 ON c.node_id_1 = n1.id
762
    JOIN nodes n2 ON c.node_id_2 = n2.id
763
    LEFT JOIN channel_policies cp1
764
        ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
765
    LEFT JOIN channel_policies cp2
766
        ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
767
WHERE c.version = $1
768
  AND (
769
       (cp1.last_update >= $2 AND cp1.last_update < $3)
770
       OR
771
       (cp2.last_update >= $2 AND cp2.last_update < $3)
772
  )
773
ORDER BY
774
    CASE
775
        WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
776
            THEN COALESCE(cp1.last_update, 0)
777
        ELSE COALESCE(cp2.last_update, 0)
778
        END ASC
779
`
780

781
type GetChannelsByPolicyLastUpdateRangeParams struct {
782
        Version   int16
783
        StartTime sql.NullInt64
784
        EndTime   sql.NullInt64
785
}
786

787
type GetChannelsByPolicyLastUpdateRangeRow struct {
788
        Channel                        Channel
789
        Node                           Node
790
        Node_2                         Node
791
        Policy1ID                      sql.NullInt64
792
        Policy1NodeID                  sql.NullInt64
793
        Policy1Version                 sql.NullInt16
794
        Policy1Timelock                sql.NullInt32
795
        Policy1FeePpm                  sql.NullInt64
796
        Policy1BaseFeeMsat             sql.NullInt64
797
        Policy1MinHtlcMsat             sql.NullInt64
798
        Policy1MaxHtlcMsat             sql.NullInt64
799
        Policy1LastUpdate              sql.NullInt64
800
        Policy1Disabled                sql.NullBool
801
        Policy1InboundBaseFeeMsat      sql.NullInt64
802
        Policy1InboundFeeRateMilliMsat sql.NullInt64
803
        Policy1Signature               []byte
804
        Policy2ID                      sql.NullInt64
805
        Policy2NodeID                  sql.NullInt64
806
        Policy2Version                 sql.NullInt16
807
        Policy2Timelock                sql.NullInt32
808
        Policy2FeePpm                  sql.NullInt64
809
        Policy2BaseFeeMsat             sql.NullInt64
810
        Policy2MinHtlcMsat             sql.NullInt64
811
        Policy2MaxHtlcMsat             sql.NullInt64
812
        Policy2LastUpdate              sql.NullInt64
813
        Policy2Disabled                sql.NullBool
814
        Policy2InboundBaseFeeMsat      sql.NullInt64
815
        Policy2InboundFeeRateMilliMsat sql.NullInt64
816
        Policy2Signature               []byte
817
}
818

819
func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error) {
×
820
        rows, err := q.db.QueryContext(ctx, getChannelsByPolicyLastUpdateRange, arg.Version, arg.StartTime, arg.EndTime)
×
821
        if err != nil {
×
822
                return nil, err
×
823
        }
×
824
        defer rows.Close()
×
825
        var items []GetChannelsByPolicyLastUpdateRangeRow
×
826
        for rows.Next() {
×
827
                var i GetChannelsByPolicyLastUpdateRangeRow
×
828
                if err := rows.Scan(
×
829
                        &i.Channel.ID,
×
830
                        &i.Channel.Version,
×
831
                        &i.Channel.Scid,
×
832
                        &i.Channel.NodeID1,
×
833
                        &i.Channel.NodeID2,
×
834
                        &i.Channel.Outpoint,
×
835
                        &i.Channel.Capacity,
×
836
                        &i.Channel.BitcoinKey1,
×
837
                        &i.Channel.BitcoinKey2,
×
838
                        &i.Channel.Node1Signature,
×
839
                        &i.Channel.Node2Signature,
×
840
                        &i.Channel.Bitcoin1Signature,
×
841
                        &i.Channel.Bitcoin2Signature,
×
842
                        &i.Node.ID,
×
843
                        &i.Node.Version,
×
844
                        &i.Node.PubKey,
×
845
                        &i.Node.Alias,
×
846
                        &i.Node.LastUpdate,
×
847
                        &i.Node.Color,
×
848
                        &i.Node.Signature,
×
849
                        &i.Node_2.ID,
×
850
                        &i.Node_2.Version,
×
851
                        &i.Node_2.PubKey,
×
852
                        &i.Node_2.Alias,
×
853
                        &i.Node_2.LastUpdate,
×
854
                        &i.Node_2.Color,
×
855
                        &i.Node_2.Signature,
×
856
                        &i.Policy1ID,
×
857
                        &i.Policy1NodeID,
×
858
                        &i.Policy1Version,
×
859
                        &i.Policy1Timelock,
×
860
                        &i.Policy1FeePpm,
×
861
                        &i.Policy1BaseFeeMsat,
×
862
                        &i.Policy1MinHtlcMsat,
×
863
                        &i.Policy1MaxHtlcMsat,
×
864
                        &i.Policy1LastUpdate,
×
865
                        &i.Policy1Disabled,
×
866
                        &i.Policy1InboundBaseFeeMsat,
×
867
                        &i.Policy1InboundFeeRateMilliMsat,
×
868
                        &i.Policy1Signature,
×
869
                        &i.Policy2ID,
×
870
                        &i.Policy2NodeID,
×
871
                        &i.Policy2Version,
×
872
                        &i.Policy2Timelock,
×
873
                        &i.Policy2FeePpm,
×
874
                        &i.Policy2BaseFeeMsat,
×
875
                        &i.Policy2MinHtlcMsat,
×
876
                        &i.Policy2MaxHtlcMsat,
×
877
                        &i.Policy2LastUpdate,
×
878
                        &i.Policy2Disabled,
×
879
                        &i.Policy2InboundBaseFeeMsat,
×
880
                        &i.Policy2InboundFeeRateMilliMsat,
×
881
                        &i.Policy2Signature,
×
882
                ); err != nil {
×
883
                        return nil, err
×
884
                }
×
885
                items = append(items, i)
×
886
        }
887
        if err := rows.Close(); err != nil {
×
888
                return nil, err
×
889
        }
×
890
        if err := rows.Err(); err != nil {
×
891
                return nil, err
×
892
        }
×
893
        return items, nil
×
894
}
895

896
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
897
SELECT node_id, type, value
898
FROM node_extra_types
899
WHERE node_id = $1
900
`
901

902
func (q *Queries) GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error) {
×
903
        rows, err := q.db.QueryContext(ctx, getExtraNodeTypes, nodeID)
×
904
        if err != nil {
×
905
                return nil, err
×
906
        }
×
907
        defer rows.Close()
×
908
        var items []NodeExtraType
×
909
        for rows.Next() {
×
910
                var i NodeExtraType
×
911
                if err := rows.Scan(&i.NodeID, &i.Type, &i.Value); err != nil {
×
912
                        return nil, err
×
913
                }
×
914
                items = append(items, i)
×
915
        }
916
        if err := rows.Close(); err != nil {
×
917
                return nil, err
×
918
        }
×
919
        if err := rows.Err(); err != nil {
×
920
                return nil, err
×
921
        }
×
922
        return items, nil
×
923
}
924

925
const getNodeAddressesByPubKey = `-- name: GetNodeAddressesByPubKey :many
926
SELECT a.type, a.address
927
FROM nodes n
928
LEFT JOIN node_addresses a ON a.node_id = n.id
929
WHERE n.pub_key = $1 AND n.version = $2
930
ORDER BY a.type ASC, a.position ASC
931
`
932

933
type GetNodeAddressesByPubKeyParams struct {
934
        PubKey  []byte
935
        Version int16
936
}
937

938
type GetNodeAddressesByPubKeyRow struct {
939
        Type    sql.NullInt16
940
        Address sql.NullString
941
}
942

943
func (q *Queries) GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error) {
×
944
        rows, err := q.db.QueryContext(ctx, getNodeAddressesByPubKey, arg.PubKey, arg.Version)
×
945
        if err != nil {
×
946
                return nil, err
×
947
        }
×
948
        defer rows.Close()
×
949
        var items []GetNodeAddressesByPubKeyRow
×
950
        for rows.Next() {
×
951
                var i GetNodeAddressesByPubKeyRow
×
952
                if err := rows.Scan(&i.Type, &i.Address); err != nil {
×
953
                        return nil, err
×
954
                }
×
955
                items = append(items, i)
×
956
        }
957
        if err := rows.Close(); err != nil {
×
958
                return nil, err
×
959
        }
×
960
        if err := rows.Err(); err != nil {
×
961
                return nil, err
×
962
        }
×
963
        return items, nil
×
964
}
965

966
const getNodeByPubKey = `-- name: GetNodeByPubKey :one
967
SELECT id, version, pub_key, alias, last_update, color, signature
968
FROM nodes
969
WHERE pub_key = $1
970
  AND version = $2
971
`
972

973
type GetNodeByPubKeyParams struct {
974
        PubKey  []byte
975
        Version int16
976
}
977

978
func (q *Queries) GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error) {
×
979
        row := q.db.QueryRowContext(ctx, getNodeByPubKey, arg.PubKey, arg.Version)
×
980
        var i Node
×
981
        err := row.Scan(
×
982
                &i.ID,
×
983
                &i.Version,
×
984
                &i.PubKey,
×
985
                &i.Alias,
×
986
                &i.LastUpdate,
×
987
                &i.Color,
×
988
                &i.Signature,
×
989
        )
×
990
        return i, err
×
991
}
×
992

993
const getNodeFeatures = `-- name: GetNodeFeatures :many
994
SELECT node_id, feature_bit
995
FROM node_features
996
WHERE node_id = $1
997
`
998

999
func (q *Queries) GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error) {
×
1000
        rows, err := q.db.QueryContext(ctx, getNodeFeatures, nodeID)
×
1001
        if err != nil {
×
1002
                return nil, err
×
1003
        }
×
1004
        defer rows.Close()
×
1005
        var items []NodeFeature
×
1006
        for rows.Next() {
×
1007
                var i NodeFeature
×
1008
                if err := rows.Scan(&i.NodeID, &i.FeatureBit); err != nil {
×
1009
                        return nil, err
×
1010
                }
×
1011
                items = append(items, i)
×
1012
        }
1013
        if err := rows.Close(); err != nil {
×
1014
                return nil, err
×
1015
        }
×
1016
        if err := rows.Err(); err != nil {
×
1017
                return nil, err
×
1018
        }
×
1019
        return items, nil
×
1020
}
1021

1022
const getNodeFeaturesByPubKey = `-- name: GetNodeFeaturesByPubKey :many
1023
SELECT f.feature_bit
1024
FROM nodes n
1025
    JOIN node_features f ON f.node_id = n.id
1026
WHERE n.pub_key = $1
1027
  AND n.version = $2
1028
`
1029

1030
type GetNodeFeaturesByPubKeyParams struct {
1031
        PubKey  []byte
1032
        Version int16
1033
}
1034

1035
func (q *Queries) GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error) {
×
1036
        rows, err := q.db.QueryContext(ctx, getNodeFeaturesByPubKey, arg.PubKey, arg.Version)
×
1037
        if err != nil {
×
1038
                return nil, err
×
1039
        }
×
1040
        defer rows.Close()
×
1041
        var items []int32
×
1042
        for rows.Next() {
×
1043
                var feature_bit int32
×
1044
                if err := rows.Scan(&feature_bit); err != nil {
×
1045
                        return nil, err
×
1046
                }
×
1047
                items = append(items, feature_bit)
×
1048
        }
1049
        if err := rows.Close(); err != nil {
×
1050
                return nil, err
×
1051
        }
×
1052
        if err := rows.Err(); err != nil {
×
1053
                return nil, err
×
1054
        }
×
1055
        return items, nil
×
1056
}
1057

1058
const getNodeIDByPubKey = `-- name: GetNodeIDByPubKey :one
1059
SELECT id
1060
FROM nodes
1061
WHERE pub_key = $1
1062
  AND version = $2
1063
`
1064

1065
type GetNodeIDByPubKeyParams struct {
1066
        PubKey  []byte
1067
        Version int16
1068
}
1069

1070
func (q *Queries) GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error) {
×
1071
        row := q.db.QueryRowContext(ctx, getNodeIDByPubKey, arg.PubKey, arg.Version)
×
1072
        var id int64
×
1073
        err := row.Scan(&id)
×
1074
        return id, err
×
1075
}
×
1076

1077
const getNodesByLastUpdateRange = `-- name: GetNodesByLastUpdateRange :many
1078
SELECT id, version, pub_key, alias, last_update, color, signature
1079
FROM nodes
1080
WHERE last_update >= $1
1081
  AND last_update < $2
1082
`
1083

1084
type GetNodesByLastUpdateRangeParams struct {
1085
        StartTime sql.NullInt64
1086
        EndTime   sql.NullInt64
1087
}
1088

1089
func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error) {
×
1090
        rows, err := q.db.QueryContext(ctx, getNodesByLastUpdateRange, arg.StartTime, arg.EndTime)
×
1091
        if err != nil {
×
1092
                return nil, err
×
1093
        }
×
1094
        defer rows.Close()
×
1095
        var items []Node
×
1096
        for rows.Next() {
×
1097
                var i Node
×
1098
                if err := rows.Scan(
×
1099
                        &i.ID,
×
1100
                        &i.Version,
×
1101
                        &i.PubKey,
×
1102
                        &i.Alias,
×
1103
                        &i.LastUpdate,
×
1104
                        &i.Color,
×
1105
                        &i.Signature,
×
1106
                ); err != nil {
×
1107
                        return nil, err
×
1108
                }
×
1109
                items = append(items, i)
×
1110
        }
1111
        if err := rows.Close(); err != nil {
×
1112
                return nil, err
×
1113
        }
×
1114
        if err := rows.Err(); err != nil {
×
1115
                return nil, err
×
1116
        }
×
1117
        return items, nil
×
1118
}
1119

1120
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
1121
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
1122
FROM channels
1123
WHERE node_1_signature IS NOT NULL
1124
  AND scid >= $1
1125
  AND scid < $2
1126
`
1127

1128
type GetPublicV1ChannelsBySCIDParams struct {
1129
        StartScid []byte
1130
        EndScid   []byte
1131
}
1132

1133
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
×
1134
        rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
×
1135
        if err != nil {
×
1136
                return nil, err
×
1137
        }
×
1138
        defer rows.Close()
×
1139
        var items []Channel
×
1140
        for rows.Next() {
×
1141
                var i Channel
×
1142
                if err := rows.Scan(
×
1143
                        &i.ID,
×
1144
                        &i.Version,
×
1145
                        &i.Scid,
×
1146
                        &i.NodeID1,
×
1147
                        &i.NodeID2,
×
1148
                        &i.Outpoint,
×
1149
                        &i.Capacity,
×
1150
                        &i.BitcoinKey1,
×
1151
                        &i.BitcoinKey2,
×
1152
                        &i.Node1Signature,
×
1153
                        &i.Node2Signature,
×
1154
                        &i.Bitcoin1Signature,
×
1155
                        &i.Bitcoin2Signature,
×
1156
                ); err != nil {
×
1157
                        return nil, err
×
1158
                }
×
1159
                items = append(items, i)
×
1160
        }
1161
        if err := rows.Close(); err != nil {
×
1162
                return nil, err
×
1163
        }
×
1164
        if err := rows.Err(); err != nil {
×
1165
                return nil, err
×
1166
        }
×
1167
        return items, nil
×
1168
}
1169

1170
const getSCIDByOutpoint = `-- name: GetSCIDByOutpoint :one
1171
SELECT scid from channels
1172
WHERE outpoint = $1 AND version = $2
1173
`
1174

1175
type GetSCIDByOutpointParams struct {
1176
        Outpoint string
1177
        Version  int16
1178
}
1179

NEW
1180
func (q *Queries) GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error) {
×
NEW
1181
        row := q.db.QueryRowContext(ctx, getSCIDByOutpoint, arg.Outpoint, arg.Version)
×
NEW
1182
        var scid []byte
×
NEW
1183
        err := row.Scan(&scid)
×
NEW
1184
        return scid, err
×
NEW
1185
}
×
1186

1187
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
1188
SELECT sn.node_id, n.pub_key
1189
FROM source_nodes sn
1190
    JOIN nodes n ON sn.node_id = n.id
1191
WHERE n.version = $1
1192
`
1193

1194
type GetSourceNodesByVersionRow struct {
1195
        NodeID int64
1196
        PubKey []byte
1197
}
1198

1199
func (q *Queries) GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error) {
×
1200
        rows, err := q.db.QueryContext(ctx, getSourceNodesByVersion, version)
×
1201
        if err != nil {
×
1202
                return nil, err
×
1203
        }
×
1204
        defer rows.Close()
×
1205
        var items []GetSourceNodesByVersionRow
×
1206
        for rows.Next() {
×
1207
                var i GetSourceNodesByVersionRow
×
1208
                if err := rows.Scan(&i.NodeID, &i.PubKey); err != nil {
×
1209
                        return nil, err
×
1210
                }
×
1211
                items = append(items, i)
×
1212
        }
1213
        if err := rows.Close(); err != nil {
×
1214
                return nil, err
×
1215
        }
×
1216
        if err := rows.Err(); err != nil {
×
1217
                return nil, err
×
1218
        }
×
1219
        return items, nil
×
1220
}
1221

1222
const getV1DisabledSCIDs = `-- name: GetV1DisabledSCIDs :many
1223
SELECT c.scid
1224
FROM channels c
1225
    JOIN channel_policies cp ON cp.channel_id = c.id
1226
WHERE cp.disabled = true
1227
AND c.version = 1
1228
GROUP BY c.scid
1229
HAVING COUNT(*) > 1
1230
`
1231

1232
// NOTE: this is V1 specific since for V1, disabled is a
1233
// simple, single boolean. The proposed V2 policy
1234
// structure will have a more complex disabled bit vector
1235
// and so the query for V2 may differ.
NEW
1236
func (q *Queries) GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error) {
×
NEW
1237
        rows, err := q.db.QueryContext(ctx, getV1DisabledSCIDs)
×
NEW
1238
        if err != nil {
×
NEW
1239
                return nil, err
×
NEW
1240
        }
×
NEW
1241
        defer rows.Close()
×
NEW
1242
        var items [][]byte
×
NEW
1243
        for rows.Next() {
×
NEW
1244
                var scid []byte
×
NEW
1245
                if err := rows.Scan(&scid); err != nil {
×
NEW
1246
                        return nil, err
×
NEW
1247
                }
×
NEW
1248
                items = append(items, scid)
×
1249
        }
NEW
1250
        if err := rows.Close(); err != nil {
×
NEW
1251
                return nil, err
×
NEW
1252
        }
×
NEW
1253
        if err := rows.Err(); err != nil {
×
NEW
1254
                return nil, err
×
NEW
1255
        }
×
NEW
1256
        return items, nil
×
1257
}
1258

1259
const getZombieChannel = `-- name: GetZombieChannel :one
1260
SELECT scid, version, node_key_1, node_key_2
1261
FROM zombie_channels
1262
WHERE scid = $1
1263
AND version = $2
1264
`
1265

1266
type GetZombieChannelParams struct {
1267
        Scid    []byte
1268
        Version int16
1269
}
1270

1271
func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error) {
×
1272
        row := q.db.QueryRowContext(ctx, getZombieChannel, arg.Scid, arg.Version)
×
1273
        var i ZombieChannel
×
1274
        err := row.Scan(
×
1275
                &i.Scid,
×
1276
                &i.Version,
×
1277
                &i.NodeKey1,
×
1278
                &i.NodeKey2,
×
1279
        )
×
1280
        return i, err
×
1281
}
×
1282

1283
const highestSCID = `-- name: HighestSCID :one
1284
SELECT scid
1285
FROM channels
1286
WHERE version = $1
1287
ORDER BY scid DESC
1288
LIMIT 1
1289
`
1290

1291
func (q *Queries) HighestSCID(ctx context.Context, version int16) ([]byte, error) {
×
1292
        row := q.db.QueryRowContext(ctx, highestSCID, version)
×
1293
        var scid []byte
×
1294
        err := row.Scan(&scid)
×
1295
        return scid, err
×
1296
}
×
1297

1298
const insertChanPolicyExtraType = `-- name: InsertChanPolicyExtraType :exec
1299
/* ─────────────────────────────────────────────
1300
   channel_policy_extra_types table queries
1301
   ─────────────────────────────────────────────
1302
*/
1303

1304
INSERT INTO channel_policy_extra_types (
1305
    channel_policy_id, type, value
1306
)
1307
VALUES ($1, $2, $3)
1308
`
1309

1310
type InsertChanPolicyExtraTypeParams struct {
1311
        ChannelPolicyID int64
1312
        Type            int64
1313
        Value           []byte
1314
}
1315

1316
func (q *Queries) InsertChanPolicyExtraType(ctx context.Context, arg InsertChanPolicyExtraTypeParams) error {
×
1317
        _, err := q.db.ExecContext(ctx, insertChanPolicyExtraType, arg.ChannelPolicyID, arg.Type, arg.Value)
×
1318
        return err
×
1319
}
×
1320

1321
const insertChannelFeature = `-- name: InsertChannelFeature :exec
1322
/* ─────────────────────────────────────────────
1323
   channel_features table queries
1324
   ─────────────────────────────────────────────
1325
*/
1326

1327
INSERT INTO channel_features (
1328
    channel_id, feature_bit
1329
) VALUES (
1330
    $1, $2
1331
)
1332
`
1333

1334
type InsertChannelFeatureParams struct {
1335
        ChannelID  int64
1336
        FeatureBit int32
1337
}
1338

1339
func (q *Queries) InsertChannelFeature(ctx context.Context, arg InsertChannelFeatureParams) error {
×
1340
        _, err := q.db.ExecContext(ctx, insertChannelFeature, arg.ChannelID, arg.FeatureBit)
×
1341
        return err
×
1342
}
×
1343

1344
const insertNodeAddress = `-- name: InsertNodeAddress :exec
1345
/* ─────────────────────────────────────────────
1346
   node_addresses table queries
1347
   ─────────────────────────────────────────────
1348
*/
1349

1350
INSERT INTO node_addresses (
1351
    node_id,
1352
    type,
1353
    address,
1354
    position
1355
) VALUES (
1356
    $1, $2, $3, $4
1357
 )
1358
`
1359

1360
type InsertNodeAddressParams struct {
1361
        NodeID   int64
1362
        Type     int16
1363
        Address  string
1364
        Position int32
1365
}
1366

1367
func (q *Queries) InsertNodeAddress(ctx context.Context, arg InsertNodeAddressParams) error {
×
1368
        _, err := q.db.ExecContext(ctx, insertNodeAddress,
×
1369
                arg.NodeID,
×
1370
                arg.Type,
×
1371
                arg.Address,
×
1372
                arg.Position,
×
1373
        )
×
1374
        return err
×
1375
}
×
1376

1377
const insertNodeFeature = `-- name: InsertNodeFeature :exec
1378
/* ─────────────────────────────────────────────
1379
   node_features table queries
1380
   ─────────────────────────────────────────────
1381
*/
1382

1383
INSERT INTO node_features (
1384
    node_id, feature_bit
1385
) VALUES (
1386
    $1, $2
1387
)
1388
`
1389

1390
type InsertNodeFeatureParams struct {
1391
        NodeID     int64
1392
        FeatureBit int32
1393
}
1394

1395
func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeatureParams) error {
×
1396
        _, err := q.db.ExecContext(ctx, insertNodeFeature, arg.NodeID, arg.FeatureBit)
×
1397
        return err
×
1398
}
×
1399

1400
const isPublicV1Node = `-- name: IsPublicV1Node :one
1401
SELECT EXISTS (
1402
    SELECT 1
1403
    FROM channels c
1404
    JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
1405
    -- NOTE: we hard-code the version here since the clauses
1406
    -- here that determine if a node is public is specific
1407
    -- to the V1 gossip protocol. In V1, a node is public
1408
    -- if it has a public channel and a public channel is one
1409
    -- where we have the set of signatures of the channel
1410
    -- announcement. It is enough to just check that we have
1411
    -- one of the signatures since we only ever set them
1412
    -- together.
1413
    WHERE c.version = 1
1414
      AND c.bitcoin_1_signature IS NOT NULL
1415
      AND n.pub_key = $1
1416
)
1417
`
1418

NEW
1419
func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error) {
×
NEW
1420
        row := q.db.QueryRowContext(ctx, isPublicV1Node, pubKey)
×
NEW
1421
        var exists bool
×
NEW
1422
        err := row.Scan(&exists)
×
NEW
1423
        return exists, err
×
NEW
1424
}
×
1425

1426
const isZombieChannel = `-- name: IsZombieChannel :one
1427
SELECT EXISTS (
1428
    SELECT 1
1429
    FROM zombie_channels
1430
    WHERE scid = $1
1431
    AND version = $2
1432
) AS is_zombie
1433
`
1434

1435
type IsZombieChannelParams struct {
1436
        Scid    []byte
1437
        Version int16
1438
}
1439

NEW
1440
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
×
NEW
1441
        row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
×
NEW
1442
        var is_zombie bool
×
NEW
1443
        err := row.Scan(&is_zombie)
×
NEW
1444
        return is_zombie, err
×
NEW
1445
}
×
1446

1447
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :many
1448
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,
1449
    n1.pub_key AS node1_pubkey,
1450
    n2.pub_key AS node2_pubkey,
1451

1452
    -- Policy 1
1453
    -- TODO(elle): use sqlc.embed to embed policy structs
1454
    --  once this issue is resolved:
1455
    --  https://github.com/sqlc-dev/sqlc/issues/2997
1456
    cp1.id AS policy1_id,
1457
    cp1.node_id AS policy1_node_id,
1458
    cp1.version AS policy1_version,
1459
    cp1.timelock AS policy1_timelock,
1460
    cp1.fee_ppm AS policy1_fee_ppm,
1461
    cp1.base_fee_msat AS policy1_base_fee_msat,
1462
    cp1.min_htlc_msat AS policy1_min_htlc_msat,
1463
    cp1.max_htlc_msat AS policy1_max_htlc_msat,
1464
    cp1.last_update AS policy1_last_update,
1465
    cp1.disabled AS policy1_disabled,
1466
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1467
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1468
    cp1.signature AS policy1_signature,
1469

1470
       -- Policy 2
1471
    cp2.id AS policy2_id,
1472
    cp2.node_id AS policy2_node_id,
1473
    cp2.version AS policy2_version,
1474
    cp2.timelock AS policy2_timelock,
1475
    cp2.fee_ppm AS policy2_fee_ppm,
1476
    cp2.base_fee_msat AS policy2_base_fee_msat,
1477
    cp2.min_htlc_msat AS policy2_min_htlc_msat,
1478
    cp2.max_htlc_msat AS policy2_max_htlc_msat,
1479
    cp2.last_update AS policy2_last_update,
1480
    cp2.disabled AS policy2_disabled,
1481
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1482
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1483
    cp2.signature AS policy2_signature
1484

1485
FROM channels c
1486
    JOIN nodes n1 ON c.node_id_1 = n1.id
1487
    JOIN nodes n2 ON c.node_id_2 = n2.id
1488
    LEFT JOIN channel_policies cp1
1489
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1490
    LEFT JOIN channel_policies cp2
1491
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1492
WHERE c.version = $1
1493
  AND (c.node_id_1 = $2 OR c.node_id_2 = $2)
1494
`
1495

1496
type ListChannelsByNodeIDParams struct {
1497
        Version int16
1498
        NodeID1 int64
1499
}
1500

1501
type ListChannelsByNodeIDRow struct {
1502
        Channel                        Channel
1503
        Node1Pubkey                    []byte
1504
        Node2Pubkey                    []byte
1505
        Policy1ID                      sql.NullInt64
1506
        Policy1NodeID                  sql.NullInt64
1507
        Policy1Version                 sql.NullInt16
1508
        Policy1Timelock                sql.NullInt32
1509
        Policy1FeePpm                  sql.NullInt64
1510
        Policy1BaseFeeMsat             sql.NullInt64
1511
        Policy1MinHtlcMsat             sql.NullInt64
1512
        Policy1MaxHtlcMsat             sql.NullInt64
1513
        Policy1LastUpdate              sql.NullInt64
1514
        Policy1Disabled                sql.NullBool
1515
        Policy1InboundBaseFeeMsat      sql.NullInt64
1516
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1517
        Policy1Signature               []byte
1518
        Policy2ID                      sql.NullInt64
1519
        Policy2NodeID                  sql.NullInt64
1520
        Policy2Version                 sql.NullInt16
1521
        Policy2Timelock                sql.NullInt32
1522
        Policy2FeePpm                  sql.NullInt64
1523
        Policy2BaseFeeMsat             sql.NullInt64
1524
        Policy2MinHtlcMsat             sql.NullInt64
1525
        Policy2MaxHtlcMsat             sql.NullInt64
1526
        Policy2LastUpdate              sql.NullInt64
1527
        Policy2Disabled                sql.NullBool
1528
        Policy2InboundBaseFeeMsat      sql.NullInt64
1529
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1530
        Policy2Signature               []byte
1531
}
1532

1533
func (q *Queries) ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error) {
×
1534
        rows, err := q.db.QueryContext(ctx, listChannelsByNodeID, arg.Version, arg.NodeID1)
×
1535
        if err != nil {
×
1536
                return nil, err
×
1537
        }
×
1538
        defer rows.Close()
×
1539
        var items []ListChannelsByNodeIDRow
×
1540
        for rows.Next() {
×
1541
                var i ListChannelsByNodeIDRow
×
1542
                if err := rows.Scan(
×
1543
                        &i.Channel.ID,
×
1544
                        &i.Channel.Version,
×
1545
                        &i.Channel.Scid,
×
1546
                        &i.Channel.NodeID1,
×
1547
                        &i.Channel.NodeID2,
×
1548
                        &i.Channel.Outpoint,
×
1549
                        &i.Channel.Capacity,
×
1550
                        &i.Channel.BitcoinKey1,
×
1551
                        &i.Channel.BitcoinKey2,
×
1552
                        &i.Channel.Node1Signature,
×
1553
                        &i.Channel.Node2Signature,
×
1554
                        &i.Channel.Bitcoin1Signature,
×
1555
                        &i.Channel.Bitcoin2Signature,
×
1556
                        &i.Node1Pubkey,
×
1557
                        &i.Node2Pubkey,
×
1558
                        &i.Policy1ID,
×
1559
                        &i.Policy1NodeID,
×
1560
                        &i.Policy1Version,
×
1561
                        &i.Policy1Timelock,
×
1562
                        &i.Policy1FeePpm,
×
1563
                        &i.Policy1BaseFeeMsat,
×
1564
                        &i.Policy1MinHtlcMsat,
×
1565
                        &i.Policy1MaxHtlcMsat,
×
1566
                        &i.Policy1LastUpdate,
×
1567
                        &i.Policy1Disabled,
×
1568
                        &i.Policy1InboundBaseFeeMsat,
×
1569
                        &i.Policy1InboundFeeRateMilliMsat,
×
1570
                        &i.Policy1Signature,
×
1571
                        &i.Policy2ID,
×
1572
                        &i.Policy2NodeID,
×
1573
                        &i.Policy2Version,
×
1574
                        &i.Policy2Timelock,
×
1575
                        &i.Policy2FeePpm,
×
1576
                        &i.Policy2BaseFeeMsat,
×
1577
                        &i.Policy2MinHtlcMsat,
×
1578
                        &i.Policy2MaxHtlcMsat,
×
1579
                        &i.Policy2LastUpdate,
×
1580
                        &i.Policy2Disabled,
×
1581
                        &i.Policy2InboundBaseFeeMsat,
×
1582
                        &i.Policy2InboundFeeRateMilliMsat,
×
1583
                        &i.Policy2Signature,
×
1584
                ); err != nil {
×
1585
                        return nil, err
×
1586
                }
×
1587
                items = append(items, i)
×
1588
        }
1589
        if err := rows.Close(); err != nil {
×
1590
                return nil, err
×
1591
        }
×
1592
        if err := rows.Err(); err != nil {
×
1593
                return nil, err
×
1594
        }
×
1595
        return items, nil
×
1596
}
1597

1598
const listChannelsWithPoliciesPaginated = `-- name: ListChannelsWithPoliciesPaginated :many
1599
SELECT
1600
    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,
1601

1602
    -- Join node pubkeys
1603
    n1.pub_key AS node1_pubkey,
1604
    n2.pub_key AS node2_pubkey,
1605

1606
    -- Node 1 policy
1607
    cp1.id AS policy_1_id,
1608
    cp1.node_id AS policy_1_node_id,
1609
    cp1.version AS policy_1_version,
1610
    cp1.timelock AS policy_1_timelock,
1611
    cp1.fee_ppm AS policy_1_fee_ppm,
1612
    cp1.base_fee_msat AS policy_1_base_fee_msat,
1613
    cp1.min_htlc_msat AS policy_1_min_htlc_msat,
1614
    cp1.max_htlc_msat AS policy_1_max_htlc_msat,
1615
    cp1.last_update AS policy_1_last_update,
1616
    cp1.disabled AS policy_1_disabled,
1617
    cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
1618
    cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
1619
    cp1.signature AS policy_1_signature,
1620

1621
    -- Node 2 policy
1622
    cp2.id AS policy_2_id,
1623
    cp2.node_id AS policy_2_node_id,
1624
    cp2.version AS policy_2_version,
1625
    cp2.timelock AS policy_2_timelock,
1626
    cp2.fee_ppm AS policy_2_fee_ppm,
1627
    cp2.base_fee_msat AS policy_2_base_fee_msat,
1628
    cp2.min_htlc_msat AS policy_2_min_htlc_msat,
1629
    cp2.max_htlc_msat AS policy_2_max_htlc_msat,
1630
    cp2.last_update AS policy_2_last_update,
1631
    cp2.disabled AS policy_2_disabled,
1632
    cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
1633
    cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
1634
    cp2.signature AS policy_2_signature
1635

1636
FROM channels c
1637
JOIN nodes n1 ON c.node_id_1 = n1.id
1638
JOIN nodes n2 ON c.node_id_2 = n2.id
1639
LEFT JOIN channel_policies cp1
1640
    ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
1641
LEFT JOIN channel_policies cp2
1642
    ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
1643
WHERE c.version = $1 AND c.id > $2
1644
ORDER BY c.id
1645
LIMIT $3
1646
`
1647

1648
type ListChannelsWithPoliciesPaginatedParams struct {
1649
        Version int16
1650
        ID      int64
1651
        Limit   int32
1652
}
1653

1654
type ListChannelsWithPoliciesPaginatedRow struct {
1655
        Channel                        Channel
1656
        Node1Pubkey                    []byte
1657
        Node2Pubkey                    []byte
1658
        Policy1ID                      sql.NullInt64
1659
        Policy1NodeID                  sql.NullInt64
1660
        Policy1Version                 sql.NullInt16
1661
        Policy1Timelock                sql.NullInt32
1662
        Policy1FeePpm                  sql.NullInt64
1663
        Policy1BaseFeeMsat             sql.NullInt64
1664
        Policy1MinHtlcMsat             sql.NullInt64
1665
        Policy1MaxHtlcMsat             sql.NullInt64
1666
        Policy1LastUpdate              sql.NullInt64
1667
        Policy1Disabled                sql.NullBool
1668
        Policy1InboundBaseFeeMsat      sql.NullInt64
1669
        Policy1InboundFeeRateMilliMsat sql.NullInt64
1670
        Policy1Signature               []byte
1671
        Policy2ID                      sql.NullInt64
1672
        Policy2NodeID                  sql.NullInt64
1673
        Policy2Version                 sql.NullInt16
1674
        Policy2Timelock                sql.NullInt32
1675
        Policy2FeePpm                  sql.NullInt64
1676
        Policy2BaseFeeMsat             sql.NullInt64
1677
        Policy2MinHtlcMsat             sql.NullInt64
1678
        Policy2MaxHtlcMsat             sql.NullInt64
1679
        Policy2LastUpdate              sql.NullInt64
1680
        Policy2Disabled                sql.NullBool
1681
        Policy2InboundBaseFeeMsat      sql.NullInt64
1682
        Policy2InboundFeeRateMilliMsat sql.NullInt64
1683
        Policy2Signature               []byte
1684
}
1685

1686
func (q *Queries) ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error) {
×
1687
        rows, err := q.db.QueryContext(ctx, listChannelsWithPoliciesPaginated, arg.Version, arg.ID, arg.Limit)
×
1688
        if err != nil {
×
1689
                return nil, err
×
1690
        }
×
1691
        defer rows.Close()
×
1692
        var items []ListChannelsWithPoliciesPaginatedRow
×
1693
        for rows.Next() {
×
1694
                var i ListChannelsWithPoliciesPaginatedRow
×
1695
                if err := rows.Scan(
×
1696
                        &i.Channel.ID,
×
1697
                        &i.Channel.Version,
×
1698
                        &i.Channel.Scid,
×
1699
                        &i.Channel.NodeID1,
×
1700
                        &i.Channel.NodeID2,
×
1701
                        &i.Channel.Outpoint,
×
1702
                        &i.Channel.Capacity,
×
1703
                        &i.Channel.BitcoinKey1,
×
1704
                        &i.Channel.BitcoinKey2,
×
1705
                        &i.Channel.Node1Signature,
×
1706
                        &i.Channel.Node2Signature,
×
1707
                        &i.Channel.Bitcoin1Signature,
×
1708
                        &i.Channel.Bitcoin2Signature,
×
1709
                        &i.Node1Pubkey,
×
1710
                        &i.Node2Pubkey,
×
1711
                        &i.Policy1ID,
×
1712
                        &i.Policy1NodeID,
×
1713
                        &i.Policy1Version,
×
1714
                        &i.Policy1Timelock,
×
1715
                        &i.Policy1FeePpm,
×
1716
                        &i.Policy1BaseFeeMsat,
×
1717
                        &i.Policy1MinHtlcMsat,
×
1718
                        &i.Policy1MaxHtlcMsat,
×
1719
                        &i.Policy1LastUpdate,
×
1720
                        &i.Policy1Disabled,
×
1721
                        &i.Policy1InboundBaseFeeMsat,
×
1722
                        &i.Policy1InboundFeeRateMilliMsat,
×
1723
                        &i.Policy1Signature,
×
1724
                        &i.Policy2ID,
×
1725
                        &i.Policy2NodeID,
×
1726
                        &i.Policy2Version,
×
1727
                        &i.Policy2Timelock,
×
1728
                        &i.Policy2FeePpm,
×
1729
                        &i.Policy2BaseFeeMsat,
×
1730
                        &i.Policy2MinHtlcMsat,
×
1731
                        &i.Policy2MaxHtlcMsat,
×
1732
                        &i.Policy2LastUpdate,
×
1733
                        &i.Policy2Disabled,
×
1734
                        &i.Policy2InboundBaseFeeMsat,
×
1735
                        &i.Policy2InboundFeeRateMilliMsat,
×
1736
                        &i.Policy2Signature,
×
1737
                ); err != nil {
×
1738
                        return nil, err
×
1739
                }
×
1740
                items = append(items, i)
×
1741
        }
1742
        if err := rows.Close(); err != nil {
×
1743
                return nil, err
×
1744
        }
×
1745
        if err := rows.Err(); err != nil {
×
1746
                return nil, err
×
1747
        }
×
1748
        return items, nil
×
1749
}
1750

1751
const listNodeIDsAndPubKeys = `-- name: ListNodeIDsAndPubKeys :many
1752
SELECT id, pub_key
1753
FROM nodes
1754
WHERE version = $1  AND id > $2
1755
ORDER BY id
1756
LIMIT $3
1757
`
1758

1759
type ListNodeIDsAndPubKeysParams struct {
1760
        Version int16
1761
        ID      int64
1762
        Limit   int32
1763
}
1764

1765
type ListNodeIDsAndPubKeysRow struct {
1766
        ID     int64
1767
        PubKey []byte
1768
}
1769

1770
func (q *Queries) ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error) {
×
1771
        rows, err := q.db.QueryContext(ctx, listNodeIDsAndPubKeys, arg.Version, arg.ID, arg.Limit)
×
1772
        if err != nil {
×
1773
                return nil, err
×
1774
        }
×
1775
        defer rows.Close()
×
1776
        var items []ListNodeIDsAndPubKeysRow
×
1777
        for rows.Next() {
×
1778
                var i ListNodeIDsAndPubKeysRow
×
1779
                if err := rows.Scan(&i.ID, &i.PubKey); err != nil {
×
1780
                        return nil, err
×
1781
                }
×
1782
                items = append(items, i)
×
1783
        }
1784
        if err := rows.Close(); err != nil {
×
1785
                return nil, err
×
1786
        }
×
1787
        if err := rows.Err(); err != nil {
×
1788
                return nil, err
×
1789
        }
×
1790
        return items, nil
×
1791
}
1792

1793
const listNodesPaginated = `-- name: ListNodesPaginated :many
1794
SELECT id, version, pub_key, alias, last_update, color, signature
1795
FROM nodes
1796
WHERE version = $1 AND id > $2
1797
ORDER BY id
1798
LIMIT $3
1799
`
1800

1801
type ListNodesPaginatedParams struct {
1802
        Version int16
1803
        ID      int64
1804
        Limit   int32
1805
}
1806

1807
func (q *Queries) ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error) {
×
1808
        rows, err := q.db.QueryContext(ctx, listNodesPaginated, arg.Version, arg.ID, arg.Limit)
×
1809
        if err != nil {
×
1810
                return nil, err
×
1811
        }
×
1812
        defer rows.Close()
×
1813
        var items []Node
×
1814
        for rows.Next() {
×
1815
                var i Node
×
1816
                if err := rows.Scan(
×
1817
                        &i.ID,
×
1818
                        &i.Version,
×
1819
                        &i.PubKey,
×
1820
                        &i.Alias,
×
1821
                        &i.LastUpdate,
×
1822
                        &i.Color,
×
1823
                        &i.Signature,
×
1824
                ); err != nil {
×
1825
                        return nil, err
×
1826
                }
×
1827
                items = append(items, i)
×
1828
        }
1829
        if err := rows.Close(); err != nil {
×
1830
                return nil, err
×
1831
        }
×
1832
        if err := rows.Err(); err != nil {
×
1833
                return nil, err
×
1834
        }
×
1835
        return items, nil
×
1836
}
1837

1838
const upsertEdgePolicy = `-- name: UpsertEdgePolicy :one
1839
/* ─────────────────────────────────────────────
1840
   channel_policies table queries
1841
   ─────────────────────────────────────────────
1842
*/
1843

1844
INSERT INTO channel_policies (
1845
    version, channel_id, node_id, timelock, fee_ppm,
1846
    base_fee_msat, min_htlc_msat, last_update, disabled,
1847
    max_htlc_msat, inbound_base_fee_msat,
1848
    inbound_fee_rate_milli_msat, signature
1849
) VALUES  (
1850
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
1851
)
1852
ON CONFLICT (channel_id, node_id, version)
1853
    -- Update the following fields if a conflict occurs on channel_id,
1854
    -- node_id, and version.
1855
    DO UPDATE SET
1856
        timelock = EXCLUDED.timelock,
1857
        fee_ppm = EXCLUDED.fee_ppm,
1858
        base_fee_msat = EXCLUDED.base_fee_msat,
1859
        min_htlc_msat = EXCLUDED.min_htlc_msat,
1860
        last_update = EXCLUDED.last_update,
1861
        disabled = EXCLUDED.disabled,
1862
        max_htlc_msat = EXCLUDED.max_htlc_msat,
1863
        inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
1864
        inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
1865
        signature = EXCLUDED.signature
1866
WHERE EXCLUDED.last_update > channel_policies.last_update
1867
RETURNING id
1868
`
1869

1870
type UpsertEdgePolicyParams struct {
1871
        Version                 int16
1872
        ChannelID               int64
1873
        NodeID                  int64
1874
        Timelock                int32
1875
        FeePpm                  int64
1876
        BaseFeeMsat             int64
1877
        MinHtlcMsat             int64
1878
        LastUpdate              sql.NullInt64
1879
        Disabled                sql.NullBool
1880
        MaxHtlcMsat             sql.NullInt64
1881
        InboundBaseFeeMsat      sql.NullInt64
1882
        InboundFeeRateMilliMsat sql.NullInt64
1883
        Signature               []byte
1884
}
1885

1886
func (q *Queries) UpsertEdgePolicy(ctx context.Context, arg UpsertEdgePolicyParams) (int64, error) {
×
1887
        row := q.db.QueryRowContext(ctx, upsertEdgePolicy,
×
1888
                arg.Version,
×
1889
                arg.ChannelID,
×
1890
                arg.NodeID,
×
1891
                arg.Timelock,
×
1892
                arg.FeePpm,
×
1893
                arg.BaseFeeMsat,
×
1894
                arg.MinHtlcMsat,
×
1895
                arg.LastUpdate,
×
1896
                arg.Disabled,
×
1897
                arg.MaxHtlcMsat,
×
1898
                arg.InboundBaseFeeMsat,
×
1899
                arg.InboundFeeRateMilliMsat,
×
1900
                arg.Signature,
×
1901
        )
×
1902
        var id int64
×
1903
        err := row.Scan(&id)
×
1904
        return id, err
×
1905
}
×
1906

1907
const upsertNode = `-- name: UpsertNode :one
1908
/* ─────────────────────────────────────────────
1909
   nodes table queries
1910
   ─────────────────────────────────────────────
1911
*/
1912

1913
INSERT INTO nodes (
1914
    version, pub_key, alias, last_update, color, signature
1915
) VALUES (
1916
    $1, $2, $3, $4, $5, $6
1917
)
1918
ON CONFLICT (pub_key, version)
1919
    -- Update the following fields if a conflict occurs on pub_key
1920
    -- and version.
1921
    DO UPDATE SET
1922
        alias = EXCLUDED.alias,
1923
        last_update = EXCLUDED.last_update,
1924
        color = EXCLUDED.color,
1925
        signature = EXCLUDED.signature
1926
WHERE nodes.last_update IS NULL
1927
    OR EXCLUDED.last_update > nodes.last_update
1928
RETURNING id
1929
`
1930

1931
type UpsertNodeParams struct {
1932
        Version    int16
1933
        PubKey     []byte
1934
        Alias      sql.NullString
1935
        LastUpdate sql.NullInt64
1936
        Color      sql.NullString
1937
        Signature  []byte
1938
}
1939

1940
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
×
1941
        row := q.db.QueryRowContext(ctx, upsertNode,
×
1942
                arg.Version,
×
1943
                arg.PubKey,
×
1944
                arg.Alias,
×
1945
                arg.LastUpdate,
×
1946
                arg.Color,
×
1947
                arg.Signature,
×
1948
        )
×
1949
        var id int64
×
1950
        err := row.Scan(&id)
×
1951
        return id, err
×
1952
}
×
1953

1954
const upsertNodeExtraType = `-- name: UpsertNodeExtraType :exec
1955
/* ─────────────────────────────────────────────
1956
   node_extra_types table queries
1957
   ─────────────────────────────────────────────
1958
*/
1959

1960
INSERT INTO node_extra_types (
1961
    node_id, type, value
1962
)
1963
VALUES ($1, $2, $3)
1964
ON CONFLICT (type, node_id)
1965
    -- Update the value if a conflict occurs on type
1966
    -- and node_id.
1967
    DO UPDATE SET value = EXCLUDED.value
1968
`
1969

1970
type UpsertNodeExtraTypeParams struct {
1971
        NodeID int64
1972
        Type   int64
1973
        Value  []byte
1974
}
1975

1976
func (q *Queries) UpsertNodeExtraType(ctx context.Context, arg UpsertNodeExtraTypeParams) error {
×
1977
        _, err := q.db.ExecContext(ctx, upsertNodeExtraType, arg.NodeID, arg.Type, arg.Value)
×
1978
        return err
×
1979
}
×
1980

1981
const upsertZombieChannel = `-- name: UpsertZombieChannel :exec
1982
/* ─────────────────────────────────────────────
1983
   zombie_channels table queries
1984
   ─────────────────────────────────────────────
1985
*/
1986

1987
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
1988
VALUES ($1, $2, $3, $4)
1989
ON CONFLICT (scid, version)
1990
DO UPDATE SET
1991
    -- If a conflict exists for the SCID and version pair, then we
1992
    -- update the node keys.
1993
    node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
1994
    node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2)
1995
`
1996

1997
type UpsertZombieChannelParams struct {
1998
        Scid     []byte
1999
        Version  int16
2000
        NodeKey1 []byte
2001
        NodeKey2 []byte
2002
}
2003

2004
func (q *Queries) UpsertZombieChannel(ctx context.Context, arg UpsertZombieChannelParams) error {
×
2005
        _, err := q.db.ExecContext(ctx, upsertZombieChannel,
×
2006
                arg.Scid,
×
2007
                arg.Version,
×
2008
                arg.NodeKey1,
×
2009
                arg.NodeKey2,
×
2010
        )
×
2011
        return err
×
2012
}
×
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