Skip to content

Commit 80e7c85

Browse files
author
Robyn Ffrancon
authored
Merge pull request #689 from GeorgeTsagk/anchor-txid-patch
Drop and re-create genesis_info_view
2 parents 0970d94 + ddff1af commit 80e7c85

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

tapdb/sqlc/migrations/000002_assets.up.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ CREATE TABLE IF NOT EXISTS asset_seedlings (
315315
CREATE VIEW genesis_info_view AS
316316
SELECT
317317
gen_asset_id, asset_id, asset_tag, assets_meta.meta_data_hash meta_hash,
318-
output_index, asset_type, genesis_points.prev_out prev_out,
319-
chain_txns.txid anchor_txid, block_height
318+
output_index, asset_type, genesis_points.prev_out prev_out, block_height
320319
FROM genesis_assets
321320
-- We do a LEFT JOIN here, as not every asset has a set of
322321
-- metadata that matches the asset.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This file is empty on purpose. There is nothing to roll back for this
2+
-- migration.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
DROP VIEW IF EXISTS key_group_info_view;
2+
DROP VIEW IF EXISTS genesis_info_view;
3+
4+
-- This view is used to fetch the base asset information from disk based on
5+
-- the raw key of the batch that will ultimately create this set of assets.
6+
-- To do so, we'll need to traverse a few tables to join the set of assets
7+
-- with the genesis points, then with the batches that reference this
8+
-- points, to the internal key that reference the batch, then restricted
9+
-- for internal keys that match our main batch key.
10+
CREATE VIEW genesis_info_view AS
11+
SELECT
12+
gen_asset_id, asset_id, asset_tag, assets_meta.meta_data_hash meta_hash,
13+
output_index, asset_type, genesis_points.prev_out prev_out,
14+
chain_txns.txid anchor_txid, block_height
15+
FROM genesis_assets
16+
-- We do a LEFT JOIN here, as not every asset has a set of
17+
-- metadata that matches the asset.
18+
LEFT JOIN assets_meta
19+
ON genesis_assets.meta_data_id = assets_meta.meta_id
20+
JOIN genesis_points
21+
ON genesis_assets.genesis_point_id = genesis_points.genesis_id
22+
LEFT JOIN chain_txns
23+
ON genesis_points.anchor_tx_id = chain_txns.txn_id;
24+
25+
-- This view is used to perform a series of joins that allow us to extract
26+
-- the group key information, as well as the group sigs for the series of
27+
-- assets we care about. We obtain only the assets found in the batch
28+
-- above, with the WHERE query at the bottom.
29+
CREATE VIEW key_group_info_view AS
30+
SELECT
31+
witness_id, gen_asset_id, witness_stack, tapscript_root,
32+
tweaked_group_key, raw_key, key_index, key_family,
33+
substr(tweaked_group_key, 2) AS x_only_group_key
34+
FROM asset_group_witnesses wit
35+
JOIN asset_groups groups
36+
ON wit.group_key_id = groups.group_id
37+
JOIN internal_keys keys
38+
ON keys.key_id = groups.internal_key_id
39+
WHERE wit.gen_asset_id IN (SELECT gen_asset_id FROM genesis_info_view);

0 commit comments

Comments
 (0)