def try_get_balance(agent_config: AgentConfig, wallet: Wallet, type_: str) -> int: """ Try to get wallet balance. :param agent_config: agent config object. :param wallet: wallet object. :param type_: type of ledger API. :retun: token balance. """ try: if type_ not in agent_config.ledger_apis_dict: # pragma: no cover raise ValueError( "No ledger api config for {} provided in aea-config.yaml.". format(type_)) ledger_apis = LedgerApis(agent_config.ledger_apis_dict, agent_config.default_ledger) address = wallet.addresses[type_] balance = ledger_apis.get_balance(type_, address) if balance is None: # pragma: no cover raise ValueError("No balance returned!") return balance except (AssertionError, ValueError) as e: # pragma: no cover raise click.ClickException(str(e))
def try_get_balance(agent_config: AgentConfig, wallet: Wallet, type_: str) -> int: """ Try to get wallet balance. :param agent_config: agent config object. :param wallet: wallet object. :param type_: type of ledger API. :retun: token balance. """ try: if type_ not in DEFAULT_LEDGER_CONFIGS: # pragma: no cover raise ValueError("No ledger api config for {} available.".format(type_)) address = wallet.addresses[type_] balance = LedgerApis.get_balance(type_, address) if balance is None: # pragma: no cover raise ValueError("No balance returned!") return balance except (AssertionError, ValueError) as e: # pragma: no cover raise click.ClickException(str(e))