Skip to content

Commit 798cfd3

Browse files
authored
[CVAT] bump: human-protocol-sdk upgrade to 4.0.3 (#3122)
* bump: `human-protocol-sdk` upgrade to 4.0.3 * lint: applied linter * fix: linter errors
1 parent 8b13e58 commit 798cfd3

File tree

12 files changed

+647
-1117
lines changed

12 files changed

+647
-1117
lines changed

packages/examples/cvat/exchange-oracle/poetry.lock

Lines changed: 294 additions & 535 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/examples/cvat/exchange-oracle/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ datumaro = {git = "https://github.com/cvat-ai/datumaro.git", rev = "ff83c00c2c1b
2424
boto3 = "^1.28.33"
2525
google-cloud-storage = "^2.14.0"
2626
pyinstrument = "^4.6.2"
27-
human-protocol-sdk = "^4.0.3b0"
2827
hexbytes = ">=1.2.0" # required for to_0x_hex() function
2928
pydantic = ">=2.6.1,<2.7.0"
3029
fastapi-pagination = "^0.12.17"
@@ -36,6 +35,7 @@ starlette = ">=0.40.0" # avoid the vulnerability with multipart/form-data
3635
cryptography = "<44.0.0" # human-protocol-sdk -> pgpy dep requires cryptography < 45
3736
aiocache = {extras = ["msgpack", "redis"], version = "^0.12.3"} # convenient api for redis (async)
3837
cachelib = "^0.13.0" # convenient api for redis (sync)
38+
human-protocol-sdk = "^4.0.3"
3939

4040

4141
[tool.poetry.group.dev.dependencies]

packages/examples/cvat/exchange-oracle/src/chain/web3.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from eth_account.messages import encode_defunct
55
from web3 import Web3
6-
from web3.middleware import construct_sign_and_send_raw_middleware
6+
from web3.middleware import SignAndSendRawMiddlewareBuilder
77
from web3.providers.rpc import HTTPProvider
88

99
from src.core.config import Config
@@ -15,27 +15,30 @@ def get_web3(chain_id: Networks):
1515
case Config.polygon_mainnet.chain_id:
1616
w3 = Web3(HTTPProvider(Config.polygon_mainnet.rpc_api))
1717
gas_payer = w3.eth.account.from_key(Config.polygon_mainnet.private_key)
18-
w3.middleware_onion.add(
19-
construct_sign_and_send_raw_middleware(gas_payer),
20-
"construct_sign_and_send_raw_middleware",
18+
w3.middleware_onion.inject(
19+
SignAndSendRawMiddlewareBuilder.build(Config.polygon_mainnet.private_key),
20+
"SignAndSendRawMiddlewareBuilder",
21+
layer=0,
2122
)
2223
w3.eth.default_account = gas_payer.address
2324
return w3
2425
case Config.polygon_amoy.chain_id:
2526
w3 = Web3(HTTPProvider(Config.polygon_amoy.rpc_api))
2627
gas_payer = w3.eth.account.from_key(Config.polygon_amoy.private_key)
27-
w3.middleware_onion.add(
28-
construct_sign_and_send_raw_middleware(gas_payer),
29-
"construct_sign_and_send_raw_middleware",
28+
w3.middleware_onion.inject(
29+
SignAndSendRawMiddlewareBuilder.build(Config.polygon_amoy.private_key),
30+
"SignAndSendRawMiddlewareBuilder",
31+
layer=0,
3032
)
3133
w3.eth.default_account = gas_payer.address
3234
return w3
3335
case Config.localhost.chain_id:
3436
w3 = Web3(HTTPProvider(Config.localhost.rpc_api))
3537
gas_payer = w3.eth.account.from_key(Config.localhost.private_key)
36-
w3.middleware_onion.add(
37-
construct_sign_and_send_raw_middleware(gas_payer),
38-
"construct_sign_and_send_raw_middleware",
38+
w3.middleware_onion.inject(
39+
SignAndSendRawMiddlewareBuilder.build(Config.localhost.private_key),
40+
"SignAndSendRawMiddlewareBuilder",
41+
layer=0,
3942
)
4043
w3.eth.default_account = gas_payer.address
4144
return w3

packages/examples/cvat/exchange-oracle/tests/integration/chain/test_web3.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from human_protocol_sdk.constants import ChainId
77
from web3 import HTTPProvider, Web3
8-
from web3.middleware import construct_sign_and_send_raw_middleware
8+
from web3.middleware import SignAndSendRawMiddlewareBuilder
99

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

2020
# Set default gas payer
2121
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
22-
self.w3.middleware_onion.add(
23-
construct_sign_and_send_raw_middleware(self.gas_payer),
24-
"construct_sign_and_send_raw_middleware",
22+
self.w3.middleware_onion.inject(
23+
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
24+
"SignAndSendRawMiddlewareBuilder",
25+
layer=0,
2526
)
2627
self.w3.eth.default_account = self.gas_payer.address
2728

packages/examples/cvat/recording-oracle/poetry.lock

Lines changed: 294 additions & 535 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/examples/cvat/recording-oracle/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ numpy = "^1.25.2"
2222
boto3 = "^1.28.40"
2323
google-cloud-storage = "^2.14.0"
2424
datumaro = {git = "https://github.com/cvat-ai/datumaro.git", rev = "ff83c00c2c1bc4b8fdfcc55067fcab0a9b5b6b11"}
25-
human-protocol-sdk = "^4.0.3b0"
2625
hexbytes = ">=1.2.0" # required for to_0x_hex() function
2726
starlette = ">=0.40.0" # avoid the vulnerability with multipart/form-data
2827
cvat-sdk = "2.25.0"
2928
cryptography = "<44.0.0" # human-protocol-sdk -> pgpy dep requires cryptography < 45
29+
human-protocol-sdk = "^4.0.3"
3030

3131
[tool.poetry.group.dev.dependencies]
3232
hypothesis = "^6.82.6"

packages/examples/cvat/recording-oracle/src/chain/web3.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from eth_account.messages import encode_defunct
55
from web3 import Web3
6-
from web3.middleware import construct_sign_and_send_raw_middleware
6+
from web3.middleware import SignAndSendRawMiddlewareBuilder
77
from web3.providers.rpc import HTTPProvider
88

99
from src.core.config import Config
@@ -15,27 +15,30 @@ def get_web3(chain_id: Networks):
1515
case Config.polygon_mainnet.chain_id:
1616
w3 = Web3(HTTPProvider(Config.polygon_mainnet.rpc_api))
1717
gas_payer = w3.eth.account.from_key(Config.polygon_mainnet.private_key)
18-
w3.middleware_onion.add(
19-
construct_sign_and_send_raw_middleware(gas_payer),
20-
"construct_sign_and_send_raw_middleware",
18+
w3.middleware_onion.inject(
19+
SignAndSendRawMiddlewareBuilder.build(Config.polygon_mainnet.private_key),
20+
"SignAndSendRawMiddlewareBuilder",
21+
layer=0,
2122
)
2223
w3.eth.default_account = gas_payer.address
2324
return w3
2425
case Config.polygon_amoy.chain_id:
2526
w3 = Web3(HTTPProvider(Config.polygon_amoy.rpc_api))
2627
gas_payer = w3.eth.account.from_key(Config.polygon_amoy.private_key)
27-
w3.middleware_onion.add(
28-
construct_sign_and_send_raw_middleware(gas_payer),
29-
"construct_sign_and_send_raw_middleware",
28+
w3.middleware_onion.inject(
29+
SignAndSendRawMiddlewareBuilder.build(Config.polygon_amoy.private_key),
30+
"SignAndSendRawMiddlewareBuilder",
31+
layer=0,
3032
)
3133
w3.eth.default_account = gas_payer.address
3234
return w3
3335
case Config.localhost.chain_id:
3436
w3 = Web3(HTTPProvider(Config.localhost.rpc_api))
3537
gas_payer = w3.eth.account.from_key(Config.localhost.private_key)
36-
w3.middleware_onion.add(
37-
construct_sign_and_send_raw_middleware(gas_payer),
38-
"construct_sign_and_send_raw_middleware",
38+
w3.middleware_onion.inject(
39+
SignAndSendRawMiddlewareBuilder.build(Config.localhost.private_key),
40+
"SignAndSendRawMiddlewareBuilder",
41+
layer=0,
3942
)
4043
w3.eth.default_account = gas_payer.address
4144
return w3
@@ -47,7 +50,7 @@ def serialize_message(message: Any) -> str:
4750
return json.dumps(message, separators=(",", ":"))
4851

4952

50-
def sign_message(chain_id: Networks, message) -> str:
53+
def sign_message(chain_id: Networks, message) -> tuple:
5154
w3 = get_web3(chain_id)
5255
private_key = ""
5356
match chain_id:

packages/examples/cvat/recording-oracle/tests/integration/chain/test_escrow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from human_protocol_sdk.encryption import EncryptionUtils
77
from human_protocol_sdk.escrow import EscrowClientError
88
from web3 import Web3
9-
from web3.middleware import construct_sign_and_send_raw_middleware
9+
from web3.middleware import SignAndSendRawMiddlewareBuilder
1010
from web3.providers.rpc import HTTPProvider
1111

1212
from src.chain.escrow import (
@@ -42,9 +42,10 @@ def setUp(self):
4242

4343
# Set default gas payer
4444
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
45-
self.w3.middleware_onion.add(
46-
construct_sign_and_send_raw_middleware(self.gas_payer),
47-
"construct_sign_and_send_raw_middleware",
45+
self.w3.middleware_onion.inject(
46+
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
47+
"SignAndSendRawMiddlewareBuilder",
48+
layer=0,
4849
)
4950
self.w3.eth.default_account = self.gas_payer.address
5051
self.network_config = Config.localhost

packages/examples/cvat/recording-oracle/tests/integration/chain/test_web3.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from human_protocol_sdk.constants import ChainId
66
from web3 import HTTPProvider, Web3
7-
from web3.middleware import construct_sign_and_send_raw_middleware
7+
from web3.middleware import SignAndSendRawMiddlewareBuilder
88

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

1919
# Set default gas payer
2020
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
21-
self.w3.middleware_onion.add(
22-
construct_sign_and_send_raw_middleware(self.gas_payer),
23-
"construct_sign_and_send_raw_middleware",
21+
self.w3.middleware_onion.inject(
22+
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
23+
"SignAndSendRawMiddlewareBuilder",
24+
layer=0,
2425
)
2526
self.w3.eth.default_account = self.gas_payer.address
2627

packages/examples/cvat/recording-oracle/tests/integration/cron/test_process_exchange_oracle_webhooks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from sqlalchemy.sql import select
77
from web3 import Web3
8-
from web3.middleware import construct_sign_and_send_raw_middleware
8+
from web3.middleware import SignAndSendRawMiddlewareBuilder
99
from web3.providers.rpc import HTTPProvider
1010

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

3434
self.gas_payer = self.w3.eth.account.from_key(DEFAULT_GAS_PAYER_PRIV)
35-
self.w3.middleware_onion.add(
36-
construct_sign_and_send_raw_middleware(self.gas_payer),
37-
"construct_sign_and_send_raw_middleware",
35+
self.w3.middleware_onion.inject(
36+
SignAndSendRawMiddlewareBuilder.build(DEFAULT_GAS_PAYER_PRIV),
37+
"SignAndSendRawMiddlewareBuilder",
38+
layer=0,
3839
)
3940
self.w3.eth.default_account = self.gas_payer.address
4041

0 commit comments

Comments
 (0)