diff --git a/bfa_client/src/client/bfa_client.go b/bfa_client/src/client/bfa_client.go index 7bce3f4fd8e18e5440188acc60b561f30dd25518..1eb16668a7fa07103fb533efd7e1d0cf7e9ab35f 100644 --- a/bfa_client/src/client/bfa_client.go +++ b/bfa_client/src/client/bfa_client.go @@ -180,10 +180,11 @@ func printSealers(sealers []string) { } } -func weiTo(wei *big.Float, unit string) (value *big.Float, ok bool) { +func weiTo(wei *big.Int, unit string) (value *big.Float, ok bool) { divisor, ok := units[unit] if ok { - value = wei.Quo(wei, divisor) + w := new(big.Float).SetInt(wei) + value = w.Quo(w, divisor) } return } @@ -198,6 +199,7 @@ func sealers() { header bool format string formatStr string + headerFmt string unit string list []string lastBlockLen int64 @@ -281,22 +283,20 @@ func sealers() { if difficulty { formatStr += " %2[6]v" } + headerFmt = formatStr if balance { - formatStr += " %[7]*[8]v" - balanceLen = 0 - for _, s := range sealers { - f := new(big.Float).SetInt(s.Balance) - b, _ := weiTo(f, unit) - balanceLen = util.Max(balanceLen, int64(len(fmt.Sprintf("%v", b)))) - } + formatStr += " %#12.6[8]e" + headerFmt += " %[7]*[8]v" + balanceLen = 12 } if header { - fmt.Printf(formatStr, + headerFmt += "\n" + fmt.Printf(headerFmt, fmt.Sprintf("%-24v", "Sealer"), lastBlockLen, fmt.Sprintf("%*v", -lastBlockLen/2-2, "Last"), timestampLen, fmt.Sprintf("%*v", -timestampLen/2-2, "Time"), "Dif", - balanceLen, fmt.Sprintf("%*v", -balanceLen/2-4, "Balance")) + balanceLen, fmt.Sprintf("%*v", -(int(balanceLen)+len(unit))/2-1, strings.Title(unit))) } } formatStr += "\n" @@ -309,8 +309,7 @@ func sealers() { if len(format) > 0 && t > 0 { formatedTimestamp = time.Unix(t, 0).Format(format) } - b := new(big.Float).SetInt(s.Balance) - convertedBalance, _ := weiTo(b, unit) + convertedBalance, _ := weiTo(s.Balance, unit) fmt.Printf(formatStr, sealer, lastBlockLen, s.LastBlock, timestampLen, formatedTimestamp, s.Difficulty, balanceLen, convertedBalance) } }