1
0

Refresh LN status in GUI using network callback.

This commit is contained in:
ThomasV
2018-07-13 12:28:00 +02:00
parent 9145d61797
commit 1db7a8334a
6 changed files with 14 additions and 7 deletions

View File

@@ -282,7 +282,6 @@ def aiosafe(f):
class Peer(PrintError):
def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False):
self.channel_update_event = asyncio.Event()
self.host = host
self.port = port
self.pubkey = pubkey
@@ -457,17 +456,17 @@ class Peer(PrintError):
'addresses': addresses
}
self.print_error('node announcement', binascii.hexlify(pubkey), alias, addresses)
self.network.trigger_callback('ln_status')
def on_init(self, payload):
pass
def on_channel_update(self, payload):
self.channel_db.on_channel_update(payload)
self.channel_update_event.set()
def on_channel_announcement(self, payload):
self.channel_db.on_channel_announcement(payload)
self.channel_update_event.set()
self.network.trigger_callback('ln_status')
def on_announcement_signatures(self, payload):
channel_id = payload['channel_id']

View File

@@ -100,6 +100,9 @@ class ChannelDB(PrintError):
self._id_to_channel_info = {}
self._channels_for_node = defaultdict(set) # node -> set(short_channel_id)
def __len__(self):
return len(self._id_to_channel_info)
def get_channel_info(self, channel_id):
return self._id_to_channel_info.get(channel_id, None)

View File

@@ -57,7 +57,7 @@ class LNWorker(PrintError):
peer = Peer(self, host, int(port), node_id, request_initial_sync=self.config.get("request_initial_sync", True))
self.network.futures.append(asyncio.run_coroutine_threadsafe(peer.main_loop(), asyncio.get_event_loop()))
self.peers[node_id] = peer
self.lock = threading.Lock()
self.network.trigger_callback('ln_status')
def save_channel(self, openchannel):
assert type(openchannel) is HTLCStateMachine

View File

@@ -26,6 +26,7 @@ class Test_LNRouter(unittest.TestCase):
def test_find_path_for_payment(self):
class fake_network:
channel_db = lnrouter.ChannelDB()
trigger_callback = lambda x: None
class fake_ln_worker:
path_finder = lnrouter.LNPathFinder(fake_network.channel_db)
privkey = bitcoin.sha256('privkeyseed')