Skip to content

Commit

Permalink
Added validator option in sp-info
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrz1 committed Nov 5, 2022
1 parent ba1b1c0 commit fc559d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
46 changes: 26 additions & 20 deletions cmd/stakepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions cmd/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func printValidators(nodes []*sdk.Validator) {
fmt.Println(" delegate_wallet:", validator.DelegateWallet)
fmt.Println(" min_stake: ", validator.MinStake)
fmt.Println(" max_stake: ", validator.MaxStake)
fmt.Println(" total_stake: ", validator.StakeTotal)
fmt.Println(" total_unstake: ", validator.UnstakeTotal)
fmt.Println(" num_delegates: ", validator.NumDelegates)
fmt.Println(" service_charge: ", validator.ServiceCharge*100, "%")
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.8.10-0.20221103163801-bf2f06602ff1
github.com/0chain/gosdk v1.8.10-0.20221104200645-a31093ce5329
github.com/icza/bitio v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20221103163801-bf2f06602ff1 h1:VJhXhHG85vhDi00n+aZKRGOH+mKbGPhc0pingznpMFw=
github.com/0chain/gosdk v1.8.10-0.20221103163801-bf2f06602ff1/go.mod h1:sxM3NRQLwMWAzXKsKThR03lxHq03rtIMRODM/fdsZ3E=
github.com/0chain/gosdk v1.8.10-0.20221104200645-a31093ce5329 h1:1mSj+6/98kYb6PNDBxEOpG4eX7XQ2N2mtCj6WC5UyXI=
github.com/0chain/gosdk v1.8.10-0.20221104200645-a31093ce5329/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=
Expand Down

0 comments on commit fc559d1

Please sign in to comment.