Skip to content

Commit

Permalink
Pass additional data to _deploy (neo-project#2239)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored and cloud8little committed Jan 24, 2021
1 parent 9f2e46c commit 25dc868
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/neo/SmartContract/Native/ContractManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,7 +121,7 @@ public IEnumerable<ContractState> 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();
Expand Down Expand Up @@ -156,15 +157,15 @@ 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() });

return contract;
}

[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();

Expand Down Expand Up @@ -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() });
}
Expand Down
4 changes: 2 additions & 2 deletions tests/neo.UnitTests/Extensions/NativeContractExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit 25dc868

Please sign in to comment.