add hardware args to cli lease creation

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

View File

@ -28,7 +28,6 @@ message MsgNewAuction {
// verified providers just specifies who's allowed to bid on the lease auction.
// STORED IN MEMORY. DOES NOT GET WRITTEN TO CHAIN STATE.
repeated string verifiedProviders = 7;
// hardware specs (mandatory)
repeated string gpus = 8;
uint64 cpuCores = 9;

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

View File

@ -9,15 +9,29 @@ const TypeMsgNewAuction = "new_auction"
var _ sdk.Msg = &MsgNewAuction{}
func NewMsgNewAuction(creator string, name string, description string, ceiling string, denom string, leaseEnd uint64, vProviders []string) *MsgNewAuction {
func NewMsgNewAuction(
// auction params
creator string, name string, description string, ceiling string, denom string, leaseEnd uint64, vProviders []string,
// hardware specs
gpus []string, cpuCores uint64, cpuArch CpuArchitecture, memMb uint64, storageGb uint64,
) *MsgNewAuction {
return &MsgNewAuction{
Creator: creator,
Creator: creator,
// creation params
Name: name,
Description: description,
Ceiling: ceiling,
Denom: denom,
LeaseEnd: leaseEnd,
VerifiedProviders: vProviders,
// hardware
Gpus: gpus,
CpuCores: cpuCores,
CpuArch: cpuArch,
MemMb: memMb,
StorageGb: storageGb,
}
}