py-near 1.1.38__tar.gz → 1.1.39__tar.gz

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.
Files changed (29) hide show
  1. {py_near-1.1.38 → py_near-1.1.39}/PKG-INFO +1 -1
  2. {py_near-1.1.38 → py_near-1.1.39}/pyproject.toml +2 -2
  3. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/providers.py +52 -68
  4. {py_near-1.1.38 → py_near-1.1.39}/LICENSE +0 -0
  5. {py_near-1.1.38 → py_near-1.1.39}/README.md +0 -0
  6. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/__init__.py +0 -0
  7. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/account.py +0 -0
  8. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/constants.py +0 -0
  9. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/__init__.py +0 -0
  10. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/core.py +0 -0
  11. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/ft/__init__.py +0 -0
  12. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/ft/async_client.py +0 -0
  13. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/ft/exceptions.py +0 -0
  14. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/ft/models.py +0 -0
  15. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/fts.py +0 -0
  16. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/keypom/__init__.py +0 -0
  17. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/keypom/async_client.py +0 -0
  18. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/keypom/exceptions.py +0 -0
  19. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/keypom/models.py +0 -0
  20. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/staking/__init__.py +0 -0
  21. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/staking/async_client.py +0 -0
  22. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/staking/exceptions.py +0 -0
  23. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/dapps/staking/models.py +0 -0
  24. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/exceptions/__init__.py +0 -0
  25. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/exceptions/exceptions.py +0 -0
  26. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/exceptions/provider.py +0 -0
  27. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/models.py +0 -0
  28. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/transactions.py +0 -0
  29. {py_near-1.1.38 → py_near-1.1.39}/src/py_near/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py-near
3
- Version: 1.1.38
3
+ Version: 1.1.39
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
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "py-near"
3
- version = "1.1.38"
3
+ version = "1.1.39"
4
4
  description="Pretty simple and fully asynchronous framework for working with NEAR blockchain"
5
5
  authors = ["pvolnov <petr@herewallet.app>"]
6
6
  readme = "README.md"
@@ -22,7 +22,7 @@ base58 = "^2.1.1"
22
22
 
23
23
  [project]
24
24
  name = "py-near"
25
- version = "1.1.38"
25
+ version = "1.1.39"
26
26
  description = "Pretty simple and fully asynchronous framework for working with NEAR blockchaink"
27
27
  authors = [ {name = "pvolnov", email = "petr@herewallet.app"} ]
28
28
  requires-python = ">=3.7"
@@ -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
- async def f(rpc_call_addr):
128
- async with aiohttp.ClientSession() as session:
129
- r = await session.post(
130
- rpc_call_addr,
131
- json=j,
132
- timeout=timeout,
133
- headers={
134
- "Referer": "https://tgapp.herewallet.app"
135
- }, # NEAR RPC requires Referer header
136
- )
137
- if r.status == 200:
138
- return json.loads(await r.text())
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
- responses = []
144
- for t in tasks:
145
- try:
146
- responses.append(await t)
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
- async with aiohttp.ClientSession() as session:
179
- r = await session.post(
180
- rpc_addr,
181
- json=j,
182
- timeout=timeout,
183
- headers={
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
- return res
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):
File without changes
File without changes
File without changes
File without changes