mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Associate every deposit with the static address parameters that created it. This lets restored deposits recover the correct script and signing keys instead of assuming the legacy root address.
378 lines
9.4 KiB
Go
378 lines
9.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: static_address_deposits.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const allDeposits = `-- name: AllDeposits :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
|
|
FROM
|
|
deposits d
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
|
ORDER BY
|
|
d.id ASC
|
|
`
|
|
|
|
type AllDepositsRow 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
|
|
}
|
|
|
|
func (q *Queries) AllDeposits(ctx context.Context) ([]AllDepositsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, allDeposits)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AllDepositsRow
|
|
for rows.Next() {
|
|
var i AllDepositsRow
|
|
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,
|
|
); 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 createDeposit = `-- name: CreateDeposit :exec
|
|
INSERT INTO deposits (
|
|
deposit_id,
|
|
tx_hash,
|
|
out_index,
|
|
amount,
|
|
confirmation_height,
|
|
timeout_sweep_pk_script,
|
|
expiry_sweep_txid,
|
|
finalized_withdrawal_tx,
|
|
static_address_id
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9
|
|
)
|
|
`
|
|
|
|
type CreateDepositParams struct {
|
|
DepositID []byte
|
|
TxHash []byte
|
|
OutIndex int32
|
|
Amount int64
|
|
ConfirmationHeight int64
|
|
TimeoutSweepPkScript []byte
|
|
ExpirySweepTxid []byte
|
|
FinalizedWithdrawalTx sql.NullString
|
|
StaticAddressID sql.NullInt32
|
|
}
|
|
|
|
func (q *Queries) CreateDeposit(ctx context.Context, arg CreateDepositParams) error {
|
|
_, err := q.db.ExecContext(ctx, createDeposit,
|
|
arg.DepositID,
|
|
arg.TxHash,
|
|
arg.OutIndex,
|
|
arg.Amount,
|
|
arg.ConfirmationHeight,
|
|
arg.TimeoutSweepPkScript,
|
|
arg.ExpirySweepTxid,
|
|
arg.FinalizedWithdrawalTx,
|
|
arg.StaticAddressID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const depositForOutpoint = `-- name: DepositForOutpoint :one
|
|
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
|
|
FROM
|
|
deposits d
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
|
WHERE
|
|
tx_hash = $1
|
|
AND
|
|
out_index = $2
|
|
`
|
|
|
|
type DepositForOutpointParams struct {
|
|
TxHash []byte
|
|
OutIndex int32
|
|
}
|
|
|
|
type DepositForOutpointRow 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
|
|
}
|
|
|
|
func (q *Queries) DepositForOutpoint(ctx context.Context, arg DepositForOutpointParams) (DepositForOutpointRow, error) {
|
|
row := q.db.QueryRowContext(ctx, depositForOutpoint, arg.TxHash, arg.OutIndex)
|
|
var i DepositForOutpointRow
|
|
err := row.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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getDeposit = `-- name: GetDeposit :one
|
|
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
|
|
FROM
|
|
deposits d
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
|
WHERE
|
|
deposit_id = $1
|
|
`
|
|
|
|
type GetDepositRow 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
|
|
}
|
|
|
|
func (q *Queries) GetDeposit(ctx context.Context, depositID []byte) (GetDepositRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getDeposit, depositID)
|
|
var i GetDepositRow
|
|
err := row.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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getLatestDepositUpdate = `-- name: GetLatestDepositUpdate :one
|
|
SELECT
|
|
id, deposit_id, update_state, update_timestamp
|
|
FROM
|
|
deposit_updates
|
|
WHERE
|
|
deposit_id = $1
|
|
ORDER BY
|
|
update_timestamp DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetLatestDepositUpdate(ctx context.Context, depositID []byte) (DepositUpdate, error) {
|
|
row := q.db.QueryRowContext(ctx, getLatestDepositUpdate, depositID)
|
|
var i DepositUpdate
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.DepositID,
|
|
&i.UpdateState,
|
|
&i.UpdateTimestamp,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertDepositUpdate = `-- name: InsertDepositUpdate :exec
|
|
INSERT INTO deposit_updates (
|
|
deposit_id,
|
|
update_state,
|
|
update_timestamp
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3
|
|
)
|
|
`
|
|
|
|
type InsertDepositUpdateParams struct {
|
|
DepositID []byte
|
|
UpdateState string
|
|
UpdateTimestamp time.Time
|
|
}
|
|
|
|
func (q *Queries) InsertDepositUpdate(ctx context.Context, arg InsertDepositUpdateParams) error {
|
|
_, err := q.db.ExecContext(ctx, insertDepositUpdate, arg.DepositID, arg.UpdateState, arg.UpdateTimestamp)
|
|
return err
|
|
}
|
|
|
|
const setAllNullDepositsStaticAddressID = `-- name: SetAllNullDepositsStaticAddressID :exec
|
|
UPDATE deposits
|
|
SET static_address_id = $1
|
|
WHERE static_address_id IS NULL
|
|
`
|
|
|
|
func (q *Queries) SetAllNullDepositsStaticAddressID(ctx context.Context, staticAddressID sql.NullInt32) error {
|
|
_, err := q.db.ExecContext(ctx, setAllNullDepositsStaticAddressID, staticAddressID)
|
|
return err
|
|
}
|
|
|
|
const updateDeposit = `-- name: UpdateDeposit :exec
|
|
UPDATE deposits
|
|
SET
|
|
tx_hash = $2,
|
|
out_index = $3,
|
|
confirmation_height = $4,
|
|
expiry_sweep_txid = $5,
|
|
finalized_withdrawal_tx = $6
|
|
WHERE
|
|
deposits.deposit_id = $1
|
|
`
|
|
|
|
type UpdateDepositParams struct {
|
|
DepositID []byte
|
|
TxHash []byte
|
|
OutIndex int32
|
|
ConfirmationHeight int64
|
|
ExpirySweepTxid []byte
|
|
FinalizedWithdrawalTx sql.NullString
|
|
}
|
|
|
|
func (q *Queries) UpdateDeposit(ctx context.Context, arg UpdateDepositParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateDeposit,
|
|
arg.DepositID,
|
|
arg.TxHash,
|
|
arg.OutIndex,
|
|
arg.ConfirmationHeight,
|
|
arg.ExpirySweepTxid,
|
|
arg.FinalizedWithdrawalTx,
|
|
)
|
|
return err
|
|
}
|