feat(core): Implement storage.cache.get_int_all_sessions().

andrewkozlik/coinjoin
Andrew Kozlik 1 year ago
parent 00dde0e312
commit e8ac548eb5

@ -46,6 +46,12 @@ def get() -> protobuf.MessageType | None:
return protobuf.load_message_buffer(buffer, msg_wire_type)
def is_set_any_session(auth_type: MessageType) -> bool:
return auth_type in storage_cache.get_int_all_sessions(
APP_COMMON_AUTHORIZATION_TYPE
)
def get_wire_types() -> Iterable[int]:
stored_auth_type = storage_cache.get(APP_COMMON_AUTHORIZATION_TYPE)
if stored_auth_type is None:

@ -1,3 +1,4 @@
import builtins
import gc
from micropython import const
from typing import TYPE_CHECKING
@ -273,6 +274,16 @@ def get_int(key: int, default: T | None = None) -> int | T | None: # noqa: F811
return int.from_bytes(encoded, "big")
def get_int_all_sessions(key: int) -> builtins.set[int]:
sessions = [_SESSIONLESS_CACHE] if key & _SESSIONLESS_FLAG else _SESSIONS
values = builtins.set()
for session in sessions:
encoded = session.get(key)
if encoded is not None:
values.add(int.from_bytes(encoded, "big"))
return values
def is_set(key: int) -> bool:
if key & _SESSIONLESS_FLAG:
return _SESSIONLESS_CACHE.is_set(key ^ _SESSIONLESS_FLAG)

Loading…
Cancel
Save