Exemplo n.º 1
0
def register_compute_asset():
    # get ocean instance
    config = ExampleConfig.get_config()
    ConfigProvider.set_config(config)
    ocean = Ocean()
    keeper = Keeper.get_instance()

    consumer_account = get_account(0)
    publisher_account = get_account(1)

    # get descriptor for compute service
    compute_descriptor = build_compute_descriptor(ocean)

    # create an asset with compute service
    ddo = ocean.assets.create(example_metadata.metadata,
                              publisher_account,
                              providers=[config.provider_address],
                              use_secret_store=False,
                              service_descriptors=[compute_descriptor])
    event = keeper.did_registry.subscribe_to_event(
        keeper.did_registry.DID_REGISTRY_EVENT_NAME,
        15,
        event_filter={
            '_did': Web3Provider.get_web3().toBytes(hexstr=ddo.asset_id),
            '_owner': publisher_account.address
        },
        wait=True)
    assert event, 'There was a problem registering an asset'
    logging.info(f'Registered asset: did={ddo.did}')

    # buy an asset access
    agreement_id = ocean.compute.order(ddo.did, consumer_account)
    event = keeper.compute_execution_condition.subscribe_condition_fulfilled(
        agreement_id, 15, None, (), wait=True)
    assert event, 'There was a problem creating an agreement'
    logging.info(f'Created asset agreement: agreement_id={agreement_id}')

    # supply metadata describing the algorithm to run against the dataset
    # you can also use an algorithm published as an Ocean asset instead
    algo_meta = AlgorithmMetadata(example_metadata.algo_metadata)

    # whether to publish the algorithm results as an Ocean assets
    output_dict = {
        'publishOutput': False,
        'publishAlgorithmLog': False,
    }

    # start the compute job
    job_id = ocean.compute.start(agreement_id,
                                 consumer_account,
                                 algorithm_meta=algo_meta,
                                 output=output_dict)
    logging.info(f'Started compute job: job_id={job_id}')

    # query operator service for job status
    status = ocean.compute.status(agreement_id, job_id, consumer_account)
    logging.info(f'Job status: {status}')
Exemplo n.º 2
0
 def __init__(self, keeper, config, ocean_tokens):
     self._keeper = keeper
     self._config = config
     self._ocean_tokens = ocean_tokens
     self._accounts = []
     addresses = [account_address for account_address in self._keeper.accounts]
     for address in addresses:
         for account in [get_account(0), get_account(1)]:
             if account and account.address.lower() == address.lower():
                 self._accounts.append(account)
                 break
Exemplo n.º 3
0
def sign_service_agreement():
    ConfigProvider.set_config(ExampleConfig.get_config())
    # make ocean instance and register an asset
    ocn = Ocean()
    acc = get_account(0)
    ddo = ocn.assets.create(example_metadata.metadata, acc)

    consumer_account = get_account(1)
    agreement_id, signature = ocn.agreements.prepare(ddo.did, consumer_account)

    sleep(ASYNC_DELAY)

    logging.info(f'service agreement signed: '
                 f'\nservice agreement id: {agreement_id}, '
                 f'\nsignature: {signature}')
Exemplo n.º 4
0
def setup_keeper(config_file=None):
    config = Config(filename=config_file) if config_file else get_config()
    keeper_url = config.keeper_url
    artifacts_path = get_keeper_path(config)

    ContractHandler.set_artifacts_path(artifacts_path)
    Web3Provider.init_web3(keeper_url)
    init_account_envvars()

    account = get_account(0)
    if account is None:
        raise AssertionError(
            f'Brizo cannot run without a valid '
            f'ethereum account. Account address was not found in the environment'
            f'variable `PROVIDER_ADDRESS`. Please set the following environment '
            f'variables and try again: `PROVIDER_ADDRESS`, [`PROVIDER_PASSWORD`, '
            f'and `PROVIDER_KEYFILE` or `PROVIDER_ENCRYPTED_KEY`] or `PROVIDER_KEY`.'
        )

    if not account._private_key and not (account.password
                                         and account._encrypted_key):
        raise AssertionError(
            f'Brizo cannot run without a valid '
            f'ethereum account with either a `PROVIDER_PASSWORD` '
            f'and `PROVIDER_KEYFILE`/`PROVIDER_ENCRYPTED_KEY` '
            f'or private key `PROVIDER_KEY`. Current account has password {account.password}, '
            f'keyfile {account.key_file}, encrypted-key {account._encrypted_key} '
            f'and private-key {account._private_key}.')
Exemplo n.º 5
0
def search_assets():
    ConfigProvider.set_config(ExampleConfig.get_config())
    ocn = Ocean()
    account = get_account(0)
    ddo = ocn.assets.create(
        example_metadata.metadata,
        account,
    )

    sleep(ASYNC_DELAY)

    logging.info(f'Registered asset: did={ddo.did}, ddo={ddo.as_text()}')
    resolved_ddo = ocn.assets.resolve(ddo.did)
    logging.info(
        f'resolved asset ddo: did={resolved_ddo.did}, ddo={resolved_ddo.as_text()}'
    )

    ddo_list = ocn.assets.search('bonding curve')
    logging.info(
        f'found {len(ddo_list)} assets that contain `bonding curve` in their metadata.'
    )
    ddo_list = ocn.assets.query(
        {"query": {
            "text": ['Ocean protocol white paper']
        }})
    logging.info(
        f'found {len(ddo_list)} assets with name that contains `Ocean protocol white paper`'
    )
