Exemplo n.º 1
0
    def run(cls, eth_passphrase, eth_auth_token, sol_file):
        """
        Runs the backend
        """
        # Note: except for stream_logger, every other import
        # to a subpackage of qsp_prototol_node must be
        # performed at this point

        from audit import QSPAuditNode
        from config import ConfigFactory
        from utils.stop import Stop

        cfg = ConfigFactory.create_from_dictionary(
            Program.__yaml_config,
            Program.__env,
            account_passwd=eth_passphrase,
            auth_token=eth_auth_token,
        )

        logger.info("Initializing QSP Audit Node")
        logger.debug("account: {0}".format(cfg.account))
        logger.debug("analyzers: {0}".format(cfg.analyzers))
        logger.debug("audit contract address: {0}".format(
            cfg.audit_contract_address))

        logger.debug("min_price_in_qsp: {0}".format(cfg.min_price_in_qsp))
        logger.debug("evt_polling: {0}".format(cfg.evt_polling))
        logger.debug("audit contract address: {0}".format(
            cfg.audit_contract_address))

        # Based on the provided configuration, instantiates a new
        # QSP audit node
        audit_node = QSPAuditNode(cfg)
        Stop.register(audit_node)

        if QSPAuditNode.is_police_officer(cfg):
            logger.info("Running QSP node (performs audits and police checks)")
        else:
            logger.info("Running QSP node (performs audits only)")

        # If a sol file is given, produce the audit report for that file and exit
        if sol_file:
            _, audit_report = audit_node.get_full_report(requestor=cfg.account,
                                                         uri=sol_file,
                                                         request_id=1)
            pprint(audit_report)
        # Runs the QSP audit node in a busy loop fashion
        else:
            try:
                audit_node.start()
            except Exception as error:
                if audit_node is not None:
                    audit_node.stop()
                    raise error