From 945f2ca47c84fbce7e7543016dc3f7122026dcaa Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Thu, 12 Mar 2020 19:52:38 +0000 Subject: [PATCH] Add slot/epoch option for chain status --- README.md | 2 +- cmd/chainstatus.go | 48 +++++++++++++++++++++++++++++++++------------- cmd/version.go | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1d258d7..ff464ad 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A command-line tool for managing common tasks in Ethereum 2. `ethdo` is a standard Go program which can be installed with: ```sh -GO111MODULE=on go get github.com/wealdtech/ethdo@v1.2.3 +GO111MODULE=on go get github.com/wealdtech/ethdo ``` ## Usage diff --git a/cmd/chainstatus.go b/cmd/chainstatus.go index ae0f166..8ba6c87 100644 --- a/cmd/chainstatus.go +++ b/cmd/chainstatus.go @@ -22,6 +22,8 @@ import ( "github.com/wealdtech/ethdo/grpc" ) +var chainStatusSlot bool + var chainStatusCmd = &cobra.Command{ Use: "status", Short: "Obtain status about a chain", @@ -47,20 +49,38 @@ In quiet mode this will return 0 if the chain status can be obtained, otherwise } slot := timestampToSlot(genesisTime.Unix(), time.Now().Unix(), config["SecondsPerSlot"].(uint64)) - fmt.Printf("Current slot:\t\t%d\n", slot) - fmt.Printf("Finalized slot:\t\t%d", info.GetFinalizedSlot()) - if verbose { - distance := slot - info.GetFinalizedSlot() - fmt.Printf(" (%d)", distance) + if chainStatusSlot { + fmt.Printf("Current slot:\t\t%d\n", slot) + fmt.Printf("Justified slot:\t\t%d", info.GetJustifiedSlot()) + if verbose { + distance := slot - info.GetJustifiedSlot() + fmt.Printf(" (%d)", distance) + } + fmt.Printf("\n") + fmt.Printf("Finalized slot:\t\t%d", info.GetFinalizedSlot()) + if verbose { + distance := slot - info.GetFinalizedSlot() + fmt.Printf(" (%d)", distance) + } + fmt.Printf("\n") + outputIf(verbose, fmt.Sprintf("Prior justified slot:\t%v (%d)", info.GetPreviousJustifiedSlot(), slot-info.GetPreviousJustifiedSlot())) + } else { + slotsPerEpoch := config["SlotsPerEpoch"].(uint64) + fmt.Printf("Current epoch:\t\t%d\n", slot/slotsPerEpoch) + fmt.Printf("Justified epoch:\t%d", info.GetJustifiedSlot()/slotsPerEpoch) + if verbose { + distance := (slot - info.GetJustifiedSlot()) / slotsPerEpoch + fmt.Printf(" (%d)", distance) + } + fmt.Printf("\n") + fmt.Printf("Finalized epoch:\t%d", info.GetFinalizedSlot()/slotsPerEpoch) + if verbose { + distance := (slot - info.GetFinalizedSlot()) / slotsPerEpoch + fmt.Printf(" (%d)", distance) + } + fmt.Printf("\n") + outputIf(verbose, fmt.Sprintf("Prior justified epoch:\t%v (%d)", info.GetPreviousJustifiedSlot()/slotsPerEpoch, (slot-info.GetPreviousJustifiedSlot())/slotsPerEpoch)) } - fmt.Printf("\n") - fmt.Printf("Justified slot:\t\t%d", info.GetJustifiedSlot()) - if verbose { - distance := slot - info.GetJustifiedSlot() - fmt.Printf(" (%d)", distance) - } - fmt.Printf("\n") - outputIf(verbose, fmt.Sprintf("Prior justified slot:\t%v (%d)", info.GetPreviousJustifiedSlot(), slot-info.GetPreviousJustifiedSlot())) os.Exit(_exit_success) }, @@ -69,4 +89,6 @@ In quiet mode this will return 0 if the chain status can be obtained, otherwise func init() { chainCmd.AddCommand(chainStatusCmd) chainFlags(chainStatusCmd) + chainStatusCmd.Flags().BoolVar(&chainStatusSlot, "slot", false, "Print slot-based values") + } diff --git a/cmd/version.go b/cmd/version.go index f1fedb5..be6504e 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{ ethdo version.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("1.2.4") + fmt.Println("1.2.5") if viper.GetBool("verbose") { buildInfo, ok := dbg.ReadBuildInfo() if ok {