mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
Merge pull request #2591 from nspcc-dev/interop/equality
interop: add equality helpers
This commit is contained in:
commit
31a559e784
32 changed files with 212 additions and 66 deletions
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -203,7 +203,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool {
|
|||
key := mkBalanceKey(owner, token)
|
||||
amount := getBalanceOf(ctx, key)
|
||||
|
||||
if string(owner) != string(to) {
|
||||
if !owner.Equals(to) {
|
||||
addToBalance(ctx, owner, token, -amount)
|
||||
removeOwner(ctx, token, owner)
|
||||
|
||||
|
@ -293,7 +293,7 @@ func TransferDivisible(from, to interop.Hash160, amount int, token []byte, data
|
|||
return false
|
||||
}
|
||||
|
||||
if string(from) != string(to) {
|
||||
if !from.Equals(to) {
|
||||
updBalance := addToBalance(ctx, from, token, -amount)
|
||||
if updBalance == 0 {
|
||||
removeOwner(ctx, token, from)
|
||||
|
@ -357,7 +357,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
|||
util.Abort()
|
||||
}
|
||||
}()
|
||||
if string(runtime.GetCallingScriptHash()) != gas.Hash {
|
||||
callingHash := runtime.GetCallingScriptHash()
|
||||
if !callingHash.Equals(gas.Hash) {
|
||||
panic("only GAS is accepted")
|
||||
}
|
||||
if amount < 10_00000000 {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
MSYS-1.0.19 Build:2016-07-13 17:45
|
||||
Exception: STATUS_ACCESS_VIOLATION at eip=0072174E
|
||||
eax=608F9138 ebx=00000000 ecx=60EA0000 edx=60EA4184 esi=00993208 edi=00000001
|
||||
ebp=0069FEB0 esp=0069FE48 program=us
|
||||
cs=0023 ds=002B es=002B fs=0053 gs=002B ss=002B
|
||||
Stack trace:
|
||||
Frame Function Args
|
||||
15750 [main] us 0 handle_exceptions: Error while dumping state (probably corrupted stack)
|
|
@ -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.6-pre.0.20220601121043-3c2fc165b609
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5
|
||||
github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220711130119-3594c4f760bc
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
)
|
||||
|
|
|
@ -171,27 +171,23 @@ github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae/go.mod h1:3FjXOoHmA
|
|||
github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20210721160347-1b03241391ac/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20220523093034-c35adf004e6f/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20220629112714-fd49ca59d354/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y=
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20210915112629-e1b6cce73d02/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U=
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 h1:n4ZaFCKt1pQJd7PXoMJabZWK9ejjbLOVrkl/lOUmshg=
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U=
|
||||
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.6-pre.0.20220601121043-3c2fc165b609 h1:g6M49nGOWscRDjdOhc66pYK90gQZMiVQpiejF0fhOAg=
|
||||
github.com/nspcc-dev/neo-go v0.98.6-pre.0.20220601121043-3c2fc165b609/go.mod h1:Bb71wjxD9RMSXFhX3OCWlBm1eu/ma9YKm8Ytl5TXEl4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220711130119-3594c4f760bc h1:jFPvWUbQeBQrBMOR2lOSHmUWJcyc2OYEBf9fh/qcPXQ=
|
||||
github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220711130119-3594c4f760bc/go.mod h1:LRmtGkErJek0nV9lakj24lscCclkPCjgUUQLG+FPw1w=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/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=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40=
|
||||
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
||||
|
@ -210,7 +206,6 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
|
|||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
|
||||
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
@ -250,7 +245,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
|||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@ -402,7 +396,6 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
|
|||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
|
@ -410,7 +403,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
|
|||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.41.0 h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E=
|
||||
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||
)
|
||||
|
||||
// Prefixes used for contract data storage.
|
||||
|
@ -164,7 +163,7 @@ func Transfer(to interop.Hash160, tokenID []byte, data interface{}) bool {
|
|||
if !runtime.CheckWitness(from) {
|
||||
return false
|
||||
}
|
||||
if !util.Equals(from, to) {
|
||||
if !from.Equals(to) {
|
||||
// update token info
|
||||
ns.Owner = to
|
||||
ns.Admin = nil
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -186,7 +186,7 @@ func Transfer(to interop.Hash160, token []byte, data interface{}) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if string(owner) != string(to) {
|
||||
if !owner.Equals(to) {
|
||||
addToBalance(ctx, owner, -1)
|
||||
removeToken(ctx, owner, token)
|
||||
|
||||
|
@ -216,7 +216,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
|||
util.Abort()
|
||||
}
|
||||
}()
|
||||
if string(runtime.GetCallingScriptHash()) != gas.Hash {
|
||||
callingHash := runtime.GetCallingScriptHash()
|
||||
if !callingHash.Equals(gas.Hash) {
|
||||
panic("only GAS is accepted")
|
||||
}
|
||||
if amount < 10_00000000 {
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -26,7 +26,8 @@ func FilteredRequest(url string, filter []byte) {
|
|||
func OracleCallback(url string, data interface{}, code int, res []byte) {
|
||||
// This function shouldn't be called directly, we only expect oracle native
|
||||
// contract to be calling it.
|
||||
if string(runtime.GetCallingScriptHash()) != oracle.Hash {
|
||||
callingHash := runtime.GetCallingScriptHash()
|
||||
if !callingHash.Equals(oracle.Hash) {
|
||||
panic("not called from oracle contract")
|
||||
}
|
||||
if code != oracle.Success {
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -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-20220601120906-3bec6657f5c5
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||
)
|
||||
|
||||
// Token holds all token info
|
||||
|
@ -105,7 +104,7 @@ func IsUsableAddress(addr []byte) bool {
|
|||
|
||||
// Check if a smart contract is calling scripthash
|
||||
callingScriptHash := runtime.GetCallingScriptHash()
|
||||
if util.Equals(callingScriptHash, addr) {
|
||||
if callingScriptHash.Equals(addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -13,7 +13,7 @@ require (
|
|||
github.com/mr-tron/base58 v1.2.0
|
||||
github.com/nspcc-dev/dbft v0.0.0-20220629112714-fd49ca59d354
|
||||
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1
|
||||
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
4
go.sum
|
@ -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-20220601120906-3bec6657f5c5 h1:bWau94hHSkztNF7EDTkvQAc8xjsxGMnaFf1DrXguvX8=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220601120906-3bec6657f5c5/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1 h1:+BoyBexD7gjb2IoeZemdcsjKvIs6ouE/iLDQFZMIBS4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220711125924-78e5f16573a1/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=
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -375,3 +376,118 @@ func TestOpcode(t *testing.T) {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestInteropTypesComparison(t *testing.T) {
|
||||
typeCheck := func(t *testing.T, typeName string, typeLen int) {
|
||||
t.Run(typeName, func(t *testing.T) {
|
||||
var ha, hb string
|
||||
for i := 0; i < typeLen; i++ {
|
||||
if i == typeLen-1 {
|
||||
ha += "2"
|
||||
hb += "3"
|
||||
} else {
|
||||
ha += "1, "
|
||||
hb += "1, "
|
||||
}
|
||||
}
|
||||
check := func(t *testing.T, a, b string, expected bool) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
func Main() bool {
|
||||
a := interop.` + typeName + `{` + a + `}
|
||||
b := interop.` + typeName + `{` + b + `}
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, expected)
|
||||
}
|
||||
t.Run("same type", func(t *testing.T) {
|
||||
check(t, ha, ha, true)
|
||||
check(t, ha, hb, false)
|
||||
})
|
||||
t.Run("a is nil", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
var a interop.` + typeName + `
|
||||
b := interop.` + typeName + `{` + hb + `}
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, false)
|
||||
})
|
||||
t.Run("b is nil", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
a := interop.` + typeName + `{` + ha + `}
|
||||
var b interop.` + typeName + `
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, false)
|
||||
})
|
||||
t.Run("both nil", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
var a interop.` + typeName + `
|
||||
var b interop.` + typeName + `
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, true)
|
||||
})
|
||||
t.Run("different types", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
a := interop.` + typeName + `{` + ha + `}
|
||||
b := 123
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, false)
|
||||
})
|
||||
t.Run("b is Buffer", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
a := interop.` + typeName + `{` + ha + `}
|
||||
b := []byte{` + ha + `}
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, true)
|
||||
})
|
||||
t.Run("b is ByteString", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
a := interop.` + typeName + `{` + ha + `}
|
||||
b := string([]byte{` + ha + `})
|
||||
return a.Equals(b)
|
||||
}`
|
||||
eval(t, src, true)
|
||||
})
|
||||
t.Run("b is compound type", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
|
||||
func Main() bool {
|
||||
a := interop.` + typeName + `{` + ha + `}
|
||||
b := struct{}{}
|
||||
return a.Equals(b)
|
||||
}`
|
||||
vm, _ := vmAndCompileInterop(t, src)
|
||||
err := vm.Run()
|
||||
require.Error(t, err)
|
||||
require.True(t, strings.Contains(err.Error(), "invalid conversion: Struct/ByteString"), err)
|
||||
})
|
||||
})
|
||||
}
|
||||
typeCheck(t, "Hash160", util.Uint160Size)
|
||||
typeCheck(t, "Hash256", util.Uint256Size)
|
||||
typeCheck(t, "Signature", 64)
|
||||
typeCheck(t, "PublicKey", 33)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package interop
|
||||
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
||||
|
||||
const (
|
||||
// Hash160Len is the length of proper Hash160 in bytes, use it to
|
||||
// sanitize input parameters.
|
||||
|
@ -35,3 +37,46 @@ type PublicKey []byte
|
|||
// Interface represents interop interface type which is needed for
|
||||
// transparent handling of VM-internal types (e.g. storage.Context).
|
||||
type Interface interface{}
|
||||
|
||||
// Equals compares Hash160 with the provided stackitem using EQUAL opcode.
|
||||
// The provided stackitem `b` must be either one of the primitive type (int,
|
||||
// bool, string, []byte) or derived from the primitive type, otherwise Equals
|
||||
// will fail on .(string) conversion.
|
||||
func (a Hash160) Equals(b interface{}) bool {
|
||||
ha := interface{}(a)
|
||||
return bytesEquals(ha, b)
|
||||
}
|
||||
|
||||
// Equals compares Hash256 with the provided stackitem using EQUAL opcode.
|
||||
// The provided stackitem `b` must be either one of the primitive type (int,
|
||||
// bool, string, []byte) or derived from the primitive type, otherwise Equals
|
||||
// will fail on .(string) conversion.
|
||||
func (a Hash256) Equals(b interface{}) bool {
|
||||
ha := interface{}(a)
|
||||
return bytesEquals(ha, b)
|
||||
}
|
||||
|
||||
// Equals compares PublicKey with the provided stackitem using EQUAL opcode.
|
||||
// The provided stackitem `b` must be either one of the primitive type (int,
|
||||
// bool, string, []byte) or derived from the primitive type, otherwise Equals
|
||||
// will fail on .(string) conversion.
|
||||
func (a PublicKey) Equals(b interface{}) bool {
|
||||
ha := interface{}(a)
|
||||
return bytesEquals(ha, b)
|
||||
}
|
||||
|
||||
// Equals compares Signature with the provided stackitem using EQUAL opcode.
|
||||
// The provided stackitem `b` must be either one of the primitive types (int,
|
||||
// bool, string, []byte) or derived from the primitive type, otherwise Equals
|
||||
// will fail on .(string) conversion.
|
||||
func (a Signature) Equals(b interface{}) bool {
|
||||
ha := interface{}(a)
|
||||
return bytesEquals(ha, b)
|
||||
}
|
||||
|
||||
// bytesEquals is an internal helper function allowed to compare types that can be
|
||||
// converted to ByteString.
|
||||
func bytesEquals(a interface{}, b interface{}) bool {
|
||||
return (a == nil && b == nil) ||
|
||||
(a != nil && b != nil && neogointernal.Opcode2("EQUAL", a.(string), b.(string)).(bool))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue