Skip to content

Commit

Permalink
Revert "Add data parameter when deploy and update contract (neo-proje…
Browse files Browse the repository at this point in the history
…ct#837)"

This reverts commit 24bd2cc.
  • Loading branch information
ZhangTao authored Nov 19, 2021
1 parent 24bd2cc commit 4253aa5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 38 deletions.
13 changes: 8 additions & 5 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ partial class MainService
/// <param name="filePath">File path</param>
/// <param name="manifestPath">Manifest path</param>
[ConsoleCommand("deploy", Category = "Contract Commands")]
private void OnDeployCommand(string filePath, string manifestPath = null, JObject data = null)
private void OnDeployCommand(string filePath, string manifestPath = null)
{
if (NoWallet()) return;
byte[] script = LoadDeploymentScript(filePath, manifestPath, data, out var nef, out var manifest);
byte[] script = LoadDeploymentScript(filePath, manifestPath, out var nef, out var manifest);

Transaction tx;
try
{
tx = CurrentWallet.MakeTransaction(NeoSystem.StoreView, script);
}
catch (InvalidOperationException e)
{
ConsoleHelper.Error(GetExceptionMessage(e));
Console.WriteLine("Error: " + GetExceptionMessage(e));
return;
}

UInt160 hash = SmartContract.Helper.GetContractHash(tx.Sender, nef.CheckSum, manifest.Name);

ConsoleHelper.Info("Contract hash: ", $"{hash}");
Expand All @@ -60,7 +62,7 @@ private void OnDeployCommand(string filePath, string manifestPath = null, JObjec
/// <param name="filePath">File path</param>
/// <param name="manifestPath">Manifest path</param>
[ConsoleCommand("update", Category = "Contract Commands")]
private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifestPath, UInt160 sender, UInt160[] signerAccounts = null, JObject data = null)
private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifestPath, UInt160 sender, UInt160[] signerAccounts = null)
{
Signer[] signers = Array.Empty<Signer>();

Expand Down Expand Up @@ -91,14 +93,15 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes

try
{
byte[] script = LoadUpdateScript(scriptHash, filePath, manifestPath, data, out var nef, out var manifest);
byte[] script = LoadUpdateScript(scriptHash, filePath, manifestPath, out var nef, out var manifest);
tx = CurrentWallet.MakeTransaction(NeoSystem.StoreView, script, sender, signers);
}
catch (InvalidOperationException e)
{
ConsoleHelper.Error(GetExceptionMessage(e));
return;
}

ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash);
if (contract == null)
{
Expand Down
37 changes: 4 additions & 33 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private bool NoWallet()
return true;
}

private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, JObject data, out NefFile nef, out ContractManifest manifest)
private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, out NefFile nef, out ContractManifest manifest)
{
if (string.IsNullOrEmpty(manifestFilePath))
{
Expand Down Expand Up @@ -259,18 +259,6 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,
nef = stream.ReadSerializable<NefFile>();
}

ContractParameter dataParameter = null;
if (data is not null)
try
{
dataParameter = ContractParameter.FromJson(data);
}
catch
{
throw new FormatException("invalid data");
}


// Basic script checks

Script script = new Script(nef.Script);
Expand All @@ -290,15 +278,12 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,

using (ScriptBuilder sb = new ScriptBuilder())
{
if (dataParameter is not null)
sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nef.ToArray(), manifest.ToJson().ToString(), dataParameter);
else
sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nef.ToArray(), manifest.ToJson().ToString());
sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", nef.ToArray(), manifest.ToJson().ToString());
return sb.ToArray();
}
}

private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string manifestFilePath, JObject data, out NefFile nef, out ContractManifest manifest)
private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string manifestFilePath, out NefFile nef, out ContractManifest manifest)
{
if (string.IsNullOrEmpty(manifestFilePath))
{
Expand Down Expand Up @@ -328,17 +313,6 @@ private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string m
nef = stream.ReadSerializable<NefFile>();
}

ContractParameter dataParameter = null;
if (data is not null)
try
{
dataParameter = ContractParameter.FromJson(data);
}
catch
{
throw new FormatException("invalid data");
}

// Basic script checks

Script script = new Script(nef.Script);
Expand All @@ -358,10 +332,7 @@ private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string m

using (ScriptBuilder sb = new ScriptBuilder())
{
if (dataParameter is null)
sb.EmitDynamicCall(scriptHash, "update", nef.ToArray(), manifest.ToJson().ToString());
else
sb.EmitDynamicCall(scriptHash, "update", nef.ToArray(), manifest.ToJson().ToString(), dataParameter);
sb.EmitDynamicCall(scriptHash, "update", nef.ToArray(), manifest.ToJson().ToString());
return sb.ToArray();
}
}
Expand Down

0 comments on commit 4253aa5

Please sign in to comment.