def deploy_tokens_and_fund_accounts(
    token_amount: int,
    number_of_tokens: int,
    deploy_service: BlockChainService,
    participants: typing.List[typing.Address],
    contract_manager: ContractManager,
) -> typing.List[typing.TokenAddress]:
    """ Deploy `number_of_tokens` ERC20 token instances with `token_amount` minted and
    distributed among `blockchain_services`. Optionally the instances will be registered with
    the raiden registry.

    Args:
        token_amount (int): number of units that will be created per token
        number_of_tokens (int): number of token instances that will be created
        deploy_service (BlockChainService): the blockchain connection that will deploy
        participants (list(address)): participant addresses that will receive tokens
    """
    result = list()
    for _ in range(number_of_tokens):
        token_address = deploy_contract_web3(
            CONTRACT_HUMAN_STANDARD_TOKEN,
            deploy_service.client,
            contract_manager=contract_manager,
            constructor_arguments=(token_amount, 2, "raiden", "Rd"),
        )

        result.append(token_address)

        # only the creator of the token starts with a balance (deploy_service),
        # transfer from the creator to the other nodes
        for transfer_to in participants:
            deploy_service.token(token_address).transfer(
                to_address=transfer_to, amount=token_amount // len(participants)
            )

    return result
def _log_unhandled_exception_and_exit(
        cls, exc_class=None, exc=None, tb=None, add_newline=False
    ):
        """A sys.excepthook implementation which logs the error and exits with failure."""
        exc_class = exc_class or sys.exc_info()[0]
        exc = exc or sys.exc_info()[1]
        tb = tb or sys.exc_info()[2]

        # This exception was raised by a signal handler with the intent to exit the program.
        if exc_class == SignalHandler.SignalHandledNonLocalExit:
            return cls._handle_signal_gracefully(exc.signum, exc.signame, exc.traceback_lines)

        extra_err_msg = None
        try:
            # Always output the unhandled exception details into a log file, including the traceback.
            exception_log_entry = cls._format_unhandled_exception_log(
                exc, tb, add_newline, should_print_backtrace=True
            )
            cls.log_exception(exception_log_entry)
        except Exception as e:
            extra_err_msg = "Additional error logging unhandled exception {}: {}".format(exc, e)
            logger.error(extra_err_msg)

        # Generate an unhandled exception report fit to be printed to the terminal (respecting the
        # Exiter's should_print_backtrace field).
        if cls._should_print_backtrace_to_terminal:
            stderr_printed_error = cls._format_unhandled_exception_log(
                exc, tb, add_newline, should_print_backtrace=cls._should_print_backtrace_to_terminal
            )
            if extra_err_msg:
                stderr_printed_error = "{}\n{}".format(stderr_printed_error, extra_err_msg)
        else:
            # If the user didn't ask for a backtrace, show a succinct error message without
            # all the exception-related preamble.  A power-user/pants developer can still
            # get all the preamble info along with the backtrace, but the end user shouldn't
            # see that boilerplate by default.
            error_msgs = getattr(exc, "end_user_messages", lambda: [str(exc)])()
            stderr_printed_error = "\n" + "\n".join(f"ERROR: {msg}" for msg in error_msgs)
        cls._exit_with_failure(stderr_printed_error)