sqldb+graph/db: implement FilterChannelRange

This lets us run `TestFilterChannelRange` against the SQL backends.
This commit is contained in:
Elle Mouton
2025-06-11 16:47:07 +02:00
parent ff84fa1cb2
commit 3687171cd5
6 changed files with 235 additions and 1 deletions

View File

@@ -316,6 +316,42 @@ func (q *Queries) GetChannelFeaturesAndExtras(ctx context.Context, channelID int
return items, nil
}
const getChannelPolicyByChannelAndNode = `-- name: GetChannelPolicyByChannelAndNode :one
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
FROM channel_policies
WHERE channel_id = $1
AND node_id = $2
AND version = $3
`
type GetChannelPolicyByChannelAndNodeParams struct {
ChannelID int64
NodeID int64
Version int16
}
func (q *Queries) GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error) {
row := q.db.QueryRowContext(ctx, getChannelPolicyByChannelAndNode, arg.ChannelID, arg.NodeID, arg.Version)
var i ChannelPolicy
err := row.Scan(
&i.ID,
&i.Version,
&i.ChannelID,
&i.NodeID,
&i.Timelock,
&i.FeePpm,
&i.BaseFeeMsat,
&i.MinHtlcMsat,
&i.MaxHtlcMsat,
&i.LastUpdate,
&i.Disabled,
&i.InboundBaseFeeMsat,
&i.InboundFeeRateMilliMsat,
&i.Signature,
)
return i, err
}
const getChannelPolicyExtraTypes = `-- name: GetChannelPolicyExtraTypes :many
SELECT
cp.id AS policy_id,
@@ -767,6 +803,56 @@ func (q *Queries) GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByL
return items, nil
}
const getPublicV1ChannelsBySCID = `-- name: GetPublicV1ChannelsBySCID :many
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
WHERE node_1_signature IS NOT NULL
AND scid >= $1
AND scid < $2
`
type GetPublicV1ChannelsBySCIDParams struct {
StartScid []byte
EndScid []byte
}
func (q *Queries) GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error) {
rows, err := q.db.QueryContext(ctx, getPublicV1ChannelsBySCID, arg.StartScid, arg.EndScid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Channel
for rows.Next() {
var i Channel
if err := rows.Scan(
&i.ID,
&i.Version,
&i.Scid,
&i.NodeID1,
&i.NodeID2,
&i.Outpoint,
&i.Capacity,
&i.BitcoinKey1,
&i.BitcoinKey2,
&i.Node1Signature,
&i.Node2Signature,
&i.Bitcoin1Signature,
&i.Bitcoin2Signature,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getSourceNodesByVersion = `-- name: GetSourceNodesByVersion :many
SELECT sn.node_id, n.pub_key
FROM source_nodes sn