py-near 1.1.38__py3-none-any.whl → 1.1.39__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py_near/providers.py
CHANGED
@@ -121,82 +121,66 @@ class JsonProvider(object):
|
|
121
121
|
):
|
122
122
|
await self.check_available_rpcs()
|
123
123
|
j = {"method": method, "params": params, "id": "dontcare", "jsonrpc": "2.0"}
|
124
|
-
res = {}
|
125
|
-
if broadcast or threshold:
|
126
124
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
125
|
+
async def f(rpc_call_addr):
|
126
|
+
auth_key = "py-near"
|
127
|
+
if "@" in rpc_call_addr:
|
128
|
+
auth_key = rpc_call_addr.split("//")[1].split("@")[0]
|
129
|
+
rpc_call_addr = rpc_call_addr.replace(auth_key + "@", "")
|
130
|
+
async with aiohttp.ClientSession() as session:
|
131
|
+
r = await session.post(
|
132
|
+
rpc_call_addr,
|
133
|
+
json=j,
|
134
|
+
timeout=timeout,
|
135
|
+
headers={
|
136
|
+
"Referer": "https://tgapp.herewallet.app",
|
137
|
+
"Authorization": f"Bearer {auth_key}",
|
138
|
+
}, # NEAR RPC requires Referer header
|
139
|
+
)
|
140
|
+
if r.status == 200:
|
141
|
+
return json.loads(await r.text())
|
139
142
|
|
143
|
+
if broadcast or threshold:
|
140
144
|
tasks = [
|
141
145
|
asyncio.create_task(f(rpc_addr)) for rpc_addr in self._available_rpcs
|
142
146
|
]
|
143
|
-
|
144
|
-
for
|
145
|
-
|
146
|
-
|
147
|
-
except Exception as e:
|
148
|
-
logger.error(f"Rpc error: {e}")
|
149
|
-
continue
|
150
|
-
|
151
|
-
def most_frequent_by_hash(array):
|
152
|
-
counter = Counter(array)
|
153
|
-
most_frequent = counter.most_common(1)[0][0]
|
154
|
-
return most_frequent
|
155
|
-
|
156
|
-
if threshold:
|
157
|
-
# return first most frequent response
|
158
|
-
array = [hash(json.dumps(x)) for x in responses]
|
159
|
-
most_frequent_element = most_frequent_by_hash(array)
|
160
|
-
correct_responses = [
|
161
|
-
x for x in responses if hash(json.dumps(x)) == most_frequent_element
|
162
|
-
]
|
163
|
-
if len(correct_responses) >= threshold:
|
164
|
-
return responses[0]
|
165
|
-
raise Exception(
|
166
|
-
f"Threshold not reached: {len(correct_responses)}/{threshold}"
|
167
|
-
)
|
168
|
-
|
169
|
-
if broadcast:
|
170
|
-
# return first response without errors
|
171
|
-
for res in responses:
|
172
|
-
if "error" not in res:
|
173
|
-
return res
|
174
|
-
return responses[0]
|
175
|
-
|
176
|
-
for rpc_addr in self._available_rpcs:
|
147
|
+
else:
|
148
|
+
tasks = [f(rpc_addr) for rpc_addr in self._available_rpcs]
|
149
|
+
responses = []
|
150
|
+
for t in tasks:
|
177
151
|
try:
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
"Referer": "https://tgapp.herewallet.app/"
|
185
|
-
}, # NEAR RPC requires Referer header
|
186
|
-
)
|
187
|
-
r.raise_for_status()
|
188
|
-
res = json.loads(await r.text())
|
189
|
-
return res
|
190
|
-
except (
|
191
|
-
RPCTimeoutError,
|
192
|
-
ClientResponseError,
|
193
|
-
ClientConnectorError,
|
194
|
-
ServerDisconnectedError,
|
195
|
-
ConnectionError,
|
196
|
-
) as e:
|
152
|
+
res = await t
|
153
|
+
if res:
|
154
|
+
responses.append(res)
|
155
|
+
if not (broadcast or threshold):
|
156
|
+
return res
|
157
|
+
except Exception as e:
|
197
158
|
logger.error(f"Rpc error: {e}")
|
198
159
|
continue
|
199
|
-
|
160
|
+
if not responses:
|
161
|
+
raise RpcEmptyResponse("RPC returned empty response")
|
162
|
+
def most_frequent_by_hash(array):
|
163
|
+
counter = Counter(array)
|
164
|
+
most_frequent = counter.most_common(1)[0][0]
|
165
|
+
return most_frequent
|
166
|
+
|
167
|
+
if threshold:
|
168
|
+
# return first most frequent response
|
169
|
+
array = [hash(json.dumps(x)) for x in responses]
|
170
|
+
most_frequent_element = most_frequent_by_hash(array)
|
171
|
+
correct_responses = [
|
172
|
+
x for x in responses if hash(json.dumps(x)) == most_frequent_element
|
173
|
+
]
|
174
|
+
if len(correct_responses) >= threshold:
|
175
|
+
return responses[0]
|
176
|
+
raise Exception(
|
177
|
+
f"Threshold not reached: {len(correct_responses)}/{threshold}"
|
178
|
+
)
|
179
|
+
|
180
|
+
for res in responses:
|
181
|
+
if "error" not in res:
|
182
|
+
return res
|
183
|
+
raise RpcEmptyResponse("RPC returned empty response")
|
200
184
|
|
201
185
|
@staticmethod
|
202
186
|
def get_error_from_response(content: dict):
|
@@ -20,10 +20,10 @@ py_near/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
20
20
|
py_near/exceptions/exceptions.py,sha256=DEFipaAHm0y7oCuN2QKzHsiQvUTUQVl-Ce36Ag7n7hs,5509
|
21
21
|
py_near/exceptions/provider.py,sha256=K-wexgjPJ8sw42JePwaP7R5dJEIn9DoFJRvVcURsx6s,7718
|
22
22
|
py_near/models.py,sha256=GZQD1TKGWlwqsJsKRXrVNBjCdAIpk7GQypU-QOtAPFs,11533
|
23
|
-
py_near/providers.py,sha256=
|
23
|
+
py_near/providers.py,sha256=W9jquOitiBtW1ezvcpuH5xs-1z0nQYOgvNbMHyevTSA,15646
|
24
24
|
py_near/transactions.py,sha256=QAXegv2JpKISk92NaChtIH6-QPHrcWbrwdKH_lH4TsU,3186
|
25
25
|
py_near/utils.py,sha256=FirRH93ydH1cwjn0-sNrZeIn3BRD6QHedrP2VkAdJ6g,126
|
26
|
-
py_near-1.1.
|
27
|
-
py_near-1.1.
|
28
|
-
py_near-1.1.
|
29
|
-
py_near-1.1.
|
26
|
+
py_near-1.1.39.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
|
27
|
+
py_near-1.1.39.dist-info/METADATA,sha256=bBtdADCm44pJN3z7ZyutWqepQGLoeaAsqX9MfuTa8Gk,4713
|
28
|
+
py_near-1.1.39.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
29
|
+
py_near-1.1.39.dist-info/RECORD,,
|
File without changes
|
File without changes
|