Esempio n. 1
0
def main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend,
         testing, insecure_transport, chains, log_format, artifact_type):
    """
    Entrypoint for the arbiter driver
    """
    loglevel = getattr(logging, log.upper(), None)
    clientlevel = getattr(logging, client_log.upper(), None)
    if not isinstance(loglevel, int) or not isinstance(clientlevel, int):
        logging.error('invalid log level')
        sys.exit(-1)

    logger_name, arbiter_class = choose_backend(backend)

    init_logging(['arbiter', logger_name], log_format, loglevel)
    init_logging(['polyswarmclient'], log_format, clientlevel)

    artifact_types = None
    if artifact_type:
        artifact_types = [
            ArtifactType.from_string(artifact) for artifact in artifact_type
        ]

    arbiter_class.connect(polyswarmd_addr,
                          keyfile,
                          password,
                          api_key=api_key,
                          testing=testing,
                          insecure_transport=insecure_transport,
                          chains=set(chains),
                          artifact_types=artifact_types).run()
Esempio n. 2
0
def main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend,
         testing, insecure_transport, allow_key_over_http, chains, log_format,
         artifact_type, bid_strategy, accept, exclude, filter, confidence):
    """ Entrypoint for the microengine driver
    """
    utils.fast_deprecation()
    loglevel = getattr(logging, log.upper(), None)
    clientlevel = getattr(logging, client_log.upper(), None)
    if not isinstance(loglevel, int) or not isinstance(clientlevel, int):
        logging.error('invalid log level')
        raise FatalError('Invalid log level', 1)

    polyswarmd_addr = utils.finalize_polyswarmd_addr(polyswarmd_addr, api_key,
                                                     allow_key_over_http,
                                                     insecure_transport)
    if insecure_transport:
        warnings.warn(
            '--insecure-transport will be removed soon. Please add http:// or https:// to polyswarmd-addr`',
            DeprecationWarning)

    logger_name, microengine_class = choose_backend(backend)
    bid_logger_name, bid_strategy_class = choose_bid_strategy(bid_strategy)

    artifact_types = None
    init_logging(['microengine', logger_name], log_format, loglevel)
    init_logging(['polyswarmclient'], log_format, clientlevel)

    if artifact_type:
        artifact_types = [
            ArtifactType.from_string(artifact) for artifact in artifact_type
        ]

    filter_accept = filter.get('accept', [])
    filter_reject = filter.get('reject', [])
    if accept or exclude:
        warnings.warn(
            'Options `--exclude|accept key:value` are deprecated, please switch to'
            ' `--filter accept|reject key comparison value`',
            DeprecationWarning)
        filter_accept.extend(accept)
        filter_reject.extend(exclude)

    favor = confidence.get('favor', [])
    penalize = confidence.get('penalize', [])

    microengine_class.connect(
        polyswarmd_addr,
        keyfile,
        password,
        api_key=api_key,
        artifact_types=artifact_types,
        bid_strategy=bid_strategy_class(),
        bounty_filter=BountyFilter(filter_accept, filter_reject),
        chains=set(chains),
        confidence_modifier=ConfidenceModifier(favor, penalize),
        testing=testing).run()
Esempio n. 3
0
    def __init__(self, artifact_type, amount, artifact_uri, num_artifacts, duration, bloom, metadata):
        super().__init__((UNKNOWN_PARAMETER, amount, artifact_uri, num_artifacts, duration, bloom, metadata))

        self.artifact_type = ArtifactType.from_string(artifact_type)
        self.amount = amount
        self.artifact_uri = artifact_uri
        self.num_artifacts = num_artifacts
        self.duration = duration
        self.bloom = bloom
        self.metadata = metadata
Esempio n. 4
0
def post_bounties():
    config = app.config['POLYSWARMD']
    session = app.config['REQUESTS_SESSION']
    account = g.chain.w3.toChecksumAddress(g.eth_address)
    base_nonce = int(
        request.args.get('base_nonce',
                         g.chain.w3.eth.getTransactionCount(account)))

    body = request.get_json()
    try:
        _post_bounties_schema(body)
    except fastjsonschema.JsonSchemaException as e:
        return failure('Invalid JSON: ' + e.message, 400)

    guid = uuid.uuid4()
    artifact_type = ArtifactType.from_string(body['artifact_type'])
    amount = int(body['amount'])
    artifact_uri = body['uri']
    duration_blocks = body['duration']
    metadata = body.get('metadata', '')

    try:
        arts = config.artifact.client.ls(artifact_uri, session)
    except HTTPError as e:
        return failure(e.response.content, e.response.status_code)
    except ArtifactException:
        logger.exception('Failed to ls given artifact uri')
        return failure(f'Failed to check artifact uri', 500)

    if amount < eth.bounty_amount_min(
            g.chain.bounty_registry.contract) * len(arts):
        return failure('Invalid bounty amount', 400)

    if metadata and not config.artifact.client.check_uri(metadata):
        return failure('Invalid bounty metadata URI (should be IPFS hash)',
                       400)

    num_artifacts = len(arts)
    bloom = calculate_bloom(arts)

    approve_amount = amount + eth.bounty_fee(g.chain.bounty_registry.contract)

    transactions = [
        build_transaction(
            g.chain.nectar_token.contract.functions.approve(
                g.chain.bounty_registry.contract.address, approve_amount),
            base_nonce),
        build_transaction(
            g.chain.bounty_registry.contract.functions.postBounty(
                guid.int, artifact_type.value, amount, artifact_uri,
                num_artifacts, duration_blocks, bloom, metadata),
            base_nonce + 1),
    ]

    return success({'transactions': transactions})
