From f65d7f06899c85d9c63ad9e11f4b2e9ebd5af115 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 | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index f072a56a0..e5ff352bc 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "errors" "fmt" + "math" "net/http" "strconv" "strings" @@ -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, } @@ -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(