mm-sol 0.5.6__py3-none-any.whl → 0.5.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.
- mm_sol/async_rpc.py +2 -2
- mm_sol/rpc_async.py +65 -0
- mm_sol/token_async.py +40 -0
- {mm_sol-0.5.6.dist-info → mm_sol-0.5.8.dist-info}/METADATA +2 -2
- {mm_sol-0.5.6.dist-info → mm_sol-0.5.8.dist-info}/RECORD +7 -5
- {mm_sol-0.5.6.dist-info → mm_sol-0.5.8.dist-info}/WHEEL +0 -0
- {mm_sol-0.5.6.dist-info → mm_sol-0.5.8.dist-info}/entry_points.txt +0 -0
mm_sol/async_rpc.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
-
from mm_std import Result,
|
|
3
|
+
from mm_std import Result, hra
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
async def rpc_call(
|
|
@@ -19,7 +19,7 @@ async def rpc_call(
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
async def _http_call(node: str, data: dict[str, object], timeout: float, proxy: str | None) -> Result[Any]:
|
|
22
|
-
res = await
|
|
22
|
+
res = await hra(node, method="POST", proxy=proxy, timeout=timeout, params=data, json_params=True)
|
|
23
23
|
try:
|
|
24
24
|
if res.is_error():
|
|
25
25
|
return res.to_err_result()
|
mm_sol/rpc_async.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from collections.abc import Sequence
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import websockets
|
|
6
|
+
from mm_std import DataResult, http_request
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def rpc_call(
|
|
10
|
+
node: str,
|
|
11
|
+
method: str,
|
|
12
|
+
params: Sequence[object],
|
|
13
|
+
timeout: float,
|
|
14
|
+
proxy: str | None,
|
|
15
|
+
id_: int = 1,
|
|
16
|
+
) -> DataResult[Any]:
|
|
17
|
+
data = {"jsonrpc": "2.0", "method": method, "params": params, "id": id_}
|
|
18
|
+
if node.startswith("http"):
|
|
19
|
+
return await _http_call(node, data, timeout, proxy)
|
|
20
|
+
return await _ws_call(node, data, timeout)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def _http_call(node: str, data: dict[str, object], timeout: float, proxy: str | None) -> DataResult[Any]:
|
|
24
|
+
res = await http_request(node, method="POST", proxy=proxy, timeout=timeout, json=data)
|
|
25
|
+
if res.is_error():
|
|
26
|
+
return res.to_data_result_err()
|
|
27
|
+
try:
|
|
28
|
+
parsed_body = res.parse_json_body()
|
|
29
|
+
err = parsed_body.get("error", {}).get("message", "")
|
|
30
|
+
if err:
|
|
31
|
+
return res.to_data_result_err(f"service_error: {err}")
|
|
32
|
+
if "result" in parsed_body:
|
|
33
|
+
return res.to_data_result_ok(parsed_body["result"])
|
|
34
|
+
return res.to_data_result_err("unknown_response")
|
|
35
|
+
except Exception as err:
|
|
36
|
+
return res.to_data_result_err(f"exception: {err}")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def _ws_call(node: str, data: dict[str, object], timeout: float) -> DataResult[Any]:
|
|
40
|
+
try:
|
|
41
|
+
async with websockets.connect(node, open_timeout=timeout) as ws:
|
|
42
|
+
await ws.send(json.dumps(data))
|
|
43
|
+
response = json.loads(await ws.recv())
|
|
44
|
+
|
|
45
|
+
err = response.get("error", {}).get("message", "")
|
|
46
|
+
if err:
|
|
47
|
+
return DataResult(err=f"service_error: {err}", data=response)
|
|
48
|
+
if "result" in response:
|
|
49
|
+
return DataResult(ok=response["result"], data=response)
|
|
50
|
+
return DataResult(err="unknown_response", data=response)
|
|
51
|
+
except TimeoutError:
|
|
52
|
+
return DataResult(err="timeout")
|
|
53
|
+
except Exception as err:
|
|
54
|
+
return DataResult(err=f"exception: {err}")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async def get_block_height(node: str, timeout: float = 10, proxy: str | None = None) -> DataResult[int]:
|
|
58
|
+
return await rpc_call(node=node, method="getBlockHeight", params=[], timeout=timeout, proxy=proxy)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def get_balance(node: str, address: str, timeout: float = 10, proxy: str | None = None) -> DataResult[int]:
|
|
62
|
+
"""Returns balance in lamports"""
|
|
63
|
+
return (await rpc_call(node=node, method="getBalance", params=[address], timeout=timeout, proxy=proxy)).map(
|
|
64
|
+
lambda r: r["value"]
|
|
65
|
+
)
|
mm_sol/token_async.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from mm_std import DataResult
|
|
3
|
+
from solana.exceptions import SolanaRpcException
|
|
4
|
+
from solana.rpc.core import RPCException
|
|
5
|
+
from solders.solders import InvalidParamsMessage, Pubkey, get_associated_token_address
|
|
6
|
+
|
|
7
|
+
from mm_sol.utils import get_async_client
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def get_token_balance(
|
|
11
|
+
node: str,
|
|
12
|
+
owner_address: str,
|
|
13
|
+
token_mint_address: str,
|
|
14
|
+
token_account: str | None = None,
|
|
15
|
+
timeout: float = 10,
|
|
16
|
+
proxy: str | None = None,
|
|
17
|
+
) -> DataResult[int]:
|
|
18
|
+
try:
|
|
19
|
+
client = get_async_client(node, proxy=proxy, timeout=timeout)
|
|
20
|
+
if not token_account:
|
|
21
|
+
token_account = str(
|
|
22
|
+
get_associated_token_address(Pubkey.from_string(owner_address), Pubkey.from_string(token_mint_address))
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
res = await client.get_token_account_balance(Pubkey.from_string(token_account))
|
|
26
|
+
|
|
27
|
+
# Sometimes it not raise an error, but it returns this :(
|
|
28
|
+
if isinstance(res, InvalidParamsMessage) and "could not find account" in res.message:
|
|
29
|
+
return DataResult(ok=0, data=res.to_json())
|
|
30
|
+
return DataResult(ok=int(res.value.amount), data=res.to_json())
|
|
31
|
+
except RPCException as e:
|
|
32
|
+
if "could not find account" in str(e):
|
|
33
|
+
return DataResult(ok=0, data={"rpc_exception": str(e)})
|
|
34
|
+
return DataResult(err="error", data={"rpc_exception": str(e)})
|
|
35
|
+
except httpx.HTTPStatusError as e:
|
|
36
|
+
return DataResult(err=f"http error: {e}")
|
|
37
|
+
except SolanaRpcException as e:
|
|
38
|
+
return DataResult(err=e.error_msg)
|
|
39
|
+
except Exception as e:
|
|
40
|
+
return DataResult(err="exception", data={"exception": str(e)})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mm-sol
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.8
|
|
4
4
|
Requires-Python: >=3.12
|
|
5
5
|
Requires-Dist: base58~=2.1.1
|
|
6
6
|
Requires-Dist: jinja2>=3.1.6
|
|
7
|
-
Requires-Dist: mm-crypto-utils>=0.2.
|
|
7
|
+
Requires-Dist: mm-crypto-utils>=0.2.13
|
|
8
8
|
Requires-Dist: mnemonic==0.21
|
|
9
9
|
Requires-Dist: socksio>=1.0.0
|
|
10
10
|
Requires-Dist: solana~=0.36.6
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
mm_sol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
mm_sol/account.py,sha256=9aDP5si-QJfSF8fz8K6geGUGh9GL83YJNkdU1qd4Xu8,4515
|
|
3
|
-
mm_sol/async_rpc.py,sha256=
|
|
3
|
+
mm_sol/async_rpc.py,sha256=3_pEu4ywBjA_ej6cX5q4WJcN1oaPDeIAFa5xNceFCGw,1406
|
|
4
4
|
mm_sol/balance.py,sha256=5sSIQbipNUeB_Hn7piwrYt-PuSEf4ZKB8puUmC986iY,5112
|
|
5
5
|
mm_sol/block.py,sha256=4Lc4TANgpGvPflVumC9MR-3vIl1dedGyci3cgzczuds,1794
|
|
6
6
|
mm_sol/constants.py,sha256=WSpfz5_cq_8XbIrNFJGu9okwbfPTL00zsyR_k9-7O0o,29
|
|
7
7
|
mm_sol/converters.py,sha256=rBxe3SIADZS8hG7TYl4FgjmvKH-ykaTmNbnWWQDiFZ4,1430
|
|
8
8
|
mm_sol/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
mm_sol/rpc.py,sha256=Tw7THbU0lShjTGNGe4-Mc6q1U5E2dgjY2LIfrMTSfeA,8057
|
|
10
|
+
mm_sol/rpc_async.py,sha256=xdvlA9RB5ZZA0lnIRvyNHOHsuIpM7iuzkFF2vKEQCGE,2474
|
|
10
11
|
mm_sol/solana_cli.py,sha256=ig3OoTvmkrl7MFQSZjRHIraLSmtse0_9kn5Nsw8_zb0,8258
|
|
11
12
|
mm_sol/token.py,sha256=O8z3UE3iZGYLWw8fnd9weYMcoQO0m88noqbRO_jntGg,1092
|
|
13
|
+
mm_sol/token_async.py,sha256=5B9sRTyUMOCmt4oj2eAPLo8vqNbs3er89Klqsb-jQSY,1613
|
|
12
14
|
mm_sol/transfer.py,sha256=taf2NTLpo-bxISeaILARXEGLldUvqvP-agp5IDva7Hw,5825
|
|
13
15
|
mm_sol/utils.py,sha256=oD06NsMSMhN6lqsM6mSgLTtiKwA1uAsen9WR82ofRTE,923
|
|
14
16
|
mm_sol/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -27,7 +29,7 @@ mm_sol/cli/cmd/wallet/keypair_cmd.py,sha256=cRHVVTs9zNYmUozZ8ZlJoutn9V6r8I1AEHBr
|
|
|
27
29
|
mm_sol/cli/cmd/wallet/mnemonic_cmd.py,sha256=IiON_fJT5AFfIr_E1LR6_iDYZ3c_jWCFc-wSYqk61V8,648
|
|
28
30
|
mm_sol/cli/examples/balances.toml,sha256=333g2EkyYBDW7OWFGMIWVZGkdFQMMo0Ag-bg-BvS4Zg,349
|
|
29
31
|
mm_sol/cli/examples/transfer.toml,sha256=kOCdmuwmhlOam4LVtlcYTKF0PoZYHWMlv9gWxNSXMOk,1624
|
|
30
|
-
mm_sol-0.5.
|
|
31
|
-
mm_sol-0.5.
|
|
32
|
-
mm_sol-0.5.
|
|
33
|
-
mm_sol-0.5.
|
|
32
|
+
mm_sol-0.5.8.dist-info/METADATA,sha256=MmEwreyEm8-zYHxk_W74OAZK_K6dUiIUN9vE2CE7G3E,321
|
|
33
|
+
mm_sol-0.5.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
34
|
+
mm_sol-0.5.8.dist-info/entry_points.txt,sha256=MrYnosumy9nsITSAw5TiR3WXDwsdoF0YvUIlZ38TLLs,46
|
|
35
|
+
mm_sol-0.5.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|