loopdb: add asset params to store

This commit is contained in:
sputn1ck 2025-01-09 16:32:59 +01:00
parent 1440b6bb1d
commit 40614a2a7a
No known key found for this signature in database
GPG key ID: 671103D881A5F0E4
11 changed files with 231 additions and 5 deletions

View file

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

View file

@ -0,0 +1,22 @@
CREATE TABLE IF NOT EXISTS loopout_swaps_asset_info (
-- swap_hash points to the parent loop out swap hash.
swap_hash BLOB PRIMARY KEY REFERENCES loopout_swaps(swap_hash),
-- asset_id is the asset that is used to pay the swap invoice.
asset_id BYTEA NOT NULL,
-- swap_rfq_id is the RFQ id that will be used to pay the swap invoice.
swap_rfq_id BYTEA NOT NULL,
-- prepay_rfq_id is the RFQ id that will be used to pay the prepay
-- invoice.
prepay_rfq_id BYTEA NOT NULL,
-- asset_amt_paid_swap is the actual asset amt that has been paid for
-- the swap invoice.
asset_amt_paid_swap BIGINT NOT NULL DEFAULT 0,
-- asset_amt_paid_prepay is the actual asset amt that has been paid for
-- the prepay invoice.
asset_amt_paid_prepay BIGINT NOT NULL DEFAULT 0
)

View file

