mm-apt 0.3.4__py3-none-any.whl → 0.4.0__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_apt/account.py +36 -0
- mm_apt/ans.py +10 -9
- mm_apt/balance.py +5 -4
- mm_apt/retry.py +2 -2
- mm_apt-0.4.0.dist-info/METADATA +5 -0
- mm_apt-0.4.0.dist-info/RECORD +10 -0
- mm_apt-0.3.4.dist-info/METADATA +0 -5
- mm_apt-0.3.4.dist-info/RECORD +0 -9
- {mm_apt-0.3.4.dist-info → mm_apt-0.4.0.dist-info}/WHEEL +0 -0
mm_apt/account.py
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
import re
|
2
|
+
|
3
|
+
# Maximum allowable Aptos account address value (256 bits)
|
4
|
+
MAX_APTOS_ADDRESS = 2**256
|
5
|
+
|
6
|
+
|
7
|
+
def is_valid_address(address: str) -> bool:
|
8
|
+
"""
|
9
|
+
Check if the address is a valid Aptos account address.
|
10
|
+
|
11
|
+
Requirements:
|
12
|
+
- Must be a 32-byte (64 hex characters) string.
|
13
|
+
- Must be an entire 64-character hex string, padded with leading zeros as needed.
|
14
|
+
- Optional '0x' or '0X' prefix is allowed.
|
15
|
+
- Numeric value must be < 2**256.
|
16
|
+
"""
|
17
|
+
# Ensure input is a string
|
18
|
+
if not isinstance(address, str):
|
19
|
+
return False
|
20
|
+
|
21
|
+
# Remove optional prefix
|
22
|
+
hex_part = address[2:] if address.startswith(("0x", "0X")) else address
|
23
|
+
|
24
|
+
# Must be exactly 64 hex characters
|
25
|
+
if len(hex_part) != 64:
|
26
|
+
return False
|
27
|
+
if not re.fullmatch(r"[0-9a-fA-F]{64}", hex_part):
|
28
|
+
return False
|
29
|
+
|
30
|
+
# Convert to integer and check range
|
31
|
+
try:
|
32
|
+
value = int(hex_part, 16)
|
33
|
+
except ValueError:
|
34
|
+
return False
|
35
|
+
|
36
|
+
return 0 <= value < MAX_APTOS_ADDRESS
|
mm_apt/ans.py
CHANGED
@@ -1,27 +1,28 @@
|
|
1
|
-
from
|
1
|
+
from mm_http import http_request
|
2
|
+
from mm_result import Result
|
2
3
|
|
3
4
|
|
4
5
|
async def address_to_name(address: str, timeout: float = 5, proxy: str | None = None) -> Result[str | None]:
|
5
6
|
url = f"https://www.aptosnames.com/api/mainnet/v1/name/{address}"
|
6
7
|
res = await http_request(url, proxy=proxy, timeout=timeout)
|
7
8
|
if res.is_err():
|
8
|
-
return res.
|
9
|
+
return res.to_result_err()
|
9
10
|
json_res = res.parse_json_body()
|
10
11
|
if res.status_code == 200 and json_res == {}:
|
11
|
-
return res.
|
12
|
+
return res.to_result_ok(None)
|
12
13
|
if "name" in json_res:
|
13
|
-
return res.
|
14
|
-
return res.
|
14
|
+
return res.to_result_ok(json_res["name"])
|
15
|
+
return res.to_result_err("unknown_response")
|
15
16
|
|
16
17
|
|
17
18
|
async def address_to_primary_name(address: str, timeout: float = 5, proxy: str | None = None) -> Result[str | None]:
|
18
19
|
url = f"https://www.aptosnames.com/api/mainnet/v1/primary-name/{address}"
|
19
20
|
res = await http_request(url, proxy=proxy, timeout=timeout)
|
20
21
|
if res.is_err():
|
21
|
-
return res.
|
22
|
+
return res.to_result_err()
|
22
23
|
json_res = res.parse_json_body()
|
23
24
|
if res.status_code == 200 and json_res == {}:
|
24
|
-
return res.
|
25
|
+
return res.to_result_ok(None)
|
25
26
|
if "name" in json_res:
|
26
|
-
return res.
|
27
|
-
return res.
|
27
|
+
return res.to_result_ok(json_res["name"])
|
28
|
+
return res.to_result_err("unknown_response")
|
mm_apt/balance.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from mm_http import http_request
|
2
|
+
from mm_result import Result
|
2
3
|
|
3
4
|
|
4
5
|
async def get_balance(node: str, account: str, coin_type: str, timeout: float = 5, proxy: str | None = None) -> Result[int]:
|
@@ -7,7 +8,7 @@ async def get_balance(node: str, account: str, coin_type: str, timeout: float =
|
|
7
8
|
try:
|
8
9
|
json_res = res.parse_json_body()
|
9
10
|
if json_res.get("error_code") == "resource_not_found":
|
10
|
-
return res.
|
11
|
-
return res.
|
11
|
+
return res.to_result_ok(0)
|
12
|
+
return res.to_result_ok(int(json_res["data"]["coin"]["value"]))
|
12
13
|
except Exception as e:
|
13
|
-
return res.
|
14
|
+
return res.to_result_err(e)
|
mm_apt/retry.py
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
mm_apt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
mm_apt/account.py,sha256=0_YyNjR3LL5EI_rCuQA5q3wTx52RyIeSIPG99CeuYNs,993
|
3
|
+
mm_apt/ans.py,sha256=r1ynL71YILm6VpYfRejf7G3Mt_5uVlvI8AXEN9qO50g,1182
|
4
|
+
mm_apt/balance.py,sha256=wy7tJCiwCyiq_GySQdV5zX9fI4jWh9vvphPDZc-dYGc,626
|
5
|
+
mm_apt/coin.py,sha256=NuVFVxDcL3acXdZBLr79dbzT44bWHZP2gtLILWxTzdE,71
|
6
|
+
mm_apt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
mm_apt/retry.py,sha256=sYfBWguuGcJMtl2b9ewvsz91t6QNt-bE3b_VBiLBV1U,439
|
8
|
+
mm_apt-0.4.0.dist-info/METADATA,sha256=xEMlxlP2SY9pF1OSWK-o9hqb7LXuj7ndLSSkARIb5o0,114
|
9
|
+
mm_apt-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
+
mm_apt-0.4.0.dist-info/RECORD,,
|
mm_apt-0.3.4.dist-info/METADATA
DELETED
mm_apt-0.3.4.dist-info/RECORD
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
mm_apt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
mm_apt/ans.py,sha256=LP9lgOW6nIC2cIWhl6iQKKMKi6I7ni2FarJ1QISyNmo,1104
|
3
|
-
mm_apt/balance.py,sha256=5GHPwxFy550FjHSTGxL3N3GcQu68nGg6RkNdl5mLimY,583
|
4
|
-
mm_apt/coin.py,sha256=NuVFVxDcL3acXdZBLr79dbzT44bWHZP2gtLILWxTzdE,71
|
5
|
-
mm_apt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
mm_apt/retry.py,sha256=ONVBcoiJRfhgTtgt5vB7-e6DOv0RBJkkKEeN-mVhqm0,434
|
7
|
-
mm_apt-0.3.4.dist-info/METADATA,sha256=kQhthNDX8gZgYaXg6QNDY6jJMm6svQiDfZzj2mFRzP0,112
|
8
|
-
mm_apt-0.3.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
-
mm_apt-0.3.4.dist-info/RECORD,,
|
File without changes
|