Add chain status

This commit is contained in:
Jim McDonald
2020-03-12 15:32:01 +00:00
parent 6786742004
commit b61eaefb0d
4 changed files with 85 additions and 7 deletions

View File

@@ -43,13 +43,10 @@ In quiet mode this will return 0 if the chain information can be obtained, other
os.Exit(_exit_success)
}
for k, v := range config {
fmt.Printf("%v => %v\n", k, v)
}
fmt.Printf("Genesis time:\t\t%s\n", genesisTime.Format(time.UnixDate))
slot := timestampToSlot(genesisTime.Unix(), time.Now().Unix(), config["SecondsPerSlot"].(uint64))
fmt.Printf("Current slot:\t\t%d\n", slot)
fmt.Printf("Current epoch:\t\t%d\n", slot/int64(config["SlotsPerEpoch"].(uint64)))
fmt.Printf("Current epoch:\t\t%d\n", slot/config["SlotsPerEpoch"].(uint64))
outputIf(verbose, fmt.Sprintf("Genesis fork version:\t%0x", config["GenesisForkVersion"].([]byte)))
outputIf(verbose, fmt.Sprintf("Genesis timestamp:\t%v", genesisTime.Unix()))
outputIf(verbose, fmt.Sprintf("Seconds per slot:\t%v", config["SecondsPerSlot"].(uint64)))
@@ -64,9 +61,9 @@ func init() {
chainFlags(chainInfoCmd)
}
func timestampToSlot(genesis int64, timestamp int64, secondsPerSlot uint64) int64 {
func timestampToSlot(genesis int64, timestamp int64, secondsPerSlot uint64) uint64 {
if timestamp < genesis {
return 0
}
return (timestamp - genesis) / int64(secondsPerSlot)
return uint64(timestamp-genesis) / secondsPerSlot
}