py-near 1.1.43__py3-none-any.whl → 1.1.44__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
@@ -81,7 +81,8 @@ class JsonProvider(object):
81
81
  await asyncio.sleep(3)
82
82
 
83
83
  if not self._available_rpcs:
84
- raise RpcNotAvailableError("All RPCs are unavailable")
84
+ self._available_rpcs = self._rpc_addresses.copy()
85
+ logger.error("All RPCs are async, reset to default list")
85
86
 
86
87
  async def _check_available_rpcs(self):
87
88
  available_rpcs = []
@@ -93,8 +94,15 @@ class JsonProvider(object):
93
94
  "params": {"finality": "final"},
94
95
  "id": 1,
95
96
  }
97
+ auth_key = "py-near"
98
+ if "@" in rpc_addr:
99
+ auth_key = rpc_addr.split("//")[1].split("@")[0]
100
+ rpc_addr = rpc_addr.replace(auth_key + "@", "")
96
101
  async with aiohttp.ClientSession() as session:
97
- async with session.post(rpc_addr, json=data) as r:
102
+ async with session.post(rpc_addr, json=data, headers={
103
+ "Referer": "https://tgapp.herewallet.app",
104
+ "Authorization": f"Bearer {auth_key}",
105
+ }) as r:
98
106
  if r.status == 200:
99
107
  data = json.loads(await r.text())["result"]
100
108
  if data["sync_info"]["syncing"]:
@@ -119,6 +127,7 @@ class JsonProvider(object):
119
127
  except Exception as e:
120
128
  if rpc_addr in self._available_rpcs:
121
129
  logger.error(f"Remove rpc: {e}")
130
+ logger.error(f"Rpc check error: {e}")
122
131
  self._available_rpcs = available_rpcs
123
132
 
124
133
  @staticmethod
@@ -163,6 +172,7 @@ class JsonProvider(object):
163
172
  ]
164
173
 
165
174
  responses = []
175
+ correct_responses = []
166
176
  while pending and len(pending):
167
177
  done, pending = await asyncio.wait(
168
178
  pending, return_when=asyncio.FIRST_COMPLETED
@@ -175,7 +185,7 @@ class JsonProvider(object):
175
185
  responses.append(result)
176
186
  except Exception as e:
177
187
  logger.warning(e)
178
- if responses:
188
+ if responses and threshold:
179
189
  array = [hash(json.dumps(x)) for x in responses]
180
190
  most_frequent_element = self.most_frequent_by_hash(array)
181
191
  correct_responses = [
@@ -185,6 +195,7 @@ class JsonProvider(object):
185
195
  for task in pending:
186
196
  task.cancel()
187
197
  return most_frequent_element
198
+ raise RpcEmptyResponse(f"Threshold not reached: {len(correct_responses)}/{threshold}")
188
199
  else:
189
200
  for rpc_addr in self._available_rpcs:
190
201
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py-near
3
- Version: 1.1.43
3
+ Version: 1.1.44
4
4
  Summary: Pretty simple and fully asynchronous framework for working with NEAR blockchain
5
5
  Author: pvolnov
6
6
  Author-email: petr@herewallet.app
@@ -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=gNYPBWoYIO1Tqj2aPvBlJUrFvUZtCIo6o19o9ibOFxo,15986
23
+ py_near/providers.py,sha256=oi4ZE-zYQv78Hiv6qNmdaJ3eD4mXYnSH6aXaP02f2lA,16626
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.43.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
27
- py_near-1.1.43.dist-info/METADATA,sha256=3xDsCOdQv1EbiwaUX4pItm0bcgqm9X5xF_3-ifSUWfM,4713
28
- py_near-1.1.43.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
29
- py_near-1.1.43.dist-info/RECORD,,
26
+ py_near-1.1.44.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
27
+ py_near-1.1.44.dist-info/METADATA,sha256=YIo51QllJAUSMYBg-9qfPN--N8CAgIzorZHdeTMPBPs,4713
28
+ py_near-1.1.44.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
29
+ py_near-1.1.44.dist-info/RECORD,,