Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CVAT] bump: human-protocol-sdk upgrade to 4.0.3 #3122

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
829 changes: 294 additions & 535 deletions packages/examples/cvat/exchange-oracle/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/examples/cvat/exchange-oracle/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ datumaro = {git = "https://github.com/cvat-ai/datumaro.git", rev = "ff83c00c2c1b
boto3 = "^1.28.33"
google-cloud-storage = "^2.14.0"
pyinstrument = "^4.6.2"
human-protocol-sdk = "^4.0.3b0"
hexbytes = ">=1.2.0" # required for to_0x_hex() function
pydantic = ">=2.6.1,<2.7.0"
fastapi-pagination = "^0.12.17"
Expand All @@ -36,6 +35,7 @@ starlette = ">=0.40.0" # avoid the vulnerability with multipart/form-data
cryptography = "<44.0.0" # human-protocol-sdk -> pgpy dep requires cryptography < 45
aiocache = {extras = ["msgpack", "redis"], version = "^0.12.3"} # convenient api for redis (async)
cachelib = "^0.13.0" # convenient api for redis (sync)
human-protocol-sdk = "^4.0.3"


[tool.poetry.group.dev.dependencies]
Expand Down
23 changes: 13 additions & 10 deletions packages/examples/cvat/exchange-oracle/src/chain/web3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from eth_account.messages import encode_defunct
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.rpc import HTTPProvider

from src.core.config import Config
Expand All @@ -15,27 +15,30 @@ def get_web3(chain_id: Networks):
case Config.polygon_mainnet.chain_id:
w3 = Web3(HTTPProvider(Config.polygon_mainnet.rpc_api))
gas_payer = w3.eth.account.from_key(Config.polygon_mainnet.private_key)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(Config.polygon_mainnet.private_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = gas_payer.address
return w3
case Config.polygon_amoy.chain_id:
w3 = Web3(HTTPProvider(Config.polygon_amoy.rpc_api))
gas_payer = w3.eth.account.from_key(Config.polygon_amoy.private_key)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(Config.polygon_amoy.private_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = gas_payer.address
return w3
case Config.localhost.chain_id:
w3 = Web3(HTTPProvider(Config.localhost.rpc_api))
gas_payer = w3.eth.account.from_key(Config.localhost.private_key)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(Config.localhost.private_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = gas_payer.address
return w3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from human_protocol_sdk.constants import ChainId
from web3 import HTTPProvider, Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder

from src.chain.web3 import get_web3, recover_signer, sign_message, validate_address
from src.core.config import LocalhostConfig
Expand All @@ -19,9 +19,10 @@ def setUp(self):

# Set default gas payer
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
self.w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(self.gas_payer),
"construct_sign_and_send_raw_middleware",
self.w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
self.w3.eth.default_account = self.gas_payer.address

Expand Down
829 changes: 294 additions & 535 deletions packages/examples/cvat/recording-oracle/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/examples/cvat/recording-oracle/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ numpy = "^1.25.2"
boto3 = "^1.28.40"
google-cloud-storage = "^2.14.0"
datumaro = {git = "https://github.com/cvat-ai/datumaro.git", rev = "ff83c00c2c1bc4b8fdfcc55067fcab0a9b5b6b11"}
human-protocol-sdk = "^4.0.3b0"
hexbytes = ">=1.2.0" # required for to_0x_hex() function
starlette = ">=0.40.0" # avoid the vulnerability with multipart/form-data
cvat-sdk = "2.25.0"
cryptography = "<44.0.0" # human-protocol-sdk -> pgpy dep requires cryptography < 45
human-protocol-sdk = "^4.0.3"

[tool.poetry.group.dev.dependencies]
hypothesis = "^6.82.6"
Expand Down
25 changes: 14 additions & 11 deletions packages/examples/cvat/recording-oracle/src/chain/web3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from eth_account.messages import encode_defunct
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.rpc import HTTPProvider

from src.core.config import Config
Expand All @@ -15,27 +15,30 @@ def get_web3(chain_id: Networks):
case Config.polygon_mainnet.chain_id:
w3 = Web3(HTTPProvider(Config.polygon_mainnet.rpc_api))
gas_payer = w3.eth.account.from_key(Config.polygon_mainnet.private_key)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(Config.polygon_mainnet.private_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = gas_payer.address
return w3
case Config.polygon_amoy.chain_id:
w3 = Web3(HTTPProvider(Config.polygon_amoy.rpc_api))
gas_payer = w3.eth.account.from_key(Config.polygon_amoy.private_key)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(Config.polygon_amoy.private_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = gas_payer.address
return w3
case Config.localhost.chain_id:
w3 = Web3(HTTPProvider(Config.localhost.rpc_api))
gas_payer = w3.eth.account.from_key(Config.localhost.private_key)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(Config.localhost.private_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = gas_payer.address
return w3
Expand All @@ -47,7 +50,7 @@ def serialize_message(message: Any) -> str:
return json.dumps(message, separators=(",", ":"))


def sign_message(chain_id: Networks, message) -> str:
def sign_message(chain_id: Networks, message) -> tuple:
w3 = get_web3(chain_id)
private_key = ""
match chain_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from human_protocol_sdk.encryption import EncryptionUtils
from human_protocol_sdk.escrow import EscrowClientError
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.rpc import HTTPProvider

from src.chain.escrow import (
Expand Down Expand Up @@ -42,9 +42,10 @@ def setUp(self):

# Set default gas payer
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
self.w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(self.gas_payer),
"construct_sign_and_send_raw_middleware",
self.w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
self.w3.eth.default_account = self.gas_payer.address
self.network_config = Config.localhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from human_protocol_sdk.constants import ChainId
from web3 import HTTPProvider, Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder

from src.chain.web3 import get_web3, recover_signer, sign_message, validate_address
from src.core.config import LocalhostConfig
Expand All @@ -18,9 +18,10 @@ def setUp(self):

# Set default gas payer
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
self.w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(self.gas_payer),
"construct_sign_and_send_raw_middleware",
self.w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
self.w3.eth.default_account = self.gas_payer.address

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from sqlalchemy.sql import select
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.rpc import HTTPProvider

from src.core.storage import compose_data_bucket_prefix, compose_results_bucket_prefix
Expand All @@ -32,9 +32,10 @@ def setUp(self):
self.w3 = Web3(HTTPProvider())

self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
self.w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(self.gas_payer),
"construct_sign_and_send_raw_middleware",
self.w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
self.w3.eth.default_account = self.gas_payer.address

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sqlalchemy.sql import select
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.rpc import HTTPProvider

from src.core.types import (
Expand All @@ -29,9 +29,10 @@ def setUp(self):
self.w3 = Web3(HTTPProvider())

self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
self.w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(self.gas_payer),
"construct_sign_and_send_raw_middleware",
self.w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
self.w3.eth.default_account = self.gas_payer.address

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from human_protocol_sdk.kvstore import KVStoreClient
from web3 import HTTPProvider, Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder

from tests.utils.constants import REPUTATION_ORACLE_PRIV

Expand All @@ -12,9 +12,10 @@ def store_kvstore_value(key: str, value: str):

# Set default gas payer
reputation_oracle = w3.eth.account.from_key(REPUTATION_ORACLE_PRIV)
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(reputation_oracle),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(REPUTATION_ORACLE_PRIV),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
w3.eth.default_account = reputation_oracle.address
kvstore_client = KVStoreClient(w3)
Expand Down
Loading