Worker¶
Helpers for retrieving worker information from the protocol.
Utilities¶
Utility helpers for worker-related queries.
Example
WorkerData ¶
Represents worker information retrieved from the subgraph.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique worker identifier. |
address |
str
|
Worker's Ethereum address. |
payout_count |
int
|
Number of payouts the worker has received. |
WorkerUtils ¶
Utility class providing worker-related query and data retrieval functions.
This class offers static methods to fetch worker data from the Human Protocol subgraph, including filtered worker lists and individual worker details.
get_worker
staticmethod
¶
Retrieve a single worker by their address.
Fetches detailed information about a specific worker from the subgraph, including their total earnings and payout history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_id
|
ChainId
|
Network where the worker has participated. |
required |
worker_address
|
str
|
Ethereum address of the worker. |
required |
options
|
Optional[SubgraphOptions]
|
Optional configuration for subgraph requests. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[WorkerData]
|
Worker data if found, otherwise |
Raises:
| Type | Description |
|---|---|
WorkerUtilsError
|
If the chain ID is not supported or the worker address is invalid. |
get_workers
staticmethod
¶
Retrieve a list of workers matching the provided filter criteria.
Queries the subgraph for workers based on the specified parameters including address filters, ordering preferences, and pagination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
WorkerFilter
|
Filter parameters including chain ID, worker address, ordering, and pagination options. |
required |
options
|
Optional[SubgraphOptions]
|
Optional configuration for subgraph requests such as custom endpoints or timeout settings. |
None
|
Returns:
| Type | Description |
|---|---|
List[WorkerData]
|
A list of worker records matching the filter criteria. Returns an empty list if no matches are found. |
Raises:
| Type | Description |
|---|---|
WorkerUtilsError
|
If the chain ID is not supported. |
Example
from human_protocol_sdk.constants import ChainId
from human_protocol_sdk.worker import WorkerUtils, WorkerFilter
# Get all workers
workers = WorkerUtils.get_workers(
WorkerFilter(chain_id=ChainId.POLYGON_AMOY)
)
for worker in workers:
print(f"{worker.address}: {worker.payout_count} payouts")
# Get specific worker
workers = WorkerUtils.get_workers(
WorkerFilter(
chain_id=ChainId.POLYGON_AMOY,
worker_address="0x1234567890123456789012345678901234567890",
)
)
WorkerUtilsError ¶
Bases: Exception
Exception raised when errors occur during worker data retrieval operations.