From c018d0110755e178597ea44c2e73c73e814b3e52 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Fri, 15 Jan 2021 16:36:53 +0800 Subject: [PATCH] Pass additional data to _deploy (#2239) --- src/neo/SmartContract/Native/ContractManagement.cs | 9 +++++---- .../neo.UnitTests/Extensions/NativeContractExtensions.cs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/neo/SmartContract/Native/ContractManagement.cs b/src/neo/SmartContract/Native/ContractManagement.cs index a65d9fd100..8d584dea87 100644 --- a/src/neo/SmartContract/Native/ContractManagement.cs +++ b/src/neo/SmartContract/Native/ContractManagement.cs @@ -5,6 +5,7 @@ using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.SmartContract.Manifest; +using Neo.VM.Types; using System; using System.Collections.Generic; using System.Linq; @@ -120,7 +121,7 @@ public IEnumerable ListContracts(StoreView snapshot) } [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] - private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest) + private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest, StackItem data) { if (!(engine.ScriptContainer is Transaction tx)) throw new InvalidOperationException(); @@ -156,7 +157,7 @@ private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] ma ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod("_deploy"); if (md != null) - engine.CallFromNativeContract(Hash, hash, md.Name, false); + engine.CallFromNativeContract(Hash, hash, md.Name, data, false); engine.SendNotification(Hash, "Deploy", new VM.Types.Array { contract.Hash.ToArray() }); @@ -164,7 +165,7 @@ private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] ma } [ContractMethod(0, CallFlags.WriteStates | CallFlags.AllowNotify)] - private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest) + private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest, StackItem data) { if (nefFile is null && manifest is null) throw new ArgumentException(); @@ -194,7 +195,7 @@ private void Update(ApplicationEngine engine, byte[] nefFile, byte[] manifest) { ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod("_deploy"); if (md != null) - engine.CallFromNativeContract(Hash, contract.Hash, md.Name, true); + engine.CallFromNativeContract(Hash, contract.Hash, md.Name, data, true); } engine.SendNotification(Hash, "Update", new VM.Types.Array { contract.Hash.ToArray() }); } diff --git a/tests/neo.UnitTests/Extensions/NativeContractExtensions.cs b/tests/neo.UnitTests/Extensions/NativeContractExtensions.cs index 07f16bc60b..b8fe4529a2 100644 --- a/tests/neo.UnitTests/Extensions/NativeContractExtensions.cs +++ b/tests/neo.UnitTests/Extensions/NativeContractExtensions.cs @@ -13,7 +13,7 @@ public static class NativeContractExtensions public static ContractState DeployContract(this StoreView snapshot, UInt160 sender, byte[] nefFile, byte[] manifest, long gas = 200_00000000) { var script = new ScriptBuilder(); - script.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nefFile, manifest); + script.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nefFile, manifest, null); var engine = ApplicationEngine.Create(TriggerType.Application, sender != null ? new Transaction() { Signers = new Signer[] { new Signer() { Account = sender } } } : null, snapshot, null, gas); @@ -34,7 +34,7 @@ public static ContractState DeployContract(this StoreView snapshot, UInt160 send public static void UpdateContract(this StoreView snapshot, UInt160 callingScriptHash, byte[] nefFile, byte[] manifest) { var script = new ScriptBuilder(); - script.EmitDynamicCall(NativeContract.ContractManagement.Hash, "update", nefFile, manifest); + script.EmitDynamicCall(NativeContract.ContractManagement.Hash, "update", nefFile, manifest, null); var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot); engine.LoadScript(script.ToArray());