packages.valory.skills.abstract_
round_
abci.utils
This module contains utility functions for the 'abstract_round_abci' skill.
VerifyDrand Objects
class VerifyDrand()
Tool to verify Randomness retrieved from various external APIs.
The ciphersuite used is BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_
cryptographic-specification section in https://drand.love/docs/specification/ https://github.com/ethereum/py_ecc
verify
def verify(data: Dict, pubkey: str) -> Tuple[bool, Optional[str]]
Verify drand value retried from external APIs.
Arguments:
data
: dictionary containing drand parameters.pubkey
: league of entropy public key public-endpoints section in https://drand.love/developer/http-api/
Returns:
bool, error message
get_
data_
from_
nested_
dict
def get_data_from_nested_dict(nested_dict: Dict,
keys: str,
separator: str = ":") -> Any
Gets content from a nested dictionary, using serialized response keys which are split by a given separator.
Arguments:
nested_dict
: the nested dictionary to get the content fromkeys
: the keys to use on the nested dictionary in order to get the contentseparator
: the separator to use in order to get the keys list. Choose the separator carefully, so that it does not conflict with any character of the keys.
Returns:
the content result
get_
value_
with_
type
def get_value_with_type(value: Any, type_name: str) -> Any
Get the given value as the specified type.
parse_
tendermint_
p2p_
url
def parse_tendermint_p2p_url(url: str) -> Tuple[str, int]
Parse tendermint P2P url.
get_
origin
def get_origin(tp)
Get the unsubscripted version of a type.
This supports generic types, Callable, Tuple, Union, Literal, Final and ClassVar. Returns None for unsupported types.
Examples:
get_origin(Literal[42]) is Literal get_origin(int) is None get_origin(ClassVar[int]) is ClassVar get_origin(Generic) is Generic get_origin(Generic[T]) is Generic get_origin(Union[T, int]) is Union get_origin(List[Tuple[T, T]][int]) == list
get_
args
def get_args(tp)
Get type arguments with all substitutions performed.
For unions, basic simplifications used by Union constructor are performed.
Examples:
get_args(Dict[str, int]) == (str, int) get_args(int) == () get_args(Union[int, Union[T, int], str][int]) == (int, str) get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) get_args(Callable[[], T][int]) == ([], int)
is_
pep604_
union
def is_pep604_union(ty: Type[Any]) -> bool
Check if a type is a PEP 604 union.
AutonomyTypeError Objects
class AutonomyTypeError(TypeError)
Type Error for the Autonomy type check system.
__
init__
def __init__(ty: Type[Any], value: Any, path: Optional[List[str]] = None)
Initialize AutonomyTypeError.
__
str__
def __str__() -> str
Get string representation of AutonomyTypeError.
Result
returns error context
check
def check(value: Any, ty: Type[Any]) -> Result
Check a value against a type.
Examples
assert is_error(check(1, str)) assert not is_error(check(1, int)) assert is_error(check(1, list)) assert is_error(check(1.3, int)) assert is_error(check(1.3, Union[str, int]))
check_
class
def check_class(value: Any, ty: Type[Any]) -> Result
Check class type.
check_
int
def check_int(value: Any, ty: Type[Any]) -> Result
Check int type.
check_
literal
def check_literal(value: Any, ty: Type[Any]) -> Result
Check literal type.
check_
tuple
def check_tuple(value: Any, ty: Type[Tuple[Any, ...]]) -> Result
Check tuple type.
check_
union
def check_union(value: Any, ty: Type[Any]) -> Result
Check union type.
check_
mono_
container
def check_mono_container(
value: Any, ty: Union[Type[List[Any]], Type[Set[Any]],
Type[FrozenSet[Any]]]) -> Result
Check mono container type.
check_
dict
def check_dict(value: Dict[Any, Any], ty: Type[Dict[Any, Any]]) -> Result
Check dict type.
check_
dataclass
def check_dataclass(value: Any, ty: Type[Any]) -> Result
Check dataclass type.
check_
typeddict
def check_typeddict(value: Any, ty: Type[Any]) -> Result
Check typeddict type.
is_
typevar
def is_typevar(ty: Type[Any]) -> TypeGuard[TypeVar]
Check typevar.
is_
error
def is_error(ret: Result) -> TypeGuard[AutonomyTypeError]
Check error.
is_
typeddict
def is_typeddict(ty: Type[Any]) -> TypeGuard[Type[TypedDict]]
Check typeddict.
check_
type
def check_type(name: str, value: Any, type_hint: Any) -> None
Check value against type hint recursively
is_
primitive_
or_
none
def is_primitive_or_none(obj: Any) -> bool
Checks if the given object is a primitive type or None
.
is_
json_
serializable
def is_json_serializable(obj: Any) -> bool
Checks if the given object is json serializable.
filter_
negative
def filter_negative(mapping: Dict[str, int]) -> Iterator[str]
Return the keys of a dictionary for which the values are negative integers.
consensus_
threshold
def consensus_threshold(nb: int) -> int
Get consensus threshold.
Arguments:
nb
: the number of participants
Returns:
the consensus threshold
inverse
def inverse(dict_: Dict[KeyType, ValueType]) -> Dict[ValueType, List[KeyType]]
Get the inverse of a dictionary.