def __claim_rewards(self):
        """
        Invokes the claimRewards function in the smart contract.
        """
        msg = "Make sure the account has enough Ether, " \
              + "the Ethereum node is connected and synced, " \
              + "and restart your node to try again."

        transaction = self.config.audit_contract.functions.claimRewards()
        tx_hash = None
        try:
            tx_hash = send_signed_transaction(self.config,
                                              transaction,
                                              wait_for_transaction_receipt=True)
            # If the tx_hash is None, the transaction did not actually complete. Exit
            if not tx_hash:
                raise Exception("The claim rewards transaction did not complete")
            self.logger.debug("Successfully claimed rewards for address {0}.".format(
                self.config.account))
        except Timeout as e:
            error_msg = "Claim rewards timed out. " + msg + " {0}, {1}."
            self.logger.debug(error_msg.format(
                str(transaction),
                str(e)))
            raise e
        except DeduplicationException as e:
            error_msg = "A transaction already exists for claiming rewards," \
                        + " but has not yet been mined. " + msg \
                        + " This may take several iterations. {0}, {1}."
            self.logger.debug(error_msg.format(
                str(transaction),
                str(e)))
            raise e
        except TransactionNotConfirmedException as e:
            error_msg = "A transaction occurred, but was then uncled and never recovered. {0}, {1}"
            self.logger.debug(error_msg.format(
                str(transaction),
                str(e)))
            raise e
        except Exception as e:
            error_msg = "Error occurred claiming rewards. " + msg + " {0}, {1}."
            self.logger.exception(error_msg.format(
                str(transaction),
                str(e)))
            raise e
        return tx_hash
Example #2
0
    def __update_min_price(self):
        """
        Updates smart contract with the minimum price in the audit node's configuration.
        """
        msg = "Make sure the account has enough Ether, " \
              + "the Ethereum node is connected and synced, " \
              + "and restart your node to try again."

        min_price_in_mini_qsp = self.config.min_price_in_qsp * (10**18)
        self.logger.info(
            "Updating min_price in the smart contract for address {0} to {1} QSP."
            .format(
                self.config.account,
                self.config.min_price_in_qsp,
            ))
        transaction = self.config.audit_contract.functions.setAuditNodePrice(
            min_price_in_mini_qsp)
        try:
            tx_hash = send_signed_transaction(
                self.config, transaction, wait_for_transaction_receipt=True)
            # If the tx_hash is None, the transaction did not actually complete. Exit
            if not tx_hash:
                raise Exception("The min price transaction did not complete")
            self.logger.debug("Successfully updated min price to {0}.".format(
                self.config.min_price_in_qsp))
        except Timeout as e:
            error_msg = "Update min price timed out, " \
                + "increase the tx_timeout_seconds in config.yaml and restart the node. " \
                + msg + " {0}, {1}."
            formatted_error = error_msg.format(str(transaction), str(e))
            self.logger.debug(formatted_error)
            raise Timeout(formatted_error) from e
        except DeduplicationException as e:
            error_msg = "A transaction already exists for updating min price," \
                        + " but has not yet been mined. " + msg \
                        + " This may take several iterations. {0}, {1}."
            self.logger.debug(error_msg.format(str(transaction), str(e)))
            raise e
        except TransactionNotConfirmedException as e:
            error_msg = "A transaction occurred, but was then uncled and never recovered. {0}, {1}"
            self.logger.debug(error_msg.format(str(transaction), str(e)))
            raise e
        except Exception as e:
            error_msg = "Error occurred setting min price. " + msg + " {0}, {1}."
            self.logger.exception(error_msg.format(str(transaction), str(e)))
            raise e
Example #3
0
    def __submit_police_report(self, request_id, compressed_report,
                               is_verified):
        """
        Submits the police report to the entire QSP network.
        """
        # Convert from a bitstring to a bytes array
        compressed_report_bytes = self.config.web3_client.toBytes(
            hexstr=compressed_report)

        tx_hash = send_signed_transaction(
            self.config,
            self.config.audit_contract.functions.submitPoliceReport(
                request_id, compressed_report_bytes, is_verified))
        self.logger.debug(
            "Police report submitted: tx hash {0}".format(tx_hash),
            requestId=request_id)
        return tx_hash
    def __submit_audit_report(self, request_id, audit_state,
                              compressed_report):
        """
        Submits the audit report to the entire QSP network.
        """
        # Convert from a bitstring to a bytes array
        compressed_report_bytes = self.config.web3_client.toBytes(
            hexstr=compressed_report)

        tx_hash = send_signed_transaction(
            self.config,
            self.config.audit_contract.functions.submitReport(
                request_id, audit_state, compressed_report_bytes))
        self.logger.debug("Audit report submitted: tx hash {0}".format(
            tx_hash.hex()),
                          requestId=request_id)
        return tx_hash
 def __get_next_audit_request(self):
     """
     Attempts to get a request from the audit request queue.
     """
     # NOTE
     # The audit contract checks whether the node has enough stake before
     # accepting a bid. No need to replicate that logic here.
     transaction = self.config.audit_contract.functions.getNextAuditRequest(
     )
     tx_hash = None
     try:
         tx_hash = send_signed_transaction(
             self.config, transaction, wait_for_transaction_receipt=True)
         self.logger.debug(
             "A getNextAuditRequest transaction has been sent in "
             "transaction {0}".format(tx_hash))
     except Timeout as e:
         self.logger.debug(
             "Transaction receipt timeout happened for {0}. {1}".format(
                 str(transaction), e))
     return tx_hash