payserver: make daemon_wallet_loaded hook reliable
daemon.load_wallet() often early-returns, e.g. in Qt case, for storage-encrypted wallets. closes https://github.com/spesmilo/electrum/issues/8118
This commit is contained in:
@@ -456,8 +456,7 @@ class Daemon(Logger):
|
|||||||
if wallet is None:
|
if wallet is None:
|
||||||
return
|
return
|
||||||
wallet.start_network(self.network)
|
wallet.start_network(self.network)
|
||||||
self._wallets[path] = wallet
|
self.add_wallet(wallet)
|
||||||
run_hook('daemon_wallet_loaded', self, wallet)
|
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -492,6 +491,7 @@ class Daemon(Logger):
|
|||||||
path = wallet.storage.path
|
path = wallet.storage.path
|
||||||
path = standardize_path(path)
|
path = standardize_path(path)
|
||||||
self._wallets[path] = wallet
|
self._wallets[path] = wallet
|
||||||
|
run_hook('daemon_wallet_loaded', self, wallet)
|
||||||
|
|
||||||
def get_wallet(self, path: str) -> Optional[Abstract_Wallet]:
|
def get_wallet(self, path: str) -> Optional[Abstract_Wallet]:
|
||||||
path = standardize_path(path)
|
path = standardize_path(path)
|
||||||
|
|||||||
@@ -26,34 +26,32 @@
|
|||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from aiohttp import ClientResponse
|
from aiohttp import web
|
||||||
from aiohttp import web, client_exceptions
|
|
||||||
from aiorpcx import timeout_after, TaskTimeout, ignore_after
|
|
||||||
from aiorpcx import NetAddress
|
from aiorpcx import NetAddress
|
||||||
|
|
||||||
|
|
||||||
from electrum.util import log_exceptions, ignore_exceptions
|
from electrum.util import log_exceptions, ignore_exceptions
|
||||||
from electrum.crypto import sha256
|
|
||||||
from electrum.plugin import BasePlugin, hook
|
from electrum.plugin import BasePlugin, hook
|
||||||
from electrum.logging import Logger
|
|
||||||
|
|
||||||
|
|
||||||
from electrum.logging import Logger
|
from electrum.logging import Logger
|
||||||
from electrum.util import EventListener, event_listener
|
from electrum.util import EventListener, event_listener
|
||||||
from electrum.invoices import PR_PAID, PR_EXPIRED
|
from electrum.invoices import PR_PAID, PR_EXPIRED
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from electrum.simple_config import SimpleConfig
|
||||||
|
from electrum.daemon import Daemon
|
||||||
|
from electrum.wallet import Abstract_Wallet
|
||||||
|
|
||||||
|
|
||||||
class PayServerPlugin(BasePlugin):
|
class PayServerPlugin(BasePlugin):
|
||||||
|
|
||||||
def __init__(self, parent, config, name):
|
def __init__(self, parent, config: 'SimpleConfig', name):
|
||||||
BasePlugin.__init__(self, parent, config, name)
|
BasePlugin.__init__(self, parent, config, name)
|
||||||
self.config = config
|
self.config = config
|
||||||
self.server = None
|
self.server = None
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def daemon_wallet_loaded(self, daemon, wallet):
|
def daemon_wallet_loaded(self, daemon: 'Daemon', wallet: 'Abstract_Wallet'):
|
||||||
# we use the first wallet loaded
|
# we use the first wallet loaded
|
||||||
if self.server is not None:
|
if self.server is not None:
|
||||||
return
|
return
|
||||||
@@ -71,7 +69,7 @@ class PayServer(Logger, EventListener):
|
|||||||
|
|
||||||
WWW_DIR = os.path.join(os.path.dirname(__file__), 'www')
|
WWW_DIR = os.path.join(os.path.dirname(__file__), 'www')
|
||||||
|
|
||||||
def __init__(self, config, wallet):
|
def __init__(self, config: 'SimpleConfig', wallet: 'Abstract_Wallet'):
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
assert self.has_www_dir(), self.WWW_DIR
|
assert self.has_www_dir(), self.WWW_DIR
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|||||||
Reference in New Issue
Block a user