py-near 1.1.30__tar.gz → 1.1.31__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.
- {py_near-1.1.30 → py_near-1.1.31}/PKG-INFO +1 -1
- {py_near-1.1.30 → py_near-1.1.31}/pyproject.toml +2 -2
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/providers.py +28 -8
- {py_near-1.1.30 → py_near-1.1.31}/LICENSE +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/README.md +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/__init__.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/account.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/constants.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/__init__.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/core.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/ft/__init__.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/ft/async_client.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/ft/exceptions.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/ft/models.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/fts.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/keypom/__init__.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/keypom/async_client.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/keypom/exceptions.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/keypom/models.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/staking/__init__.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/staking/async_client.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/staking/exceptions.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/dapps/staking/models.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/exceptions/__init__.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/exceptions/exceptions.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/exceptions/provider.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/models.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/transactions.py +0 -0
- {py_near-1.1.30 → py_near-1.1.31}/src/py_near/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "py-near"
|
3
|
-
version = "1.1.
|
3
|
+
version = "1.1.31"
|
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.
|
25
|
+
version = "1.1.31"
|
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"
|
@@ -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,12 @@ 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
|
+
)
|
177
196
|
|
178
197
|
async def wait_for_trx(self, trx_hash, receiver_id) -> TransactionResult:
|
179
198
|
for _ in range(6):
|
@@ -207,6 +226,7 @@ class JsonProvider(object):
|
|
207
226
|
"broadcast_tx_commit",
|
208
227
|
[signed_tx],
|
209
228
|
timeout=timeout,
|
229
|
+
broadcast=self.allow_broadcast,
|
210
230
|
)
|
211
231
|
return TransactionResult(**res)
|
212
232
|
except RPCTimeoutError:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|