From 7e7b1d0929557fa0027e76c9281e5a19820267a1 Mon Sep 17 00:00:00 2001 From: jseagrave21 Date: Wed, 29 May 2019 23:07:44 -0400 Subject: [PATCH 1/3] include alias in pretty print - if an alias exists for the address, print the alias --- neo/Implementations/Wallets/peewee/UserWallet.py | 9 +++++++++ neo/Prompt/Commands/tests/test_address_commands.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/neo/Implementations/Wallets/peewee/UserWallet.py b/neo/Implementations/Wallets/peewee/UserWallet.py index 291f2d4c7..d224f2493 100755 --- a/neo/Implementations/Wallets/peewee/UserWallet.py +++ b/neo/Implementations/Wallets/peewee/UserWallet.py @@ -525,8 +525,17 @@ def pretty_print(self, verbose=False): 'tokens': self._get_token_balances(addr_str) }}) + aliases = dict() + alia = NamedAddress.select() + if len(alia): + for n in alia: + aliases[n.Title] = n.ToString() + # pretty print for address, data in addresses.items(): + for title, addr in aliases.items(): + if address == addr: + print(f"Alias : {title}") addr_str = address + " (watch only)" if data['watchonly'] else address print(f"Address : {addr_str}") if verbose: diff --git a/neo/Prompt/Commands/tests/test_address_commands.py b/neo/Prompt/Commands/tests/test_address_commands.py index e73536d8f..af5391f98 100644 --- a/neo/Prompt/Commands/tests/test_address_commands.py +++ b/neo/Prompt/Commands/tests/test_address_commands.py @@ -97,6 +97,14 @@ def test_wallet_alias(self): res = CommandWallet().execute(args) self.assertFalse(res) + # verify wallet has no aliases + with patch('sys.stdout', new=StringIO()) as mock_print: + args = [""] + res = CommandWallet().execute(args) + self.assertTrue(res) + self.assertEqual(len(PromptData.Wallet.NamedAddr), 0) + self.assertNotIn("Alias", mock_print.getvalue()) + # test wallet alias successful self.assertNotIn('mine', [n.Title for n in PromptData.Wallet.NamedAddr]) @@ -105,6 +113,12 @@ def test_wallet_alias(self): self.assertTrue(res) self.assertIn('mine', [n.Title for n in PromptData.Wallet.NamedAddr]) + with patch('sys.stdout', new=StringIO()) as mock_print: + args = [""] + res = CommandWallet().execute(args) + self.assertTrue(res) + self.assertIn("Alias : mine", mock_print.getvalue()) + def test_6_split_unspent(self): wallet = self.GetWallet1(recreate=True) addr = wallet.ToScriptHash('AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3') From d5cfa511ed26b57e2514d39a2b3df5439e2cf745 Mon Sep 17 00:00:00 2001 From: jseagrave21 Date: Wed, 29 May 2019 23:09:42 -0400 Subject: [PATCH 2/3] update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6d49ff6cc..b974e5b55 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -31,7 +31,7 @@ All notable changes to this project are documented in this file. - Various code cleaning updates - Ensure LevelDB iterators are close, ensure all ``MemoryStream`` usages go through ``StreamManger`` and are closed. - Fix ``np-import`` not importing headers ahead of block persisting potentially unexpected VM execution results - +- Extend ``pretty_print`` to include address aliases [0.8.4] 2019-02-14 ------------------ From fceeec53e40d81ae9986524fc00f39a641e4f5ef Mon Sep 17 00:00:00 2001 From: jseagrave21 Date: Tue, 4 Jun 2019 23:29:35 -0400 Subject: [PATCH 3/3] update per feedback --- neo/Implementations/Wallets/peewee/UserWallet.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/neo/Implementations/Wallets/peewee/UserWallet.py b/neo/Implementations/Wallets/peewee/UserWallet.py index d224f2493..e9016a932 100755 --- a/neo/Implementations/Wallets/peewee/UserWallet.py +++ b/neo/Implementations/Wallets/peewee/UserWallet.py @@ -527,9 +527,8 @@ def pretty_print(self, verbose=False): aliases = dict() alia = NamedAddress.select() - if len(alia): - for n in alia: - aliases[n.Title] = n.ToString() + for n in alia: + aliases[n.Title] = n.ToString() # pretty print for address, data in addresses.items():