Skip to content

Commit 4cd1dce

Browse files
committed
tapd+tapdb: return anchor block height in ListTransfers if available
Previously, confirmed anchors included only the block hash, requiring clients to perform extra steps to look up the block height. This change adds the block height directly to the RPC response when available.
1 parent c63d418 commit 4cd1dce

File tree

9 files changed

+688
-635
lines changed

9 files changed

+688
-635
lines changed

rpcserver.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,13 +3591,14 @@ func marshalOutboundParcel(
35913591
})
35923592

35933593
return &taprpc.AssetTransfer{
3594-
TransferTimestamp: parcel.TransferTime.Unix(),
3595-
AnchorTxHash: anchorTxHash[:],
3596-
AnchorTxHeightHint: parcel.AnchorTxHeightHint,
3597-
AnchorTxChainFees: parcel.ChainFees,
3598-
AnchorTxBlockHash: anchorTxBlockHash,
3599-
Inputs: rpcInputs,
3600-
Outputs: rpcOutputs,
3594+
TransferTimestamp: parcel.TransferTime.Unix(),
3595+
AnchorTxHash: anchorTxHash[:],
3596+
AnchorTxHeightHint: parcel.AnchorTxHeightHint,
3597+
AnchorTxChainFees: parcel.ChainFees,
3598+
AnchorTxBlockHash: anchorTxBlockHash,
3599+
AnchorTxBlockHeight: parcel.AnchorTxBlockHeight,
3600+
Inputs: rpcInputs,
3601+
Outputs: rpcOutputs,
36013602
}, nil
36023603
}
36033604

tapdb/assets_store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,6 +3491,14 @@ func (a *AssetStore) QueryParcels(ctx context.Context,
34913491
Inputs: inputs,
34923492
Outputs: outputs,
34933493
}
3494+
3495+
// Set the block height if the anchor is marked as
3496+
// confirmed in the database.
3497+
if dbAnchorTx.BlockHeight.Valid {
3498+
parcel.AnchorTxBlockHeight = uint32(
3499+
dbAnchorTx.BlockHeight.Int32,
3500+
)
3501+
}
34943502
outboundParcels = append(outboundParcels, parcel)
34953503
}
34963504

tapdb/assets_store_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,15 @@ func TestAssetExportLog(t *testing.T) {
15561556
)
15571557
require.NoError(t, err)
15581558

1559+
// Make sure that if we query for the asset transfer again, we now have
1560+
// the block hash and height set.
1561+
parcels, err = assetsStore.QueryParcels(ctx, &anchorTxHash, false)
1562+
require.NoError(t, err)
1563+
require.Len(t, parcels, 1)
1564+
spendDelta.AnchorTxBlockHash = fn.Some(fakeBlockHash)
1565+
spendDelta.AnchorTxBlockHeight = uint32(blockHeight)
1566+
require.Equal(t, spendDelta, parcels[0])
1567+
15591568
// We'll now fetch all the assets to verify that they were updated
15601569
// properly on disk.
15611570
chainAssets, err := assetsStore.FetchAllAssets(ctx, false, true, nil)

tapfreighter/chain_porter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ func (p *ChainPorter) waitForTransferTxConf(pkg *sendPackage) error {
405405
pkg.OutboundPkg.AnchorTxBlockHash = fn.MaybeSome(
406406
confEvent.BlockHash,
407407
)
408+
pkg.OutboundPkg.AnchorTxBlockHeight = confEvent.BlockHeight
408409

409410
pkg.SendState = SendStateStorePostAnchorTxConf
410411

tapfreighter/interface.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ type OutboundParcel struct {
348348
// confirmed.
349349
AnchorTxBlockHash fn.Option[chainhash.Hash]
350350

351+
// AnchorTxBlockHeight is the block height of the block that contains
352+
// the anchor transaction. This is set once the anchor transaction is
353+
// confirmed.
354+
AnchorTxBlockHeight uint32
355+
351356
// TransferTime holds the timestamp of the outbound spend.
352357
TransferTime time.Time
353358

taprpc/assetwalletrpc/assetwallet.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@
921921
"anchor_tx_block_hash": {
922922
"$ref": "#/definitions/taprpcChainHash",
923923
"description": "The block hash of the blockchain block that contains the anchor\ntransaction. If this value is unset, the anchor transaction is\nunconfirmed."
924+
},
925+
"anchor_tx_block_height": {
926+
"type": "integer",
927+
"format": "int64",
928+
"description": "The block height of the blockchain block that contains the anchor\ntransaction. If the anchor transaction is still unconfirmed, this value\nwill be 0."
924929
}
925930
}
926931
},

taprpc/taprootassets.pb.go

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

taprpc/taprootassets.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,11 @@ message AssetTransfer {
726726
// transaction. If this value is unset, the anchor transaction is
727727
// unconfirmed.
728728
ChainHash anchor_tx_block_hash = 7;
729+
730+
// The block height of the blockchain block that contains the anchor
731+
// transaction. If the anchor transaction is still unconfirmed, this value
732+
// will be 0.
733+
uint32 anchor_tx_block_height = 8;
729734
}
730735

731736
message TransferInput {

taprpc/taprootassets.swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,11 @@
14951495
"anchor_tx_block_hash": {
14961496
"$ref": "#/definitions/taprpcChainHash",
14971497
"description": "The block hash of the blockchain block that contains the anchor\ntransaction. If this value is unset, the anchor transaction is\nunconfirmed."
1498+
},
1499+
"anchor_tx_block_height": {
1500+
"type": "integer",
1501+
"format": "int64",
1502+
"description": "The block height of the blockchain block that contains the anchor\ntransaction. If the anchor transaction is still unconfirmed, this value\nwill be 0."
14981503
}
14991504
}
15001505
},

0 commit comments

Comments
 (0)