Skip to content

Commit

Permalink
fix to use serde not vmtypes serises
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 30, 2023
1 parent 602d2bc commit 0065dc7
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions x/move/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

sdkmath "cosmossdk.io/math"
"github.com/initia-labs/initia/x/move/types"
vmtypes "github.com/initia-labs/initiavm/types"
"github.com/novifinancial/serde-reflection/serde-generate/runtime/golang/bcs"
"github.com/novifinancial/serde-reflection/serde-generate/runtime/golang/serde"
flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -66,36 +65,55 @@ func asciiDecodeString(s string) ([]byte, error) {

func BcsSerializeArg(argType string, arg string, s serde.Serializer) ([]byte, error) {
if arg == "" {
return vmtypes.SerializeBytes([]byte(arg))
err := s.SerializeBytes([]byte(arg))
return s.GetBytes(), err
}
switch argType {
case "raw_hex":
decoded, err := hex.DecodeString(arg)
if err != nil {
return nil, err
}
return vmtypes.SerializeBytes(decoded)

err = s.SerializeBytes(decoded)
return s.GetBytes(), err
case "raw_base64":
decoded, err := base64.StdEncoding.DecodeString(arg)
if err != nil {
return nil, err
}
return vmtypes.SerializeBytes(decoded)

err = s.SerializeBytes(decoded)
return s.GetBytes(), err
case "address", "object":
accAddr, err := types.AccAddressFromString(arg)
if err != nil {
return nil, err
}
return accAddr.BcsSerialize()

err = s.IncreaseContainerDepth()
if err != nil {
return nil, err
}
for _, item := range accAddr {
if err := s.SerializeU8(item); err != nil {
return nil, err
}
}
s.DecreaseContainerDepth()

return s.GetBytes(), nil
case "string":
return vmtypes.SerializeString(arg)
err := s.SerializeBytes([]byte(arg))
return s.GetBytes(), err

case "bool":
if arg == "true" || arg == "True" {
return vmtypes.SerializeBool(true)
err := s.SerializeBool(true)
return s.GetBytes(), err
} else if arg == "false" || arg == "False" {
return vmtypes.SerializeBool(false)
err := s.SerializeBool(false)
return s.GetBytes(), err
} else {
return nil, errors.New("unsupported bool value")
}
Expand Down

0 comments on commit 0065dc7

Please sign in to comment.