@@ -1091,8 +1091,12 @@ func (r *rpcServer) fetchRpcAssets(ctx context.Context, withWitness,
10911091
10921092 rpcAssets := make ([]* taprpc.Asset , len (assets ))
10931093 for i , a := range assets {
1094+ if a == nil {
1095+ return nil , fmt .Errorf ("nil asset at index %d" , i )
1096+ }
1097+
10941098 rpcAssets [i ], err = r .MarshalChainAsset (
1095- ctx , a , nil , withWitness , r .cfg .AddrBook ,
1099+ ctx , * a , nil , withWitness , r .cfg .AddrBook ,
10961100 )
10971101 if err != nil {
10981102 return nil , fmt .Errorf ("unable to marshal asset: %w" ,
@@ -1104,7 +1108,7 @@ func (r *rpcServer) fetchRpcAssets(ctx context.Context, withWitness,
11041108}
11051109
11061110// MarshalChainAsset marshals the given chain asset into an RPC asset.
1107- func (r * rpcServer ) MarshalChainAsset (ctx context.Context , a * asset.ChainAsset ,
1111+ func (r * rpcServer ) MarshalChainAsset (ctx context.Context , a asset.ChainAsset ,
11081112 meta * proof.MetaReveal , withWitness bool ,
11091113 keyRing taprpc.KeyLookup ) (* taprpc.Asset , error ) {
11101114
@@ -1125,38 +1129,9 @@ func (r *rpcServer) MarshalChainAsset(ctx context.Context, a *asset.ChainAsset,
11251129 return nil , err
11261130 }
11271131
1128- rpcAsset , err := taprpc .MarshalAsset (
1129- ctx , a . Asset , a . IsSpent , withWitness , keyRing , decDisplay ,
1132+ return taprpc .MarshalChainAsset (
1133+ ctx , a , decDisplay , withWitness , keyRing ,
11301134 )
1131- if err != nil {
1132- return nil , err
1133- }
1134-
1135- var anchorTxBytes []byte
1136- if a .AnchorTx != nil {
1137- anchorTxBytes , err = serialize (a .AnchorTx )
1138- if err != nil {
1139- return nil , fmt .Errorf ("unable to serialize anchor " +
1140- "tx: %w" , err )
1141- }
1142- }
1143-
1144- rpcAsset .ChainAnchor = & taprpc.AnchorInfo {
1145- AnchorTx : anchorTxBytes ,
1146- AnchorBlockHash : a .AnchorBlockHash .String (),
1147- AnchorOutpoint : a .AnchorOutpoint .String (),
1148- InternalKey : a .AnchorInternalKey .SerializeCompressed (),
1149- MerkleRoot : a .AnchorMerkleRoot ,
1150- TapscriptSibling : a .AnchorTapscriptSibling ,
1151- BlockHeight : a .AnchorBlockHeight ,
1152- }
1153-
1154- if a .AnchorLeaseOwner != [32 ]byte {} {
1155- rpcAsset .LeaseOwner = a .AnchorLeaseOwner [:]
1156- rpcAsset .LeaseExpiry = a .AnchorLeaseExpiry .UTC ().Unix ()
1157- }
1158-
1159- return rpcAsset , nil
11601135}
11611136
11621137func (r * rpcServer ) listBalancesByAsset (ctx context.Context ,
@@ -1750,10 +1725,6 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
17501725 rpcMeta * taprpc.AssetMeta
17511726 rpcGenesis = p .GenesisReveal
17521727 rpcGroupKey = p .GroupKeyReveal
1753- anchorOutpoint = wire.OutPoint {
1754- Hash : p .AnchorTx .TxHash (),
1755- Index : p .InclusionProof .OutputIndex ,
1756- }
17571728 txMerkleProof = p .TxMerkleProof
17581729 inclusionProof = p .InclusionProof
17591730 splitRootProof = p .SplitRootProof
@@ -1772,31 +1743,10 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
17721743 err )
17731744 }
17741745
1775- if inclusionProof .CommitmentProof == nil {
1776- return nil , fmt .Errorf ("inclusion proof is missing " +
1777- "commitment proof" )
1778- }
1779- tsSibling , tsHash , err := commitment .MaybeEncodeTapscriptPreimage (
1780- inclusionProof .CommitmentProof .TapSiblingPreimage ,
1781- )
1782- if err != nil {
1783- return nil , fmt .Errorf ("error encoding tapscript sibling: %w" ,
1784- err )
1785- }
1786-
1787- tapProof , err := inclusionProof .CommitmentProof .DeriveByAssetInclusion (
1788- & p .Asset ,
1789- )
1790- if err != nil {
1791- return nil , fmt .Errorf ("error deriving inclusion proof: %w" ,
1792- err )
1793- }
1794- merkleRoot := tapProof .TapscriptRoot (tsHash )
1795-
17961746 var exclusionProofs [][]byte
17971747 for _ , exclusionProof := range p .ExclusionProofs {
17981748 var exclusionProofBuf bytes.Buffer
1799- err = exclusionProof .Encode (& exclusionProofBuf )
1749+ err : = exclusionProof .Encode (& exclusionProofBuf )
18001750 if err != nil {
18011751 return nil , fmt .Errorf ("unable to encode exclusion " +
18021752 "proofs: %w" , err )
@@ -1808,7 +1758,7 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
18081758
18091759 var splitRootProofBuf bytes.Buffer
18101760 if splitRootProof != nil {
1811- err = splitRootProof .Encode (& splitRootProofBuf )
1761+ err : = splitRootProof .Encode (& splitRootProofBuf )
18121762 if err != nil {
18131763 return nil , fmt .Errorf ("unable to encode split root " +
18141764 "proof: %w" , err )
@@ -1828,18 +1778,19 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
18281778 }
18291779 }
18301780
1831- rpcAsset , err := r .MarshalChainAsset (ctx , & asset.ChainAsset {
1832- Asset : & p .Asset ,
1833- AnchorTx : & p .AnchorTx ,
1834- AnchorBlockHash : p .BlockHeader .BlockHash (),
1835- AnchorBlockHeight : p .BlockHeight ,
1836- AnchorOutpoint : anchorOutpoint ,
1837- AnchorInternalKey : p .InclusionProof .InternalKey ,
1838- AnchorMerkleRoot : merkleRoot [:],
1839- AnchorTapscriptSibling : tsSibling ,
1840- }, p .MetaReveal , withPrevWitnesses , r .cfg .AddrBook )
1781+ chainAsset , err := p .ToChainAsset ()
18411782 if err != nil {
1842- return nil , err
1783+ return nil , fmt .Errorf ("unable to convert proof to chain " +
1784+ "asset: %w" , err )
1785+ }
1786+
1787+ rpcAsset , err := r .MarshalChainAsset (
1788+ ctx , chainAsset , p .MetaReveal , withPrevWitnesses ,
1789+ r .cfg .AddrBook ,
1790+ )
1791+ if err != nil {
1792+ return nil , fmt .Errorf ("unable to marshal chain asset: %w" ,
1793+ err )
18431794 }
18441795
18451796 if withMetaReveal {
0 commit comments