add hardware args to cli lease creation

[UNTESTED]
This commit is contained in:
2022-09-22 23:43:15 +00:00
parent f25f798443
commit e57473e2d2
3 changed files with 63 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package cli
import (
"encoding/json"
"strconv"
"colinear/x/colinearcore/types"
@@ -15,12 +16,12 @@ var _ = strconv.Itoa(0)
func CmdNewAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "new-auction [name] [description] [ceiling] [denom] [end date] [verified providers (separated by spaces)...]",
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(5),
Args: cobra.ExactArgs(10),
// below: we're hardcoding the max providers param since we
// can't check chain params locally
Args: cobra.RangeArgs(5, 1005),
// Args: cobra.RangeArgs(10, 1010),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argName := args[0]
argDescription := args[1]
@@ -28,23 +29,57 @@ func CmdNewAuction() *cobra.Command {
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{}
if len(args) >= 6 {
// set to remaining arguments
verifiedProviders = args[5:]
}
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,
@@ -53,6 +88,11 @@ func CmdNewAuction() *cobra.Command {
argDenom,
uint64(le),
verifiedProviders,
gpuModels,
uint64(nCpuCores),
types.CpuArchitecture(nCpuArch),
uint64(nMemMb),
uint64(nStorageGb),
)
if err := msg.ValidateBasic(); err != nil {
return err