From cc9ad3ae9087831e668a55120ec279f8a7135584 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 5 Jul 2019 19:27:44 +0200 Subject: [PATCH] wallet: fix restore_wallet_from_text edge case closes #5490 --- electrum/tests/test_wallet.py | 7 +++++++ electrum/wallet.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/electrum/tests/test_wallet.py b/electrum/tests/test_wallet.py index f7ed78494..7d062501d 100644 --- a/electrum/tests/test_wallet.py +++ b/electrum/tests/test_wallet.py @@ -189,6 +189,13 @@ class TestCreateRestoreWallet(WalletTestCase): self.assertEqual(text, wallet.keystore.get_master_public_key()) self.assertEqual('bc1q2ccr34wzep58d4239tl3x3734ttle92a8srmuw', wallet.get_receiving_addresses()[0]) + def test_restore_wallet_from_text_xkey_that_is_also_a_valid_electrum_seed_by_chance(self): + text = 'yprvAJBpuoF4FKpK92ofzQ7ge6VJMtorow3maAGPvPGj38ggr2xd1xCrC9ojUVEf9jhW5L9SPu6fU2U3o64cLrRQ83zaQGNa6YP3ajZS6hHNPXj' + d = restore_wallet_from_text(text, path=self.wallet_path, network=None, gap_limit=1) + wallet = d['wallet'] # type: Standard_Wallet + self.assertEqual(text, wallet.keystore.get_master_private_key(password=None)) + self.assertEqual('3Pa4hfP3LFWqa2nfphYaF7PZfdJYNusAnp', wallet.get_receiving_addresses()[0]) + def test_restore_wallet_from_text_xprv(self): text = 'zprvAZzHPqhCMt51fskXBUYB1fTFYgG3CBjJUT4WEZTpGw6hPSDWBPZYZARC5sE9xAcX8NeWvvucFws8vZxEa65RosKAhy7r5MsmKTxr3hmNmea' d = restore_wallet_from_text(text, path=self.wallet_path, network=None, gap_limit=1) diff --git a/electrum/wallet.py b/electrum/wallet.py index 12ad89d59..051bba8b6 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -2051,10 +2051,10 @@ def restore_wallet_from_text(text, *, path, network=None, if not good_inputs: raise Exception("None of the given privkeys can be imported") else: - if keystore.is_seed(text): - k = keystore.from_seed(text, passphrase) - elif keystore.is_master_key(text): + if keystore.is_master_key(text): k = keystore.from_master_key(text) + elif keystore.is_seed(text): + k = keystore.from_seed(text, passphrase) else: raise Exception("Seed or key not recognized") storage.put('keystore', k.dump())