gitlab.com/SkynetLabs/skyd@v1.6.9/cmd/skyc/consensuscmd.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/spf13/cobra" 8 9 "gitlab.com/NebulousLabs/errors" 10 "gitlab.com/SkynetLabs/skyd/node/api" 11 ) 12 13 var ( 14 consensusCmd = &cobra.Command{ 15 Use: "consensus", 16 Short: "Print the current state of consensus", 17 Long: "Print the current state of consensus such as current block, block height, and target.", 18 Run: wrap(consensuscmd), 19 } 20 ) 21 22 // consensuscmd is the handler for the command `skyc consensus`. 23 // Prints the current state of consensus. 24 func consensuscmd() { 25 cg, err := httpClient.ConsensusGet() 26 if errors.Contains(err, api.ErrAPICallNotRecognized) { 27 // Assume module is not loaded if status command is not recognized. 28 fmt.Printf("Consensus:\n Status: %s\n\n", moduleNotReadyStatus) 29 return 30 } else if err != nil { 31 die("Could not get current consensus state:", err) 32 } 33 34 if cg.Synced { 35 fmt.Printf(`Synced: %v 36 Block: %v 37 Height: %v 38 Target: %v 39 Difficulty: %v 40 `, yesNo(cg.Synced), cg.CurrentBlock, cg.Height, cg.Target, cg.Difficulty) 41 } else { 42 estimatedHeight := estimatedHeightAt(time.Now(), cg) 43 estimatedProgress := float64(cg.Height) / float64(estimatedHeight) * 100 44 if estimatedProgress > 100 { 45 estimatedProgress = 99.9 46 } 47 if estimatedProgress == 100 && !cg.Synced { 48 estimatedProgress = 99.9 49 } 50 fmt.Printf(`Synced: %v 51 Height: %v 52 Progress (estimated): %.1f%% 53 `, yesNo(cg.Synced), cg.Height, estimatedProgress) 54 } 55 if verbose { 56 fmt.Println() 57 fmt.Println("Block Frequency:", cg.BlockFrequency) 58 fmt.Println("Block Size Limit:", cg.BlockSizeLimit) 59 fmt.Println("Maturity Delay:", cg.MaturityDelay) 60 fmt.Println("Genesis Timestamp:", time.Unix(int64(cg.GenesisTimestamp), 0)) 61 } 62 }