From 2dce41ad6a517548f2b7fc44c191df18b11c2e67 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 23 Nov 2016 18:22:44 -0500 Subject: [PATCH] types: pretty print validators --- types/validators.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/types/validators.go b/types/validators.go index 6494394ee..185355d15 100644 --- a/types/validators.go +++ b/types/validators.go @@ -2,6 +2,8 @@ package types import ( "bytes" + + "github.com/tendermint/go-wire" ) // validators implements sort @@ -22,3 +24,18 @@ func (v Validators) Swap(i, j int) { v[i] = v[j] v[j] = v1 } + +//------------------------------------- + +type validatorPretty struct { + PubKey []byte `json:"pub_key"` + Power uint64 `json:"power"` +} + +func ValidatorsString(vs Validators) string { + s := make([]validatorPretty, len(vs)) + for i, v := range vs { + s[i] = validatorPretty{v.PubKey, v.Power} + } + return string(wire.JSONBytes(s)) +}