sqlc: withdrawal address for deposits

Deposit schema extension with a withdrawal
sweep address. If the user selects a deposit
for withdrawal the destination address of the
sweep is stored here.
This commit is contained in:
Slyghtning 2024-05-06 14:07:36 +02:00
parent 70b21893e0
commit 55f7625bc5
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
4 changed files with 48 additions and 29 deletions

View file

@ -24,7 +24,12 @@ CREATE TABLE IF NOT EXISTS deposits (
timeout_sweep_pk_script BYTEA NOT NULL,
-- expiry_sweep_txid is the transaction id of the expiry sweep.
expiry_sweep_txid BLOB
expiry_sweep_txid BLOB,
-- finalized_withdrawal_tx is the coop signed tx that will be used to sweep
-- the deposit back to the clients wallet. It will be republished on block
-- arrival and after daemon restarts.
finalized_withdrawal_tx TEXT
);
-- deposit_updates contains all the updates to a deposit.

View file

@ -10,14 +10,15 @@ import (
)
type Deposit struct {
ID int32
DepositID []byte
TxHash []byte
OutIndex int32
Amount int64
ConfirmationHeight int64
TimeoutSweepPkScript []byte
ExpirySweepTxid []byte
ID int32
DepositID []byte
TxHash []byte
OutIndex int32
Amount int64
ConfirmationHeight int64
TimeoutSweepPkScript []byte
ExpirySweepTxid []byte
FinalizedWithdrawalTx sql.NullString
}
type DepositUpdate struct {

View file

@ -6,7 +6,8 @@ INSERT INTO deposits (
amount,
confirmation_height,
timeout_sweep_pk_script,
expiry_sweep_txid
expiry_sweep_txid,
finalized_withdrawal_tx
) VALUES (
$1,
$2,
@ -14,7 +15,8 @@ INSERT INTO deposits (
$4,
$5,
$6,
$7
$7,
$8
);
-- name: UpdateDeposit :exec
@ -23,7 +25,8 @@ SET
tx_hash = $2,
out_index = $3,
confirmation_height = $4,
expiry_sweep_txid = $5
expiry_sweep_txid = $5,
finalized_withdrawal_tx = $6
WHERE
deposits.deposit_id = $1;

View file

@ -7,12 +7,13 @@ package sqlc
import (
"context"
"database/sql"
"time"
)
const allDeposits = `-- name: AllDeposits :many
SELECT
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx
FROM
deposits
ORDER BY
@ -37,6 +38,7 @@ func (q *Queries) AllDeposits(ctx context.Context) ([]Deposit, error) {
&i.ConfirmationHeight,
&i.TimeoutSweepPkScript,
&i.ExpirySweepTxid,
&i.FinalizedWithdrawalTx,
); err != nil {
return nil, err
}
@ -59,7 +61,8 @@ INSERT INTO deposits (
amount,
confirmation_height,
timeout_sweep_pk_script,
expiry_sweep_txid
expiry_sweep_txid,
finalized_withdrawal_tx
) VALUES (
$1,
$2,
@ -67,18 +70,20 @@ INSERT INTO deposits (
$4,
$5,
$6,
$7
$7,
$8
)
`
type CreateDepositParams struct {
DepositID []byte
TxHash []byte
OutIndex int32
Amount int64
ConfirmationHeight int64
TimeoutSweepPkScript []byte
ExpirySweepTxid []byte
DepositID []byte
TxHash []byte
OutIndex int32
Amount int64
ConfirmationHeight int64
TimeoutSweepPkScript []byte
ExpirySweepTxid []byte
FinalizedWithdrawalTx sql.NullString
}
func (q *Queries) CreateDeposit(ctx context.Context, arg CreateDepositParams) error {
@ -90,13 +95,14 @@ func (q *Queries) CreateDeposit(ctx context.Context, arg CreateDepositParams) er
arg.ConfirmationHeight,
arg.TimeoutSweepPkScript,
arg.ExpirySweepTxid,
arg.FinalizedWithdrawalTx,
)
return err
}
const getDeposit = `-- name: GetDeposit :one
SELECT
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid
id, deposit_id, tx_hash, out_index, amount, confirmation_height, timeout_sweep_pk_script, expiry_sweep_txid, finalized_withdrawal_tx
FROM
deposits
WHERE
@ -115,6 +121,7 @@ func (q *Queries) GetDeposit(ctx context.Context, depositID []byte) (Deposit, er
&i.ConfirmationHeight,
&i.TimeoutSweepPkScript,
&i.ExpirySweepTxid,
&i.FinalizedWithdrawalTx,
)
return i, err
}
@ -172,17 +179,19 @@ SET
tx_hash = $2,
out_index = $3,
confirmation_height = $4,
expiry_sweep_txid = $5
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
DepositID []byte
TxHash []byte
OutIndex int32
ConfirmationHeight int64
ExpirySweepTxid []byte
FinalizedWithdrawalTx sql.NullString
}
func (q *Queries) UpdateDeposit(ctx context.Context, arg UpdateDepositParams) error {
@ -192,6 +201,7 @@ func (q *Queries) UpdateDeposit(ctx context.Context, arg UpdateDepositParams) er
arg.OutIndex,
arg.ConfirmationHeight,
arg.ExpirySweepTxid,
arg.FinalizedWithdrawalTx,
)
return err
}