Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ All notable changes to this project are documented in this file.
- Fix ``np-import`` not importing headers ahead of block persisting potentially unexpected VM execution results
- Fix undesired debug statement printing
- Add negative bitwise shifting support for ``BigInteger`` to match C#
- Include address aliases in ``wallet`` command output
- Fix ``config maxpeers`` and update tests


Expand Down
8 changes: 8 additions & 0 deletions neo/Implementations/Wallets/peewee/UserWallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,16 @@ def pretty_print(self, verbose=False):
'tokens': self._get_token_balances(addr_str)
}})

aliases = dict()
alia = NamedAddress.select()
for n in alia:
aliases[n.Title] = n.ToString()

# pretty print
for address, data in addresses.items():
for title, addr in aliases.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a general comment;

I think we could have used NamedAddress.get() to query if an alias exists for the given address/scripthash instead of iterating over all available data. Now it doesn't really matter as we won't have a huge list of aliases. Just something to try and keep in mind when you encounter some performance critical part with larger data sets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback!

if address == addr:
print(f"Alias : {title}")
addr_str = address + " (watch only)" if data['watchonly'] else address
print(f"Address : {addr_str}")
if verbose:
Expand Down
14 changes: 14 additions & 0 deletions neo/Prompt/Commands/tests/test_address_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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')
Expand Down