2024-03-07 17:25:07 +01:00
|
|
|
-- 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
|
|
|
);
|
|
|
|
|
|
|
|
|
|
-- 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;
|
|
|
|
|
|
|
|
|
|
-- name: InsertDepositUpdate :exec
|
|
|
|
|
INSERT INTO deposit_updates (
|
|
|
|
|
deposit_id,
|
|
|
|
|
update_state,
|
|
|
|
|
update_timestamp
|
|
|
|
|
) VALUES (
|
|
|
|
|
$1,
|
|
|
|
|
$2,
|
|
|
|
|
$3
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
-- name: GetDeposit :one
|
|
|
|
|
SELECT
|
2026-07-10 11:58:03 +02:00
|
|
|
d.*,
|
|
|
|
|
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;
|
|
|
|
|
|
2025-04-02 14:29:48 +02:00
|
|
|
-- name: DepositForOutpoint :one
|
|
|
|
|
SELECT
|
2026-07-10 11:58:03 +02:00
|
|
|
d.*,
|
|
|
|
|
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;
|
|
|
|
|
|
2024-03-07 17:25:07 +01:00
|
|
|
-- name: AllDeposits :many
|
|
|
|
|
SELECT
|
2026-07-10 11:58:03 +02:00
|
|
|
d.*,
|
|
|
|
|
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
|
|
|
|
|
|
|
|
-- name: GetLatestDepositUpdate :one
|
|
|
|
|
SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
|
|
|
|
deposit_updates
|
|
|
|
|
WHERE
|
|
|
|
|
deposit_id = $1
|
|
|
|
|
ORDER BY
|
|
|
|
|
update_timestamp DESC
|
2026-07-10 11:58:03 +02:00
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
|
|
-- name: SetAllNullDepositsStaticAddressID :exec
|
|
|
|
|
UPDATE deposits
|
|
|
|
|
SET static_address_id = $1
|
|
|
|
|
WHERE static_address_id IS NULL;
|