mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Associate every deposit with the static address parameters that created it. This lets restored deposits recover the correct script and signing keys instead of assuming the legacy root address.
152 lines
3.5 KiB
Go
152 lines
3.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: static_addresses.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const allStaticAddresses = `-- name: AllStaticAddresses :many
|
|
SELECT id, client_pubkey, server_pubkey, expiry, client_key_family, client_key_index, pkscript, protocol_version, initiation_height FROM static_addresses
|
|
ORDER BY id ASC
|
|
`
|
|
|
|
func (q *Queries) AllStaticAddresses(ctx context.Context) ([]StaticAddress, error) {
|
|
rows, err := q.db.QueryContext(ctx, allStaticAddresses)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []StaticAddress
|
|
for rows.Next() {
|
|
var i StaticAddress
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ClientPubkey,
|
|
&i.ServerPubkey,
|
|
&i.Expiry,
|
|
&i.ClientKeyFamily,
|
|
&i.ClientKeyIndex,
|
|
&i.Pkscript,
|
|
&i.ProtocolVersion,
|
|
&i.InitiationHeight,
|
|
); 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 createStaticAddress = `-- name: CreateStaticAddress :exec
|
|
INSERT INTO static_addresses (
|
|
client_pubkey,
|
|
server_pubkey,
|
|
expiry,
|
|
client_key_family,
|
|
client_key_index,
|
|
pkscript,
|
|
protocol_version,
|
|
initiation_height
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8
|
|
)
|
|
`
|
|
|
|
type CreateStaticAddressParams struct {
|
|
ClientPubkey []byte
|
|
ServerPubkey []byte
|
|
Expiry int32
|
|
ClientKeyFamily int32
|
|
ClientKeyIndex int32
|
|
Pkscript []byte
|
|
ProtocolVersion int32
|
|
InitiationHeight int32
|
|
}
|
|
|
|
func (q *Queries) CreateStaticAddress(ctx context.Context, arg CreateStaticAddressParams) error {
|
|
_, err := q.db.ExecContext(ctx, createStaticAddress,
|
|
arg.ClientPubkey,
|
|
arg.ServerPubkey,
|
|
arg.Expiry,
|
|
arg.ClientKeyFamily,
|
|
arg.ClientKeyIndex,
|
|
arg.Pkscript,
|
|
arg.ProtocolVersion,
|
|
arg.InitiationHeight,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const getLegacyAddress = `-- name: GetLegacyAddress :one
|
|
SELECT id, client_pubkey, server_pubkey, expiry, client_key_family, client_key_index, pkscript, protocol_version, initiation_height FROM static_addresses
|
|
ORDER BY id ASC
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetLegacyAddress(ctx context.Context) (StaticAddress, error) {
|
|
row := q.db.QueryRowContext(ctx, getLegacyAddress)
|
|
var i StaticAddress
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ClientPubkey,
|
|
&i.ServerPubkey,
|
|
&i.Expiry,
|
|
&i.ClientKeyFamily,
|
|
&i.ClientKeyIndex,
|
|
&i.Pkscript,
|
|
&i.ProtocolVersion,
|
|
&i.InitiationHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getStaticAddress = `-- name: GetStaticAddress :one
|
|
SELECT id, client_pubkey, server_pubkey, expiry, client_key_family, client_key_index, pkscript, protocol_version, initiation_height FROM static_addresses
|
|
WHERE pkscript=$1
|
|
`
|
|
|
|
func (q *Queries) GetStaticAddress(ctx context.Context, pkscript []byte) (StaticAddress, error) {
|
|
row := q.db.QueryRowContext(ctx, getStaticAddress, pkscript)
|
|
var i StaticAddress
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ClientPubkey,
|
|
&i.ServerPubkey,
|
|
&i.Expiry,
|
|
&i.ClientKeyFamily,
|
|
&i.ClientKeyIndex,
|
|
&i.Pkscript,
|
|
&i.ProtocolVersion,
|
|
&i.InitiationHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getStaticAddressID = `-- name: GetStaticAddressID :one
|
|
SELECT id FROM static_addresses
|
|
WHERE pkscript=$1
|
|
`
|
|
|
|
func (q *Queries) GetStaticAddressID(ctx context.Context, pkscript []byte) (int32, error) {
|
|
row := q.db.QueryRowContext(ctx, getStaticAddressID, pkscript)
|
|
var id int32
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|