mirror of
https://github.com/lightninglabs/faraday.git
synced 2026-08-13 12:33:35 +02:00
Add ScidToPeerMap, which materialises a snapshot of every short channel id paired with the pubkey of the channel's remote peer. Forwarding-data sources index events by short channel id, but downstream analyses need to attribute behaviour to the peer, not the channel. The map skips channels whose short channel id is still zero (unconfirmed), so callers see only fully advertised channels. Coverage extends TestStore with a two-channel fixture pinning the join.
229 lines
5.5 KiB
Go
229 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: chanevents.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const getChannelByChanPoint = `-- name: GetChannelByChanPoint :one
|
|
SELECT id, channel_point, short_channel_id, peer_id FROM channels WHERE channel_point = $1
|
|
`
|
|
|
|
func (q *Queries) GetChannelByChanPoint(ctx context.Context, channelPoint string) (Channel, error) {
|
|
row := q.db.QueryRowContext(ctx, getChannelByChanPoint, channelPoint)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ChannelPoint,
|
|
&i.ShortChannelID,
|
|
&i.PeerID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getChannelByShortChanID = `-- name: GetChannelByShortChanID :one
|
|
SELECT id, channel_point, short_channel_id, peer_id FROM channels WHERE short_channel_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetChannelByShortChanID(ctx context.Context, shortChannelID int64) (Channel, error) {
|
|
row := q.db.QueryRowContext(ctx, getChannelByShortChanID, shortChannelID)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ChannelPoint,
|
|
&i.ShortChannelID,
|
|
&i.PeerID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getChannelEvents = `-- name: GetChannelEvents :many
|
|
SELECT id, channel_id, event_type, timestamp, local_balance_sat, remote_balance_sat, is_sync FROM channel_events
|
|
WHERE channel_id = $1
|
|
AND id > $2
|
|
AND timestamp >= $3
|
|
AND timestamp < $4
|
|
ORDER BY id ASC
|
|
LIMIT $5
|
|
`
|
|
|
|
type GetChannelEventsParams struct {
|
|
ChannelID int64
|
|
ID int64
|
|
Timestamp time.Time
|
|
Timestamp_2 time.Time
|
|
Limit int32
|
|
}
|
|
|
|
func (q *Queries) GetChannelEvents(ctx context.Context, arg GetChannelEventsParams) ([]ChannelEvent, error) {
|
|
rows, err := q.db.QueryContext(ctx, getChannelEvents,
|
|
arg.ChannelID,
|
|
arg.ID,
|
|
arg.Timestamp,
|
|
arg.Timestamp_2,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ChannelEvent
|
|
for rows.Next() {
|
|
var i ChannelEvent
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ChannelID,
|
|
&i.EventType,
|
|
&i.Timestamp,
|
|
&i.LocalBalanceSat,
|
|
&i.RemoteBalanceSat,
|
|
&i.IsSync,
|
|
); 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 getChannels = `-- name: GetChannels :many
|
|
SELECT c.id, c.short_channel_id, p.pubkey
|
|
FROM channels c
|
|
JOIN peers p ON c.peer_id = p.id
|
|
`
|
|
|
|
type GetChannelsRow struct {
|
|
ID int64
|
|
ShortChannelID int64
|
|
Pubkey string
|
|
}
|
|
|
|
func (q *Queries) GetChannels(ctx context.Context) ([]GetChannelsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getChannels)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetChannelsRow
|
|
for rows.Next() {
|
|
var i GetChannelsRow
|
|
if err := rows.Scan(&i.ID, &i.ShortChannelID, &i.Pubkey); 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 getLatestChannelEventBefore = `-- name: GetLatestChannelEventBefore :one
|
|
SELECT id, channel_id, event_type, timestamp, local_balance_sat, remote_balance_sat, is_sync FROM channel_events
|
|
WHERE channel_id = $1 AND event_type = $2 AND timestamp < $3
|
|
ORDER BY timestamp DESC, id DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetLatestChannelEventBeforeParams struct {
|
|
ChannelID int64
|
|
EventType int16
|
|
Timestamp time.Time
|
|
}
|
|
|
|
func (q *Queries) GetLatestChannelEventBefore(ctx context.Context, arg GetLatestChannelEventBeforeParams) (ChannelEvent, error) {
|
|
row := q.db.QueryRowContext(ctx, getLatestChannelEventBefore, arg.ChannelID, arg.EventType, arg.Timestamp)
|
|
var i ChannelEvent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ChannelID,
|
|
&i.EventType,
|
|
&i.Timestamp,
|
|
&i.LocalBalanceSat,
|
|
&i.RemoteBalanceSat,
|
|
&i.IsSync,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPeerByPubKey = `-- name: GetPeerByPubKey :one
|
|
SELECT id, pubkey FROM peers WHERE pubkey = $1
|
|
`
|
|
|
|
func (q *Queries) GetPeerByPubKey(ctx context.Context, pubkey string) (Peer, error) {
|
|
row := q.db.QueryRowContext(ctx, getPeerByPubKey, pubkey)
|
|
var i Peer
|
|
err := row.Scan(&i.ID, &i.Pubkey)
|
|
return i, err
|
|
}
|
|
|
|
const insertChannel = `-- name: InsertChannel :one
|
|
INSERT INTO channels (channel_point, short_channel_id, peer_id) VALUES ($1, $2, $3) RETURNING id
|
|
`
|
|
|
|
type InsertChannelParams struct {
|
|
ChannelPoint string
|
|
ShortChannelID int64
|
|
PeerID int64
|
|
}
|
|
|
|
func (q *Queries) InsertChannel(ctx context.Context, arg InsertChannelParams) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, insertChannel, arg.ChannelPoint, arg.ShortChannelID, arg.PeerID)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const insertChannelEvent = `-- name: InsertChannelEvent :exec
|
|
INSERT INTO channel_events (
|
|
channel_id, event_type, timestamp, local_balance_sat, remote_balance_sat,
|
|
is_sync
|
|
) VALUES ($1, $2, $3, $4, $5, $6)
|
|
`
|
|
|
|
type InsertChannelEventParams struct {
|
|
ChannelID int64
|
|
EventType int16
|
|
Timestamp time.Time
|
|
LocalBalanceSat sql.NullInt64
|
|
RemoteBalanceSat sql.NullInt64
|
|
IsSync bool
|
|
}
|
|
|
|
func (q *Queries) InsertChannelEvent(ctx context.Context, arg InsertChannelEventParams) error {
|
|
_, err := q.db.ExecContext(ctx, insertChannelEvent,
|
|
arg.ChannelID,
|
|
arg.EventType,
|
|
arg.Timestamp,
|
|
arg.LocalBalanceSat,
|
|
arg.RemoteBalanceSat,
|
|
arg.IsSync,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertPeer = `-- name: InsertPeer :one
|
|
INSERT INTO peers (pubkey) VALUES ($1) RETURNING id
|
|
`
|
|
|
|
func (q *Queries) InsertPeer(ctx context.Context, pubkey string) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, insertPeer, pubkey)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|