server: Try to convert in known_active_capabilities (#15046)

This commit is contained in:
dustinface 2023-04-18 23:28:00 +07:00 committed by GitHub
parent e5b94d34a0
commit 58302968d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,22 +5,20 @@ from typing import Iterable, List, Set, Tuple
from chia.protocols.shared_protocol import Capability
from chia.util.ints import uint16
_capability_values = {int(capability) for capability in Capability}
def known_active_capabilities(values: Iterable[Tuple[uint16, str]]) -> List[Capability]:
# NOTE: order is not guaranteed
# TODO: what if there's a claim for both supporting and not?
# presently it considers it supported
filtered: Set[uint16] = set()
filtered: Set[Capability] = set()
for value, state in values:
if state != "1":
continue
if value not in _capability_values:
continue
filtered.add(value)
try:
filtered.add(Capability(value))
except ValueError:
pass
# TODO: consider changing all uses to sets instead of lists
return [Capability(value) for value in filtered]
return list(filtered)