def setup_all(): config = ExampleConfig.get_config() ConfigProvider.set_config(config) Web3Provider.init_web3( provider=get_web3_connection_provider(config.network_url)) ContractHandler.set_artifacts_path(config.artifacts_path) network = Web3Helper.get_network_name() wallet = get_ganache_wallet() if network in ["ganache", "development"] and wallet: print( f"sender: {wallet.key}, {wallet.address}, {wallet.password}, {wallet.keysStr()}" ) print( f"sender balance: {Web3Helper.from_wei(Web3Helper.get_ether_balance(wallet.address))}" ) assert Web3Helper.from_wei(Web3Helper.get_ether_balance( wallet.address)) > 10 from ocean_lib.models.data_token import DataToken OCEAN_token = DataToken(get_ocean_token_address(network)) amt_distribute = 1000 amt_distribute_base = to_base_18(float(amt_distribute)) for w in (get_publisher_wallet(), get_consumer_wallet()): if Web3Helper.from_wei(Web3Helper.get_ether_balance( w.address)) < 2: Web3Helper.send_ether(wallet, w.address, 4) if OCEAN_token.token_balance(w.address) < 100: OCEAN_token.transfer(w.address, amt_distribute_base, from_wallet=wallet)
def test_get_ocean_token_address(config): addresses = util.get_contracts_addresses(config.address_file, "ganache") assert addresses assert isinstance(addresses, dict) assert "Ocean" in addresses address = get_ocean_token_address(config.address_file, "ganache") assert address[:2] == "0x", "It is not a token address." assert address == addresses["Ocean"]
def OCEAN_address(): return get_ocean_token_address(_NETWORK)
def __init__(self, config=None, data_provider=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 >> asset = ocean.assets.create(metadata, publisher_wallet) * Discover/Search assets via the current configured metadata store (Aquarius) >> assets_list = ocean.assets.search('search text') An instance of Ocean is parameterized by a `Config` instance. :param config: Config instance :param data_provider: DataServiceProvider instance """ # Configuration information for the market is stored in the Config class # config = Config(filename=config_file, options_dict=config_dict) if not config: try: config = ConfigProvider.get_config() except AssertionError: config = Config(os.getenv(ENV_CONFIG_FILE)) ConfigProvider.set_config(config) if isinstance(config, dict): # fallback to metadataStoreUri cache_key = ("metadataCacheUri" if ("metadataCacheUri" in config) else "metadataStoreUri") aqua_url = config.get( cache_key, config.get("aquarius.url", "http://localhost:5000")) config_dict = { "eth-network": { "network": config.get("network", "") }, "resources": { "aquarius.url": aqua_url, "provider.url": config.get("providerUri", "http://localhost:8030"), }, } config = Config(options_dict=config_dict) ConfigProvider.set_config(config) self._config = config ContractHandler.set_artifacts_path(self._config.artifacts_path) Web3Provider.init_web3( provider=get_web3_connection_provider(self._config.network_url)) self._web3 = Web3Provider.get_web3() if not data_provider: data_provider = DataServiceProvider network = Web3Helper.get_network_name() addresses = get_contracts_addresses(network, self._config) self.assets = OceanAssets( self._config, data_provider, addresses.get(MetadataContract.CONTRACT_NAME)) self.services = OceanServices() self.auth = OceanAuth(self._config.storage_path) self.compute = OceanCompute(self.auth, self._config, data_provider) ocean_address = get_ocean_token_address(network) self.pool = OceanPool(ocean_address, get_bfactory_address(network)) self.exchange = OceanExchange( ocean_address, FixedRateExchange.configured_address( network or Web3Helper.get_network_name(), ConfigProvider.get_config().address_file, ), self.config, ) logger.debug("Ocean instance initialized: ")
def OCEAN_address(self): return get_ocean_token_address(Web3Helper.get_network_name())
def test_get_OCEAN_address(publisher_ocean_instance): """Tests OCEAN address retrieval.""" network = get_network_name() assert publisher_ocean_instance.pool.get_OCEAN_address( ) == get_ocean_token_address(network)
def OCEAN_address(config): return get_ocean_token_address(config.address_file, _NETWORK)
def OCEAN_address(self): return get_ocean_token_address(get_network_name())
def __init__( self, config: Union[Dict, Config], data_provider: Optional[Type] = None ) -> None: """Initialize Ocean class. Usage: Make a new Ocean instance `ocean = Ocean({...})` This class provides the main top-level functions in ocean protocol: 1. 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 `asset = ocean.assets.create(metadata, publisher_wallet)` 2. Discover/Search assets via the current configured metadata store (Aquarius) - Usage: `assets_list = ocean.assets.search('search text')` An instance of Ocean is parameterized by a `Config` instance. :param config: `Config` instance :param data_provider: `DataServiceProvider` instance """ if isinstance(config, dict): # fallback to metadataStoreUri cache_key = ( "metadataCacheUri" if ("metadataCacheUri" in config) else "metadataStoreUri" ) metadata_cache_uri = config.get( cache_key, config.get("metadata_cache_uri", "http://localhost:5000") ) config_dict = { "eth-network": {"network": config.get("network", "")}, "resources": { "metadata_cache_uri": metadata_cache_uri, "provider.url": config.get("providerUri", "http://localhost:8030"), }, } config = Config(options_dict=config_dict) self.config = config self.web3 = get_web3(self.config.network_url) if not data_provider: data_provider = DataServiceProvider network = get_network_name(web3=self.web3) addresses = get_contracts_addresses(self.config.address_file, network) self.assets = OceanAssets( self.config, self.web3, data_provider, addresses.get(MetadataContract.CONTRACT_NAME), ) self.compute = OceanCompute(self.config, data_provider) ocean_address = get_ocean_token_address(self.config.address_file, network) self.pool = OceanPool( self.web3, ocean_address, get_bfactory_address(self.config.address_file, network), get_dtfactory_address(self.config.address_file, network), ) self.exchange = OceanExchange( self.web3, ocean_address, FixedRateExchange.configured_address(network, self.config.address_file), self.config, ) logger.debug("Ocean instance initialized: ")
def OCEAN_address(self) -> str: return get_ocean_token_address(self.config.address_file, web3=self.web3)