From bfb65806a706faf0e2a2e570567ad9b2b13602f6 Mon Sep 17 00:00:00 2001 From: rezoan Date: Mon, 10 Oct 2022 02:21:27 +0600 Subject: [PATCH] Added validator option in sp-info --- cmd/stakepool.go | 46 ++++++++++++++++++++++++++-------------------- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/cmd/stakepool.go b/cmd/stakepool.go index e24510c8..60200066 100644 --- a/cmd/stakepool.go +++ b/cmd/stakepool.go @@ -12,17 +12,11 @@ import ( ) func printStakePoolInfo(info *sdk.StakePoolInfo) { - fmt.Println("blobber_id: ", info.ID) - fmt.Println("total stake: ", info.Balance) - fmt.Println("going to unlock, total:", info.UnstakeTotal) - - fmt.Println("capacity:") - fmt.Println(" capacity: ", info.Capacity, "(blobber bid)") - fmt.Println(" free: ", info.Free, "(for current write price)") - fmt.Println(" write_price: ", info.WritePrice, "(blobber write price)") - fmt.Println(" offers_total: ", info.OffersTotal, "(total stake committed to offers)") - fmt.Println(" unstake_total: ", info.UnstakeTotal, "(total stake not available for further commitments)") - fmt.Println(" unclaimed rewards:", info.Rewards) + fmt.Println("pool id: ", info.ID) + fmt.Println("balance: ", info.Balance) + fmt.Println("total stake: ", info.StakeTotal) + fmt.Println("total unstake: ", info.UnstakeTotal, "(total stake not available for further commitments)") + fmt.Println("unclaimed rewards: ", info.Rewards) if len(info.Delegate) == 0 { fmt.Println("delegate_pools: no delegate pools") } else { @@ -78,24 +72,34 @@ var spInfo = &cobra.Command{ Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { var ( - flags = cmd.Flags() - blobberID string - err error + flags = cmd.Flags() + err error + providerID string + providerType sdk.ProviderType ) doJSON, _ := cmd.Flags().GetBool("json") - if !flags.Changed("blobber_id") { - log.Fatalf("Error: blobber_id flag is missing") + if flags.Changed("blobber_id") { + if providerID, err = flags.GetString("blobber_id"); err != nil { + log.Fatalf("Error: cannot get the value of blobber_id") + } else { + providerType = sdk.ProviderBlobber + } + } else if flags.Changed("validator_id") { + if providerID, err = flags.GetString("validator_id"); err != nil { + log.Fatalf("Error: cannot get the value of validator_id") + } else { + providerType = sdk.ProviderValidator + } } - blobberID, err = flags.GetString("blobber_id") - if err != nil { - log.Fatalf("Error: cannot get the value of blobber_id") + if providerType == 0 || providerID == "" { + log.Fatal("Error: missing flag: one of 'blobber_id' or 'validator_id' is required") } var info *sdk.StakePoolInfo - if info, err = sdk.GetStakePoolInfo(blobberID); err != nil { + if info, err = sdk.GetStakePoolInfo(providerType, providerID); err != nil { log.Fatalf("Failed to get stake pool info: %v", err) } if doJSON { @@ -271,6 +275,8 @@ func init() { spInfo.PersistentFlags().String("blobber_id", "", "for given blobber") + spInfo.PersistentFlags().String("validator_id", "", + "for given validator") spInfo.PersistentFlags().Bool("json", false, "pass this option to print response as json data") spUserInfo.PersistentFlags().Bool("json", false, "pass this option to print response as json data") diff --git a/go.mod b/go.mod index ff4332eb..f72f99e1 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/0chain/errors v1.0.3 - github.com/0chain/gosdk v1.8.10-0.20221026040749-2a049c31338c + github.com/0chain/gosdk v1.8.10-0.20221104131111-f58e516459c6 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.6.0 diff --git a/go.sum b/go.sum index 96cbc412..afb5ac84 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.8.10-0.20221026040749-2a049c31338c h1:BHd5d82pLzDceU5JjAu0dccaV/l1BSIqnJ4QErFedqo= -github.com/0chain/gosdk v1.8.10-0.20221026040749-2a049c31338c/go.mod h1:sxM3NRQLwMWAzXKsKThR03lxHq03rtIMRODM/fdsZ3E= +github.com/0chain/gosdk v1.8.10-0.20221104131111-f58e516459c6 h1:Di735e3z0KVeNNFQPytusnF/XMwCzy0upv5++wLH+zo= +github.com/0chain/gosdk v1.8.10-0.20221104131111-f58e516459c6/go.mod h1:sxM3NRQLwMWAzXKsKThR03lxHq03rtIMRODM/fdsZ3E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o=