Skip to content

Commit

Permalink
rpcserver+taprpc: distinguish group anchor from non-grouped asset
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Oct 10, 2023
1 parent 7d0ac89 commit 92623d0
Show file tree
Hide file tree
Showing 5 changed files with 449 additions and 299 deletions.
38 changes: 21 additions & 17 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1251,27 +1251,31 @@ func AssertUniverseAssetStats(t *testing.T, node *tapdHarness,
require.Len(t, assetStats.AssetStats, len(assets))

for _, assetStat := range assetStats.AssetStats {
found := fn.Any(
assets, func(a *taprpc.Asset) bool {
groupKeyEqual := true
if a.AssetGroup != nil {
groupKeyEqual = bytes.Equal(
assetStat.GroupKey,
a.AssetGroup.TweakedGroupKey,
)
}
var statAsset *unirpc.AssetStatsAsset
if assetStat.GroupAnchor != nil {
statAsset = assetStat.GroupAnchor
} else {
statAsset = assetStat.Asset
}

return groupKeyEqual && bytes.Equal(
assetStat.Asset.AssetId,
a.AssetGenesis.AssetId,
found := fn.Any(assets, func(a *taprpc.Asset) bool {
groupKeyEqual := true
if a.AssetGroup != nil {
groupKeyEqual = bytes.Equal(
assetStat.GroupKey,
a.AssetGroup.TweakedGroupKey,
)
},
)
}

return groupKeyEqual && bytes.Equal(
statAsset.AssetId, a.AssetGenesis.AssetId,
)
})
require.True(t, found)

require.NotZero(t, assetStat.Asset.GenesisHeight)
require.NotZero(t, assetStat.Asset.GenesisTimestamp)
require.NotEmpty(t, assetStat.Asset.GenesisPoint)
require.NotZero(t, statAsset.GenesisHeight)
require.NotZero(t, statAsset.GenesisTimestamp)
require.NotEmpty(t, statAsset.GenesisPoint)
}

eventStats, err := node.QueryEvents(ctxb, &unirpc.QueryEventsRequest{})
Expand Down
40 changes: 22 additions & 18 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3492,25 +3492,32 @@ func (r *rpcServer) UniverseStats(ctx context.Context,

// marshalAssetSyncSnapshot maps a universe asset sync stat snapshot to the RPC
// counterpart.
func marshalAssetSyncSnapshot(
func (r *rpcServer) marshalAssetSyncSnapshot(ctx context.Context,
a universe.AssetSyncSnapshot) *unirpc.AssetStatsSnapshot {

var groupKey []byte
if a.GroupKey != nil {
groupKey = a.GroupKey.SerializeCompressed()
resp := &unirpc.AssetStatsSnapshot{
TotalSyncs: int64(a.TotalSyncs),
TotalProofs: int64(a.TotalProofs),
GroupSupply: int64(a.GroupSupply),
}
rpcAsset := &unirpc.AssetStatsAsset{
AssetId: a.AssetID[:],
GenesisPoint: a.GenesisPoint.String(),
AssetName: a.AssetName,
AssetType: taprpc.AssetType(a.AssetType),
TotalSupply: int64(a.TotalSupply),
GenesisHeight: int32(a.GenesisHeight),
GenesisTimestamp: r.getBlockTimestamp(ctx, a.GenesisHeight),
}

return &unirpc.AssetStatsSnapshot{
AssetId: a.AssetID[:],
GroupKey: groupKey,
GenesisPoint: a.GenesisPoint.String(),
AssetName: a.AssetName,
AssetType: taprpc.AssetType(a.AssetType),
TotalSupply: int64(a.TotalSupply),
GenesisHeight: int32(a.GenesisHeight),
TotalSyncs: int64(a.TotalSyncs),
TotalProofs: int64(a.TotalProofs),
if a.GroupKey != nil {
resp.GroupKey = a.GroupKey.SerializeCompressed()
resp.GroupAnchor = rpcAsset
} else {
resp.Asset = rpcAsset
}

return resp
}

// QueryAssetStats returns a set of statistics for a given set of assets.
Expand Down Expand Up @@ -3554,10 +3561,7 @@ func (r *rpcServer) QueryAssetStats(ctx context.Context,
),
}
for idx, snapshot := range assetStats.SyncStats {
resp.AssetStats[idx] = marshalAssetSyncSnapshot(snapshot)
resp.AssetStats[idx].GenesisTimestamp = r.getBlockTimestamp(
ctx, snapshot.GenesisHeight,
)
resp.AssetStats[idx] = r.marshalAssetSyncSnapshot(ctx, snapshot)
}

return resp, nil
Expand Down
Loading

0 comments on commit 92623d0

Please sign in to comment.