mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
instantout: add instantout store
This commit is contained in:
parent
56ed6f7ccb
commit
ee0309f942
9 changed files with 958 additions and 3 deletions
329
loopdb/sqlc/instantout.sql.go
Normal file
329
loopdb/sqlc/instantout.sql.go
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.17.2
|
||||
// source: instantout.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
const getInstantOutSwap = `-- name: GetInstantOutSwap :one
|
||||
SELECT
|
||||
swaps.id, swaps.swap_hash, swaps.preimage, swaps.initiation_time, swaps.amount_requested, swaps.cltv_expiry, swaps.max_miner_fee, swaps.max_swap_fee, swaps.initiation_height, swaps.protocol_version, swaps.label,
|
||||
instantout_swaps.swap_hash, instantout_swaps.preimage, instantout_swaps.sweep_address, instantout_swaps.outgoing_chan_set, instantout_swaps.htlc_fee_rate, instantout_swaps.reservation_ids, instantout_swaps.swap_invoice, instantout_swaps.finalized_htlc_tx, instantout_swaps.sweep_tx_hash, instantout_swaps.finalized_sweepless_sweep_tx, instantout_swaps.sweep_confirmation_height,
|
||||
htlc_keys.swap_hash, htlc_keys.sender_script_pubkey, htlc_keys.receiver_script_pubkey, htlc_keys.sender_internal_pubkey, htlc_keys.receiver_internal_pubkey, htlc_keys.client_key_family, htlc_keys.client_key_index
|
||||
FROM
|
||||
swaps
|
||||
JOIN
|
||||
instantout_swaps ON swaps.swap_hash = instantout_swaps.swap_hash
|
||||
JOIN
|
||||
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
|
||||
WHERE
|
||||
swaps.swap_hash = $1
|
||||
`
|
||||
|
||||
type GetInstantOutSwapRow struct {
|
||||
ID int32
|
||||
SwapHash []byte
|
||||
Preimage []byte
|
||||
InitiationTime time.Time
|
||||
AmountRequested int64
|
||||
CltvExpiry int32
|
||||
MaxMinerFee int64
|
||||
MaxSwapFee int64
|
||||
InitiationHeight int32
|
||||
ProtocolVersion int32
|
||||
Label string
|
||||
SwapHash_2 []byte
|
||||
Preimage_2 []byte
|
||||
SweepAddress string
|
||||
OutgoingChanSet string
|
||||
HtlcFeeRate int64
|
||||
ReservationIds []byte
|
||||
SwapInvoice string
|
||||
FinalizedHtlcTx []byte
|
||||
SweepTxHash []byte
|
||||
FinalizedSweeplessSweepTx []byte
|
||||
SweepConfirmationHeight sql.NullInt32
|
||||
SwapHash_3 []byte
|
||||
SenderScriptPubkey []byte
|
||||
ReceiverScriptPubkey []byte
|
||||
SenderInternalPubkey []byte
|
||||
ReceiverInternalPubkey []byte
|
||||
ClientKeyFamily int32
|
||||
ClientKeyIndex int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetInstantOutSwap(ctx context.Context, swapHash []byte) (GetInstantOutSwapRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getInstantOutSwap, swapHash)
|
||||
var i GetInstantOutSwapRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SwapHash,
|
||||
&i.Preimage,
|
||||
&i.InitiationTime,
|
||||
&i.AmountRequested,
|
||||
&i.CltvExpiry,
|
||||
&i.MaxMinerFee,
|
||||
&i.MaxSwapFee,
|
||||
&i.InitiationHeight,
|
||||
&i.ProtocolVersion,
|
||||
&i.Label,
|
||||
&i.SwapHash_2,
|
||||
&i.Preimage_2,
|
||||
&i.SweepAddress,
|
||||
&i.OutgoingChanSet,
|
||||
&i.HtlcFeeRate,
|
||||
&i.ReservationIds,
|
||||
&i.SwapInvoice,
|
||||
&i.FinalizedHtlcTx,
|
||||
&i.SweepTxHash,
|
||||
&i.FinalizedSweeplessSweepTx,
|
||||
&i.SweepConfirmationHeight,
|
||||
&i.SwapHash_3,
|
||||
&i.SenderScriptPubkey,
|
||||
&i.ReceiverScriptPubkey,
|
||||
&i.SenderInternalPubkey,
|
||||
&i.ReceiverInternalPubkey,
|
||||
&i.ClientKeyFamily,
|
||||
&i.ClientKeyIndex,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getInstantOutSwapUpdates = `-- name: GetInstantOutSwapUpdates :many
|
||||
SELECT
|
||||
instantout_updates.id, instantout_updates.swap_hash, instantout_updates.update_state, instantout_updates.update_timestamp
|
||||
FROM
|
||||
instantout_updates
|
||||
WHERE
|
||||
instantout_updates.swap_hash = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetInstantOutSwapUpdates(ctx context.Context, swapHash []byte) ([]InstantoutUpdate, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getInstantOutSwapUpdates, swapHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []InstantoutUpdate
|
||||
for rows.Next() {
|
||||
var i InstantoutUpdate
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SwapHash,
|
||||
&i.UpdateState,
|
||||
&i.UpdateTimestamp,
|
||||
); 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 getInstantOutSwaps = `-- name: GetInstantOutSwaps :many
|
||||
SELECT
|
||||
swaps.id, swaps.swap_hash, swaps.preimage, swaps.initiation_time, swaps.amount_requested, swaps.cltv_expiry, swaps.max_miner_fee, swaps.max_swap_fee, swaps.initiation_height, swaps.protocol_version, swaps.label,
|
||||
instantout_swaps.swap_hash, instantout_swaps.preimage, instantout_swaps.sweep_address, instantout_swaps.outgoing_chan_set, instantout_swaps.htlc_fee_rate, instantout_swaps.reservation_ids, instantout_swaps.swap_invoice, instantout_swaps.finalized_htlc_tx, instantout_swaps.sweep_tx_hash, instantout_swaps.finalized_sweepless_sweep_tx, instantout_swaps.sweep_confirmation_height,
|
||||
htlc_keys.swap_hash, htlc_keys.sender_script_pubkey, htlc_keys.receiver_script_pubkey, htlc_keys.sender_internal_pubkey, htlc_keys.receiver_internal_pubkey, htlc_keys.client_key_family, htlc_keys.client_key_index
|
||||
FROM
|
||||
swaps
|
||||
JOIN
|
||||
instantout_swaps ON swaps.swap_hash = instantout_swaps.swap_hash
|
||||
JOIN
|
||||
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
|
||||
ORDER BY
|
||||
swaps.id
|
||||
`
|
||||
|
||||
type GetInstantOutSwapsRow struct {
|
||||
ID int32
|
||||
SwapHash []byte
|
||||
Preimage []byte
|
||||
InitiationTime time.Time
|
||||
AmountRequested int64
|
||||
CltvExpiry int32
|
||||
MaxMinerFee int64
|
||||
MaxSwapFee int64
|
||||
InitiationHeight int32
|
||||
ProtocolVersion int32
|
||||
Label string
|
||||
SwapHash_2 []byte
|
||||
Preimage_2 []byte
|
||||
SweepAddress string
|
||||
OutgoingChanSet string
|
||||
HtlcFeeRate int64
|
||||
ReservationIds []byte
|
||||
SwapInvoice string
|
||||
FinalizedHtlcTx []byte
|
||||
SweepTxHash []byte
|
||||
FinalizedSweeplessSweepTx []byte
|
||||
SweepConfirmationHeight sql.NullInt32
|
||||
SwapHash_3 []byte
|
||||
SenderScriptPubkey []byte
|
||||
ReceiverScriptPubkey []byte
|
||||
SenderInternalPubkey []byte
|
||||
ReceiverInternalPubkey []byte
|
||||
ClientKeyFamily int32
|
||||
ClientKeyIndex int32
|
||||
}
|
||||
|
||||
func (q *Queries) GetInstantOutSwaps(ctx context.Context) ([]GetInstantOutSwapsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getInstantOutSwaps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetInstantOutSwapsRow
|
||||
for rows.Next() {
|
||||
var i GetInstantOutSwapsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SwapHash,
|
||||
&i.Preimage,
|
||||
&i.InitiationTime,
|
||||
&i.AmountRequested,
|
||||
&i.CltvExpiry,
|
||||
&i.MaxMinerFee,
|
||||
&i.MaxSwapFee,
|
||||
&i.InitiationHeight,
|
||||
&i.ProtocolVersion,
|
||||
&i.Label,
|
||||
&i.SwapHash_2,
|
||||
&i.Preimage_2,
|
||||
&i.SweepAddress,
|
||||
&i.OutgoingChanSet,
|
||||
&i.HtlcFeeRate,
|
||||
&i.ReservationIds,
|
||||
&i.SwapInvoice,
|
||||
&i.FinalizedHtlcTx,
|
||||
&i.SweepTxHash,
|
||||
&i.FinalizedSweeplessSweepTx,
|
||||
&i.SweepConfirmationHeight,
|
||||
&i.SwapHash_3,
|
||||
&i.SenderScriptPubkey,
|
||||
&i.ReceiverScriptPubkey,
|
||||
&i.SenderInternalPubkey,
|
||||
&i.ReceiverInternalPubkey,
|
||||
&i.ClientKeyFamily,
|
||||
&i.ClientKeyIndex,
|
||||
); 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 insertInstantOut = `-- name: InsertInstantOut :exec
|
||||
INSERT INTO instantout_swaps (
|
||||
swap_hash,
|
||||
preimage,
|
||||
sweep_address,
|
||||
outgoing_chan_set,
|
||||
htlc_fee_rate,
|
||||
reservation_ids,
|
||||
swap_invoice
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
)
|
||||
`
|
||||
|
||||
type InsertInstantOutParams struct {
|
||||
SwapHash []byte
|
||||
Preimage []byte
|
||||
SweepAddress string
|
||||
OutgoingChanSet string
|
||||
HtlcFeeRate int64
|
||||
ReservationIds []byte
|
||||
SwapInvoice string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertInstantOut(ctx context.Context, arg InsertInstantOutParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertInstantOut,
|
||||
arg.SwapHash,
|
||||
arg.Preimage,
|
||||
arg.SweepAddress,
|
||||
arg.OutgoingChanSet,
|
||||
arg.HtlcFeeRate,
|
||||
arg.ReservationIds,
|
||||
arg.SwapInvoice,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertInstantOutUpdate = `-- name: InsertInstantOutUpdate :exec
|
||||
INSERT INTO instantout_updates (
|
||||
swap_hash,
|
||||
update_state,
|
||||
update_timestamp
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
)
|
||||
`
|
||||
|
||||
type InsertInstantOutUpdateParams struct {
|
||||
SwapHash []byte
|
||||
UpdateState string
|
||||
UpdateTimestamp time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) InsertInstantOutUpdate(ctx context.Context, arg InsertInstantOutUpdateParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertInstantOutUpdate, arg.SwapHash, arg.UpdateState, arg.UpdateTimestamp)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateInstantOut = `-- name: UpdateInstantOut :exec
|
||||
UPDATE instantout_swaps
|
||||
SET
|
||||
finalized_htlc_tx = $2,
|
||||
sweep_tx_hash = $3,
|
||||
finalized_sweepless_sweep_tx = $4,
|
||||
sweep_confirmation_height = $5
|
||||
WHERE
|
||||
instantout_swaps.swap_hash = $1
|
||||
`
|
||||
|
||||
type UpdateInstantOutParams struct {
|
||||
SwapHash []byte
|
||||
FinalizedHtlcTx []byte
|
||||
SweepTxHash []byte
|
||||
FinalizedSweeplessSweepTx []byte
|
||||
SweepConfirmationHeight sql.NullInt32
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateInstantOut(ctx context.Context, arg UpdateInstantOutParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateInstantOut,
|
||||
arg.SwapHash,
|
||||
arg.FinalizedHtlcTx,
|
||||
arg.SweepTxHash,
|
||||
arg.FinalizedSweeplessSweepTx,
|
||||
arg.SweepConfirmationHeight,
|
||||
)
|
||||
return err
|
||||
}
|
||||
4
loopdb/sqlc/migrations/000006_instantout.down.sql
Normal file
4
loopdb/sqlc/migrations/000006_instantout.down.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DROP INDEX IF EXISTS instantout_updates_swap_hash_idx;
|
||||
DROP INDEX IF EXISTS instantout_swap_hash_idx;
|
||||
DROP TABLE IF EXISTS instantout_updates;
|
||||
DROP TABLE IF EXISTS instantout_swaps;
|
||||
52
loopdb/sqlc/migrations/000006_instantout.up.sql
Normal file
52
loopdb/sqlc/migrations/000006_instantout.up.sql
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
CREATE TABLE IF NOT EXISTS instantout_swaps (
|
||||
-- swap_hash points to the parent swap hash.
|
||||
swap_hash BLOB PRIMARY KEY,
|
||||
|
||||
-- preimage is the preimage of the swap.
|
||||
preimage BLOB NOT NULL,
|
||||
|
||||
-- sweep_address is the address that the server should sweep the funds to.
|
||||
sweep_address TEXT NOT NULL,
|
||||
|
||||
-- outgoing_chan_set is the set of short ids of channels that may be used.
|
||||
-- If empty, any channel may be used.
|
||||
outgoing_chan_set TEXT NOT NULL,
|
||||
|
||||
-- htlc_fee_rate is the fee rate in sat/kw that is used for the htlc transaction.
|
||||
htlc_fee_rate BIGINT NOT NULL,
|
||||
|
||||
-- reservation_ids is a list of ids of the reservations that are used for this swap.
|
||||
reservation_ids BLOB NOT NULL,
|
||||
|
||||
-- swap_invoice is the invoice that is to be paid by the client to
|
||||
-- initiate the loop out swap.
|
||||
swap_invoice TEXT NOT NULL,
|
||||
|
||||
-- finalized_htlc_tx contains the fully signed htlc transaction.
|
||||
finalized_htlc_tx BLOB,
|
||||
|
||||
-- sweep_tx_hash is the hash of the transaction that sweeps the htlc.
|
||||
sweep_tx_hash BLOB,
|
||||
|
||||
-- finalized_sweepless_sweep_tx contains the fully signed sweepless sweep transaction.
|
||||
finalized_sweepless_sweep_tx BLOB,
|
||||
|
||||
-- sweep_confirmation_height is the block height at which the sweep transaction is confirmed.
|
||||
sweep_confirmation_height INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS instantout_updates (
|
||||
-- id is auto incremented for each update.
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
||||
-- swap_hash is the hash of the swap that this update is for.
|
||||
swap_hash BLOB NOT NULL REFERENCES instantout_swaps(swap_hash),
|
||||
|
||||
-- update_state is the state of the swap at the time of the update.
|
||||
update_state TEXT NOT NULL,
|
||||
|
||||
-- update_timestamp is the time at which the update was created.
|
||||
update_timestamp TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS instantout_updates_swap_hash_idx ON instantout_updates(swap_hash);
|
||||
|
|
@ -19,6 +19,27 @@ type HtlcKey struct {
|
|||
ClientKeyIndex int32
|
||||
}
|
||||
|
||||
type InstantoutSwap struct {
|
||||
SwapHash []byte
|
||||
Preimage []byte
|
||||
SweepAddress string
|
||||
OutgoingChanSet string
|
||||
HtlcFeeRate int64
|
||||
ReservationIds []byte
|
||||
SwapInvoice string
|
||||
FinalizedHtlcTx []byte
|
||||
SweepTxHash []byte
|
||||
FinalizedSweeplessSweepTx []byte
|
||||
SweepConfirmationHeight sql.NullInt32
|
||||
}
|
||||
|
||||
type InstantoutUpdate struct {
|
||||
ID int32
|
||||
SwapHash []byte
|
||||
UpdateState string
|
||||
UpdateTimestamp time.Time
|
||||
}
|
||||
|
||||
type LiquidityParam struct {
|
||||
ID int32
|
||||
Params []byte
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ type Querier interface {
|
|||
CreateReservation(ctx context.Context, arg CreateReservationParams) error
|
||||
FetchLiquidityParams(ctx context.Context) ([]byte, error)
|
||||
GetBatchSweeps(ctx context.Context, batchID int32) ([]GetBatchSweepsRow, error)
|
||||
GetInstantOutSwap(ctx context.Context, swapHash []byte) (GetInstantOutSwapRow, error)
|
||||
GetInstantOutSwapUpdates(ctx context.Context, swapHash []byte) ([]InstantoutUpdate, error)
|
||||
GetInstantOutSwaps(ctx context.Context) ([]GetInstantOutSwapsRow, error)
|
||||
GetLoopInSwap(ctx context.Context, swapHash []byte) (GetLoopInSwapRow, error)
|
||||
GetLoopInSwaps(ctx context.Context) ([]GetLoopInSwapsRow, error)
|
||||
GetLoopOutSwap(ctx context.Context, swapHash []byte) (GetLoopOutSwapRow, error)
|
||||
|
|
@ -25,12 +28,15 @@ type Querier interface {
|
|||
GetUnconfirmedBatches(ctx context.Context) ([]SweepBatch, error)
|
||||
InsertBatch(ctx context.Context, arg InsertBatchParams) (int32, error)
|
||||
InsertHtlcKeys(ctx context.Context, arg InsertHtlcKeysParams) error
|
||||
InsertInstantOut(ctx context.Context, arg InsertInstantOutParams) error
|
||||
InsertInstantOutUpdate(ctx context.Context, arg InsertInstantOutUpdateParams) error
|
||||
InsertLoopIn(ctx context.Context, arg InsertLoopInParams) error
|
||||
InsertLoopOut(ctx context.Context, arg InsertLoopOutParams) error
|
||||
InsertReservationUpdate(ctx context.Context, arg InsertReservationUpdateParams) error
|
||||
InsertSwap(ctx context.Context, arg InsertSwapParams) error
|
||||
InsertSwapUpdate(ctx context.Context, arg InsertSwapUpdateParams) error
|
||||
UpdateBatch(ctx context.Context, arg UpdateBatchParams) error
|
||||
UpdateInstantOut(ctx context.Context, arg UpdateInstantOutParams) error
|
||||
UpdateReservation(ctx context.Context, arg UpdateReservationParams) error
|
||||
UpsertLiquidityParams(ctx context.Context, params []byte) error
|
||||
UpsertSweep(ctx context.Context, arg UpsertSweepParams) error
|
||||
|
|
|
|||
75
loopdb/sqlc/queries/instantout.sql
Normal file
75
loopdb/sqlc/queries/instantout.sql
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
-- name: InsertInstantOut :exec
|
||||
INSERT INTO instantout_swaps (
|
||||
swap_hash,
|
||||
preimage,
|
||||
sweep_address,
|
||||
outgoing_chan_set,
|
||||
htlc_fee_rate,
|
||||
reservation_ids,
|
||||
swap_invoice
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
);
|
||||
|
||||
-- name: UpdateInstantOut :exec
|
||||
UPDATE instantout_swaps
|
||||
SET
|
||||
finalized_htlc_tx = $2,
|
||||
sweep_tx_hash = $3,
|
||||
finalized_sweepless_sweep_tx = $4,
|
||||
sweep_confirmation_height = $5
|
||||
WHERE
|
||||
instantout_swaps.swap_hash = $1;
|
||||
|
||||
-- name: InsertInstantOutUpdate :exec
|
||||
INSERT INTO instantout_updates (
|
||||
swap_hash,
|
||||
update_state,
|
||||
update_timestamp
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
);
|
||||
|
||||
-- name: GetInstantOutSwap :one
|
||||
SELECT
|
||||
swaps.*,
|
||||
instantout_swaps.*,
|
||||
htlc_keys.*
|
||||
FROM
|
||||
swaps
|
||||
JOIN
|
||||
instantout_swaps ON swaps.swap_hash = instantout_swaps.swap_hash
|
||||
JOIN
|
||||
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
|
||||
WHERE
|
||||
swaps.swap_hash = $1;
|
||||
|
||||
-- name: GetInstantOutSwaps :many
|
||||
SELECT
|
||||
swaps.*,
|
||||
instantout_swaps.*,
|
||||
htlc_keys.*
|
||||
FROM
|
||||
swaps
|
||||
JOIN
|
||||
instantout_swaps ON swaps.swap_hash = instantout_swaps.swap_hash
|
||||
JOIN
|
||||
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
|
||||
ORDER BY
|
||||
swaps.id;
|
||||
|
||||
-- name: GetInstantOutSwapUpdates :many
|
||||
SELECT
|
||||
instantout_updates.*
|
||||
FROM
|
||||
instantout_updates
|
||||
WHERE
|
||||
instantout_updates.swap_hash = $1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue