|
@ -174,7 +174,7 @@ class WatchTowerServer(Logger): |
|
|
|
|
|
|
|
|
class HttpServer(Logger): |
|
|
class HttpServer(Logger): |
|
|
|
|
|
|
|
|
def __init__(self, daemon): |
|
|
def __init__(self, daemon: 'Daemon'): |
|
|
Logger.__init__(self) |
|
|
Logger.__init__(self) |
|
|
self.daemon = daemon |
|
|
self.daemon = daemon |
|
|
self.config = daemon.config |
|
|
self.config = daemon.config |
|
@ -287,7 +287,7 @@ class Daemon(Logger): |
|
|
self.fx = FxThread(config, self.network) |
|
|
self.fx = FxThread(config, self.network) |
|
|
self.gui_object = None |
|
|
self.gui_object = None |
|
|
# path -> wallet; make sure path is standardized. |
|
|
# path -> wallet; make sure path is standardized. |
|
|
self.wallets = {} # type: Dict[str, Abstract_Wallet] |
|
|
self._wallets = {} # type: Dict[str, Abstract_Wallet] |
|
|
jobs = [self.fx.run] |
|
|
jobs = [self.fx.run] |
|
|
# Setup JSONRPC server |
|
|
# Setup JSONRPC server |
|
|
if listen_jsonrpc: |
|
|
if listen_jsonrpc: |
|
@ -379,8 +379,8 @@ class Daemon(Logger): |
|
|
def load_wallet(self, path, password) -> Optional[Abstract_Wallet]: |
|
|
def load_wallet(self, path, password) -> Optional[Abstract_Wallet]: |
|
|
path = standardize_path(path) |
|
|
path = standardize_path(path) |
|
|
# wizard will be launched if we return |
|
|
# wizard will be launched if we return |
|
|
if path in self.wallets: |
|
|
if path in self._wallets: |
|
|
wallet = self.wallets[path] |
|
|
wallet = self._wallets[path] |
|
|
return wallet |
|
|
return wallet |
|
|
storage = WalletStorage(path, manual_upgrades=True) |
|
|
storage = WalletStorage(path, manual_upgrades=True) |
|
|
if not storage.file_exists(): |
|
|
if not storage.file_exists(): |
|
@ -397,38 +397,39 @@ class Daemon(Logger): |
|
|
return |
|
|
return |
|
|
wallet = Wallet(storage) |
|
|
wallet = Wallet(storage) |
|
|
wallet.start_network(self.network) |
|
|
wallet.start_network(self.network) |
|
|
self.wallets[path] = wallet |
|
|
self._wallets[path] = wallet |
|
|
self.wallet = wallet |
|
|
self.wallet = wallet |
|
|
return wallet |
|
|
return wallet |
|
|
|
|
|
|
|
|
def add_wallet(self, wallet: Abstract_Wallet): |
|
|
def add_wallet(self, wallet: Abstract_Wallet) -> None: |
|
|
path = wallet.storage.path |
|
|
path = wallet.storage.path |
|
|
path = standardize_path(path) |
|
|
path = standardize_path(path) |
|
|
self.wallets[path] = wallet |
|
|
self._wallets[path] = wallet |
|
|
|
|
|
|
|
|
def get_wallet(self, path): |
|
|
def get_wallet(self, path: str) -> Abstract_Wallet: |
|
|
path = standardize_path(path) |
|
|
path = standardize_path(path) |
|
|
return self.wallets.get(path) |
|
|
return self._wallets.get(path) |
|
|
|
|
|
|
|
|
def delete_wallet(self, path): |
|
|
def get_wallets(self) -> Dict[str, Abstract_Wallet]: |
|
|
|
|
|
return dict(self._wallets) # copy |
|
|
|
|
|
|
|
|
|
|
|
def delete_wallet(self, path: str) -> bool: |
|
|
self.stop_wallet(path) |
|
|
self.stop_wallet(path) |
|
|
if os.path.exists(path): |
|
|
if os.path.exists(path): |
|
|
os.unlink(path) |
|
|
os.unlink(path) |
|
|
return True |
|
|
return True |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
def stop_wallet(self, path) -> bool: |
|
|
def stop_wallet(self, path: str) -> bool: |
|
|
"""Returns True iff a wallet was found.""" |
|
|
"""Returns True iff a wallet was found.""" |
|
|
path = standardize_path(path) |
|
|
path = standardize_path(path) |
|
|
wallet = self.wallets.pop(path, None) |
|
|
wallet = self._wallets.pop(path, None) |
|
|
if not wallet: |
|
|
if not wallet: |
|
|
return False |
|
|
return False |
|
|
wallet.stop_threads() |
|
|
wallet.stop_threads() |
|
|
return True |
|
|
return True |
|
|
|
|
|
|
|
|
async def run_cmdline(self, config_options): |
|
|
async def run_cmdline(self, config_options): |
|
|
password = config_options.get('password') |
|
|
|
|
|
new_password = config_options.get('new_password') |
|
|
|
|
|
config = SimpleConfig(config_options) |
|
|
config = SimpleConfig(config_options) |
|
|
# FIXME this is ugly... |
|
|
# FIXME this is ugly... |
|
|
config.fee_estimates = self.network.config.fee_estimates.copy() |
|
|
config.fee_estimates = self.network.config.fee_estimates.copy() |
|
@ -474,7 +475,7 @@ class Daemon(Logger): |
|
|
if self.gui_object: |
|
|
if self.gui_object: |
|
|
self.gui_object.stop() |
|
|
self.gui_object.stop() |
|
|
# stop network/wallets |
|
|
# stop network/wallets |
|
|
for k, wallet in self.wallets.items(): |
|
|
for k, wallet in self._wallets.items(): |
|
|
wallet.stop_threads() |
|
|
wallet.stop_threads() |
|
|
if self.network: |
|
|
if self.network: |
|
|
self.logger.info("shutting down network") |
|
|
self.logger.info("shutting down network") |
|
|