Skip to content

Commit

Permalink
Merge pull request #58 from oceanprotocol/feature/token-address-did
Browse files Browse the repository at this point in the history
feature/token-address-did
  • Loading branch information
ssallam authored Sep 22, 2020
2 parents a221b94 + e5d80b2 commit fdd142e
Show file tree
Hide file tree
Showing 32 changed files with 29,471 additions and 31,435 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.5
current_version = 0.4.0
commit = True
tag = True

Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ services:
before_install:
- git clone https://github.com/oceanprotocol/barge
- cd barge
- git checkout v3
- git checkout feature/did-datatoken
- export AQUARIUS_VERSION=decentralized
- export PROVIDER_VERSION=v0.3.0
- export CONTRACTS_VERSION=v0.4.3
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
- cd ..
- |
Expand Down
1,582 changes: 740 additions & 842 deletions artifacts/BFactory.json

Large diffs are not rendered by default.

26,692 changes: 14,358 additions & 12,334 deletions artifacts/BPool.json

Large diffs are not rendered by default.

13,838 changes: 6,118 additions & 7,720 deletions artifacts/BToken.json

Large diffs are not rendered by default.

4,307 changes: 0 additions & 4,307 deletions artifacts/DDO.json

This file was deleted.

1,533 changes: 719 additions & 814 deletions artifacts/DTFactory.json

Large diffs are not rendered by default.

6,031 changes: 2,792 additions & 3,239 deletions artifacts/DataTokenTemplate.json

Large diffs are not rendered by default.

4,094 changes: 2,047 additions & 2,047 deletions artifacts/FixedRateExchange.json

Large diffs are not rendered by default.

2,490 changes: 2,490 additions & 0 deletions artifacts/Metadata.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ address.file =

;aquarius.url = http://localhost:5000
aquarius.url = https://aquarius.marketplace.dev-ocean.com
provider.url = http://localhost:8030
provider.url = http://localhost:8030/api/v1
provider.address = 0x00bd138abd70e2f00903268f3db08f2d25677c9e

storage.path = ocean_lib.db
Expand Down
10 changes: 5 additions & 5 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from examples import ExampleConfig
from ocean_lib.config_provider import ConfigProvider
from ocean_lib.models.data_token import DataToken
from ocean_lib.models.ddo import DDOContract
from ocean_lib.models.metadata import MetadataContract
from ocean_lib.models.dtfactory import DTFactory
from ocean_lib.models.fixed_rate_exchange import FixedRateExchange
from ocean_lib.models.bfactory import BFactory
Expand Down Expand Up @@ -142,10 +142,10 @@ def deploy(network, addresses_file):
addresses[FixedRateExchange.CONTRACT_NAME] = FixedRateExchange.deploy(web3, deployer_wallet, artifacts_path)
print("****Deploy 'FixedRateExchange': done****\n")

if DDOContract.CONTRACT_NAME not in _addresses:
print("****Deploy 'DDO': begin****")
addresses[DDOContract.CONTRACT_NAME] = DDOContract.deploy(web3, deployer_wallet, artifacts_path)
print("****Deploy 'DDO': done****\n")
if MetadataContract.CONTRACT_NAME not in _addresses:
print("****Deploy 'Metadata': begin****")
addresses[MetadataContract.CONTRACT_NAME] = MetadataContract.deploy(web3, deployer_wallet, artifacts_path)
print("****Deploy 'Metadata': done****\n")

if network == 'ganache' and 'Ocean' not in _addresses:
print("****Deploy fake OCEAN: begin****")
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
author = 'ocean-lib-py contributors'

