Skip to content

Commit

Permalink
Merge pull request #663 from GeorgeTsagk/rpc-remove-anchor-txid
Browse files Browse the repository at this point in the history
RPC: Remove `anchor_txid` from `AnchorInfo`
  • Loading branch information
GeorgeTsagk authored Nov 9, 2023
2 parents 12d2439 + da6dcea commit cdd6707
Show file tree
Hide file tree
Showing 8 changed files with 731 additions and 749 deletions.
13 changes: 10 additions & 3 deletions itest/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,17 @@ func AssetAnchorCheck(txid, blockHash chainhash.Hash) AssetCheck {
return fmt.Errorf("asset is missing chain anchor field")
}

if a.ChainAnchor.AnchorTxid != txid.String() {
out, err :=
wire.NewOutPointFromString(a.ChainAnchor.AnchorOutpoint)
if err != nil {
return fmt.Errorf("unable to parse outpoint: %v", err)
}

anchorTxid := out.Hash.String()

if anchorTxid != txid.String() {
return fmt.Errorf("unexpected asset anchor TXID, got "+
"%v wanted %x", a.ChainAnchor.AnchorTxid,
txid[:])
"%v wanted %x", anchorTxid, txid[:])
}

if a.ChainAnchor.AnchorBlockHash != blockHash.String() {
Expand Down
9 changes: 6 additions & 3 deletions itest/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/taprpc"
Expand Down Expand Up @@ -173,11 +174,13 @@ func transferAssetProofs(t *harnessTest, src, dst *tapdHarness,
importedAssets := GroupAssetsByName(listResp.Assets)
for _, existingAsset := range assets {
gen := existingAsset.AssetGenesis
anchorTxHash, err := chainhash.NewHashFromStr(
existingAsset.ChainAnchor.AnchorTxid,
out, err := wire.NewOutPointFromString(
existingAsset.ChainAnchor.AnchorOutpoint,
)
require.NoError(t.t, err)

anchorTxHash := out.Hash

anchorBlockHash, err := chainhash.NewHashFromStr(
existingAsset.ChainAnchor.AnchorBlockHash,
)
Expand All @@ -187,7 +190,7 @@ func transferAssetProofs(t *harnessTest, src, dst *tapdHarness,
t.t, importedAssets, gen.Name, gen.MetaHash,
AssetAmountCheck(existingAsset.Amount),
AssetTypeCheck(existingAsset.AssetGenesis.AssetType),
AssetAnchorCheck(*anchorTxHash, *anchorBlockHash),
AssetAnchorCheck(anchorTxHash, *anchorBlockHash),
AssetScriptKeyIsLocalCheck(shouldShowUpAsLocal),
)
}
Expand Down
2 changes: 0 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@ func (r *rpcServer) marshalChainAsset(ctx context.Context, a *tapdb.ChainAsset,

rpcAsset.ChainAnchor = &taprpc.AnchorInfo{
AnchorTx: anchorTxBytes,
AnchorTxid: a.AnchorTxid.String(),
AnchorBlockHash: a.AnchorBlockHash.String(),
AnchorOutpoint: a.AnchorOutpoint.String(),
InternalKey: a.AnchorInternalKey.SerializeCompressed(),
Expand Down Expand Up @@ -1380,7 +1379,6 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
rpcAsset, err := r.marshalChainAsset(ctx, &tapdb.ChainAsset{
Asset: &p.Asset,
AnchorTx: &p.AnchorTx,
AnchorTxid: p.AnchorTx.TxHash(),
AnchorBlockHash: p.BlockHeader.BlockHash(),
AnchorBlockHeight: p.BlockHeight,
AnchorOutpoint: anchorOutpoint,
Expand Down
4 changes: 0 additions & 4 deletions tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ type ChainAsset struct {
// AnchorTx is the transaction that anchors this chain asset.
AnchorTx *wire.MsgTx

// AnchorTxid is the TXID of the anchor tx.
AnchorTxid chainhash.Hash

// AnchorBlockHash is the blockhash that mined the anchor tx.
AnchorBlockHash chainhash.Hash

Expand Down Expand Up @@ -761,7 +758,6 @@ func (a *AssetStore) dbAssetsToChainAssets(dbAssets []ConfirmedAsset,
Asset: assetSprout,
IsSpent: sprout.Spent,
AnchorTx: anchorTx,
AnchorTxid: anchorTx.TxHash(),
AnchorBlockHash: anchorBlockHash,
AnchorOutpoint: anchorOutpoint,
AnchorInternalKey: anchorInternalKey,
Expand Down
1,441 changes: 715 additions & 726 deletions taprpc/taprootassets.pb.go

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions taprpc/taprootassets.proto
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ message AnchorInfo {
// resides.
bytes anchor_tx = 1;

// The txid of the above transaction.
string anchor_txid = 2;

// The block hash the contains the anchor transaction above.
string anchor_block_hash = 3;

Expand Down
4 changes: 0 additions & 4 deletions taprpc/taprootassets.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,6 @@
"format": "byte",
"description": "The transaction that anchors the Taproot Asset commitment where the asset\n resides."
},
"anchor_txid": {
"type": "string",
"description": "The txid of the above transaction."
},
"anchor_block_hash": {
"type": "string",
"description": "The block hash the contains the anchor transaction above."
Expand Down
4 changes: 0 additions & 4 deletions taprpc/universerpc/universe.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1304,10 +1304,6 @@
"format": "byte",
"description": "The transaction that anchors the Taproot Asset commitment where the asset\n resides."
},
"anchor_txid": {
"type": "string",
"description": "The txid of the above transaction."
},
"anchor_block_hash": {
"type": "string",
"description": "The block hash the contains the anchor transaction above."
Expand Down

0 comments on commit cdd6707

Please sign in to comment.