Пример #1
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}.')
Пример #2
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}.')
Пример #3
0
def test_get_condition_name_by_address():
    config = ExampleConfig.get_config()
    Web3Provider.init_web3(config.keeper_url)
    ContractHandler.set_artifacts_path(config.keeper_path)
    keeper = Keeper.get_instance()
    name = keeper.get_condition_name_by_address(
        keeper.lock_reward_condition.address)
    assert name == 'lockReward'

    name = keeper.get_condition_name_by_address(
        keeper.access_secret_store_condition.address)
    assert name == 'accessSecretStore'

    name = keeper.get_condition_name_by_address(
        keeper.escrow_reward_condition.address)
    assert name == 'escrowReward'
Пример #4
0
    def __init__(self, address, abi_path=None, abi=None):
        name = self.contract_name
        assert name, 'contract_name property needs to be implemented in subclasses.'
        if not abi_path and not abi:
            abi_path = ContractHandler.artifacts_path

        if abi_path and not abi:
            abi = CustomContractBase.read_abi_from_file(name, abi_path)['abi']

        contract = Web3Provider.get_web3().eth.contract(address=address,
                                                        abi=abi)
        ContractHandler.set(name, contract)
        ContractBase.__init__(self, name)
        assert self.contract == contract
        assert self.contract_concise is not None
        assert self.address == address
Пример #5
0
def ocean_agreements():
    config = ExampleConfig.get_config()
    Web3Provider.init_web3(config.keeper_url)
    ContractHandler.set_artifacts_path(config.keeper_path)
    keeper = Keeper.get_instance()
    w3 = Web3Provider.get_web3()
    did_resolver = Mock()
    ddo = get_ddo_sample()
    service = ddo.get_service(ServiceTypes.ASSET_ACCESS)
    service.update_value(
        ServiceAgreementTemplate.TEMPLATE_ID_KEY,
        w3.toChecksumAddress("0x00bd138abd70e2f00903268f3db08f2d25677c9e"))
    did_resolver.resolve = MagicMock(return_value=ddo)
    # consumer_class = Mock
    # consumer_class.download = MagicMock(return_value='')
    return OceanAgreements(keeper, did_resolver, AssetConsumer,
                           ConfigProvider.get_config())
Пример #6
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)
Пример #7
0
def setup_all():
    config = ExampleConfig.get_config()
    Web3Provider.init_web3(config.keeper_url)
    ContractHandler.set_artifacts_path(config.keeper_path)
    Keeper.get_instance()
Пример #8
0
    def __init__(self, config=None):
        """
        Initialize Ocean class.
           >> # Make a new Ocean instance
           >> ocean = Ocean({...})

        This class provides the main top-level functions in ocean protocol:
         * Publish assets metadata and associated services
            * Each asset is assigned a unique DID and a DID Document (DDO)
            * The DDO contains the asset's services including the metadata
            * The DID is registered on-chain with a URL of the metadata store
              to retrieve the DDO from

            >> ddo = ocean.assets.create(metadata, publisher_account)

         * Discover/Search assets via the current configured metadata store (Aquarius)
            >> assets_list = ocean.assets.search('search text')

         * Purchase asset services by choosing a service agreement from the
           asset's DDO. Purchase goes through the service agreements interface
           and starts by signing a service agreement then sending the signature
           to the publisher's Brizo server via the `purchaseEndpoint` in the service
           definition:

           >> service_def_id = ddo.get_service(ServiceTypes.ASSET_ACCESS).service_definition_id
           >> service_agreement_id = ocean.assets.order(did, service_def_id, consumer_account)

        An instance of Ocean is parameterized by a `Config` instance.

        :param config: Config instance
        """
        # Configuration information for the market is stored in the Config class
        # config = Config(filename=config_file, options_dict=config_dict)
        if not config:
            config = ConfigProvider.get_config()

        self._config = config
        self._web3 = Web3Provider.get_web3(self._config.keeper_url)
        ContractHandler.set_artifacts_path(self._config.keeper_path)
        contracts = [
            'DIDRegistry', 'Dispenser', 'TemplateStoreManager', 'OceanToken',
            'ConditionStoreManager', 'EscrowAccessSecretStoreTemplate',
            'AgreementStoreManager', 'AgreementStoreManager',
            'AccessSecretStoreCondition', 'LockRewardCondition',
            'HashLockCondition', 'SignCondition', 'EscrowReward'
        ]
        self._keeper = Keeper.get_instance(contracts)
        self._did_resolver = DIDResolver(self._keeper.did_registry)

        # Initialize the public sub-modules
        self.tokens = OceanTokens(self._keeper)
        self.accounts = OceanAccounts(self._keeper, self._config, self.tokens)
        self.secret_store = OceanSecretStore(self._config)
        self.templates = OceanTemplates(self._keeper, config)
        self.agreements = self._make_ocean_agreements()
        self.assets = OceanAssets(self._keeper, self._did_resolver,
                                  self.agreements, AssetConsumer,
                                  AssetExecutor, self._config)
        self.services = OceanServices()
        self.ocean_providers = OceanProviders(self._keeper, self._did_resolver,
                                              self._config)
        self.auth = OceanAuth(self._keeper, self._config.storage_path)

        logger.debug('Squid Ocean instance initialized: ')
        logger.debug(
            f'\tOther accounts: {sorted([a.address for a in self.accounts.list()])}'
        )
        logger.debug(f'\tDIDRegistry @ {self._keeper.did_registry.address}')
Пример #9
0
def setup_all():
    Web3Provider.init_web3('http://localhost:8545')
    ContractHandler.set_artifacts_path(
        os.path.expanduser('~/.ocean/keeper-contracts/artifacts'))
    Keeper.get_instance()
Пример #10
0
def setup_all():
    config = get_config()
    keeper_url = config.keeper_url
    Web3Provider.init_web3(keeper_url)
    ContractHandler.set_artifacts_path(get_keeper_path(config))
    init_account_envvars()