py-near 1.1.30__py3-none-any.whl → 1.1.32__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 +12 -4
- py_near/providers.py +44 -8
- {py_near-1.1.30.dist-info → py_near-1.1.32.dist-info}/METADATA +1 -1
- {py_near-1.1.30.dist-info → py_near-1.1.32.dist-info}/RECORD +6 -6
- {py_near-1.1.30.dist-info → py_near-1.1.32.dist-info}/WHEEL +1 -1
- {py_near-1.1.30.dist-info → py_near-1.1.32.dist-info}/LICENSE +0 -0
py_near/account.py
CHANGED
@@ -108,7 +108,7 @@ class Account(object):
|
|
108
108
|
self._latest_block_hash_ts = utils.timestamp()
|
109
109
|
|
110
110
|
async def sign_and_submit_tx(
|
111
|
-
self, receiver_id, actions: List[Action], nowait=False
|
111
|
+
self, receiver_id, actions: List[Action], nowait=False, included=False
|
112
112
|
) -> Union[TransactionResult, str]:
|
113
113
|
"""
|
114
114
|
Sign transaction and send it to blockchain
|
@@ -116,6 +116,7 @@ class Account(object):
|
|
116
116
|
:param actions: list of actions
|
117
117
|
:param nowait: if nowait is True, return transaction hash, else wait execution
|
118
118
|
confirm and return TransactionResult
|
119
|
+
:param included: if included is True, return transaction hash, else wait execution
|
119
120
|
:return: transaction hash or TransactionResult
|
120
121
|
"""
|
121
122
|
if not self._signers:
|
@@ -149,7 +150,10 @@ class Account(object):
|
|
149
150
|
)
|
150
151
|
|
151
152
|
try:
|
152
|
-
if
|
153
|
+
if included:
|
154
|
+
await self._provider.send_tx_included(serialized_tx)
|
155
|
+
return trx_hash
|
156
|
+
elif nowait:
|
153
157
|
return await self._provider.send_tx(serialized_tx)
|
154
158
|
return await self._provider.send_tx_and_wait(
|
155
159
|
serialized_tx, trx_hash=trx_hash, receiver_id=receiver_id
|
@@ -211,17 +215,18 @@ class Account(object):
|
|
211
215
|
return await self._provider.get_account(self.account_id)
|
212
216
|
|
213
217
|
async def send_money(
|
214
|
-
self, account_id: str, amount: int, nowait: bool = False
|
218
|
+
self, account_id: str, amount: int, nowait: bool = False, included=False
|
215
219
|
) -> TransactionResult:
|
216
220
|
"""
|
217
221
|
Send money to account_id
|
218
222
|
:param account_id: receiver account id
|
219
223
|
:param amount: amount in yoctoNEAR
|
220
224
|
:param nowait: if nowait is True, return transaction hash, else wait execution
|
225
|
+
:param included: if included is True, return transaction hash, else wait execution
|
221
226
|
:return: transaction hash or TransactionResult
|
222
227
|
"""
|
223
228
|
return await self.sign_and_submit_tx(
|
224
|
-
account_id, [transactions.create_transfer_action(amount)], nowait
|
229
|
+
account_id, [transactions.create_transfer_action(amount)], nowait, included
|
225
230
|
)
|
226
231
|
|
227
232
|
async def function_call(
|
@@ -232,6 +237,7 @@ class Account(object):
|
|
232
237
|
gas: int = constants.DEFAULT_ATTACHED_GAS,
|
233
238
|
amount: int = 0,
|
234
239
|
nowait: bool = False,
|
240
|
+
included=False
|
235
241
|
):
|
236
242
|
"""
|
237
243
|
Call function on smart contract
|
@@ -241,6 +247,7 @@ class Account(object):
|
|
241
247
|
:param gas: amount of attachment gas. Default is 200000000000000
|
242
248
|
:param amount: amount of attachment NEAR, Default is 0
|
243
249
|
:param nowait: if nowait is True, return transaction hash, else wait execution
|
250
|
+
:param included: if included is True, return transaction hash, else wait execution
|
244
251
|
:return: transaction hash or TransactionResult
|
245
252
|
"""
|
246
253
|
ser_args = json.dumps(args).encode("utf8")
|
@@ -252,6 +259,7 @@ class Account(object):
|
|
252
259
|
)
|
253
260
|
],
|
254
261
|
nowait,
|
262
|
+
included
|
255
263
|
)
|
256
264
|
|
257
265
|
async def create_account(
|
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 (
|
@@ -109,10 +114,12 @@ 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(
|
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:
|
@@ -120,10 +127,14 @@ class JsonProvider(object):
|
|
120
127
|
rpc_addr,
|
121
128
|
json=j,
|
122
129
|
timeout=timeout,
|
123
|
-
headers={
|
130
|
+
headers={
|
131
|
+
"Referer": "https://tgapp.herewallet.app/"
|
132
|
+
}, # NEAR RPC requires Referer header
|
124
133
|
)
|
125
134
|
r.raise_for_status()
|
126
|
-
|
135
|
+
res = json.loads(await r.text())
|
136
|
+
if not broadcast:
|
137
|
+
return res
|
127
138
|
except (
|
128
139
|
RPCTimeoutError,
|
129
140
|
ClientResponseError,
|
@@ -133,6 +144,7 @@ class JsonProvider(object):
|
|
133
144
|
) as e:
|
134
145
|
logger.error(f"Rpc error: {e}")
|
135
146
|
continue
|
147
|
+
return res
|
136
148
|
|
137
149
|
@staticmethod
|
138
150
|
def get_error_from_response(content: dict):
|
@@ -156,8 +168,10 @@ class JsonProvider(object):
|
|
156
168
|
break
|
157
169
|
return error
|
158
170
|
|
159
|
-
async def json_rpc(self, method, params, timeout=TIMEOUT_WAIT_RPC):
|
160
|
-
content = await self.call_rpc_request(
|
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
|
+
)
|
161
175
|
if not content:
|
162
176
|
raise RpcEmptyResponse("RPC returned empty response")
|
163
177
|
|
@@ -173,7 +187,28 @@ class JsonProvider(object):
|
|
173
187
|
:param timeout: rpc request timeout
|
174
188
|
:return:
|
175
189
|
"""
|
176
|
-
return await self.json_rpc(
|
190
|
+
return await self.json_rpc(
|
191
|
+
"broadcast_tx_async",
|
192
|
+
[signed_tx],
|
193
|
+
timeout=timeout,
|
194
|
+
broadcast=self.allow_broadcast,
|
195
|
+
)
|
196
|
+
|
197
|
+
async def send_tx_included(
|
198
|
+
self, signed_tx: str, timeout: int = constants.TIMEOUT_WAIT_RPC
|
199
|
+
):
|
200
|
+
"""
|
201
|
+
Send a signed transaction to the network and return the hash of the transaction
|
202
|
+
:param signed_tx: base64 encoded signed transaction, str.
|
203
|
+
:param timeout: rpc request timeout
|
204
|
+
:return:
|
205
|
+
"""
|
206
|
+
return await self.json_rpc(
|
207
|
+
"send_tx",
|
208
|
+
{"signed_tx_base64": signed_tx, "wait_until": "INCLUDED_FINAL"},
|
209
|
+
timeout=timeout,
|
210
|
+
broadcast=self.allow_broadcast,
|
211
|
+
)
|
177
212
|
|
178
213
|
async def wait_for_trx(self, trx_hash, receiver_id) -> TransactionResult:
|
179
214
|
for _ in range(6):
|
@@ -207,6 +242,7 @@ class JsonProvider(object):
|
|
207
242
|
"broadcast_tx_commit",
|
208
243
|
[signed_tx],
|
209
244
|
timeout=timeout,
|
245
|
+
broadcast=self.allow_broadcast,
|
210
246
|
)
|
211
247
|
return TransactionResult(**res)
|
212
248
|
except RPCTimeoutError:
|
@@ -1,5 +1,5 @@
|
|
1
1
|
py_near/__init__.py,sha256=t5fAxjaU8dN8xpQR2vz0ZGhfTkdVy2RCbkhJhZFglk4,50
|
2
|
-
py_near/account.py,sha256
|
2
|
+
py_near/account.py,sha256=-Tmz4E03Aq4e9Ce-31s3lUyOAx5HqlGbs8PViCw8MXY,17201
|
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=
|
23
|
+
py_near/providers.py,sha256=E1FTza1IokXrFtOCPABW9UsXkgzqoTuxZfRWhCeixhk,13933
|
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.32.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
|
27
|
+
py_near-1.1.32.dist-info/METADATA,sha256=W-AOwBRd0vwecMFL7PpUtKvmKQpoR0s4HaohoV-MskI,4713
|
28
|
+
py_near-1.1.32.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
29
|
+
py_near-1.1.32.dist-info/RECORD,,
|
File without changes
|