From e06b2bb563f4354e59571548d5ede89fbdb61b1c Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 14 Aug 2021 11:20:04 +0800 Subject: [PATCH 01/29] user friendly cli log system --- Neo.ConsoleService/ConsoleServiceBase.cs | 10 +-- neo-cli/CLI/MainService.NEP17.cs | 2 +- neo-cli/CLI/MainService.Network.cs | 10 +-- neo-cli/CLI/MainService.Node.cs | 10 ++- neo-cli/CLI/MainService.Plugins.cs | 10 +-- neo-cli/CLI/MainService.Vote.cs | 28 ++++---- neo-cli/CLI/MainService.Wallet.cs | 81 ++++++++++++------------ neo-cli/CLI/MainService.cs | 20 +++--- 8 files changed, 88 insertions(+), 83 deletions(-) diff --git a/Neo.ConsoleService/ConsoleServiceBase.cs b/Neo.ConsoleService/ConsoleServiceBase.cs index 711daba11..88952faad 100644 --- a/Neo.ConsoleService/ConsoleServiceBase.cs +++ b/Neo.ConsoleService/ConsoleServiceBase.cs @@ -514,7 +514,7 @@ public void Run(string[] args) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { - Console.WriteLine("Only support for installing services on Windows."); + ConsoleLog.Warning("Only support for installing services on Windows."); return; } string arguments = string.Format("create {0} start= auto binPath= \"{1}\"", ServiceName, Process.GetCurrentProcess().MainModule.FileName); @@ -536,7 +536,7 @@ public void Run(string[] args) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { - Console.WriteLine("Only support for installing services on Windows."); + ConsoleLog.Warning("Only support for installing services on Windows."); return; } Process process = Process.Start(new ProcessStartInfo @@ -609,16 +609,16 @@ public virtual void RunConsole() { if (!OnCommand(line)) { - Console.WriteLine("error: Command not found"); + ConsoleLog.Error("Command not found"); } } catch (TargetInvocationException ex) { - Console.WriteLine($"error: {ex.InnerException.Message}"); + ConsoleLog.Error($" {ex.InnerException.Message}"); } catch (Exception ex) { - Console.WriteLine($"error: {ex.Message}"); + ConsoleLog.Error($" {ex.Message}"); } } diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index 099019334..f9afe43f6 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -52,7 +52,7 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount, UI } catch (InvalidOperationException e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleLog.Error(GetExceptionMessage(e)); return; } if (!ReadUserInput("Relay tx(no|yes)").IsYes()) diff --git a/neo-cli/CLI/MainService.Network.cs b/neo-cli/CLI/MainService.Network.cs index 50cd9a1d6..1c6a13233 100644 --- a/neo-cli/CLI/MainService.Network.cs +++ b/neo-cli/CLI/MainService.Network.cs @@ -24,7 +24,7 @@ private void OnBroadcastAddressCommand(IPAddress payload, ushort port) { if (payload == null) { - Console.WriteLine("You must input the payload to relay."); + ConsoleLog.Warning("You must input the payload to relay."); return; } @@ -124,7 +124,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) { if (jsonObjectToRelay == null) { - Console.WriteLine("You must input JSON object to relay."); + ConsoleLog.Warning("You must input JSON object to relay."); return; } @@ -133,12 +133,12 @@ private void OnRelayCommand(JObject jsonObjectToRelay) ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToRelay.ToString(), NeoSystem.StoreView); if (!context.Completed) { - Console.WriteLine("The signature is incomplete."); + ConsoleLog.Error("The signature is incomplete."); return; } if (!(context.Verifiable is Transaction tx)) { - Console.WriteLine($"Only support to relay transaction."); + ConsoleLog.Warning($"Only support to relay transaction."); return; } tx.Witnesses = context.GetWitnesses(); @@ -147,7 +147,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) } catch (Exception e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleLog.Error(GetExceptionMessage(e)); } } } diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index f94ec0af2..d910de6c5 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -76,8 +76,14 @@ private void OnShowStateCommand() int linesWritten = 1; foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray()) { - Console.WriteLine( - $" ip: {node.Remote.Address,-15}\tport: {node.Remote.Port,-5}\tlisten: {node.ListenerTcpPort,-5}\theight: {node.LastBlockIndex,-7}"); + ConsoleLog.Info($"\r ip: ", + $"{ node.Remote.Address,-15}\t", + $"port: ", + $"{node.Remote.Port,-5}\t", + $"listen: ", + $"{node.ListenerTcpPort,-5}\t", + $"height: ", + $"{node.LastBlockIndex,-7}"); linesWritten++; } diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 0d1271190..400e67432 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -54,7 +54,7 @@ private void OnInstallCommand(string pluginName) try { zip.ExtractToDirectory("."); - Console.WriteLine($"Install successful, please restart neo-cli."); + ConsoleLog.Warning($"Install successful, please restart neo-cli."); } catch (IOException) { @@ -73,12 +73,12 @@ private void OnUnInstallCommand(string pluginName) var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName); if (plugin is null) { - Console.WriteLine("Plugin not found"); + ConsoleLog.Warning("Plugin not found"); return; } if (plugin is Logger) { - Console.WriteLine("You cannot uninstall a built-in plugin."); + ConsoleLog.Error("You cannot uninstall a built-in plugin."); return; } @@ -91,7 +91,7 @@ private void OnUnInstallCommand(string pluginName) catch (IOException) { } - Console.WriteLine($"Uninstall successful, please restart neo-cli."); + ConsoleLog.Warning($"Uninstall successful, please restart neo-cli."); } /// @@ -106,7 +106,7 @@ private void OnPluginsCommand() foreach (Plugin plugin in Plugin.Plugins) { if (plugin is Logger) continue; - Console.WriteLine($"\t{plugin.Name,-20}{plugin.Description}"); + ConsoleLog.Info($"\t{plugin.Name,-20}", $"{plugin.Description}"); } } else diff --git a/neo-cli/CLI/MainService.Vote.cs b/neo-cli/CLI/MainService.Vote.cs index 2792933c6..fae6fbcef 100644 --- a/neo-cli/CLI/MainService.Vote.cs +++ b/neo-cli/CLI/MainService.Vote.cs @@ -25,7 +25,7 @@ private void OnRegisterCandidateCommand(UInt160 account) if (NoWallet()) { - Console.WriteLine("Need open wallet!"); + ConsoleLog.Warning("Need open wallet!"); return; } @@ -33,14 +33,14 @@ private void OnRegisterCandidateCommand(UInt160 account) if (currentAccount == null) { - Console.WriteLine("This address isn't in your wallet!"); + ConsoleLog.Warning("This address isn't in your wallet!"); return; } else { if (currentAccount.Lock || currentAccount.WatchOnly) { - Console.WriteLine("Locked or WatchOnly address."); + ConsoleLog.Warning("Locked or WatchOnly address."); return; } } @@ -65,7 +65,7 @@ private void OnUnregisterCandidateCommand(UInt160 account) { if (NoWallet()) { - Console.WriteLine("Need open wallet!"); + ConsoleLog.Warning("Need open wallet!"); return; } @@ -73,14 +73,14 @@ private void OnUnregisterCandidateCommand(UInt160 account) if (currentAccount == null) { - Console.WriteLine("This address isn't in your wallet!"); + ConsoleLog.Warning("This address isn't in your wallet!"); return; } else { if (currentAccount.Lock || currentAccount.WatchOnly) { - Console.WriteLine("Locked or WatchOnly address."); + ConsoleLog.Warning("Locked or WatchOnly address."); return; } } @@ -106,7 +106,7 @@ private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) { if (NoWallet()) { - Console.WriteLine("Need open wallet!"); + ConsoleLog.Warning("Need open wallet!"); return; } @@ -129,7 +129,7 @@ private void OnUnvoteCommand(UInt160 senderAccount) { if (NoWallet()) { - Console.WriteLine("Need open wallet!"); + ConsoleLog.Warning("Need open wallet!"); return; } @@ -156,7 +156,7 @@ private void OnGetCandidatesCommand() if (resJArray.Count > 0) { Console.WriteLine(); - Console.WriteLine("Candidates:"); + ConsoleLog.Info("Candidates:"); foreach (var item in resJArray) { @@ -181,7 +181,7 @@ private void OnGetCommitteeCommand() if (resJArray.Count > 0) { Console.WriteLine(); - Console.WriteLine("Committee:"); + ConsoleLog.Info("Committee:"); foreach (var item in resJArray) { @@ -203,7 +203,7 @@ private void OnGetNextBlockValidatorsCommand() if (resJArray.Count > 0) { Console.WriteLine(); - Console.WriteLine("Next validators:"); + ConsoleLog.Info("Next validators:"); foreach (var item in resJArray) { @@ -240,9 +240,9 @@ private void OnGetAccountState(UInt160 address) } } var publickey = ECPoint.Parse(((ByteString)resJArray?[2])?.GetSpan().ToHexString(), ECCurve.Secp256r1); - Console.WriteLine("Voted: " + Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); - Console.WriteLine("Amount: " + new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)); - Console.WriteLine("Block: " + ((Integer)resJArray?[1]).GetInteger()); + ConsoleLog.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); + ConsoleLog.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}"); + ConsoleLog.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}"); } } } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index a35c2f29f..4b619586c 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -28,7 +28,7 @@ private void OnOpenWallet(string path) { if (!File.Exists(path)) { - Console.WriteLine($"File does not exist"); + ConsoleLog.Error($"File does not exist"); return; } string password = ReadUserInput("password", true); @@ -43,7 +43,7 @@ private void OnOpenWallet(string path) } catch (System.Security.Cryptography.CryptographicException) { - Console.WriteLine($"Failed to open file \"{path}\""); + ConsoleLog.Error($"Failed to open file \"{path}\""); } } @@ -55,7 +55,7 @@ private void OnCloseWalletCommand() { if (CurrentWallet == null) { - Console.WriteLine($"Wallet is not opened"); + ConsoleLog.Warning($"Wallet is not opened"); return; } CurrentWallet = null; @@ -70,12 +70,12 @@ private void OnUpgradeWalletCommand(string path) { if (Path.GetExtension(path).ToLowerInvariant() != ".db3") { - Console.WriteLine("Can't upgrade the wallet file."); + ConsoleLog.Warning("Can't upgrade the wallet file."); return; } if (!File.Exists(path)) { - Console.WriteLine("File does not exist."); + ConsoleLog.Error("File does not exist."); return; } string password = ReadUserInput("password", true); @@ -129,7 +129,7 @@ private void OnCreateAddressCommand(ushort count = 1) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - Console.WriteLine($"Export addresses to {path}"); + ConsoleLog.Info($"Export addresses to", $" {path}"); File.WriteAllLines(path, addresses); } @@ -144,7 +144,7 @@ private void OnExportKeyCommand(string path = null, UInt160 scriptHash = null) if (NoWallet()) return; if (path != null && File.Exists(path)) { - Console.WriteLine($"Error: File '{path}' already exists"); + ConsoleLog.Error($"File '{path}' already exists"); return; } string password = ReadUserInput("password", true); @@ -188,7 +188,7 @@ private void OnCreateWalletCommand(string path) string password2 = ReadUserInput("password", true); if (password != password2) { - Console.WriteLine("Error"); + ConsoleLog.Error("Two passwords not match."); return; } if (!File.Exists(path)) @@ -215,7 +215,7 @@ private void OnImportMultisigAddress(ushort m, ECPoint[] publicKeys) if (m < 1 || m > n || n > 1024) { - Console.WriteLine("Error. Invalid parameters."); + ConsoleLog.Error("Invalid parameters."); return; } @@ -226,7 +226,7 @@ private void OnImportMultisigAddress(ushort m, ECPoint[] publicKeys) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - Console.WriteLine("Multisig. Addr.: " + multiSignContract.ScriptHash.ToAddress(NeoSystem.Settings.AddressVersion)); + ConsoleLog.Info("Multisig. Addr.: ", multiSignContract.ScriptHash.ToAddress(NeoSystem.Settings.AddressVersion)); } /// @@ -247,7 +247,7 @@ private void OnImportKeyCommand(string wifOrFile) if (!fileInfo.Exists) { - Console.WriteLine($"Error: File '{fileInfo.FullName}' doesn't exists"); + ConsoleLog.Error($"File '{fileInfo.FullName}' doesn't exists"); return; } @@ -278,8 +278,8 @@ private void OnImportKeyCommand(string wifOrFile) { WalletAccount account = CurrentWallet.CreateAccount(prikey); Array.Clear(prikey, 0, prikey.Length); - Console.WriteLine($"Address: {account.Address}"); - Console.WriteLine($" Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleLog.Info($"Address:", $" {account.Address}"); + ConsoleLog.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -303,7 +303,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) if (!fileInfo.Exists) { - Console.WriteLine($"Error: File '{fileInfo.FullName}' doesn't exists"); + ConsoleLog.Error($"File '{fileInfo.FullName}' doesn't exists"); return; } @@ -329,7 +329,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) else { WalletAccount account = CurrentWallet.CreateAccount(address); - Console.WriteLine($"Address: {account.Address}"); + ConsoleLog.Info($"Address:", $" {account.Address}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -366,8 +366,8 @@ private void OnListAddressCommand() type = "Deployed-Nonstandard"; } - Console.WriteLine($"{" Address: "}{account.Address}\t{type}"); - Console.WriteLine($"{"ScriptHash: "}{account.ScriptHash}\n"); + ConsoleLog.Info($"{" Address: "}", $"{account.Address}\t{type}"); + ConsoleLog.Info($"{"ScriptHash: "}", $"{account.ScriptHash}\n"); } } @@ -387,10 +387,10 @@ private void OnListAssetCommand() Console.WriteLine(); } Console.WriteLine("----------------------------------------------------"); - Console.WriteLine($"Total: NEO: {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); + ConsoleLog.Info($"Total: NEO:", $" {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); Console.WriteLine(); - Console.WriteLine("NEO hash: " + NativeContract.NEO.Hash); - Console.WriteLine("GAS hash: " + NativeContract.GAS.Hash); + ConsoleLog.Info("NEO hash: ", $" {NativeContract.NEO.Hash}"); + ConsoleLog.Info("GAS hash: ", $" {NativeContract.GAS.Hash}"); } /// @@ -402,9 +402,9 @@ private void OnListKeyCommand() if (NoWallet()) return; foreach (WalletAccount account in CurrentWallet.GetAccounts().Where(p => p.HasKey)) { - Console.WriteLine($" Address: {account.Address}"); - Console.WriteLine($"ScriptHash: {account.ScriptHash}"); - Console.WriteLine($" PublicKey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); + ConsoleLog.Info($" Address:", $" { account.Address}"); + ConsoleLog.Info($"ScriptHash:", $" { account.ScriptHash}"); + ConsoleLog.Info($" PublicKey:", $" { account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); } } @@ -419,7 +419,7 @@ private void OnSignCommand(JObject jsonObjectToSign) if (jsonObjectToSign == null) { - Console.WriteLine("You must input JSON object pending signature data."); + ConsoleLog.Warning("You must input JSON object pending signature data."); return; } try @@ -428,7 +428,7 @@ private void OnSignCommand(JObject jsonObjectToSign) ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToSign.ToString(), snapshot); if (context.Network != neoSystem.Settings.Network) { - Console.WriteLine("Network mismatch."); + ConsoleLog.Warning("Network mismatch."); return; } else if (!CurrentWallet.Sign(context)) @@ -440,7 +440,7 @@ private void OnSignCommand(JObject jsonObjectToSign) } catch (Exception e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleLog.Error(GetExceptionMessage(e)); } } @@ -465,7 +465,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } if (!CurrentWallet.VerifyPassword(password)) { - Console.WriteLine("Incorrect password"); + ConsoleLog.Warning("Incorrect password"); return; } var snapshot = NeoSystem.StoreView; @@ -473,7 +473,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro AssetDescriptor descriptor = new AssetDescriptor(snapshot, NeoSystem.Settings, asset); if (!BigDecimal.TryParse(amount, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0) { - Console.WriteLine("Incorrect Amount Format"); + ConsoleLog.Warning("Incorrect Amount Format"); return; } try @@ -497,13 +497,13 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } catch (Exception e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleLog.Error(GetExceptionMessage(e)); return; } if (tx == null) { - Console.WriteLine("Insufficient funds"); + ConsoleLog.Warning("Insufficient funds"); return; } @@ -513,12 +513,11 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - Console.WriteLine($"TXID: {tx.Hash}"); + ConsoleLog.Info($"TXID:", $" {tx.Hash}"); } else { - Console.WriteLine("SignatureContext:"); - Console.WriteLine(context.ToString()); + ConsoleLog.Info("SignatureContext:\n", context.ToString()); } } @@ -534,7 +533,7 @@ private void OnShowGasCommand() uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1; foreach (UInt160 account in CurrentWallet.GetAccounts().Select(p => p.ScriptHash)) gas += NativeContract.NEO.UnclaimedGas(snapshot, account, height); - Console.WriteLine($"Unclaimed gas: {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); + ConsoleLog.Info($"Unclaimed gas:", $" {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); } /// @@ -552,14 +551,14 @@ private void OnChangePasswordCommand() } if (!CurrentWallet.VerifyPassword(oldPassword)) { - Console.WriteLine("Incorrect password"); + ConsoleLog.Error("Incorrect password"); return; } string newPassword = ReadUserInput("New password", true); string newPasswordReEntered = ReadUserInput("Re-Enter Password", true); if (!newPassword.Equals(newPasswordReEntered)) { - Console.WriteLine("Two passwords entered are inconsistent!"); + ConsoleLog.Error("Two passwords entered are inconsistent!"); return; } @@ -568,7 +567,7 @@ private void OnChangePasswordCommand() string backupFile = wallet.Path + ".bak"; if (!File.Exists(wallet.Path) || File.Exists(backupFile)) { - Console.WriteLine("Wallet backup fail"); + ConsoleLog.Error("Wallet backup fail"); return; } try @@ -577,7 +576,7 @@ private void OnChangePasswordCommand() } catch (IOException) { - Console.WriteLine("Wallet backup fail"); + ConsoleLog.Error("Wallet backup fail"); return; } } @@ -591,7 +590,7 @@ private void OnChangePasswordCommand() } else { - Console.WriteLine("Failed to change password"); + ConsoleLog.Error("Failed to change password"); } } @@ -604,7 +603,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } catch (InvalidOperationException e) { - Console.WriteLine($"Error creating contract params: " + GetExceptionMessage(e)); + ConsoleLog.Error($"Failed creating contract params: " + GetExceptionMessage(e)); throw; } CurrentWallet.Sign(context); @@ -616,7 +615,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } else { - Console.WriteLine("Incomplete signature:"); + ConsoleLog.Error("Incomplete signature:"); Console.WriteLine(context.ToString()); } } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 99d336376..5b1c2ab50 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -435,15 +435,15 @@ public async void Start(string[] args) } catch (FileNotFoundException) { - Console.WriteLine($"Warning: wallet file \"{Settings.Default.UnlockWallet.Path}\" not found."); + ConsoleLog.Warning($"wallet file \"{Settings.Default.UnlockWallet.Path}\" not found."); } catch (System.Security.Cryptography.CryptographicException) { - Console.WriteLine($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\""); + ConsoleLog.Error($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\""); } catch (Exception ex) { - Console.WriteLine($"error: {ex.GetBaseException().Message}"); + ConsoleLog.Error($"{ex.GetBaseException().Message}"); } } } @@ -546,7 +546,7 @@ private void SendTransaction(byte[] script, UInt160 account = null, long gas = T } catch (InvalidOperationException e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleLog.Error(GetExceptionMessage(e)); return; } @@ -579,7 +579,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash); if (contract == null) { - Console.WriteLine("Contract does not exist."); + ConsoleLog.Warning("Contract does not exist."); result = StackItem.Null; return false; } @@ -587,7 +587,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI { if (contract.Manifest.Abi.GetMethod(operation, parameters.Count) == null) { - Console.WriteLine("This method does not not exist in this contract."); + ConsoleLog.Warning("This method does not not exist in this contract."); result = StackItem.Null; return false; } @@ -615,14 +615,14 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI private void PrintExecutionOutput(ApplicationEngine engine, bool showStack = true) { - Console.WriteLine($"VM State: {engine.State}"); - Console.WriteLine($"Gas Consumed: {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); + ConsoleLog.Info($"VM State:", $" {engine.State}"); + ConsoleLog.Info($"Gas Consumed:", $" {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); if (showStack) - Console.WriteLine($"Result Stack: {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); + ConsoleLog.Info($"Result Stack:", $" {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); if (engine.State == VMState.FAULT) - Console.WriteLine("Error: " + GetExceptionMessage(engine.FaultException)); + ConsoleLog.Error(GetExceptionMessage(engine.FaultException)); } static string GetExceptionMessage(Exception exception) From cfd68318d73da5e45fd353ca1474e4f7b5ee6f55 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 14 Aug 2021 11:20:21 +0800 Subject: [PATCH 02/29] add log class --- Neo.ConsoleService/ConsoleLog.cs | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Neo.ConsoleService/ConsoleLog.cs diff --git a/Neo.ConsoleService/ConsoleLog.cs b/Neo.ConsoleService/ConsoleLog.cs new file mode 100644 index 000000000..39155cdad --- /dev/null +++ b/Neo.ConsoleService/ConsoleLog.cs @@ -0,0 +1,45 @@ +using System; + +namespace Neo.ConsoleService +{ + public class ConsoleLog + { + public static void WriteLine(string msg) + { + Console.WriteLine(msg); + } + + public static void Info(params string[] values) + { + for (int i = 0; i < values.Length; i++) + { + Console.ForegroundColor = ConsoleColor.Cyan; + if (i % 2 == 1) + Console.ForegroundColor = ConsoleColor.White; + Console.Write(values[i]); + } + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine(); + } + + public static void Warning(string msg) + { + Log("Warning", ConsoleColor.Yellow, msg); + } + + public static void Error(string msg) + { + Log("Error", ConsoleColor.Red, msg); + } + + private static void Log(string tag, ConsoleColor tagColor, string msg, ConsoleColor msgColor = ConsoleColor.White) + { + Console.ForegroundColor = tagColor; + Console.Write($"{tag}: "); + Console.ForegroundColor = msgColor; + Console.WriteLine(msg); + } + + + } +} From 49c9813f8c89c74bc706d8f750cc3b8fe78c2f7a Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 14 Aug 2021 11:29:34 +0800 Subject: [PATCH 03/29] add more log to wallet --- neo-cli/CLI/MainService.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 5b1c2ab50..ff1286264 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -131,9 +131,9 @@ public void CreateWallet(string path, string password) { UserWallet wallet = UserWallet.Create(path, password, NeoSystem.Settings); WalletAccount account = wallet.CreateAccount(); - Console.WriteLine($" Address: {account.Address}"); - Console.WriteLine($" Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - Console.WriteLine($"ScriptHash: {account.ScriptHash}"); + ConsoleLog.Info($" Address:", $" {account.Address}"); + ConsoleLog.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleLog.Info($"ScriptHash:", $" {account.ScriptHash}"); CurrentWallet = wallet; } break; @@ -143,9 +143,9 @@ public void CreateWallet(string path, string password) wallet.Unlock(password); WalletAccount account = wallet.CreateAccount(); wallet.Save(); - Console.WriteLine($" Address: {account.Address}"); - Console.WriteLine($" Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - Console.WriteLine($"ScriptHash: {account.ScriptHash}"); + ConsoleLog.Info($" Address:", $" {account.Address}"); + ConsoleLog.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleLog.Info($"ScriptHash:", $" {account.ScriptHash}"); CurrentWallet = wallet; } break; From 067367793407464da56ef7c0eeaa3af47aebcf7d Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 14 Aug 2021 11:35:29 +0800 Subject: [PATCH 04/29] fix format --- Neo.ConsoleService/ConsoleLog.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Neo.ConsoleService/ConsoleLog.cs b/Neo.ConsoleService/ConsoleLog.cs index 39155cdad..6355af769 100644 --- a/Neo.ConsoleService/ConsoleLog.cs +++ b/Neo.ConsoleService/ConsoleLog.cs @@ -32,14 +32,12 @@ public static void Error(string msg) Log("Error", ConsoleColor.Red, msg); } - private static void Log(string tag, ConsoleColor tagColor, string msg, ConsoleColor msgColor = ConsoleColor.White) + private static void Log(string tag, ConsoleColor tagColor, string msg, ConsoleColor msgColor = ConsoleColor.White) { Console.ForegroundColor = tagColor; Console.Write($"{tag}: "); Console.ForegroundColor = msgColor; Console.WriteLine(msg); } - - } } From e9504f2450d2cb07425ed60f5e2f2dfc03319387 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sun, 15 Aug 2021 19:42:27 +0800 Subject: [PATCH 05/29] change `consolelog` to `consolewrite` --- Neo.ConsoleService/ConsoleServiceBase.cs | 10 +-- .../{ConsoleLog.cs => ConsoleWrite.cs} | 2 +- neo-cli/CLI/MainService.NEP17.cs | 2 +- neo-cli/CLI/MainService.Network.cs | 10 +-- neo-cli/CLI/MainService.Node.cs | 2 +- neo-cli/CLI/MainService.Plugins.cs | 10 +-- neo-cli/CLI/MainService.Vote.cs | 28 +++---- neo-cli/CLI/MainService.Wallet.cs | 80 +++++++++---------- neo-cli/CLI/MainService.cs | 32 ++++---- 9 files changed, 88 insertions(+), 88 deletions(-) rename Neo.ConsoleService/{ConsoleLog.cs => ConsoleWrite.cs} (97%) diff --git a/Neo.ConsoleService/ConsoleServiceBase.cs b/Neo.ConsoleService/ConsoleServiceBase.cs index 88952faad..0dab22884 100644 --- a/Neo.ConsoleService/ConsoleServiceBase.cs +++ b/Neo.ConsoleService/ConsoleServiceBase.cs @@ -514,7 +514,7 @@ public void Run(string[] args) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { - ConsoleLog.Warning("Only support for installing services on Windows."); + ConsoleWrite.Warning("Only support for installing services on Windows."); return; } string arguments = string.Format("create {0} start= auto binPath= \"{1}\"", ServiceName, Process.GetCurrentProcess().MainModule.FileName); @@ -536,7 +536,7 @@ public void Run(string[] args) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { - ConsoleLog.Warning("Only support for installing services on Windows."); + ConsoleWrite.Warning("Only support for installing services on Windows."); return; } Process process = Process.Start(new ProcessStartInfo @@ -609,16 +609,16 @@ public virtual void RunConsole() { if (!OnCommand(line)) { - ConsoleLog.Error("Command not found"); + ConsoleWrite.Error("Command not found"); } } catch (TargetInvocationException ex) { - ConsoleLog.Error($" {ex.InnerException.Message}"); + ConsoleWrite.Error($" {ex.InnerException.Message}"); } catch (Exception ex) { - ConsoleLog.Error($" {ex.Message}"); + ConsoleWrite.Error($" {ex.Message}"); } } diff --git a/Neo.ConsoleService/ConsoleLog.cs b/Neo.ConsoleService/ConsoleWrite.cs similarity index 97% rename from Neo.ConsoleService/ConsoleLog.cs rename to Neo.ConsoleService/ConsoleWrite.cs index 6355af769..c8e021ff5 100644 --- a/Neo.ConsoleService/ConsoleLog.cs +++ b/Neo.ConsoleService/ConsoleWrite.cs @@ -2,7 +2,7 @@ namespace Neo.ConsoleService { - public class ConsoleLog + public class ConsoleWrite { public static void WriteLine(string msg) { diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index f9afe43f6..db7f70ab3 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -52,7 +52,7 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount, UI } catch (InvalidOperationException e) { - ConsoleLog.Error(GetExceptionMessage(e)); + ConsoleWrite.Error(GetExceptionMessage(e)); return; } if (!ReadUserInput("Relay tx(no|yes)").IsYes()) diff --git a/neo-cli/CLI/MainService.Network.cs b/neo-cli/CLI/MainService.Network.cs index 1c6a13233..75fd64aec 100644 --- a/neo-cli/CLI/MainService.Network.cs +++ b/neo-cli/CLI/MainService.Network.cs @@ -24,7 +24,7 @@ private void OnBroadcastAddressCommand(IPAddress payload, ushort port) { if (payload == null) { - ConsoleLog.Warning("You must input the payload to relay."); + ConsoleWrite.Warning("You must input the payload to relay."); return; } @@ -124,7 +124,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) { if (jsonObjectToRelay == null) { - ConsoleLog.Warning("You must input JSON object to relay."); + ConsoleWrite.Warning("You must input JSON object to relay."); return; } @@ -133,12 +133,12 @@ private void OnRelayCommand(JObject jsonObjectToRelay) ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToRelay.ToString(), NeoSystem.StoreView); if (!context.Completed) { - ConsoleLog.Error("The signature is incomplete."); + ConsoleWrite.Error("The signature is incomplete."); return; } if (!(context.Verifiable is Transaction tx)) { - ConsoleLog.Warning($"Only support to relay transaction."); + ConsoleWrite.Warning($"Only support to relay transaction."); return; } tx.Witnesses = context.GetWitnesses(); @@ -147,7 +147,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) } catch (Exception e) { - ConsoleLog.Error(GetExceptionMessage(e)); + ConsoleWrite.Error(GetExceptionMessage(e)); } } } diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index d910de6c5..7e95019b2 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -76,7 +76,7 @@ private void OnShowStateCommand() int linesWritten = 1; foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray()) { - ConsoleLog.Info($"\r ip: ", + ConsoleWrite.Info($"\r ip: ", $"{ node.Remote.Address,-15}\t", $"port: ", $"{node.Remote.Port,-5}\t", diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 400e67432..d65490b4e 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -54,7 +54,7 @@ private void OnInstallCommand(string pluginName) try { zip.ExtractToDirectory("."); - ConsoleLog.Warning($"Install successful, please restart neo-cli."); + ConsoleWrite.Warning($"Install successful, please restart neo-cli."); } catch (IOException) { @@ -73,12 +73,12 @@ private void OnUnInstallCommand(string pluginName) var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName); if (plugin is null) { - ConsoleLog.Warning("Plugin not found"); + ConsoleWrite.Warning("Plugin not found"); return; } if (plugin is Logger) { - ConsoleLog.Error("You cannot uninstall a built-in plugin."); + ConsoleWrite.Error("You cannot uninstall a built-in plugin."); return; } @@ -91,7 +91,7 @@ private void OnUnInstallCommand(string pluginName) catch (IOException) { } - ConsoleLog.Warning($"Uninstall successful, please restart neo-cli."); + ConsoleWrite.Warning($"Uninstall successful, please restart neo-cli."); } /// @@ -106,7 +106,7 @@ private void OnPluginsCommand() foreach (Plugin plugin in Plugin.Plugins) { if (plugin is Logger) continue; - ConsoleLog.Info($"\t{plugin.Name,-20}", $"{plugin.Description}"); + ConsoleWrite.Info($"\t{plugin.Name,-20}", $"{plugin.Description}"); } } else diff --git a/neo-cli/CLI/MainService.Vote.cs b/neo-cli/CLI/MainService.Vote.cs index fae6fbcef..2205d4205 100644 --- a/neo-cli/CLI/MainService.Vote.cs +++ b/neo-cli/CLI/MainService.Vote.cs @@ -25,7 +25,7 @@ private void OnRegisterCandidateCommand(UInt160 account) if (NoWallet()) { - ConsoleLog.Warning("Need open wallet!"); + ConsoleWrite.Warning("Need open wallet!"); return; } @@ -33,14 +33,14 @@ private void OnRegisterCandidateCommand(UInt160 account) if (currentAccount == null) { - ConsoleLog.Warning("This address isn't in your wallet!"); + ConsoleWrite.Warning("This address isn't in your wallet!"); return; } else { if (currentAccount.Lock || currentAccount.WatchOnly) { - ConsoleLog.Warning("Locked or WatchOnly address."); + ConsoleWrite.Warning("Locked or WatchOnly address."); return; } } @@ -65,7 +65,7 @@ private void OnUnregisterCandidateCommand(UInt160 account) { if (NoWallet()) { - ConsoleLog.Warning("Need open wallet!"); + ConsoleWrite.Warning("Need open wallet!"); return; } @@ -73,14 +73,14 @@ private void OnUnregisterCandidateCommand(UInt160 account) if (currentAccount == null) { - ConsoleLog.Warning("This address isn't in your wallet!"); + ConsoleWrite.Warning("This address isn't in your wallet!"); return; } else { if (currentAccount.Lock || currentAccount.WatchOnly) { - ConsoleLog.Warning("Locked or WatchOnly address."); + ConsoleWrite.Warning("Locked or WatchOnly address."); return; } } @@ -106,7 +106,7 @@ private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) { if (NoWallet()) { - ConsoleLog.Warning("Need open wallet!"); + ConsoleWrite.Warning("Need open wallet!"); return; } @@ -129,7 +129,7 @@ private void OnUnvoteCommand(UInt160 senderAccount) { if (NoWallet()) { - ConsoleLog.Warning("Need open wallet!"); + ConsoleWrite.Warning("Need open wallet!"); return; } @@ -156,7 +156,7 @@ private void OnGetCandidatesCommand() if (resJArray.Count > 0) { Console.WriteLine(); - ConsoleLog.Info("Candidates:"); + ConsoleWrite.Info("Candidates:"); foreach (var item in resJArray) { @@ -181,7 +181,7 @@ private void OnGetCommitteeCommand() if (resJArray.Count > 0) { Console.WriteLine(); - ConsoleLog.Info("Committee:"); + ConsoleWrite.Info("Committee:"); foreach (var item in resJArray) { @@ -203,7 +203,7 @@ private void OnGetNextBlockValidatorsCommand() if (resJArray.Count > 0) { Console.WriteLine(); - ConsoleLog.Info("Next validators:"); + ConsoleWrite.Info("Next validators:"); foreach (var item in resJArray) { @@ -240,9 +240,9 @@ private void OnGetAccountState(UInt160 address) } } var publickey = ECPoint.Parse(((ByteString)resJArray?[2])?.GetSpan().ToHexString(), ECCurve.Secp256r1); - ConsoleLog.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); - ConsoleLog.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}"); - ConsoleLog.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}"); + ConsoleWrite.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); + ConsoleWrite.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}"); + ConsoleWrite.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}"); } } } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 4b619586c..7b65a2cda 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -28,7 +28,7 @@ private void OnOpenWallet(string path) { if (!File.Exists(path)) { - ConsoleLog.Error($"File does not exist"); + ConsoleWrite.Error($"File does not exist"); return; } string password = ReadUserInput("password", true); @@ -43,7 +43,7 @@ private void OnOpenWallet(string path) } catch (System.Security.Cryptography.CryptographicException) { - ConsoleLog.Error($"Failed to open file \"{path}\""); + ConsoleWrite.Error($"Failed to open file \"{path}\""); } } @@ -55,7 +55,7 @@ private void OnCloseWalletCommand() { if (CurrentWallet == null) { - ConsoleLog.Warning($"Wallet is not opened"); + ConsoleWrite.Warning($"Wallet is not opened"); return; } CurrentWallet = null; @@ -70,12 +70,12 @@ private void OnUpgradeWalletCommand(string path) { if (Path.GetExtension(path).ToLowerInvariant() != ".db3") { - ConsoleLog.Warning("Can't upgrade the wallet file."); + ConsoleWrite.Warning("Can't upgrade the wallet file."); return; } if (!File.Exists(path)) { - ConsoleLog.Error("File does not exist."); + ConsoleWrite.Error("File does not exist."); return; } string password = ReadUserInput("password", true); @@ -129,7 +129,7 @@ private void OnCreateAddressCommand(ushort count = 1) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - ConsoleLog.Info($"Export addresses to", $" {path}"); + ConsoleWrite.Info($"Export addresses to", $" {path}"); File.WriteAllLines(path, addresses); } @@ -144,7 +144,7 @@ private void OnExportKeyCommand(string path = null, UInt160 scriptHash = null) if (NoWallet()) return; if (path != null && File.Exists(path)) { - ConsoleLog.Error($"File '{path}' already exists"); + ConsoleWrite.Error($"File '{path}' already exists"); return; } string password = ReadUserInput("password", true); @@ -188,7 +188,7 @@ private void OnCreateWalletCommand(string path) string password2 = ReadUserInput("password", true); if (password != password2) { - ConsoleLog.Error("Two passwords not match."); + ConsoleWrite.Error("Two passwords not match."); return; } if (!File.Exists(path)) @@ -215,7 +215,7 @@ private void OnImportMultisigAddress(ushort m, ECPoint[] publicKeys) if (m < 1 || m > n || n > 1024) { - ConsoleLog.Error("Invalid parameters."); + ConsoleWrite.Error("Invalid parameters."); return; } @@ -226,7 +226,7 @@ private void OnImportMultisigAddress(ushort m, ECPoint[] publicKeys) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - ConsoleLog.Info("Multisig. Addr.: ", multiSignContract.ScriptHash.ToAddress(NeoSystem.Settings.AddressVersion)); + ConsoleWrite.Info("Multisig. Addr.: ", multiSignContract.ScriptHash.ToAddress(NeoSystem.Settings.AddressVersion)); } /// @@ -247,7 +247,7 @@ private void OnImportKeyCommand(string wifOrFile) if (!fileInfo.Exists) { - ConsoleLog.Error($"File '{fileInfo.FullName}' doesn't exists"); + ConsoleWrite.Error($"File '{fileInfo.FullName}' doesn't exists"); return; } @@ -278,8 +278,8 @@ private void OnImportKeyCommand(string wifOrFile) { WalletAccount account = CurrentWallet.CreateAccount(prikey); Array.Clear(prikey, 0, prikey.Length); - ConsoleLog.Info($"Address:", $" {account.Address}"); - ConsoleLog.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleWrite.Info($"Address:", $" {account.Address}"); + ConsoleWrite.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -303,7 +303,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) if (!fileInfo.Exists) { - ConsoleLog.Error($"File '{fileInfo.FullName}' doesn't exists"); + ConsoleWrite.Error($"File '{fileInfo.FullName}' doesn't exists"); return; } @@ -329,7 +329,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) else { WalletAccount account = CurrentWallet.CreateAccount(address); - ConsoleLog.Info($"Address:", $" {account.Address}"); + ConsoleWrite.Info($"Address:", $" {account.Address}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -366,8 +366,8 @@ private void OnListAddressCommand() type = "Deployed-Nonstandard"; } - ConsoleLog.Info($"{" Address: "}", $"{account.Address}\t{type}"); - ConsoleLog.Info($"{"ScriptHash: "}", $"{account.ScriptHash}\n"); + ConsoleWrite.Info($"{" Address: "}", $"{account.Address}\t{type}"); + ConsoleWrite.Info($"{"ScriptHash: "}", $"{account.ScriptHash}\n"); } } @@ -387,10 +387,10 @@ private void OnListAssetCommand() Console.WriteLine(); } Console.WriteLine("----------------------------------------------------"); - ConsoleLog.Info($"Total: NEO:", $" {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); + ConsoleWrite.Info($"Total: NEO:", $" {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); Console.WriteLine(); - ConsoleLog.Info("NEO hash: ", $" {NativeContract.NEO.Hash}"); - ConsoleLog.Info("GAS hash: ", $" {NativeContract.GAS.Hash}"); + ConsoleWrite.Info("NEO hash: ", $" {NativeContract.NEO.Hash}"); + ConsoleWrite.Info("GAS hash: ", $" {NativeContract.GAS.Hash}"); } /// @@ -402,9 +402,9 @@ private void OnListKeyCommand() if (NoWallet()) return; foreach (WalletAccount account in CurrentWallet.GetAccounts().Where(p => p.HasKey)) { - ConsoleLog.Info($" Address:", $" { account.Address}"); - ConsoleLog.Info($"ScriptHash:", $" { account.ScriptHash}"); - ConsoleLog.Info($" PublicKey:", $" { account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); + ConsoleWrite.Info($" Address:", $" { account.Address}"); + ConsoleWrite.Info($"ScriptHash:", $" { account.ScriptHash}"); + ConsoleWrite.Info($" PublicKey:", $" { account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); } } @@ -419,7 +419,7 @@ private void OnSignCommand(JObject jsonObjectToSign) if (jsonObjectToSign == null) { - ConsoleLog.Warning("You must input JSON object pending signature data."); + ConsoleWrite.Warning("You must input JSON object pending signature data."); return; } try @@ -428,7 +428,7 @@ private void OnSignCommand(JObject jsonObjectToSign) ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToSign.ToString(), snapshot); if (context.Network != neoSystem.Settings.Network) { - ConsoleLog.Warning("Network mismatch."); + ConsoleWrite.Warning("Network mismatch."); return; } else if (!CurrentWallet.Sign(context)) @@ -440,7 +440,7 @@ private void OnSignCommand(JObject jsonObjectToSign) } catch (Exception e) { - ConsoleLog.Error(GetExceptionMessage(e)); + ConsoleWrite.Error(GetExceptionMessage(e)); } } @@ -465,7 +465,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } if (!CurrentWallet.VerifyPassword(password)) { - ConsoleLog.Warning("Incorrect password"); + ConsoleWrite.Warning("Incorrect password"); return; } var snapshot = NeoSystem.StoreView; @@ -473,7 +473,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro AssetDescriptor descriptor = new AssetDescriptor(snapshot, NeoSystem.Settings, asset); if (!BigDecimal.TryParse(amount, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0) { - ConsoleLog.Warning("Incorrect Amount Format"); + ConsoleWrite.Warning("Incorrect Amount Format"); return; } try @@ -497,13 +497,13 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } catch (Exception e) { - ConsoleLog.Error(GetExceptionMessage(e)); + ConsoleWrite.Error(GetExceptionMessage(e)); return; } if (tx == null) { - ConsoleLog.Warning("Insufficient funds"); + ConsoleWrite.Warning("Insufficient funds"); return; } @@ -513,11 +513,11 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - ConsoleLog.Info($"TXID:", $" {tx.Hash}"); + ConsoleWrite.Info($"TXID:", $" {tx.Hash}"); } else { - ConsoleLog.Info("SignatureContext:\n", context.ToString()); + ConsoleWrite.Info("SignatureContext:\n", context.ToString()); } } @@ -533,7 +533,7 @@ private void OnShowGasCommand() uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1; foreach (UInt160 account in CurrentWallet.GetAccounts().Select(p => p.ScriptHash)) gas += NativeContract.NEO.UnclaimedGas(snapshot, account, height); - ConsoleLog.Info($"Unclaimed gas:", $" {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); + ConsoleWrite.Info($"Unclaimed gas:", $" {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); } /// @@ -551,14 +551,14 @@ private void OnChangePasswordCommand() } if (!CurrentWallet.VerifyPassword(oldPassword)) { - ConsoleLog.Error("Incorrect password"); + ConsoleWrite.Error("Incorrect password"); return; } string newPassword = ReadUserInput("New password", true); string newPasswordReEntered = ReadUserInput("Re-Enter Password", true); if (!newPassword.Equals(newPasswordReEntered)) { - ConsoleLog.Error("Two passwords entered are inconsistent!"); + ConsoleWrite.Error("Two passwords entered are inconsistent!"); return; } @@ -567,7 +567,7 @@ private void OnChangePasswordCommand() string backupFile = wallet.Path + ".bak"; if (!File.Exists(wallet.Path) || File.Exists(backupFile)) { - ConsoleLog.Error("Wallet backup fail"); + ConsoleWrite.Error("Wallet backup fail"); return; } try @@ -576,7 +576,7 @@ private void OnChangePasswordCommand() } catch (IOException) { - ConsoleLog.Error("Wallet backup fail"); + ConsoleWrite.Error("Wallet backup fail"); return; } } @@ -590,7 +590,7 @@ private void OnChangePasswordCommand() } else { - ConsoleLog.Error("Failed to change password"); + ConsoleWrite.Error("Failed to change password"); } } @@ -603,7 +603,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } catch (InvalidOperationException e) { - ConsoleLog.Error($"Failed creating contract params: " + GetExceptionMessage(e)); + ConsoleWrite.Error($"Failed creating contract params: " + GetExceptionMessage(e)); throw; } CurrentWallet.Sign(context); @@ -615,7 +615,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } else { - ConsoleLog.Error("Incomplete signature:"); + ConsoleWrite.Error("Incomplete signature:"); Console.WriteLine(context.ToString()); } } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index ff1286264..b11d7937c 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -131,9 +131,9 @@ public void CreateWallet(string path, string password) { UserWallet wallet = UserWallet.Create(path, password, NeoSystem.Settings); WalletAccount account = wallet.CreateAccount(); - ConsoleLog.Info($" Address:", $" {account.Address}"); - ConsoleLog.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleLog.Info($"ScriptHash:", $" {account.ScriptHash}"); + ConsoleWrite.Info($" Address:", $" {account.Address}"); + ConsoleWrite.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleWrite.Info($"ScriptHash:", $" {account.ScriptHash}"); CurrentWallet = wallet; } break; @@ -143,9 +143,9 @@ public void CreateWallet(string path, string password) wallet.Unlock(password); WalletAccount account = wallet.CreateAccount(); wallet.Save(); - ConsoleLog.Info($" Address:", $" {account.Address}"); - ConsoleLog.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleLog.Info($"ScriptHash:", $" {account.ScriptHash}"); + ConsoleWrite.Info($" Address:", $" {account.Address}"); + ConsoleWrite.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleWrite.Info($"ScriptHash:", $" {account.ScriptHash}"); CurrentWallet = wallet; } break; @@ -435,15 +435,15 @@ public async void Start(string[] args) } catch (FileNotFoundException) { - ConsoleLog.Warning($"wallet file \"{Settings.Default.UnlockWallet.Path}\" not found."); + ConsoleWrite.Warning($"wallet file \"{Settings.Default.UnlockWallet.Path}\" not found."); } catch (System.Security.Cryptography.CryptographicException) { - ConsoleLog.Error($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\""); + ConsoleWrite.Error($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\""); } catch (Exception ex) { - ConsoleLog.Error($"{ex.GetBaseException().Message}"); + ConsoleWrite.Error($"{ex.GetBaseException().Message}"); } } } @@ -546,7 +546,7 @@ private void SendTransaction(byte[] script, UInt160 account = null, long gas = T } catch (InvalidOperationException e) { - ConsoleLog.Error(GetExceptionMessage(e)); + ConsoleWrite.Error(GetExceptionMessage(e)); return; } @@ -579,7 +579,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash); if (contract == null) { - ConsoleLog.Warning("Contract does not exist."); + ConsoleWrite.Warning("Contract does not exist."); result = StackItem.Null; return false; } @@ -587,7 +587,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI { if (contract.Manifest.Abi.GetMethod(operation, parameters.Count) == null) { - ConsoleLog.Warning("This method does not not exist in this contract."); + ConsoleWrite.Warning("This method does not not exist in this contract."); result = StackItem.Null; return false; } @@ -615,14 +615,14 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI private void PrintExecutionOutput(ApplicationEngine engine, bool showStack = true) { - ConsoleLog.Info($"VM State:", $" {engine.State}"); - ConsoleLog.Info($"Gas Consumed:", $" {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); + ConsoleWrite.Info($"VM State:", $" {engine.State}"); + ConsoleWrite.Info($"Gas Consumed:", $" {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); if (showStack) - ConsoleLog.Info($"Result Stack:", $" {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); + ConsoleWrite.Info($"Result Stack:", $" {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); if (engine.State == VMState.FAULT) - ConsoleLog.Error(GetExceptionMessage(engine.FaultException)); + ConsoleWrite.Error(GetExceptionMessage(engine.FaultException)); } static string GetExceptionMessage(Exception exception) From 48d32fdee54518c367e1022ae2a8629f2283e3a2 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sun, 15 Aug 2021 23:39:57 +0800 Subject: [PATCH 06/29] remove `WriteLine` --- Neo.ConsoleService/ConsoleWrite.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Neo.ConsoleService/ConsoleWrite.cs b/Neo.ConsoleService/ConsoleWrite.cs index c8e021ff5..798357626 100644 --- a/Neo.ConsoleService/ConsoleWrite.cs +++ b/Neo.ConsoleService/ConsoleWrite.cs @@ -4,10 +4,6 @@ namespace Neo.ConsoleService { public class ConsoleWrite { - public static void WriteLine(string msg) - { - Console.WriteLine(msg); - } public static void Info(params string[] values) { From 5aa1153b902a71214e7b8a1144746be1f9ae2723 Mon Sep 17 00:00:00 2001 From: Shargon Date: Tue, 17 Aug 2021 08:52:10 +0600 Subject: [PATCH 07/29] Update ConsoleWrite.cs --- Neo.ConsoleService/ConsoleWrite.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Neo.ConsoleService/ConsoleWrite.cs b/Neo.ConsoleService/ConsoleWrite.cs index 798357626..40540bf05 100644 --- a/Neo.ConsoleService/ConsoleWrite.cs +++ b/Neo.ConsoleService/ConsoleWrite.cs @@ -4,7 +4,6 @@ namespace Neo.ConsoleService { public class ConsoleWrite { - public static void Info(params string[] values) { for (int i = 0; i < values.Length; i++) From 935db80d1e447da97f44152b55d373f91bf77559 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 18 Aug 2021 16:36:04 +0800 Subject: [PATCH 08/29] static class --- Neo.ConsoleService/ConsoleWrite.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neo.ConsoleService/ConsoleWrite.cs b/Neo.ConsoleService/ConsoleWrite.cs index 40540bf05..b80d88f37 100644 --- a/Neo.ConsoleService/ConsoleWrite.cs +++ b/Neo.ConsoleService/ConsoleWrite.cs @@ -2,7 +2,7 @@ namespace Neo.ConsoleService { - public class ConsoleWrite + public static class ConsoleWrite { public static void Info(params string[] values) { From 3397d7621727ec4b0ec80c90a436be9b2d1e6ac3 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 18 Aug 2021 16:38:16 +0800 Subject: [PATCH 09/29] Rename --- .../{ConsoleWrite.cs => ConsoleHelper.cs} | 2 +- Neo.ConsoleService/ConsoleServiceBase.cs | 10 +-- neo-cli/CLI/MainService.NEP17.cs | 2 +- neo-cli/CLI/MainService.Network.cs | 10 +-- neo-cli/CLI/MainService.Node.cs | 2 +- neo-cli/CLI/MainService.Plugins.cs | 10 +-- neo-cli/CLI/MainService.Vote.cs | 30 +++---- neo-cli/CLI/MainService.Wallet.cs | 80 +++++++++---------- neo-cli/CLI/MainService.cs | 32 ++++---- 9 files changed, 89 insertions(+), 89 deletions(-) rename Neo.ConsoleService/{ConsoleWrite.cs => ConsoleHelper.cs} (96%) diff --git a/Neo.ConsoleService/ConsoleWrite.cs b/Neo.ConsoleService/ConsoleHelper.cs similarity index 96% rename from Neo.ConsoleService/ConsoleWrite.cs rename to Neo.ConsoleService/ConsoleHelper.cs index b80d88f37..e1cbbcb89 100644 --- a/Neo.ConsoleService/ConsoleWrite.cs +++ b/Neo.ConsoleService/ConsoleHelper.cs @@ -2,7 +2,7 @@ namespace Neo.ConsoleService { - public static class ConsoleWrite + public static class ConsoleHelper { public static void Info(params string[] values) { diff --git a/Neo.ConsoleService/ConsoleServiceBase.cs b/Neo.ConsoleService/ConsoleServiceBase.cs index 0dab22884..bcfc8d560 100644 --- a/Neo.ConsoleService/ConsoleServiceBase.cs +++ b/Neo.ConsoleService/ConsoleServiceBase.cs @@ -514,7 +514,7 @@ public void Run(string[] args) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { - ConsoleWrite.Warning("Only support for installing services on Windows."); + ConsoleHelper.Warning("Only support for installing services on Windows."); return; } string arguments = string.Format("create {0} start= auto binPath= \"{1}\"", ServiceName, Process.GetCurrentProcess().MainModule.FileName); @@ -536,7 +536,7 @@ public void Run(string[] args) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { - ConsoleWrite.Warning("Only support for installing services on Windows."); + ConsoleHelper.Warning("Only support for installing services on Windows."); return; } Process process = Process.Start(new ProcessStartInfo @@ -609,16 +609,16 @@ public virtual void RunConsole() { if (!OnCommand(line)) { - ConsoleWrite.Error("Command not found"); + ConsoleHelper.Error("Command not found"); } } catch (TargetInvocationException ex) { - ConsoleWrite.Error($" {ex.InnerException.Message}"); + ConsoleHelper.Error($" {ex.InnerException.Message}"); } catch (Exception ex) { - ConsoleWrite.Error($" {ex.Message}"); + ConsoleHelper.Error($" {ex.Message}"); } } diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index db7f70ab3..3425442cc 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -52,7 +52,7 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount, UI } catch (InvalidOperationException e) { - ConsoleWrite.Error(GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); return; } if (!ReadUserInput("Relay tx(no|yes)").IsYes()) diff --git a/neo-cli/CLI/MainService.Network.cs b/neo-cli/CLI/MainService.Network.cs index 75fd64aec..52688fcde 100644 --- a/neo-cli/CLI/MainService.Network.cs +++ b/neo-cli/CLI/MainService.Network.cs @@ -24,7 +24,7 @@ private void OnBroadcastAddressCommand(IPAddress payload, ushort port) { if (payload == null) { - ConsoleWrite.Warning("You must input the payload to relay."); + ConsoleHelper.Warning("You must input the payload to relay."); return; } @@ -124,7 +124,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) { if (jsonObjectToRelay == null) { - ConsoleWrite.Warning("You must input JSON object to relay."); + ConsoleHelper.Warning("You must input JSON object to relay."); return; } @@ -133,12 +133,12 @@ private void OnRelayCommand(JObject jsonObjectToRelay) ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToRelay.ToString(), NeoSystem.StoreView); if (!context.Completed) { - ConsoleWrite.Error("The signature is incomplete."); + ConsoleHelper.Error("The signature is incomplete."); return; } if (!(context.Verifiable is Transaction tx)) { - ConsoleWrite.Warning($"Only support to relay transaction."); + ConsoleHelper.Warning($"Only support to relay transaction."); return; } tx.Witnesses = context.GetWitnesses(); @@ -147,7 +147,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) } catch (Exception e) { - ConsoleWrite.Error(GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); } } } diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index 7e95019b2..d4bd198fb 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -76,7 +76,7 @@ private void OnShowStateCommand() int linesWritten = 1; foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray()) { - ConsoleWrite.Info($"\r ip: ", + ConsoleHelper.Info($"\r ip: ", $"{ node.Remote.Address,-15}\t", $"port: ", $"{node.Remote.Port,-5}\t", diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index d65490b4e..2ad099369 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -54,7 +54,7 @@ private void OnInstallCommand(string pluginName) try { zip.ExtractToDirectory("."); - ConsoleWrite.Warning($"Install successful, please restart neo-cli."); + ConsoleHelper.Warning($"Install successful, please restart neo-cli."); } catch (IOException) { @@ -73,12 +73,12 @@ private void OnUnInstallCommand(string pluginName) var plugin = Plugin.Plugins.FirstOrDefault(p => p.Name == pluginName); if (plugin is null) { - ConsoleWrite.Warning("Plugin not found"); + ConsoleHelper.Warning("Plugin not found"); return; } if (plugin is Logger) { - ConsoleWrite.Error("You cannot uninstall a built-in plugin."); + ConsoleHelper.Error("You cannot uninstall a built-in plugin."); return; } @@ -91,7 +91,7 @@ private void OnUnInstallCommand(string pluginName) catch (IOException) { } - ConsoleWrite.Warning($"Uninstall successful, please restart neo-cli."); + ConsoleHelper.Warning($"Uninstall successful, please restart neo-cli."); } /// @@ -106,7 +106,7 @@ private void OnPluginsCommand() foreach (Plugin plugin in Plugin.Plugins) { if (plugin is Logger) continue; - ConsoleWrite.Info($"\t{plugin.Name,-20}", $"{plugin.Description}"); + ConsoleHelper.Info($"\t{plugin.Name,-20}", $"{plugin.Description}"); } } else diff --git a/neo-cli/CLI/MainService.Vote.cs b/neo-cli/CLI/MainService.Vote.cs index 2205d4205..1702d8608 100644 --- a/neo-cli/CLI/MainService.Vote.cs +++ b/neo-cli/CLI/MainService.Vote.cs @@ -1,8 +1,8 @@ using Neo.ConsoleService; using Neo.Cryptography.ECC; using Neo.IO.Json; -using Neo.SmartContract.Native; using Neo.SmartContract; +using Neo.SmartContract.Native; using Neo.VM; using Neo.VM.Types; using Neo.Wallets; @@ -25,7 +25,7 @@ private void OnRegisterCandidateCommand(UInt160 account) if (NoWallet()) { - ConsoleWrite.Warning("Need open wallet!"); + ConsoleHelper.Warning("Need open wallet!"); return; } @@ -33,14 +33,14 @@ private void OnRegisterCandidateCommand(UInt160 account) if (currentAccount == null) { - ConsoleWrite.Warning("This address isn't in your wallet!"); + ConsoleHelper.Warning("This address isn't in your wallet!"); return; } else { if (currentAccount.Lock || currentAccount.WatchOnly) { - ConsoleWrite.Warning("Locked or WatchOnly address."); + ConsoleHelper.Warning("Locked or WatchOnly address."); return; } } @@ -65,7 +65,7 @@ private void OnUnregisterCandidateCommand(UInt160 account) { if (NoWallet()) { - ConsoleWrite.Warning("Need open wallet!"); + ConsoleHelper.Warning("Need open wallet!"); return; } @@ -73,14 +73,14 @@ private void OnUnregisterCandidateCommand(UInt160 account) if (currentAccount == null) { - ConsoleWrite.Warning("This address isn't in your wallet!"); + ConsoleHelper.Warning("This address isn't in your wallet!"); return; } else { if (currentAccount.Lock || currentAccount.WatchOnly) { - ConsoleWrite.Warning("Locked or WatchOnly address."); + ConsoleHelper.Warning("Locked or WatchOnly address."); return; } } @@ -106,7 +106,7 @@ private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) { if (NoWallet()) { - ConsoleWrite.Warning("Need open wallet!"); + ConsoleHelper.Warning("Need open wallet!"); return; } @@ -129,7 +129,7 @@ private void OnUnvoteCommand(UInt160 senderAccount) { if (NoWallet()) { - ConsoleWrite.Warning("Need open wallet!"); + ConsoleHelper.Warning("Need open wallet!"); return; } @@ -156,7 +156,7 @@ private void OnGetCandidatesCommand() if (resJArray.Count > 0) { Console.WriteLine(); - ConsoleWrite.Info("Candidates:"); + ConsoleHelper.Info("Candidates:"); foreach (var item in resJArray) { @@ -181,7 +181,7 @@ private void OnGetCommitteeCommand() if (resJArray.Count > 0) { Console.WriteLine(); - ConsoleWrite.Info("Committee:"); + ConsoleHelper.Info("Committee:"); foreach (var item in resJArray) { @@ -203,7 +203,7 @@ private void OnGetNextBlockValidatorsCommand() if (resJArray.Count > 0) { Console.WriteLine(); - ConsoleWrite.Info("Next validators:"); + ConsoleHelper.Info("Next validators:"); foreach (var item in resJArray) { @@ -240,9 +240,9 @@ private void OnGetAccountState(UInt160 address) } } var publickey = ECPoint.Parse(((ByteString)resJArray?[2])?.GetSpan().ToHexString(), ECCurve.Secp256r1); - ConsoleWrite.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); - ConsoleWrite.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}"); - ConsoleWrite.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}"); + ConsoleHelper.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); + ConsoleHelper.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}"); + ConsoleHelper.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}"); } } } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 7b65a2cda..4713bfa5a 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -28,7 +28,7 @@ private void OnOpenWallet(string path) { if (!File.Exists(path)) { - ConsoleWrite.Error($"File does not exist"); + ConsoleHelper.Error($"File does not exist"); return; } string password = ReadUserInput("password", true); @@ -43,7 +43,7 @@ private void OnOpenWallet(string path) } catch (System.Security.Cryptography.CryptographicException) { - ConsoleWrite.Error($"Failed to open file \"{path}\""); + ConsoleHelper.Error($"Failed to open file \"{path}\""); } } @@ -55,7 +55,7 @@ private void OnCloseWalletCommand() { if (CurrentWallet == null) { - ConsoleWrite.Warning($"Wallet is not opened"); + ConsoleHelper.Warning($"Wallet is not opened"); return; } CurrentWallet = null; @@ -70,12 +70,12 @@ private void OnUpgradeWalletCommand(string path) { if (Path.GetExtension(path).ToLowerInvariant() != ".db3") { - ConsoleWrite.Warning("Can't upgrade the wallet file."); + ConsoleHelper.Warning("Can't upgrade the wallet file."); return; } if (!File.Exists(path)) { - ConsoleWrite.Error("File does not exist."); + ConsoleHelper.Error("File does not exist."); return; } string password = ReadUserInput("password", true); @@ -129,7 +129,7 @@ private void OnCreateAddressCommand(ushort count = 1) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - ConsoleWrite.Info($"Export addresses to", $" {path}"); + ConsoleHelper.Info($"Export addresses to", $" {path}"); File.WriteAllLines(path, addresses); } @@ -144,7 +144,7 @@ private void OnExportKeyCommand(string path = null, UInt160 scriptHash = null) if (NoWallet()) return; if (path != null && File.Exists(path)) { - ConsoleWrite.Error($"File '{path}' already exists"); + ConsoleHelper.Error($"File '{path}' already exists"); return; } string password = ReadUserInput("password", true); @@ -188,7 +188,7 @@ private void OnCreateWalletCommand(string path) string password2 = ReadUserInput("password", true); if (password != password2) { - ConsoleWrite.Error("Two passwords not match."); + ConsoleHelper.Error("Two passwords not match."); return; } if (!File.Exists(path)) @@ -215,7 +215,7 @@ private void OnImportMultisigAddress(ushort m, ECPoint[] publicKeys) if (m < 1 || m > n || n > 1024) { - ConsoleWrite.Error("Invalid parameters."); + ConsoleHelper.Error("Invalid parameters."); return; } @@ -226,7 +226,7 @@ private void OnImportMultisigAddress(ushort m, ECPoint[] publicKeys) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - ConsoleWrite.Info("Multisig. Addr.: ", multiSignContract.ScriptHash.ToAddress(NeoSystem.Settings.AddressVersion)); + ConsoleHelper.Info("Multisig. Addr.: ", multiSignContract.ScriptHash.ToAddress(NeoSystem.Settings.AddressVersion)); } /// @@ -247,7 +247,7 @@ private void OnImportKeyCommand(string wifOrFile) if (!fileInfo.Exists) { - ConsoleWrite.Error($"File '{fileInfo.FullName}' doesn't exists"); + ConsoleHelper.Error($"File '{fileInfo.FullName}' doesn't exists"); return; } @@ -278,8 +278,8 @@ private void OnImportKeyCommand(string wifOrFile) { WalletAccount account = CurrentWallet.CreateAccount(prikey); Array.Clear(prikey, 0, prikey.Length); - ConsoleWrite.Info($"Address:", $" {account.Address}"); - ConsoleWrite.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info($"Address:", $" {account.Address}"); + ConsoleHelper.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -303,7 +303,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) if (!fileInfo.Exists) { - ConsoleWrite.Error($"File '{fileInfo.FullName}' doesn't exists"); + ConsoleHelper.Error($"File '{fileInfo.FullName}' doesn't exists"); return; } @@ -329,7 +329,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) else { WalletAccount account = CurrentWallet.CreateAccount(address); - ConsoleWrite.Info($"Address:", $" {account.Address}"); + ConsoleHelper.Info($"Address:", $" {account.Address}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -366,8 +366,8 @@ private void OnListAddressCommand() type = "Deployed-Nonstandard"; } - ConsoleWrite.Info($"{" Address: "}", $"{account.Address}\t{type}"); - ConsoleWrite.Info($"{"ScriptHash: "}", $"{account.ScriptHash}\n"); + ConsoleHelper.Info($"{" Address: "}", $"{account.Address}\t{type}"); + ConsoleHelper.Info($"{"ScriptHash: "}", $"{account.ScriptHash}\n"); } } @@ -387,10 +387,10 @@ private void OnListAssetCommand() Console.WriteLine(); } Console.WriteLine("----------------------------------------------------"); - ConsoleWrite.Info($"Total: NEO:", $" {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); + ConsoleHelper.Info($"Total: NEO:", $" {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); Console.WriteLine(); - ConsoleWrite.Info("NEO hash: ", $" {NativeContract.NEO.Hash}"); - ConsoleWrite.Info("GAS hash: ", $" {NativeContract.GAS.Hash}"); + ConsoleHelper.Info("NEO hash: ", $" {NativeContract.NEO.Hash}"); + ConsoleHelper.Info("GAS hash: ", $" {NativeContract.GAS.Hash}"); } /// @@ -402,9 +402,9 @@ private void OnListKeyCommand() if (NoWallet()) return; foreach (WalletAccount account in CurrentWallet.GetAccounts().Where(p => p.HasKey)) { - ConsoleWrite.Info($" Address:", $" { account.Address}"); - ConsoleWrite.Info($"ScriptHash:", $" { account.ScriptHash}"); - ConsoleWrite.Info($" PublicKey:", $" { account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); + ConsoleHelper.Info($" Address:", $" { account.Address}"); + ConsoleHelper.Info($"ScriptHash:", $" { account.ScriptHash}"); + ConsoleHelper.Info($" PublicKey:", $" { account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); } } @@ -419,7 +419,7 @@ private void OnSignCommand(JObject jsonObjectToSign) if (jsonObjectToSign == null) { - ConsoleWrite.Warning("You must input JSON object pending signature data."); + ConsoleHelper.Warning("You must input JSON object pending signature data."); return; } try @@ -428,7 +428,7 @@ private void OnSignCommand(JObject jsonObjectToSign) ContractParametersContext context = ContractParametersContext.Parse(jsonObjectToSign.ToString(), snapshot); if (context.Network != neoSystem.Settings.Network) { - ConsoleWrite.Warning("Network mismatch."); + ConsoleHelper.Warning("Network mismatch."); return; } else if (!CurrentWallet.Sign(context)) @@ -440,7 +440,7 @@ private void OnSignCommand(JObject jsonObjectToSign) } catch (Exception e) { - ConsoleWrite.Error(GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); } } @@ -465,7 +465,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } if (!CurrentWallet.VerifyPassword(password)) { - ConsoleWrite.Warning("Incorrect password"); + ConsoleHelper.Warning("Incorrect password"); return; } var snapshot = NeoSystem.StoreView; @@ -473,7 +473,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro AssetDescriptor descriptor = new AssetDescriptor(snapshot, NeoSystem.Settings, asset); if (!BigDecimal.TryParse(amount, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0) { - ConsoleWrite.Warning("Incorrect Amount Format"); + ConsoleHelper.Warning("Incorrect Amount Format"); return; } try @@ -497,13 +497,13 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } catch (Exception e) { - ConsoleWrite.Error(GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); return; } if (tx == null) { - ConsoleWrite.Warning("Insufficient funds"); + ConsoleHelper.Warning("Insufficient funds"); return; } @@ -513,11 +513,11 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - ConsoleWrite.Info($"TXID:", $" {tx.Hash}"); + ConsoleHelper.Info($"TXID:", $" {tx.Hash}"); } else { - ConsoleWrite.Info("SignatureContext:\n", context.ToString()); + ConsoleHelper.Info("SignatureContext:\n", context.ToString()); } } @@ -533,7 +533,7 @@ private void OnShowGasCommand() uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1; foreach (UInt160 account in CurrentWallet.GetAccounts().Select(p => p.ScriptHash)) gas += NativeContract.NEO.UnclaimedGas(snapshot, account, height); - ConsoleWrite.Info($"Unclaimed gas:", $" {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info($"Unclaimed gas:", $" {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); } /// @@ -551,14 +551,14 @@ private void OnChangePasswordCommand() } if (!CurrentWallet.VerifyPassword(oldPassword)) { - ConsoleWrite.Error("Incorrect password"); + ConsoleHelper.Error("Incorrect password"); return; } string newPassword = ReadUserInput("New password", true); string newPasswordReEntered = ReadUserInput("Re-Enter Password", true); if (!newPassword.Equals(newPasswordReEntered)) { - ConsoleWrite.Error("Two passwords entered are inconsistent!"); + ConsoleHelper.Error("Two passwords entered are inconsistent!"); return; } @@ -567,7 +567,7 @@ private void OnChangePasswordCommand() string backupFile = wallet.Path + ".bak"; if (!File.Exists(wallet.Path) || File.Exists(backupFile)) { - ConsoleWrite.Error("Wallet backup fail"); + ConsoleHelper.Error("Wallet backup fail"); return; } try @@ -576,7 +576,7 @@ private void OnChangePasswordCommand() } catch (IOException) { - ConsoleWrite.Error("Wallet backup fail"); + ConsoleHelper.Error("Wallet backup fail"); return; } } @@ -590,7 +590,7 @@ private void OnChangePasswordCommand() } else { - ConsoleWrite.Error("Failed to change password"); + ConsoleHelper.Error("Failed to change password"); } } @@ -603,7 +603,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } catch (InvalidOperationException e) { - ConsoleWrite.Error($"Failed creating contract params: " + GetExceptionMessage(e)); + ConsoleHelper.Error($"Failed creating contract params: " + GetExceptionMessage(e)); throw; } CurrentWallet.Sign(context); @@ -615,7 +615,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } else { - ConsoleWrite.Error("Incomplete signature:"); + ConsoleHelper.Error("Incomplete signature:"); Console.WriteLine(context.ToString()); } } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index b11d7937c..b43524f6f 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -131,9 +131,9 @@ public void CreateWallet(string path, string password) { UserWallet wallet = UserWallet.Create(path, password, NeoSystem.Settings); WalletAccount account = wallet.CreateAccount(); - ConsoleWrite.Info($" Address:", $" {account.Address}"); - ConsoleWrite.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleWrite.Info($"ScriptHash:", $" {account.ScriptHash}"); + ConsoleHelper.Info($" Address:", $" {account.Address}"); + ConsoleHelper.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info($"ScriptHash:", $" {account.ScriptHash}"); CurrentWallet = wallet; } break; @@ -143,9 +143,9 @@ public void CreateWallet(string path, string password) wallet.Unlock(password); WalletAccount account = wallet.CreateAccount(); wallet.Save(); - ConsoleWrite.Info($" Address:", $" {account.Address}"); - ConsoleWrite.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleWrite.Info($"ScriptHash:", $" {account.ScriptHash}"); + ConsoleHelper.Info($" Address:", $" {account.Address}"); + ConsoleHelper.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info($"ScriptHash:", $" {account.ScriptHash}"); CurrentWallet = wallet; } break; @@ -435,15 +435,15 @@ public async void Start(string[] args) } catch (FileNotFoundException) { - ConsoleWrite.Warning($"wallet file \"{Settings.Default.UnlockWallet.Path}\" not found."); + ConsoleHelper.Warning($"wallet file \"{Settings.Default.UnlockWallet.Path}\" not found."); } catch (System.Security.Cryptography.CryptographicException) { - ConsoleWrite.Error($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\""); + ConsoleHelper.Error($"Failed to open file \"{Settings.Default.UnlockWallet.Path}\""); } catch (Exception ex) { - ConsoleWrite.Error($"{ex.GetBaseException().Message}"); + ConsoleHelper.Error($"{ex.GetBaseException().Message}"); } } } @@ -546,7 +546,7 @@ private void SendTransaction(byte[] script, UInt160 account = null, long gas = T } catch (InvalidOperationException e) { - ConsoleWrite.Error(GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); return; } @@ -579,7 +579,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash); if (contract == null) { - ConsoleWrite.Warning("Contract does not exist."); + ConsoleHelper.Warning("Contract does not exist."); result = StackItem.Null; return false; } @@ -587,7 +587,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI { if (contract.Manifest.Abi.GetMethod(operation, parameters.Count) == null) { - ConsoleWrite.Warning("This method does not not exist in this contract."); + ConsoleHelper.Warning("This method does not not exist in this contract."); result = StackItem.Null; return false; } @@ -615,14 +615,14 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI private void PrintExecutionOutput(ApplicationEngine engine, bool showStack = true) { - ConsoleWrite.Info($"VM State:", $" {engine.State}"); - ConsoleWrite.Info($"Gas Consumed:", $" {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info($"VM State:", $" {engine.State}"); + ConsoleHelper.Info($"Gas Consumed:", $" {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); if (showStack) - ConsoleWrite.Info($"Result Stack:", $" {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); + ConsoleHelper.Info($"Result Stack:", $" {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); if (engine.State == VMState.FAULT) - ConsoleWrite.Error(GetExceptionMessage(engine.FaultException)); + ConsoleHelper.Error(GetExceptionMessage(engine.FaultException)); } static string GetExceptionMessage(Exception exception) From 99af5931aa6d3544bb703faa508bd0f730bf9039 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 17:13:26 +0800 Subject: [PATCH 10/29] use colorset --- Neo.ConsoleService/ConsoleHelper.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Neo.ConsoleService/ConsoleHelper.cs b/Neo.ConsoleService/ConsoleHelper.cs index e1cbbcb89..0ba91ad35 100644 --- a/Neo.ConsoleService/ConsoleHelper.cs +++ b/Neo.ConsoleService/ConsoleHelper.cs @@ -4,34 +4,41 @@ namespace Neo.ConsoleService { public static class ConsoleHelper { + private static readonly ConsoleColorSet InfoColor = new ConsoleColorSet(ConsoleColor.Cyan); + private static readonly ConsoleColorSet WarningColor = new ConsoleColorSet(ConsoleColor.Yellow); + private static readonly ConsoleColorSet ErrorColor = new ConsoleColorSet(ConsoleColor.Red); public static void Info(params string[] values) { + var currentColor = new ConsoleColorSet(); + for (int i = 0; i < values.Length; i++) { - Console.ForegroundColor = ConsoleColor.Cyan; + InfoColor.Apply(); if (i % 2 == 1) - Console.ForegroundColor = ConsoleColor.White; + currentColor.Apply(); Console.Write(values[i]); } - Console.ForegroundColor = ConsoleColor.White; + currentColor.Apply(); Console.WriteLine(); } public static void Warning(string msg) { - Log("Warning", ConsoleColor.Yellow, msg); + Log("Warning", WarningColor, msg); } public static void Error(string msg) { - Log("Error", ConsoleColor.Red, msg); + Log("Error", ErrorColor, msg); } - private static void Log(string tag, ConsoleColor tagColor, string msg, ConsoleColor msgColor = ConsoleColor.White) + private static void Log(string tag, ConsoleColorSet colorSet, string msg) { - Console.ForegroundColor = tagColor; + var currentColor = new ConsoleColorSet(); + + colorSet.Apply(); Console.Write($"{tag}: "); - Console.ForegroundColor = msgColor; + currentColor.Apply(); Console.WriteLine(msg); } } From b257e8ff7ca26c5ad691859ea7c3dd7c32a5c186 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 18 Aug 2021 17:47:56 +0800 Subject: [PATCH 11/29] Update ConsoleHelper.cs --- Neo.ConsoleService/ConsoleHelper.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Neo.ConsoleService/ConsoleHelper.cs b/Neo.ConsoleService/ConsoleHelper.cs index 0ba91ad35..5083d7cee 100644 --- a/Neo.ConsoleService/ConsoleHelper.cs +++ b/Neo.ConsoleService/ConsoleHelper.cs @@ -4,9 +4,10 @@ namespace Neo.ConsoleService { public static class ConsoleHelper { - private static readonly ConsoleColorSet InfoColor = new ConsoleColorSet(ConsoleColor.Cyan); - private static readonly ConsoleColorSet WarningColor = new ConsoleColorSet(ConsoleColor.Yellow); - private static readonly ConsoleColorSet ErrorColor = new ConsoleColorSet(ConsoleColor.Red); + private static readonly ConsoleColorSet InfoColor = new(ConsoleColor.Cyan); + private static readonly ConsoleColorSet WarningColor = new(ConsoleColor.Yellow); + private static readonly ConsoleColorSet ErrorColor = new(ConsoleColor.Red); + public static void Info(params string[] values) { var currentColor = new ConsoleColorSet(); From b7fddd5e2f7c84b26c1deacb2f89ef533032f7eb Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 18 Aug 2021 17:50:39 +0800 Subject: [PATCH 12/29] Optimize --- Neo.ConsoleService/ConsoleHelper.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Neo.ConsoleService/ConsoleHelper.cs b/Neo.ConsoleService/ConsoleHelper.cs index 5083d7cee..47a832e8e 100644 --- a/Neo.ConsoleService/ConsoleHelper.cs +++ b/Neo.ConsoleService/ConsoleHelper.cs @@ -14,8 +14,9 @@ public static void Info(params string[] values) for (int i = 0; i < values.Length; i++) { - InfoColor.Apply(); - if (i % 2 == 1) + if (i % 2 == 0) + InfoColor.Apply(); + else currentColor.Apply(); Console.Write(values[i]); } From eac96f62dae071d4985f89ca28ec43598363c7e2 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 18 Aug 2021 18:13:56 +0800 Subject: [PATCH 13/29] Update --- Neo.ConsoleService/ConsoleServiceBase.cs | 4 +-- neo-cli/CLI/MainService.Network.cs | 2 +- neo-cli/CLI/MainService.Plugins.cs | 2 +- neo-cli/CLI/MainService.Vote.cs | 4 +-- neo-cli/CLI/MainService.Wallet.cs | 35 ++++++++++++------------ neo-cli/CLI/MainService.cs | 20 +++++++------- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Neo.ConsoleService/ConsoleServiceBase.cs b/Neo.ConsoleService/ConsoleServiceBase.cs index bcfc8d560..5c47fc558 100644 --- a/Neo.ConsoleService/ConsoleServiceBase.cs +++ b/Neo.ConsoleService/ConsoleServiceBase.cs @@ -614,11 +614,11 @@ public virtual void RunConsole() } catch (TargetInvocationException ex) { - ConsoleHelper.Error($" {ex.InnerException.Message}"); + ConsoleHelper.Error(ex.InnerException.Message); } catch (Exception ex) { - ConsoleHelper.Error($" {ex.Message}"); + ConsoleHelper.Error(ex.Message); } } diff --git a/neo-cli/CLI/MainService.Network.cs b/neo-cli/CLI/MainService.Network.cs index 52688fcde..21bca705e 100644 --- a/neo-cli/CLI/MainService.Network.cs +++ b/neo-cli/CLI/MainService.Network.cs @@ -138,7 +138,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) } if (!(context.Verifiable is Transaction tx)) { - ConsoleHelper.Warning($"Only support to relay transaction."); + ConsoleHelper.Warning("Only support to relay transaction."); return; } tx.Witnesses = context.GetWitnesses(); diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 2ad099369..8a3d8d82c 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -106,7 +106,7 @@ private void OnPluginsCommand() foreach (Plugin plugin in Plugin.Plugins) { if (plugin is Logger) continue; - ConsoleHelper.Info($"\t{plugin.Name,-20}", $"{plugin.Description}"); + ConsoleHelper.Info($"\t{plugin.Name,-20}", plugin.Description); } } else diff --git a/neo-cli/CLI/MainService.Vote.cs b/neo-cli/CLI/MainService.Vote.cs index 1702d8608..714679a93 100644 --- a/neo-cli/CLI/MainService.Vote.cs +++ b/neo-cli/CLI/MainService.Vote.cs @@ -241,8 +241,8 @@ private void OnGetAccountState(UInt160 address) } var publickey = ECPoint.Parse(((ByteString)resJArray?[2])?.GetSpan().ToHexString(), ECCurve.Secp256r1); ConsoleHelper.Info("Voted: ", Contract.CreateSignatureRedeemScript(publickey).ToScriptHash().ToAddress(NeoSystem.Settings.AddressVersion)); - ConsoleHelper.Info("Amount: ", $"{new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals)}"); - ConsoleHelper.Info("Block: ", $"{((Integer)resJArray?[1]).GetInteger()}"); + ConsoleHelper.Info("Amount: ", new BigDecimal(((Integer)resJArray?[0]).GetInteger(), NativeContract.NEO.Decimals).ToString()); + ConsoleHelper.Info("Block: ", ((Integer)resJArray?[1]).GetInteger().ToString()); } } } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 4713bfa5a..494b065b1 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -28,7 +28,7 @@ private void OnOpenWallet(string path) { if (!File.Exists(path)) { - ConsoleHelper.Error($"File does not exist"); + ConsoleHelper.Error("File does not exist"); return; } string password = ReadUserInput("password", true); @@ -55,7 +55,7 @@ private void OnCloseWalletCommand() { if (CurrentWallet == null) { - ConsoleHelper.Warning($"Wallet is not opened"); + ConsoleHelper.Warning("Wallet is not opened"); return; } CurrentWallet = null; @@ -129,7 +129,7 @@ private void OnCreateAddressCommand(ushort count = 1) if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); - ConsoleHelper.Info($"Export addresses to", $" {path}"); + Console.WriteLine($"Export addresses to {path}"); File.WriteAllLines(path, addresses); } @@ -278,8 +278,8 @@ private void OnImportKeyCommand(string wifOrFile) { WalletAccount account = CurrentWallet.CreateAccount(prikey); Array.Clear(prikey, 0, prikey.Length); - ConsoleHelper.Info($"Address:", $" {account.Address}"); - ConsoleHelper.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info("Address: ", account.Address); + ConsoleHelper.Info(" Pubkey: ", account.GetKey().PublicKey.EncodePoint(true).ToHexString()); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -329,7 +329,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) else { WalletAccount account = CurrentWallet.CreateAccount(address); - ConsoleHelper.Info($"Address:", $" {account.Address}"); + ConsoleHelper.Info("Address: ", account.Address); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); @@ -366,8 +366,8 @@ private void OnListAddressCommand() type = "Deployed-Nonstandard"; } - ConsoleHelper.Info($"{" Address: "}", $"{account.Address}\t{type}"); - ConsoleHelper.Info($"{"ScriptHash: "}", $"{account.ScriptHash}\n"); + ConsoleHelper.Info(" Address: ", $"{account.Address}\t{type}"); + ConsoleHelper.Info("ScriptHash: ", $"{account.ScriptHash}\n"); } } @@ -387,10 +387,10 @@ private void OnListAssetCommand() Console.WriteLine(); } Console.WriteLine("----------------------------------------------------"); - ConsoleHelper.Info($"Total: NEO:", $" {CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); + ConsoleHelper.Info("Total: NEO: ", $"{CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); Console.WriteLine(); - ConsoleHelper.Info("NEO hash: ", $" {NativeContract.NEO.Hash}"); - ConsoleHelper.Info("GAS hash: ", $" {NativeContract.GAS.Hash}"); + ConsoleHelper.Info("NEO hash: ", NativeContract.NEO.Hash.ToString()); + ConsoleHelper.Info("GAS hash: ", NativeContract.GAS.Hash.ToString()); } /// @@ -402,9 +402,10 @@ private void OnListKeyCommand() if (NoWallet()) return; foreach (WalletAccount account in CurrentWallet.GetAccounts().Where(p => p.HasKey)) { - ConsoleHelper.Info($" Address:", $" { account.Address}"); - ConsoleHelper.Info($"ScriptHash:", $" { account.ScriptHash}"); - ConsoleHelper.Info($" PublicKey:", $" { account.GetKey().PublicKey.EncodePoint(true).ToHexString()}\n"); + ConsoleHelper.Info(" Address: ", account.Address); + ConsoleHelper.Info("ScriptHash: ", account.ScriptHash.ToString()); + ConsoleHelper.Info(" PublicKey: ", account.GetKey().PublicKey.EncodePoint(true).ToHexString()); + Console.WriteLine(); } } @@ -513,7 +514,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - ConsoleHelper.Info($"TXID:", $" {tx.Hash}"); + ConsoleHelper.Info("TXID: ", tx.Hash.ToString()); } else { @@ -533,7 +534,7 @@ private void OnShowGasCommand() uint height = NativeContract.Ledger.CurrentIndex(snapshot) + 1; foreach (UInt160 account in CurrentWallet.GetAccounts().Select(p => p.ScriptHash)) gas += NativeContract.NEO.UnclaimedGas(snapshot, account, height); - ConsoleHelper.Info($"Unclaimed gas:", $" {new BigDecimal(gas, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info("Unclaimed gas: ", new BigDecimal(gas, NativeContract.GAS.Decimals).ToString()); } /// @@ -603,7 +604,7 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) } catch (InvalidOperationException e) { - ConsoleHelper.Error($"Failed creating contract params: " + GetExceptionMessage(e)); + ConsoleHelper.Error("Failed creating contract params: " + GetExceptionMessage(e)); throw; } CurrentWallet.Sign(context); diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index b43524f6f..1e6aed8b9 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -131,9 +131,9 @@ public void CreateWallet(string path, string password) { UserWallet wallet = UserWallet.Create(path, password, NeoSystem.Settings); WalletAccount account = wallet.CreateAccount(); - ConsoleHelper.Info($" Address:", $" {account.Address}"); - ConsoleHelper.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleHelper.Info($"ScriptHash:", $" {account.ScriptHash}"); + ConsoleHelper.Info(" Address: ", account.Address); + ConsoleHelper.Info(" Pubkey: ", account.GetKey().PublicKey.EncodePoint(true).ToHexString()); + ConsoleHelper.Info("ScriptHash: ", account.ScriptHash.ToString()); CurrentWallet = wallet; } break; @@ -143,9 +143,9 @@ public void CreateWallet(string path, string password) wallet.Unlock(password); WalletAccount account = wallet.CreateAccount(); wallet.Save(); - ConsoleHelper.Info($" Address:", $" {account.Address}"); - ConsoleHelper.Info($" Pubkey:", $" {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleHelper.Info($"ScriptHash:", $" {account.ScriptHash}"); + ConsoleHelper.Info(" Address: ", account.Address); + ConsoleHelper.Info(" Pubkey: ", account.GetKey().PublicKey.EncodePoint(true).ToHexString()); + ConsoleHelper.Info("ScriptHash: ", account.ScriptHash.ToString()); CurrentWallet = wallet; } break; @@ -443,7 +443,7 @@ public async void Start(string[] args) } catch (Exception ex) { - ConsoleHelper.Error($"{ex.GetBaseException().Message}"); + ConsoleHelper.Error(ex.GetBaseException().Message); } } } @@ -615,11 +615,11 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI private void PrintExecutionOutput(ApplicationEngine engine, bool showStack = true) { - ConsoleHelper.Info($"VM State:", $" {engine.State}"); - ConsoleHelper.Info($"Gas Consumed:", $" {new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info("VM State: ", engine.State.ToString()); + ConsoleHelper.Info("Gas Consumed: ", new BigDecimal((BigInteger)engine.GasConsumed, NativeContract.GAS.Decimals).ToString()); if (showStack) - ConsoleHelper.Info($"Result Stack:", $" {new JArray(engine.ResultStack.Select(p => p.ToJson()))}"); + ConsoleHelper.Info("Result Stack: ", new JArray(engine.ResultStack.Select(p => p.ToJson())).ToString()); if (engine.State == VMState.FAULT) ConsoleHelper.Error(GetExceptionMessage(engine.FaultException)); From 899460241d994134f093c987d4d1a83c9ff22040 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 18 Aug 2021 18:17:54 +0800 Subject: [PATCH 14/29] Update MainService.Plugins.cs --- neo-cli/CLI/MainService.Plugins.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 8a3d8d82c..818e94227 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -54,7 +54,7 @@ private void OnInstallCommand(string pluginName) try { zip.ExtractToDirectory("."); - ConsoleHelper.Warning($"Install successful, please restart neo-cli."); + ConsoleHelper.Warning("Install successful, please restart neo-cli."); } catch (IOException) { @@ -91,7 +91,7 @@ private void OnUnInstallCommand(string pluginName) catch (IOException) { } - ConsoleHelper.Warning($"Uninstall successful, please restart neo-cli."); + ConsoleHelper.Warning("Uninstall successful, please restart neo-cli."); } /// From ad5eab60f4f5aa2c079a8b348d72d004f84f1f3e Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 18:42:58 +0800 Subject: [PATCH 15/29] remove "\r" --- neo-cli/CLI/MainService.Node.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index d4bd198fb..7990fe6b7 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -76,7 +76,7 @@ private void OnShowStateCommand() int linesWritten = 1; foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray()) { - ConsoleHelper.Info($"\r ip: ", + ConsoleHelper.Info($" ip: ", $"{ node.Remote.Address,-15}\t", $"port: ", $"{node.Remote.Port,-5}\t", From ac46decb98e143de3739633ff1ebe193619bf51a Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 18:47:55 +0800 Subject: [PATCH 16/29] fix `list asset` color --- neo-cli/CLI/MainService.Wallet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 494b065b1..49c550d86 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -387,7 +387,7 @@ private void OnListAssetCommand() Console.WriteLine(); } Console.WriteLine("----------------------------------------------------"); - ConsoleHelper.Info("Total: NEO: ", $"{CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} GAS: {CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); + ConsoleHelper.Info("Total: NEO: ", $"{CurrentWallet.GetAvailable(snapshot, NativeContract.NEO.Hash),10} ", "GAS: ", $"{CurrentWallet.GetAvailable(snapshot, NativeContract.GAS.Hash),18}"); Console.WriteLine(); ConsoleHelper.Info("NEO hash: ", NativeContract.NEO.Hash.ToString()); ConsoleHelper.Info("GAS hash: ", NativeContract.GAS.Hash.ToString()); From 9e1b985be11e6753ce81dfd0eb52a1ccc89bc3ec Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 18:59:35 +0800 Subject: [PATCH 17/29] check all console output with `ConsoleHelper` --- neo-cli/CLI/MainService.Blockchain.cs | 2 +- neo-cli/CLI/MainService.Contracts.cs | 12 +++++++----- neo-cli/CLI/MainService.NEP17.cs | 6 +++--- neo-cli/CLI/MainService.Native.cs | 2 +- neo-cli/CLI/MainService.Tools.cs | 2 +- neo-cli/CLI/MainService.cs | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/neo-cli/CLI/MainService.Blockchain.cs b/neo-cli/CLI/MainService.Blockchain.cs index 8927ce421..277e2e1b0 100644 --- a/neo-cli/CLI/MainService.Blockchain.cs +++ b/neo-cli/CLI/MainService.Blockchain.cs @@ -18,7 +18,7 @@ private void OnExportBlocksStartCountCommand(uint start, uint count = uint.MaxVa uint height = NativeContract.Ledger.CurrentIndex(NeoSystem.StoreView); if (height < start) { - Console.WriteLine("Error: invalid start height."); + ConsoleHelper.Error("invalid start height."); return; } diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index ab12639ce..532113c63 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -88,14 +88,14 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes } catch (InvalidOperationException e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); return; } ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash); if (contract == null) { - Console.WriteLine($"Can't upgrade, contract hash not exist: {scriptHash}"); + ConsoleHelper.Warning($"Can't upgrade, contract hash not exist: {scriptHash}"); } else { @@ -159,11 +159,13 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra } catch (InvalidOperationException e) { - Console.WriteLine("Error: " + GetExceptionMessage(e)); + ConsoleHelper.Error(GetExceptionMessage(e)); return; } - Console.WriteLine($"Network fee: {new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}"); - Console.WriteLine($"Total fee: {new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); + ConsoleHelper.Info($"Network fee: ", + $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}", + "Total fee: ", + $"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); if (!ReadUserInput("Relay tx? (no|yes)").IsYes()) { return; diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index 3425442cc..e03bb5938 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -93,7 +93,7 @@ private void OnNameCommand(UInt160 tokenHash) { ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, tokenHash); if (contract == null) Console.WriteLine($"Contract hash not exist: {tokenHash}"); - else Console.WriteLine($"Result : {contract.Manifest.Name.ToString()}"); + else ConsoleHelper.Info("Result : ", $"{contract.Manifest.Name.ToString()}"); } /// @@ -105,7 +105,7 @@ private void OnDecimalsCommand(UInt160 tokenHash) { if (!OnInvokeWithResult(tokenHash, "decimals", out StackItem result, null)) return; - Console.WriteLine($"Result : {((PrimitiveType)result).GetInteger()}"); + ConsoleHelper.Info("Result : ", $"{((PrimitiveType)result).GetInteger()}"); } /// @@ -120,7 +120,7 @@ private void OnTotalSupplyCommand(UInt160 tokenHash) var asset = new AssetDescriptor(NeoSystem.StoreView, NeoSystem.Settings, tokenHash); var totalSupply = new BigDecimal(((PrimitiveType)result).GetInteger(), asset.Decimals); - Console.WriteLine($"Result : {totalSupply}"); + ConsoleHelper.Info("Result : ", $"{totalSupply}"); } } } diff --git a/neo-cli/CLI/MainService.Native.cs b/neo-cli/CLI/MainService.Native.cs index d9f59bcbc..e81101c3b 100644 --- a/neo-cli/CLI/MainService.Native.cs +++ b/neo-cli/CLI/MainService.Native.cs @@ -13,7 +13,7 @@ partial class MainService [ConsoleCommand("list nativecontract", Category = "Native Contract")] private void OnListNativeContract() { - NativeContract.Contracts.ToList().ForEach(p => Console.WriteLine($"\t{p.Name,-20}{p.Hash}")); + NativeContract.Contracts.ToList().ForEach(p => ConsoleHelper.Info($"\t{p.Name,-20}", $"{p.Hash}")); } } } diff --git a/neo-cli/CLI/MainService.Tools.cs b/neo-cli/CLI/MainService.Tools.cs index 266c898fd..40e70e7b2 100644 --- a/neo-cli/CLI/MainService.Tools.cs +++ b/neo-cli/CLI/MainService.Tools.cs @@ -48,7 +48,7 @@ private void OnParseCommand(string value) if (!any) { - Console.WriteLine($"Was not possible to convert: '{value}'"); + ConsoleHelper.Warning($"Was not possible to convert: '{value}'"); } } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 1e6aed8b9..d49de1695 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -529,7 +529,7 @@ private void SendTransaction(byte[] script, UInt160 account = null, long gas = T try { Transaction tx = CurrentWallet.MakeTransaction(snapshot, script, account, signers, maxGas: gas); - Console.WriteLine($"Invoking script with: '{tx.Script.ToBase64String()}'"); + ConsoleHelper.Info("Invoking script with: ", $"'{tx.Script.ToBase64String()}'"); using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, snapshot, container: tx, settings: NeoSystem.Settings, gas: gas)) { @@ -599,7 +599,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI { scriptBuilder.EmitDynamicCall(scriptHash, operation, parameters.ToArray()); script = scriptBuilder.ToArray(); - Console.WriteLine($"Invoking script with: '{script.ToBase64String()}'"); + ConsoleHelper.Info("Invoking script with: ", $"'{script.ToBase64String()}'"); } if (verificable is Transaction tx) From 40cdc85b291b0dc5a13f091c634d4b4f509106e1 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 19:13:39 +0800 Subject: [PATCH 18/29] update more console output --- neo-cli/CLI/MainService.Contracts.cs | 2 +- neo-cli/CLI/MainService.Network.cs | 2 +- neo-cli/CLI/MainService.Plugins.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index 532113c63..3f4b50e23 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -162,7 +162,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra ConsoleHelper.Error(GetExceptionMessage(e)); return; } - ConsoleHelper.Info($"Network fee: ", + ConsoleHelper.Info("Network fee: ", $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}", "Total fee: ", $"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); diff --git a/neo-cli/CLI/MainService.Network.cs b/neo-cli/CLI/MainService.Network.cs index 21bca705e..549981f42 100644 --- a/neo-cli/CLI/MainService.Network.cs +++ b/neo-cli/CLI/MainService.Network.cs @@ -143,7 +143,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) } tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - Console.WriteLine($"Data relay success, the hash is shown as follows:{Environment.NewLine}{tx.Hash}"); + ConsoleHelper.Info("Data relay success, the hash is shown as follows:", $"{Environment.NewLine}{tx.Hash}"); } catch (Exception e) { diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 818e94227..6386f77dd 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -111,7 +111,7 @@ private void OnPluginsCommand() } else { - Console.WriteLine("No loaded plugins"); + ConsoleHelper.Warning("No loaded plugins"); } } } From 05b47c46df4cb33c642788b8b256dfe860801215 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 19:24:21 +0800 Subject: [PATCH 19/29] add more `ConsoleHelper.Info` output --- neo-cli/CLI/MainService.Contracts.cs | 10 +++++----- neo-cli/CLI/MainService.Node.cs | 6 +++--- neo-cli/CLI/MainService.Wallet.cs | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index 3f4b50e23..c6b43b687 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -99,11 +99,11 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes } else { - Console.WriteLine($"Contract hash: {scriptHash}"); - Console.WriteLine($"Updated times: {contract.UpdateCounter}"); - Console.WriteLine($"Gas consumed: {new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals)}"); - Console.WriteLine($"Network fee: {new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}"); - Console.WriteLine($"Total fee: {new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); + ConsoleHelper.Info("Contract hash: ", $"{scriptHash}"); + ConsoleHelper.Info("Updated times: ", $"{contract.UpdateCounter}"); + ConsoleHelper.Info("Gas consumed: ", $"{new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info("Network fee: ", $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info("Total fee: ", $"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); if (!ReadUserInput("Relay tx? (no|yes)").IsYes()) // Add this in case just want to get hash but not relay { return; diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index 7990fe6b7..40b932f71 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -78,11 +78,11 @@ private void OnShowStateCommand() { ConsoleHelper.Info($" ip: ", $"{ node.Remote.Address,-15}\t", - $"port: ", + "port: ", $"{node.Remote.Port,-5}\t", - $"listen: ", + "listen: ", $"{node.ListenerTcpPort,-5}\t", - $"height: ", + "height: ", $"{node.LastBlockIndex,-7}"); linesWritten++; } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 49c550d86..93399a2e1 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -382,8 +382,8 @@ private void OnListAssetCommand() foreach (UInt160 account in CurrentWallet.GetAccounts().Select(p => p.ScriptHash)) { Console.WriteLine(account.ToAddress(NeoSystem.Settings.AddressVersion)); - Console.WriteLine($"NEO: {CurrentWallet.GetBalance(snapshot, NativeContract.NEO.Hash, account)}"); - Console.WriteLine($"GAS: {CurrentWallet.GetBalance(snapshot, NativeContract.GAS.Hash, account)}"); + ConsoleHelper.Info("NEO: ", $"{CurrentWallet.GetBalance(snapshot, NativeContract.NEO.Hash, account)}"); + ConsoleHelper.Info("GAS: ", $"{CurrentWallet.GetBalance(snapshot, NativeContract.GAS.Hash, account)}"); Console.WriteLine(); } Console.WriteLine("----------------------------------------------------"); @@ -434,10 +434,10 @@ private void OnSignCommand(JObject jsonObjectToSign) } else if (!CurrentWallet.Sign(context)) { - Console.WriteLine("Non-existent private key in wallet."); + ConsoleHelper.Warning("Non-existent private key in wallet."); return; } - Console.WriteLine($"Signed Output:{Environment.NewLine}{context}"); + ConsoleHelper.Info("Signed Output: ", $"{Environment.NewLine}{context}"); } catch (Exception e) { @@ -466,7 +466,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro } if (!CurrentWallet.VerifyPassword(password)) { - ConsoleHelper.Warning("Incorrect password"); + ConsoleHelper.Error("Incorrect password"); return; } var snapshot = NeoSystem.StoreView; @@ -474,7 +474,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro AssetDescriptor descriptor = new AssetDescriptor(snapshot, NeoSystem.Settings, asset); if (!BigDecimal.TryParse(amount, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0) { - ConsoleHelper.Warning("Incorrect Amount Format"); + ConsoleHelper.Error("Incorrect Amount Format"); return; } try From f65a00f61111b76bc1456b546ebf5ac96b507a03 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Wed, 18 Aug 2021 19:28:02 +0800 Subject: [PATCH 20/29] fix some output format. --- neo-cli/CLI/MainService.NEP17.cs | 6 +++--- neo-cli/CLI/MainService.Network.cs | 2 +- neo-cli/CLI/MainService.Wallet.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index e03bb5938..a3b302341 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -93,7 +93,7 @@ private void OnNameCommand(UInt160 tokenHash) { ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, tokenHash); if (contract == null) Console.WriteLine($"Contract hash not exist: {tokenHash}"); - else ConsoleHelper.Info("Result : ", $"{contract.Manifest.Name.ToString()}"); + else ConsoleHelper.Info("Result: ", $"{contract.Manifest.Name.ToString()}"); } /// @@ -105,7 +105,7 @@ private void OnDecimalsCommand(UInt160 tokenHash) { if (!OnInvokeWithResult(tokenHash, "decimals", out StackItem result, null)) return; - ConsoleHelper.Info("Result : ", $"{((PrimitiveType)result).GetInteger()}"); + ConsoleHelper.Info("Result: ", $"{((PrimitiveType)result).GetInteger()}"); } /// @@ -120,7 +120,7 @@ private void OnTotalSupplyCommand(UInt160 tokenHash) var asset = new AssetDescriptor(NeoSystem.StoreView, NeoSystem.Settings, tokenHash); var totalSupply = new BigDecimal(((PrimitiveType)result).GetInteger(), asset.Decimals); - ConsoleHelper.Info("Result : ", $"{totalSupply}"); + ConsoleHelper.Info("Result: ", $"{totalSupply}"); } } } diff --git a/neo-cli/CLI/MainService.Network.cs b/neo-cli/CLI/MainService.Network.cs index 549981f42..c2171fe0c 100644 --- a/neo-cli/CLI/MainService.Network.cs +++ b/neo-cli/CLI/MainService.Network.cs @@ -143,7 +143,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay) } tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - ConsoleHelper.Info("Data relay success, the hash is shown as follows:", $"{Environment.NewLine}{tx.Hash}"); + Console.WriteLine($"Data relay success, the hash is shown as follows: {Environment.NewLine}{tx.Hash}"); } catch (Exception e) { diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 93399a2e1..778f5a114 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -197,7 +197,7 @@ private void OnCreateWalletCommand(string path) } else { - Console.WriteLine("This wallet already exists, please create another one."); + ConsoleHelper.Warning("This wallet already exists, please create another one."); } } From 558921940631cf1eb91d4ea7a36acec7588a0451 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Thu, 19 Aug 2021 09:49:35 +0800 Subject: [PATCH 21/29] add comments --- Neo.ConsoleService/ConsoleHelper.cs | 18 ++++++++++++++++++ neo-cli/CLI/MainService.Contracts.cs | 8 ++++---- neo-cli/CLI/MainService.Node.cs | 2 +- neo-cli/CLI/MainService.Wallet.cs | 2 +- neo-cli/CLI/MainService.cs | 6 +++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Neo.ConsoleService/ConsoleHelper.cs b/Neo.ConsoleService/ConsoleHelper.cs index 47a832e8e..24dd76fc8 100644 --- a/Neo.ConsoleService/ConsoleHelper.cs +++ b/Neo.ConsoleService/ConsoleHelper.cs @@ -8,6 +8,11 @@ public static class ConsoleHelper private static readonly ConsoleColorSet WarningColor = new(ConsoleColor.Yellow); private static readonly ConsoleColorSet ErrorColor = new(ConsoleColor.Red); + /// + /// Info handles message in the form of "[tag]:[msg]", + /// avoid using Info if the `tag` is too long + /// + /// public static void Info(params string[] values) { var currentColor = new ConsoleColorSet(); @@ -24,11 +29,24 @@ public static void Info(params string[] values) Console.WriteLine(); } + /// + /// Use warning if something unexpected happens + /// or the execution result is not correct. + /// Also use warning if you just want to remind + /// user of doing something. + /// + /// public static void Warning(string msg) { Log("Warning", WarningColor, msg); } + /// + /// Use Error if the verification or input format check fails + /// or exception that breaks the execution of interactive + /// command throws. + /// + /// public static void Error(string msg) { Log("Error", ErrorColor, msg); diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index c6b43b687..4f308e221 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -35,10 +35,10 @@ private void OnDeployCommand(string filePath, string manifestPath = null) UInt160 hash = SmartContract.Helper.GetContractHash(tx.Sender, nef.CheckSum, manifest.Name); - Console.WriteLine($"Contract hash: {hash}"); - Console.WriteLine($"Gas consumed: {new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals)}"); - Console.WriteLine($"Network fee: {new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}"); - Console.WriteLine($"Total fee: {new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); + ConsoleHelper.Info("Contract hash: ", $"{hash}"); + ConsoleHelper.Info("Gas consumed: ", $"{new BigDecimal((BigInteger)tx.SystemFee, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info("Network fee: ", $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}"); + ConsoleHelper.Info("Total fee: ", $"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); if (!ReadUserInput("Relay tx? (no|yes)").IsYes()) // Add this in case just want to get hash but not relay { return; diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index 40b932f71..b524507af 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -76,7 +76,7 @@ private void OnShowStateCommand() int linesWritten = 1; foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray()) { - ConsoleHelper.Info($" ip: ", + ConsoleHelper.Info(" ip: ", $"{ node.Remote.Address,-15}\t", "port: ", $"{node.Remote.Port,-5}\t", diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 778f5a114..7f5405688 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -303,7 +303,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) if (!fileInfo.Exists) { - ConsoleHelper.Error($"File '{fileInfo.FullName}' doesn't exists"); + ConsoleHelper.Warning($"File '{fileInfo.FullName}' doesn't exists"); return; } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index d49de1695..15ce6112c 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -221,7 +221,7 @@ private IEnumerable GetBlocksFromFile() private bool NoWallet() { if (CurrentWallet != null) return false; - Console.WriteLine("You have to open the wallet first."); + ConsoleHelper.Error("You have to open the wallet first."); return true; } @@ -579,7 +579,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash); if (contract == null) { - ConsoleHelper.Warning("Contract does not exist."); + ConsoleHelper.Error("Contract does not exist."); result = StackItem.Null; return false; } @@ -587,7 +587,7 @@ private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackI { if (contract.Manifest.Abi.GetMethod(operation, parameters.Count) == null) { - ConsoleHelper.Warning("This method does not not exist in this contract."); + ConsoleHelper.Error("This method does not not exist in this contract."); result = StackItem.Null; return false; } From 3324a05d6a616a2cc2f533c53e3fe2efed07ec32 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Thu, 19 Aug 2021 13:54:38 +0800 Subject: [PATCH 22/29] Update MainService.NEP17.cs --- neo-cli/CLI/MainService.NEP17.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index a3b302341..6478524a1 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -93,7 +93,7 @@ private void OnNameCommand(UInt160 tokenHash) { ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, tokenHash); if (contract == null) Console.WriteLine($"Contract hash not exist: {tokenHash}"); - else ConsoleHelper.Info("Result: ", $"{contract.Manifest.Name.ToString()}"); + else ConsoleHelper.Info("Result: ", contract.Manifest.Name); } /// From d59e1cfdf27c417921d48ca8aa8b8bcbba84148e Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 21 Aug 2021 08:45:25 +0800 Subject: [PATCH 23/29] update comment --- Neo.ConsoleService/ConsoleHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Neo.ConsoleService/ConsoleHelper.cs b/Neo.ConsoleService/ConsoleHelper.cs index 24dd76fc8..fdf6f180c 100644 --- a/Neo.ConsoleService/ConsoleHelper.cs +++ b/Neo.ConsoleService/ConsoleHelper.cs @@ -9,10 +9,10 @@ public static class ConsoleHelper private static readonly ConsoleColorSet ErrorColor = new(ConsoleColor.Red); /// - /// Info handles message in the form of "[tag]:[msg]", + /// Info handles message in the format of "[tag]:[message]", /// avoid using Info if the `tag` is too long /// - /// + /// The log message in pairs of (tag, message) public static void Info(params string[] values) { var currentColor = new ConsoleColorSet(); @@ -35,7 +35,7 @@ public static void Info(params string[] values) /// Also use warning if you just want to remind /// user of doing something. /// - /// + /// Warning message public static void Warning(string msg) { Log("Warning", WarningColor, msg); @@ -46,7 +46,7 @@ public static void Warning(string msg) /// or exception that breaks the execution of interactive /// command throws. /// - /// + /// Error message public static void Error(string msg) { Log("Error", ErrorColor, msg); From 2ca13126d28f32555fd66670f00761b8e30e62ed Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Thu, 26 Aug 2021 17:37:44 +0800 Subject: [PATCH 24/29] update log --- neo-cli/CLI/MainService.Vote.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/neo-cli/CLI/MainService.Vote.cs b/neo-cli/CLI/MainService.Vote.cs index 9ea4f31d2..d96761632 100644 --- a/neo-cli/CLI/MainService.Vote.cs +++ b/neo-cli/CLI/MainService.Vote.cs @@ -34,10 +34,7 @@ private void OnRegisterCandidateCommand(UInt160 account) var testGas = NativeContract.NEO.GetRegisterPrice(NeoSystem.StoreView) + (BigInteger)Math.Pow(10, NativeContract.GAS.Decimals) * 10; if (NoWallet()) - { - ConsoleHelper.Warning("Need open wallet!"); return; - } WalletAccount currentAccount = CurrentWallet.GetAccount(account); @@ -74,10 +71,7 @@ private void OnRegisterCandidateCommand(UInt160 account) private void OnUnregisterCandidateCommand(UInt160 account) { if (NoWallet()) - { - ConsoleHelper.Warning("Need open wallet!"); return; - } WalletAccount currentAccount = CurrentWallet.GetAccount(account); @@ -115,10 +109,7 @@ private void OnUnregisterCandidateCommand(UInt160 account) private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) { if (NoWallet()) - { - ConsoleHelper.Warning("Need open wallet!"); return; - } byte[] script; using (ScriptBuilder scriptBuilder = new ScriptBuilder()) @@ -138,10 +129,7 @@ private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) private void OnUnvoteCommand(UInt160 senderAccount) { if (NoWallet()) - { - ConsoleHelper.Warning("Need open wallet!"); return; - } byte[] script; using (ScriptBuilder scriptBuilder = new ScriptBuilder()) @@ -228,7 +216,7 @@ private void OnGetNextBlockValidatorsCommand() [ConsoleCommand("get accountstate", Category = "Vote Commands")] private void OnGetAccountState(UInt160 address) { - string notice = "Notice: No vote record!"; + string notice = "No vote record!"; var arg = new JObject(); arg["type"] = "Hash160"; arg["value"] = address.ToString(); @@ -237,7 +225,7 @@ private void OnGetAccountState(UInt160 address) Console.WriteLine(); if (result.IsNull) { - Console.WriteLine(notice); + ConsoleHelper.Warning(notice); return; } var resJArray = (VM.Types.Array)result; @@ -245,7 +233,7 @@ private void OnGetAccountState(UInt160 address) { if (value.IsNull) { - Console.WriteLine(notice); + ConsoleHelper.Warning(notice); return; } } From f8acfbfd0bd9856ec5ff4ecc0e17a7a6ed3cf740 Mon Sep 17 00:00:00 2001 From: superboyiii <573504781@qq.com> Date: Mon, 30 Aug 2021 18:30:35 +0800 Subject: [PATCH 25/29] improve --- neo-cli/CLI/MainService.NEP17.cs | 2 +- neo-cli/CLI/MainService.Node.cs | 4 ++-- neo-cli/CLI/MainService.Plugins.cs | 4 ++-- neo-cli/CLI/MainService.Wallet.cs | 15 ++++++++------- neo-cli/CLI/MainService.cs | 8 ++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/neo-cli/CLI/MainService.NEP17.cs b/neo-cli/CLI/MainService.NEP17.cs index dcc1c8e18..8cce43dbf 100644 --- a/neo-cli/CLI/MainService.NEP17.cs +++ b/neo-cli/CLI/MainService.NEP17.cs @@ -91,7 +91,7 @@ private void OnBalanceOfCommand(UInt160 tokenHash, UInt160 address) var balance = new BigDecimal(((PrimitiveType)balanceResult).GetInteger(), asset.Decimals); Console.WriteLine(); - Console.WriteLine($"{asset.AssetName} balance: {balance}"); + ConsoleHelper.Info($"{asset.AssetName} balance: ", $"{balance}"); } /// diff --git a/neo-cli/CLI/MainService.Node.cs b/neo-cli/CLI/MainService.Node.cs index 0396c8b50..df879e5a2 100644 --- a/neo-cli/CLI/MainService.Node.cs +++ b/neo-cli/CLI/MainService.Node.cs @@ -35,10 +35,10 @@ private void OnShowPoolCommand(bool verbose = false) NeoSystem.MemPool.GetVerifiedAndUnverifiedTransactions( out IEnumerable verifiedTransactions, out IEnumerable unverifiedTransactions); - Console.WriteLine("Verified Transactions:"); + ConsoleHelper.Info("Verified Transactions:"); foreach (Transaction tx in verifiedTransactions) Console.WriteLine($" {tx.Hash} {tx.GetType().Name} {tx.NetworkFee} GAS_NetFee"); - Console.WriteLine("Unverified Transactions:"); + ConsoleHelper.Info("Unverified Transactions:"); foreach (Transaction tx in unverifiedTransactions) Console.WriteLine($" {tx.Hash} {tx.GetType().Name} {tx.NetworkFee} GAS_NetFee"); diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 8ab09d8b3..59a5970e5 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -68,7 +68,7 @@ private void OnInstallCommand(string pluginName) } catch (IOException) { - Console.WriteLine($"Plugin already exist."); + ConsoleHelper.Warning($"Plugin already exist."); } } } @@ -88,7 +88,7 @@ private void OnUnInstallCommand(string pluginName) } if (plugin is Logger) { - ConsoleHelper.Error("You cannot uninstall a built-in plugin."); + ConsoleHelper.Warning("You cannot uninstall a built-in plugin."); return; } diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 96f776516..7bf8ed4fa 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -65,7 +65,7 @@ private void OnCloseWalletCommand() { if (NoWallet()) return; CurrentWallet = null; - ConsoleHelper.Warning("Wallet is closed"); + ConsoleHelper.Info("Wallet is closed"); } /// @@ -76,7 +76,7 @@ private void OnUpgradeWalletCommand(string path) { if (Path.GetExtension(path).ToLowerInvariant() != ".db3") { - ConsoleHelper.Warning("Can't upgrade the wallet file."); + ConsoleHelper.Warning("Can't upgrade the wallet file. Check if your wallet is in db3 format."); return; } if (!File.Exists(path)) @@ -93,7 +93,7 @@ private void OnUpgradeWalletCommand(string path) string path_new = Path.ChangeExtension(path, ".json"); if (File.Exists(path_new)) { - Console.WriteLine($"File '{path_new}' already exists"); + ConsoleHelper.Warning($"File '{path_new}' already exists"); return; } NEP6Wallet.Migrate(path_new, path, password, NeoSystem.Settings).Save(); @@ -363,7 +363,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) WalletAccount account = CurrentWallet.GetAccount(address); if (account is not null) { - Console.WriteLine("This address is already in your wallet"); + ConsoleHelper.Info("This address is already in your wallet"); } else { @@ -651,12 +651,13 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - Console.WriteLine($"Signed and relayed transaction with hash={tx.Hash}"); + ConsoleHelper.Warning("Signed and relayed transaction with hash: "); + ConsoleHelper.Info(tx.Hash.ToString()); } else { - ConsoleHelper.Error("Incomplete signature:"); - Console.WriteLine(context.ToString()); + ConsoleHelper.Warning("Incomplete signature: "); + ConsoleHelper.Info(context.ToString()); } } } diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 5ab56ce76..2a93a03aa 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -145,15 +145,15 @@ public void CreateWallet(string path, string password, bool createDefaultAccount ((NEP6Wallet)CurrentWallet).Unlock(password); break; default: - Console.WriteLine("Wallet files in that format are not supported, please use a .json or .db3 file extension."); + ConsoleHelper.Warning("Wallet files in that format are not supported, please use a .json or .db3 file extension."); return; } if (createDefaultAccount) { WalletAccount account = CurrentWallet.CreateAccount(); - Console.WriteLine($" Address: {account.Address}"); - Console.WriteLine($" Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - Console.WriteLine($"ScriptHash: {account.ScriptHash}"); + ConsoleHelper.Info($" Address: {account.Address}"); + ConsoleHelper.Info($" Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info($"ScriptHash: {account.ScriptHash}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); From 159b039f5c01d980ed620a7e536f4509b274a069 Mon Sep 17 00:00:00 2001 From: superboyiii <573504781@qq.com> Date: Tue, 31 Aug 2021 11:30:44 +0800 Subject: [PATCH 26/29] improve more --- neo-cli/CLI/MainService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 2a93a03aa..6928b834d 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -151,9 +151,9 @@ public void CreateWallet(string path, string password, bool createDefaultAccount if (createDefaultAccount) { WalletAccount account = CurrentWallet.CreateAccount(); - ConsoleHelper.Info($" Address: {account.Address}"); - ConsoleHelper.Info($" Pubkey: {account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); - ConsoleHelper.Info($"ScriptHash: {account.ScriptHash}"); + ConsoleHelper.Info(" Address: ", $"{account.Address}"); + ConsoleHelper.Info(" Pubkey: ", $"{account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info("ScriptHash: ", $"{account.ScriptHash}"); } if (CurrentWallet is NEP6Wallet wallet) wallet.Save(); From 1b9e5525eab829912d071bed0fcb0144f00a3954 Mon Sep 17 00:00:00 2001 From: superboyiii <573504781@qq.com> Date: Tue, 31 Aug 2021 12:20:02 +0800 Subject: [PATCH 27/29] fix --- neo-cli/CLI/MainService.Contracts.cs | 2 +- neo-cli/CLI/MainService.Plugins.cs | 4 ++-- neo-cli/CLI/MainService.Wallet.cs | 16 +++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index 6e8686c13..3311081cb 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -173,7 +173,7 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra return; } ConsoleHelper.Info("Network fee: ", - $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}", + $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}\t", "Total fee: ", $"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS"); if (!ReadUserInput("Relay tx? (no|yes)").IsYes()) diff --git a/neo-cli/CLI/MainService.Plugins.cs b/neo-cli/CLI/MainService.Plugins.cs index 59a5970e5..dabab9dba 100644 --- a/neo-cli/CLI/MainService.Plugins.cs +++ b/neo-cli/CLI/MainService.Plugins.cs @@ -64,7 +64,7 @@ private void OnInstallCommand(string pluginName) try { zip.ExtractToDirectory("."); - ConsoleHelper.Warning("Install successful, please restart neo-cli."); + ConsoleHelper.Info("Install successful, please restart neo-cli."); } catch (IOException) { @@ -101,7 +101,7 @@ private void OnUnInstallCommand(string pluginName) catch (IOException) { } - ConsoleHelper.Warning("Uninstall successful, please restart neo-cli."); + ConsoleHelper.Info("Uninstall successful, please restart neo-cli."); } /// diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 7bf8ed4fa..7aef67195 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -155,11 +155,11 @@ private void OnDeleteAddressCommand(UInt160 address) { wallet.Save(); } - Console.WriteLine($"Address {address} deleted."); + ConsoleHelper.Info($"Address {address} deleted."); } else { - Console.WriteLine($"Address {address} doesn't exist."); + ConsoleHelper.Warning($"Address {address} doesn't exist."); } } } @@ -363,7 +363,7 @@ private void OnImportWatchOnlyCommand(string addressOrFile) WalletAccount account = CurrentWallet.GetAccount(address); if (account is not null) { - ConsoleHelper.Info("This address is already in your wallet"); + ConsoleHelper.Warning("This address is already in your wallet"); } else { @@ -553,11 +553,11 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - ConsoleHelper.Info("TXID: ", tx.Hash.ToString()); + ConsoleHelper.Info("TXID:\n", $"{tx.Hash}"); } else { - ConsoleHelper.Info("SignatureContext:\n", context.ToString()); + ConsoleHelper.Info("SignatureContext:\n", $"{context}"); } } @@ -651,13 +651,11 @@ private void SignAndSendTx(DataCache snapshot, Transaction tx) { tx.Witnesses = context.GetWitnesses(); NeoSystem.Blockchain.Tell(tx); - ConsoleHelper.Warning("Signed and relayed transaction with hash: "); - ConsoleHelper.Info(tx.Hash.ToString()); + ConsoleHelper.Info("Signed and relayed transaction with hash:\n", $"{tx.Hash}"); } else { - ConsoleHelper.Warning("Incomplete signature: "); - ConsoleHelper.Info(context.ToString()); + ConsoleHelper.Info("Incomplete signature:\n", $"{context}"); } } } From 3452aded46232b718c61e115ec3179a715db096a Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Tue, 31 Aug 2021 13:28:46 +0800 Subject: [PATCH 28/29] Optimize --- neo-cli/CLI/MainService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 6928b834d..5020f651e 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -151,8 +151,8 @@ public void CreateWallet(string path, string password, bool createDefaultAccount if (createDefaultAccount) { WalletAccount account = CurrentWallet.CreateAccount(); - ConsoleHelper.Info(" Address: ", $"{account.Address}"); - ConsoleHelper.Info(" Pubkey: ", $"{account.GetKey().PublicKey.EncodePoint(true).ToHexString()}"); + ConsoleHelper.Info(" Address: ", account.Address); + ConsoleHelper.Info(" Pubkey: ", account.GetKey().PublicKey.EncodePoint(true).ToHexString()); ConsoleHelper.Info("ScriptHash: ", $"{account.ScriptHash}"); } if (CurrentWallet is NEP6Wallet wallet) From a8fe751689a15280bd9345f1afb8c342eb38c6cc Mon Sep 17 00:00:00 2001 From: superboyiii <573504781@qq.com> Date: Tue, 31 Aug 2021 14:28:23 +0800 Subject: [PATCH 29/29] fix --- neo-cli/CLI/MainService.Wallet.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 7aef67195..f4835a5fa 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -44,7 +44,7 @@ private void OnOpenWallet(string path) string password = ReadUserInput("password", true); if (password.Length == 0) { - Console.WriteLine("Cancelled"); + ConsoleHelper.Info("Cancelled"); return; } try @@ -87,7 +87,7 @@ private void OnUpgradeWalletCommand(string path) string password = ReadUserInput("password", true); if (password.Length == 0) { - Console.WriteLine("Cancelled"); + ConsoleHelper.Info("Cancelled"); return; } string path_new = Path.ChangeExtension(path, ".json"); @@ -181,12 +181,12 @@ private void OnExportKeyCommand(string path = null, UInt160 scriptHash = null) string password = ReadUserInput("password", true); if (password.Length == 0) { - Console.WriteLine("Cancelled"); + ConsoleHelper.Info("Cancelled"); return; } if (!CurrentWallet.VerifyPassword(password)) { - Console.WriteLine("Incorrect password"); + ConsoleHelper.Error("Incorrect password"); return; } IEnumerable keys; @@ -213,7 +213,7 @@ private void OnCreateWalletCommand(string path, string wifOrFile = null) string password = ReadUserInput("password", true); if (password.Length == 0) { - Console.WriteLine("Cancelled"); + ConsoleHelper.Info("Cancelled"); return; } string password2 = ReadUserInput("repeat password", true); @@ -500,7 +500,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 fro string password = ReadUserInput("password", true); if (password.Length == 0) { - Console.WriteLine("Cancelled"); + ConsoleHelper.Info("Cancelled"); return; } if (!CurrentWallet.VerifyPassword(password)) @@ -586,7 +586,7 @@ private void OnChangePasswordCommand() string oldPassword = ReadUserInput("password", true); if (oldPassword.Length == 0) { - Console.WriteLine("Cancelled"); + ConsoleHelper.Info("Cancelled"); return; } if (!CurrentWallet.VerifyPassword(oldPassword))