sqlc: static address migrations, models, queries

pull/733/head
Slyghtning 6 months ago
parent cd5dc903f9
commit e05891359b
No known key found for this signature in database
GPG Key ID: F82D456EA023C9BF

@ -0,0 +1 @@
DROP TABLE IF EXISTS static_addresses;

@ -0,0 +1,38 @@
-- static_address stores the static loop-in addresses that clients
-- cooperatively created with the server.
CREATE TABLE IF NOT EXISTS static_addresses (
-- id is the auto-incrementing primary key for a static address.
id INTEGER PRIMARY KEY,
-- client_pubkey is the client side public taproot key that is used to
-- construct the 2-of-2 MuSig2 taproot output that represents the static
-- address.
client_pubkey BYTEA NOT NULL,
-- server_pubkey is the server side public taproot key that is used to
-- construct the 2-of-2 MuSig2 taproot output that represents the static
-- address.
server_pubkey BYTEA NOT NULL,
-- expiry denotes the CSV delay at which funds at a specific static address
-- can be swept back to the client.
expiry INT NOT NULL,
-- client_key_family is the key family of the client public key from the
-- client's lnd wallet.
client_key_family INT NOT NULL,
-- client_key_index is the key index of the client public key from the
-- client's lnd wallet.
client_key_index INT NOT NULL,
-- pkscript is the witness program that represents the static address. It is
-- unique amongst all static addresses.
pkscript BYTEA NOT NULL UNIQUE,
-- protocol_version is the protocol version that the swap was created with.
-- Note that this version is not upgraded if the client upgrades or
-- downgrades their protocol version for static address outputs already in
-- use.
protocol_version INTEGER NOT NULL
);

@ -88,6 +88,17 @@ type ReservationUpdate struct {
UpdateTimestamp time.Time
}
type StaticAddress struct {
ID int32
ClientPubkey []byte
ServerPubkey []byte
Expiry int32
ClientKeyFamily int32
ClientKeyIndex int32
Pkscript []byte
ProtocolVersion int32
}
type Swap struct {
ID int32
SwapHash []byte

@ -9,8 +9,10 @@ import (
)
type Querier interface {
AllStaticAddresses(ctx context.Context) ([]StaticAddress, error)
ConfirmBatch(ctx context.Context, id int32) error
CreateReservation(ctx context.Context, arg CreateReservationParams) error
CreateStaticAddress(ctx context.Context, arg CreateStaticAddressParams) error
FetchLiquidityParams(ctx context.Context) ([]byte, error)
GetBatchSweeps(ctx context.Context, batchID int32) ([]GetBatchSweepsRow, error)
GetBatchSweptAmount(ctx context.Context, batchID int32) (int64, error)
@ -25,6 +27,7 @@ type Querier interface {
GetReservation(ctx context.Context, reservationID []byte) (Reservation, error)
GetReservationUpdates(ctx context.Context, reservationID []byte) ([]ReservationUpdate, error)
GetReservations(ctx context.Context) ([]Reservation, error)
GetStaticAddress(ctx context.Context, pkscript []byte) (StaticAddress, error)
GetSwapUpdates(ctx context.Context, swapHash []byte) ([]SwapUpdate, error)
GetSweepStatus(ctx context.Context, swapHash []byte) (bool, error)
GetUnconfirmedBatches(ctx context.Context) ([]SweepBatch, error)

@ -0,0 +1,25 @@
-- name: AllStaticAddresses :many
SELECT * FROM static_addresses;
-- name: GetStaticAddress :one
SELECT * FROM static_addresses
WHERE pkscript=$1;
-- name: CreateStaticAddress :exec
INSERT INTO static_addresses (
client_pubkey,
server_pubkey,
expiry,
client_key_family,
client_key_index,
pkscript,
protocol_version
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
);

@ -0,0 +1,110 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
// 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 FROM static_addresses
`
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,
); 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
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
)
`
type CreateStaticAddressParams struct {
ClientPubkey []byte
ServerPubkey []byte
Expiry int32
ClientKeyFamily int32
ClientKeyIndex int32
Pkscript []byte
ProtocolVersion 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,
)
return err
}
const getStaticAddress = `-- name: GetStaticAddress :one
SELECT id, client_pubkey, server_pubkey, expiry, client_key_family, client_key_index, pkscript, protocol_version 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,
)
return i, err
}
Loading…
Cancel
Save