Esempio n. 5
0
def main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend,
         testing, insecure_transport, chains, log_format, artifact_type,
         bid_strategy, accept, exclude):
    """Entrypoint for the microengine driver

    Args:
        log (str): Logging level for all app logs
        client_log (str): Logging level for all polyswarmclient logs
        polyswarmd_addr(str): Address of polyswarmd
        keyfile (str): Path to private key file to use to sign transactions
        password (str): Password to decrypt the encrypted private key
        backend (str): Backend implementation to use
        api_key(str): API key to use with polyswarmd
        testing (int): Mode to process N bounties then exit (optional)
        insecure_transport (bool): Connect to polyswarmd without TLS
        chains (list[str]): List of chains on which to scan artifacts
        log_format (str): Format to output logs in. `text` or `json`
        artifact_type (list[str]): List of artifact types to scan
        bid_strategy (str): Bid strategy module name
        accept (list[tuple[str]]): List of excluded mimetypes
        exclude (list[tuple[str]]): List of excluded mimetypes
    """
    loglevel = getattr(logging, log.upper(), None)
    clientlevel = getattr(logging, client_log.upper(), None)
    if not isinstance(loglevel, int) or not isinstance(clientlevel, int):
        logging.error('invalid log level')
        sys.exit(-1)

    logger_name, microengine_class = choose_backend(backend)
    bid_logger_name, bid_strategy_class = choose_bid_strategy(bid_strategy)

    artifact_types = None
    init_logging(['microengine', logger_name], log_format, loglevel)
    init_logging(['polyswarmclient'], log_format, clientlevel)

    if artifact_type:
        artifact_types = [
            ArtifactType.from_string(artifact) for artifact in artifact_type
        ]

    microengine_class.connect(polyswarmd_addr,
                              keyfile,
                              password,
                              api_key=api_key,
                              testing=testing,
                              insecure_transport=insecure_transport,
                              chains=set(chains),
                              artifact_types=artifact_types,
                              exclude=exclude,
                              accept=accept,
                              bid_strategy=bid_strategy_class()).run()
Esempio n. 6
0
def main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend,
         testing, insecure_transport, chains, log_format, artifact_type,
         bid_strategy, accept, exclude, filter, confidence):
    """Entrypoint for the microengine driver
    """
    loglevel = getattr(logging, log.upper(), None)
    clientlevel = getattr(logging, client_log.upper(), None)
    if not isinstance(loglevel, int) or not isinstance(clientlevel, int):
        logging.error('invalid log level')
        sys.exit(-1)

    logger_name, microengine_class = choose_backend(backend)
    bid_logger_name, bid_strategy_class = choose_bid_strategy(bid_strategy)

    artifact_types = None
    init_logging(['microengine', logger_name], log_format, loglevel)
    init_logging(['polyswarmclient'], log_format, clientlevel)

    if artifact_type:
        artifact_types = [
            ArtifactType.from_string(artifact) for artifact in artifact_type
        ]

    filter_accept = filter.get('accept', [])
    filter_reject = filter.get('reject', [])
    if accept or exclude:
        logger.warning(
            'Options `--exclude|accept key:value` are deprecated, please switch to `--filter '
            'accept|reject key comparison value`')

        filter_accept.extend(accept)
        filter_reject.extend(exclude)

    favor = confidence.get('favor', [])
    penalize = confidence.get('penalize', [])

    microengine_class.connect(
        polyswarmd_addr,
        keyfile,
        password,
        api_key=api_key,
        artifact_types=artifact_types,
        bid_strategy=bid_strategy_class(),
        bounty_filter=BountyFilter(filter_accept, filter_reject),
        chains=set(chains),
        confidence_modifier=ConfidenceModifier(favor, penalize),
        insecure_transport=insecure_transport,
        testing=testing).run()
