Skip to content

Commit 23f0d5b

Browse files
committed
sqlc: update queries to include leased param
1 parent 46f9bb8 commit 23f0d5b

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

tapdb/sqlc/assets.sql.go

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

tapdb/sqlc/querier.go

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

tapdb/sqlc/queries/assets.sql

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,18 @@ JOIN genesis_info_view
321321
-- around that needs to be used with this query until a sqlc bug is fixed.
322322
LEFT JOIN key_group_info_view
323323
ON assets.genesis_id = key_group_info_view.gen_asset_id
324-
WHERE spent = FALSE
324+
JOIN managed_utxos utxos
325+
ON assets.anchor_utxo_id = utxos.utxo_id AND
326+
CASE
327+
WHEN sqlc.narg('leased') = true THEN
328+
(utxos.lease_owner IS NOT NULL AND utxos.lease_expiry > @now)
329+
WHEN sqlc.narg('leased') = false THEN
330+
(utxos.lease_owner IS NULL OR
331+
utxos.lease_expiry IS NULL OR
332+
utxos.lease_expiry <= @now)
333+
ELSE TRUE
334+
END
335+
WHERE spent = FALSE
325336
GROUP BY assets.genesis_id, genesis_info_view.asset_id,
326337
genesis_info_view.asset_tag, genesis_info_view.meta_hash,
327338
genesis_info_view.asset_type, genesis_info_view.output_index,
@@ -335,7 +346,18 @@ JOIN key_group_info_view
335346
ON assets.genesis_id = key_group_info_view.gen_asset_id AND
336347
(key_group_info_view.tweaked_group_key = sqlc.narg('key_group_filter') OR
337348
sqlc.narg('key_group_filter') IS NULL)
338-
WHERE spent = FALSE
349+
JOIN managed_utxos utxos
350+
ON assets.anchor_utxo_id = utxos.utxo_id AND
351+
CASE
352+
WHEN sqlc.narg('leased') = true THEN
353+
(utxos.lease_owner IS NOT NULL AND utxos.lease_expiry > @now)
354+
WHEN sqlc.narg('leased') = false THEN
355+
(utxos.lease_owner IS NULL OR
356+
utxos.lease_expiry IS NULL OR
357+
utxos.lease_expiry <= @now)
358+
ELSE TRUE
359+
END
360+
WHERE spent = FALSE
339361
GROUP BY key_group_info_view.tweaked_group_key;
340362

341363
-- name: FetchGroupedAssets :many

0 commit comments

Comments
 (0)