From 546619659bb96f2391f4c424099b793154593c1d Mon Sep 17 00:00:00 2001 From: Qiao Jin Date: Wed, 18 Aug 2021 14:43:44 +0800 Subject: [PATCH 1/3] add delete address command --- neo-cli/CLI/MainService.Wallet.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index a35c2f29f..142af6607 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -133,6 +133,36 @@ private void OnCreateAddressCommand(ushort count = 1) File.WriteAllLines(path, addresses); } + /// + /// Process "delete address" command + /// + /// Address + [ConsoleCommand("delete address", Category = "Wallet Commands")] + private void OnDeleteAddressCommand(UInt160 address) + { + if (NoWallet()) + { + Console.WriteLine("Need open wallet!"); + return; + } + + if (ReadUserInput($"Warning: Deleted address can no longer be back.\nAre you sure to delete address {address.ToAddress(NeoSystem.Settings.AddressVersion)}? (no|yes)").IsYes()) + { + if (CurrentWallet.DeleteAccount(address)) + { + if (CurrentWallet is NEP6Wallet wallet) + { + wallet.Save(); + } + Console.WriteLine($"Address {address} deleted."); + } + else + { + Console.WriteLine($"Address {address} doesn't exist."); + } + } + } + /// /// Process "export key" command /// From ec23f6967b1c8d8204f70246db8f62ea5de4d250 Mon Sep 17 00:00:00 2001 From: Qiao Jin Date: Wed, 18 Aug 2021 15:02:12 +0800 Subject: [PATCH 2/3] optimize --- neo-cli/CLI/MainService.Contracts.cs | 2 +- neo-cli/CLI/MainService.Vote.cs | 24 ++++-------------------- neo-cli/CLI/MainService.Wallet.cs | 6 +----- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/neo-cli/CLI/MainService.Contracts.cs b/neo-cli/CLI/MainService.Contracts.cs index ab12639ce..10164c4f2 100644 --- a/neo-cli/CLI/MainService.Contracts.cs +++ b/neo-cli/CLI/MainService.Contracts.cs @@ -57,7 +57,7 @@ private void OnUpdateCommand(UInt160 scriptHash, string filePath, string manifes Signer[] signers = Array.Empty(); if (NoWallet()) return; - if (!NoWallet() && sender != null) + if (sender != null) { if (signerAccounts == null) signerAccounts = new UInt160[1] { sender }; diff --git a/neo-cli/CLI/MainService.Vote.cs b/neo-cli/CLI/MainService.Vote.cs index 2792933c6..6d73d59dd 100644 --- a/neo-cli/CLI/MainService.Vote.cs +++ b/neo-cli/CLI/MainService.Vote.cs @@ -23,11 +23,7 @@ private void OnRegisterCandidateCommand(UInt160 account) { var testGas = NativeContract.NEO.GetRegisterPrice(NeoSystem.StoreView) + (BigInteger)Math.Pow(10, NativeContract.GAS.Decimals) * 10; - if (NoWallet()) - { - Console.WriteLine("Need open wallet!"); - return; - } + if (NoWallet()) return; WalletAccount currentAccount = CurrentWallet.GetAccount(account); @@ -63,11 +59,7 @@ private void OnRegisterCandidateCommand(UInt160 account) [ConsoleCommand("unregister candidate", Category = "Vote Commands")] private void OnUnregisterCandidateCommand(UInt160 account) { - if (NoWallet()) - { - Console.WriteLine("Need open wallet!"); - return; - } + if (NoWallet()) return; WalletAccount currentAccount = CurrentWallet.GetAccount(account); @@ -104,11 +96,7 @@ private void OnUnregisterCandidateCommand(UInt160 account) [ConsoleCommand("vote", Category = "Vote Commands")] private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) { - if (NoWallet()) - { - Console.WriteLine("Need open wallet!"); - return; - } + if (NoWallet()) return; byte[] script; using (ScriptBuilder scriptBuilder = new ScriptBuilder()) @@ -127,11 +115,7 @@ private void OnVoteCommand(UInt160 senderAccount, ECPoint publicKey) [ConsoleCommand("unvote", Category = "Vote Commands")] private void OnUnvoteCommand(UInt160 senderAccount) { - if (NoWallet()) - { - Console.WriteLine("Need open wallet!"); - return; - } + if (NoWallet()) return; byte[] script; using (ScriptBuilder scriptBuilder = new ScriptBuilder()) diff --git a/neo-cli/CLI/MainService.Wallet.cs b/neo-cli/CLI/MainService.Wallet.cs index 142af6607..2a28a81c6 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -140,11 +140,7 @@ private void OnCreateAddressCommand(ushort count = 1) [ConsoleCommand("delete address", Category = "Wallet Commands")] private void OnDeleteAddressCommand(UInt160 address) { - if (NoWallet()) - { - Console.WriteLine("Need open wallet!"); - return; - } + if (NoWallet()) return; if (ReadUserInput($"Warning: Deleted address can no longer be back.\nAre you sure to delete address {address.ToAddress(NeoSystem.Settings.AddressVersion)}? (no|yes)").IsYes()) { From 20199aeb0aa6cfc697290c99ae6422043c70ae6e Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Wed, 25 Aug 2021 16:02:00 +0800 Subject: [PATCH 3/3] Update neo-cli/CLI/MainService.Wallet.cs Co-authored-by: Jinghui Liao --- 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 21a87ee23..f6ea2dfcc 100644 --- a/neo-cli/CLI/MainService.Wallet.cs +++ b/neo-cli/CLI/MainService.Wallet.cs @@ -147,7 +147,7 @@ private void OnDeleteAddressCommand(UInt160 address) { if (NoWallet()) return; - if (ReadUserInput($"Warning: Deleted address can no longer be back.\nAre you sure to delete address {address.ToAddress(NeoSystem.Settings.AddressVersion)}? (no|yes)").IsYes()) + if (ReadUserInput($"Warning: Irrevocable operation!\nAre you sure to delete account {address.ToAddress(NeoSystem.Settings.AddressVersion)}? (no|yes)").IsYes()) { if (CurrentWallet.DeleteAccount(address)) {