From e57473e2d238e9690ee3568b47cca6466e9040a9 Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Thu, 22 Sep 2022 23:43:15 +0000 Subject: [PATCH] add hardware args to cli lease creation [UNTESTED] --- proto/colinearcore/tx.proto | 1 - x/colinearcore/client/cli/tx_new_auction.go | 54 ++++++++++++++++++--- x/colinearcore/types/message_new_auction.go | 18 ++++++- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/proto/colinearcore/tx.proto b/proto/colinearcore/tx.proto index 0474177..de39fda 100644 --- a/proto/colinearcore/tx.proto +++ b/proto/colinearcore/tx.proto @@ -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; diff --git a/x/colinearcore/client/cli/tx_new_auction.go b/x/colinearcore/client/cli/tx_new_auction.go index b1a26b3..9d77e76 100644 --- a/x/colinearcore/client/cli/tx_new_auction.go +++ b/x/colinearcore/client/cli/tx_new_auction.go @@ -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 diff --git a/x/colinearcore/types/message_new_auction.go b/x/colinearcore/types/message_new_auction.go index 0a38f98..f3a0af8 100644 --- a/x/colinearcore/types/message_new_auction.go +++ b/x/colinearcore/types/message_new_auction.go @@ -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, } }