cli: fix add_peer cmd
This commit is contained in:
@@ -776,7 +776,9 @@ class Commands:
|
||||
# lightning network commands
|
||||
@command('wn')
|
||||
def add_peer(self, connection_string, timeout=20):
|
||||
return self.lnworker.add_peer(connection_string)
|
||||
coro = self.lnworker.add_peer(connection_string)
|
||||
self.network.run_from_another_thread(coro, timeout=timeout)
|
||||
return True
|
||||
|
||||
@command('wpn')
|
||||
def open_channel(self, connection_string, amount, channel_push=0, password=None):
|
||||
|
||||
@@ -643,7 +643,7 @@ class LNWallet(LNWorker):
|
||||
def on_channels_updated(self):
|
||||
self.network.trigger_callback('channels')
|
||||
|
||||
async def add_peer(self, connect_str, timeout=20):
|
||||
async def add_peer(self, connect_str: str) -> Peer:
|
||||
node_id, rest = extract_nodeid(connect_str)
|
||||
peer = self.peers.get(node_id)
|
||||
if not peer:
|
||||
|
||||
@@ -311,10 +311,10 @@ class Network(Logger):
|
||||
self.lnwatcher = None
|
||||
self.lngossip = None
|
||||
|
||||
def run_from_another_thread(self, coro):
|
||||
def run_from_another_thread(self, coro, *, timeout=None):
|
||||
assert self._loop_thread != threading.current_thread(), 'must not be called from network thread'
|
||||
fut = asyncio.run_coroutine_threadsafe(coro, self.asyncio_loop)
|
||||
return fut.result()
|
||||
return fut.result(timeout)
|
||||
|
||||
@staticmethod
|
||||
def get_instance() -> Optional["Network"]:
|
||||
|
||||
Reference in New Issue
Block a user