From d8f7d5d5b67cb9b88a18ccf12e6da64746ab5b65 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 23 May 2022 14:01:42 +0300 Subject: [PATCH] core: adjust Signer to stackitem conversion Follow the https://github.com/neo-project/neo/pull/2708. --- pkg/core/native/ledger.go | 8 -------- pkg/core/native/native_test/ledger_test.go | 5 ----- pkg/interop/native/ledger/transaction_signer.go | 2 -- 3 files changed, 15 deletions(-) diff --git a/pkg/core/native/ledger.go b/pkg/core/native/ledger.go index 5752ec6f8..c3962c311 100644 --- a/pkg/core/native/ledger.go +++ b/pkg/core/native/ledger.go @@ -10,7 +10,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "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" @@ -261,12 +260,7 @@ func TransactionToStackItem(t *transaction.Transaction) stackitem.Item { // SignersToStackItem converts transaction.Signers to stackitem.Item. func SignersToStackItem(signers []transaction.Signer) stackitem.Item { res := make([]stackitem.Item, len(signers)) - bw := io.NewBufBinWriter() for i, s := range signers { - s.EncodeBinary(bw.BinWriter) - if bw.Err != nil { - panic(fmt.Errorf("failed to serialize signer %d to stackitem: %w", i, bw.Err)) - } contracts := make([]stackitem.Item, len(s.AllowedContracts)) for j, c := range s.AllowedContracts { contracts[j] = stackitem.NewByteArray(c.BytesBE()) @@ -280,14 +274,12 @@ func SignersToStackItem(signers []transaction.Signer) stackitem.Item { rules[j] = r.ToStackItem() } res[i] = stackitem.NewArray([]stackitem.Item{ - stackitem.NewByteArray(bw.Bytes()), stackitem.NewByteArray(s.Account.BytesBE()), stackitem.NewBigInteger(big.NewInt(int64(s.Scopes))), stackitem.NewArray(contracts), stackitem.NewArray(groups), stackitem.NewArray(rules), }) - bw.Reset() } return stackitem.NewArray(res) } diff --git a/pkg/core/native/native_test/ledger_test.go b/pkg/core/native/native_test/ledger_test.go index b3fb555db..dbdd3a7d5 100644 --- a/pkg/core/native/native_test/ledger_test.go +++ b/pkg/core/native/native_test/ledger_test.go @@ -10,7 +10,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/util" @@ -190,12 +189,8 @@ func TestLedger_GetTransactionSigners(t *testing.T) { Account: c.CommitteeHash, Scopes: transaction.Global, } - bw := io.NewBufBinWriter() - s.EncodeBinary(bw.BinWriter) - require.NoError(t, bw.Err) expected := stackitem.NewArray([]stackitem.Item{ stackitem.NewArray([]stackitem.Item{ - stackitem.NewByteArray(bw.Bytes()), stackitem.NewByteArray(s.Account.BytesBE()), stackitem.NewBigInteger(big.NewInt(int64(s.Scopes))), stackitem.NewArray([]stackitem.Item{}), diff --git a/pkg/interop/native/ledger/transaction_signer.go b/pkg/interop/native/ledger/transaction_signer.go index b27ab735a..04f04772b 100644 --- a/pkg/interop/native/ledger/transaction_signer.go +++ b/pkg/interop/native/ledger/transaction_signer.go @@ -5,8 +5,6 @@ import "github.com/nspcc-dev/neo-go/pkg/interop" // TransactionSigner represent the signer of a NEO transaction. It's similar to // Signer class in Neo .net framework. type TransactionSigner struct { - // Bytes is a binary serialized representation of the given signer. - Bytes []byte // Account represents the account (160 bit BE value in a 20 byte slice) of // the given signer. Account interop.Hash160