@ -86,6 +86,15 @@ type LoopoutSwap struct {
PaymentTimeout int32
}
type LoopoutSwapsAssetInfo struct {
SwapHash []byte
AssetID []byte
SwapRfqID []byte
PrepayRfqID []byte
AssetAmtPaidSwap int64
AssetAmtPaidPrepay int64
}
type MigrationTracker struct {
MigrationID string
MigrationTs sql.NullTime

View file

@ -49,6 +49,7 @@ type Querier interface {
InsertInstantOutUpdate(ctx context.Context, arg InsertInstantOutUpdateParams) error
InsertLoopIn(ctx context.Context, arg InsertLoopInParams) error
InsertLoopOut(ctx context.Context, arg InsertLoopOutParams) error
InsertLoopOutAsset(ctx context.Context, arg InsertLoopOutAssetParams) error
InsertMigration(ctx context.Context, arg InsertMigrationParams) error
InsertReservationUpdate(ctx context.Context, arg InsertReservationUpdateParams) error
InsertStaticAddressLoopIn(ctx context.Context, arg InsertStaticAddressLoopInParams) error
@ -60,6 +61,7 @@ type Querier interface {
UpdateBatch(ctx context.Context, arg UpdateBatchParams) error
UpdateDeposit(ctx context.Context, arg UpdateDepositParams) error
UpdateInstantOut(ctx context.Context, arg UpdateInstantOutParams) error
UpdateLoopOutAssetOffchainPayments(ctx context.Context, arg UpdateLoopOutAssetOffchainPaymentsParams) error
UpdateReservation(ctx context.Context, arg UpdateReservationParams) error
UpdateStaticAddressLoopIn(ctx context.Context, arg UpdateStaticAddressLoopInParams) error
UpsertLiquidityParams(ctx context.Context, params []byte) error

View file

@ -2,13 +2,16 @@
SELECT
swaps.*,
loopout_swaps.*,
htlc_keys.*
htlc_keys.*,
loopout_swaps_asset_info.*
FROM
swaps
JOIN
loopout_swaps ON swaps.swap_hash = loopout_swaps.swap_hash
JOIN
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
LEFT JOIN
loopout_swaps_asset_info ON swaps.swap_hash = loopout_swaps_asset_info.swap_hash
ORDER BY
swaps.id;
@ -16,13 +19,16 @@ ORDER BY
SELECT
swaps.*,
loopout_swaps.*,
htlc_keys.*
htlc_keys.*,
loopout_swaps_asset_info.*
FROM
swaps
JOIN
loopout_swaps ON swaps.swap_hash = loopout_swaps.swap_hash
JOIN
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
LEFT JOIN
loopout_swaps_asset_info ON swaps.swap_hash = loopout_swaps_asset_info.swap_hash
WHERE
swaps.swap_hash = $1;
@ -111,6 +117,23 @@ INSERT INTO loopout_swaps (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
);
-- name: InsertLoopOutAsset :exec
INSERT INTO loopout_swaps_asset_info (
swap_hash,
asset_id,
swap_rfq_id,
prepay_rfq_id
) VALUES (
$1, $2, $3, $4
);
-- name: UpdateLoopOutAssetOffchainPayments :exec
UPDATE loopout_swaps_asset_info
SET
asset_amt_paid_swap = $2,
asset_amt_paid_prepay = $3
WHERE swap_hash = $1;
-- name: InsertLoopIn :exec
INSERT INTO loopin_swaps (
swap_hash,

View file

@ -7,6 +7,7 @@ package sqlc
import (
"context"
"database/sql"
"time"
)
@ -185,13 +186,16 @@ const getLoopOutSwap = `-- name: GetLoopOutSwap :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,
loopout_swaps.swap_hash, loopout_swaps.dest_address, loopout_swaps.swap_invoice, loopout_swaps.max_swap_routing_fee, loopout_swaps.sweep_conf_target, loopout_swaps.htlc_confirmations, loopout_swaps.outgoing_chan_set, loopout_swaps.prepay_invoice, loopout_swaps.max_prepay_routing_fee, loopout_swaps.publication_deadline, loopout_swaps.single_sweep, loopout_swaps.payment_timeout,
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
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,
loopout_swaps_asset_info.swap_hash, loopout_swaps_asset_info.asset_id, loopout_swaps_asset_info.swap_rfq_id, loopout_swaps_asset_info.prepay_rfq_id, loopout_swaps_asset_info.asset_amt_paid_swap, loopout_swaps_asset_info.asset_amt_paid_prepay
FROM
swaps
JOIN
loopout_swaps ON swaps.swap_hash = loopout_swaps.swap_hash
JOIN
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
LEFT JOIN
loopout_swaps_asset_info ON swaps.swap_hash = loopout_swaps_asset_info.swap_hash
WHERE
swaps.swap_hash = $1
`
@ -227,6 +231,12 @@ type GetLoopOutSwapRow struct {
ReceiverInternalPubkey []byte
ClientKeyFamily int32
ClientKeyIndex int32
SwapHash_4 []byte
AssetID []byte
SwapRfqID []byte
PrepayRfqID []byte
AssetAmtPaidSwap sql.NullInt64
AssetAmtPaidPrepay sql.NullInt64
}
func (q *Queries) GetLoopOutSwap(ctx context.Context, swapHash []byte) (GetLoopOutSwapRow, error) {
@ -263,6 +273,12 @@ func (q *Queries) GetLoopOutSwap(ctx context.Context, swapHash []byte) (GetLoopO
&i.ReceiverInternalPubkey,
&i.ClientKeyFamily,
&i.ClientKeyIndex,
&i.SwapHash_4,
&i.AssetID,
&i.SwapRfqID,
&i.PrepayRfqID,
&i.AssetAmtPaidSwap,
&i.AssetAmtPaidPrepay,
)
return i, err
}
@ -271,13 +287,16 @@ const getLoopOutSwaps = `-- name: GetLoopOutSwaps :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,
loopout_swaps.swap_hash, loopout_swaps.dest_address, loopout_swaps.swap_invoice, loopout_swaps.max_swap_routing_fee, loopout_swaps.sweep_conf_target, loopout_swaps.htlc_confirmations, loopout_swaps.outgoing_chan_set, loopout_swaps.prepay_invoice, loopout_swaps.max_prepay_routing_fee, loopout_swaps.publication_deadline, loopout_swaps.single_sweep, loopout_swaps.payment_timeout,
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
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,
loopout_swaps_asset_info.swap_hash, loopout_swaps_asset_info.asset_id, loopout_swaps_asset_info.swap_rfq_id, loopout_swaps_asset_info.prepay_rfq_id, loopout_swaps_asset_info.asset_amt_paid_swap, loopout_swaps_asset_info.asset_amt_paid_prepay
FROM
swaps
JOIN
loopout_swaps ON swaps.swap_hash = loopout_swaps.swap_hash
JOIN
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
LEFT JOIN
loopout_swaps_asset_info ON swaps.swap_hash = loopout_swaps_asset_info.swap_hash
ORDER BY
swaps.id
`
@ -313,6 +332,12 @@ type GetLoopOutSwapsRow struct {
ReceiverInternalPubkey []byte
ClientKeyFamily int32
ClientKeyIndex int32
SwapHash_4 []byte
AssetID []byte
SwapRfqID []byte
PrepayRfqID []byte
AssetAmtPaidSwap sql.NullInt64
AssetAmtPaidPrepay sql.NullInt64
}
func (q *Queries) GetLoopOutSwaps(ctx context.Context) ([]GetLoopOutSwapsRow, error) {
@ -355,6 +380,12 @@ func (q *Queries) GetLoopOutSwaps(ctx context.Context) ([]GetLoopOutSwapsRow, er
&i.ReceiverInternalPubkey,
&i.ClientKeyFamily,
&i.ClientKeyIndex,
&i.SwapHash_4,
&i.AssetID,
&i.SwapRfqID,
&i.PrepayRfqID,
&i.AssetAmtPaidSwap,
&i.AssetAmtPaidPrepay,
); err != nil {
return nil, err
}
@ -529,6 +560,34 @@ func (q *Queries) InsertLoopOut(ctx context.Context, arg InsertLoopOutParams) er
return err
}
const insertLoopOutAsset = `-- name: InsertLoopOutAsset :exec
INSERT INTO loopout_swaps_asset_info (
swap_hash,
asset_id,
swap_rfq_id,
prepay_rfq_id
) VALUES (
$1, $2, $3, $4
)
`
type InsertLoopOutAssetParams struct {
SwapHash []byte
AssetID []byte
SwapRfqID []byte
PrepayRfqID []byte
}
func (q *Queries) InsertLoopOutAsset(ctx context.Context, arg InsertLoopOutAssetParams) error {
_, err := q.db.ExecContext(ctx, insertLoopOutAsset,
arg.SwapHash,
arg.AssetID,
arg.SwapRfqID,
arg.PrepayRfqID,
)
return err
}
const insertSwap = `-- name: InsertSwap :exec
INSERT INTO swaps (
swap_hash,
@ -637,3 +696,22 @@ func (q *Queries) OverrideSwapCosts(ctx context.Context, arg OverrideSwapCostsPa
)
return err
}
const updateLoopOutAssetOffchainPayments = `-- name: UpdateLoopOutAssetOffchainPayments :exec
UPDATE loopout_swaps_asset_info
SET
asset_amt_paid_swap = $2,
asset_amt_paid_prepay = $3
WHERE swap_hash = $1
`
type UpdateLoopOutAssetOffchainPaymentsParams struct {
SwapHash []byte
AssetAmtPaidSwap int64
AssetAmtPaidPrepay int64
}
func (q *Queries) UpdateLoopOutAssetOffchainPayments(ctx context.Context, arg UpdateLoopOutAssetOffchainPaymentsParams) error {
_, err := q.db.ExecContext(ctx, updateLoopOutAssetOffchainPayments, arg.SwapHash, arg.AssetAmtPaidSwap, arg.AssetAmtPaidPrepay)
return err
}