Exemplo n.º 6
0
def setup_network(config_file=None):
    config = Config(filename=config_file) if config_file else get_config()
    keeper_url = config.keeper_url
    artifacts_path = get_keeper_path(config)

    ContractHandler.set_artifacts_path(artifacts_path)
    if keeper_url.startswith('http'):
        provider = CustomHTTPProvider
    elif keeper_url.startswith('wss'):
        provider = WebsocketProvider
    else:
        raise AssertionError(f'Unsupported network url {keeper_url}. Must start with http or wss.')

    Web3Provider.init_web3(provider=provider(keeper_url))
    from web3.middleware import geth_poa_middleware
    Web3Provider.get_web3().middleware_stack.inject(geth_poa_middleware, layer=0)

    init_account_envvars()

    account = get_account(0)
    if account is None:
        raise AssertionError(f'Ocean Provider cannot run without a valid '
                             f'ethereum account. Account address was not found in the environment'
                             f'variable `PROVIDER_ADDRESS`. Please set the following environment '
                             f'variables and try again: `PROVIDER_ADDRESS`, [`PROVIDER_PASSWORD`, '
                             f'and `PROVIDER_KEYFILE` or `PROVIDER_ENCRYPTED_KEY`] or `PROVIDER_KEY`.')

    if not account._private_key and not (account.password and account._encrypted_key):
        raise AssertionError(f'Ocean Provider cannot run without a valid '
                             f'ethereum account with either a `PROVIDER_PASSWORD` '
                             f'and `PROVIDER_KEYFILE`/`PROVIDER_ENCRYPTED_KEY` '
                             f'or private key `PROVIDER_KEY`. Current account has password {account.password}, '
                             f'keyfile {account.key_file}, encrypted-key {account._encrypted_key} '
                             f'and private-key {account._private_key}.')
Exemplo n.º 7
0
def resolve_asset():
    ConfigProvider.set_config(ExampleConfig.get_config())
    ocn = Ocean()
    account = get_account(0)
    ddo = ocn.assets.create(
        example_metadata.metadata, account,
    )

    sleep(ASYNC_DELAY)

    logging.info(f'Registered asset: did={ddo.did}, ddo={ddo.as_text()}')
    resolved_ddo = ocn.assets.resolve(ddo.did)
    logging.info(f'resolved asset ddo: did={resolved_ddo.did}, ddo={resolved_ddo.as_text()}')
Exemplo n.º 8
0
def register_asset():
    # make ocean instance
    ConfigProvider.set_config(ExampleConfig.get_config())
    ocn = Ocean()
    account = get_account(0)
    # account = ([acc for acc in ocn.accounts.list() if acc.password] or ocn.accounts.list())[0]
    ddo = ocn.assets.create(
        example_metadata.metadata,
        account,
        providers=['0xfEF2d5e1670342b9EF22eeeDcb287EC526B48095'])

    sleep(ASYNC_DELAY)

    logging.info(
        f'Registered asset: did={ddo.did}, ddo-services={ddo.services}')
    resolved_ddo = ocn.assets.resolve(ddo.did)
    logging.info(
        f'resolved asset ddo: did={resolved_ddo.did}, ddo={resolved_ddo.as_text()}'
    )
Exemplo n.º 9
0
def run_events_monitor():
    setup_logging()
    config = get_config()
    keeper_url = config.keeper_url
    artifacts_path = get_keeper_path(config)
    storage_path = config.get('resources',
                              'storage.path',
                              fallback='./provider-events-monitor.db')

    ContractHandler.set_artifacts_path(artifacts_path)
    web3 = Web3Provider.get_web3(keeper_url)
    keeper = Keeper.get_instance()
    init_account_envvars()

    account = get_account(0)
    if account is None:
        raise AssertionError(
            f'Provider events monitor cannot run without a valid '
            f'ethereum account. Account address was not found in the environment'
            f'variable `PROVIDER_ADDRESS`. Please set the following environment '
            f'variables and try again: `PROVIDER_ADDRESS`, [`PROVIDER_PASSWORD`, '
            f'and `PROVIDER_KEYFILE` or `PROVIDER_ENCRYPTED_KEY`] or `PROVIDER_KEY`.'
        )

    if not account._private_key and not (account.password
                                         and account._encrypted_key):
        raise AssertionError(
            f'Provider events monitor cannot run without a valid '
            f'ethereum account with either a `PROVIDER_PASSWORD` '
            f'and `PROVIDER_KEYFILE`/`PROVIDER_ENCRYPTED_KEY` '
            f'or private key `PROVIDER_KEY`. Current account has password {account.password}, '
            f'keyfile {account.key_file}, encrypted-key {account._encrypted_key} '
            f'and private-key {account._private_key}.')

    monitor = ProviderEventsMonitor(keeper, web3, storage_path, account)
    monitor.start_agreement_events_monitor()
    while True:
        time.sleep(5)
Exemplo n.º 10
0
def get_consumer_account():
    return get_account(1)
Exemplo n.º 11
0
def get_publisher_account():
    return get_account(0)
Exemplo n.º 12
0
def get_provider_account():
    return get_account(0)