mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Merge pull request #764 from bhandras/costs-cleanup-migration
loop: add migration to fix stored loop out costs
This commit is contained in:
commit
55241ffe04
18 changed files with 805 additions and 8 deletions
45
loopdb/sqlc/migration_tracker.sql.go
Normal file
45
loopdb/sqlc/migration_tracker.sql.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.25.0
|
||||
// source: migration_tracker.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const getMigration = `-- name: GetMigration :one
|
||||
SELECT
|
||||
migration_id,
|
||||
migration_ts
|
||||
FROM
|
||||
migration_tracker
|
||||
WHERE
|
||||
migration_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetMigration(ctx context.Context, migrationID string) (MigrationTracker, error) {
|
||||
row := q.db.QueryRowContext(ctx, getMigration, migrationID)
|
||||
var i MigrationTracker
|
||||
err := row.Scan(&i.MigrationID, &i.MigrationTs)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertMigration = `-- name: InsertMigration :exec
|
||||
INSERT INTO migration_tracker (
|
||||
migration_id,
|
||||
migration_ts
|
||||
) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type InsertMigrationParams struct {
|
||||
MigrationID string
|
||||
MigrationTs sql.NullTime
|
||||
}
|
||||
|
||||
func (q *Queries) InsertMigration(ctx context.Context, arg InsertMigrationParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertMigration, arg.MigrationID, arg.MigrationTs)
|
||||
return err
|
||||
}
|
||||
2
loopdb/sqlc/migrations/000008_migration_tracker.down.sql
Normal file
2
loopdb/sqlc/migrations/000008_migration_tracker.down.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DROP TABLE migration_tracker;
|
||||
|
||||
9
loopdb/sqlc/migrations/000008_migration_tracker.up.sql
Normal file
9
loopdb/sqlc/migrations/000008_migration_tracker.up.sql
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
CREATE TABLE migration_tracker (
|
||||
-- migration_id is the id of the migration.
|
||||
migration_id TEXT NOT NULL,
|
||||
|
||||
-- migration_ts is the timestamp at which the migration was run.
|
||||
migration_ts TIMESTAMP,
|
||||
|
||||
PRIMARY KEY (migration_id)
|
||||
);
|
||||
|
|
@ -67,6 +67,11 @@ type LoopoutSwap struct {
|
|||
PaymentTimeout int32
|
||||
}
|
||||
|
||||
type MigrationTracker struct {
|
||||
MigrationID string
|
||||
MigrationTs sql.NullTime
|
||||
}
|
||||
|
||||
type Reservation struct {
|
||||
ID int32
|
||||
ReservationID []byte
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@ type Querier interface {
|
|||
GetInstantOutSwap(ctx context.Context, swapHash []byte) (GetInstantOutSwapRow, error)
|
||||
GetInstantOutSwapUpdates(ctx context.Context, swapHash []byte) ([]InstantoutUpdate, error)
|
||||
GetInstantOutSwaps(ctx context.Context) ([]GetInstantOutSwapsRow, error)
|
||||
GetLastUpdateID(ctx context.Context, swapHash []byte) (int32, error)
|
||||
GetLoopInSwap(ctx context.Context, swapHash []byte) (GetLoopInSwapRow, error)
|
||||
GetLoopInSwaps(ctx context.Context) ([]GetLoopInSwapsRow, error)
|
||||
GetLoopOutSwap(ctx context.Context, swapHash []byte) (GetLoopOutSwapRow, error)
|
||||
GetLoopOutSwaps(ctx context.Context) ([]GetLoopOutSwapsRow, error)
|
||||
GetMigration(ctx context.Context, migrationID string) (MigrationTracker, error)
|
||||
GetParentBatch(ctx context.Context, swapHash []byte) (SweepBatch, error)
|
||||
GetReservation(ctx context.Context, reservationID []byte) (Reservation, error)
|
||||
GetReservationUpdates(ctx context.Context, reservationID []byte) ([]ReservationUpdate, error)
|
||||
|
|
@ -35,9 +37,11 @@ type Querier interface {
|
|||
InsertInstantOutUpdate(ctx context.Context, arg InsertInstantOutUpdateParams) error
|
||||
InsertLoopIn(ctx context.Context, arg InsertLoopInParams) error
|
||||
InsertLoopOut(ctx context.Context, arg InsertLoopOutParams) error
|
||||
InsertMigration(ctx context.Context, arg InsertMigrationParams) error
|
||||
InsertReservationUpdate(ctx context.Context, arg InsertReservationUpdateParams) error
|
||||
InsertSwap(ctx context.Context, arg InsertSwapParams) error
|
||||
InsertSwapUpdate(ctx context.Context, arg InsertSwapUpdateParams) error
|
||||
OverrideSwapCosts(ctx context.Context, arg OverrideSwapCostsParams) error
|
||||
UpdateBatch(ctx context.Context, arg UpdateBatchParams) error
|
||||
UpdateInstantOut(ctx context.Context, arg UpdateInstantOutParams) error
|
||||
UpdateReservation(ctx context.Context, arg UpdateReservationParams) error
|
||||
|
|
|
|||
14
loopdb/sqlc/queries/migration_tracker.sql
Normal file
14
loopdb/sqlc/queries/migration_tracker.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- name: InsertMigration :exec
|
||||
INSERT INTO migration_tracker (
|
||||
migration_id,
|
||||
migration_ts
|
||||
) VALUES ($1, $2);
|
||||
|
||||
-- name: GetMigration :one
|
||||
SELECT
|
||||
migration_id,
|
||||
migration_ts
|
||||
FROM
|
||||
migration_tracker
|
||||
WHERE
|
||||
migration_id = $1;
|
||||
|
|
@ -133,3 +133,19 @@ INSERT INTO htlc_keys(
|
|||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7
|
||||
);
|
||||
|
||||
-- name: GetLastUpdateID :one
|
||||
SELECT id
|
||||
FROM swap_updates
|
||||
WHERE swap_hash = $1
|
||||
ORDER BY update_timestamp DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: OverrideSwapCosts :exec
|
||||
UPDATE swap_updates
|
||||
SET
|
||||
server_cost = $2,
|
||||
onchain_cost = $3,
|
||||
offchain_cost = $4
|
||||
WHERE id = $1;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,21 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const getLastUpdateID = `-- name: GetLastUpdateID :one
|
||||
SELECT id
|
||||
FROM swap_updates
|
||||
WHERE swap_hash = $1
|
||||
ORDER BY update_timestamp DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetLastUpdateID(ctx context.Context, swapHash []byte) (int32, error) {
|
||||
row := q.db.QueryRowContext(ctx, getLastUpdateID, swapHash)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getLoopInSwap = `-- name: GetLoopInSwap :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,
|
||||
|
|
@ -596,3 +611,29 @@ func (q *Queries) InsertSwapUpdate(ctx context.Context, arg InsertSwapUpdatePara
|
|||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const overrideSwapCosts = `-- name: OverrideSwapCosts :exec
|
||||
UPDATE swap_updates
|
||||
SET
|
||||
server_cost = $2,
|
||||
onchain_cost = $3,
|
||||
offchain_cost = $4
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
type OverrideSwapCostsParams struct {
|
||||
ID int32
|
||||
ServerCost int64
|
||||
OnchainCost int64
|
||||
OffchainCost int64
|
||||
}
|
||||
|
||||
func (q *Queries) OverrideSwapCosts(ctx context.Context, arg OverrideSwapCostsParams) error {
|
||||
_, err := q.db.ExecContext(ctx, overrideSwapCosts,
|
||||
arg.ID,
|
||||
arg.ServerCost,
|
||||
arg.OnchainCost,
|
||||
arg.OffchainCost,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue