Skip to content

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 from
  • keys: the keys to use on the nested dictionary in order to get the content
  • separator: 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.