mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Create a fresh static change address for fractional loop-ins and persist its key locator with the selected HTLC outpoint. Recovery reconstructs the same change output instead of returning funds to the legacy root address.
669 lines
20 KiB
Go
669 lines
20 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: static_address_loopin.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"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 depositsForSwapHash = `-- name: DepositsForSwapHash :many
|
|
SELECT
|
|
d.id, d.deposit_id, d.tx_hash, d.out_index, d.amount, d.confirmation_height, d.timeout_sweep_pk_script, d.expiry_sweep_txid, d.finalized_withdrawal_tx, d.swap_hash, d.static_address_id,
|
|
sa.client_pubkey client_pubkey,
|
|
sa.server_pubkey server_pubkey,
|
|
sa.expiry expiry,
|
|
sa.client_key_family client_key_family,
|
|
sa.client_key_index client_key_index,
|
|
sa.pkscript pkscript,
|
|
sa.protocol_version protocol_version,
|
|
sa.initiation_height initiation_height,
|
|
u.update_state,
|
|
u.update_timestamp
|
|
FROM
|
|
deposits d
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
|
LEFT JOIN
|
|
deposit_updates u ON u.id = (
|
|
SELECT id
|
|
FROM deposit_updates
|
|
WHERE deposit_id = d.deposit_id
|
|
ORDER BY update_timestamp DESC
|
|
LIMIT 1
|
|
)
|
|
WHERE
|
|
d.swap_hash = $1
|
|
`
|
|
|
|
type DepositsForSwapHashRow struct {
|
|
ID int32
|
|
DepositID []byte
|
|
TxHash []byte
|
|
OutIndex int32
|
|
Amount int64
|
|
ConfirmationHeight int64
|
|
TimeoutSweepPkScript []byte
|
|
ExpirySweepTxid []byte
|
|
FinalizedWithdrawalTx sql.NullString
|
|
SwapHash []byte
|
|
StaticAddressID sql.NullInt32
|
|
ClientPubkey []byte
|
|
ServerPubkey []byte
|
|
Expiry sql.NullInt32
|
|
ClientKeyFamily sql.NullInt32
|
|
ClientKeyIndex sql.NullInt32
|
|
Pkscript []byte
|
|
ProtocolVersion sql.NullInt32
|
|
InitiationHeight sql.NullInt32
|
|
UpdateState sql.NullString
|
|
UpdateTimestamp sql.NullTime
|
|
}
|
|
|
|
func (q *Queries) DepositsForSwapHash(ctx context.Context, swapHash []byte) ([]DepositsForSwapHashRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, depositsForSwapHash, swapHash)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []DepositsForSwapHashRow
|
|
for rows.Next() {
|
|
var i DepositsForSwapHashRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.DepositID,
|
|
&i.TxHash,
|
|
&i.OutIndex,
|
|
&i.Amount,
|
|
&i.ConfirmationHeight,
|
|
&i.TimeoutSweepPkScript,
|
|
&i.ExpirySweepTxid,
|
|
&i.FinalizedWithdrawalTx,
|
|
&i.SwapHash,
|
|
&i.StaticAddressID,
|
|
&i.ClientPubkey,
|
|
&i.ServerPubkey,
|
|
&i.Expiry,
|
|
&i.ClientKeyFamily,
|
|
&i.ClientKeyIndex,
|
|
&i.Pkscript,
|
|
&i.ProtocolVersion,
|
|
&i.InitiationHeight,
|
|
&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 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
|
|
FROM
|
|
static_address_swap_updates
|
|
WHERE
|
|
swap_hash = $1
|
|
`
|
|
|
|
func (q *Queries) GetLoopInSwapUpdates(ctx context.Context, swapHash []byte) ([]StaticAddressSwapUpdate, error) {
|
|
rows, err := q.db.QueryContext(ctx, getLoopInSwapUpdates, swapHash)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []StaticAddressSwapUpdate
|
|
for rows.Next() {
|
|
var i StaticAddressSwapUpdate
|
|
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 getStaticAddressLoopInSwap = `-- name: GetStaticAddressLoopInSwap :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,
|
|
static_address_swaps.id, static_address_swaps.swap_hash, static_address_swaps.swap_invoice, static_address_swaps.last_hop, static_address_swaps.payment_timeout_seconds, static_address_swaps.quoted_swap_fee_satoshis, static_address_swaps.deposit_outpoints, static_address_swaps.htlc_tx_fee_rate_sat_kw, static_address_swaps.htlc_timeout_sweep_tx_id, static_address_swaps.htlc_timeout_sweep_address, static_address_swaps.selected_amount, static_address_swaps.fast, static_address_swaps.confirmation_risk_decision, static_address_swaps.confirmation_risk_decision_time, static_address_swaps.change_static_address_id, static_address_swaps.confirmed_htlc_tx_id, static_address_swaps.confirmed_htlc_output_index, static_address_swaps.confirmed_htlc_output_value,
|
|
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,
|
|
change_address.client_pubkey change_client_pubkey,
|
|
change_address.server_pubkey change_server_pubkey,
|
|
change_address.expiry change_expiry,
|
|
change_address.client_key_family change_client_key_family,
|
|
change_address.client_key_index change_client_key_index,
|
|
change_address.pkscript change_pkscript,
|
|
change_address.protocol_version change_protocol_version,
|
|
change_address.initiation_height change_initiation_height
|
|
FROM
|
|
swaps
|
|
JOIN
|
|
static_address_swaps ON swaps.swap_hash = static_address_swaps.swap_hash
|
|
JOIN
|
|
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
|
|
LEFT JOIN
|
|
static_addresses change_address
|
|
ON static_address_swaps.change_static_address_id = change_address.id
|
|
WHERE
|
|
swaps.swap_hash = $1
|
|
`
|
|
|
|
type GetStaticAddressLoopInSwapRow struct {
|
|
ID int32
|
|
SwapHash []byte
|
|
Preimage []byte
|
|
InitiationTime time.Time
|
|
AmountRequested int64
|
|
CltvExpiry int32
|
|
MaxMinerFee int64
|
|
MaxSwapFee int64
|
|
InitiationHeight int32
|
|
ProtocolVersion int32
|
|
Label string
|
|
ID_2 int32
|
|
SwapHash_2 []byte
|
|
SwapInvoice string
|
|
LastHop []byte
|
|
PaymentTimeoutSeconds int32
|
|
QuotedSwapFeeSatoshis int64
|
|
DepositOutpoints string
|
|
HtlcTxFeeRateSatKw int64
|
|
HtlcTimeoutSweepTxID sql.NullString
|
|
HtlcTimeoutSweepAddress string
|
|
SelectedAmount int64
|
|
Fast bool
|
|
ConfirmationRiskDecision string
|
|
ConfirmationRiskDecisionTime sql.NullTime
|
|
ChangeStaticAddressID sql.NullInt32
|
|
ConfirmedHtlcTxID sql.NullString
|
|
ConfirmedHtlcOutputIndex sql.NullInt32
|
|
ConfirmedHtlcOutputValue sql.NullInt64
|
|
SwapHash_3 []byte
|
|
SenderScriptPubkey []byte
|
|
ReceiverScriptPubkey []byte
|
|
SenderInternalPubkey []byte
|
|
ReceiverInternalPubkey []byte
|
|
ClientKeyFamily int32
|
|
ClientKeyIndex int32
|
|
ChangeClientPubkey []byte
|
|
ChangeServerPubkey []byte
|
|
ChangeExpiry sql.NullInt32
|
|
ChangeClientKeyFamily sql.NullInt32
|
|
ChangeClientKeyIndex sql.NullInt32
|
|
ChangePkscript []byte
|
|
ChangeProtocolVersion sql.NullInt32
|
|
ChangeInitiationHeight sql.NullInt32
|
|
}
|
|
|
|
func (q *Queries) GetStaticAddressLoopInSwap(ctx context.Context, swapHash []byte) (GetStaticAddressLoopInSwapRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getStaticAddressLoopInSwap, swapHash)
|
|
var i GetStaticAddressLoopInSwapRow
|
|
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.ID_2,
|
|
&i.SwapHash_2,
|
|
&i.SwapInvoice,
|
|
&i.LastHop,
|
|
&i.PaymentTimeoutSeconds,
|
|
&i.QuotedSwapFeeSatoshis,
|
|
&i.DepositOutpoints,
|
|
&i.HtlcTxFeeRateSatKw,
|
|
&i.HtlcTimeoutSweepTxID,
|
|
&i.HtlcTimeoutSweepAddress,
|
|
&i.SelectedAmount,
|
|
&i.Fast,
|
|
&i.ConfirmationRiskDecision,
|
|
&i.ConfirmationRiskDecisionTime,
|
|
&i.ChangeStaticAddressID,
|
|
&i.ConfirmedHtlcTxID,
|
|
&i.ConfirmedHtlcOutputIndex,
|
|
&i.ConfirmedHtlcOutputValue,
|
|
&i.SwapHash_3,
|
|
&i.SenderScriptPubkey,
|
|
&i.ReceiverScriptPubkey,
|
|
&i.SenderInternalPubkey,
|
|
&i.ReceiverInternalPubkey,
|
|
&i.ClientKeyFamily,
|
|
&i.ClientKeyIndex,
|
|
&i.ChangeClientPubkey,
|
|
&i.ChangeServerPubkey,
|
|
&i.ChangeExpiry,
|
|
&i.ChangeClientKeyFamily,
|
|
&i.ChangeClientKeyIndex,
|
|
&i.ChangePkscript,
|
|
&i.ChangeProtocolVersion,
|
|
&i.ChangeInitiationHeight,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getStaticAddressLoopInSwapsByStates = `-- name: GetStaticAddressLoopInSwapsByStates :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,
|
|
static_address_swaps.id, static_address_swaps.swap_hash, static_address_swaps.swap_invoice, static_address_swaps.last_hop, static_address_swaps.payment_timeout_seconds, static_address_swaps.quoted_swap_fee_satoshis, static_address_swaps.deposit_outpoints, static_address_swaps.htlc_tx_fee_rate_sat_kw, static_address_swaps.htlc_timeout_sweep_tx_id, static_address_swaps.htlc_timeout_sweep_address, static_address_swaps.selected_amount, static_address_swaps.fast, static_address_swaps.confirmation_risk_decision, static_address_swaps.confirmation_risk_decision_time, static_address_swaps.change_static_address_id, static_address_swaps.confirmed_htlc_tx_id, static_address_swaps.confirmed_htlc_output_index, static_address_swaps.confirmed_htlc_output_value,
|
|
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,
|
|
change_address.client_pubkey change_client_pubkey,
|
|
change_address.server_pubkey change_server_pubkey,
|
|
change_address.expiry change_expiry,
|
|
change_address.client_key_family change_client_key_family,
|
|
change_address.client_key_index change_client_key_index,
|
|
change_address.pkscript change_pkscript,
|
|
change_address.protocol_version change_protocol_version,
|
|
change_address.initiation_height change_initiation_height
|
|
FROM
|
|
swaps
|
|
JOIN
|
|
static_address_swaps ON swaps.swap_hash = static_address_swaps.swap_hash
|
|
JOIN
|
|
htlc_keys ON swaps.swap_hash = htlc_keys.swap_hash
|
|
LEFT JOIN
|
|
static_addresses change_address
|
|
ON static_address_swaps.change_static_address_id = change_address.id
|
|
JOIN
|
|
static_address_swap_updates u ON swaps.swap_hash = u.swap_hash
|
|
-- This subquery ensures that we are checking only the latest update for
|
|
-- each swap_hash.
|
|
AND u.update_timestamp = (
|
|
SELECT MAX(update_timestamp)
|
|
FROM static_address_swap_updates
|
|
WHERE swap_hash = u.swap_hash
|
|
)
|
|
WHERE
|
|
(',' || $1 || ',') LIKE ('%,' || u.update_state || ',%')
|
|
ORDER BY
|
|
swaps.id
|
|
`
|
|
|
|
type GetStaticAddressLoopInSwapsByStatesRow struct {
|
|
ID int32
|
|
SwapHash []byte
|
|
Preimage []byte
|
|
InitiationTime time.Time
|
|
AmountRequested int64
|
|
CltvExpiry int32
|
|
MaxMinerFee int64
|
|
MaxSwapFee int64
|
|
InitiationHeight int32
|
|
ProtocolVersion int32
|
|
Label string
|
|
ID_2 int32
|
|
SwapHash_2 []byte
|
|
SwapInvoice string
|
|
LastHop []byte
|
|
PaymentTimeoutSeconds int32
|
|
QuotedSwapFeeSatoshis int64
|
|
DepositOutpoints string
|
|
HtlcTxFeeRateSatKw int64
|
|
HtlcTimeoutSweepTxID sql.NullString
|
|
HtlcTimeoutSweepAddress string
|
|
SelectedAmount int64
|
|
Fast bool
|
|
ConfirmationRiskDecision string
|
|
ConfirmationRiskDecisionTime sql.NullTime
|
|
ChangeStaticAddressID sql.NullInt32
|
|
ConfirmedHtlcTxID sql.NullString
|
|
ConfirmedHtlcOutputIndex sql.NullInt32
|
|
ConfirmedHtlcOutputValue sql.NullInt64
|
|
SwapHash_3 []byte
|
|
SenderScriptPubkey []byte
|
|
ReceiverScriptPubkey []byte
|
|
SenderInternalPubkey []byte
|
|
ReceiverInternalPubkey []byte
|
|
ClientKeyFamily int32
|
|
ClientKeyIndex int32
|
|
ChangeClientPubkey []byte
|
|
ChangeServerPubkey []byte
|
|
ChangeExpiry sql.NullInt32
|
|
ChangeClientKeyFamily sql.NullInt32
|
|
ChangeClientKeyIndex sql.NullInt32
|
|
ChangePkscript []byte
|
|
ChangeProtocolVersion sql.NullInt32
|
|
ChangeInitiationHeight sql.NullInt32
|
|
}
|
|
|
|
func (q *Queries) GetStaticAddressLoopInSwapsByStates(ctx context.Context, dollar_1 sql.NullString) ([]GetStaticAddressLoopInSwapsByStatesRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getStaticAddressLoopInSwapsByStates, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetStaticAddressLoopInSwapsByStatesRow
|
|
for rows.Next() {
|
|
var i GetStaticAddressLoopInSwapsByStatesRow
|
|
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.ID_2,
|
|
&i.SwapHash_2,
|
|
&i.SwapInvoice,
|
|
&i.LastHop,
|
|
&i.PaymentTimeoutSeconds,
|
|
&i.QuotedSwapFeeSatoshis,
|
|
&i.DepositOutpoints,
|
|
&i.HtlcTxFeeRateSatKw,
|
|
&i.HtlcTimeoutSweepTxID,
|
|
&i.HtlcTimeoutSweepAddress,
|
|
&i.SelectedAmount,
|
|
&i.Fast,
|
|
&i.ConfirmationRiskDecision,
|
|
&i.ConfirmationRiskDecisionTime,
|
|
&i.ChangeStaticAddressID,
|
|
&i.ConfirmedHtlcTxID,
|
|
&i.ConfirmedHtlcOutputIndex,
|
|
&i.ConfirmedHtlcOutputValue,
|
|
&i.SwapHash_3,
|
|
&i.SenderScriptPubkey,
|
|
&i.ReceiverScriptPubkey,
|
|
&i.SenderInternalPubkey,
|
|
&i.ReceiverInternalPubkey,
|
|
&i.ClientKeyFamily,
|
|
&i.ClientKeyIndex,
|
|
&i.ChangeClientPubkey,
|
|
&i.ChangeServerPubkey,
|
|
&i.ChangeExpiry,
|
|
&i.ChangeClientKeyFamily,
|
|
&i.ChangeClientKeyIndex,
|
|
&i.ChangePkscript,
|
|
&i.ChangeProtocolVersion,
|
|
&i.ChangeInitiationHeight,
|
|
); 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 insertStaticAddressLoopIn = `-- name: InsertStaticAddressLoopIn :exec
|
|
INSERT INTO static_address_swaps (
|
|
swap_hash,
|
|
swap_invoice,
|
|
last_hop,
|
|
payment_timeout_seconds,
|
|
quoted_swap_fee_satoshis,
|
|
deposit_outpoints,
|
|
selected_amount,
|
|
htlc_tx_fee_rate_sat_kw,
|
|
htlc_timeout_sweep_tx_id,
|
|
htlc_timeout_sweep_address,
|
|
fast,
|
|
change_static_address_id
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12
|
|
)
|
|
`
|
|
|
|
type InsertStaticAddressLoopInParams struct {
|
|
SwapHash []byte
|
|
SwapInvoice string
|
|
LastHop []byte
|
|
PaymentTimeoutSeconds int32
|
|
QuotedSwapFeeSatoshis int64
|
|
DepositOutpoints string
|
|
SelectedAmount int64
|
|
HtlcTxFeeRateSatKw int64
|
|
HtlcTimeoutSweepTxID sql.NullString
|
|
HtlcTimeoutSweepAddress string
|
|
Fast bool
|
|
ChangeStaticAddressID sql.NullInt32
|
|
}
|
|
|
|
func (q *Queries) InsertStaticAddressLoopIn(ctx context.Context, arg InsertStaticAddressLoopInParams) error {
|
|
_, err := q.db.ExecContext(ctx, insertStaticAddressLoopIn,
|
|
arg.SwapHash,
|
|
arg.SwapInvoice,
|
|
arg.LastHop,
|
|
arg.PaymentTimeoutSeconds,
|
|
arg.QuotedSwapFeeSatoshis,
|
|
arg.DepositOutpoints,
|
|
arg.SelectedAmount,
|
|
arg.HtlcTxFeeRateSatKw,
|
|
arg.HtlcTimeoutSweepTxID,
|
|
arg.HtlcTimeoutSweepAddress,
|
|
arg.Fast,
|
|
arg.ChangeStaticAddressID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const insertStaticAddressMetaUpdate = `-- name: InsertStaticAddressMetaUpdate :exec
|
|
INSERT INTO static_address_swap_updates (
|
|
swap_hash,
|
|
update_state,
|
|
update_timestamp
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3
|
|
)
|
|
`
|
|
|
|
type InsertStaticAddressMetaUpdateParams struct {
|
|
SwapHash []byte
|
|
UpdateState string
|
|
UpdateTimestamp time.Time
|
|
}
|
|
|
|
func (q *Queries) InsertStaticAddressMetaUpdate(ctx context.Context, arg InsertStaticAddressMetaUpdateParams) error {
|
|
_, err := q.db.ExecContext(ctx, insertStaticAddressMetaUpdate, arg.SwapHash, arg.UpdateState, arg.UpdateTimestamp)
|
|
return err
|
|
}
|
|
|
|
const isStored = `-- name: IsStored :one
|
|
SELECT EXISTS (
|
|
SELECT 1
|
|
FROM static_address_swaps
|
|
WHERE swap_hash = $1
|
|
)
|
|
`
|
|
|
|
func (q *Queries) IsStored(ctx context.Context, swapHash []byte) (bool, error) {
|
|
row := q.db.QueryRowContext(ctx, isStored, swapHash)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
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 overrideSelectedSwapAmount = `-- name: OverrideSelectedSwapAmount :exec
|
|
UPDATE static_address_swaps
|
|
SET
|
|
selected_amount = $2
|
|
WHERE swap_hash = $1
|
|
`
|
|
|
|
type OverrideSelectedSwapAmountParams struct {
|
|
SwapHash []byte
|
|
SelectedAmount int64
|
|
}
|
|
|
|
func (q *Queries) OverrideSelectedSwapAmount(ctx context.Context, arg OverrideSelectedSwapAmountParams) error {
|
|
_, err := q.db.ExecContext(ctx, overrideSelectedSwapAmount, arg.SwapHash, arg.SelectedAmount)
|
|
return err
|
|
}
|
|
|
|
const recordStaticAddressRiskDecision = `-- name: RecordStaticAddressRiskDecision :exec
|
|
UPDATE static_address_swaps
|
|
SET
|
|
confirmation_risk_decision = $2,
|
|
confirmation_risk_decision_time = CASE
|
|
WHEN confirmation_risk_decision = $2 THEN
|
|
COALESCE(confirmation_risk_decision_time, $3)
|
|
ELSE $3
|
|
END
|
|
WHERE
|
|
swap_hash = $1
|
|
AND NOT (
|
|
confirmation_risk_decision = 'rejected'
|
|
AND $2 = 'accepted'
|
|
)
|
|
`
|
|
|
|
type RecordStaticAddressRiskDecisionParams struct {
|
|
SwapHash []byte
|
|
ConfirmationRiskDecision string
|
|
ConfirmationRiskDecisionTime sql.NullTime
|
|
}
|
|
|
|
func (q *Queries) RecordStaticAddressRiskDecision(ctx context.Context, arg RecordStaticAddressRiskDecisionParams) error {
|
|
_, err := q.db.ExecContext(ctx, recordStaticAddressRiskDecision, arg.SwapHash, arg.ConfirmationRiskDecision, arg.ConfirmationRiskDecisionTime)
|
|
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
|
|
htlc_tx_fee_rate_sat_kw = $2,
|
|
htlc_timeout_sweep_tx_id = $3,
|
|
confirmed_htlc_tx_id = $4,
|
|
confirmed_htlc_output_index = $5,
|
|
confirmed_htlc_output_value = $6
|
|
WHERE
|
|
swap_hash = $1
|
|
`
|
|
|
|
type UpdateStaticAddressLoopInParams struct {
|
|
SwapHash []byte
|
|
HtlcTxFeeRateSatKw int64
|
|
HtlcTimeoutSweepTxID sql.NullString
|
|
ConfirmedHtlcTxID sql.NullString
|
|
ConfirmedHtlcOutputIndex sql.NullInt32
|
|
ConfirmedHtlcOutputValue sql.NullInt64
|
|
}
|
|
|
|
func (q *Queries) UpdateStaticAddressLoopIn(ctx context.Context, arg UpdateStaticAddressLoopInParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateStaticAddressLoopIn,
|
|
arg.SwapHash,
|
|
arg.HtlcTxFeeRateSatKw,
|
|
arg.HtlcTimeoutSweepTxID,
|
|
arg.ConfirmedHtlcTxID,
|
|
arg.ConfirmedHtlcOutputIndex,
|
|
arg.ConfirmedHtlcOutputValue,
|
|
)
|
|
return err
|
|
}
|