Pretty print Vote, VoteSet

This commit is contained in:
omni
2014-10-15 20:15:38 -07:00
parent 18fc7aec73
commit c5d9a93cbe
6 changed files with 114 additions and 12 deletions
+18
View File
@@ -2,6 +2,7 @@ package blocks
import (
"errors"
"fmt"
"io"
. "github.com/tendermint/tendermint/binary"
@@ -56,3 +57,20 @@ func (v *Vote) GetSignature() Signature {
func (v *Vote) SetSignature(sig Signature) {
v.Signature = sig
}
func (v *Vote) String() string {
blockHash := v.BlockHash
if len(v.BlockHash) == 0 {
blockHash = make([]byte, 6) // for printing
}
switch v.Type {
case VoteTypeBare:
return fmt.Sprintf("Vote{%v/%v:%X:%v}", v.Height, v.Round, blockHash, v.SignerId)
case VoteTypePrecommit:
return fmt.Sprintf("Precommit{%v/%v:%X:%v}", v.Height, v.Round, blockHash, v.SignerId)
case VoteTypeCommit:
return fmt.Sprintf("Commit{%v/%v:%X:%v}", v.Height, v.Round, v.BlockHash[:6], v.SignerId)
default:
panic("Unknown vote type")
}
}