diff --git a/src/neo/SmartContract/Native/ContractManagement.cs b/src/neo/SmartContract/Native/ContractManagement.cs index 1bbfbac331..229dbecee7 100644 --- a/src/neo/SmartContract/Native/ContractManagement.cs +++ b/src/neo/SmartContract/Native/ContractManagement.cs @@ -120,6 +120,12 @@ public IEnumerable ListContracts(StoreView snapshot) return snapshot.Storages.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable()); } + [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] + private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest) + { + return Deploy(engine, nefFile, manifest, StackItem.Null); + } + [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest, StackItem data) { @@ -164,6 +170,12 @@ private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] ma return contract; } + [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] + private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest) + { + Update(engine, nefFile, manifest, StackItem.Null); + } + [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest, StackItem data) { diff --git a/src/neo/SmartContract/Native/NativeContract.cs b/src/neo/SmartContract/Native/NativeContract.cs index 64fc0544a8..1f2443b79c 100644 --- a/src/neo/SmartContract/Native/NativeContract.cs +++ b/src/neo/SmartContract/Native/NativeContract.cs @@ -16,7 +16,7 @@ public abstract class NativeContract private static readonly List contractsList = new List(); private static readonly Dictionary contractsIdDictionary = new Dictionary(); private static readonly Dictionary contractsHashDictionary = new Dictionary(); - private readonly Dictionary methods = new Dictionary(); + private readonly Dictionary<(string, int), ContractMethodMetadata> methods = new Dictionary<(string, int), ContractMethodMetadata>(); private static int id_counter = 0; #region Named Native Contracts @@ -69,7 +69,7 @@ protected NativeContract() Parameters = metadata.Parameters.Select(p => new ContractParameterDefinition { Type = ToParameterType(p.Type), Name = p.Name }).ToArray(), Safe = (attribute.RequiredCallFlags & ~CallFlags.ReadOnly) == 0 }); - methods.Add(metadata.Name, metadata); + methods.Add((metadata.Name, metadata.Parameters.Length), metadata); } this.Manifest = new ContractManifest { @@ -121,7 +121,7 @@ internal void Invoke(ApplicationEngine engine) throw new InvalidOperationException("It is not allowed to use Neo.Native.Call directly to call native contracts. System.Contract.Call should be used."); ExecutionContext context = engine.CurrentContext; string operation = context.EvaluationStack.Pop().GetString(); - ContractMethodMetadata method = methods[operation]; + ContractMethodMetadata method = methods[(operation, context.EvaluationStack.Count)]; ExecutionContextState state = context.GetState(); if (!state.CallFlags.HasFlag(method.RequiredCallFlags)) throw new InvalidOperationException($"Cannot call this method with the flag {state.CallFlags}."); diff --git a/tests/neo.UnitTests/SmartContract/Native/UT_NativeContract.cs b/tests/neo.UnitTests/SmartContract/Native/UT_NativeContract.cs index d8704b614a..4f378c13e1 100644 --- a/tests/neo.UnitTests/SmartContract/Native/UT_NativeContract.cs +++ b/tests/neo.UnitTests/SmartContract/Native/UT_NativeContract.cs @@ -8,7 +8,6 @@ using System; using System.Collections.Generic; using System.Numerics; -using VMArray = Neo.VM.Types.Array; namespace Neo.UnitTests.SmartContract.Native { @@ -100,14 +99,10 @@ public void TestInvoke() engine.LoadScript(testNativeContract.Script, configureState: p => p.ScriptHash = testNativeContract.Hash); ByteString method1 = new ByteString(System.Text.Encoding.Default.GetBytes("wrongMethod")); - VMArray args1 = new VMArray(); - engine.CurrentContext.EvaluationStack.Push(args1); engine.CurrentContext.EvaluationStack.Push(method1); Assert.ThrowsException(() => testNativeContract.Invoke(engine)); ByteString method2 = new ByteString(System.Text.Encoding.Default.GetBytes("helloWorld")); - VMArray args2 = new VMArray(); - engine.CurrentContext.EvaluationStack.Push(args2); engine.CurrentContext.EvaluationStack.Push(method2); testNativeContract.Invoke(engine); }