Skip to content
Snippets Groups Projects
Commit c0e78cb1 authored by Miguel Montes's avatar Miguel Montes
Browse files

Corrección del formateo del balance

parent 879bc601
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment