mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr: migrate swap hashes to deposits
This commit is contained in:
parent
35901d1247
commit
6e7441ba8d
12 changed files with 499 additions and 4 deletions
1
loopdb/sqlc/migrations/000017_deposit_swaphash.down.sql
Normal file
1
loopdb/sqlc/migrations/000017_deposit_swaphash.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE deposits DROP COLUMN swap_hash;
|
||||
1
loopdb/sqlc/migrations/000017_deposit_swaphash.up.sql
Normal file
1
loopdb/sqlc/migrations/000017_deposit_swaphash.up.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE deposits ADD swap_hash BLOB;
|
||||
|
|
@ -19,6 +19,7 @@ type Deposit struct {
|
|||
TimeoutSweepPkScript []byte
|
||||
ExpirySweepTxid []byte
|
||||
FinalizedWithdrawalTx sql.NullString
|
||||
SwapHash []byte
|
||||
}
|
||||
|
||||
type DepositUpdate struct {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type Querier interface {
|
|||
CreateWithdrawal(ctx context.Context, arg CreateWithdrawalParams) error
|
||||
CreateWithdrawalDeposit(ctx context.Context, arg CreateWithdrawalDepositParams) error
|
||||
DepositForOutpoint(ctx context.Context, arg DepositForOutpointParams) (Deposit, error)
|
||||
DepositIDsForSwapHash(ctx context.Context, swapHash []byte) ([][]byte, error)
|
||||
FetchLiquidityParams(ctx context.Context) ([]byte, error)
|
||||
GetAllWithdrawals(ctx context.Context) ([]Withdrawal, error)
|
||||
GetBatchSweeps(ctx context.Context, batchID int32) ([]Sweep, error)
|
||||
|
|
@ -62,7 +63,9 @@ type Querier interface {
|
|||
InsertSwap(ctx context.Context, arg InsertSwapParams) error
|
||||
InsertSwapUpdate(ctx context.Context, arg InsertSwapUpdateParams) error
|
||||
IsStored(ctx context.Context, swapHash []byte) (bool, error)
|
||||
MapDepositToSwap(ctx context.Context, arg MapDepositToSwapParams) error
|
||||
OverrideSwapCosts(ctx context.Context, arg OverrideSwapCostsParams) error
|
||||
SwapHashForDepositID(ctx context.Context, depositID []byte) ([]byte, error)
|
||||
UpdateBatch(ctx context.Context, arg UpdateBatchParams) error
|
||||
UpdateDeposit(ctx context.Context, arg UpdateDepositParams) error
|
||||
UpdateInstantOut(ctx context.Context, arg UpdateInstantOutParams) error
|
||||
|
|
|
|||
|
|
@ -93,3 +93,30 @@ SELECT EXISTS (
|
|||
FROM static_address_swaps
|
||||
WHERE swap_hash = $1
|
||||
);
|
||||
|
||||
-- name: MapDepositToSwap :exec
|
||||
UPDATE
|
||||
deposits
|
||||
SET
|
||||
swap_hash = $2
|
||||
WHERE
|
||||
deposit_id = $1;
|
||||
|
||||
-- name: SwapHashForDepositID :one
|
||||
SELECT
|
||||
swap_hash
|
||||
FROM
|
||||
deposits
|
||||
WHERE
|
||||
deposit_id = $1;
|
||||
|
||||
-- name: DepositIDsForSwapHash :many
|
||||
SELECT
|
||||
deposit_id
|
||||
FROM
|
||||
deposits
|
||||
WHERE
|
||||
swap_hash = $1;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
const allDeposits = `-- name: AllDeposits :many
|
||||
SELECT
|
||||
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx
|
||||
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx, swap_hash
|
||||
FROM
|
||||
deposits
|
||||
ORDER BY
|
||||
|
|
@ -39,6 +39,7 @@ func (q *Queries) AllDeposits(ctx context.Context) ([]Deposit, error) {
|
|||
&i.TimeoutSweepPkScript,
|
||||
&i.ExpirySweepTxid,
|
||||
&i.FinalizedWithdrawalTx,
|
||||
&i.SwapHash,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -102,7 +103,7 @@ func (q *Queries) CreateDeposit(ctx context.Context, arg CreateDepositParams) er
|
|||
|
||||
const depositForOutpoint = `-- name: DepositForOutpoint :one
|
||||
SELECT
|
||||
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx
|
||||
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx, swap_hash
|
||||
FROM
|
||||
deposits
|
||||
WHERE
|
||||
|
|
@ -129,13 +130,14 @@ func (q *Queries) DepositForOutpoint(ctx context.Context, arg DepositForOutpoint
|
|||
&i.TimeoutSweepPkScript,
|
||||
&i.ExpirySweepTxid,
|
||||
&i.FinalizedWithdrawalTx,
|
||||
&i.SwapHash,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getDeposit = `-- name: GetDeposit :one
|
||||
SELECT
|
||||
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx
|
||||
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx, swap_hash
|
||||
FROM
|
||||
deposits
|
||||
WHERE
|
||||
|
|
@ -155,6 +157,7 @@ func (q *Queries) GetDeposit(ctx context.Context, depositID []byte) (Deposit, er
|
|||
&i.TimeoutSweepPkScript,
|
||||
&i.ExpirySweepTxid,
|
||||
&i.FinalizedWithdrawalTx,
|
||||
&i.SwapHash,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,38 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const depositIDsForSwapHash = `-- name: DepositIDsForSwapHash :many
|
||||
SELECT
|
||||
deposit_id
|
||||
FROM
|
||||
deposits
|
||||
WHERE
|
||||
swap_hash = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DepositIDsForSwapHash(ctx context.Context, swapHash []byte) ([][]byte, error) {
|
||||
rows, err := q.db.QueryContext(ctx, depositIDsForSwapHash, swapHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items [][]byte
|
||||
for rows.Next() {
|
||||
var deposit_id []byte
|
||||
if err := rows.Scan(&deposit_id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, deposit_id)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getLoopInSwapUpdates = `-- name: GetLoopInSwapUpdates :many
|
||||
SELECT
|
||||
static_address_swap_updates.id, static_address_swap_updates.swap_hash, static_address_swap_updates.update_state, static_address_swap_updates.update_timestamp
|
||||
|
|
@ -328,6 +360,41 @@ func (q *Queries) IsStored(ctx context.Context, swapHash []byte) (bool, error) {
|
|||
return exists, err
|
||||
}
|
||||
|
||||
const mapDepositToSwap = `-- name: MapDepositToSwap :exec
|
||||
UPDATE
|
||||
deposits
|
||||
SET
|
||||
swap_hash = $2
|
||||
WHERE
|
||||
deposit_id = $1
|
||||
`
|
||||
|
||||
type MapDepositToSwapParams struct {
|
||||
DepositID []byte
|
||||
SwapHash []byte
|
||||
}
|
||||
|
||||
func (q *Queries) MapDepositToSwap(ctx context.Context, arg MapDepositToSwapParams) error {
|
||||
_, err := q.db.ExecContext(ctx, mapDepositToSwap, arg.DepositID, arg.SwapHash)
|
||||
return err
|
||||
}
|
||||
|
||||
const swapHashForDepositID = `-- name: SwapHashForDepositID :one
|
||||
SELECT
|
||||
swap_hash
|
||||
FROM
|
||||
deposits
|
||||
WHERE
|
||||
deposit_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) SwapHashForDepositID(ctx context.Context, depositID []byte) ([]byte, error) {
|
||||
row := q.db.QueryRowContext(ctx, swapHashForDepositID, depositID)
|
||||
var swap_hash []byte
|
||||
err := row.Scan(&swap_hash)
|
||||
return swap_hash, err
|
||||
}
|
||||
|
||||
const updateStaticAddressLoopIn = `-- name: UpdateStaticAddressLoopIn :exec
|
||||
UPDATE static_address_swaps
|
||||
SET
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue