Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass additional data to _deploy #2239

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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