Skip to content

Commit

Permalink
Merge pull request #197 from ben-kaufman/fix-wallets-loading
Browse files Browse the repository at this point in the history
Fix wallets loading issue
  • Loading branch information
stepansnigirev authored Jul 6, 2020
2 parents b52785e + 40934e9 commit d6363cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/cryptoadvance/specter/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ def update(self, data_folder=None):
# creating folders if they don't exist
if not os.path.isdir(data_folder):
os.mkdir(data_folder)
self.devices = {}
devices = {}
devices_files = load_jsons(self.data_folder, key="name")
for device_alias in devices_files:
fullpath = os.path.join(self.data_folder, "%s.json" % device_alias)
self.devices[devices_files[device_alias]["name"]] = get_device_class(devices_files[device_alias]["type"]).from_json(
devices[devices_files[device_alias]["name"]] = get_device_class(devices_files[device_alias]["type"]).from_json(
devices_files[device_alias],
self,
default_alias=device_alias,
default_fullpath=fullpath
)
self.devices = devices

@property
def devices_names(self):
Expand Down
15 changes: 8 additions & 7 deletions src/cryptoadvance/specter/wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def update(self, data_folder=None, cli=None, chain=None):
if cli is not None:
self.cli = cli

self.wallets = {}
wallets = {}
if self.working_folder is not None:
wallets_files = load_jsons(self.working_folder, key="name")
existing_wallets = [w["name"] for w in self.cli.listwalletdir()["wallets"]]
Expand All @@ -74,18 +74,19 @@ def update(self, data_folder=None, cli=None, chain=None):
try:
logger.debug("loading %s " % wallets_files[wallet]["alias"])
self.cli.loadwallet(os.path.join(self.cli_path, wallet_alias))
self.wallets[wallet_name] = Wallet.from_json(wallets_files[wallet], self.device_manager, self)
wallets[wallet_name] = Wallet.from_json(wallets_files[wallet], self.device_manager, self)
# Lock UTXO of pending PSBTs
if len(self.wallets[wallet_name].pending_psbts) > 0:
for psbt in self.wallets[wallet_name].pending_psbts:
logger.debug("lock %s " % wallet_alias, self.wallets[wallet_name].pending_psbts[psbt]["tx"]["vin"])
self.wallets[wallet_name].cli.lockunspent(False, [utxo for utxo in self.wallets[wallet_name].pending_psbts[psbt]["tx"]["vin"]])
if len(wallets[wallet_name].pending_psbts) > 0:
for psbt in wallets[wallet_name].pending_psbts:
logger.debug("lock %s " % wallet_alias, wallets[wallet_name].pending_psbts[psbt]["tx"]["vin"])
wallets[wallet_name].cli.lockunspent(False, [utxo for utxo in wallets[wallet_name].pending_psbts[psbt]["tx"]["vin"]])
except RpcError:
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:
self.wallets[wallet_name] = Wallet.from_json(wallets_files[wallet], self.device_manager, self)
wallets[wallet_name] = Wallet.from_json(wallets_files[wallet], self.device_manager, self)
else:
logger.warn("Couldn't find wallet %s in core's wallets. Silently ignored!" % wallet_alias)
self.wallets = wallets
self.is_loading = False

def get_by_alias(self, alias):
Expand Down

0 comments on commit d6363cf

Please sign in to comment.