Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: unconstrain meta field for MintAssets #559

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 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,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),
Roasbeef marked this conversation as resolved.
Show resolved Hide resolved
Data: req.Asset.AssetMeta.Data,
}

Expand Down Expand Up @@ -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(
Expand Down