Skip to content

Commit 3c01a80

Browse files
authored
Merge pull request #1480 from jamaljsr/leaves-chain-anchor
Add chain_anchor with block_timestamp to AssetLeaves RPC
2 parents e621bee + ba859b9 commit 3c01a80

File tree

8 files changed

+1009
-960
lines changed

8 files changed

+1009
-960
lines changed

asset/asset.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,10 @@ type ChainAsset struct {
18631863
// tx.
18641864
AnchorBlockHeight uint32
18651865

1866+
// AnchorBlockTimestamp is the Unix timestamp of the block that mined
1867+
// the anchor tx.
1868+
AnchorBlockTimestamp int64
1869+
18661870
// AnchorOutpoint is the outpoint that commits to the asset.
18671871
AnchorOutpoint wire.OutPoint
18681872

proof/proof.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ func (p *Proof) ToChainAsset() (asset.ChainAsset, error) {
530530
AnchorBlockHash: p.BlockHeader.BlockHash(),
531531
AnchorOutpoint: p.OutPoint(),
532532
AnchorBlockHeight: p.BlockHeight,
533+
AnchorBlockTimestamp: p.BlockHeader.Timestamp.Unix(),
533534
AnchorInternalKey: p.InclusionProof.InternalKey,
534535
AnchorMerkleRoot: merkleRoot[:],
535536
AnchorTapscriptSibling: tsSibling,

rpcserver.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,13 @@ func (r *rpcServer) MarshalChainAsset(ctx context.Context, a asset.ChainAsset,
12121212
return nil, err
12131213
}
12141214

1215+
// Ensure the block timestamp is set if a block height is set.
1216+
if a.AnchorBlockTimestamp == 0 && a.AnchorBlockHeight > 0 {
1217+
a.AnchorBlockTimestamp = r.cfg.ChainBridge.GetBlockTimestamp(
1218+
ctx, a.AnchorBlockHeight,
1219+
)
1220+
}
1221+
12151222
return taprpc.MarshalChainAsset(
12161223
ctx, a, decDisplay, withWitness, keyRing,
12171224
)
@@ -5293,8 +5300,19 @@ func marshalAssetLeaf(ctx context.Context, keys taprpc.KeyLookup,
52935300
assetLeaf *universe.Leaf,
52945301
decDisplay fn.Option[uint32]) (*unirpc.AssetLeaf, error) {
52955302

5296-
rpcAsset, err := taprpc.MarshalAsset(
5297-
ctx, assetLeaf.Asset, false, true, keys, decDisplay,
5303+
// Decode the single proof to extract on-chain anchor info.
5304+
p, err := proof.Decode(assetLeaf.RawProof)
5305+
if err != nil {
5306+
return nil, err
5307+
}
5308+
chainAsset, err := p.ToChainAsset()
5309+
if err != nil {
5310+
return nil, err
5311+
}
5312+
5313+
// Marshal as a chain asset to include chain_anchor details.
5314+
rpcAsset, err := taprpc.MarshalChainAsset(
5315+
ctx, chainAsset, decDisplay, true, keys,
52985316
)
52995317
if err != nil {
53005318
return nil, err

taprpc/marshal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ func MarshalChainAsset(ctx context.Context, a asset.ChainAsset,
510510
MerkleRoot: a.AnchorMerkleRoot,
511511
TapscriptSibling: a.AnchorTapscriptSibling,
512512
BlockHeight: a.AnchorBlockHeight,
513+
BlockTimestamp: a.AnchorBlockTimestamp,
513514
}
514515

515516
if a.AnchorLeaseOwner != [32]byte{} {

taprpc/taprootassets.pb.go

Lines changed: 970 additions & 958 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taprpc/taprootassets.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ message AnchorInfo {
265265

266266
// The height of the block which contains the anchor transaction.
267267
uint32 block_height = 8;
268+
269+
// The UTC Unix timestamp of the block containing the anchor transaction.
270+
int64 block_timestamp = 9;
268271
}
269272

270273
message GenesisInfo {

taprpc/taprootassets.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,11 @@
12561256
"type": "integer",
12571257
"format": "int64",
12581258
"description": "The height of the block which contains the anchor transaction."
1259+
},
1260+
"block_timestamp": {
1261+
"type": "string",
1262+
"format": "int64",
1263+
"description": "The UTC Unix timestamp of the block containing the anchor transaction."
12591264
}
12601265
}
12611266
},

taprpc/universerpc/universe.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,11 @@
17001700
"type": "integer",
17011701
"format": "int64",
17021702
"description": "The height of the block which contains the anchor transaction."
1703+
},
1704+
"block_timestamp": {
1705+
"type": "string",
1706+
"format": "int64",
1707+
"description": "The UTC Unix timestamp of the block containing the anchor transaction."
17031708
}
17041709
}
17051710
},

0 commit comments

Comments
 (0)