Skip to content

Commit 524e6bd

Browse files
committed
tapdb: add mint asset anchor output idx and universe commitments support
Add a new `assets_output_index` column to the `asset_minting_batches` table to store the output index of the asset anchor transaction. Populate this column for existing entries based on the `change_output_index`. Introduce a `universe_commitments` flag column to indicate whether universe commitments are enabled for a minting batch, defaulting to `FALSE`. Create the `mint_anchor_uni_commitments` table to associate a mint batch anchor transaction with its universe commitments, storing the pre-commitment output index, Taproot internal key, and asset group pub key.
1 parent 1c2a38b commit 524e6bd

File tree

8 files changed

+236
-55
lines changed

8 files changed

+236
-55
lines changed

tapdb/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// daemon.
2323
//
2424
// NOTE: This MUST be updated when a new migration is added.
25-
LatestMigrationVersion = 29
25+
LatestMigrationVersion = 30
2626
)
2727

2828
// MigrationTarget is a functional option that can be passed to applyMigrations

tapdb/sqlc/assets.sql.go

Lines changed: 117 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Drop the mint_anchor_uni_commitments table and its unique index.
2+
DROP INDEX IF EXISTS mint_anchor_uni_commitments_unique;
3+
4+
-- Drop the table mint_anchor_uni_commitments.
5+
DROP TABLE IF EXISTS mint_anchor_uni_commitments;
6+
7+
-- Drop the universe_commitments column from the asset_minting_batches table.
8+
ALTER TABLE asset_minting_batches DROP COLUMN universe_commitments;
9+
10+
-- Drop the assets output index column from the asset_minting_batches table.
11+
ALTER TABLE asset_minting_batches DROP COLUMN assets_output_index;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- Add a column to the asset_minting_batches table which stores the output index
2+
-- of the asset anchor transaction output.
3+
ALTER TABLE asset_minting_batches ADD COLUMN assets_output_index INTEGER;
4+
5+
-- Existing minting anchor transactions have exactly two outputs: the asset
6+
-- commitment and the change output. We can therefore infer the asset anchor
7+
-- output index from the change output index.
8+
UPDATE asset_minting_batches
9+
SET assets_output_index = CASE
10+
WHEN change_output_index = 1 THEN 0
11+
WHEN change_output_index = 0 THEN 1
12+
-- If change_output_index is neither 0 nor 1, just set the asset anchor
13+
-- output index to NULL.
14+
ELSE NULL
15+
END;
16+
17+
-- Add a flag column which indicates if the universe commitments are enabled for
18+
-- this minting batch. This should default to false for all existing minting
19+
-- batches.
20+
ALTER TABLE asset_minting_batches
21+
ADD COLUMN universe_commitments BOOLEAN NOT NULL DEFAULT FALSE;
22+
23+
-- Create a table to relate a mint batch anchor transaction to its universe
24+
-- commitments.
25+
CREATE TABLE IF NOT EXISTS mint_anchor_uni_commitments (
26+
id INTEGER PRIMARY KEY,
27+
28+
-- The ID of the minting batch this universe commitment relates to.
29+
batch_id INTEGER NOT NULL REFERENCES asset_minting_batches(batch_id),
30+
31+
-- The index of the mint batch anchor transaction pre-commitment output.
32+
tx_output_index INTEGER NOT NULL,
33+
34+
-- The Taproot output internal key for the pre-commitment output.
35+
taproot_internal_key BLOB,
36+
37+
-- The asset group key associated with the universe commitment.
38+
group_key BLOB
39+
);
40+
41+
-- Create a unique index on the mint_anchor_uni_commitments table to enforce the
42+
-- uniqueness of (batch_id, tx_output_index) pairs.
43+
CREATE UNIQUE INDEX mint_anchor_uni_commitments_unique
44+
ON mint_anchor_uni_commitments (batch_id, tx_output_index);

tapdb/sqlc/models.go

Lines changed: 18 additions & 8 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: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)