diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index dadeaee35..b5e433d14 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -20,7 +20,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -903,10 +902,9 @@ func (n *NEO) getAccountState(ic *interop.Context, args []stackitem.Item) stacki return stackitem.Null{} } - r := io.NewBinReaderFromBuf(si) - item := stackitem.DecodeBinary(r) - if r.Err != nil { - panic(r.Err) // no errors are expected but we better be sure + item, err := stackitem.Deserialize(si) + if err != nil { + panic(err) // no errors are expected but we better be sure } return item } diff --git a/pkg/core/native/native_neo_candidate.go b/pkg/core/native/native_neo_candidate.go index a1a7bb44f..f0802d512 100644 --- a/pkg/core/native/native_neo_candidate.go +++ b/pkg/core/native/native_neo_candidate.go @@ -3,7 +3,6 @@ package native import ( "math/big" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -14,17 +13,18 @@ type candidate struct { // Bytes marshals c to byte array. func (c *candidate) Bytes() []byte { - w := io.NewBufBinWriter() - stackitem.EncodeBinary(c.toStackItem(), w.BinWriter) - return w.Bytes() + res, err := stackitem.Serialize(c.toStackItem()) + if err != nil { + panic(err) + } + return res } // FromBytes unmarshals candidate from byte array. func (c *candidate) FromBytes(data []byte) *candidate { - r := io.NewBinReaderFromBuf(data) - item := stackitem.DecodeBinary(r) - if r.Err != nil { - panic(r.Err) + item, err := stackitem.Deserialize(data) + if err != nil { + panic(err) } return c.fromStackItem(item) } diff --git a/pkg/core/native/neo_types.go b/pkg/core/native/neo_types.go index 15dcf1e97..21e5dfb3b 100644 --- a/pkg/core/native/neo_types.go +++ b/pkg/core/native/neo_types.go @@ -6,7 +6,6 @@ import ( "math/big" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -84,21 +83,18 @@ func (k *keysWithVotes) fromStackItem(item stackitem.Item) error { // Bytes serializes keys with votes slice. func (k keysWithVotes) Bytes() []byte { - var it = k.toStackItem() - var w = io.NewBufBinWriter() - stackitem.EncodeBinary(it, w.BinWriter) - if w.Err != nil { - panic(w.Err) + buf, err := stackitem.Serialize(k.toStackItem()) + if err != nil { + panic(err) } - return w.Bytes() + return buf } // DecodeBytes deserializes keys and votes slice. func (k *keysWithVotes) DecodeBytes(data []byte) error { - var r = io.NewBinReaderFromBuf(data) - var it = stackitem.DecodeBinary(r) - if r.Err != nil { - return r.Err + it, err := stackitem.Deserialize(data) + if err != nil { + return err } return k.fromStackItem(it) } diff --git a/pkg/core/native/oracle.go b/pkg/core/native/oracle.go index 624346fa8..9b640b226 100644 --- a/pkg/core/native/oracle.go +++ b/pkg/core/native/oracle.go @@ -359,12 +359,10 @@ func (o *Oracle) RequestInternal(ic *interop.Context, url string, filter *string return err } - w := io.NewBufBinWriter() - stackitem.EncodeBinary(userData, w.BinWriter) - if w.Err != nil { - return w.Err + data, err := stackitem.Serialize(userData) + if err != nil { + return err } - data := w.Bytes() if len(data) > maxUserDataLength { return ErrBigArgument } diff --git a/pkg/core/native/std_test.go b/pkg/core/native/std_test.go index 2558b5f2d..2817850e0 100644 --- a/pkg/core/native/std_test.go +++ b/pkg/core/native/std_test.go @@ -11,7 +11,6 @@ import ( "github.com/mr-tron/base58" "github.com/nspcc-dev/neo-go/pkg/core/interop" base58neogo "github.com/nspcc-dev/neo-go/pkg/encoding/base58" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/stretchr/testify/assert" @@ -275,11 +274,8 @@ func TestStdLibSerialize(t *testing.T) { actualSerialized = s.serialize(ic, []stackitem.Item{stackitem.Make(42)}) }) - w := io.NewBufBinWriter() - stackitem.EncodeBinary(stackitem.Make(42), w.BinWriter) - require.NoError(t, w.Err) - - encoded := w.Bytes() + encoded, err := stackitem.Serialize(stackitem.Make(42)) + require.NoError(t, err) require.Equal(t, stackitem.Make(encoded), actualSerialized) require.NotPanics(t, func() {