package cli import ( "encoding/json" "strconv" "colinear/x/colinearcore/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/spf13/cobra" ) var _ = strconv.Itoa(0) func CmdNewAuction() *cobra.Command { cmd := &cobra.Command{ Use: "new-auction [name] [description] [ceiling] [denom] [end date] [verified providers (json string)] [gpus (json string)] [cpu cores] [cpu arch] [memory (MB)] [storage (GB)]", Short: "Broadcast message newAuction", Args: cobra.ExactArgs(11), // below: we're hardcoding the max providers param since we // can't check chain params locally // Args: cobra.RangeArgs(10, 1010), RunE: func(cmd *cobra.Command, args []string) (err error) { argName := args[0] argDescription := args[1] argCeiling := args[2] argDenom := args[3] argLeaseEnd := args[4] vProvString := args[5] gpusString := args[6] cpuCores := args[7] cpuArch := args[8] memMb := args[9] storageGb := args[10] verifiedProviders := []string{} gpuModels := []string{} clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } // try to marshal JSON lists if err := json.Unmarshal([]byte(vProvString), &verifiedProviders); err != nil { return err } if err := json.Unmarshal([]byte(gpusString), &gpuModels); err != nil { return err } // try to parse int strings var le int le, err = strconv.Atoi(argLeaseEnd) if err != nil { return err } nCpuCores, err := strconv.Atoi(cpuCores) if err != nil { return err } nCpuArch, err := strconv.Atoi(cpuArch) if err != nil { return err } nMemMb, err := strconv.Atoi(memMb) if err != nil { return err } nStorageGb, err := strconv.Atoi(storageGb) if err != nil { return err } msg := types.NewMsgNewAuction( clientCtx.GetFromAddress().String(), argName, argDescription, argCeiling, argDenom, uint64(le), verifiedProviders, gpuModels, uint64(nCpuCores), types.CpuArchitecture(nCpuArch), uint64(nMemMb), uint64(nStorageGb), ) if err := msg.ValidateBasic(); err != nil { return err } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } flags.AddTxFlagsToCmd(cmd) return cmd }