Add slot/epoch option for chain status

This commit is contained in:
Jim McDonald
2020-03-12 19:52:38 +00:00
parent b61eaefb0d
commit 945f2ca47c
3 changed files with 37 additions and 15 deletions

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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 {