Skip to content

Commit 1463fbe

Browse files
committed
Fix returning redeem txs with matching txid in sqlite db
1 parent 49b51d5 commit 1463fbe

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

server/internal/infrastructure/db/sqlite/round_repo.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,17 @@ func (r *roundRepository) GetVtxoTreeWithTxid(ctx context.Context, txid string)
373373
}
374374

375375
func (r *roundRepository) GetTxsWithTxids(ctx context.Context, txids []string) ([]string, error) {
376-
rows, err := r.querier.GetTxsByTxid(ctx, txids)
376+
rows, err := r.querier.GetTxsByTxid(ctx, queries.GetTxsByTxidParams{
377+
Ids1: txids,
378+
Ids2: txids,
379+
})
377380
if err != nil {
378381
return nil, err
379382
}
380383

381384
resp := make([]string, 0, len(rows))
382385
for _, row := range rows {
383-
resp = append(resp, row.Tx.Tx)
386+
resp = append(resp, row.Data)
384387
}
385388

386389
return resp, nil

server/internal/infrastructure/db/sqlite/sqlc/queries/query.sql.go

Lines changed: 32 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/internal/infrastructure/db/sqlite/sqlc/query.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ ON CONFLICT(id) DO UPDATE SET
4040
swept = EXCLUDED.swept;
4141

4242
-- name: GetTxsByTxid :many
43-
SELECT sqlc.embed(tx) FROM tx
44-
WHERE txid in (sqlc.slice('ids'));
43+
SELECT
44+
tx.txid,
45+
tx.tx AS data
46+
FROM tx
47+
WHERE tx.txid IN (sqlc.slice('ids1'))
48+
UNION
49+
SELECT
50+
vtxo.txid,
51+
vtxo.redeem_tx AS data
52+
FROM vtxo
53+
WHERE vtxo.txid IN (sqlc.slice('ids2')) AND vtxo.redeem_tx IS NOT '';
4554

4655
-- name: UpsertTxRequest :exec
4756
INSERT INTO tx_request (id, round_id) VALUES (?, ?)

0 commit comments

Comments
 (0)