mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
Add CreatePayment and CompletePayment (#229)
Co-authored-by: Marco Argentieri <tiero@users.noreply.github.com> * Add claim command * Persist pending data in sqlite repo * Remove debug log * Return pending data at interface level * Fix unlocking btc wallet after restart * Lint & Fix whitelist permissions * Fix send command for covenant * Update client/covenantless/claim.go Signed-off-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> * Fix * Pay for min relay fee instead of estimating fees for redeem and unconf forfeit txs * Add support for pending payments (coventanless) * Fixes * Fixes * Improve verbosity * Fix coin selection * Fix --------- Signed-off-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> Co-authored-by: louisinger <louis@vulpem.com> Co-authored-by: Marco Argentieri <tiero@users.noreply.github.com> Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
57ce08f239
commit
72a7f29bab
@@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
// sqlc v1.27.0
|
||||
// source: query.sql
|
||||
|
||||
package queries
|
||||
@@ -54,30 +54,45 @@ func (q *Queries) MarkVtxoAsSwept(ctx context.Context, arg MarkVtxoAsSweptParams
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxos = `-- name: SelectNotRedeemedVtxos :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE redeemed = false
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx,
|
||||
uncond_forfeit_tx_vw.id, uncond_forfeit_tx_vw.tx, uncond_forfeit_tx_vw.vtxo_txid, uncond_forfeit_tx_vw.vtxo_vout, uncond_forfeit_tx_vw.position
|
||||
FROM vtxo
|
||||
LEFT OUTER JOIN uncond_forfeit_tx_vw ON vtxo.txid=uncond_forfeit_tx_vw.vtxo_txid AND vtxo.vout=uncond_forfeit_tx_vw.vtxo_vout
|
||||
WHERE redeemed = false
|
||||
`
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]Vtxo, error) {
|
||||
type SelectNotRedeemedVtxosRow struct {
|
||||
Vtxo Vtxo
|
||||
UncondForfeitTxVw UncondForfeitTxVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]SelectNotRedeemedVtxosRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectNotRedeemedVtxos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
var items []SelectNotRedeemedVtxosRow
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
var i SelectNotRedeemedVtxosRow
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
&i.Vtxo.Spent,
|
||||
&i.Vtxo.Redeemed,
|
||||
&i.Vtxo.Swept,
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.UncondForfeitTxVw.ID,
|
||||
&i.UncondForfeitTxVw.Tx,
|
||||
&i.UncondForfeitTxVw.VtxoTxid,
|
||||
&i.UncondForfeitTxVw.VtxoVout,
|
||||
&i.UncondForfeitTxVw.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -93,30 +108,45 @@ func (q *Queries) SelectNotRedeemedVtxos(ctx context.Context) ([]Vtxo, error) {
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxosWithPubkey = `-- name: SelectNotRedeemedVtxosWithPubkey :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE redeemed = false AND pubkey = ?
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx,
|
||||
uncond_forfeit_tx_vw.id, uncond_forfeit_tx_vw.tx, uncond_forfeit_tx_vw.vtxo_txid, uncond_forfeit_tx_vw.vtxo_vout, uncond_forfeit_tx_vw.position
|
||||
FROM vtxo
|
||||
LEFT OUTER JOIN uncond_forfeit_tx_vw ON vtxo.txid=uncond_forfeit_tx_vw.vtxo_txid AND vtxo.vout=uncond_forfeit_tx_vw.vtxo_vout
|
||||
WHERE redeemed = false AND pubkey = ?
|
||||
`
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, pubkey string) ([]Vtxo, error) {
|
||||
type SelectNotRedeemedVtxosWithPubkeyRow struct {
|
||||
Vtxo Vtxo
|
||||
UncondForfeitTxVw UncondForfeitTxVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectNotRedeemedVtxosWithPubkey(ctx context.Context, pubkey string) ([]SelectNotRedeemedVtxosWithPubkeyRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectNotRedeemedVtxosWithPubkey, pubkey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
var items []SelectNotRedeemedVtxosWithPubkeyRow
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
var i SelectNotRedeemedVtxosWithPubkeyRow
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
&i.Vtxo.Spent,
|
||||
&i.Vtxo.Redeemed,
|
||||
&i.Vtxo.Swept,
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.UncondForfeitTxVw.ID,
|
||||
&i.UncondForfeitTxVw.Tx,
|
||||
&i.UncondForfeitTxVw.VtxoTxid,
|
||||
&i.UncondForfeitTxVw.VtxoVout,
|
||||
&i.UncondForfeitTxVw.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -195,7 +225,7 @@ SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id, payment_vtxo_vw.redeem_tx
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
@@ -260,6 +290,7 @@ func (q *Queries) SelectRoundWithRoundId(ctx context.Context, id string) ([]Sele
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -279,7 +310,7 @@ SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id, payment_vtxo_vw.redeem_tx
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
@@ -344,6 +375,7 @@ func (q *Queries) SelectRoundWithRoundTxId(ctx context.Context, txid string) ([]
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -363,7 +395,7 @@ SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id, payment_vtxo_vw.redeem_tx
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
@@ -428,6 +460,7 @@ func (q *Queries) SelectSweepableRounds(ctx context.Context) ([]SelectSweepableR
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -443,30 +476,45 @@ func (q *Queries) SelectSweepableRounds(ctx context.Context) ([]SelectSweepableR
|
||||
}
|
||||
|
||||
const selectSweepableVtxos = `-- name: SelectSweepableVtxos :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE redeemed = false AND swept = false
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx,
|
||||
uncond_forfeit_tx_vw.id, uncond_forfeit_tx_vw.tx, uncond_forfeit_tx_vw.vtxo_txid, uncond_forfeit_tx_vw.vtxo_vout, uncond_forfeit_tx_vw.position
|
||||
FROM vtxo
|
||||
LEFT OUTER JOIN uncond_forfeit_tx_vw ON vtxo.txid=uncond_forfeit_tx_vw.vtxo_txid AND vtxo.vout=uncond_forfeit_tx_vw.vtxo_vout
|
||||
WHERE redeemed = false AND swept = false
|
||||
`
|
||||
|
||||
func (q *Queries) SelectSweepableVtxos(ctx context.Context) ([]Vtxo, error) {
|
||||
type SelectSweepableVtxosRow struct {
|
||||
Vtxo Vtxo
|
||||
UncondForfeitTxVw UncondForfeitTxVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectSweepableVtxos(ctx context.Context) ([]SelectSweepableVtxosRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectSweepableVtxos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
var items []SelectSweepableVtxosRow
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
var i SelectSweepableVtxosRow
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
&i.Vtxo.Spent,
|
||||
&i.Vtxo.Redeemed,
|
||||
&i.Vtxo.Swept,
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.UncondForfeitTxVw.ID,
|
||||
&i.UncondForfeitTxVw.Tx,
|
||||
&i.UncondForfeitTxVw.VtxoTxid,
|
||||
&i.UncondForfeitTxVw.VtxoVout,
|
||||
&i.UncondForfeitTxVw.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -486,7 +534,7 @@ SELECT round.id, round.starting_timestamp, round.ending_timestamp, round.ended,
|
||||
round_payment_vw.id, round_payment_vw.round_id,
|
||||
round_tx_vw.id, round_tx_vw.tx, round_tx_vw.round_id, round_tx_vw.type, round_tx_vw.position, round_tx_vw.txid, round_tx_vw.tree_level, round_tx_vw.parent_txid, round_tx_vw.is_leaf,
|
||||
payment_receiver_vw.payment_id, payment_receiver_vw.pubkey, payment_receiver_vw.amount, payment_receiver_vw.onchain_address,
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id
|
||||
payment_vtxo_vw.txid, payment_vtxo_vw.vout, payment_vtxo_vw.pubkey, payment_vtxo_vw.amount, payment_vtxo_vw.pool_tx, payment_vtxo_vw.spent_by, payment_vtxo_vw.spent, payment_vtxo_vw.redeemed, payment_vtxo_vw.swept, payment_vtxo_vw.expire_at, payment_vtxo_vw.payment_id, payment_vtxo_vw.redeem_tx
|
||||
FROM round
|
||||
LEFT OUTER JOIN round_payment_vw ON round.id=round_payment_vw.round_id
|
||||
LEFT OUTER JOIN round_tx_vw ON round.id=round_tx_vw.round_id
|
||||
@@ -551,6 +599,7 @@ func (q *Queries) SelectSweptRounds(ctx context.Context) ([]SelectSweptRoundsRow
|
||||
&i.PaymentVtxoVw.Swept,
|
||||
&i.PaymentVtxoVw.ExpireAt,
|
||||
&i.PaymentVtxoVw.PaymentID,
|
||||
&i.PaymentVtxoVw.RedeemTx,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -566,7 +615,11 @@ func (q *Queries) SelectSweptRounds(ctx context.Context) ([]SelectSweptRoundsRow
|
||||
}
|
||||
|
||||
const selectVtxoByOutpoint = `-- name: SelectVtxoByOutpoint :one
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE txid = ? AND vout = ?
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx,
|
||||
uncond_forfeit_tx_vw.id, uncond_forfeit_tx_vw.tx, uncond_forfeit_tx_vw.vtxo_txid, uncond_forfeit_tx_vw.vtxo_vout, uncond_forfeit_tx_vw.position
|
||||
FROM vtxo
|
||||
LEFT OUTER JOIN uncond_forfeit_tx_vw ON vtxo.txid=uncond_forfeit_tx_vw.vtxo_txid AND vtxo.vout=uncond_forfeit_tx_vw.vtxo_vout
|
||||
WHERE txid = ? AND vout = ?
|
||||
`
|
||||
|
||||
type SelectVtxoByOutpointParams struct {
|
||||
@@ -574,50 +627,76 @@ type SelectVtxoByOutpointParams struct {
|
||||
Vout int64
|
||||
}
|
||||
|
||||
func (q *Queries) SelectVtxoByOutpoint(ctx context.Context, arg SelectVtxoByOutpointParams) (Vtxo, error) {
|
||||
type SelectVtxoByOutpointRow struct {
|
||||
Vtxo Vtxo
|
||||
UncondForfeitTxVw UncondForfeitTxVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectVtxoByOutpoint(ctx context.Context, arg SelectVtxoByOutpointParams) (SelectVtxoByOutpointRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, selectVtxoByOutpoint, arg.Txid, arg.Vout)
|
||||
var i Vtxo
|
||||
var i SelectVtxoByOutpointRow
|
||||
err := row.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
&i.Vtxo.Spent,
|
||||
&i.Vtxo.Redeemed,
|
||||
&i.Vtxo.Swept,
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.UncondForfeitTxVw.ID,
|
||||
&i.UncondForfeitTxVw.Tx,
|
||||
&i.UncondForfeitTxVw.VtxoTxid,
|
||||
&i.UncondForfeitTxVw.VtxoVout,
|
||||
&i.UncondForfeitTxVw.Position,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const selectVtxosByPoolTxid = `-- name: SelectVtxosByPoolTxid :many
|
||||
SELECT txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, payment_id FROM vtxo WHERE pool_tx = ?
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.payment_id, vtxo.redeem_tx,
|
||||
uncond_forfeit_tx_vw.id, uncond_forfeit_tx_vw.tx, uncond_forfeit_tx_vw.vtxo_txid, uncond_forfeit_tx_vw.vtxo_vout, uncond_forfeit_tx_vw.position
|
||||
FROM vtxo
|
||||
LEFT OUTER JOIN uncond_forfeit_tx_vw ON vtxo.txid=uncond_forfeit_tx_vw.vtxo_txid AND vtxo.vout=uncond_forfeit_tx_vw.vtxo_vout
|
||||
WHERE pool_tx = ?
|
||||
`
|
||||
|
||||
func (q *Queries) SelectVtxosByPoolTxid(ctx context.Context, poolTx string) ([]Vtxo, error) {
|
||||
type SelectVtxosByPoolTxidRow struct {
|
||||
Vtxo Vtxo
|
||||
UncondForfeitTxVw UncondForfeitTxVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectVtxosByPoolTxid(ctx context.Context, poolTx string) ([]SelectVtxosByPoolTxidRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectVtxosByPoolTxid, poolTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Vtxo
|
||||
var items []SelectVtxosByPoolTxidRow
|
||||
for rows.Next() {
|
||||
var i Vtxo
|
||||
var i SelectVtxosByPoolTxidRow
|
||||
if err := rows.Scan(
|
||||
&i.Txid,
|
||||
&i.Vout,
|
||||
&i.Pubkey,
|
||||
&i.Amount,
|
||||
&i.PoolTx,
|
||||
&i.SpentBy,
|
||||
&i.Spent,
|
||||
&i.Redeemed,
|
||||
&i.Swept,
|
||||
&i.ExpireAt,
|
||||
&i.PaymentID,
|
||||
&i.Vtxo.Txid,
|
||||
&i.Vtxo.Vout,
|
||||
&i.Vtxo.Pubkey,
|
||||
&i.Vtxo.Amount,
|
||||
&i.Vtxo.PoolTx,
|
||||
&i.Vtxo.SpentBy,
|
||||
&i.Vtxo.Spent,
|
||||
&i.Vtxo.Redeemed,
|
||||
&i.Vtxo.Swept,
|
||||
&i.Vtxo.ExpireAt,
|
||||
&i.Vtxo.PaymentID,
|
||||
&i.Vtxo.RedeemTx,
|
||||
&i.UncondForfeitTxVw.ID,
|
||||
&i.UncondForfeitTxVw.Tx,
|
||||
&i.UncondForfeitTxVw.VtxoTxid,
|
||||
&i.UncondForfeitTxVw.VtxoVout,
|
||||
&i.UncondForfeitTxVw.Position,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -803,18 +882,44 @@ func (q *Queries) UpsertTransaction(ctx context.Context, arg UpsertTransactionPa
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertUnconditionalForfeitTx = `-- name: UpsertUnconditionalForfeitTx :exec
|
||||
INSERT INTO uncond_forfeit_tx (tx, vtxo_txid, vtxo_vout, position)
|
||||
VALUES (?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET
|
||||
tx = EXCLUDED.tx,
|
||||
vtxo_txid = EXCLUDED.vtxo_txid,
|
||||
vtxo_vout = EXCLUDED.vtxo_vout,
|
||||
position = EXCLUDED.position
|
||||
`
|
||||
|
||||
type UpsertUnconditionalForfeitTxParams struct {
|
||||
Tx string
|
||||
VtxoTxid string
|
||||
VtxoVout int64
|
||||
Position int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertUnconditionalForfeitTx(ctx context.Context, arg UpsertUnconditionalForfeitTxParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertUnconditionalForfeitTx,
|
||||
arg.Tx,
|
||||
arg.VtxoTxid,
|
||||
arg.VtxoVout,
|
||||
arg.Position,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertVtxo = `-- name: UpsertVtxo :exec
|
||||
INSERT INTO vtxo (txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(txid) DO UPDATE SET
|
||||
vout = excluded.vout,
|
||||
pubkey = excluded.pubkey,
|
||||
amount = excluded.amount,
|
||||
pool_tx = excluded.pool_tx,
|
||||
spent_by = excluded.spent_by,
|
||||
spent = excluded.spent,
|
||||
redeemed = excluded.redeemed,
|
||||
swept = excluded.swept,
|
||||
expire_at = excluded.expire_at
|
||||
INSERT INTO vtxo (txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, redeem_tx)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(txid, vout) DO UPDATE SET
|
||||
pubkey = EXCLUDED.pubkey,
|
||||
amount = EXCLUDED.amount,
|
||||
pool_tx = EXCLUDED.pool_tx,
|
||||
spent_by = EXCLUDED.spent_by,
|
||||
spent = EXCLUDED.spent,
|
||||
redeemed = EXCLUDED.redeemed,
|
||||
swept = EXCLUDED.swept,
|
||||
expire_at = EXCLUDED.expire_at,
|
||||
redeem_tx = EXCLUDED.redeem_tx
|
||||
`
|
||||
|
||||
type UpsertVtxoParams struct {
|
||||
@@ -828,6 +933,7 @@ type UpsertVtxoParams struct {
|
||||
Redeemed bool
|
||||
Swept bool
|
||||
ExpireAt int64
|
||||
RedeemTx sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertVtxo(ctx context.Context, arg UpsertVtxoParams) error {
|
||||
@@ -842,6 +948,7 @@ func (q *Queries) UpsertVtxo(ctx context.Context, arg UpsertVtxoParams) error {
|
||||
arg.Redeemed,
|
||||
arg.Swept,
|
||||
arg.ExpireAt,
|
||||
arg.RedeemTx,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user