Merge pull request #2511 from nspcc-dev/signers-to-stackitem

core: adjust Signer to stackitem conversion
This commit is contained in:
Roman Khimov 2022-05-23 14:44:06 +03:00 committed by GitHub
commit ddec756af5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 39 additions and 54 deletions

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/engine
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/events
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/iterator
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -3,7 +3,7 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd-nns
go 1.16
require (
github.com/nspcc-dev/neo-go v0.98.5-pre.0.20220512113228-bb5cffc4a85e
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
github.com/nspcc-dev/neo-go v0.98.6-pre.0.20220523110500-1cc107d4610e
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c
github.com/stretchr/testify v1.7.0
)

View file

@ -179,10 +179,10 @@ github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM=
github.com/nspcc-dev/neo-go v0.98.5-pre.0.20220512113228-bb5cffc4a85e h1:d6a1kyLYiRaPGeNQC3bKCFevo2cgrPIdHT0AhusRL6E=
github.com/nspcc-dev/neo-go v0.98.5-pre.0.20220512113228-bb5cffc4a85e/go.mod h1:gcrFLrKkISbhevADP2vwWEqst66Q23j+s9ujVnLoxlk=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go v0.98.6-pre.0.20220523110500-1cc107d4610e h1:KlCtKZvCzPysT1pnK4e2TSyXF/CFsfTA7AU8P9jbeLU=
github.com/nspcc-dev/neo-go v0.98.6-pre.0.20220523110500-1cc107d4610e/go.mod h1:IYV+4Zl0zKAcH7BP09lx3Q9UYFzk47WH2vTslZN3CRA=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/oracle
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/runtime
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/storage
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/timer
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

View file

@ -2,4 +2,4 @@ module github.com/nspcc-dev/neo-go/examples/token
go 1.16
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c

View file

@ -1,2 +1,2 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=

2
go.mod
View file

@ -12,7 +12,7 @@ require (
github.com/mr-tron/base58 v1.2.0
github.com/nspcc-dev/dbft v0.0.0-20220414131237-e497bbf7868e
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659
github.com/nspcc-dev/rfc6979 v0.2.0
github.com/pierrec/lz4 v2.6.1+incompatible

4
go.sum
View file

@ -185,8 +185,8 @@ github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe h1:R6DsjC+5NOWDpDm7fdLoF+AwTfzKU1ygRetNbY8oyWc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220512113124-e31f4ca331fe/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c h1:3e7iTZ2/wssMdIkpGb6KMhLJiBiQVxEQDKM+6K1VCLM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220523110142-d8f7d5d5b67c/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gvdA0uYJ/GWZQ=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=

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