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

Commit

Permalink
Rebase + fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Thacryba authored and meevee98 committed Mar 31, 2020
1 parent ada8634 commit 924e4d8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 13 deletions.
10 changes: 5 additions & 5 deletions neo-cli/CLI/MainService.Show.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Neo.CommandParser;
using Neo.ConsoleService;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
Expand All @@ -16,7 +16,7 @@ partial class MainService
/// </summary>
/// <param name="desiredCount"></param>
/// <returns></returns>
[ConsoleCommand("show", "last-transactions", HelpCategory = "Show Commands")]
[ConsoleCommand("show last-transactions", Category = "Show Commands")]
private void OnShowLastTransactions(uint desiredCount)
{
if (desiredCount < 1)
Expand Down Expand Up @@ -71,7 +71,7 @@ private void OnShowLastTransactions(uint desiredCount)
/// </summary>
/// <param name="contractHash"></param>
/// <returns></returns>
[ConsoleCommand("show", "contract", HelpCategory = "Show Commands")]
[ConsoleCommand("show contract", Category = "Show Commands")]
private void OnShowContract(string contractHash)
{
if (knownSmartContracts.ContainsKey(contractHash))
Expand Down Expand Up @@ -148,7 +148,7 @@ private string ToCLIString(ContractState c)
/// </summary>
/// <param name="transactionHash"></param>
/// <returns></returns>
[ConsoleCommand("show", "transaction", HelpCategory = "Show Commands")]
[ConsoleCommand("show transaction", Category = "Show Commands")]
private void OnShowTransaction(UInt256 transactionHash)
{
using (var snapshot = Blockchain.Singleton.GetSnapshot())
Expand Down Expand Up @@ -200,7 +200,7 @@ private string ToCLIString(Transaction t, ulong blockTimestamp = 0)
/// </summary>
/// <param name="blockHashOrId"></param>
/// <returns></returns>
[ConsoleCommand("show", "block", HelpCategory = "Show Commands")]
[ConsoleCommand("show block", Category = "Show Commands")]
private void OnShowBlock(string blockHashOrId)
{
if (UInt256.TryParse(blockHashOrId, out var blockHash))
Expand Down
81 changes: 73 additions & 8 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Akka.Actor;
using Microsoft.Extensions.Configuration;
using Neo.ConsoleService;
using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.IO.Json;
using Neo.Ledger;
using Neo.Network.P2P;
using Neo.Network.P2P.Payloads;
using Neo.Plugins;
using Neo.Services;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Native;
using Neo.SmartContract.Native.Tokens;
using Neo.VM;
using Neo.Wallets;
using Neo.Wallets.NEP6;
Expand All @@ -20,7 +20,7 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -75,14 +75,79 @@ private set
/// </summary>
public MainService() : base()
{
RegisterCommandHander<string, UInt160>(false, (str) =>
{
switch (str.ToLowerInvariant())
{
case "neo": return SmartContract.Native.NativeContract.NEO.Hash;
case "gas": return SmartContract.Native.NativeContract.GAS.Hash;
}
// Try to parse as UInt160
if (UInt160.TryParse(str, out var addr))
{
return addr;
}
// Accept wallet format
return str.ToScriptHash();
});

RegisterCommandHander<string, UInt256>(false, (str) => UInt256.Parse(str));
RegisterCommandHander<string[], UInt256[]>((str) => str.Select(u => UInt256.Parse(u.Trim())).ToArray());
RegisterCommandHander<string[], UInt160[]>((arr) =>
{
return arr.Select(str =>
{
switch (str.ToLowerInvariant())
{
case "neo": return SmartContract.Native.NativeContract.NEO.Hash;
case "gas": return SmartContract.Native.NativeContract.GAS.Hash;
}
// Try to parse as UInt160
if (UInt160.TryParse(str, out var addr))
{
return addr;
}
// Accept wallet format
return str.ToScriptHash();
})
.ToArray();
});

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

RegisterCommand(this);

foreach (var plugin in Plugin.Plugins)
{
// Register plugins commands

RegisterCommand(plugin);
RegisterCommand(plugin, plugin.Name);
}
}

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

var cliV = Assembly.GetAssembly(typeof(Program)).GetVersion();
var neoV = Assembly.GetAssembly(typeof(NeoSystem)).GetVersion();
var vmV = Assembly.GetAssembly(typeof(ExecutionEngine)).GetVersion();
Console.WriteLine($"{ServiceName} v{cliV} - NEO v{neoV} - NEO-VM v{vmV}");
Console.WriteLine();

base.RunConsole();
}

public void CreateWallet(string path, string password)
{
switch (Path.GetExtension(path))
Expand Down Expand Up @@ -331,13 +396,13 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,
}
}

protected internal override void OnStart(string[] args)
public override void OnStart(string[] args)
{
base.OnStart(args);
Start(args);
}

protected internal override void OnStop()
public override void OnStop()
{
base.OnStop();
Stop();
Expand Down Expand Up @@ -426,7 +491,7 @@ public async void Start(string[] args)
{
Console.WriteLine($"Warning: wallet file \"{Settings.Default.UnlockWallet.Path}\" not found.");
}
catch (CryptographicException)
catch (System.Security.Cryptography.CryptographicException)
{
Console.WriteLine($"failed to open file \"{Settings.Default.UnlockWallet.Path}\"");
}
Expand Down

0 comments on commit 924e4d8

Please sign in to comment.