py-near 1.1.28__py3-none-any.whl → 1.1.31__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/account.py CHANGED
@@ -122,13 +122,9 @@ class Account(object):
122
122
  raise ValueError("You must provide a private key or seed to call methods")
123
123
  await self._update_last_block_hash()
124
124
 
125
- while True:
126
- if self._free_signers.empty():
127
- logger.info("Free signer not found")
128
- await asyncio.sleep(0.5)
129
- continue
130
- break
131
125
  pk = await self._free_signers.get()
126
+ await self._free_signers.put(pk)
127
+
132
128
  if self._access_key_nonce[pk] == 0:
133
129
  access_key = await self.get_access_key(pk)
134
130
  self._access_key_nonce[pk] = access_key.nonce
py_near/providers.py CHANGED
@@ -44,7 +44,11 @@ PROVIDER_CODE_TO_EXCEPTION = {
44
44
 
45
45
 
46
46
  class JsonProvider(object):
47
- def __init__(self, rpc_addr):
47
+ def __init__(self, rpc_addr, allow_broadcast=True):
48
+ """
49
+ :param rpc_addr: str or list of str
50
+ :param allow_broadcast: bool - submit signed transaction to all RPCs
51
+ """
48
52
  if isinstance(rpc_addr, tuple):
49
53
  self._rpc_addresses = ["http://{}:{}".format(*rpc_addr)]
50
54
  elif isinstance(rpc_addr, list):
@@ -53,6 +57,7 @@ class JsonProvider(object):
53
57
  self._rpc_addresses = [rpc_addr]
54
58
  self._available_rpcs = self._rpc_addresses.copy()
55
59
  self._last_rpc_addr_check = 0
60
+ self.allow_broadcast = allow_broadcast
56
61
 
57
62
  async def check_available_rpcs(self):
58
63
  if (
@@ -84,7 +89,7 @@ class JsonProvider(object):
84
89
  async with aiohttp.ClientSession() as session:
85
90
  async with session.post(rpc_addr, json=data) as r:
86
91
  if r.status == 200:
87
- data = json.loads(await r.text())['result']
92
+ data = json.loads(await r.text())["result"]
88
93
  if data["sync_info"]["syncing"]:
89
94
  last_block_ts = datetime.datetime.fromisoformat(
90
95
  data["sync_info"]["latest_block_time"]
@@ -109,16 +114,27 @@ class JsonProvider(object):
109
114
  logger.error(f"Remove rpc: {e}")
110
115
  self._available_rpcs = available_rpcs
111
116
 
112
- async def call_rpc_request(self, method, params, timeout=TIMEOUT_WAIT_RPC):
117
+ async def call_rpc_request(
118
+ self, method, params, timeout=TIMEOUT_WAIT_RPC, broadcast=False
119
+ ):
113
120
  await self.check_available_rpcs()
114
121
  j = {"method": method, "params": params, "id": "dontcare", "jsonrpc": "2.0"}
115
-
122
+ res = {}
116
123
  for rpc_addr in self._available_rpcs:
117
124
  try:
118
125
  async with aiohttp.ClientSession() as session:
119
- r = await session.post(rpc_addr, json=j, timeout=timeout)
126
+ r = await session.post(
127
+ rpc_addr,
128
+ json=j,
129
+ timeout=timeout,
130
+ headers={
131
+ "Referer": "https://tgapp.herewallet.app/"
132
+ }, # NEAR RPC requires Referer header
133
+ )
120
134
  r.raise_for_status()
121
- return json.loads(await r.text())
135
+ res = json.loads(await r.text())
136
+ if not broadcast:
137
+ return res
122
138
  except (
123
139
  RPCTimeoutError,
124
140
  ClientResponseError,
@@ -128,6 +144,7 @@ class JsonProvider(object):
128
144
  ) as e:
129
145
  logger.error(f"Rpc error: {e}")
130
146
  continue
147
+ return res
131
148
 
132
149
  @staticmethod
133
150
  def get_error_from_response(content: dict):
@@ -151,8 +168,10 @@ class JsonProvider(object):
151
168
  break
152
169
  return error
153
170
 
154
- async def json_rpc(self, method, params, timeout=TIMEOUT_WAIT_RPC):
155
- content = await self.call_rpc_request(method, params, timeout)
171
+ async def json_rpc(self, method, params, timeout=TIMEOUT_WAIT_RPC, broadcast=False):
172
+ content = await self.call_rpc_request(
173
+ method, params, timeout, broadcast=broadcast
174
+ )
156
175
  if not content:
157
176
  raise RpcEmptyResponse("RPC returned empty response")
158
177
 
@@ -168,7 +187,12 @@ class JsonProvider(object):
168
187
  :param timeout: rpc request timeout
169
188
  :return:
170
189
  """
171
- return await self.json_rpc("broadcast_tx_async", [signed_tx], timeout=timeout)
190
+ return await self.json_rpc(
191
+ "broadcast_tx_async",
192
+ [signed_tx],
193
+ timeout=timeout,
194
+ broadcast=self.allow_broadcast,
195
+ )
172
196
 
173
197
  async def wait_for_trx(self, trx_hash, receiver_id) -> TransactionResult:
174
198
  for _ in range(6):
@@ -202,6 +226,7 @@ class JsonProvider(object):
202
226
  "broadcast_tx_commit",
203
227
  [signed_tx],
204
228
  timeout=timeout,
229
+ broadcast=self.allow_broadcast,
205
230
  )
206
231
  return TransactionResult(**res)
207
232
  except RPCTimeoutError:
@@ -221,7 +246,7 @@ class JsonProvider(object):
221
246
  async with aiohttp.ClientSession() as session:
222
247
  async with session.post(rpc_addr, json=data) as r:
223
248
  if r.status == 200:
224
- return json.loads(await r.text())['result']
249
+ return json.loads(await r.text())["result"]
225
250
  except (
226
251
  ClientResponseError,
227
252
  ClientConnectorError,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py-near
3
- Version: 1.1.28
3
+ Version: 1.1.31
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,5 +1,5 @@
1
1
  py_near/__init__.py,sha256=t5fAxjaU8dN8xpQR2vz0ZGhfTkdVy2RCbkhJhZFglk4,50
2
- py_near/account.py,sha256=s2-nq5qKlxGPK9KHj6Ige2RuCi5uPVVQ9HpFG9eKJ8c,16872
2
+ py_near/account.py,sha256=YbF7wnO-FFsSlJINYqF0Z5M4oF5Z4IVEXd64qZFvgZI,16714
3
3
  py_near/constants.py,sha256=inaWIuwmF1EB5JSB0ynnZY5rKY_QsxhF9KuCOhPsM6k,164
4
4
  py_near/dapps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  py_near/dapps/core.py,sha256=LtN9aW2gw2mvEdhzQcQJIidtjv-XL1xjb0LK8DzqtqE,231
@@ -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=a6u-JMmHnYAYKzHd1kde2DFG5afHRj6CUeo6x25isYk,12549
23
+ py_near/providers.py,sha256=wRY_fHePvlV-jC-j8NTtpHhb8EedpzLFQ1DQROt-brE,13363
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.28.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
27
- py_near-1.1.28.dist-info/METADATA,sha256=p0h71-fg9WGFFIYX2nbAGRs-7U_I2Z7-Ht9HLn4O6oY,4713
28
- py_near-1.1.28.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
29
- py_near-1.1.28.dist-info/RECORD,,
26
+ py_near-1.1.31.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
27
+ py_near-1.1.31.dist-info/METADATA,sha256=EiR0adIzbk1Dxot0y4nK3jVRkG5oPxrY9YPRsuRK4YQ,4713
28
+ py_near-1.1.31.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
29
+ py_near-1.1.31.dist-info/RECORD,,