1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-04 21:48:17 +00:00

refactor(core): improve readability of channel_manager

[no changelog]
This commit is contained in:
M1nd3r 2024-12-03 17:18:40 +01:00
parent 1adf4a9d5b
commit c019e65631

View File

@ -15,10 +15,10 @@ def create_new_channel(iface: WireInterface, buffer: utils.BufferType) -> Channe
Creates a new channel for the interface `iface` with the buffer `buffer`. Creates a new channel for the interface `iface` with the buffer `buffer`.
""" """
channel_cache = cache_thp.get_new_channel(interface_manager.encode_iface(iface)) channel_cache = cache_thp.get_new_channel(interface_manager.encode_iface(iface))
r = Channel(channel_cache) channel = Channel(channel_cache)
r.set_buffer(buffer) channel.set_buffer(buffer)
r.set_channel_state(ChannelState.TH1) channel.set_channel_state(ChannelState.TH1)
return r return channel
def load_cached_channels(buffer: utils.BufferType) -> dict[int, Channel]: def load_cached_channels(buffer: utils.BufferType) -> dict[int, Channel]:
@ -27,8 +27,8 @@ def load_cached_channels(buffer: utils.BufferType) -> dict[int, Channel]:
""" """
channels: dict[int, Channel] = {} channels: dict[int, Channel] = {}
cached_channels = cache_thp.get_all_allocated_channels() cached_channels = cache_thp.get_all_allocated_channels()
for c in cached_channels: for channel in cached_channels:
channels[int.from_bytes(c.channel_id, "big")] = Channel(c) channels[int.from_bytes(channel.channel_id, "big")] = Channel(channel)
for c in channels.values(): for channel in channels.values():
c.set_buffer(buffer) channel.set_buffer(buffer)
return channels return channels