Esempio n. 7
0
def main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend,
         testing, insecure_transport, chains, log_format, artifact_type):
    """Entrypoint for the arbiter driver

    Args:
        log (str): Logging level for all app logs
        client_log (str): Logging level for all polyswarmclient logs
        polyswarmd_addr(str): Address of polyswarmd
        keyfile (str): Path to private key file to use to sign transactions
        password (str): Password to decrypt the encrypted private key
        backend (str): Backend implementation to use
        api_key(str): API key to use with polyswarmd
        testing (int): Mode to process N bounties then exit (optional)
        insecure_transport (bool): Connect to polyswarmd without TLS
        chains (List[str]): Chain(s) to operate on
        log_format (str): Format to output logs in. `text` or `json`
        artifact_type (list[str]): List of artifact types to scan
    """

    loglevel = getattr(logging, log.upper(), None)
    clientlevel = getattr(logging, client_log.upper(), None)
    if not isinstance(loglevel, int) or not isinstance(clientlevel, int):
        logging.error('invalid log level')
        sys.exit(-1)

    logger_name, arbiter_class = choose_backend(backend)

    init_logging(['arbiter', logger_name], log_format, loglevel)
    init_logging(['polyswarmclient'], log_format, clientlevel)

    artifact_types = None
    if artifact_type:
        artifact_types = [
            ArtifactType.from_string(artifact) for artifact in artifact_type
        ]

    arbiter_class.connect(polyswarmd_addr,
                          keyfile,
                          password,
                          api_key=api_key,
                          testing=testing,
                          insecure_transport=insecure_transport,
                          chains=set(chains),
                          artifact_types=artifact_types).run()
Esempio n. 8
0
    async def run(self, guid, artifact_type, author, amount, uri, expiration,
                  metadata, block_number, txhash, chain):
        """Run the registered callbacks

        Args:
            guid (str): Bounty GUID
            artifact_type (str): String representation of artifact type
            author (str): Author of the bounty
            amount (str): Bounty reward amount
            uri (str): URI of the artifacts in the bounty
            expiration (int): Block number the bounty expires on
            metadata (dict): Dictionary or string of metadata
            block_number (int): Block number the bounty was posted on
            txhash (str): Transaction hash which caused the event
            chain (str): Chain event received on
        """
        return await super().run(guid, ArtifactType.from_string(artifact_type),
                                 author, amount, uri, expiration, metadata,
                                 block_number, txhash, chain)
Esempio n. 9
0
def main(log, client_log, polyswarmd_addr, keyfile, password, api_key, backend,
         testing, insecure_transport, allow_key_over_http, chains, log_format,
         artifact_type):
    """
    Entrypoint for the arbiter driver
    """
    utils.fast_deprecation()

    loglevel = getattr(logging, log.upper(), None)
    clientlevel = getattr(logging, client_log.upper(), None)
    if not isinstance(loglevel, int) or not isinstance(clientlevel, int):
        logging.error('invalid log level')
        raise FatalError('Invalid log level', 1)

    logger_name, arbiter_class = choose_backend(backend)

    init_logging(['arbiter', logger_name], log_format, loglevel)
    init_logging(['polyswarmclient'], log_format, clientlevel)

    polyswarmd_addr = utils.finalize_polyswarmd_addr(polyswarmd_addr, api_key,
                                                     allow_key_over_http,
                                                     insecure_transport)
    if insecure_transport:
        warnings.warn(
            '--insecure-transport will be removed soon. Please add http:// or https:// to polyswarmd-addr`',
            DeprecationWarning)

    artifact_types = None
    if artifact_type:
        artifact_types = [
            ArtifactType.from_string(artifact) for artifact in artifact_type
        ]

    arbiter_class.connect(polyswarmd_addr,
                          keyfile,
                          password,
                          api_key=api_key,
                          testing=testing,
                          chains=set(chains),
                          artifact_types=artifact_types).run()
def test_file_artifact_type_from_lowercase_string():
    # arrange
    # act
    artifact_type = ArtifactType.from_string('file')
    # assert
    assert artifact_type == ArtifactType.FILE
def test_none_artifact_type():
    # arrange
    # act
    artifact_type = ArtifactType.from_string(None)
    # assert
    assert artifact_type is None
def test_fake_artifact_type_from_uppercase_string():
    # arrange
    # act
    artifact_type = ArtifactType.from_string('fake')
    # assert
    assert artifact_type is None
def test_url_artifact_type_from_uppercase_string():
    # arrange
    # act
    artifact_type = ArtifactType.from_string('URL')
    # assert
    assert artifact_type == ArtifactType.URL