Skip to content

Commit

Permalink
Create config function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariacarmina committed Oct 22, 2024
1 parent 03fddaf commit d312846
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
11 changes: 4 additions & 7 deletions READMEs/ocean-nodes-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,12 @@ In the Python console:
# Create Ocean instance
import os
from ocean_lib.ocean.ocean import Ocean
from ocean_lib.example_config import get_web3
from ocean_lib.example_config import get_ocean_node_config

network_url = "http://localhost:8545"
# Follow parameters.md guide for config parameters
config = {
'METADATA_CACHE_URI': "http://127.0.0.1:8000", # Assuming that HTTP_API_PORT from Ocean Nodes is set to default 8000 as it is in quickstart https://github.com/oceanprotocol/ocean-node/blob/main/scripts/ocean-node-quickstart.sh#L80
'PROVIDER_URL' : "http://127.0.0.1:8000",
"web3_instance": get_web3(network_url)
}
node_uri = "http://127.0.0.1:8000"

config = get_ocean_node_config(network_url, node_uri)
ocean = Ocean(config)

# Create OCEAN object. Barge auto-created OCEAN, and ocean instance knows
Expand Down
13 changes: 5 additions & 8 deletions READMEs/setup-remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,18 @@ Config creation in Python console when using Ocean Nodes:
# Create Ocean instance
import os
from ocean_lib.ocean.ocean import Ocean
from ocean_lib.example_config import get_web3
from ocean_lib.example_config import get_ocean_node_config

network_url = os.getenv("MUMBAI_RPC_URL")
# Follow parameters.md guide for config parameters
config = {
'METADATA_CACHE_URI': "http://127.0.0.1:8000", # Assuming that HTTP_API_PORT from Ocean Nodes is set to default 8000 as it is in quickstart https://github.com/oceanprotocol/ocean-node/blob/main/scripts/ocean-node-quickstart.sh#L80
'PROVIDER_URL' : "http://127.0.0.1:8000", # If Ocean Node is hosted in another environment, provide the public DNS or IP
"web3_instance": get_web3(network_url)
}
node_uri = "http://127.0.0.1:8000" # If Ocean Node is hosted in another environment, provide the public DNS or IP

config = get_ocean_node_config(network_url, node_uri)
ocean = Ocean(config)

# Continue with OCEAN token creation and wallets setup.
```

In the Python console:
Config creation in Python console when using as-is Aquarius & Provider:
```python
# Create Ocean instance
import os
Expand Down
36 changes: 36 additions & 0 deletions ocean_lib/example_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@
8996: "development",
}

def get_ocean_node_config(network_url: Optional[str] = None, node_uri: Optional[str] = None) -> dict:
if not network_url:
network_url = "http://127.0.0.1:8545"

if not node_uri:
node_uri = "http://127.0.0.1:8000" # Assuming that HTTP_API_PORT from Ocean Nodes is set to default 8000 as it is in quickstart https://github.com/oceanprotocol/ocean-node/blob/main/scripts/ocean-node-quickstart.sh#L80

config_dict = copy.deepcopy(config_defaults)
config_dict["web3_instance"] = get_web3(network_url)
config_dict["CHAIN_ID"] = config_dict["web3_instance"].eth.chain_id
config_dict["METADATA_CACHE_URI"] = node_uri
config_dict["PROVIDER_URL"] = node_uri
chain_id = config_dict["CHAIN_ID"]

if os.getenv("ADDRESS_FILE"):
base_file = os.getenv("ADDRESS_FILE")
address_file = os.path.expanduser(base_file)
elif chain_id == 8996:
# this is auto-created when barge is run
base_file = "~/.ocean/ocean-contracts/artifacts/address.json"
address_file = os.path.expanduser(base_file)
else:
# `contract_addresses` comes from "ocean-contracts" pypi library,
# a JSON blob holding addresses of contract deployments, per network
address_file = (
Path(os.path.join(addresses.__file__, "..", "address.json"))
.expanduser()
.resolve()
)
assert os.path.exists(address_file), f"Could not find address_file={address_file}."

config_dict["ADDRESS_FILE"] = address_file

return config_dict



def get_config_dict(network_url: Optional[str] = None) -> dict:
"""Return config dict containing default values for a given network.
Expand Down

0 comments on commit d312846

Please sign in to comment.