def worker_update(self, worker_id, details): """ Update the worker with details data which is json string """ if (self.__contract_instance is not None): if not is_valid_hex_str( binascii.hexlify(worker_id).decode("utf8")): logging.error("Invalid worker id {}".format(worker_id)) return construct_message( "failed", "Invalid worker id {}".format(worker_id)) if details is not None: is_valid = validate_details(details) if is_valid is not None: logging.error(is_valid) return construct_message("failed", is_valid) txn_hash = self.__contract_instance.functions.workerUpdate( worker_id, details).buildTransaction({ "chainId": self.__eth_client.get_channel_id(), "gas": self.__eth_client.get_gas_limit(), "gasPrice": self.__eth_client.get_gas_price(), "nonce": self.__eth_client.get_txn_nonce() }) tx = self.__eth_client.execute_transaction(txn_hash) return tx else: logging.error( "worker registry contract instance is not initialized") return construct_message( "failed", "worker registry contract instance is not initialized")
def worker_register(self, worker_id, worker_type, org_id, application_ids, details): """ Register new worker with details of worker """ if (self.__contract_instance is not None): if not is_valid_hex_str( binascii.hexlify(worker_id).decode("utf8")): logging.info("Invalid worker id {}".format(worker_id)) return construct_message( "failed", "Invalid worker id {}".format(worker_id)) if not isinstance(worker_type, WorkerType): logging.info("Invalid workerType {}".format(worker_type)) return construct_message( "failed", "Invalid workerType {}".format(worker_type)) if not is_valid_hex_str(binascii.hexlify(org_id).decode("utf8")): logging.info("Invalid organization id {}".format(org_id)) return construct_message( "failed", "Invalid organization id {}".format(org_id)) for aid in application_ids: if not is_valid_hex_str(binascii.hexlify(aid).decode("utf8")): logging.info("Invalid application id {}".format(aid)) return construct_message( "failed", "Invalid application id {}".format(aid)) if details is not None: is_valid = validate_details(details) if is_valid is not None: return construct_message("failed", is_valid) txn_hash = self.__contract_instance.functions.workerRegister( worker_id, worker_type.value, org_id, application_ids, details).buildTransaction({ "chainId": self.__eth_client.get_channel_id(), "gas": self.__eth_client.get_gas_limit(), "gasPrice": self.__eth_client.get_gas_price(), "nonce": self.__eth_client.get_txn_nonce() }) tx = self.__eth_client.execute_transaction(txn_hash) return tx else: logging.error( "worker registry contract instance is not initialized") return construct_message( "failed", "worker registry contract instance is not initialized")
def worker_register(self, worker_id, worker_type, org_id, application_type_ids, details, id=None): """ Adds worker details to registry """ if worker_id is None or not is_hex(worker_id): logging.error("Worker id is empty or Invalid") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Worker id is empty or Invalid") if not isinstance(worker_type, WorkerType): logging.error("Invalid worker type") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid worker type") if org_id is not None and not is_hex(org_id): logging.error("Invalid organization id") return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid organization id") if application_type_ids is not None: for app_id in application_type_ids: if not is_hex(app_id): logging.error("Invalid application type id") return create_jrpc_response( id, JsonRpcErrorCode.INVALID_PARAMETER, "Invalid application type id") break if details is not None: is_valid = validate_details(details) if is_valid is not None: logging.error(is_valid) return create_jrpc_response(id, JsonRpcErrorCode.INVALID_PARAMETER, is_valid) json_rpc_request = { "jsonrpc": "2.0", "method": "WorkerRegister", "id": id, "params": { "workerId": worker_id, "workerType": worker_type.value, "organizationId": org_id, "applicationTypeId": application_type_ids, "details": json.loads(details) } } response = self.__uri_client._postmsg(json.dumps(json_rpc_request)) return response