Browse Source

types: fix formatting when printing signatures

- use cmn.Fingerprint and %X
pull/2152/head
Ethan Buchman 6 years ago
parent
commit
309a6772d7
3 changed files with 17 additions and 13 deletions
  1. +5
    -2
      types/proposal.go
  2. +1
    -1
      types/proposal_test.go
  3. +11
    -10
      types/vote.go

+ 5
- 2
types/proposal.go View File

@ -4,6 +4,8 @@ import (
"errors"
"fmt"
"time"
cmn "github.com/tendermint/tendermint/libs/common"
)
var (
@ -41,9 +43,10 @@ func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRou
// String returns a string representation of the Proposal.
func (p *Proposal) String() string {
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v @ %s}",
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %X @ %s}",
p.Height, p.Round, p.BlockPartsHeader, p.POLRound,
p.POLBlockID, p.Signature, CanonicalTime(p.Timestamp))
p.POLBlockID,
cmn.Fingerprint(p.Signature), CanonicalTime(p.Timestamp))
}
// SignBytes returns the Proposal bytes for signing


+ 1
- 1
types/proposal_test.go View File

@ -39,7 +39,7 @@ func TestProposalSignable(t *testing.T) {
func TestProposalString(t *testing.T) {
str := testProposal.String()
expected := `Proposal{12345/23456 111:626C6F636B70 (-1,:0:000000000000) [] @ 2018-02-11T07:09:22.765Z}`
expected := `Proposal{12345/23456 111:626C6F636B70 (-1,:0:000000000000) 000000000000 @ 2018-02-11T07:09:22.765Z}`
if str != expected {
t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str)
}


+ 11
- 10
types/vote.go View File

@ -61,14 +61,14 @@ type Address = cmn.HexBytes
// Represents a prevote, precommit, or commit vote from validators for consensus.
type Vote struct {
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"`
Round int `json:"round"`
Timestamp time.Time `json:"timestamp"`
Type byte `json:"type"`
BlockID BlockID `json:"block_id"` // zero if vote is nil.
Signature []byte `json:"signature"`
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"`
Round int `json:"round"`
Timestamp time.Time `json:"timestamp"`
Type byte `json:"type"`
BlockID BlockID `json:"block_id"` // zero if vote is nil.
Signature []byte `json:"signature"`
}
func (vote *Vote) SignBytes(chainID string) []byte {
@ -98,10 +98,11 @@ func (vote *Vote) String() string {
cmn.PanicSanity("Unknown vote type")
}
return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %v @ %s}",
return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}",
vote.ValidatorIndex, cmn.Fingerprint(vote.ValidatorAddress),
vote.Height, vote.Round, vote.Type, typeString,
cmn.Fingerprint(vote.BlockID.Hash), vote.Signature,
cmn.Fingerprint(vote.BlockID.Hash),
cmn.Fingerprint(vote.Signature),
CanonicalTime(vote.Timestamp))
}


Loading…
Cancel
Save