mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
* bugfix on detecting pending vtxos * bugfix: don't return on error from previous round * bugfix on wasm browser storage * implements listVtxos on SDK * Bug fix Co-authored-by: Pietralberto Mazza <altafan@users.noreply.github.com> * bug fix * Fixes * revert RedeemTx check * Fix after merge * bug fix on wasm wrapper * Fix static tx history (without tx feed) * add createAt timestamp in Vtxo domain * Fixes * Fixes * Polish * Fix * Fix --------- Co-authored-by: Pietralberto Mazza <altafan@users.noreply.github.com> Co-authored-by: altafan <18440657+altafan@users.noreply.github.com> Co-authored-by: louisinger <louis@vulpem.com>
159 lines
5.6 KiB
SQL
159 lines
5.6 KiB
SQL
-- name: UpsertTransaction :exec
|
|
INSERT INTO tx (
|
|
tx, round_id, type, position, txid, tree_level, parent_txid, is_leaf
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
ON CONFLICT(id) DO UPDATE SET
|
|
tx = EXCLUDED.tx,
|
|
round_id = EXCLUDED.round_id,
|
|
type = EXCLUDED.type,
|
|
position = EXCLUDED.position,
|
|
txid = EXCLUDED.txid,
|
|
tree_level = EXCLUDED.tree_level,
|
|
parent_txid = EXCLUDED.parent_txid,
|
|
is_leaf = EXCLUDED.is_leaf;
|
|
|
|
-- name: UpsertRound :exec
|
|
INSERT INTO round (
|
|
id,
|
|
starting_timestamp,
|
|
ending_timestamp,
|
|
ended, failed,
|
|
stage_code,
|
|
txid,
|
|
unsigned_tx,
|
|
connector_address,
|
|
dust_amount,
|
|
version,
|
|
swept
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
ON CONFLICT(id) DO UPDATE SET
|
|
starting_timestamp = EXCLUDED.starting_timestamp,
|
|
ending_timestamp = EXCLUDED.ending_timestamp,
|
|
ended = EXCLUDED.ended,
|
|
failed = EXCLUDED.failed,
|
|
stage_code = EXCLUDED.stage_code,
|
|
txid = EXCLUDED.txid,
|
|
unsigned_tx = EXCLUDED.unsigned_tx,
|
|
connector_address = EXCLUDED.connector_address,
|
|
dust_amount = EXCLUDED.dust_amount,
|
|
version = EXCLUDED.version,
|
|
swept = EXCLUDED.swept;
|
|
|
|
-- name: UpsertPayment :exec
|
|
INSERT INTO payment (id, round_id) VALUES (?, ?)
|
|
ON CONFLICT(id) DO UPDATE SET round_id = EXCLUDED.round_id;
|
|
|
|
-- name: UpsertReceiver :exec
|
|
INSERT INTO receiver (payment_id, pubkey, onchain_address, amount) VALUES (?, ?, ?, ?)
|
|
ON CONFLICT(payment_id, pubkey, onchain_address) DO UPDATE SET
|
|
amount = EXCLUDED.amount,
|
|
pubkey = EXCLUDED.pubkey,
|
|
onchain_address = EXCLUDED.onchain_address;
|
|
|
|
-- name: UpdateVtxoPaymentId :exec
|
|
UPDATE vtxo SET payment_id = ? WHERE txid = ? AND vout = ?;
|
|
|
|
-- name: SelectRoundWithRoundId :many
|
|
SELECT sqlc.embed(round),
|
|
sqlc.embed(round_payment_vw),
|
|
sqlc.embed(round_tx_vw),
|
|
sqlc.embed(payment_receiver_vw),
|
|
sqlc.embed(payment_vtxo_vw)
|
|
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
|
|
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
|
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
|
WHERE round.id = ?;
|
|
|
|
-- name: SelectRoundWithRoundTxId :many
|
|
SELECT sqlc.embed(round),
|
|
sqlc.embed(round_payment_vw),
|
|
sqlc.embed(round_tx_vw),
|
|
sqlc.embed(payment_receiver_vw),
|
|
sqlc.embed(payment_vtxo_vw)
|
|
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
|
|
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
|
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
|
WHERE round.txid = ?;
|
|
|
|
-- name: SelectSweepableRounds :many
|
|
SELECT sqlc.embed(round),
|
|
sqlc.embed(round_payment_vw),
|
|
sqlc.embed(round_tx_vw),
|
|
sqlc.embed(payment_receiver_vw),
|
|
sqlc.embed(payment_vtxo_vw)
|
|
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
|
|
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
|
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
|
WHERE round.swept = false AND round.ended = true AND round.failed = false;
|
|
|
|
-- name: SelectSweptRounds :many
|
|
SELECT sqlc.embed(round),
|
|
sqlc.embed(round_payment_vw),
|
|
sqlc.embed(round_tx_vw),
|
|
sqlc.embed(payment_receiver_vw),
|
|
sqlc.embed(payment_vtxo_vw)
|
|
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
|
|
LEFT OUTER JOIN payment_receiver_vw ON round_payment_vw.id=payment_receiver_vw.payment_id
|
|
LEFT OUTER JOIN payment_vtxo_vw ON round_payment_vw.id=payment_vtxo_vw.payment_id
|
|
WHERE round.swept = true AND round.failed = false AND round.ended = true AND round.connector_address <> '';
|
|
|
|
-- name: SelectRoundIdsInRange :many
|
|
SELECT id FROM round WHERE starting_timestamp > ? AND starting_timestamp < ?;
|
|
|
|
-- name: SelectRoundIds :many
|
|
SELECT id FROM round;
|
|
|
|
-- name: UpsertVtxo :exec
|
|
INSERT INTO vtxo (txid, vout, pubkey, amount, pool_tx, spent_by, spent, redeemed, swept, expire_at, created_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,
|
|
created_at = EXCLUDED.created_at,
|
|
redeem_tx = EXCLUDED.redeem_tx;
|
|
|
|
-- name: SelectSweepableVtxos :many
|
|
SELECT sqlc.embed(vtxo) FROM vtxo
|
|
WHERE redeemed = false AND swept = false;
|
|
|
|
-- name: SelectNotRedeemedVtxos :many
|
|
SELECT sqlc.embed(vtxo) FROM vtxo
|
|
WHERE redeemed = false;
|
|
|
|
-- name: SelectNotRedeemedVtxosWithPubkey :many
|
|
SELECT sqlc.embed(vtxo) FROM vtxo
|
|
WHERE redeemed = false AND pubkey = ?;
|
|
|
|
-- name: SelectVtxoByOutpoint :one
|
|
SELECT sqlc.embed(vtxo) FROM vtxo
|
|
WHERE txid = ? AND vout = ?;
|
|
|
|
-- name: SelectVtxosByPoolTxid :many
|
|
SELECT sqlc.embed(vtxo) FROM vtxo
|
|
WHERE pool_tx = ?;
|
|
|
|
-- name: MarkVtxoAsRedeemed :exec
|
|
UPDATE vtxo SET redeemed = true WHERE txid = ? AND vout = ?;
|
|
|
|
-- name: MarkVtxoAsSwept :exec
|
|
UPDATE vtxo SET swept = true WHERE txid = ? AND vout = ?;
|
|
|
|
-- name: MarkVtxoAsSpent :exec
|
|
UPDATE vtxo SET spent = true, spent_by = ? WHERE txid = ? AND vout = ?;
|
|
|
|
-- name: UpdateVtxoExpireAt :exec
|
|
UPDATE vtxo SET expire_at = ? WHERE txid = ? AND vout = ?;
|