From 33386065bc01b549db8f95a6358c62a11faada0a Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 22 Dec 2020 17:30:45 +0300 Subject: [PATCH] core: adjust parameters of native methods This commit is mostly about Hash160 -> ByteArray for native contracts' methods. Manifest is included into states, so we need to be compatible. --- pkg/core/native/management.go | 2 +- pkg/core/native/native_neo.go | 10 +++++----- pkg/core/native/native_nep17.go | 17 +++++++++-------- pkg/core/native/policy.go | 6 +++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index ef5a5361c..8fef66d93 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -64,7 +64,7 @@ func newManagement() *Management { } desc := newDescriptor("getContract", smartcontract.ArrayType, - manifest.NewParameter("hash", smartcontract.Hash160Type)) + manifest.NewParameter("hash", smartcontract.ByteArrayType)) md := newMethodAndPrice(m.getContract, 1000000, smartcontract.ReadStates) m.AddMethod(md, desc) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 739264680..88cd18e05 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -108,24 +108,24 @@ func newNEO() *NEO { n.committeeHash.Store(util.Uint160{}) desc := newDescriptor("unclaimedGas", smartcontract.IntegerType, - manifest.NewParameter("account", smartcontract.Hash160Type), + manifest.NewParameter("account", smartcontract.ByteArrayType), manifest.NewParameter("end", smartcontract.IntegerType)) md := newMethodAndPrice(n.unclaimedGas, 3000000, smartcontract.ReadStates) n.AddMethod(md, desc) desc = newDescriptor("registerCandidate", smartcontract.BoolType, - manifest.NewParameter("pubkey", smartcontract.PublicKeyType)) + manifest.NewParameter("pubkey", smartcontract.ByteArrayType)) md = newMethodAndPrice(n.registerCandidate, 5000000, smartcontract.WriteStates) n.AddMethod(md, desc) desc = newDescriptor("unregisterCandidate", smartcontract.BoolType, - manifest.NewParameter("pubkey", smartcontract.PublicKeyType)) + manifest.NewParameter("pubkey", smartcontract.ByteArrayType)) md = newMethodAndPrice(n.unregisterCandidate, 5000000, smartcontract.WriteStates) n.AddMethod(md, desc) desc = newDescriptor("vote", smartcontract.BoolType, - manifest.NewParameter("account", smartcontract.Hash160Type), - manifest.NewParameter("pubkey", smartcontract.PublicKeyType)) + manifest.NewParameter("account", smartcontract.ByteArrayType), + manifest.NewParameter("pubkey", smartcontract.ByteArrayType)) md = newMethodAndPrice(n.vote, 5000000, smartcontract.WriteStates) n.AddMethod(md, desc) diff --git a/pkg/core/native/native_nep17.go b/pkg/core/native/native_nep17.go index cfb2cf7cd..cf23f2549 100644 --- a/pkg/core/native/native_nep17.go +++ b/pkg/core/native/native_nep17.go @@ -59,22 +59,23 @@ func newNEP17Native(name string) *nep17TokenNative { n.AddMethod(md, desc) desc = newDescriptor("balanceOf", smartcontract.IntegerType, - manifest.NewParameter("account", smartcontract.Hash160Type)) + manifest.NewParameter("account", smartcontract.ByteArrayType)) md = newMethodAndPrice(n.balanceOf, 1000000, smartcontract.ReadStates) n.AddMethod(md, desc) - transferParams := []manifest.Parameter{ - manifest.NewParameter("from", smartcontract.Hash160Type), - manifest.NewParameter("to", smartcontract.Hash160Type), - manifest.NewParameter("amount", smartcontract.IntegerType), - } desc = newDescriptor("transfer", smartcontract.BoolType, - append(transferParams, manifest.NewParameter("data", smartcontract.AnyType))..., + manifest.NewParameter("from", smartcontract.ByteArrayType), + manifest.NewParameter("to", smartcontract.ByteArrayType), + manifest.NewParameter("amount", smartcontract.IntegerType), + manifest.NewParameter("data", smartcontract.AnyType), ) md = newMethodAndPrice(n.Transfer, 9000000, smartcontract.WriteStates|smartcontract.AllowCall|smartcontract.AllowNotify) n.AddMethod(md, desc) - n.AddEvent("Transfer", transferParams...) + n.AddEvent("Transfer", + manifest.NewParameter("from", smartcontract.Hash160Type), + manifest.NewParameter("to", smartcontract.Hash160Type), + manifest.NewParameter("amount", smartcontract.IntegerType)) return n } diff --git a/pkg/core/native/policy.go b/pkg/core/native/policy.go index 3c7411315..90f4ced7b 100644 --- a/pkg/core/native/policy.go +++ b/pkg/core/native/policy.go @@ -97,7 +97,7 @@ func newPolicy() *Policy { p.AddMethod(md, desc) desc = newDescriptor("isBlocked", smartcontract.BoolType, - manifest.NewParameter("account", smartcontract.Hash160Type)) + manifest.NewParameter("account", smartcontract.ByteArrayType)) md = newMethodAndPrice(p.isBlocked, 1000000, smartcontract.ReadStates) p.AddMethod(md, desc) @@ -144,12 +144,12 @@ func newPolicy() *Policy { p.AddMethod(md, desc) desc = newDescriptor("blockAccount", smartcontract.BoolType, - manifest.NewParameter("account", smartcontract.Hash160Type)) + manifest.NewParameter("account", smartcontract.ByteArrayType)) md = newMethodAndPrice(p.blockAccount, 3000000, smartcontract.WriteStates) p.AddMethod(md, desc) desc = newDescriptor("unblockAccount", smartcontract.BoolType, - manifest.NewParameter("account", smartcontract.Hash160Type)) + manifest.NewParameter("account", smartcontract.ByteArrayType)) md = newMethodAndPrice(p.unblockAccount, 3000000, smartcontract.WriteStates) p.AddMethod(md, desc)