Skip to content

Commit

Permalink
taprpc+proof: update asset marshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Jun 19, 2024
1 parent 12a1f8b commit 90c4253
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
5 changes: 4 additions & 1 deletion proof/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,11 @@ func (c *UniverseRpcCourier) DeliverProof(ctx context.Context,
proofAsset := transitionProof.Asset

// Construct asset leaf.
// TODO(george): We pass in a 0 dec display as we have no easy
// access to that value here, would have to pollute interfaces.
// Does this value matter in the proof flow?
rpcAsset, err := taprpc.MarshalAsset(
ctx, &proofAsset, true, true, nil,
ctx, &proofAsset, true, true, nil, 0,
)
if err != nil {
return err
Expand Down
22 changes: 17 additions & 5 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ func (r *rpcServer) fetchRpcAssets(ctx context.Context, withWitness,

rpcAssets := make([]*taprpc.Asset, len(assets))
for i, a := range assets {
rpcAssets[i], err = MarshalChainAsset(
rpcAssets[i], err = r.MarshalChainAsset(
ctx, a, withWitness, r.cfg.AddrBook,
)
if err != nil {
Expand All @@ -987,11 +987,23 @@ func (r *rpcServer) fetchRpcAssets(ctx context.Context, withWitness,
}

// MarshalChainAsset marshals the given chain asset into an RPC asset.
func MarshalChainAsset(ctx context.Context, a *asset.ChainAsset,
func (r *rpcServer) MarshalChainAsset(ctx context.Context, a *asset.ChainAsset,
withWitness bool, keyRing taprpc.KeyLookup) (*taprpc.Asset, error) {

meta, err := r.cfg.AssetStore.FetchAssetMetaForAsset(ctx, a.ID())
if err != nil {
return nil, fmt.Errorf("unable to fetch asset meta for "+
"asset_id=%v :%v", a.ID(), err)
}

_, decDisplay, err := meta.GetDecDisplay()
if err != nil {
return nil, fmt.Errorf("unable to extract decimal display for "+
"asset_id=%v :%v", a.ID(), err)
}

rpcAsset, err := taprpc.MarshalAsset(
ctx, a.Asset, a.IsSpent, withWitness, keyRing,
ctx, a.Asset, a.IsSpent, withWitness, keyRing, decDisplay,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1670,7 +1682,7 @@ func (r *rpcServer) marshalProof(ctx context.Context, p *proof.Proof,
}
}

rpcAsset, err := MarshalChainAsset(ctx, &asset.ChainAsset{
rpcAsset, err := r.MarshalChainAsset(ctx, &asset.ChainAsset{
Asset: &p.Asset,
AnchorTx: &p.AnchorTx,
AnchorBlockHash: p.BlockHeader.BlockHash(),
Expand Down Expand Up @@ -4866,7 +4878,7 @@ func marshalAssetLeaf(ctx context.Context, keys taprpc.KeyLookup,
assetLeaf *universe.Leaf) (*unirpc.AssetLeaf, error) {

rpcAsset, err := taprpc.MarshalAsset(
ctx, assetLeaf.Asset, false, true, keys,
ctx, assetLeaf.Asset, false, true, keys, 0,
)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions taprpc/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ func UnmarshalGroupWitness(wit *GroupWitness) (*asset.PendingGroupWitness,

// MarshalAsset converts an asset to its rpc representation.
func MarshalAsset(ctx context.Context, a *asset.Asset,
isSpent, withWitness bool, keyRing KeyLookup) (*Asset, error) {
isSpent, withWitness bool, keyRing KeyLookup,
decDisplay uint32) (*Asset, error) {

scriptKeyIsLocal := false
if a.ScriptKey.TweakedScriptKey != nil && keyRing != nil {
Expand Down Expand Up @@ -472,6 +473,7 @@ func MarshalAsset(ctx context.Context, a *asset.Asset,
ScriptKeyHasScriptPath: a.ScriptKey.HasScriptPath(),
IsSpent: isSpent,
IsBurn: a.IsBurn(),
DecimalDisplay: decDisplay,
}

if a.GroupKey != nil {
Expand Down Expand Up @@ -520,7 +522,7 @@ func MarshalAsset(ctx context.Context, a *asset.Asset,
if witness.SplitCommitment != nil {
rootAsset, err := MarshalAsset(
ctx, &witness.SplitCommitment.RootAsset,
false, true, nil,
false, true, nil, decDisplay,
)
if err != nil {
return nil, err
Expand Down

0 comments on commit 90c4253

Please sign in to comment.