diff --git a/pkg/consensus/payload.go b/pkg/consensus/payload.go index f7ad50a07..80d73e2c7 100644 --- a/pkg/consensus/payload.go +++ b/pkg/consensus/payload.go @@ -217,7 +217,7 @@ func (p *Payload) DecodeBinaryUnsigned(r *io.BinReader) { r.ReadLE(&p.validatorIndex) r.ReadLE(&p.timestamp) - data := r.ReadBytes() + data := r.ReadVarBytes() if r.Err != nil { return } diff --git a/pkg/consensus/recovery_message.go b/pkg/consensus/recovery_message.go index c6bb1b57a..4e6094f66 100644 --- a/pkg/consensus/recovery_message.go +++ b/pkg/consensus/recovery_message.go @@ -93,7 +93,7 @@ func (p *changeViewCompact) DecodeBinary(r *io.BinReader) { r.ReadLE(&p.ValidatorIndex) r.ReadLE(&p.OriginalViewNumber) r.ReadLE(&p.Timestamp) - p.InvocationScript = r.ReadBytes() + p.InvocationScript = r.ReadVarBytes() } // EncodeBinary implements io.Serializable interface. @@ -109,7 +109,7 @@ func (p *commitCompact) DecodeBinary(r *io.BinReader) { r.ReadLE(&p.ViewNumber) r.ReadLE(&p.ValidatorIndex) r.ReadBE(p.Signature[:]) - p.InvocationScript = r.ReadBytes() + p.InvocationScript = r.ReadVarBytes() } // EncodeBinary implements io.Serializable interface. @@ -123,7 +123,7 @@ func (p *commitCompact) EncodeBinary(w *io.BinWriter) { // DecodeBinary implements io.Serializable interface. func (p *preparationCompact) DecodeBinary(r *io.BinReader) { r.ReadLE(&p.ValidatorIndex) - p.InvocationScript = r.ReadBytes() + p.InvocationScript = r.ReadVarBytes() } // EncodeBinary implements io.Serializable interface. diff --git a/pkg/core/contract_state.go b/pkg/core/contract_state.go index 6d976b209..5af26e1a8 100644 --- a/pkg/core/contract_state.go +++ b/pkg/core/contract_state.go @@ -38,7 +38,7 @@ func (a Contracts) commit(store storage.Store) error { // DecodeBinary implements Serializable interface. func (cs *ContractState) DecodeBinary(br *io.BinReader) { - cs.Script = br.ReadBytes() + cs.Script = br.ReadVarBytes() br.ReadArray(&cs.ParamList) br.ReadLE(&cs.ReturnType) br.ReadLE(&cs.Properties) diff --git a/pkg/core/storage_item.go b/pkg/core/storage_item.go index 331104b46..b61b66a2d 100644 --- a/pkg/core/storage_item.go +++ b/pkg/core/storage_item.go @@ -59,6 +59,6 @@ func (si *StorageItem) EncodeBinary(w *io.BinWriter) { // DecodeBinary implements Serializable interface. func (si *StorageItem) DecodeBinary(r *io.BinReader) { - si.Value = r.ReadBytes() + si.Value = r.ReadVarBytes() r.ReadLE(&si.IsConst) } diff --git a/pkg/core/transaction/invocation.go b/pkg/core/transaction/invocation.go index 6276a1a28..50ad3c78f 100644 --- a/pkg/core/transaction/invocation.go +++ b/pkg/core/transaction/invocation.go @@ -35,7 +35,7 @@ func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction { // DecodeBinary implements Serializable interface. func (tx *InvocationTX) DecodeBinary(br *io.BinReader) { - tx.Script = br.ReadBytes() + tx.Script = br.ReadVarBytes() if tx.Version >= 1 { br.ReadLE(&tx.Gas) } else { diff --git a/pkg/core/transaction/publish.go b/pkg/core/transaction/publish.go index 131a4ac9a..fc76f3535 100644 --- a/pkg/core/transaction/publish.go +++ b/pkg/core/transaction/publish.go @@ -22,7 +22,7 @@ type PublishTX struct { // DecodeBinary implements Serializable interface. func (tx *PublishTX) DecodeBinary(br *io.BinReader) { - tx.Script = br.ReadBytes() + tx.Script = br.ReadVarBytes() lenParams := br.ReadVarUint() tx.ParamList = make([]smartcontract.ParamType, lenParams) diff --git a/pkg/core/transaction/state_descriptor.go b/pkg/core/transaction/state_descriptor.go index c5d3cc958..e38889373 100644 --- a/pkg/core/transaction/state_descriptor.go +++ b/pkg/core/transaction/state_descriptor.go @@ -25,8 +25,8 @@ type StateDescriptor struct { func (s *StateDescriptor) DecodeBinary(r *io.BinReader) { r.ReadLE(&s.Type) - s.Key = r.ReadBytes() - s.Value = r.ReadBytes() + s.Key = r.ReadVarBytes() + s.Value = r.ReadVarBytes() s.Field = r.ReadString() } diff --git a/pkg/core/transaction/witness.go b/pkg/core/transaction/witness.go index bdbecb80d..6292ca981 100644 --- a/pkg/core/transaction/witness.go +++ b/pkg/core/transaction/witness.go @@ -17,8 +17,8 @@ type Witness struct { // DecodeBinary implements Serializable interface. func (w *Witness) DecodeBinary(br *io.BinReader) { - w.InvocationScript = br.ReadBytes() - w.VerificationScript = br.ReadBytes() + w.InvocationScript = br.ReadVarBytes() + w.VerificationScript = br.ReadVarBytes() } // EncodeBinary implements Serializable interface. diff --git a/pkg/io/binaryReader.go b/pkg/io/binaryReader.go index 1283537b2..6bc67fd66 100644 --- a/pkg/io/binaryReader.go +++ b/pkg/io/binaryReader.go @@ -127,17 +127,17 @@ func (r *BinReader) ReadVarUint() uint64 { return uint64(b) } -// ReadBytes reads the next set of bytes from the underlying reader. +// ReadVarBytes reads the next set of bytes from the underlying reader. // ReadVarUInt() is used to determine how large that slice is -func (r *BinReader) ReadBytes() []byte { +func (r *BinReader) ReadVarBytes() []byte { n := r.ReadVarUint() b := make([]byte, n) r.ReadLE(b) return b } -// ReadString calls ReadBytes and casts the results as a string. +// ReadString calls ReadVarBytes and casts the results as a string. func (r *BinReader) ReadString() string { - b := r.ReadBytes() + b := r.ReadVarBytes() return string(b) } diff --git a/pkg/io/binaryrw_test.go b/pkg/io/binaryrw_test.go index 8c6d64c6e..7047357a8 100644 --- a/pkg/io/binaryrw_test.go +++ b/pkg/io/binaryrw_test.go @@ -91,7 +91,7 @@ func TestReaderErrHandling(t *testing.T) { assert.Equal(t, i, iorig) val := br.ReadVarUint() assert.Equal(t, val, uint64(0)) - b := br.ReadBytes() + b := br.ReadVarBytes() assert.Equal(t, b, []byte{}) s := br.ReadString() assert.Equal(t, s, "") diff --git a/pkg/network/payload/merkleblock.go b/pkg/network/payload/merkleblock.go index 67142c2b4..410e2b749 100644 --- a/pkg/network/payload/merkleblock.go +++ b/pkg/network/payload/merkleblock.go @@ -21,7 +21,7 @@ func (m *MerkleBlock) DecodeBinary(br *io.BinReader) { m.TxCount = int(br.ReadVarUint()) br.ReadArray(&m.Hashes) - m.Flags = br.ReadBytes() + m.Flags = br.ReadVarBytes() } // EncodeBinary implements Serializable interface. diff --git a/pkg/network/payload/version.go b/pkg/network/payload/version.go index b221eef63..c8d62ab20 100644 --- a/pkg/network/payload/version.go +++ b/pkg/network/payload/version.go @@ -60,7 +60,7 @@ func (p *Version) DecodeBinary(br *io.BinReader) { br.ReadLE(&p.Timestamp) br.ReadLE(&p.Port) br.ReadLE(&p.Nonce) - p.UserAgent = br.ReadBytes() + p.UserAgent = br.ReadVarBytes() br.ReadLE(&p.StartHeight) br.ReadLE(&p.Relay) } diff --git a/pkg/smartcontract/contract_test.go b/pkg/smartcontract/contract_test.go index 3f9667e16..b6ba9b39f 100644 --- a/pkg/smartcontract/contract_test.go +++ b/pkg/smartcontract/contract_test.go @@ -27,7 +27,7 @@ func TestCreateMultiSigRedeemScript(t *testing.T) { assert.Equal(t, opcode.PUSH3, opcode.Opcode(b)) for i := 0; i < len(validators); i++ { - bb := br.ReadBytes() + bb := br.ReadVarBytes() if br.Err != nil { t.Fatal(err) } diff --git a/pkg/vm/serialization.go b/pkg/vm/serialization.go index 8f155a8d6..79c7b7228 100644 --- a/pkg/vm/serialization.go +++ b/pkg/vm/serialization.go @@ -102,14 +102,14 @@ func DecodeBinaryStackItem(r *io.BinReader) StackItem { switch stackItemType(t) { case byteArrayT: - data := r.ReadBytes() + data := r.ReadVarBytes() return NewByteArrayItem(data) case booleanT: var b bool r.ReadLE(&b) return NewBoolItem(b) case integerT: - data := r.ReadBytes() + data := r.ReadVarBytes() num := new(big.Int).SetBytes(util.ArrayReverse(data)) return &BigIntegerItem{ value: num,