|
|
|
|
@ -25,34 +25,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import asyncio |
|
|
|
|
import os |
|
|
|
|
import random |
|
|
|
|
from typing import TYPE_CHECKING |
|
|
|
|
|
|
|
|
|
from electrum.plugin import BasePlugin, hook |
|
|
|
|
from electrum.util import log_exceptions, ignore_exceptions |
|
|
|
|
from electrum import ecc |
|
|
|
|
|
|
|
|
|
from .server import SwapServer |
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING: |
|
|
|
|
from electrum.simple_config import SimpleConfig |
|
|
|
|
from electrum.daemon import Daemon |
|
|
|
|
from electrum.wallet import Abstract_Wallet |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SwapServerPlugin(BasePlugin): |
|
|
|
|
|
|
|
|
|
def __init__(self, parent, config, name): |
|
|
|
|
def __init__(self, parent, config: 'SimpleConfig', name): |
|
|
|
|
BasePlugin.__init__(self, parent, config, name) |
|
|
|
|
self.config = config |
|
|
|
|
self.server = None |
|
|
|
|
|
|
|
|
|
@hook |
|
|
|
|
def daemon_wallet_loaded(self, daemon, wallet): |
|
|
|
|
def daemon_wallet_loaded(self, daemon: 'Daemon', wallet: 'Abstract_Wallet'): |
|
|
|
|
# we use the first wallet loaded |
|
|
|
|
if self.server is not None: |
|
|
|
|
return |
|
|
|
|
if self.config.get('offline'): |
|
|
|
|
if self.config.NETWORK_OFFLINE: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
self.server = SwapServer(self.config, wallet) |
|
|
|
|
sm = wallet.lnworker.swap_manager |
|
|
|
|
jobs = [ |
|
|
|
|
sm.pay_pending_invoices(), |
|
|
|
|
for coro in [ |
|
|
|
|
sm.pay_pending_invoices(), # FIXME this method can raise, which is not properly handled...? |
|
|
|
|
self.server.run(), |
|
|
|
|
] |
|
|
|
|
asyncio.run_coroutine_threadsafe(daemon._run(jobs=jobs), daemon.asyncio_loop) |
|
|
|
|
]: |
|
|
|
|
asyncio.run_coroutine_threadsafe(daemon.taskgroup.spawn(coro), daemon.asyncio_loop) |
|
|
|
|
|