コード例 #1
0
ファイル: farmer.py プロジェクト: rongou/chia-blockchain
    async def _pool_put_farmer(self, pool_config: PoolWalletConfig,
                               authentication_token_timeout: uint8,
                               owner_sk: PrivateKey) -> Optional[Dict]:
        put_farmer_payload: PutFarmerPayload = PutFarmerPayload(
            pool_config.launcher_id,
            get_current_authentication_token(authentication_token_timeout),
            pool_config.authentication_public_key,
            pool_config.payout_instructions,
            None,
        )
        assert owner_sk.get_g1() == pool_config.owner_public_key
        signature: G2Element = AugSchemeMPL.sign(owner_sk,
                                                 put_farmer_payload.get_hash())
        put_farmer_request = PutFarmerRequest(put_farmer_payload, signature)
        put_farmer_body = json.dumps(put_farmer_request.to_json_dict())

        try:
            async with aiohttp.ClientSession() as session:
                async with session.put(
                        f"{pool_config.pool_url}/farmer",
                        data=put_farmer_body,
                        ssl=ssl_context_for_root(get_mozilla_ca_crt()),
                ) as resp:
                    if resp.ok:
                        response: Dict = json.loads(await resp.text())
                        self.log.info(f"PUT /farmer response: {response}")
                        if "error_code" in response:
                            self.pool_state[
                                pool_config.p2_singleton_puzzle_hash][
                                    "pool_errors_24h"].append(response)
                        return response
                    else:
                        self.handle_failed_pool_response(
                            pool_config.p2_singleton_puzzle_hash,
                            f"Error in PUT /farmer {pool_config.pool_url}, {resp.status}",
                        )
        except Exception as e:
            self.handle_failed_pool_response(
                pool_config.p2_singleton_puzzle_hash,
                f"Exception in PUT /farmer {pool_config.pool_url}, {e}")
        return None
コード例 #2
0
    async def put_farmer(self, request_obj) -> web.Response:
        # TODO(pool): add rate limiting
        put_farmer_request: PutFarmerRequest = PutFarmerRequest.from_json_dict(
            await request_obj.json())

        authentication_token_error = check_authentication_token(
            put_farmer_request.payload.launcher_id,
            put_farmer_request.payload.authentication_token,
            self.pool.authentication_token_timeout,
        )
        if authentication_token_error is not None:
            return authentication_token_error

        # Process the request
        put_farmer_response = await self.pool.update_farmer(put_farmer_request)

        self.pool.log.info(
            f"put_farmer response {put_farmer_response}, "
            f"launcher_id: {put_farmer_request.payload.launcher_id.hex()}", )
        return obj_to_response(put_farmer_response)