func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) { roundState := consensusState.GetRoundState() peerRoundStates := []string{} for _, peer := range p2pSwitch.Peers().List() { // TODO: clean this up? peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState) peerRoundState := peerState.GetRoundState() peerRoundStateStr := peer.Key + ":" + string(binary.JSONBytes(peerRoundState)) peerRoundStates = append(peerRoundStates, peerRoundStateStr) } return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil }
// Get the current consensus state. func (this *consensus) State() (*ConsensusState, error) { roundState := this.consensusState.GetRoundState() peerRoundStates := []string{} for _, peer := range this.p2pSwitch.Peers().List() { // TODO: clean this up? peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState) peerRoundState := peerState.GetRoundState() peerRoundStateStr := peer.Key + ":" + string(binary.JSONBytes(peerRoundState)) peerRoundStates = append(peerRoundStates, peerRoundStateStr) } return FromRoundState(roundState), nil }
func (privVal *PrivValidator) save() { if privVal.filePath == "" { // SANITY CHECK panic("Cannot save PrivValidator: filePath not set") } jsonBytes := binary.JSONBytes(privVal) err := WriteFileAtomic(privVal.filePath, jsonBytes) if err != nil { // `@; BOOM!!! panic(err) } }
func (tx *BondTx) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) { binary.WriteTo([]byte(Fmt(`{"chain_id":%s`, jsonEscape(chainID))), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err) for i, in := range tx.Inputs { in.WriteSignBytes(w, n, err) if i != len(tx.Inputs)-1 { binary.WriteTo([]byte(","), w, n, err) } } binary.WriteTo([]byte(Fmt(`],"pub_key":`)), w, n, err) binary.WriteTo(binary.JSONBytes(tx.PubKey), w, n, err) binary.WriteTo([]byte(`,"unbond_to":[`), w, n, err) for i, out := range tx.UnbondTo { out.WriteSignBytes(w, n, err) if i != len(tx.UnbondTo)-1 { binary.WriteTo([]byte(","), w, n, err) } } binary.WriteTo([]byte(`]}]}`), w, n, err) }
// Encode to a byte array. func (this *TCodec) EncodeBytes(v interface{}) ([]byte, error) { return binary.JSONBytes(v), nil }