core: adjust Signer to stackitem conversion

Follow the https://github.com/neo-project/neo/pull/2708.
This commit is contained in:
Anna Shaleva 2022-05-23 14:01:42 +03:00
parent 73ef36e03e
commit d8f7d5d5b6
3 changed files with 0 additions and 15 deletions

View file

@ -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)
}

View file

@ -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{}),

View file

@ -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