Part 3: Annotated Specification
Helper Functions
Participation flags
These two simple utilities were added in the Altair upgrade.
add_flag
def add_flag(flags: ParticipationFlags, flag_index: int) -> ParticipationFlags:
"""
Return a new ``ParticipationFlags`` adding ``flag_index`` to ``flags``.
"""
flag = ParticipationFlags(2**flag_index)
return flags | flag
This is simple and self-explanatory. The 2**flag_index
is a bit Pythonic. In a C-like language it would use a bit-shift:
1 << flag_index
Used by | process_attestation() |
See also | ParticipationFlags |
has_flag
def has_flag(flags: ParticipationFlags, flag_index: int) -> bool:
"""
Return whether ``flags`` has ``flag_index`` set.
"""
flag = ParticipationFlags(2**flag_index)
return flags & flag == flag
Move along now, nothing to see here.
Used by | get_unslashed_participating_indices() , process_attestation() |
See also | ParticipationFlags |