Skip to content

Commit

Permalink
universe+tapdb: add group supply to asset stats
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Oct 10, 2023
1 parent b53141d commit 7d0ac89
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions tapdb/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions tapdb/sqlc/queries/universe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ WITH stats AS (
FROM mssmt_nodes nodes
JOIN mssmt_roots roots
ON nodes.hash_key = roots.root_hash AND
nodes.namespace = roots.namespace
nodes.namespace = roots.namespace
JOIN universe_roots uroots
ON roots.namespace = uroots.namespace_root
), aggregated AS (
Expand Down Expand Up @@ -215,8 +215,17 @@ WITH asset_supply AS (
JOIN genesis_info_view gen
ON leaves.asset_genesis_id = gen.gen_asset_id
GROUP BY gen.asset_id
), group_supply AS (
SELECT sum AS num_assets, uroots.group_key AS group_key
FROM mssmt_nodes nodes
JOIN mssmt_roots roots
ON nodes.hash_key = roots.root_hash AND
nodes.namespace = roots.namespace
JOIN universe_roots uroots
ON roots.namespace = uroots.namespace_root
), asset_info AS (
SELECT asset_supply.supply, gen.asset_id AS asset_id,
SELECT asset_supply.supply, group_supply.num_assets AS group_supply,
gen.asset_id AS asset_id,
gen.asset_tag AS asset_name, gen.asset_type AS asset_type,
gen.block_height AS genesis_height, gen.prev_out AS genesis_prev_out,
group_info.tweaked_group_key AS group_key
Expand All @@ -228,11 +237,15 @@ WITH asset_supply AS (
-- doesn't have a group key.
LEFT JOIN key_group_info_view group_info
ON gen.gen_asset_id = group_info.gen_asset_id
LEFT JOIN group_supply
ON group_supply.group_key = group_info.x_only_group_key
WHERE (gen.asset_tag = sqlc.narg('asset_name') OR sqlc.narg('asset_name') IS NULL) AND
(gen.asset_type = sqlc.narg('asset_type') OR sqlc.narg('asset_type') IS NULL) AND
(gen.asset_id = sqlc.narg('asset_id') OR sqlc.narg('asset_id') IS NULL)
)
SELECT asset_info.supply AS asset_supply, asset_info.asset_name AS asset_name,
SELECT asset_info.supply AS asset_supply,
asset_info.group_supply AS group_supply,
asset_info.asset_name AS asset_name,
asset_info.asset_type AS asset_type, asset_info.asset_id AS asset_id,
asset_info.genesis_height AS genesis_height,
asset_info.genesis_prev_out AS genesis_prev_out,
Expand Down
21 changes: 18 additions & 3 deletions tapdb/sqlc/universe.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tapdb/universe_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ func (u *UniverseStats) QuerySyncStats(ctx context.Context,
),
TotalSyncs: uint64(assetStat.TotalSyncs),
TotalProofs: uint64(assetStat.TotalProofs),
GroupSupply: uint64(assetStat.GroupSupply.Int64),
}

if len(assetStat.GroupKey) > 0 {
Expand Down
4 changes: 4 additions & 0 deletions universe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ type AssetSyncSnapshot struct {
// GroupKey is the optional group key of the asset.
GroupKey *btcec.PublicKey

// GroupSupply is the total supply of the whole asset group. This is
// only set for grouped assets.
GroupSupply uint64

// GenesisPoint is the first previous output that created the asset.
GenesisPoint wire.OutPoint

Expand Down

0 comments on commit 7d0ac89

Please sign in to comment.