diff --git a/.bumpversion.cfg b/.bumpversion.cfg index b62999d9c..09a19b854 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.0.0-alpha.3 +current_version = 1.0.0-alpha.4 commit = True tag = True diff --git a/READMEs/c2d-flow-more-examples.md b/READMEs/c2d-flow-more-examples.md index 57700d896..41e7d348e 100644 --- a/READMEs/c2d-flow-more-examples.md +++ b/READMEs/c2d-flow-more-examples.md @@ -59,7 +59,7 @@ ALGO_metadata = { "container": { "entrypoint": "python $ALGO", "image": "oceanprotocol/algo_dockers", - "tag": "python-branin", # This image provides all the dependencies of the grayscale.py algorithm + "tag": "python-branin", # This image provides all the dependencies of the grayscale.py algorithm "checksum": "44e10daa6637893f4276bb8d7301eb35306ece50f61ca34dcab550", }, } diff --git a/READMEs/c2d-flow.md b/READMEs/c2d-flow.md index a6a258fb2..79e0380c2 100644 --- a/READMEs/c2d-flow.md +++ b/READMEs/c2d-flow.md @@ -56,21 +56,8 @@ Please refer to [data-nfts-and-datatokens-flow](data-nfts-and-datatokens-flow.md In the same python console: ```python -from ocean_lib.web3_internal.constants import ZERO_ADDRESS - # Publish the datatoken -DATA_datatoken = erc721_nft.create_datatoken( - template_index=1, - name="Datatoken 1", - symbol="DT1", - minter=alice_wallet.address, - fee_manager=alice_wallet.address, - publish_market_order_fee_address=ZERO_ADDRESS, - publish_market_order_fee_token=ocean.OCEAN_address, - publish_market_order_fee_amount=0, - bytess=[b""], - from_wallet=alice_wallet, -) +DATA_datatoken = erc721_nft.create_datatoken("DATA 1", "D1", from_wallet=alice_wallet) print(f"DATA_datatoken address = '{DATA_datatoken.address}'") # Specify metadata and services, using the Branin test dataset @@ -137,18 +124,7 @@ ALGO_nft_token = ocean.create_erc721_nft("NFTToken1", "NFT1", alice_wallet) print(f"ALGO_nft_token address = '{ALGO_nft_token.address}'") # Publish the datatoken -ALGO_datatoken = ALGO_nft_token.create_datatoken( - template_index=1, - name="Datatoken 1", - symbol="DT1", - minter=alice_wallet.address, - fee_manager=alice_wallet.address, - publish_market_order_fee_address=ZERO_ADDRESS, - publish_market_order_fee_token=ocean.OCEAN_address, - publish_market_order_fee_amount=0, - bytess=[b""], - from_wallet=alice_wallet, -) +ALGO_datatoken = ALGO_nft_token.create_datatoken("ALGO 1", "A1", from_wallet=alice_wallet) print(f"ALGO_datatoken address = '{ALGO_datatoken.address}'") # Specify metadata and services, using the Branin test dataset @@ -315,14 +291,14 @@ X0_vec = numpy.linspace(-5., 10., 15) X1_vec = numpy.linspace(0., 15., 15) X0, X1 = numpy.meshgrid(X0_vec, X1_vec) b, c, t = 0.12918450914398066, 1.5915494309189535, 0.039788735772973836 -u = X1 - b*X0**2 + c*X0 - 6 -r = 10.*(1. - t) * numpy.cos(X0) + 10 -Z = u**2 + r +u = X1 - b * X0 ** 2 + c * X0 - 6 +r = 10. * (1. - t) * numpy.cos(X0) + 10 +Z = u ** 2 + r fig, ax = pyplot.subplots(subplot_kw={"projection": "3d"}) ax.scatter(X0, X1, model, c="r", label="model") pyplot.title("Data + model") -pyplot.show() # or pyplot.savefig("test.png") to save the plot as a .png file instead +pyplot.show() # or pyplot.savefig("test.png") to save the plot as a .png file instead ``` You should see something like this: @@ -336,7 +312,7 @@ For examples using different datasets and algorithms, please see [c2d-flow-more- In the "publish algorithm" step, to replace the sample algorithm with another one: - Use one of the standard [Ocean algo_dockers images](https://github.com/oceanprotocol/algo_dockers) or publish a custom docker image. -- Use the image name and tag in the `container` part of the algorithm metadata. +- Use the image name and tag in the `container` part of the algorithm metadata. - The image must have basic support for installing dependencies. E.g. "pip" for the case of Python. You can use other languages, of course. - More info: https://docs.oceanprotocol.com/tutorials/compute-to-data-algorithms/) diff --git a/READMEs/consume-flow.md b/READMEs/consume-flow.md index bcd0ef2bf..d97ec416a 100644 --- a/READMEs/consume-flow.md +++ b/READMEs/consume-flow.md @@ -70,7 +70,7 @@ erc20_token.mint( # Bob points to the service object from ocean_lib.web3_internal.constants import ZERO_ADDRESS -fee_receiver = ZERO_ADDRESS # could also be market address +fee_receiver = ZERO_ADDRESS # could also be market address service = asset.services[0] # Bob sends his datatoken to the service @@ -92,7 +92,7 @@ file_path = ocean.assets.download_asset( destination='./', order_tx_id=order_tx_id ) -print(f"file_path = '{file_path}'") #e.g. datafile.0xAf07... +print(f"file_path = '{file_path}'") # e.g. datafile.0xAf07... ``` In console: diff --git a/READMEs/data-nfts-and-datatokens-flow.md b/READMEs/data-nfts-and-datatokens-flow.md index d9c421a20..2704d23eb 100644 --- a/READMEs/data-nfts-and-datatokens-flow.md +++ b/READMEs/data-nfts-and-datatokens-flow.md @@ -100,20 +100,8 @@ Congrats, you've created your first Ocean data NFT! In the same python console: ```python # Create ERC20 token related to the above NFT. -from ocean_lib.web3_internal.constants import ZERO_ADDRESS - -erc20_token = erc721_nft.create_datatoken( - template_index=1, # default value - name="ERC20DT1", # name for ERC20 token - symbol="ERC20DT1Symbol", # symbol for ERC20 token - minter=alice_wallet.address, # minter address - fee_manager=alice_wallet.address, # fee manager for this ERC20 token - publish_market_order_fee_address=alice_wallet.address, # publishing Market Address - publish_market_order_fee_token=ZERO_ADDRESS, # publishing Market Fee Token - publish_market_order_fee_amount=0, - bytess=[b""], - from_wallet=alice_wallet -) + +erc20_token = erc721_nft.create_datatoken("Datatoken 1", "DT1", from_wallet=alice_wallet) print(f"Created ERC20 datatoken. Its address is {erc20_token.address}") ``` @@ -125,20 +113,20 @@ You can combine creating a data NFT and datatoken into a single call: `ocean.cre To learn more about some of the objects you created, here are some examples. ```python -#config +# config print(f"config.network_url = '{config.network_url}'") print(f"config.block_confirmations = {config.block_confirmations.value}") print(f"config.metadata_cache_uri = '{config.metadata_cache_uri}'") print(f"config.provider_url = '{config.provider_url}'") -#wallet +# wallet print(f"alice_wallet.address = '{alice_wallet.address}'") -#data NFT +# data NFT print(f"data NFT token name: {erc721_nft.token_name()}") print(f"data NFT token symbol: {erc721_nft.symbol()}") -#datatoken +# datatoken print(f"datatoken name: {erc20_token.token_name()}") print(f"datatoken symbol: {erc20_token.symbol()}") ``` diff --git a/READMEs/erc20-enterprise.md b/READMEs/erc20-enterprise.md index 5ad2f3e83..366e7d048 100644 --- a/READMEs/erc20-enterprise.md +++ b/READMEs/erc20-enterprise.md @@ -52,15 +52,9 @@ In the Python console: from ocean_lib.web3_internal.constants import ZERO_ADDRESS erc20_enterprise_token = erc721_nft.create_datatoken( - template_index=2, # this is the value for ERC20 Enterprise token name="ERC20DT1", # name for ERC20 token symbol="ERC20DT1Symbol", # symbol for ERC20 token - minter=alice_wallet.address, # minter address - fee_manager=alice_wallet.address, # fee manager for this ERC20 token - publish_market_order_fee_address=alice_wallet.address, # publishing Market Address - publish_market_order_fee_token=ZERO_ADDRESS, # publishing Market Fee Token - publish_market_order_fee_amount=0, - bytess=[b""], + template_index=2, # this is the value for ERC20 Enterprise token from_wallet=alice_wallet, ) print(f"ERC20 Enterprise address: {erc20_enterprise_token.address}") @@ -144,15 +138,9 @@ In the Python console: from ocean_lib.web3_internal.constants import ZERO_ADDRESS erc20_enterprise_token = erc721_nft.create_datatoken( - template_index=2, # this is the value for ERC20 Enterprise token name="ERC20DT1", # name for ERC20 token symbol="ERC20DT1Symbol", # symbol for ERC20 token - minter=alice_wallet.address, # minter address - fee_manager=alice_wallet.address, # fee manager for this ERC20 token - publish_market_order_fee_address=alice_wallet.address, # publishing Market Address - publish_market_order_fee_token=ZERO_ADDRESS, # publishing Market Fee Token - publish_market_order_fee_amount=0, - bytess=[b""], + template_index=2, # this is the value for ERC20 Enterprise token from_wallet=alice_wallet, ) print(f"ERC20 Enterprise address: {erc20_enterprise_token.address}") diff --git a/READMEs/fixed-rate-exchange-flow.md b/READMEs/fixed-rate-exchange-flow.md index 43990d5e5..89d5e587f 100644 --- a/READMEs/fixed-rate-exchange-flow.md +++ b/READMEs/fixed-rate-exchange-flow.md @@ -46,7 +46,7 @@ Please refer to [data-nfts-and-datatokens-flow](data-nfts-and-datatokens-flow.md In the same python console: ```python -#Mint the datatokens +# Mint the datatokens erc20_token.mint(alice_wallet.address, ocean.to_wei(100), alice_wallet) ``` diff --git a/READMEs/key-value-flow.md b/READMEs/key-value-flow.md index 8c0d1d9f1..e06539f42 100644 --- a/READMEs/key-value-flow.md +++ b/READMEs/key-value-flow.md @@ -36,17 +36,17 @@ From [data-nfts-and-datatokens-flow](data-nfts-and-datatokens-flow.md), do: ## 3. Add key-value pair to data NFT ```python -#Key-value pair +# Key-value pair key = "fav_color" value = "blue" -#prep key for setter -key_hash = ocean.web3.keccak(text=key) #Contract/ERC725 requires keccak256 hash +# prep key for setter +key_hash = ocean.web3.keccak(text=key) # Contract/ERC725 requires keccak256 hash -#prep value for setter -value_hex = value.encode('utf-8').hex() #set_new_data() needs hex +# prep value for setter +value_hex = value.encode('utf-8').hex() # set_new_data() needs hex -#set +# set erc721_nft.set_new_data(key_hash, value_hex, alice_wallet) ``` diff --git a/READMEs/marketplace-flow.md b/READMEs/marketplace-flow.md index 4363e7232..74677ba10 100644 --- a/READMEs/marketplace-flow.md +++ b/READMEs/marketplace-flow.md @@ -87,7 +87,6 @@ bpool = ocean.create_pool( from_wallet=alice_wallet ) print(f"BPool address: {bpool.address}") - ``` ## 4. Marketplace displays asset for sale @@ -142,7 +141,7 @@ assert erc20_token.balanceOf(bob_wallet.address) >= ocean.to_wei( # Bob points to the service object from ocean_lib.web3_internal.constants import ZERO_ADDRESS -fee_receiver = ZERO_ADDRESS # could also be market address +fee_receiver = ZERO_ADDRESS # could also be market address asset = ocean.assets.resolve(did) service = asset.services[0] diff --git a/READMEs/profile-nfts-flow.md b/READMEs/profile-nfts-flow.md index 7d085b5ba..4ca149b31 100644 --- a/READMEs/profile-nfts-flow.md +++ b/READMEs/profile-nfts-flow.md @@ -56,33 +56,33 @@ erc721_nft = ocean.create_erc721_nft('NFTToken1', 'NFT1', alice_wallet, transfer ## 3. Alice adds key-value pair to data NFT. 'value' encrypted with a symmetric key 'symkey' ```python -#imports +# imports from base64 import b64encode from cryptography.fernet import Fernet from eth_account.messages import encode_defunct from hashlib import sha256 web3 = ocean.web3 -#Key-value pair +# Key-value pair profiledata_name = "fav_color" profiledata_val = "blue" -#Prep key for setter. Contract/ERC725 requires keccak256 hash +# Prep key for setter. Contract/ERC725 requires keccak256 hash profiledata_name_hash = web3.keccak(text=profiledata_name) -#Choose a symkey where: +# Choose a symkey where: # - sharing it unlocks only this field: make unique to this data nft & field # - only Alice can compute it: make it a function of her private key # - is hardware wallet friendly: uses Alice's digital signature not private key preimage = erc721_nft.address + profiledata_name msg = encode_defunct(text=sha256(preimage.encode('utf-8')).hexdigest()) signed_msg = web3.eth.account.sign_message(msg, private_key=alice_wallet.private_key) -symkey = b64encode(signed_msg.signature.hex().encode('ascii'))[:43] + b'=' #bytes +symkey = b64encode(signed_msg.signature.hex().encode('ascii'))[:43] + b'=' # bytes -#Prep value for setter +# Prep value for setter profiledata_val_encr_hex = Fernet(symkey).encrypt(profiledata_val.encode('utf-8')).hex() -#set +# set erc721_nft.set_new_data(profiledata_name_hash, profiledata_val_encr_hex, alice_wallet) ``` @@ -96,8 +96,8 @@ from eth_utils import decode_hex dapp_private_key = os.getenv('TEST_PRIVATE_KEY2') dapp_private_key_obj = keys.PrivateKey(decode_hex(dapp_private_key)) -dapp_public_key = str(dapp_private_key_obj.public_key) #str -dapp_address = dapp_private_key_obj.public_key.to_address() #str +dapp_public_key = str(dapp_private_key_obj.public_key) # str +dapp_address = dapp_private_key_obj.public_key.to_address() # str ``` ## 5. Alice encrypts symkey with Dapp's public key and shares to Dapp @@ -107,12 +107,12 @@ There are various ways for Alice to share the encrypted symkey to the Dapp (see ```python from ecies import encrypt as asymmetric_encrypt -symkey_name = (profiledata_name + ':for:' + dapp_address[:10]) #str +symkey_name = (profiledata_name + ':for:' + dapp_address[:10]) # str symkey_name_hash = web3.keccak(text=symkey_name) -symkey_val_encr = asymmetric_encrypt(dapp_public_key, symkey) #bytes +symkey_val_encr = asymmetric_encrypt(dapp_public_key, symkey) # bytes -symkey_val_encr_hex = symkey_val_encr.hex() #hex +symkey_val_encr_hex = symkey_val_encr.hex() # hex # arg types: key=bytes32, value=bytes, wallet=wallet erc721_nft.set_new_data(symkey_name_hash, symkey_val_encr_hex, alice_wallet) @@ -123,11 +123,11 @@ erc721_nft.set_new_data(symkey_name_hash, symkey_val_encr_hex, alice_wallet) ```python from ecies import decrypt as asymmetric_decrypt -#symkey_name_hash = +# symkey_name_hash = symkey_val_encr2 = erc721_nft.get_data(symkey_name_hash) symkey2 = asymmetric_decrypt(dapp_private_key, symkey_val_encr2) -#profiledata_name_hash = +# profiledata_name_hash = profiledata_val_encr_hex2 = erc721_nft.get_data(profiledata_name_hash) profiledata_val2_bytes = Fernet(symkey).decrypt(profiledata_val_encr_hex2) profiledata_val2 = profiledata_val2_bytes.decode('utf-8') diff --git a/READMEs/publish-flow.md b/READMEs/publish-flow.md index c9a10029f..2fddf61c7 100644 --- a/READMEs/publish-flow.md +++ b/READMEs/publish-flow.md @@ -77,7 +77,6 @@ asset = ocean.assets.create( did = asset.did # did contains the datatoken address print(f"did = '{did}'") - ``` Note on asset encryption: In order to encrypt the entire asset, when using a private market or metadata cache, use the encrypt keyword. diff --git a/READMEs/services.md b/READMEs/services.md index 5ab4b332e..45453d19e 100644 --- a/READMEs/services.md +++ b/READMEs/services.md @@ -47,7 +47,7 @@ In Python, import and configure the components / services: import os from ocean_lib.config import Config -#configure the components +# configure the components config = Config(os.getenv('OCEAN_CONFIG_FILE')) ``` diff --git a/ocean_lib/__init__.py b/ocean_lib/__init__.py index 0f780e2a4..7e4bdd874 100644 --- a/ocean_lib/__init__.py +++ b/ocean_lib/__init__.py @@ -7,5 +7,5 @@ __author__ = """OceanProtocol""" # fmt: off -__version__ = '1.0.0-alpha.3' +__version__ = '1.0.0-alpha.4' # fmt: on diff --git a/ocean_lib/models/erc721_nft.py b/ocean_lib/models/erc721_nft.py index 320f9a8f6..4fad116de 100644 --- a/ocean_lib/models/erc721_nft.py +++ b/ocean_lib/models/erc721_nft.py @@ -3,14 +3,14 @@ # SPDX-License-Identifier: Apache-2.0 # from enum import IntEnum -from typing import List, Union +from typing import List, Optional, Union from enforce_typing import enforce_types from ocean_lib.models.erc20_enterprise import ERC20Enterprise from ocean_lib.models.erc20_token import ERC20Token from ocean_lib.structures.abi_tuples import MetadataProof -from ocean_lib.web3_internal.constants import MAX_INT256 +from ocean_lib.web3_internal.constants import MAX_INT256, ZERO_ADDRESS from ocean_lib.web3_internal.contract_base import ContractBase from ocean_lib.web3_internal.wallet import Wallet @@ -279,31 +279,51 @@ def set_token_uri( @enforce_types def create_datatoken( self, - template_index: int, name: str, symbol: str, - minter: str, - fee_manager: str, - publish_market_order_fee_address: str, - publish_market_order_fee_token: str, - publish_market_order_fee_amount: int, - bytess: List[bytes], from_wallet: Wallet, + template_index: Optional[int] = 1, + minter: Optional[str] = None, + fee_manager: Optional[str] = None, + publish_market_order_fee_address: Optional[str] = None, + publish_market_order_fee_token: Optional[str] = None, + publish_market_order_fee_amount: Optional[int] = 0, + bytess: Optional[List[bytes]] = None, ) -> ERC20Token: initial_list = self.get_tokens_list() - self.create_erc20( - template_index=template_index, - name=name, - symbol=symbol, - minter=minter, - fee_manager=fee_manager, - publish_market_order_fee_address=publish_market_order_fee_address, - publish_market_order_fee_token=publish_market_order_fee_token, - publish_market_order_fee_amount=publish_market_order_fee_amount, - bytess=bytess, - from_wallet=from_wallet, - ) + local_values = locals().copy() + create_args = { + lv_index: local_values[lv_index] + for lv_index in [ + "template_index", + "name", + "symbol", + "from_wallet", + "minter", + "fee_manager", + "publish_market_order_fee_address", + "publish_market_order_fee_token", + "publish_market_order_fee_amount", + "bytess", + ] + } + + for default_attribute in [ + "minter", + "fee_manager", + "publish_market_order_fee_address", + ]: + if create_args[default_attribute] is None: + create_args[default_attribute] = from_wallet.address + + if publish_market_order_fee_token is None: + create_args["publish_market_order_fee_token"] = ZERO_ADDRESS + + if bytess is None: + create_args["bytess"] = [b""] + + self.create_erc20(**create_args) new_elements = [ item for item in self.get_tokens_list() if item not in initial_list diff --git a/setup.py b/setup.py index 5290a0158..4a3ae3c1d 100644 --- a/setup.py +++ b/setup.py @@ -102,7 +102,7 @@ url="https://github.com/oceanprotocol/ocean.py", # fmt: off # bumpversion.sh needs single-quotes - version='1.0.0-alpha.3', + version='1.0.0-alpha.4', # fmt: on zip_safe=False, ) diff --git a/tests/readmes/test_c2d_flow.py b/tests/readmes/test_c2d_flow.py index 91e20e076..13239c95e 100644 --- a/tests/readmes/test_c2d_flow.py +++ b/tests/readmes/test_c2d_flow.py @@ -18,7 +18,6 @@ from ocean_lib.ocean.ocean import Ocean from ocean_lib.services.service import Service from ocean_lib.structures.file_objects import UrlFile -from ocean_lib.web3_internal.constants import ZERO_ADDRESS from ocean_lib.web3_internal.wallet import Wallet @@ -84,15 +83,8 @@ def c2d_flow_readme( # Publish the datatoken DATA_datatoken = erc721_nft.create_datatoken( - template_index=1, - name="Datatoken 1", - symbol="DT1", - minter=alice_wallet.address, - fee_manager=alice_wallet.address, - publish_market_order_fee_address=ZERO_ADDRESS, - publish_market_order_fee_token=ocean.OCEAN_address, - publish_market_order_fee_amount=0, - bytess=[b""], + "Datatoken 1", + "DT1", from_wallet=alice_wallet, ) assert DATA_datatoken.address @@ -155,15 +147,8 @@ def c2d_flow_readme( # Publish the datatoken ALGO_datatoken = ALGO_nft_token.create_datatoken( - template_index=1, - name="Datatoken 1", - symbol="DT1", - minter=alice_wallet.address, - fee_manager=alice_wallet.address, - publish_market_order_fee_address=ZERO_ADDRESS, - publish_market_order_fee_token=ocean.OCEAN_address, - publish_market_order_fee_amount=0, - bytess=[b""], + "Datatoken 1", + "DT1", from_wallet=alice_wallet, ) assert ALGO_datatoken.address diff --git a/tests/stress/compute_flow_with_threads.py b/tests/stress/compute_flow_with_threads.py index 53a6c9b72..687361e64 100644 --- a/tests/stress/compute_flow_with_threads.py +++ b/tests/stress/compute_flow_with_threads.py @@ -16,7 +16,6 @@ from ocean_lib.ocean.ocean import Ocean from ocean_lib.services.service import Service from ocean_lib.structures.file_objects import UrlFile -from ocean_lib.web3_internal.constants import ZERO_ADDRESS from tests.resources.ddo_helpers import get_first_service_by_type from tests.resources.helper_functions import generate_wallet @@ -38,15 +37,8 @@ def c2d_flow_readme( # Publish the datatoken DATA_datatoken = erc721_nft.create_datatoken( - template_index=1, - name="Datatoken 1", - symbol="DT1", - minter=publisher_wallet.address, - fee_manager=publisher_wallet.address, - publish_market_order_fee_address=ZERO_ADDRESS, - publish_market_order_fee_token=ocean.OCEAN_address, - publish_market_order_fee_amount=0, - bytess=[b""], + "Datatoken 1", + "DT1", from_wallet=publisher_wallet, ) assert DATA_datatoken.address @@ -107,15 +99,8 @@ def c2d_flow_readme( # Publish the datatoken ALGO_datatoken = ALGO_nft_token.create_datatoken( - template_index=1, - name="Datatoken 1", - symbol="DT1", - minter=publisher_wallet.address, - fee_manager=publisher_wallet.address, - publish_market_order_fee_address=ZERO_ADDRESS, - publish_market_order_fee_token=ocean.OCEAN_address, - publish_market_order_fee_amount=0, - bytess=[b""], + "Datatoken 1", + "DT1", from_wallet=publisher_wallet, ) assert ALGO_datatoken.address