2022-08-27 14:19:03 -07:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2022-09-22 16:43:15 -07:00
|
|
|
"encoding/json"
|
2022-08-27 14:19:03 -07:00
|
|
|
"strconv"
|
|
|
|
|
2022-09-06 15:18:09 -07:00
|
|
|
"colinear/x/colinearcore/types"
|
2022-08-31 21:49:24 -07:00
|
|
|
|
2022-08-27 14:19:03 -07:00
|
|
|
"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{
|
2022-09-22 16:43:15 -07:00
|
|
|
Use: "new-auction [name] [description] [ceiling] [denom] [end date] [verified providers (json string)] [gpus (json string)] [cpu cores] [cpu arch] [memory (MB)] [storage (GB)]",
|
2022-08-27 14:19:03 -07:00
|
|
|
Short: "Broadcast message newAuction",
|
2022-09-22 16:59:03 -07:00
|
|
|
Args: cobra.ExactArgs(11),
|
2022-09-21 17:16:09 -07:00
|
|
|
// below: we're hardcoding the max providers param since we
|
|
|
|
// can't check chain params locally
|
2022-09-22 16:43:15 -07:00
|
|
|
// Args: cobra.RangeArgs(10, 1010),
|
2022-08-27 14:19:03 -07:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
2022-08-31 21:49:24 -07:00
|
|
|
argName := args[0]
|
|
|
|
argDescription := args[1]
|
2022-09-02 14:58:22 -07:00
|
|
|
argCeiling := args[2]
|
|
|
|
argDenom := args[3]
|
|
|
|
argLeaseEnd := args[4]
|
2022-08-27 14:19:03 -07:00
|
|
|
|
2022-09-22 16:43:15 -07:00
|
|
|
vProvString := args[5]
|
|
|
|
gpusString := args[6]
|
|
|
|
cpuCores := args[7]
|
|
|
|
cpuArch := args[8]
|
|
|
|
memMb := args[9]
|
|
|
|
storageGb := args[10]
|
|
|
|
|
2022-09-13 15:58:07 -07:00
|
|
|
verifiedProviders := []string{}
|
2022-09-22 16:43:15 -07:00
|
|
|
gpuModels := []string{}
|
2022-09-13 15:58:07 -07:00
|
|
|
|
2022-08-27 14:19:03 -07:00
|
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-22 16:43:15 -07:00
|
|
|
// 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
|
|
|
|
|
2022-09-02 14:58:22 -07:00
|
|
|
var le int
|
|
|
|
le, err = strconv.Atoi(argLeaseEnd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-22 16:43:15 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-08-27 14:19:03 -07:00
|
|
|
msg := types.NewMsgNewAuction(
|
|
|
|
clientCtx.GetFromAddress().String(),
|
|
|
|
argName,
|
|
|
|
argDescription,
|
2022-09-02 14:58:22 -07:00
|
|
|
argCeiling,
|
2022-08-31 21:49:24 -07:00
|
|
|
argDenom,
|
2022-09-02 14:58:22 -07:00
|
|
|
uint64(le),
|
2022-09-13 15:58:07 -07:00
|
|
|
verifiedProviders,
|
2022-09-22 16:43:15 -07:00
|
|
|
gpuModels,
|
|
|
|
uint64(nCpuCores),
|
|
|
|
types.CpuArchitecture(nCpuArch),
|
|
|
|
uint64(nMemMb),
|
|
|
|
uint64(nStorageGb),
|
2022-08-27 14:19:03 -07:00
|
|
|
)
|
|
|
|
if err := msg.ValidateBasic(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|