diff --git a/tapdb/sqlc/models.go b/tapdb/sqlc/models.go index 721110f63..6829aac7d 100644 --- a/tapdb/sqlc/models.go +++ b/tapdb/sqlc/models.go @@ -201,6 +201,7 @@ type KeyGroupInfoView struct { RawKey []byte KeyIndex int32 KeyFamily int32 + XOnlyGroupKey []byte } type Macaroon struct { diff --git a/tapdb/sqlc/queries/universe.sql b/tapdb/sqlc/queries/universe.sql index a4214087c..eb247525f 100644 --- a/tapdb/sqlc/queries/universe.sql +++ b/tapdb/sqlc/queries/universe.sql @@ -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 ( @@ -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 @@ -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, diff --git a/tapdb/sqlc/universe.sql.go b/tapdb/sqlc/universe.sql.go index 0e240d17a..6ce9771e8 100644 --- a/tapdb/sqlc/universe.sql.go +++ b/tapdb/sqlc/universe.sql.go @@ -380,8 +380,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 @@ -393,11 +402,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 = $5 OR $5 IS NULL) AND (gen.asset_type = $6 OR $6 IS NULL) AND (gen.asset_id = $7 OR $7 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, @@ -451,6 +464,7 @@ type QueryUniverseAssetStatsParams struct { type QueryUniverseAssetStatsRow struct { AssetSupply int64 + GroupSupply sql.NullInt64 AssetName string AssetType int16 AssetID []byte @@ -482,6 +496,7 @@ func (q *Queries) QueryUniverseAssetStats(ctx context.Context, arg QueryUniverse var i QueryUniverseAssetStatsRow if err := rows.Scan( &i.AssetSupply, + &i.GroupSupply, &i.AssetName, &i.AssetType, &i.AssetID, @@ -577,7 +592,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 ( diff --git a/tapdb/universe_stats.go b/tapdb/universe_stats.go index cd16a972a..2d9238245 100644 --- a/tapdb/universe_stats.go +++ b/tapdb/universe_stats.go @@ -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 { diff --git a/universe/interface.go b/universe/interface.go index 0d69e8af3..af67ef6aa 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -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