diff --git a/state/state.go b/state/state.go index 575a1630e..fb5d78c47 100644 --- a/state/state.go +++ b/state/state.go @@ -86,7 +86,11 @@ func (s State) Equals(s2 State) bool { // Bytes serializes the State using go-wire. func (s State) Bytes() []byte { - return wire.BinaryBytes(s) + bz, err := wire.MarshalBinary(s) + if err != nil { + panic(err) + } + return bz } // IsEmpty returns true if the State is equal to the empty State. diff --git a/state/store.go b/state/store.go index de2d4d67c..df07ec540 100644 --- a/state/store.go +++ b/state/store.go @@ -1,7 +1,6 @@ package state import ( - "bytes" "fmt" abci "github.com/tendermint/abci/types" @@ -70,12 +69,11 @@ func loadState(db dbm.DB, key []byte) (state State) { return state } - r, n, err := bytes.NewReader(buf), new(int), new(error) - wire.ReadBinaryPtr(&state, r, 0, n, err) - if *err != nil { + err := wire.UnmarshalBinary(buf, &state) + if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED cmn.Exit(cmn.Fmt(`LoadState: Data has been corrupted or its spec has changed: - %v\n`, *err)) + %v\n`, err)) } // TODO: ensure that buf is completely read. @@ -113,7 +111,11 @@ func NewABCIResponses(block *types.Block) *ABCIResponses { // Bytes serializes the ABCIResponse using go-wire func (a *ABCIResponses) Bytes() []byte { - return wire.BinaryBytes(*a) + bz, err := wire.MarshalBinary(*a) + if err != nil { + panic(err) + } + return bz } func (a *ABCIResponses) ResultsHash() []byte { @@ -131,12 +133,11 @@ func LoadABCIResponses(db dbm.DB, height int64) (*ABCIResponses, error) { } abciResponses := new(ABCIResponses) - r, n, err := bytes.NewReader(buf), new(int), new(error) - wire.ReadBinaryPtr(abciResponses, r, 0, n, err) - if *err != nil { + err := wire.UnmarshalBinary(buf, abciResponses) + if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED cmn.Exit(cmn.Fmt(`LoadABCIResponses: Data has been corrupted or its spec has - changed: %v\n`, *err)) + changed: %v\n`, err)) } // TODO: ensure that buf is completely read. @@ -160,7 +161,11 @@ type ValidatorsInfo struct { // Bytes serializes the ValidatorsInfo using go-wire func (valInfo *ValidatorsInfo) Bytes() []byte { - return wire.BinaryBytes(*valInfo) + bz, err := wire.MarshalBinary(*valInfo) + if err != nil { + panic(err) + } + return bz } // LoadValidators loads the ValidatorSet for a given height. @@ -189,12 +194,11 @@ func loadValidatorsInfo(db dbm.DB, height int64) *ValidatorsInfo { } v := new(ValidatorsInfo) - r, n, err := bytes.NewReader(buf), new(int), new(error) - wire.ReadBinaryPtr(v, r, 0, n, err) - if *err != nil { + err := wire.UnmarshalBinary(buf, v) + if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED cmn.Exit(cmn.Fmt(`LoadValidators: Data has been corrupted or its spec has changed: - %v\n`, *err)) + %v\n`, err)) } // TODO: ensure that buf is completely read. @@ -225,7 +229,11 @@ type ConsensusParamsInfo struct { // Bytes serializes the ConsensusParamsInfo using go-wire func (params ConsensusParamsInfo) Bytes() []byte { - return wire.BinaryBytes(params) + bz, err := wire.MarshalBinary(params) + if err != nil { + panic(err) + } + return bz } // LoadConsensusParams loads the ConsensusParams for a given height. @@ -255,12 +263,11 @@ func loadConsensusParamsInfo(db dbm.DB, height int64) *ConsensusParamsInfo { } paramsInfo := new(ConsensusParamsInfo) - r, n, err := bytes.NewReader(buf), new(int), new(error) - wire.ReadBinaryPtr(paramsInfo, r, 0, n, err) - if *err != nil { + err := wire.UnmarshalBinary(buf, paramsInfo) + if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED cmn.Exit(cmn.Fmt(`LoadConsensusParams: Data has been corrupted or its spec has changed: - %v\n`, *err)) + %v\n`, err)) } // TODO: ensure that buf is completely read. diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index ed4fcc8a6..f32f1f28d 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -67,10 +67,8 @@ func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { return nil, nil } - r := bytes.NewReader(rawBytes) - var n int - var err error - txResult := wire.ReadBinary(&types.TxResult{}, r, 0, &n, &err).(*types.TxResult) + txResult := new(types.TxResult) + err := wire.UnmarshalBinary(rawBytes, txResult) if err != nil { return nil, fmt.Errorf("Error reading TxResult: %v", err) } @@ -93,7 +91,10 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { } // index tx by hash - rawBytes := wire.BinaryBytes(result) + rawBytes, err := wire.MarshalBinary(result) + if err != nil { + return err + } storeBatch.Set(hash, rawBytes) } @@ -115,7 +116,10 @@ func (txi *TxIndex) Index(result *types.TxResult) error { } // index tx by hash - rawBytes := wire.BinaryBytes(result) + rawBytes, err := wire.MarshalBinary(result) + if err != nil { + return err + } b.Set(hash, rawBytes) b.Write()