Skip to content

Commit

Permalink
rpc: unconstrain meta field for MintAssets
Browse files Browse the repository at this point in the history
In this commit, we stop trying to strictly parse the meta field.
Instead, users can set it to w/e they want, with the default being
opaque. This lets users start to add structure to the meta field from
day one. One example is a set meta with fields that dictate how the
asset unit is to be displayed. This can be used to do things like
leverage the current fix point format to add decimal places for display.
  • Loading branch information
Roasbeef committed Oct 11, 2023
1 parent d65192b commit f65d7f0
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"math"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -372,13 +373,15 @@ func (r *rpcServer) MintAsset(ctx context.Context,
}

if req.Asset.AssetMeta != nil {
metaType, err := unmarshalMetaType(req.Asset.AssetMeta.Type)
if err != nil {
return nil, err
// Ensure that the meta field is within bounds.
if req.Asset.AssetMeta.Type > math.MaxUint8 {
return nil, fmt.Errorf("meta type is too large: %v, "+
"max is: %v", req.Asset.AssetMeta.Type,
math.MaxUint8)
}

seedling.Meta = &proof.MetaReveal{
Type: metaType,
Type: proof.MetaType(req.Asset.AssetMeta.Type),
Data: req.Asset.AssetMeta.Data,
}

Expand Down Expand Up @@ -3960,17 +3963,6 @@ func (r *rpcServer) RemoveUTXOLease(ctx context.Context,
return &wrpc.RemoveUTXOLeaseResponse{}, nil
}

// unmarshalMetaType maps an RPC meta type into a concrete type.
func unmarshalMetaType(rpcMeta taprpc.AssetMetaType) (proof.MetaType, error) {
switch rpcMeta {
case taprpc.AssetMetaType_META_TYPE_OPAQUE:
return proof.MetaOpaque, nil

default:
return 0, fmt.Errorf("unknown meta type: %v", rpcMeta)
}
}

// MarshalAssetFedSyncCfg returns an RPC ready asset specific federation sync
// config.
func MarshalAssetFedSyncCfg(
Expand Down

0 comments on commit f65d7f0

Please sign in to comment.