mine.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:two1-python 作者: 21dotco 项目源码 文件源码
def get_work(client):
    """ Get work from the pool using the rest client.

    Args:
        client (TwentyOneRestClient): rest client used for communication with the backend api

    Returns:
        WorkNotification: a Swirl work notification message
    """
    try:
        response = client.get_work()
    except exceptions.ServerRequestError as e:
        profile_url = "{}/{}".format(two1.TWO1_WWW_HOST, client.username)
        profile_cta = uxstring.UxString.mining_profile_call_to_action.format(profile_url)
        err_string = None
        if e.status_code == 403 and e.data.get("error") == "TO201":
            err_string = uxstring.UxString.Error.suspended_account
        elif e.status_code == 403 and e.data.get("error") == "TO501":
            err_string = uxstring.UxString.monthly_mining_limit_reached
        elif e.status_code == 403 and e.data.get("error") == "TO502":
            err_string = uxstring.UxString.lifetime_earn_limit_reached
        elif e.status_code == 403 and e.data.get("error") == "TO503":
            err_string = uxstring.UxString.no_earn_allocations.format(two1.TWO1_WWW_HOST,
                                                                      client.username)
        elif e.status_code == 404:
            if bitcoin_computer.has_mining_chip():
                err_string = uxstring.UxString.monthly_mining_limit_reached
            else:
                err_string = uxstring.UxString.earn_limit_reached

        if err_string:
            raise exceptions.MiningDisabledError("{}\n\n{}".format(err_string, profile_cta))
        else:
            raise e

    msg_factory = message_factory.SwirlMessageFactory()
    msg = base64.decodebytes(response.content)
    work = msg_factory.read_object(msg)
    return work
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号