-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathescrow.py
More file actions
135 lines (128 loc) · 3.04 KB
/
escrow.py
File metadata and controls
135 lines (128 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from datetime import datetime
from human_protocol_sdk.filter import EscrowFilter
escrow_fragment = """
fragment EscrowFields on Escrow {
address
amountPaid
balance
count
factoryAddress
finalResultsUrl
id
intermediateResultsUrl
launcher
jobRequesterId
manifestHash
manifestUrl
recordingOracle
reputationOracle
exchangeOracle
status
token
totalFundedAmount
createdAt
}
"""
def get_escrows_query(filter: EscrowFilter):
return """
query GetEscrows(
$launcher: String
$reputationOracle: String
$recordingOracle: String
$exchangeOracle: String
$jobRequesterId: String
$status: [String!]
$from: Int
$to: Int
$orderDirection: String
$first: Int
$skip: Int
) {{
escrows(
where: {{
{launcher_clause}
{reputation_oracle_clause}
{recording_oracle_clause}
{exchange_oracle_clause}
{job_requester_clause}
{status_clause}
{from_clause}
{to_clause}
}}
orderBy: createdAt
orderDirection: $orderDirection
first: $first
skip: $skip
) {{
...EscrowFields
}}
}}
{escrow_fragment}
""".format(
escrow_fragment=escrow_fragment,
launcher_clause="launcher: $launcher" if filter.launcher else "",
reputation_oracle_clause=(
"reputationOracle: $reputationOracle" if filter.reputation_oracle else ""
),
recording_oracle_clause=(
"recordingOracle: $recordingOracle" if filter.recording_oracle else ""
),
exchange_oracle_clause=(
"exchangeOracle: $exchangeOracle" if filter.exchange_oracle else ""
),
job_requester_clause=(
"jobRequesterId: $jobRequesterId" if filter.job_requester_id else ""
),
status_clause="status_in: $status" if filter.status else "",
from_clause="createdAt_gte: $from" if filter.date_from else "",
to_clause="createdAt_lte: $to" if filter.date_to else "",
)
def get_escrow_query():
return """
query GetEscrow(
$escrowAddress: String!
) {{
escrow(id: $escrowAddress) {{
...EscrowFields
}}
}}
{escrow_fragment}
""".format(
escrow_fragment=escrow_fragment
)
def get_status_query(
from_: datetime = None, to_: datetime = None, launcher: str = None
):
return """
query getStatus(
$status: [String!]!
$from: Int
$to: Int
$launcher: String
$orderDirection: String
$first: Int
$skip: Int
) {{
escrowStatusEvents(
where: {{
status_in: $status
{from_clause}
{to_clause}
{launcher_clause}
}}
orderBy: timestamp
orderDirection: $orderDirection
first: $first
skip: $skip
) {{
id
escrowAddress
timestamp
status
}}
}}
""".format(
from_clause="timestamp_gte: $from" if from_ else "",
to_clause="timestamp_lte: $to" if to_ else "",
launcher_clause=f"launcher: $launcher" if launcher else "",
)