# The full version, including alpha/beta/rc tags
release = '0.3.5'
release = '0.4.0'
# The short X.Y version
release_parts = release.split('.') # a list
version = release_parts[0] + '.' + release_parts[1]
Expand Down
4 changes: 2 additions & 2 deletions examples/example_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_base_config():
},
"resources": {
"aquarius.url": "http://aquarius:5000",
"provider.url": "http://localhost:8030",
"provider.url": "http://localhost:8030/api/v1",
"provider.address": '0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0',
"storage.path": "ocean_lib.db",
"downloads.path": "consume-downloads"
Expand All @@ -54,7 +54,7 @@ def get_rinkeby_config():
"resources": {
"aquarius.url": "http://aquarius:5000",
# "aquarius.url": "https://aquarius.marketplace.dev-ocean.com",
"provider.url": "http://localhost:8030",
"provider.url": "http://localhost:8030/api/v1",
"provider.address": '0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0',
"storage.path": "ocean_lib.db",
"downloads.path": "consume-downloads"
Expand Down
2 changes: 1 addition & 1 deletion ocean_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = """OceanProtocol"""
__version__ = '0.3.5'
__version__ = '0.4.0'

# Copyright 2018 Ocean Protocol Foundation
# SPDX-License-Identifier: Apache-2.0
35 changes: 31 additions & 4 deletions ocean_lib/data_provider/data_service_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,43 @@ def get_url(config):
:param config: Config
:return: Url, str
"""
_url = 'http://localhost:8030'
_url = 'http://localhost:8030/api/v1'
if config.has_option('resources', 'provider.url'):
_url = config.get('resources', 'provider.url') or _url

_path = '/api/v1'
return f'{_url}{_path}'
return _url

@staticmethod
def build_endpoint(service_name, provider_uri=None):
if not provider_uri:
config = ConfigProvider.get_config()
provider_uri = DataServiceProvider.get_url(config)
return f'{provider_uri}/services/{service_name}'

@staticmethod
def build_encrypt_endpoint(provider_uri=None):
return DataServiceProvider.build_endpoint('encrypt', provider_uri)

@staticmethod
def build_initialize_endpoint(provider_uri=None):
return DataServiceProvider.build_endpoint('initialize', provider_uri)

@staticmethod
def build_download_endpoint(provider_uri=None):
return DataServiceProvider.build_endpoint('download', provider_uri)

@staticmethod
def build_compute_endpoint(provider_uri=None):
return DataServiceProvider.build_endpoint('compute', provider_uri)

@staticmethod
def get_initialize_endpoint(service_endpoint):
base_url = '/'.join(service_endpoint.split('/')[:-1])
parts = service_endpoint.split('/')
if parts[-2] == 'services':
base_url = '/'.join(parts[:-2])
return f'{base_url}/services/initialize'

base_url = '/'.join(parts[:-1])
return f'{base_url}/initialize'

@staticmethod
Expand Down
10 changes: 7 additions & 3 deletions ocean_lib/models/data_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,16 @@ def verify_order_tx(self, web3, tx_id, did, service_id, amount_base, sender):
assert len(event_logs) == 1, \
f'Multiple order events in the same transaction !!! {event_logs}'

asset_id = remove_0x_prefix(did)
if order_log.args.did.hex() != asset_id or str(order_log.args.serviceId) != str(service_id):
asset_id = remove_0x_prefix(did).lower()
log_did = remove_0x_prefix(order_log.args.did.hex().lower())
if len(log_did) > 40:
log_did = log_did[: 40]

if log_did != asset_id or str(order_log.args.serviceId) != str(service_id):
raise AssertionError(f'The asset id (DID) or service id in the event does '
f'not match the requested asset. \n'
f'requested: (did={did}, serviceId={service_id}\n'
f'event: (did={order_log.args.did.hex()}, serviceId={order_log.args.serviceId}')
f'event: (did={log_did}, serviceId={order_log.args.serviceId}')

target_amount = amount_base - self.calculate_fee(amount_base, self.OPF_FEE_PERCENTAGE)
if order_log.args.mrktFeeCollector and order_log.args.marketFee > 0:
Expand Down
11 changes: 11 additions & 0 deletions ocean_lib/models/dtfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ class DTFactory(ContractBase):
CONTRACT_NAME = 'DTFactory'
FIRST_BLOB = 'https://example.com/dataset-1'

def verify_data_token(self, dt_address):
event = getattr(self.events, 'TokenRegistered')
filter_params = {'tokenAddress': dt_address}
event_filter = event().createFilter(
fromBlock=0,
argument_filters=filter_params
)
logs = event_filter.get_all_entries()

return logs and logs[0].args.tokenAddress == dt_address

def get_token_registered_event(self, block_number, metadata_url, sender):
event = getattr(self.events, 'TokenRegistered')
filter_params = {}
Expand Down
25 changes: 13 additions & 12 deletions ocean_lib/models/ddo.py → ocean_lib/models/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
from ocean_lib.web3_internal.wallet import Wallet


class DDOContract(ContractBase):
CONTRACT_NAME = 'DDO'
EVENT_DDO_CREATED = 'DDOCreated'
EVENT_DDO_UPDATED = 'DDOCreated'
EVENT_OWNERSHIP_TRANSFERRED = 'DDOOwnershipTransferred'
class MetadataContract(ContractBase):
CONTRACT_NAME = 'Metadata'
EVENT_METADATA_CREATED = 'MetadataCreated'
EVENT_METADATA_UPDATED = 'MetadataUpdated'

@property
def event_MetadataCreated(self):
return getattr(self.events, self.EVENT_METADATA_CREATED)

@property
def event_MetadataUpdated(self):
return getattr(self.events, self.EVENT_METADATA_UPDATED)

def get_event_log(self, event_name, block, did, timeout=45):
did = remove_0x_prefix(did)
Expand All @@ -30,22 +37,16 @@ def get_event_log(self, event_name, block, did, timeout=45):

_log = None
for log in logs:
if log.args.did.hex() == did:
if remove_0x_prefix(log.args.dataToken) == did:
_log = log
break
return _log

def verify_tx(self, tx_hash: str) -> bool:
return self.get_tx_receipt(tx_hash).status == 1

def didOwner(self, did: str) -> str:
return self.contract_concise.didOwners(did)

def create(self, did: str, flags: bytes, data: bytes, from_wallet: Wallet) -> str:
return self.send_transaction('create', (did, flags, data), from_wallet)

def update(self, did: str, flags: bytes, data: bytes, from_wallet: Wallet) -> str:
return self.send_transaction('update', (did, flags, data), from_wallet)

def transferOwnership(self, did: str, owner: str, from_wallet: Wallet) -> str:
return self.send_transaction('transferOwnership', (did, owner), from_wallet)
6 changes: 3 additions & 3 deletions ocean_lib/ocean/ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from ocean_lib.models.data_token import DataToken
from ocean_lib.models.ddo import DDOContract
from ocean_lib.models.metadata import MetadataContract
from ocean_lib.models.fixed_rate_exchange import FixedRateExchange
from ocean_lib.ocean.ocean_exchange import OceanExchange
from ocean_lib.ocean.ocean_pool import OceanPool
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, config=None, data_provider=None):
},
'resources': {
'aquarius.url': aqua_url,
'provider.url': config.get('providerUri', 'http://localhost:8030')
'provider.url': config.get('providerUri', 'http://localhost:8030/api/v1')
}
}
config = Config(options_dict=config_dict)
Expand All @@ -88,7 +88,7 @@ def __init__(self, config=None, data_provider=None):
self.assets = OceanAssets(
self._config,
data_provider,
addresses.get(DDOContract.CONTRACT_NAME)
addresses.get(MetadataContract.CONTRACT_NAME)
)
self.services = OceanServices()
self.auth = OceanAuth(self._config.storage_path)
Expand Down
Loading

0 comments on commit fdd142e

Please sign in to comment.