py-near 1.1.5__py3-none-any.whl → 1.1.8__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 +36 -20
- py_near/dapps/fts.py +1 -0
- py_near/exceptions/exceptions.py +8 -2
- py_near/providers.py +2 -1
- py_near/transactions.py +27 -0
- {py_near-1.1.5.dist-info → py_near-1.1.8.dist-info}/METADATA +2 -2
- {py_near-1.1.5.dist-info → py_near-1.1.8.dist-info}/RECORD +9 -9
- {py_near-1.1.5.dist-info → py_near-1.1.8.dist-info}/LICENSE +0 -0
- {py_near-1.1.5.dist-info → py_near-1.1.8.dist-info}/WHEEL +0 -0
py_near/account.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
import asyncio
|
2
|
+
import base64
|
2
3
|
import collections
|
4
|
+
import hashlib
|
3
5
|
import json
|
6
|
+
import logging
|
4
7
|
from typing import List, Union, Dict, Optional
|
5
8
|
|
6
9
|
import base58
|
@@ -13,7 +16,7 @@ from py_near import utils
|
|
13
16
|
from py_near.dapps.ft.async_client import FT
|
14
17
|
from py_near.dapps.phone.async_client import Phone
|
15
18
|
from py_near.dapps.staking.async_client import Staking
|
16
|
-
from py_near.exceptions.
|
19
|
+
from py_near.exceptions.provider import RpcTimeoutError, InternalError
|
17
20
|
from py_near.models import (
|
18
21
|
TransactionResult,
|
19
22
|
ViewFunctionResult,
|
@@ -120,6 +123,14 @@ class Account(object):
|
|
120
123
|
await self._update_last_block_hash()
|
121
124
|
|
122
125
|
block_hash = base58.b58decode(self._latest_block_hash.encode("utf8"))
|
126
|
+
trx_hash = transactions.calc_trx_hash(
|
127
|
+
self.account_id,
|
128
|
+
pk,
|
129
|
+
receiver_id,
|
130
|
+
access_key.nonce + 1,
|
131
|
+
actions,
|
132
|
+
block_hash,
|
133
|
+
)
|
123
134
|
serialized_tx = transactions.sign_and_serialize_transaction(
|
124
135
|
self.account_id,
|
125
136
|
pk,
|
@@ -128,20 +139,23 @@ class Account(object):
|
|
128
139
|
actions,
|
129
140
|
block_hash,
|
130
141
|
)
|
142
|
+
|
131
143
|
if nowait:
|
132
144
|
return await self._provider.send_tx(serialized_tx)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
+
try:
|
146
|
+
result = await self._provider.send_tx_and_wait(serialized_tx)
|
147
|
+
return TransactionResult(**result)
|
148
|
+
except RpcTimeoutError:
|
149
|
+
for _ in range(constants.TIMEOUT_WAIT_RPC // 3):
|
150
|
+
await asyncio.sleep(3)
|
151
|
+
try:
|
152
|
+
result = await self._provider.get_tx(trx_hash, receiver_id)
|
153
|
+
except InternalError:
|
154
|
+
continue
|
155
|
+
if result:
|
156
|
+
return result
|
157
|
+
raise RpcTimeoutError("Transaction not found")
|
158
|
+
|
145
159
|
except Exception as e:
|
146
160
|
raise e
|
147
161
|
finally:
|
@@ -227,10 +241,14 @@ class Account(object):
|
|
227
241
|
:param nowait: if nowait is True, return transaction hash, else wait execution
|
228
242
|
:return: transaction hash or TransactionResult
|
229
243
|
"""
|
230
|
-
|
244
|
+
ser_args = json.dumps(args).encode("utf8")
|
231
245
|
return await self.sign_and_submit_tx(
|
232
246
|
contract_id,
|
233
|
-
[
|
247
|
+
[
|
248
|
+
transactions.create_function_call_action(
|
249
|
+
method_name, ser_args, gas, amount
|
250
|
+
)
|
251
|
+
],
|
234
252
|
nowait,
|
235
253
|
)
|
236
254
|
|
@@ -323,9 +341,7 @@ class Account(object):
|
|
323
341
|
actions = [
|
324
342
|
transactions.create_signed_delegate(delegate_action, signature),
|
325
343
|
]
|
326
|
-
return await self.sign_and_submit_tx(
|
327
|
-
delegate_action.sender_id, actions, nowait
|
328
|
-
)
|
344
|
+
return await self.sign_and_submit_tx(delegate_action.sender_id, actions, nowait)
|
329
345
|
|
330
346
|
async def deploy_contract(self, contract_code: bytes, nowait=False):
|
331
347
|
"""
|
@@ -389,14 +405,14 @@ class Account(object):
|
|
389
405
|
await self._update_last_block_hash()
|
390
406
|
|
391
407
|
private_key = ed25519.SigningKey(pk)
|
392
|
-
|
408
|
+
verifying_key = private_key.get_verifying_key()
|
393
409
|
return DelegateActionModel(
|
394
410
|
sender_id=self.account_id,
|
395
411
|
receiver_id=receiver_id,
|
396
412
|
actions=actions,
|
397
413
|
nonce=access_key.nonce + 1,
|
398
414
|
max_block_height=self._latest_block_height + 1000,
|
399
|
-
public_key=base58.b58encode(
|
415
|
+
public_key=base58.b58encode(verifying_key.to_bytes()).decode("utf-8"),
|
400
416
|
)
|
401
417
|
|
402
418
|
def sign_delegate_transaction(
|
py_near/dapps/fts.py
CHANGED
@@ -11,6 +11,7 @@ class FTS:
|
|
11
11
|
USDTe = FtModel("dac17f958d2ee523a2206206994597c13d831ec7.factory.bridge.near", 6)
|
12
12
|
DAIe = FtModel("6b175474e89094c44da98b954eedeac495271d0f.factory.bridge.near", 18)
|
13
13
|
USDCe = FtModel("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.factory.bridge.near", 6)
|
14
|
+
USDC = FtModel("17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1", 6)
|
14
15
|
AURORA = FtModel("aaaaaa20d9e0e2461697782ef11675f668207961.factory.bridge.near", 18)
|
15
16
|
WBTCe = FtModel("2260fac5e5542a773aa44fbcfedf7c193bc2c599.factory.bridge.near", 8)
|
16
17
|
ETH = FtModel("aurora", 18)
|
py_near/exceptions/exceptions.py
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
import json
|
2
2
|
from dataclasses import dataclass
|
3
3
|
|
4
|
+
from py_near.exceptions.provider import LackBalanceForState
|
5
|
+
|
4
6
|
|
5
7
|
class RpcNotAvailableError(Exception):
|
6
8
|
pass
|
7
9
|
|
8
10
|
|
9
11
|
class ActionErrorKind(Exception):
|
10
|
-
|
12
|
+
def __init__(self, **kargs):
|
13
|
+
for arg, value in kargs.items():
|
14
|
+
setattr(self, arg, value)
|
11
15
|
|
12
16
|
|
13
17
|
@dataclass
|
@@ -170,6 +174,7 @@ class NewReceiptValidationError(ActionErrorKind):
|
|
170
174
|
|
171
175
|
pass
|
172
176
|
|
177
|
+
|
173
178
|
class DelegateActionExpired(ActionErrorKind):
|
174
179
|
"""
|
175
180
|
Error occurs when a new `DelegateActionExpired` created by the `FunctionCall` action fails
|
@@ -193,7 +198,8 @@ _ERROR_TYPE_TO_EXCEPTION = {
|
|
193
198
|
"FunctionCallError": FunctionCallError,
|
194
199
|
"ExecutionError": ExecutionError,
|
195
200
|
"NewReceiptValidationError": NewReceiptValidationError,
|
196
|
-
"
|
201
|
+
"DelegateActionExpired": DelegateActionExpired,
|
202
|
+
"LackBalanceForState": LackBalanceForState,
|
197
203
|
}
|
198
204
|
|
199
205
|
|
py_near/providers.py
CHANGED
@@ -2,7 +2,7 @@ import base64
|
|
2
2
|
import json
|
3
3
|
|
4
4
|
import aiohttp
|
5
|
-
from aiohttp import ClientResponseError, ClientConnectorError
|
5
|
+
from aiohttp import ClientResponseError, ClientConnectorError, ServerDisconnectedError
|
6
6
|
from loguru import logger
|
7
7
|
|
8
8
|
from py_near.constants import TIMEOUT_WAIT_RPC
|
@@ -72,6 +72,7 @@ class JsonProvider(object):
|
|
72
72
|
RpcTimeoutError,
|
73
73
|
ClientResponseError,
|
74
74
|
ClientConnectorError,
|
75
|
+
ServerDisconnectedError,
|
75
76
|
ConnectionError,
|
76
77
|
) as e:
|
77
78
|
logger.error(f"Rpc error: {e}")
|
py_near/transactions.py
CHANGED
@@ -49,6 +49,33 @@ def sign_and_serialize_transaction(
|
|
49
49
|
return base64.b64encode(signed_trx).decode("utf-8")
|
50
50
|
|
51
51
|
|
52
|
+
def calc_trx_hash(
|
53
|
+
account_id,
|
54
|
+
private_key,
|
55
|
+
receiver_id,
|
56
|
+
nonce,
|
57
|
+
actions: List[Action],
|
58
|
+
block_hash: bytes,
|
59
|
+
) -> str:
|
60
|
+
if isinstance(private_key, str):
|
61
|
+
pk = base58.b58decode(private_key.replace("ed25519:", ""))
|
62
|
+
else:
|
63
|
+
pk = private_key
|
64
|
+
private_key = ed25519.SigningKey(pk)
|
65
|
+
|
66
|
+
transaction = Transaction(
|
67
|
+
account_id,
|
68
|
+
private_key.get_verifying_key().to_bytes(),
|
69
|
+
nonce,
|
70
|
+
receiver_id,
|
71
|
+
block_hash,
|
72
|
+
actions,
|
73
|
+
)
|
74
|
+
|
75
|
+
signed_trx = bytes(bytearray(transaction.get_hash()))
|
76
|
+
return base58.b58encode(signed_trx).decode("utf-8")
|
77
|
+
|
78
|
+
|
52
79
|
def create_create_account_action():
|
53
80
|
return CreateAccountAction()
|
54
81
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: py-near
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.8
|
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
|
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
14
14
|
Requires-Dist: aiohttp (>=3.7.4,<4.0.0)
|
15
15
|
Requires-Dist: ed25519 (>=1.5,<2.0)
|
16
|
-
Requires-Dist: py-near-primitives (>=0.2.
|
16
|
+
Requires-Dist: py-near-primitives (>=0.2.3,<0.3.0)
|
17
17
|
Description-Content-Type: text/markdown
|
18
18
|
|
19
19
|
# py-near
|
@@ -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=uCqR24QZ0AEqqvxYgRmMQa35UMWTxzbH2G-HB-K5EVU,16767
|
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
|
@@ -7,7 +7,7 @@ py_near/dapps/ft/__init__.py,sha256=hx8qh4yEs37Ul_JhDWn8LHd-9lzsaATivxKOJPaUqTE,
|
|
7
7
|
py_near/dapps/ft/async_client.py,sha256=Oir5EQOGueq0lsNn0ybe_1uvMnmV5K1m_mHFuFWIUu4,6717
|
8
8
|
py_near/dapps/ft/exceptions.py,sha256=UjXLFsDQX0vDGS9CGO7HE9XpLD0vovFNUzCb11WKAtc,92
|
9
9
|
py_near/dapps/ft/models.py,sha256=_URS8nXZvfuxjU7Ov2E-nteBak5qKtPKN3bLOR7sC9k,186
|
10
|
-
py_near/dapps/fts.py,sha256=
|
10
|
+
py_near/dapps/fts.py,sha256=ViMoQx0h-sgVTozr-JZk3hUGdGxsVP3oP3sAY8i8g5Q,946
|
11
11
|
py_near/dapps/keypom/__init__.py,sha256=6fWGxsVr_lb_wTf_MHrbwBl1fgf78b5ezmsVa3JeFjI,32
|
12
12
|
py_near/dapps/keypom/async_client.py,sha256=DS594S00xhcyvVtD1W0PjmtmT3YhvXTZZ3hskbn1-1w,1422
|
13
13
|
py_near/dapps/keypom/exceptions.py,sha256=pGz0w1Ubh2A1aHEWvUX4dVaCcO9r2Y-h2JwhBY5KJbU,45
|
@@ -21,13 +21,13 @@ py_near/dapps/staking/async_client.py,sha256=TYudiPwF4tQ03rZuWNL-PUQ2kKpx06BxWWm
|
|
21
21
|
py_near/dapps/staking/exceptions.py,sha256=UjXLFsDQX0vDGS9CGO7HE9XpLD0vovFNUzCb11WKAtc,92
|
22
22
|
py_near/dapps/staking/models.py,sha256=zC5M_pc1oMqHq4GaYif1uwFbW6acD2BsiA9rbyiaUTs,124
|
23
23
|
py_near/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
py_near/exceptions/exceptions.py,sha256=
|
24
|
+
py_near/exceptions/exceptions.py,sha256=5iOeRpoVy63hPF6PC-wQkj7k4PHsn2NtxTTl9Jkp88M,5050
|
25
25
|
py_near/exceptions/provider.py,sha256=NU_sGBVmxJbDOANl35ADxZe9fpHLvwFBk_BQNiLMhgw,7642
|
26
26
|
py_near/models.py,sha256=QKQxL1wkTKZ4MWb5dprJZYalzrvd7bHSXC3WeBujuWE,9426
|
27
|
-
py_near/providers.py,sha256=
|
28
|
-
py_near/transactions.py,sha256=
|
27
|
+
py_near/providers.py,sha256=gI_xYFr_3xMleyDkI_3LpkcW4-yaDy5QSRzZKe3FkNM,8394
|
28
|
+
py_near/transactions.py,sha256=QAXegv2JpKISk92NaChtIH6-QPHrcWbrwdKH_lH4TsU,3186
|
29
29
|
py_near/utils.py,sha256=FirRH93ydH1cwjn0-sNrZeIn3BRD6QHedrP2VkAdJ6g,126
|
30
|
-
py_near-1.1.
|
31
|
-
py_near-1.1.
|
32
|
-
py_near-1.1.
|
33
|
-
py_near-1.1.
|
30
|
+
py_near-1.1.8.dist-info/LICENSE,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
|
31
|
+
py_near-1.1.8.dist-info/METADATA,sha256=E2PQwhLLx5lC0MPOSIg5je_I5y4MAE0oUY0rM7RXwpQ,4661
|
32
|
+
py_near-1.1.8.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
33
|
+
py_near-1.1.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|