Skip to content

Commit

Permalink
Add chainId parameter to encryption.
Browse files Browse the repository at this point in the history
  • Loading branch information
calina-c committed Nov 17, 2022
1 parent d89ffd1 commit 21a18cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
17 changes: 15 additions & 2 deletions ocean_provider/routes/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def encrypt():
consumes:
- application/octet-stream
parameters:
- in: chainId
name: chainId
required: true
description: chainId to be used for encryption, given as query parameter
- in: body
name: body
required: true
Expand All @@ -54,14 +58,23 @@ def encrypt():
logger,
)

chain_id = request.args.get("chainId")
if not chain_id:
return error_response(
"Missing chainId query parameter.",
400,
logger,
)

data = request.get_data()
logger.debug(f"encrypt called. arguments = {data}")

return _encrypt(data)
return _encrypt(data, chain_id)


def _encrypt(data: bytes) -> Response:
def _encrypt(data: bytes, chain_id) -> Response:
try:
provider_wallet = get_provider_wallet(chain_id)
encrypted_data = do_encrypt(data, provider_wallet)
logger.info(f"encrypted_data = {encrypted_data}")
except Exception:
Expand Down
31 changes: 17 additions & 14 deletions ocean_provider/utils/compute_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from ocean_provider.requests_session import get_requests_session
from ocean_provider.utils.address import get_provider_fee_token
from ocean_provider.utils.basics import get_config, get_web3

from ocean_provider.utils.basics import get_config, get_configured_chains

requests_session = get_requests_session()

Expand All @@ -19,18 +18,22 @@ def get_c2d_environments() -> List:
return []

standard_headers = {"Content-type": "application/json", "Connection": "close"}
web3 = get_web3()
params = {"chainId": web3.chain_id}
response = requests_session.get(
get_compute_environments_endpoint(), headers=standard_headers, params=params
)

# loop envs and add provider token from config
envs = response.json()
for env in envs:
env["feeToken"] = get_provider_fee_token(web3.chain_id)

return envs
all_environments = []

for chain in get_configured_chains():
params = {"chainId": chain}
response = requests_session.get(
get_compute_environments_endpoint(), headers=standard_headers, params=params
)

# add provider token from config
envs = response.json()
for env in envs:
env["feeToken"] = get_provider_fee_token(chain)

all_environments.extend(envs)

return all_environments


def check_environment_exists(envs, env_id):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_encrypt_and_decrypt_with_only_encryption(

# Encrypt DDO
encrypt_response = client.post(
BaseURLs.SERVICES_URL + "/encrypt",
BaseURLs.SERVICES_URL + "/encrypt?chainId=8996",
data=ddo_string,
content_type="application/octet-stream",
)
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_encrypt_and_decrypt_with_compression_and_encryption(

# Encrypt DDO
encrypt_response = client.post(
BaseURLs.SERVICES_URL + "/encrypt",
BaseURLs.SERVICES_URL + "/encrypt?chainId=8996",
data=ddo_compressed,
content_type="application/octet-stream",
)
Expand Down

0 comments on commit 21a18cd

Please sign in to comment.