Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle problems with listwalletdir properly #331

Merged
merged 4 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/cryptoadvance/specter/devices/bitcoin_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,18 @@ def setup_device(self, mnemonic, passphrase,
self.add_keys(keys)

def _load_wallet(self, wallet_manager):
existing_wallets = [w["name"]
for w
in wallet_manager.cli.listwalletdir()["wallets"]]
try:
existing_wallets = [w["name"]
for w
in wallet_manager.cli.listwalletdir()["wallets"]]
except:
existing_wallets = None
loaded_wallets = wallet_manager.cli.listwallets()
not_loaded_wallets = [
w for w in existing_wallets if w not in loaded_wallets]

hotstorage_path = wallet_manager.cli_path + "_hotstorage"
if os.path.join(hotstorage_path, self.alias) in existing_wallets:
if os.path.join(hotstorage_path, self.alias) in not_loaded_wallets:
if (existing_wallets is None or
os.path.join(hotstorage_path, self.alias) in existing_wallets):
if os.path.join(hotstorage_path, self.alias) not in loaded_wallets:
wallet_manager.cli.loadwallet(os.path.join(
hotstorage_path, self.alias))

Expand Down
21 changes: 9 additions & 12 deletions src/cryptoadvance/specter/wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,24 @@ def update(self, data_folder=None, cli=None, chain=None):
try:
if self.working_folder is not None and self.cli is not None:
wallets_files = load_jsons(self.working_folder, key="name")
existing_wallets = [
w["name"] for w in self.cli.listwalletdir()["wallets"]
]
try:
existing_wallets = [
w["name"] for w in self.cli.listwalletdir()["wallets"]
]
except:
existing_wallets = None
loaded_wallets = self.cli.listwallets()
not_loaded_wallets = [
w for w in existing_wallets if w not in loaded_wallets
]
for wallet in wallets_files:
wallet_alias = wallets_files[wallet]["alias"]
wallet_name = wallets_files[wallet]["name"]
if os.path.join(
if existing_wallets is None or os.path.join(
self.cli_path,
wallet_alias
) in existing_wallets:
if os.path.join(
self.cli_path,
wallet_alias
) in not_loaded_wallets:
) not in loaded_wallets:
try:
logger.debug(
"loading %s " %
Expand Down Expand Up @@ -134,10 +134,7 @@ def update(self, data_folder=None, cli=None, chain=None):
logger.warn(
"Couldn't load wallet %s into core.\
Silently ignored!" % wallet_alias)
elif os.path.join(
self.cli_path,
wallet_alias
) in loaded_wallets:
else:
if wallet_name not in existing_names:
# ok wallet is already there
# we only need to update
Expand Down