Skip to content

Commit 8547da7

Browse files
committed
Refactor GraphQL types and interfaces for improved nullability and consistency
- Removed unused types and consolidated daily statistics types. - Updated operator-related fields to allow null values for better handling of optional data. - Introduced new types for payout and cancellation refund data. - Adjusted mapping functions to accommodate changes in data types and nullability. - Enhanced test cases to reflect the updated types and ensure correctness.
1 parent bbacf06 commit 8547da7

File tree

20 files changed

+694
-573
lines changed

20 files changed

+694
-573
lines changed

packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ def __init__(
5757
count: int,
5858
factory_address: str,
5959
launcher: str,
60+
job_requester_id: Optional[str],
6061
status: str,
6162
token: str,
6263
total_funded_amount: int,
63-
created_at: datetime,
64+
created_at: int,
6465
final_results_url: Optional[str] = None,
6566
final_results_hash: Optional[str] = None,
6667
intermediate_results_url: Optional[str] = None,
@@ -85,10 +86,11 @@ def __init__(
8586
:param count: Count
8687
:param factory_address: Factory address
8788
:param launcher: Launcher
89+
:param job_requester_id: Job requester identifier
8890
:param status: Status
8991
:param token: Token
9092
:param total_funded_amount: Total funded amount
91-
:param created_at: Creation date
93+
:param created_at: Creation timestamp in milliseconds
9294
:param final_results_url: URL for final results.
9395
:param final_results_hash: Hash for final results.
9496
:param intermediate_results_url: URL for intermediate results.
@@ -114,6 +116,7 @@ def __init__(
114116
self.intermediate_results_url = intermediate_results_url
115117
self.intermediate_results_hash = intermediate_results_hash
116118
self.launcher = launcher
119+
self.job_requester_id = job_requester_id
117120
self.manifest_hash = manifest_hash
118121
self.manifest = manifest
119122
self.recording_oracle = recording_oracle
@@ -125,15 +128,15 @@ def __init__(
125128
self.status = status
126129
self.token = token
127130
self.total_funded_amount = total_funded_amount
128-
self.created_at = created_at
131+
self.created_at = created_at * 1000
129132
self.chain_id = chain_id
130133

131134

132135
class StatusEvent:
133136
"""
134137
Initializes a StatusEvent instance.
135138
136-
:param timestamp: The timestamp of the event.
139+
:param timestamp: The timestamp of the event in milliseconds.
137140
:param status: The status of the escrow.
138141
:param chain_id: The chain identifier where the event occurred.
139142
:param escrow_address: The address of the escrow.
@@ -142,7 +145,7 @@ class StatusEvent:
142145
def __init__(
143146
self, timestamp: int, status: str, chain_id: ChainId, escrow_address: str
144147
):
145-
self.timestamp = timestamp
148+
self.timestamp = timestamp * 1000
146149
self.status = status
147150
self.chain_id = chain_id
148151
self.escrow_address = escrow_address
@@ -157,7 +160,7 @@ class Payout:
157160
:param escrow_address: The address of the escrow that executed the payout.
158161
:param recipient: The address of the recipient.
159162
:param amount: The amount of the payout.
160-
:param created_at: The time of creation of the payout.
163+
:param created_at: The time of creation of the payout in milliseconds.
161164
"""
162165

163166
def __init__(
@@ -167,7 +170,7 @@ def __init__(
167170
self.escrow_address = escrow_address
168171
self.recipient = recipient
169172
self.amount = amount
170-
self.created_at = created_at
173+
self.created_at = created_at * 1000
171174

172175

173176
class CancellationRefund:
@@ -179,7 +182,7 @@ class CancellationRefund:
179182
:param receiver: The address of the recipient receiving the refund.
180183
:param amount: The amount being refunded.
181184
:param block: The block number in which the refund was processed.
182-
:param timestamp: The timestamp of the refund event.
185+
:param timestamp: The timestamp of the refund event in milliseconds.
183186
:param tx_hash: The transaction hash of the refund event.
184187
"""
185188

@@ -198,7 +201,7 @@ def __init__(
198201
self.receiver = receiver
199202
self.amount = amount
200203
self.block = block
201-
self.timestamp = timestamp
204+
self.timestamp = timestamp * 1000
202205
self.tx_hash = tx_hash
203206

204207

@@ -290,30 +293,27 @@ def get_escrows(
290293
[
291294
EscrowData(
292295
chain_id=chain_id,
293-
id=escrow.get("id") or "",
294-
address=escrow.get("address") or "",
295-
amount_paid=int(escrow.get("amountPaid") or 0),
296-
balance=int(escrow.get("balance") or 0),
297-
count=int(escrow.get("count") or 0),
298-
factory_address=escrow.get("factoryAddress") or "",
299-
launcher=escrow.get("launcher") or "",
300-
status=escrow.get("status") or "",
301-
token=escrow.get("token") or "",
302-
total_funded_amount=int(escrow.get("totalFundedAmount") or 0),
303-
created_at=datetime.fromtimestamp(
304-
int(escrow.get("createdAt") or 0)
305-
),
306-
final_results_url=escrow.get("finalResultsUrl", None),
307-
final_results_hash=escrow.get("finalResultsHash", None),
308-
intermediate_results_url=escrow.get("intermediateResultsUrl", None),
309-
intermediate_results_hash=escrow.get(
310-
"intermediateResultsHash", None
311-
),
312-
manifest_hash=escrow.get("manifestHash", None),
313-
manifest=escrow.get("manifest", None),
314-
recording_oracle=escrow.get("recordingOracle", None),
315-
reputation_oracle=escrow.get("reputationOracle", None),
316-
exchange_oracle=escrow.get("exchangeOracle", None),
296+
id=escrow.get("id"),
297+
address=escrow.get("address"),
298+
amount_paid=int(escrow.get("amountPaid")),
299+
balance=int(escrow.get("balance")),
300+
count=int(escrow.get("count")),
301+
factory_address=escrow.get("factoryAddress"),
302+
launcher=escrow.get("launcher"),
303+
job_requester_id=escrow.get("jobRequesterId"),
304+
status=escrow.get("status"),
305+
token=escrow.get("token"),
306+
total_funded_amount=int(escrow.get("totalFundedAmount")),
307+
created_at=int(escrow.get("createdAt")),
308+
final_results_url=escrow.get("finalResultsUrl"),
309+
final_results_hash=escrow.get("finalResultsHash"),
310+
intermediate_results_url=escrow.get("intermediateResultsUrl"),
311+
intermediate_results_hash=escrow.get("intermediateResultsHash"),
312+
manifest_hash=escrow.get("manifestHash"),
313+
manifest=escrow.get("manifest"),
314+
recording_oracle=escrow.get("recordingOracle"),
315+
reputation_oracle=escrow.get("reputationOracle"),
316+
exchange_oracle=escrow.get("exchangeOracle"),
317317
recording_oracle_fee=(
318318
int(escrow.get("recordingOracleFee"))
319319
if escrow.get("recordingOracleFee")
@@ -393,26 +393,27 @@ def get_escrow(
393393

394394
return EscrowData(
395395
chain_id=chain_id,
396-
id=escrow.get("id") or "",
397-
address=escrow.get("address") or "",
398-
amount_paid=int(escrow.get("amountPaid") or 0),
399-
balance=int(escrow.get("balance") or 0),
400-
count=int(escrow.get("count") or 0),
401-
factory_address=escrow.get("factoryAddress") or "",
402-
launcher=escrow.get("launcher") or "",
403-
status=escrow.get("status") or "",
404-
token=escrow.get("token") or "",
405-
total_funded_amount=int(escrow.get("totalFundedAmount") or 0),
406-
created_at=datetime.fromtimestamp(int(escrow.get("createdAt") or 0)),
407-
final_results_url=escrow.get("finalResultsUrl", None),
408-
final_results_hash=escrow.get("finalResultsHash", None),
409-
intermediate_results_url=escrow.get("intermediateResultsUrl", None),
410-
intermediate_results_hash=escrow.get("intermediateResultsHash", None),
411-
manifest_hash=escrow.get("manifestHash", None),
412-
manifest=escrow.get("manifest", None),
413-
recording_oracle=escrow.get("recordingOracle", None),
414-
reputation_oracle=escrow.get("reputationOracle", None),
415-
exchange_oracle=escrow.get("exchangeOracle", None),
396+
id=escrow.get("id"),
397+
address=escrow.get("address"),
398+
amount_paid=int(escrow.get("amountPaid")),
399+
balance=int(escrow.get("balance")),
400+
count=int(escrow.get("count")),
401+
factory_address=escrow.get("factoryAddress"),
402+
launcher=escrow.get("launcher"),
403+
job_requester_id=escrow.get("jobRequesterId"),
404+
status=escrow.get("status"),
405+
token=escrow.get("token"),
406+
total_funded_amount=int(escrow.get("totalFundedAmount")),
407+
created_at=int(escrow.get("createdAt")),
408+
final_results_url=escrow.get("finalResultsUrl"),
409+
final_results_hash=escrow.get("finalResultsHash"),
410+
intermediate_results_url=escrow.get("intermediateResultsUrl"),
411+
intermediate_results_hash=escrow.get("intermediateResultsHash"),
412+
manifest_hash=escrow.get("manifestHash"),
413+
manifest=escrow.get("manifest"),
414+
recording_oracle=escrow.get("recordingOracle"),
415+
reputation_oracle=escrow.get("reputationOracle"),
416+
exchange_oracle=escrow.get("exchangeOracle"),
416417
recording_oracle_fee=(
417418
int(escrow.get("recordingOracleFee"))
418419
if escrow.get("recordingOracleFee")
@@ -478,7 +479,7 @@ def get_status_events(filter: StatusEventFilter) -> List[StatusEvent]:
478479

479480
events_with_chain_id = [
480481
StatusEvent(
481-
timestamp=event["timestamp"],
482+
timestamp=int(event["timestamp"]),
482483
escrow_address=event["escrowAddress"],
483484
status=event["status"],
484485
chain_id=filter.chain_id,

0 commit comments

Comments
 (0)