Skip to content

Commit

Permalink
Merge pull request #667 from GeorgeTsagk/asset-stats-anchor-point
Browse files Browse the repository at this point in the history
Expose anchor point in AssetStats
  • Loading branch information
GeorgeTsagk authored Nov 15, 2023
2 parents 6dd69b2 + 4bf4542 commit d684ab0
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 207 deletions.
4 changes: 4 additions & 0 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,10 @@ func AssertUniverseAssetStats(t *testing.T, node *tapdHarness,
require.NotZero(t, statAsset.GenesisHeight)
require.NotZero(t, statAsset.GenesisTimestamp)
require.NotEmpty(t, statAsset.GenesisPoint)
require.NotEmpty(t, statAsset.AnchorPoint)
require.NotEqual(
t, statAsset.GenesisPoint, statAsset.AnchorPoint,
)
}

eventStats, err := node.QueryEvents(ctxb, &unirpc.QueryEventsRequest{})
Expand Down
1 change: 1 addition & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4209,6 +4209,7 @@ func (r *rpcServer) marshalAssetSyncSnapshot(ctx context.Context,
TotalSupply: int64(a.TotalSupply),
GenesisHeight: int32(a.GenesisHeight),
GenesisTimestamp: r.getBlockTimestamp(ctx, a.GenesisHeight),
AnchorPoint: a.AnchorPoint.String(),
}

if a.GroupKey != nil {
Expand Down
3 changes: 2 additions & 1 deletion tapdb/sqlc/assets.sql.go

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

3 changes: 2 additions & 1 deletion tapdb/sqlc/migrations/000002_assets.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ CREATE TABLE IF NOT EXISTS asset_seedlings (
CREATE VIEW genesis_info_view AS
SELECT
gen_asset_id, asset_id, asset_tag, assets_meta.meta_data_hash meta_hash,
output_index, asset_type, genesis_points.prev_out prev_out, block_height
output_index, asset_type, genesis_points.prev_out prev_out,
chain_txns.txid anchor_txid, block_height
FROM genesis_assets
-- We do a LEFT JOIN here, as not every asset has a set of
-- metadata that matches the asset.
Expand Down
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.

5 changes: 4 additions & 1 deletion tapdb/sqlc/queries/universe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ WITH asset_supply AS (
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
group_info.tweaked_group_key AS group_key,
gen.output_index AS anchor_index, gen.anchor_txid AS anchor_txid
FROM genesis_info_view gen
JOIN asset_supply
ON asset_supply.asset_id = gen.asset_id
Expand All @@ -269,6 +270,8 @@ SELECT asset_info.supply AS asset_supply,
asset_info.genesis_height AS genesis_height,
asset_info.genesis_prev_out AS genesis_prev_out,
asset_info.group_key AS group_key,
asset_info.anchor_index AS anchor_index,
asset_info.anchor_txid AS anchor_txid,
universe_stats.total_asset_syncs AS total_syncs,
universe_stats.total_asset_proofs AS total_proofs
FROM asset_info
Expand Down
9 changes: 8 additions & 1 deletion tapdb/sqlc/universe.sql.go

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

12 changes: 12 additions & 0 deletions tapdb/universe_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/davecgh/go-spew/spew"
"github.com/lightninglabs/neutrino/cache/lru"
"github.com/lightninglabs/taproot-assets/asset"
Expand Down Expand Up @@ -839,6 +841,16 @@ func (u *UniverseStats) QuerySyncStats(ctx context.Context,
err)
}

hash, err := chainhash.NewHash(assetStat.AnchorTxid[:])
if err != nil {
return err
}

stats.AnchorPoint = wire.OutPoint{
Hash: *hash,
Index: uint32(assetStat.AnchorIndex),
}

resp.SyncStats = append(resp.SyncStats, stats)
}

Expand Down
Loading

0 comments on commit d684ab0

Please sign in to comment.