Skip to content

Commit

Permalink
Merge pull request #23 from initia-labs/fix/cli-move-view
Browse files Browse the repository at this point in the history
fix: view function
  • Loading branch information
beer-1 authored Nov 30, 2023
2 parents 397cc8b + d47ae48 commit c82131d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
22 changes: 11 additions & 11 deletions x/move/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,18 @@ func GetCmdTableEntries() *cobra.Command {
func GetCmdQueryEntryFunction() *cobra.Command {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
cmd := &cobra.Command{
Use: "execute [module owner] [module name] [function name]",
Short: "Get entry function execution result",
Use: "view [module owner] [module name] [function name]",
Short: "Get view function execution result",
Long: strings.TrimSpace(
fmt.Sprintf(`
Get an entry function execution result
Supported types : u8, u16, u32, u64, u128, u256, bool, string, address, raw, vector<inner_type>
Get an view function execution result
Supported types : u8, u16, u32, u64, u128, u256, bool, string, address, raw_hex, raw_base64,
vector<inner_type>, option<inner_type>, decimal128, decimal256, fixed_point32, fixed_point64
Example of args: address:0x1 bool:true u8:0 string:hello vector<u32>:a,b,c,d
Example:
$ %s query move execute \
$ %s query move view \
%s1lwjmdnks33xwnmfayc64ycprww49n33mtm92ne \
BasicCoin \
getBalance \
Expand Down Expand Up @@ -320,15 +320,15 @@ $ %s query move execute \
return err
}

argTypes, args := parseArguments(flagArgs)
if len(argTypes) != len(args) {
moveArgTypes, moveArgs := parseArguments(flagArgs)
if len(moveArgTypes) != len(moveArgs) {
return fmt.Errorf("invalid argument format len(types) != len(args)")
}

serializer := NewSerializer()
bcsArgs := [][]byte{}
for i := range argTypes {
bcsArg, err := BcsSerializeArg(argTypes[i], args[i], serializer)
for i := range moveArgTypes {
serializer := NewSerializer()
bcsArg, err := BcsSerializeArg(moveArgTypes[i], moveArgs[i], serializer)
if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion x/move/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ func BcsSerializeArg(argType string, arg string, s serde.Serializer) ([]byte, er
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":
if err := s.SerializeStr(arg); err != nil {
Expand Down

0 comments on commit c82131d

Please sign in to comment.