From f39fda2b28d1d05bed04236b95d2c60e81466389 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 10 Oct 2023 16:17:35 -0700 Subject: [PATCH] rpc: unconstrain meta field for MintAssets 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. --- rpcserver.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index f072a56a0..68176e8ff 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "errors" "fmt" + "math" "net/http" "strconv" "strings" @@ -372,13 +373,19 @@ 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. + switch { + case req.Asset.AssetMeta.Type < 0: + return nil, fmt.Errorf("meta type cannot be negative") + + case 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, } @@ -3960,17 +3967,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(