Skip to content

Commit

Permalink
bump: use '*' instead of frozen dependencies in human-protocol-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzeranov committed Feb 21, 2025
1 parent ad26574 commit f959f03
Show file tree
Hide file tree
Showing 11 changed files with 1,302 additions and 1,120 deletions.
6 changes: 3 additions & 3 deletions packages/sdk/python/human-protocol-sdk/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ sphinx-autodoc-typehints = "*"
[packages]
cryptography = "*"
minio = "*"
validators = "==0.20.0"
web3 = "==6.8.*"
validators = "*"
web3 = "*"
aiohttp = "<4.0.0" # broken freeze in one of dependencies
pgpy = "*"
eth-typing = "==4.1.0"
eth-typing = "*"

[requires]
python_version = "3.10"
Expand Down
2,118 changes: 1,121 additions & 997 deletions packages/sdk/python/human-protocol-sdk/Pipfile.lock

Large diffs are not rendered by default.

48 changes: 37 additions & 11 deletions packages/sdk/python/human-protocol-sdk/example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime

from regex import F

from human_protocol_sdk.constants import ChainId, Status
from human_protocol_sdk.escrow import EscrowUtils
from human_protocol_sdk.filter import EscrowFilter, StatisticsFilter
Expand Down Expand Up @@ -142,19 +144,43 @@ def agreement_example():


if __name__ == "__main__":
statistics_client = StatisticsClient()
# statistics_client = StatisticsClient()

# Run single example while testing, and remove comments before commit

get_escrows()
get_leaders()
# get_escrows()
# get_leaders()

# statistics_client = StatisticsClient(ChainId.POLYGON_AMOY)
# get_hmt_holders(statistics_client)
# get_escrow_statistics(statistics_client)
# get_hmt_statistics(statistics_client)
# get_payment_statistics(statistics_client)
# get_worker_statistics(statistics_client)
# get_hmt_daily_data(statistics_client)

# agreement_example()
from web3 import Web3
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.rpc import HTTPProvider

from human_protocol_sdk.kvstore import KVStoreClient

priv_key = "20712e37eba71a497b3a584dad1514f80dac1840d94ffea3cee4aea93f82362d"
web3 = Web3(
HTTPProvider(
"https://polygon-amoy.g.alchemy.com/v2/Jomagi_shxwCUrKtZfgZepvngWRuO8-e"
)
)
gas_payer = web3.eth.account.from_key(priv_key)
web3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
"SignAndSendRawMiddlewareBuilder",
layer=0,
)
web3.eth.default_account = gas_payer.address

statistics_client = StatisticsClient(ChainId.POLYGON_AMOY)
get_hmt_holders(statistics_client)
get_escrow_statistics(statistics_client)
get_hmt_statistics(statistics_client)
get_payment_statistics(statistics_client)
get_worker_statistics(statistics_client)
get_hmt_daily_data(statistics_client)
kvs = KVStoreClient(web3)
kvs.set("role", "exchange_oracle")

agreement_example()
print(123)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -24,9 +24,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -69,7 +70,7 @@ def get_w3_with_priv_key(priv_key: str):
)
from web3 import Web3, contract
from web3 import eth
from web3.middleware import geth_poa_middleware
from web3.middleware import ExtraDataToPOAMiddleware
from web3.types import TxParams
from eth_utils import abi

Expand Down Expand Up @@ -188,8 +189,10 @@ def __init__(self, web3: Web3):

# Initialize web3 instance
self.w3 = web3
if not self.w3.middleware_onion.get("geth_poa"):
self.w3.middleware_onion.inject(geth_poa_middleware, "geth_poa", layer=0)
if not self.w3.middleware_onion.get("ExtraDataToPOA"):
self.w3.middleware_onion.inject(
ExtraDataToPOAMiddleware, "ExtraDataToPOA", layer=0
)

chain_id = None
# Load network configuration based on chain_id
Expand Down Expand Up @@ -230,7 +233,7 @@ def create_escrow(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -240,9 +243,10 @@ def get_w3_with_priv_key(priv_key: str):
URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -304,7 +308,7 @@ def setup(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -314,9 +318,10 @@ def get_w3_with_priv_key(priv_key: str):
URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -384,7 +389,7 @@ def fund(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -393,9 +398,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -449,7 +455,7 @@ def store_results(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -458,9 +464,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -508,7 +515,7 @@ def complete(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -517,9 +524,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -571,7 +579,7 @@ def bulk_payout(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -580,9 +588,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -670,7 +679,7 @@ def create_bulk_payout_transaction(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -679,9 +688,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -830,7 +840,7 @@ def cancel(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -839,9 +849,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -912,7 +923,7 @@ def add_trusted_handlers(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -921,9 +932,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down Expand Up @@ -981,7 +993,7 @@ def withdraw(
from eth_typing import URI
from web3 import Web3
from web3.middleware import construct_sign_and_send_raw_middleware
from web3.middleware import SignAndSendRawMiddlewareBuilder
from web3.providers.auto import load_provider_from_uri
from human_protocol_sdk.escrow import EscrowClient
Expand All @@ -990,9 +1002,10 @@ def get_w3_with_priv_key(priv_key: str):
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
gas_payer = w3.eth.account.from_key(priv_key)
w3.eth.default_account = gas_payer.address
w3.middleware_onion.add(
construct_sign_and_send_raw_middleware(gas_payer),
"construct_sign_and_send_raw_middleware",
w3.middleware_onion.inject(
SignAndSendRawMiddlewareBuilder.build(priv_key),
'SignAndSendRawMiddlewareBuilder',
layer=0,
)
return (w3, gas_payer)
Expand Down
Loading

0 comments on commit f959f03

Please sign in to comment.