Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Oracle: Improve user experience #573

Merged
merged 3 commits into from
Apr 23, 2020
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
15 changes: 3 additions & 12 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ private void OnDeployCommand(string filePath, string manifestPath = null)
/// </summary>
/// <param name="scriptHash">Script hash</param>
/// <param name="operation">Operation</param>
/// <param name="contractParameters">Contract parameters</param>
/// <param name="parameters">Contract parameters</param>
/// <param name="witnessAddress">Witness address</param>
/// <param name="oracle">Oracle</param>
[ConsoleCommand("invoke", Category = "Contract Commands")]
private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contractParameters = null, UInt160[] witnessAddress = null, OracleWalletBehaviour oracle = OracleWalletBehaviour.OracleWithAssert)
private void OnInvokeCommand(UInt160 scriptHash, string operation, ContractParameter[] parameters = null, UInt160[] witnessAddress = null, OracleWalletBehaviour oracle = OracleWalletBehaviour.OracleWithAssert)
{
List<ContractParameter> parameters = new List<ContractParameter>();
List<Cosigner> signCollection = new List<Cosigner>();

if (!NoWallet() && witnessAddress != null)
Expand All @@ -80,20 +79,12 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra
}
}

if (contractParameters != null)
{
foreach (var contractParameter in contractParameters)
{
parameters.Add(ContractParameter.FromJson(contractParameter));
}
}

byte[] script;
Transaction tx;

using ScriptBuilder scriptBuilder = new ScriptBuilder();
{
scriptBuilder.EmitAppCall(scriptHash, operation, parameters.ToArray());
scriptBuilder.EmitAppCall(scriptHash, operation, parameters ?? Array.Empty<ContractParameter>());
script = scriptBuilder.ToArray();
Console.WriteLine($"Invoking script with: '{script.ToHexString()}'");
}
Expand Down
2 changes: 2 additions & 0 deletions neo-cli/CLI/MainService.Oracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ private void OnStartOracleCommand(byte numberOfTasks = 4)
ShowPrompt = false;
NeoSystem.StartOracle(CurrentWallet, numberOfTasks);

// TODO: Remove this before merge to master

ApplicationEngine.Log += ApplicationEngine_Log;
}

Expand Down
29 changes: 28 additions & 1 deletion neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,37 @@ public MainService() : base()
RegisterCommandHander<string[], ECPoint[]>((str) => str.Select(u => ECPoint.Parse(u.Trim(), ECCurve.Secp256r1)).ToArray());
RegisterCommandHander<string, JObject>((str) => JObject.Parse(str));
RegisterCommandHander<JObject, JArray>((obj) => (JArray)obj);

RegisterCommandHander<JArray, ContractParameter[]>((arr) => arr.Select(u => ContractParameterFromJson(u)).ToArray());
RegisterCommand(this);
}

private ContractParameter ContractParameterFromJson(JObject json)
{
// As string

if (json is JString)
{
// Is not an array
return new ContractParameter
{
Type = ContractParameterType.String,
Value = json.AsString()
};
}
else if (json is JBoolean)
{
return new ContractParameter
{
Type = ContractParameterType.Boolean,
Value = json.AsBoolean()
};
}

// As array format

return ContractParameter.FromJson(json);
}

public override void RunConsole()
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Expand Down