mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 17:31:36 +00:00
lnbase: decorator that handles exceptions
This commit is contained in:
parent
177286ab1d
commit
f62887e565
1 changed files with 26 additions and 21 deletions
|
@ -223,6 +223,19 @@ def get_unused_public_keys():
|
||||||
_, _, _, _, child_c, child_cK = bitcoin.deserialize_xpub(childxpub)
|
_, _, _, _, child_c, child_cK = bitcoin.deserialize_xpub(childxpub)
|
||||||
yield child_cK
|
yield child_cK
|
||||||
|
|
||||||
|
def aiosafe(f):
|
||||||
|
async def f2(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return await f(*args, **kwargs)
|
||||||
|
except:
|
||||||
|
# if the loop isn't stopped
|
||||||
|
# run_forever in network.py would not return,
|
||||||
|
# the asyncioThread would not die,
|
||||||
|
# and we would block on shutdown
|
||||||
|
asyncio.get_event_loop().stop()
|
||||||
|
traceback.print_exc()
|
||||||
|
return f2
|
||||||
|
|
||||||
class Peer(PrintError):
|
class Peer(PrintError):
|
||||||
|
|
||||||
def __init__(self, privkey, host, port, pubkey):
|
def __init__(self, privkey, host, port, pubkey):
|
||||||
|
@ -332,29 +345,22 @@ class Peer(PrintError):
|
||||||
#def open_channel(self, funding_sat, push_msat):
|
#def open_channel(self, funding_sat, push_msat):
|
||||||
# self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat))
|
# self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat))
|
||||||
|
|
||||||
|
@aiosafe
|
||||||
async def main_loop(self):
|
async def main_loop(self):
|
||||||
try:
|
self.reader, self.writer = await asyncio.open_connection(self.host, self.port)
|
||||||
self.reader, self.writer = await asyncio.open_connection(self.host, self.port)
|
await self.handshake()
|
||||||
await self.handshake()
|
# send init
|
||||||
# send init
|
self.send_message(gen_msg("init", gflen=0, lflen=0))
|
||||||
self.send_message(gen_msg("init", gflen=0, lflen=0))
|
# read init
|
||||||
# read init
|
msg = await self.read_message()
|
||||||
|
self.process_message(msg)
|
||||||
|
# initialized
|
||||||
|
self.init_message_received_future.set_result(msg)
|
||||||
|
# loop
|
||||||
|
while True:
|
||||||
|
self.ping_if_required()
|
||||||
msg = await self.read_message()
|
msg = await self.read_message()
|
||||||
self.process_message(msg)
|
self.process_message(msg)
|
||||||
# initialized
|
|
||||||
self.init_message_received_future.set_result(msg)
|
|
||||||
# loop
|
|
||||||
while True:
|
|
||||||
self.ping_if_required()
|
|
||||||
msg = await self.read_message()
|
|
||||||
self.process_message(msg)
|
|
||||||
except:
|
|
||||||
# if the loop isn't stopped
|
|
||||||
# run_forever in network.py would not return,
|
|
||||||
# the asyncioThread would not die,
|
|
||||||
# and we would block on shutdown
|
|
||||||
asyncio.get_event_loop().stop()
|
|
||||||
traceback.print_exc()
|
|
||||||
# close socket
|
# close socket
|
||||||
self.print_error('closing lnbase')
|
self.print_error('closing lnbase')
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
|
@ -370,7 +376,6 @@ class Peer(PrintError):
|
||||||
accept_channel = await self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
accept_channel = await self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
||||||
finally:
|
finally:
|
||||||
del self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
del self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
|
||||||
|
|
||||||
raise Exception("TODO: create funding transaction using wallet")
|
raise Exception("TODO: create funding transaction using wallet")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue