Beispiel #1
0
def get_another_consumer_ocean_instance(
        use_provider_mock: bool = False) -> Ocean:
    data_provider = DataProviderMock if use_provider_mock else None
    ocn = Ocean(data_provider=data_provider)
    account = get_another_consumer_wallet()
    ocn.main_account = account
    return ocn
def get_publisher_ocean_instance(use_provider_mock=False) -> Ocean:
    config = ExampleConfig.get_config()
    data_provider = DataProviderMock if use_provider_mock else None
    ocn = Ocean(config, data_provider=data_provider)
    account = get_publisher_wallet()
    ocn.main_account = account
    return ocn
Beispiel #3
0
def main(did, pool_address, order_tx_id=None):
ocean = Ocean(config=Config(options_dict=get_config_dict()))
publisher = Wallet(ocean.web3, private_key='0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58')  # 0xe2DD09d719Da89e5a3D0F2549c7E24566e947260
#consumer = Wallet(ocean.web3, private_key='0x9bf5d7e4978ed5206f760e6daded34d657572bd49fa5b3fe885679329fb16b16')  # 0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0
publisher_wallet = Wallet(ocean.web3, private_key=os.getenv('Publisher_Key')) #addr: 0xc966Ba2a41888B6B4c5273323075B98E27B9F364
consumer = Wallet(ocean.web3, private_key=os.getenv('Consumer_Key')) #addr: 0xEF5dc33A53DD2ED3F670B53F07cEc5ADD4D80504

    if not (did and pool_address):
        metadata_file = './examples/data/metadata.json'
        with open(metadata_file) as f:
            metadata = json.load(f)

        asset, pool = publish_asset(metadata, publisher)
        #Dataset asset created successfully: did=did:op:784Cc17176533cc962cf659B9f49349ba6F9df3b, datatoken=0x784Cc17176533cc962cf659B9f49349ba6F9df3b
        #pool_address = 0x3490DDd035B2e1DA30Af09AB6090Bf71fdb94898
    else:
        asset = ocean.assets.resolve(did)
        pool = BPool(pool_address)

    if not asset:
        print(f'publish asset failed, cannot continue with running compute.')
        return

    print(f'Requesting compute using asset {asset.did} and pool {pool.address}')
    algo_file = './examples/data/algorithm.py'
    order_tx_id=

    job_id, status = run_compute(asset.did, consumer, algo_file, pool.address, order_tx_id)
    print(f'Compute started on asset {asset.did}: job_id={job_id}, status={status}')
Beispiel #4
0
def make_info(name, private_key_name):
    # assume that this account has ETH with gas.
    class _Info:
        pass

    info = _Info()
    web3 = get_web3()
    config = ExampleConfig.get_config()

    info.web3 = web3

    info.private_key = os.environ.get(private_key_name)
    info.wallet = Wallet(
        web3,
        private_key=info.private_key,
        block_confirmations=config.block_confirmations,
        transaction_timeout=config.transaction_timeout,
    )
    info.address = info.wallet.address
    wallet = get_ganache_wallet()
    if wallet:
        assert get_ether_balance(
            web3, wallet.address) >= to_wei(4), "Ether balance less than 4."
        if get_ether_balance(web3, info.address) < to_wei(2):
            send_ether(wallet, info.address, to_wei(4))

    from ocean_lib.ocean.ocean import Ocean

    info.ocean = Ocean(config)
    info.T1 = _deployAndMintToken(web3, "TOK1", info.address)
    info.T2 = _deployAndMintToken(web3, "TOK2", info.address)

    return info
Beispiel #5
0
def main(did, pool_address, order_tx_id=None):
    ocean = Ocean(config=Config(options_dict=get_config_dict()))
    publisher = Wallet(
        ocean.web3,
        private_key="0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58",
    )  # 0xe2DD09d719Da89e5a3D0F2549c7E24566e947260
    consumer = Wallet(
        ocean.web3,
        private_key="0x9bf5d7e4978ed5206f760e6daded34d657572bd49fa5b3fe885679329fb16b16",
    )  # 0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0

    if not (did and pool_address):
        metadata_file = "./examples/data/metadata.json"
        with open(metadata_file) as f:
            metadata = json.load(f)

        asset, pool = publish_asset(metadata, publisher)
    else:
        asset = ocean.assets.resolve(did)
        pool = BPool(pool_address)

    if not asset:
        print("publish asset failed, cannot continue with running compute.")
        return

    print(f"Requesting compute using asset {asset.did} and pool {pool.address}")
    algo_file = "./examples/data/algorithm.py"
    job_id, status = run_compute(
        asset.did, consumer, algo_file, pool.address, order_tx_id
    )
    print(f"Compute started on asset {asset.did}: job_id={job_id}, status={status}")
Beispiel #6
0
def make_info(name, private_key_name):
    # assume that this account has ETH with gas.
    class _Info:
        pass

    info = _Info()
    web3 = get_web3()

    info.web3 = web3

    info.private_key = os.environ.get(private_key_name)
    info.wallet = Wallet(web3, private_key=info.private_key)
    info.address = info.wallet.address
    info.account = Account(private_key=info.private_key)
    wallet = get_ganache_wallet()
    if wallet:
        assert (from_wei(get_ether_balance(wallet.address)) >
                4), "Ether balance less than 4."
        if from_wei(get_ether_balance(info.address)) < 2:
            send_ether(wallet, info.address, 4)

    from ocean_lib.ocean.ocean import Ocean

    info.ocean = Ocean()
    info.T1 = _deployAndMintToken("TOK1", info.address)
    info.T2 = _deployAndMintToken("TOK2", info.address)

    return info
Beispiel #7
0
def publish_asset(metadata, publisher_wallet):
    ocean = Ocean(config=Config(options_dict=get_config_dict()))

    # create compute service
    compute_descriptor = build_compute_descriptor(ocean, publisher_wallet.address)

    # create asset DDO and datatoken
    try:
        asset = ocean.assets.create(metadata, publisher_wallet, [compute_descriptor], dt_name='Compute with data6', dt_symbol='DT-Testx7')
        print(f'Dataset asset created successfully: did={asset.did}, datatoken={asset.data_token_address}')
        #Dataset asset created successfully: did=did:op:2cbDb0Aaa1F546829E31267d1a7F74d926Bb5B1B, datatoken=0x2cbDb0Aaa1F546829E31267d1a7F74d926Bb5B1B
    except Exception as e:
        print(f'Publishing asset failed: {e}')
        return None, None

    dt = DataToken(asset.data_token_address)
    txid = dt.mint_tokens(publisher_wallet.address, 100, publisher_wallet)
    receipt = dt.get_tx_receipt(txid)
    assert receipt and receipt.status == 1, f'datatoken mint failed: tx={txid}, txReceipt={receipt}'


    # Create datatoken liquidity pool for the new asset
    pool = ocean.pool.create(asset.data_token_address, 50, 5, publisher_wallet, 5) #50 datatokens - 5 ocean in pool
    print(f'datatoken liquidity pool was created at address {pool.address}')
    #datatoken liquidity pool was created at address 0xeaD638506951B4a4c3575bbC0c7D1491c17B7A08
    # Now the asset can be discovered and consumed
    dt_cost = ocean.pool.calcInGivenOut(pool.address, ocean.OCEAN_address, asset.data_token_address, 1.0)
    print(f'Asset {asset.did} can now be purchased from pool @{pool.address} '
          f'at the price of {dt_cost} OCEAN tokens.')
    return asset, pool
Beispiel #8
0
def test_metadataStoreUri_version():
    config_dict = {
        "metadataStoreUri": "http://ItWorked.com",
        "network": "rinkeby"
    }
    ocean_instance = Ocean(config=config_dict)
    assert "http://ItWorked.com" == ocean_instance.config.aquarius_url
Beispiel #9
0
def initialize_ocean_market():
    """Initialize a test Ocean data market."""
    local_config = dotenv_values('../../.env')
    os.environ['OCEAN_NETWORK_URL'] = local_config['OCEAN_NETWORK_URL']
    config = ExampleConfig.get_config()
    ocean = Ocean(config)
    return ocean, local_config
Beispiel #10
0
def test1():
    # ocean instance
    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)

    ocean = Ocean(config)
    OCEAN_address_before = ocean.OCEAN_address

    # deploy, distribute, etc
    deploy_fake_OCEAN()

    # test: OCEAN address should have changed
    OCEAN_address_after = ocean.OCEAN_address
    assert OCEAN_address_before != OCEAN_address_after

    # test: TEST_PRIVATE_KEY{1,2} should each hold OCEAN
    wallet1 = Wallet(ocean.web3, private_key=os.getenv("TEST_PRIVATE_KEY1"))
    wallet2 = Wallet(ocean.web3, private_key=os.getenv("TEST_PRIVATE_KEY2"))

    OCEAN_after = BToken(ocean.OCEAN_address)
    assert OCEAN_after.balanceOf(wallet1.address) > 0
    assert OCEAN_after.balanceOf(wallet2.address) > 0
Beispiel #11
0
def publish_asset(metadata, publisher_wallet):
    ocean = Ocean(config=Config(options_dict=get_config_dict()))

    # create compute service
    compute_descriptor = build_compute_descriptor(ocean, publisher_wallet.address)

    # create asset DDO and datatoken
    try:
        asset = ocean.assets.create(metadata, publisher_wallet, [compute_descriptor],
                        dt_name='Dataset with Compute', dt_symbol='DT-Compute')
        print(f'Dataset asset created successfully: did={asset.did}, datatoken={asset.data_token_address}')
    except Exception as e:
        print(f'Publishing asset failed: {e}')
        return None, None

    dt = DataToken(asset.data_token_address)
    txid = dt.mint_tokens(publisher_wallet.address, 100, publisher_wallet)
    receipt = dt.get_tx_receipt(txid)
    assert receipt and receipt.status == 1, f'datatoken mint failed: tx={txid}, txReceipt={receipt}'

    # Create datatoken liquidity pool for the new asset
    pool = ocean.pool.create(asset.data_token_address, 50, 50, publisher_wallet, 5)
    print(f'datatoken liquidity pool was created at address {pool.address}')

    # Now the asset can be discovered and consumed
    dt_cost = ocean.pool.calcInGivenOut(pool.address, ocean.OCEAN_address, asset.data_token_address, 1.0)
    print(f'Asset {asset.did} can now be purchased from pool @{pool.address} '
          f'at the price of {dt_cost} OCEAN tokens.')
    return asset, pool
Beispiel #12
0
def test_metadataCacheUri_version():
    """Tests that the Aquarius URL can use the custom metadataCacheUri key."""
    config_dict = {
        "metadataCacheUri": "http://ItWorked.com",
        "network": "ganache"
    }
    ocean_instance = Ocean(config=config_dict)
    assert "http://ItWorked.com" == ocean_instance.config.aquarius_url
Beispiel #13
0
def test_metadataStoreUri_version():
    """Tests that the Aquarius URL can fallback on the custom metadataStoreUri key."""
    config_dict = {
        "metadataStoreUri": "http://ItWorked.com",
        "network": "rinkeby"
    }
    ocean_instance = Ocean(config=config_dict)
    assert "http://ItWorked.com" == ocean_instance.config.aquarius_url
Beispiel #14
0
def run_compute(did, consumer_wallet, algorithm_file, pool_address, order_id=None):
    ocean = Ocean(config=Config(options_dict=get_config_dict()))

    # Get asset DDO/metadata and service
    asset = ocean.assets.resolve(did)
    service = asset.get_service(ServiceTypes.CLOUD_COMPUTE)

    # check the price in ocean tokens
    num_ocean = ocean.pool.calcInGivenOut(pool_address, ocean.OCEAN_address, asset.data_token_address, 1.0)

    # buy datatoken to be able to run the compute service
    dt = DataToken(asset.asset_id)
    dt_balance = dt.token_balance(consumer_wallet.address)
    if dt_balance < 1.0:
        pool = BPool(pool_address)
        txid = ocean.pool.buy_data_tokens(pool_address, 1.0, num_ocean+0.1, consumer_wallet)
        receipt = pool.get_tx_receipt(txid)
        if not receipt or receipt.status != 1:
            print(f'buying data token failed: txId={txid}, txReceipt={receipt}')
            return None, None

    tx_id = order_id
    if not tx_id:
        tx_id = ocean.assets.pay_for_service(1.0, asset.data_token_address, did, service.index,
                                             fee_receiver=asset.publisher, from_wallet=consumer_wallet)

    # load python algorithm to run in the compute job
    with open(algorithm_file) as f:
        algorithm_text = f.read()

    # whether to publish the algorithm results as an Ocean assets
    output_dict = {
        'publishOutput': False,
        'publishAlgorithmLog': False,
    }
    # start the compute job (submit the compute service request)
    algorithm_meta = AlgorithmMetadata(
        {
            'language': 'python',
            'rawcode': algorithm_text,
            'container': {
                'tag': 'latest',
                'image': 'amancevice/pandas',
                'entrypoint': 'python $ALGO'
            }
        }
    )
    job_id = ocean.compute.start(did, consumer_wallet, tx_id, algorithm_meta=algorithm_meta, output=output_dict)

    # check the status of the compute job
    status = ocean.compute.status(did, job_id, consumer_wallet)
    print(f'status of compute job {job_id}: {status}')

    # get the result of the compute run
    result = ocean.compute.result(did, job_id, consumer_wallet)
    print(f'got result of compute job {job_id}: {result}')
    return job_id, status
Beispiel #15
0
def test_issue185_system(monkeypatch):
    """A system-level test, to replicate original failure seen in #185"""
    setup_issue_185(monkeypatch)

    # actual test. Imports only come now, to avoid setting class-level attributes
    from ocean_lib.ocean.ocean import Ocean
    from ocean_lib.web3_internal.wallet import Wallet

    private_key = os.getenv("TEST_PRIVATE_KEY1")
    config = {"network": os.getenv("NETWORK_URL")}
    ocean = Ocean(config)

    wallet = Wallet(ocean.web3, private_key=private_key)

    # this failed before the fix
    datatoken = ocean.create_data_token("Dataset name",
                                        "dtsymbol",
                                        from_wallet=wallet)
    assert datatoken is not None
Beispiel #16
0
def initialize_market(env_file='env.yaml'):
    """Initialize an Ocean data marketplace.
    Args:
        env_file (str): An environment variable file,
            `env.yaml` by default.
    Returns:
    
    """
    config = None
    with open(env_file, 'r') as f:
        config = yaml.load(f, Loader=yaml.FullLoader)
    os.environ['ocean_network_url'] = config['OCEAN_NETWORK_URL']
    return Ocean(config)
Beispiel #17
0
def initialize(private_key):
    load_dotenv(".env")
    config = Config(os.getenv('config.ini'))
    config = Config(os.getenv('config.ini'))
    print(config.network_url)
    # config.network_url="https://rinkeby.infura.io/v3/31d95be121a545b688a0e07e4de4d256"
    ConfigProvider.set_config(config)
    Web3Provider.init_web3(
        provider=get_web3_connection_provider(config.network_url))
    ContractHandler.set_artifacts_path(config.artifacts_path)
    ocean = Ocean()
    wallet = Wallet(ocean.web3, private_key=private_key)
    return ocean, wallet
Beispiel #18
0
def run_scenario():
    config = Config('config.ini')
    ocean = Ocean(config)
    wallet = Wallet(
        ocean.web3,
        0x376e05899a4ae00463a3a607c774069b7d6a647860dba723f39b735c91238ddf,
        None, "EARLYTOBEDANDEARLYTORISE")
    ConfigProvider.set_config(config)
    Web3Provider.init_web3(
        provider=get_web3_connection_provider(config.network_url))
    ContractHandler.set_artifacts_path(config.artifacts_path)
    print(dir(wallet))
    print(wallet.address)
    print(config.network_url)
    print(config.provider_url)
    print(config.network_url)
    print(config.artifacts_path)

    data_token = ocean.create_data_token('S1Seven', 'S1SV', from_wallet=wallet)
    print(f'created new datatoken with address {data_token.address}')
    token_address = data_token.address
    print(token_address)
    '''
def get_user_balances(userAddress):
    """

    :param userAddress:
    :return:
    """
    try:
        data = get_request_data(request) or {}
        from_block = data.get('fromBlock', int(os.getenv('BFACTORY_BLOCK', 0)))
        ocean = Ocean(ConfigProvider.get_config())
        result = ocean.pool.get_user_balances(userAddress, from_block)
        return Response(json.dumps(result),
                        200,
                        content_type='application/json')
    except Exception as e:
        logger.error(f'pools/user/{userAddress}: {str(e)}')
        return f'Get pool user balances failed: {str(e)}', 500
def get_current_liquidity_stats(poolAddress):
    """

    :param poolAddress:
    :return:
    """
    try:
        data = get_request_data(request) or {}
        dt_address = data.get('datatokenAddress', None)
        from_block = data.get('fromBlock', None)
        to_block = data.get('toBlock', None)
        ocean = Ocean(ConfigProvider.get_config())
        pool_info = ocean.pool.get_short_pool_info(poolAddress, dt_address,
                                                   from_block, to_block)
        return Response(json.dumps(pool_info),
                        200,
                        content_type='application/json')
    except Exception as e:
        logger.error(f'pools/liquidity/{poolAddress}: {str(e)}')
        return f'Get pool current liquidity stats failed: {str(e)}', 500
def get_liquidity_history(poolAddress):
    """

    :param poolAddress:
    :return: json object with two keys: `ocean` and `datatoken`
      each has a list of datapoints sampled at specific time intervals from the pools liquidity history.
    """
    try:
        result = dict()
        ocean = Ocean(ConfigProvider.get_config())
        pool = BPool(poolAddress)
        dt_address = ocean.pool.get_token_address(poolAddress,
                                                  pool,
                                                  validate=False)
        swap_fee = from_base_18(pool.getSwapFee())
        ocn_weight = from_base_18(
            pool.getDenormalizedWeight(ocean.OCEAN_address))
        dt_weight = from_base_18(pool.getDenormalizedWeight(dt_address))

        ocn_add_remove_list, dt_add_remove_list = ocean.pool.get_liquidity_history(
            poolAddress)
        ocn_add_remove_list = [(v, int(t)) for v, t in ocn_add_remove_list]
        dt_add_remove_list = [(v, int(t)) for v, t in dt_add_remove_list]

        ocn_reserve_history, dt_reserve_history, price_history = build_liquidity_and_price_history(
            ocn_add_remove_list, dt_add_remove_list, ocn_weight, dt_weight,
            swap_fee)

        result['oceanAddRemove'] = ocn_add_remove_list
        result['datatokenAddRemove'] = dt_add_remove_list
        result['oceanReserveHistory'] = ocn_reserve_history
        result['datatokenReserveHistory'] = dt_reserve_history
        result['datatokenPriceHistory'] = price_history
        return Response(json.dumps(result),
                        200,
                        content_type='application/json')
    except Exception as e:
        logger.error(f'pools/history/{poolAddress}: {str(e)}', exc_info=1)
        return f'Get pool liquidity/price history failed: {str(e)}', 500
Beispiel #22
0
def test_issue185_unit(monkeypatch):
    """For #185, unit-test the root cause method, which is load"""
    setup_issue_185(monkeypatch)

    # ensure that conftest::setup_all() was not called
    assert ConfigProvider._config is None
    assert Web3Provider._web3 is None
    assert ContractHandler._contracts == dict()
    assert ContractHandler.artifacts_path is None

    # actual test. Imports only come now, to avoid setting class-level attributes
    # isort: off
    from ocean_lib.ocean.ocean import Ocean
    from ocean_lib.web3_internal.wallet import Wallet

    # isort: on

    private_key = os.getenv("TEST_PRIVATE_KEY1")
    config = {"network": os.getenv("NETWORK_URL")}
    ocean = Ocean(config)

    # Ensure it's using a path like '/home/trentmc/ocean.py/venv/artifacts'
    assert os.path.exists(ocean._config.artifacts_path)
    assert "venv/artifacts" in ocean._config.artifacts_path

    wallet = Wallet(ocean.web3, private_key=private_key)
    assert wallet is not None

    # At this point, shouldn't have any contracts cached
    assert ContractHandler._contracts == {}

    # This is the call that causes problems in system test.
    contract = ContractHandler._get("DataTokenTemplate", None)
    assert contract is not None

    # The first call may have caused caching. So call again:)
    contract = ContractHandler._get("DataTokenTemplate", None)
    assert contract is not None
Beispiel #23
0
from ocean_lib.models.algorithm_metadata import AlgorithmMetadata
from ocean_lib.models.bpool import BPool
from ocean_lib.models.data_token import DataToken
from ocean_lib.ocean.ocean import Ocean
from ocean_lib.web3_internal.wallet import Wallet
import os

from examples.compute_service import build_compute_descriptor, get_config_dict, run_compute, publish_asset
#Publish Model with compute to data, with training algorithim
#Alice's config
config = {
   'network' : os.getenv('NETWORK_URL'),
   'metadataStoreUri' : os.getenv('AQUARIUS_URL'),
   'providerUri' : os.getenv('PROVIDER_URL'),
}
ocean = Ocean(config)


alice_wallet = Wallet(ocean.web3, private_key=os.getenv('Publisher_Key'))

data_token = ocean.create_data_token('DToxen2', 'DTX2', alice_wallet, blob=ocean.config.metadata_store_url)
token_address = data_token.address

date_created = "2020-02-01T10:55:11Z"
service_attributes = {
        "main": {
            "name": "dataAssetAccessServiceAgreement",
            "creator": alice_wallet.address,
            "timeout": 3600 * 24,
            "datePublished": date_created,
            "cost": 1.0, # <don't change, this is obsolete>
Beispiel #24
0
def test_metadataCacheUri_config_key():
    """Tests that the metadata_cache_uri config property can be set using the
    `metadataCacheUri` config dict key when created via the Ocean __init__"""
    config_dict = {"metadataCacheUri": "http://ItWorked.com", "network": "ganache"}
    ocean_instance = Ocean(config=config_dict)
    assert "http://ItWorked.com" == ocean_instance.config.metadata_cache_uri
from ocean_lib.ocean.util import get_web3_connection_provider

from ocean_lib.web3_internal.web3_provider import Web3Provider, CustomHTTPProvider
from ocean_lib.data_provider.data_service_provider import DataServiceProvider

from ocean_utils.agreements.service_factory import ServiceDescriptor

from ocean_lib.web3_internal.contract_handler import ContractHandler
from ocean_lib.web3_internal.wallet import Wallet



config = Config('config.ini')
# Ocean instance: create/get datatoken, get dtfactory, user orders (history)
ocean = Ocean(config)

# wallet = Wallet(ocean.web3, b'7n\x05\x89\x9aJ\xe0\x04c\xa3\xa6\x07\xc7t\x06\x9b}jdx`\xdb\xa7#\xf3\x9bs\\\x91#\x8d\xdf', None, "EARLYTOBEDANDEARLYTORISE")
wallet = Wallet(ocean.web3, 0x376e05899a4ae00463a3a607c774069b7d6a647860dba723f39b735c91238ddf, None, "EARLYTOBEDANDEARLYTORISE")


'''
config_file = """
[eth-network]
network = https://rinkeby.infura.io/v3/102d6a75aad644f6a5b131e254d08892

[resources]
aquarius.url = https://aquarius.rinkeby.v3.dev-ocean.com
provider.url = https://provider.rinkeby.v3.dev-ocean.co
"""
'''
Beispiel #26
0
import os

from ocean_lib.ocean.ocean import Ocean
from ocean_lib.web3_internal.wallet import Wallet
from ocean_lib.data_provider.data_service_provider import DataServiceProvider
from ocean_utils.agreements.service_factory import ServiceDescriptor
#Publish asset to download. Tetsing
#Alice's config
config = {
   'network' : os.getenv('NETWORK_URL'),
   'metadataStoreUri' : os.getenv('AQUARIUS_URL'),
   'providerUri' : os.getenv('PROVIDER_URL'),
}
ocean = Ocean(config)


alice_wallet = Wallet(ocean.web3, private_key=os.getenv('Publisher_Key'))

data_token = ocean.create_data_token('GPT-2 Pretrained', 'GPT2P', alice_wallet, blob=ocean.config.metadata_store_url)
token_address = data_token.address

date_created = "2020-02-01T10:55:11Z"
service_attributes = {
        "main": {
            "name": "dataAssetAccessServiceAgreement",
            "creator": alice_wallet.address,
            "timeout": 3600 * 24,
            "datePublished": date_created,
            "cost": 1.0, # <don't change, this is obsolete>
        }
    }
Beispiel #27
0
import os
from datetime import date
from ocean_lib.ocean.ocean import Ocean
from ocean_lib.web3_internal.wallet import Wallet
from ocean_lib.data_provider.data_service_provider import DataServiceProvider
from ocean_utils.agreements.service_factory import ServiceDescriptor
import datetime
from ocean_lib.ocean.ocean_compute import OceanCompute
from ocean_lib.ocean.ocean_auth import OceanAuth
import json

ocean = Ocean()
from dotenv import load_dotenv
# from main import initialize
#
from ocean_lib.config import Config
from web3 import Web3
from ocean_lib.config_provider import ConfigProvider

#
# alice_wallet = Wallet(ocean.web3, private_key="58ea0ec8af8f64aad99296c7e7b960ed54c94c8c49a86990a8d369ce9b9a177f")
# trying to make compute jobs in ocean protocol


# we need this auth and all for the compute job
# computer job attributes
def auth_ocean_token(wallet):
    ocean_auth = OceanAuth("./storage_tokens")
    token = ocean_auth.get(wallet)
    return ocean_auth
Beispiel #28
0
def main(did, pool_address, order_tx_id=None):
    ocean = Ocean(config=Config(options_dict=get_config_dict()))
import os

from ocean_lib.ocean.ocean import Ocean
from ocean_lib.web3_internal.wallet import Wallet
from ocean_lib.config import Config
from ocean_lib.config_provider import ConfigProvider

from ocean_lib.data_provider.data_service_provider import DataServiceProvider
from ocean_utils.agreements.service_factory import ServiceDescriptor


config = Config('config.ini')
ocean = Ocean(config)

alice_wallet = Wallet(ocean.web3, 0x376e05899a4ae00463a3a607c774069b7d6a647860dba723f39b735c91238ddf)
b'Uau3\xc8\x96`\xe5J\xa1\x88x\xeaT\xa6[}\x01kE\xcb\xf4AQ\xdd\xb0\xc2\xb3\xb9Q\xc1\xd5'


web3 = Web

#data_token = ocean.create_data_token('DataToken1', 'DT1', alice_wallet, blob=ocean.config.metadata_store_url)
#data_token = ocean.create_data_token('DataToken1', 'DT1', alice_wallet)
#token_address = data_token.address



Beispiel #30
0
import os
from ocean_utils.agreements.service_types import ServiceTypes

from ocean_lib.ocean.ocean import Ocean
from ocean_lib.ocean.util import from_base_18
from ocean_lib.models.bpool import BPool

# Market's config
config = {
    'network': os.getenv('NETWORK_URL'),
}
market_ocean = Ocean(config)

#did='did:op:2cbDb0Aaa1F546829E31267d1a7F74d926Bb5B1B'  # from step 3
#pool_address = '0xeaD638506951B4a4c3575bbC0c7D1491c17B7A08'  # from step 4
asset = market_ocean.assets.resolve(did)
service1 = asset.get_service(ServiceTypes.ASSET_ACCESS)
pool = market_ocean.pool.get(pool_address)
#token_address = '0x2cbDb0Aaa1F546829E31267d1a7F74d926Bb5B1B'

OCEAN_address = market_ocean.pool.ocean_address
price_in_OCEAN = ocean.pool.calcInGivenOut(pool_address,
                                           OCEAN_address,
                                           token_address,
                                           token_out_amount=1.0)
print(f"Price of 1 datatoken is {price_in_OCEAN} OCEAN")

import os
from ocean_lib.ocean.util import to_base_18
from ocean_lib.web3_internal.wallet import Wallet