2024-03-07 17:25:07 +01:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
|
// versions:
|
|
|
|
|
// sqlc v1.25.0
|
|
|
|
|
// source: static_address_deposits.sql
|
|
|
|
|
|
|
|
|
|
package sqlc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-05-06 14:07:36 +02:00
|
|
|
"database/sql"
|
2024-03-07 17:25:07 +01:00
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const allDeposits = `-- name: AllDeposits :many
|
|
|
|
|
SELECT
|
2026-07-10 11:58:03 +02:00
|
|
|
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
|
2024-03-07 17:25:07 +01:00
|
|
|
FROM
|
2026-07-10 11:58:03 +02:00
|
|
|
deposits d
|
|
|
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
2024-03-07 17:25:07 +01:00
|
|
|
ORDER BY
|
2026-07-10 11:58:03 +02:00
|
|
|
d.id ASC
|
2024-03-07 17:25:07 +01:00
|
|
|
`
|
|
|
|
|
|
2026-07-10 11:58:03 +02:00
|
|
|
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) {
|
2024-03-07 17:25:07 +01:00
|
|
|
rows, err := q.db.QueryContext(ctx, allDeposits)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
2026-07-10 11:58:03 +02:00
|
|
|
var items []AllDepositsRow
|
2024-03-07 17:25:07 +01:00
|
|
|
for rows.Next() {
|
2026-07-10 11:58:03 +02:00
|
|
|
var i AllDepositsRow
|
2024-03-07 17:25:07 +01:00
|
|
|
if err := rows.Scan(
|
|
|
|
|
&i.ID,
|
|
|
|
|
&i.DepositID,
|
|
|
|
|
&i.TxHash,
|
|
|
|
|
&i.OutIndex,
|
|
|
|
|
&i.Amount,
|
|
|
|
|
&i.ConfirmationHeight,
|
|
|
|
|
&i.TimeoutSweepPkScript,
|
|
|
|
|
&i.ExpirySweepTxid,
|
2024-05-06 14:07:36 +02:00
|
|
|
&i.FinalizedWithdrawalTx,
|
2025-07-30 12:00:03 +02:00
|
|
|
&i.SwapHash,
|
2026-07-10 11:58:03 +02:00
|
|
|
&i.StaticAddressID,
|
|
|
|
|
&i.ClientPubkey,
|
|
|
|
|
&i.ServerPubkey,
|
|
|
|
|
&i.Expiry,
|
|
|
|
|
&i.ClientKeyFamily,
|
|
|
|
|
&i.ClientKeyIndex,
|
|
|
|
|
&i.Pkscript,
|
|
|
|
|
&i.ProtocolVersion,
|
|
|
|
|
&i.InitiationHeight,
|
2024-03-07 17:25:07 +01:00
|
|
|
); 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,
|
2024-05-06 14:07:36 +02:00
|
|
|
expiry_sweep_txid,
|
2026-07-10 11:58:03 +02:00
|
|
|
finalized_withdrawal_tx,
|
|
|
|
|
static_address_id
|
2024-03-07 17:25:07 +01:00
|
|
|
) VALUES (
|
|
|
|
|
$1,
|
|
|
|
|
$2,
|
|
|
|
|
$3,
|
|
|
|
|
$4,
|
|
|
|
|
$5,
|
|
|
|
|
$6,
|
2024-05-06 14:07:36 +02:00
|
|
|
$7,
|
2026-07-10 11:58:03 +02:00
|
|
|
$8,
|
|
|
|
|
$9
|
2024-03-07 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type CreateDepositParams struct {
|
2024-05-06 14:07:36 +02:00
|
|
|
DepositID []byte
|
|
|
|
|
TxHash []byte
|
|
|
|
|
OutIndex int32
|
|
|
|
|
Amount int64
|
|
|
|
|
ConfirmationHeight int64
|
|
|
|
|
TimeoutSweepPkScript []byte
|
|
|
|
|
ExpirySweepTxid []byte
|
|
|
|
|
FinalizedWithdrawalTx sql.NullString
|
2026-07-10 11:58:03 +02:00
|
|
|
StaticAddressID sql.NullInt32
|
2024-03-07 17:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2024-05-06 14:07:36 +02:00
|
|
|
arg.FinalizedWithdrawalTx,
|
2026-07-10 11:58:03 +02:00
|
|
|
arg.StaticAddressID,
|
2024-03-07 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 14:29:48 +02:00
|
|
|
const depositForOutpoint = `-- name: DepositForOutpoint :one
|
|
|
|
|
SELECT
|
2026-07-10 11:58:03 +02:00
|
|
|
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
|
2025-04-02 14:29:48 +02:00
|
|
|
FROM
|
2026-07-10 11:58:03 +02:00
|
|
|
deposits d
|
|
|
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
2025-04-02 14:29:48 +02:00
|
|
|
WHERE
|
|
|
|
|
tx_hash = $1
|
|
|
|
|
AND
|
|
|
|
|
out_index = $2
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type DepositForOutpointParams struct {
|
|
|
|
|
TxHash []byte
|
|
|
|
|
OutIndex int32
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 11:58:03 +02:00
|
|
|
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) {
|
2025-04-02 14:29:48 +02:00
|
|
|
row := q.db.QueryRowContext(ctx, depositForOutpoint, arg.TxHash, arg.OutIndex)
|
2026-07-10 11:58:03 +02:00
|
|
|
var i DepositForOutpointRow
|
2025-04-02 14:29:48 +02:00
|
|
|
err := row.Scan(
|
|
|
|
|
&i.ID,
|
|
|
|
|
&i.DepositID,
|
|
|
|
|
&i.TxHash,
|
|
|
|
|
&i.OutIndex,
|
|
|
|
|
&i.Amount,
|
|
|
|
|
&i.ConfirmationHeight,
|
|
|
|
|
&i.TimeoutSweepPkScript,
|
|
|
|
|
&i.ExpirySweepTxid,
|
|
|
|
|
&i.FinalizedWithdrawalTx,
|
2025-07-30 12:00:03 +02:00
|
|
|
&i.SwapHash,
|
2026-07-10 11:58:03 +02:00
|
|
|
&i.StaticAddressID,
|
|
|
|
|
&i.ClientPubkey,
|
|
|
|
|
&i.ServerPubkey,
|
|
|
|
|
&i.Expiry,
|
|
|
|
|
&i.ClientKeyFamily,
|
|
|
|
|
&i.ClientKeyIndex,
|
|
|
|
|
&i.Pkscript,
|
|
|
|
|
&i.ProtocolVersion,
|
|
|
|
|
&i.InitiationHeight,
|
2025-04-02 14:29:48 +02:00
|
|
|
)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-07 17:25:07 +01:00
|
|
|
const getDeposit = `-- name: GetDeposit :one
|
|
|
|
|
SELECT
|
2026-07-10 11:58:03 +02:00
|
|
|
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
|
2024-03-07 17:25:07 +01:00
|
|
|
FROM
|
2026-07-10 11:58:03 +02:00
|
|
|
deposits d
|
|
|
|
|
LEFT JOIN static_addresses sa ON sa.id = d.static_address_id
|
2024-03-07 17:25:07 +01:00
|
|
|
WHERE
|
|
|
|
|
deposit_id = $1
|
|
|
|
|
`
|
|
|
|
|
|
2026-07-10 11:58:03 +02:00
|
|
|
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) {
|
2024-03-07 17:25:07 +01:00
|
|
|
row := q.db.QueryRowContext(ctx, getDeposit, depositID)
|
2026-07-10 11:58:03 +02:00
|
|
|
var i GetDepositRow
|
2024-03-07 17:25:07 +01:00
|
|
|
err := row.Scan(
|
|
|
|
|
&i.ID,
|
|
|
|
|
&i.DepositID,
|
|
|
|
|
&i.TxHash,
|
|
|
|
|
&i.OutIndex,
|
|
|
|
|
&i.Amount,
|
|
|
|
|
&i.ConfirmationHeight,
|
|
|
|
|
&i.TimeoutSweepPkScript,
|
|
|
|
|
&i.ExpirySweepTxid,
|
2024-05-06 14:07:36 +02:00
|
|
|
&i.FinalizedWithdrawalTx,
|
2025-07-30 12:00:03 +02:00
|
|
|
&i.SwapHash,
|
2026-07-10 11:58:03 +02:00
|
|
|
&i.StaticAddressID,
|
|
|
|
|
&i.ClientPubkey,
|
|
|
|
|
&i.ServerPubkey,
|
|
|
|
|
&i.Expiry,
|
|
|
|
|
&i.ClientKeyFamily,
|
|
|
|
|
&i.ClientKeyIndex,
|
|
|
|
|
&i.Pkscript,
|
|
|
|
|
&i.ProtocolVersion,
|
|
|
|
|
&i.InitiationHeight,
|
2024-03-07 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-10 11:58:03 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-07 17:25:07 +01:00
|
|
|
const updateDeposit = `-- name: UpdateDeposit :exec
|
|
|
|
|
UPDATE deposits
|
|
|
|
|
SET
|
|
|
|
|
tx_hash = $2,
|
|
|
|
|
out_index = $3,
|
|
|
|
|
confirmation_height = $4,
|
2024-05-06 14:07:36 +02:00
|
|
|
expiry_sweep_txid = $5,
|
|
|
|
|
finalized_withdrawal_tx = $6
|
2024-03-07 17:25:07 +01:00
|
|
|
WHERE
|
|
|
|
|
deposits.deposit_id = $1
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type UpdateDepositParams struct {
|
2024-05-06 14:07:36 +02:00
|
|
|
DepositID []byte
|
|
|
|
|
TxHash []byte
|
|
|
|
|
OutIndex int32
|
|
|
|
|
ConfirmationHeight int64
|
|
|
|
|
ExpirySweepTxid []byte
|
|
|
|
|
FinalizedWithdrawalTx sql.NullString
|
2024-03-07 17:25:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2024-05-06 14:07:36 +02:00
|
|
|
arg.FinalizedWithdrawalTx,
|
2024-03-07 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
return err
|
|
|
|
|
}
|