Browse Source

use MarshalJSONIndent for init files. closes #1506

pull/1510/head
Ethan Buchman 6 years ago
parent
commit
94c016a04e
5 changed files with 14 additions and 9 deletions
  1. +2
    -1
      consensus/replay_file.go
  2. +6
    -5
      consensus/types/state.go
  3. +1
    -1
      types/genesis.go
  4. +1
    -1
      types/priv_validator/priv_validator.go
  5. +4
    -1
      types/validator_set.go

+ 2
- 1
consensus/replay_file.go View File

@ -29,6 +29,7 @@ const (
//--------------------------------------------------------
// replay messages interactively or all at once
// replay the wal file
func RunReplayFile(config cfg.BaseConfig, csConfig *cfg.ConsensusConfig, console bool) {
consensusState := newConsensusStateForReplay(config, csConfig)
@ -262,7 +263,7 @@ func (pb *playback) replayConsoleLoop() int {
case "locked_block":
fmt.Printf("%v %v\n", rs.LockedBlockParts.StringShort(), rs.LockedBlock.StringShort())
case "votes":
fmt.Println(rs.Votes.StringIndented(" "))
fmt.Println(rs.Votes.StringIndented(" "))
default:
fmt.Println("Unknown option", tokens[1])


+ 6
- 5
consensus/types/state.go View File

@ -13,6 +13,7 @@ import (
// RoundStepType enumerates the state of the consensus state machine
type RoundStepType uint8 // These must be numeric, ordered.
// RoundStepType
const (
RoundStepNewHeight = RoundStepType(0x01) // Wait til CommitTime + timeoutCommit
RoundStepNewRound = RoundStepType(0x02) // Setup new round and go to RoundStepPropose
@ -80,12 +81,12 @@ type RoundState struct {
func (rs *RoundState) RoundStateEvent() types.EventDataRoundState {
// XXX: copy the RoundState
// if we want to avoid this, we may need synchronous events after all
rs_ := *rs
rsCopy := *rs
edrs := types.EventDataRoundState{
Height: rs.Height,
Round: rs.Round,
Step: rs.Step.String(),
RoundState: &rs_,
RoundState: &rsCopy,
}
return edrs
}
@ -115,16 +116,16 @@ func (rs *RoundState) StringIndented(indent string) string {
indent, rs.Height, rs.Round, rs.Step,
indent, rs.StartTime,
indent, rs.CommitTime,
indent, rs.Validators.StringIndented(indent+" "),
indent, rs.Validators.StringIndented(indent+" "),
indent, rs.Proposal,
indent, rs.ProposalBlockParts.StringShort(), rs.ProposalBlock.StringShort(),
indent, rs.LockedRound,
indent, rs.LockedBlockParts.StringShort(), rs.LockedBlock.StringShort(),
indent, rs.ValidRound,
indent, rs.ValidBlockParts.StringShort(), rs.ValidBlock.StringShort(),
indent, rs.Votes.StringIndented(indent+" "),
indent, rs.Votes.StringIndented(indent+" "),
indent, rs.LastCommit.StringShort(),
indent, rs.LastValidators.StringIndented(indent+" "),
indent, rs.LastValidators.StringIndented(indent+" "),
indent)
}


+ 1
- 1
types/genesis.go View File

@ -41,7 +41,7 @@ func (genDoc *GenesisDoc) AppState() json.RawMessage {
// SaveAs is a utility method for saving GenensisDoc as a JSON file.
func (genDoc *GenesisDoc) SaveAs(file string) error {
genDocBytes, err := cdc.MarshalJSON(genDoc)
genDocBytes, err := cdc.MarshalJSONIndent(genDoc, "", " ")
if err != nil {
return err
}


+ 1
- 1
types/priv_validator/priv_validator.go View File

@ -120,7 +120,7 @@ func (pv *FilePV) save() {
if outFile == "" {
panic("Cannot save PrivValidator: filePath not set")
}
jsonBytes, err := cdc.MarshalJSON(pv)
jsonBytes, err := cdc.MarshalJSONIndent(pv, "", " ")
if err != nil {
panic(err)
}


+ 4
- 1
types/validator_set.go View File

@ -69,6 +69,7 @@ func (valSet *ValidatorSet) IncrementAccum(times int) {
}
}
// Copy each validator into a new ValidatorSet
func (valSet *ValidatorSet) Copy() *ValidatorSet {
validators := make([]*Validator, len(valSet.Validators))
for i, val := range valSet.Validators {
@ -368,6 +369,7 @@ func (valSet *ValidatorSet) String() string {
return valSet.StringIndented("")
}
// String
func (valSet *ValidatorSet) StringIndented(indent string) string {
if valSet == nil {
return "nil-ValidatorSet"
@ -384,7 +386,7 @@ func (valSet *ValidatorSet) StringIndented(indent string) string {
%s}`,
indent, valSet.GetProposer().String(),
indent,
indent, strings.Join(valStrings, "\n"+indent+" "),
indent, strings.Join(valStrings, "\n"+indent+" "),
indent)
}
@ -392,6 +394,7 @@ func (valSet *ValidatorSet) StringIndented(indent string) string {
//-------------------------------------
// Implements sort for sorting validators by address.
// Sort validators by address
type ValidatorsByAddress []*Validator
func (vs ValidatorsByAddress) Len() int {


Loading…
Cancel
Save