mirror of https://github.com/lightninglabs/loop
sqlc: static address migrations, models, queries
parent
cd5dc903f9
commit
e05891359b
@ -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
|
||||||
|
);
|
@ -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…
Reference in New Issue