Skip to content

Commit 83af173

Browse files
authored
Simplify create_datatoken function to take in some defaults. (#842)
* Simplify create_datatoken function to take in some defaults. * Adds flake8 formatting to readmes. * Make template_index also default, simplify call even more. * Adjust names and symbols in readme. * Bump version: 1.0.0-alpha.3 → 1.0.0-alpha.4
1 parent 3468a81 commit 83af173

17 files changed

Lines changed: 93 additions & 153 deletions

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.0-alpha.3
2+
current_version = 1.0.0-alpha.4
33
commit = True
44
tag = True
55

READMEs/c2d-flow-more-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ALGO_metadata = {
5959
"container": {
6060
"entrypoint": "python $ALGO",
6161
"image": "oceanprotocol/algo_dockers",
62-
"tag": "python-branin", # This image provides all the dependencies of the grayscale.py algorithm
62+
"tag": "python-branin", # This image provides all the dependencies of the grayscale.py algorithm
6363
"checksum": "44e10daa6637893f4276bb8d7301eb35306ece50f61ca34dcab550",
6464
},
6565
}

READMEs/c2d-flow.md

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,8 @@ Please refer to [data-nfts-and-datatokens-flow](data-nfts-and-datatokens-flow.md
5656
In the same python console:
5757

5858
```python
59-
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
60-
6159
# Publish the datatoken
62-
DATA_datatoken = erc721_nft.create_datatoken(
63-
template_index=1,
64-
name="Datatoken 1",
65-
symbol="DT1",
66-
minter=alice_wallet.address,
67-
fee_manager=alice_wallet.address,
68-
publish_market_order_fee_address=ZERO_ADDRESS,
69-
publish_market_order_fee_token=ocean.OCEAN_address,
70-
publish_market_order_fee_amount=0,
71-
bytess=[b""],
72-
from_wallet=alice_wallet,
73-
)
60+
DATA_datatoken = erc721_nft.create_datatoken("DATA 1", "D1", from_wallet=alice_wallet)
7461
print(f"DATA_datatoken address = '{DATA_datatoken.address}'")
7562

7663
# Specify metadata and services, using the Branin test dataset
@@ -137,18 +124,7 @@ ALGO_nft_token = ocean.create_erc721_nft("NFTToken1", "NFT1", alice_wallet)
137124
print(f"ALGO_nft_token address = '{ALGO_nft_token.address}'")
138125

139126
# Publish the datatoken
140-
ALGO_datatoken = ALGO_nft_token.create_datatoken(
141-
template_index=1,
142-
name="Datatoken 1",
143-
symbol="DT1",
144-
minter=alice_wallet.address,
145-
fee_manager=alice_wallet.address,
146-
publish_market_order_fee_address=ZERO_ADDRESS,
147-
publish_market_order_fee_token=ocean.OCEAN_address,
148-
publish_market_order_fee_amount=0,
149-
bytess=[b""],
150-
from_wallet=alice_wallet,
151-
)
127+
ALGO_datatoken = ALGO_nft_token.create_datatoken("ALGO 1", "A1", from_wallet=alice_wallet)
152128
print(f"ALGO_datatoken address = '{ALGO_datatoken.address}'")
153129

154130
# Specify metadata and services, using the Branin test dataset
@@ -315,14 +291,14 @@ X0_vec = numpy.linspace(-5., 10., 15)
315291
X1_vec = numpy.linspace(0., 15., 15)
316292
X0, X1 = numpy.meshgrid(X0_vec, X1_vec)
317293
b, c, t = 0.12918450914398066, 1.5915494309189535, 0.039788735772973836
318-
u = X1 - b*X0**2 + c*X0 - 6
319-
r = 10.*(1. - t) * numpy.cos(X0) + 10
320-
Z = u**2 + r
294+
u = X1 - b * X0 ** 2 + c * X0 - 6
295+
r = 10. * (1. - t) * numpy.cos(X0) + 10
296+
Z = u ** 2 + r
321297

322298
fig, ax = pyplot.subplots(subplot_kw={"projection": "3d"})
323299
ax.scatter(X0, X1, model, c="r", label="model")
324300
pyplot.title("Data + model")
325-
pyplot.show() # or pyplot.savefig("test.png") to save the plot as a .png file instead
301+
pyplot.show() # or pyplot.savefig("test.png") to save the plot as a .png file instead
326302
```
327303

328304
You should see something like this:
@@ -336,7 +312,7 @@ For examples using different datasets and algorithms, please see [c2d-flow-more-
336312
In the "publish algorithm" step, to replace the sample algorithm with another one:
337313

338314
- Use one of the standard [Ocean algo_dockers images](https://github.com/oceanprotocol/algo_dockers) or publish a custom docker image.
339-
- Use the image name and tag in the `container` part of the algorithm metadata.
315+
- Use the image name and tag in the `container` part of the algorithm metadata.
340316
- The image must have basic support for installing dependencies. E.g. "pip" for the case of Python. You can use other languages, of course.
341317
- More info: https://docs.oceanprotocol.com/tutorials/compute-to-data-algorithms/)
342318

READMEs/consume-flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ erc20_token.mint(
7070

7171
# Bob points to the service object
7272
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
73-
fee_receiver = ZERO_ADDRESS # could also be market address
73+
fee_receiver = ZERO_ADDRESS # could also be market address
7474
service = asset.services[0]
7575

7676
# Bob sends his datatoken to the service
@@ -92,7 +92,7 @@ file_path = ocean.assets.download_asset(
9292
destination='./',
9393
order_tx_id=order_tx_id
9494
)
95-
print(f"file_path = '{file_path}'") #e.g. datafile.0xAf07...
95+
print(f"file_path = '{file_path}'") # e.g. datafile.0xAf07...
9696
```
9797

9898
In console:

READMEs/data-nfts-and-datatokens-flow.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,8 @@ Congrats, you've created your first Ocean data NFT!
100100
In the same python console:
101101
```python
102102
# Create ERC20 token related to the above NFT.
103-
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
104-
105-
erc20_token = erc721_nft.create_datatoken(
106-
template_index=1, # default value
107-
name="ERC20DT1", # name for ERC20 token
108-
symbol="ERC20DT1Symbol", # symbol for ERC20 token
109-
minter=alice_wallet.address, # minter address
110-
fee_manager=alice_wallet.address, # fee manager for this ERC20 token
111-
publish_market_order_fee_address=alice_wallet.address, # publishing Market Address
112-
publish_market_order_fee_token=ZERO_ADDRESS, # publishing Market Fee Token
113-
publish_market_order_fee_amount=0,
114-
bytess=[b""],
115-
from_wallet=alice_wallet
116-
)
103+
104+
erc20_token = erc721_nft.create_datatoken("Datatoken 1", "DT1", from_wallet=alice_wallet)
117105
print(f"Created ERC20 datatoken. Its address is {erc20_token.address}")
118106
```
119107

@@ -125,20 +113,20 @@ You can combine creating a data NFT and datatoken into a single call: `ocean.cre
125113

126114
To learn more about some of the objects you created, here are some examples.
127115
```python
128-
#config
116+
# config
129117
print(f"config.network_url = '{config.network_url}'")
130118
print(f"config.block_confirmations = {config.block_confirmations.value}")
131119
print(f"config.metadata_cache_uri = '{config.metadata_cache_uri}'")
132120
print(f"config.provider_url = '{config.provider_url}'")
133121

134-
#wallet
122+
# wallet
135123
print(f"alice_wallet.address = '{alice_wallet.address}'")
136124

137-
#data NFT
125+
# data NFT
138126
print(f"data NFT token name: {erc721_nft.token_name()}")
139127
print(f"data NFT token symbol: {erc721_nft.symbol()}")
140128

141-
#datatoken
129+
# datatoken
142130
print(f"datatoken name: {erc20_token.token_name()}")
143131
print(f"datatoken symbol: {erc20_token.symbol()}")
144132
```

READMEs/erc20-enterprise.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ In the Python console:
5252
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
5353

5454
erc20_enterprise_token = erc721_nft.create_datatoken(
55-
template_index=2, # this is the value for ERC20 Enterprise token
5655
name="ERC20DT1", # name for ERC20 token
5756
symbol="ERC20DT1Symbol", # symbol for ERC20 token
58-
minter=alice_wallet.address, # minter address
59-
fee_manager=alice_wallet.address, # fee manager for this ERC20 token
60-
publish_market_order_fee_address=alice_wallet.address, # publishing Market Address
61-
publish_market_order_fee_token=ZERO_ADDRESS, # publishing Market Fee Token
62-
publish_market_order_fee_amount=0,
63-
bytess=[b""],
57+
template_index=2, # this is the value for ERC20 Enterprise token
6458
from_wallet=alice_wallet,
6559
)
6660
print(f"ERC20 Enterprise address: {erc20_enterprise_token.address}")
@@ -144,15 +138,9 @@ In the Python console:
144138
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
145139

146140
erc20_enterprise_token = erc721_nft.create_datatoken(
147-
template_index=2, # this is the value for ERC20 Enterprise token
148141
name="ERC20DT1", # name for ERC20 token
149142
symbol="ERC20DT1Symbol", # symbol for ERC20 token
150-
minter=alice_wallet.address, # minter address
151-
fee_manager=alice_wallet.address, # fee manager for this ERC20 token
152-
publish_market_order_fee_address=alice_wallet.address, # publishing Market Address
153-
publish_market_order_fee_token=ZERO_ADDRESS, # publishing Market Fee Token
154-
publish_market_order_fee_amount=0,
155-
bytess=[b""],
143+
template_index=2, # this is the value for ERC20 Enterprise token
156144
from_wallet=alice_wallet,
157145
)
158146
print(f"ERC20 Enterprise address: {erc20_enterprise_token.address}")

READMEs/fixed-rate-exchange-flow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Please refer to [data-nfts-and-datatokens-flow](data-nfts-and-datatokens-flow.md
4646

4747
In the same python console:
4848
```python
49-
#Mint the datatokens
49+
# Mint the datatokens
5050
erc20_token.mint(alice_wallet.address, ocean.to_wei(100), alice_wallet)
5151
```
5252

READMEs/key-value-flow.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ From [data-nfts-and-datatokens-flow](data-nfts-and-datatokens-flow.md), do:
3636
## 3. Add key-value pair to data NFT
3737

3838
```python
39-
#Key-value pair
39+
# Key-value pair
4040
key = "fav_color"
4141
value = "blue"
4242

43-
#prep key for setter
44-
key_hash = ocean.web3.keccak(text=key) #Contract/ERC725 requires keccak256 hash
43+
# prep key for setter
44+
key_hash = ocean.web3.keccak(text=key) # Contract/ERC725 requires keccak256 hash
4545

46-
#prep value for setter
47-
value_hex = value.encode('utf-8').hex() #set_new_data() needs hex
46+
# prep value for setter
47+
value_hex = value.encode('utf-8').hex() # set_new_data() needs hex
4848

49-
#set
49+
# set
5050
erc721_nft.set_new_data(key_hash, value_hex, alice_wallet)
5151
```
5252

READMEs/marketplace-flow.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ bpool = ocean.create_pool(
8787
from_wallet=alice_wallet
8888
)
8989
print(f"BPool address: {bpool.address}")
90-
9190
```
9291

9392
## 4. Marketplace displays asset for sale
@@ -142,7 +141,7 @@ assert erc20_token.balanceOf(bob_wallet.address) >= ocean.to_wei(
142141

143142
# Bob points to the service object
144143
from ocean_lib.web3_internal.constants import ZERO_ADDRESS
145-
fee_receiver = ZERO_ADDRESS # could also be market address
144+
fee_receiver = ZERO_ADDRESS # could also be market address
146145
asset = ocean.assets.resolve(did)
147146
service = asset.services[0]
148147

READMEs/profile-nfts-flow.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,33 @@ erc721_nft = ocean.create_erc721_nft('NFTToken1', 'NFT1', alice_wallet, transfer
5656
## 3. Alice adds key-value pair to data NFT. 'value' encrypted with a symmetric key 'symkey'
5757

5858
```python
59-
#imports
59+
# imports
6060
from base64 import b64encode
6161
from cryptography.fernet import Fernet
6262
from eth_account.messages import encode_defunct
6363
from hashlib import sha256
6464
web3 = ocean.web3
6565

66-
#Key-value pair
66+
# Key-value pair
6767
profiledata_name = "fav_color"
6868
profiledata_val = "blue"
6969

70-
#Prep key for setter. Contract/ERC725 requires keccak256 hash
70+
# Prep key for setter. Contract/ERC725 requires keccak256 hash
7171
profiledata_name_hash = web3.keccak(text=profiledata_name)
7272

73-
#Choose a symkey where:
73+
# Choose a symkey where:
7474
# - sharing it unlocks only this field: make unique to this data nft & field
7575
# - only Alice can compute it: make it a function of her private key
7676
# - is hardware wallet friendly: uses Alice's digital signature not private key
7777
preimage = erc721_nft.address + profiledata_name
7878
msg = encode_defunct(text=sha256(preimage.encode('utf-8')).hexdigest())
7979
signed_msg = web3.eth.account.sign_message(msg, private_key=alice_wallet.private_key)
80-
symkey = b64encode(signed_msg.signature.hex().encode('ascii'))[:43] + b'=' #bytes
80+
symkey = b64encode(signed_msg.signature.hex().encode('ascii'))[:43] + b'=' # bytes
8181

82-
#Prep value for setter
82+
# Prep value for setter
8383
profiledata_val_encr_hex = Fernet(symkey).encrypt(profiledata_val.encode('utf-8')).hex()
8484

85-
#set
85+
# set
8686
erc721_nft.set_new_data(profiledata_name_hash, profiledata_val_encr_hex, alice_wallet)
8787
```
8888

@@ -96,8 +96,8 @@ from eth_utils import decode_hex
9696

9797
dapp_private_key = os.getenv('TEST_PRIVATE_KEY2')
9898
dapp_private_key_obj = keys.PrivateKey(decode_hex(dapp_private_key))
99-
dapp_public_key = str(dapp_private_key_obj.public_key) #str
100-
dapp_address = dapp_private_key_obj.public_key.to_address() #str
99+
dapp_public_key = str(dapp_private_key_obj.public_key) # str
100+
dapp_address = dapp_private_key_obj.public_key.to_address() # str
101101
```
102102

103103
## 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
107107
```python
108108
from ecies import encrypt as asymmetric_encrypt
109109

110-
symkey_name = (profiledata_name + ':for:' + dapp_address[:10]) #str
110+
symkey_name = (profiledata_name + ':for:' + dapp_address[:10]) # str
111111
symkey_name_hash = web3.keccak(text=symkey_name)
112112

113-
symkey_val_encr = asymmetric_encrypt(dapp_public_key, symkey) #bytes
113+
symkey_val_encr = asymmetric_encrypt(dapp_public_key, symkey) # bytes
114114

115-
symkey_val_encr_hex = symkey_val_encr.hex() #hex
115+
symkey_val_encr_hex = symkey_val_encr.hex() # hex
116116

117117
# arg types: key=bytes32, value=bytes, wallet=wallet
118118
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)
123123
```python
124124
from ecies import decrypt as asymmetric_decrypt
125125

126-
#symkey_name_hash = <Dapp would set like above>
126+
# symkey_name_hash = <Dapp would set like above>
127127
symkey_val_encr2 = erc721_nft.get_data(symkey_name_hash)
128128
symkey2 = asymmetric_decrypt(dapp_private_key, symkey_val_encr2)
129129

130-
#profiledata_name_hash = <Dapp would set like above>
130+
# profiledata_name_hash = <Dapp would set like above>
131131
profiledata_val_encr_hex2 = erc721_nft.get_data(profiledata_name_hash)
132132
profiledata_val2_bytes = Fernet(symkey).decrypt(profiledata_val_encr_hex2)
133133
profiledata_val2 = profiledata_val2_bytes.decode('utf-8')

0 commit comments

Comments
 (0)