Skip to content

Commit d684ab0

Browse files
authored
Merge pull request #667 from GeorgeTsagk/asset-stats-anchor-point
Expose anchor point in AssetStats
2 parents 6dd69b2 + 4bf4542 commit d684ab0

File tree

12 files changed

+257
-207
lines changed

12 files changed

+257
-207
lines changed

itest/assertions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,10 @@ func AssertUniverseAssetStats(t *testing.T, node *tapdHarness,
13001300
require.NotZero(t, statAsset.GenesisHeight)
13011301
require.NotZero(t, statAsset.GenesisTimestamp)
13021302
require.NotEmpty(t, statAsset.GenesisPoint)
1303+
require.NotEmpty(t, statAsset.AnchorPoint)
1304+
require.NotEqual(
1305+
t, statAsset.GenesisPoint, statAsset.AnchorPoint,
1306+
)
13031307
}
13041308

13051309
eventStats, err := node.QueryEvents(ctxb, &unirpc.QueryEventsRequest{})

rpcserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,7 @@ func (r *rpcServer) marshalAssetSyncSnapshot(ctx context.Context,
42094209
TotalSupply: int64(a.TotalSupply),
42104210
GenesisHeight: int32(a.GenesisHeight),
42114211
GenesisTimestamp: r.getBlockTimestamp(ctx, a.GenesisHeight),
4212+
AnchorPoint: a.AnchorPoint.String(),
42124213
}
42134214

42144215
if a.GroupKey != nil {

tapdb/sqlc/assets.sql.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/migrations/000002_assets.up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ CREATE TABLE IF NOT EXISTS asset_seedlings (
315315
CREATE VIEW genesis_info_view AS
316316
SELECT
317317
gen_asset_id, asset_id, asset_tag, assets_meta.meta_data_hash meta_hash,
318-
output_index, asset_type, genesis_points.prev_out prev_out, block_height
318+
output_index, asset_type, genesis_points.prev_out prev_out,
319+
chain_txns.txid anchor_txid, block_height
319320
FROM genesis_assets
320321
-- We do a LEFT JOIN here, as not every asset has a set of
321322
-- metadata that matches the asset.

tapdb/sqlc/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/queries/universe.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ WITH asset_supply AS (
247247
gen.asset_id AS asset_id,
248248
gen.asset_tag AS asset_name, gen.asset_type AS asset_type,
249249
gen.block_height AS genesis_height, gen.prev_out AS genesis_prev_out,
250-
group_info.tweaked_group_key AS group_key
250+
group_info.tweaked_group_key AS group_key,
251+
gen.output_index AS anchor_index, gen.anchor_txid AS anchor_txid
251252
FROM genesis_info_view gen
252253
JOIN asset_supply
253254
ON asset_supply.asset_id = gen.asset_id
@@ -269,6 +270,8 @@ SELECT asset_info.supply AS asset_supply,
269270
asset_info.genesis_height AS genesis_height,
270271
asset_info.genesis_prev_out AS genesis_prev_out,
271272
asset_info.group_key AS group_key,
273+
asset_info.anchor_index AS anchor_index,
274+
asset_info.anchor_txid AS anchor_txid,
272275
universe_stats.total_asset_syncs AS total_syncs,
273276
universe_stats.total_asset_proofs AS total_proofs
274277
FROM asset_info

tapdb/sqlc/universe.sql.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/universe_stats.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/btcsuite/btcd/btcec/v2"
1414
"github.com/btcsuite/btcd/btcec/v2/schnorr"
15+
"github.com/btcsuite/btcd/chaincfg/chainhash"
16+
"github.com/btcsuite/btcd/wire"
1517
"github.com/davecgh/go-spew/spew"
1618
"github.com/lightninglabs/neutrino/cache/lru"
1719
"github.com/lightninglabs/taproot-assets/asset"
@@ -839,6 +841,16 @@ func (u *UniverseStats) QuerySyncStats(ctx context.Context,
839841
err)
840842
}
841843

844+
hash, err := chainhash.NewHash(assetStat.AnchorTxid[:])
845+
if err != nil {
846+
return err
847+
}
848+
849+
stats.AnchorPoint = wire.OutPoint{
850+
Hash: *hash,
851+
Index: uint32(assetStat.AnchorIndex),
852+
}
853+
842854
resp.SyncStats = append(resp.SyncStats, stats)
843855
}
844856

0 commit comments

Comments
 (0)