Skip to content

Commit da3dde7

Browse files
authored
Merge pull request #5 from renlabs-dev/dev
dev
2 parents d578b56 + e8cafd7 commit da3dde7

File tree

23 files changed

+1441
-821
lines changed

23 files changed

+1441
-821
lines changed

CHANGELOG

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 0.2.4
4+
- Overhaul in display of balances
5+
- Fixed some references to the previous codebase
6+
- New key storage format
7+
- Added `torus key migrate` to migrate keys to torus storage format
8+
- Added new proposals type: `torus proposal propose-emission`
9+
- Validates agent metadata on registration
10+
- Only asks for key passwords where keypair is needed
11+
312
## 0.2.3.1
413
- Disabling `torus misc apr`
514

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "torusdk"
3-
version = "0.2.3.1"
3+
version = "0.2.4"
44
description = "Torus network official CLI"
55
authors = ["renlabs <[email protected]>"]
66
license = "MIT"

src/torusdk/_common.py

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
import re
33
import warnings
44
from collections import defaultdict
5-
from enum import Enum
65
from typing import Any, Callable, Mapping, TypeVar
76

87
from pydantic import SecretStr
98
from pydantic_settings import BaseSettings, SettingsConfigDict
109

11-
from torusdk.balance import from_nano
12-
from torusdk.types import Ss58Address
10+
from torusdk.types.types import Ss58Address
1311

14-
IPFS_REGEX = re.compile(r"^Qm[1-9A-HJ-NP-Za-km-z]{44}$")
12+
IPFS_REGEX = re.compile(r"^Qm[1-9A-HJ-NP-Za-km-z]{44}$|bafk[1-7a-z]{52}$/i")
13+
CID_REGEX = re.compile(
14+
r"^(?:ipfs://)?(?P<cid>Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(?:/[\d\w.]+)*$"
15+
)
1516
SS58_FORMAT = 42
1617

1718

18-
def extract_ipfs():
19-
pass
20-
21-
2219
def deprecated(func: Callable[..., Any]) -> Callable[..., Any]:
2320
def wrapper(*args: Any, **kwargs: Any) -> Any:
2421
warnings.warn(
@@ -30,8 +27,8 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
3027
return wrapper
3128

3229

33-
class ComxSettings(BaseSettings):
34-
model_config = SettingsConfigDict(env_prefix="COMX_")
30+
class TorusSettings(BaseSettings):
31+
model_config = SettingsConfigDict(env_prefix="TORUS_")
3532
# TODO: improve node lists
3633
NODE_URLS: list[str] = [
3734
"wss://api.torus.network",
@@ -42,51 +39,30 @@ class ComxSettings(BaseSettings):
4239

4340

4441
def get_node_url(
45-
comx_settings: ComxSettings | None = None, *, use_testnet: bool = False
42+
torus_settings: TorusSettings | None = None, *, use_testnet: bool = False
4643
) -> str:
47-
comx_settings = comx_settings or ComxSettings()
44+
torus_settings = torus_settings or TorusSettings()
4845
match use_testnet:
4946
case True:
50-
node_url = random.choice(comx_settings.TESTNET_NODE_URLS)
47+
node_url = random.choice(torus_settings.TESTNET_NODE_URLS)
5148
case False:
52-
node_url = random.choice(comx_settings.NODE_URLS)
49+
node_url = random.choice(torus_settings.NODE_URLS)
5350
return node_url
5451

5552

5653
def get_available_nodes(
57-
comx_settings: ComxSettings | None = None, *, use_testnet: bool = False
54+
torus_settings: TorusSettings | None = None, *, use_testnet: bool = False
5855
) -> list[str]:
59-
comx_settings = comx_settings or ComxSettings()
56+
torus_settings = torus_settings or TorusSettings()
6057

6158
match use_testnet:
6259
case True:
63-
node_urls = comx_settings.TESTNET_NODE_URLS
60+
node_urls = torus_settings.TESTNET_NODE_URLS
6461
case False:
65-
node_urls = comx_settings.NODE_URLS
62+
node_urls = torus_settings.NODE_URLS
6663
return node_urls
6764

6865

69-
class BalanceUnit(str, Enum):
70-
joule = "joule"
71-
j = "j"
72-
nano = "nano"
73-
n = "n"
74-
75-
76-
def format_balance(balance: int, unit: BalanceUnit = BalanceUnit.nano) -> str:
77-
"""
78-
Formats a balance.
79-
"""
80-
81-
match unit:
82-
case BalanceUnit.nano | BalanceUnit.n:
83-
return f"{balance}"
84-
case BalanceUnit.joule | BalanceUnit.j:
85-
in_joules = from_nano(balance)
86-
round_joules = round(in_joules, 4)
87-
return f"{round_joules:,} $TORUS"
88-
89-
9066
K = TypeVar("K")
9167
V = TypeVar("V")
9268
Z = TypeVar("Z")

src/torusdk/balance.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,47 @@
1+
from enum import Enum
12
from typing import Any, TypeVar
23

34
DECIMALS = 18
4-
UNIT_NAME = "Toids"
5+
UNIT_NAME = "Rems"
56

67

7-
def from_nano(amount: int) -> float:
8+
def from_rems(amount: int) -> float:
89
"""
910
Converts from nano to j
1011
"""
1112

1213
return amount / (10**DECIMALS)
1314

1415

15-
def to_nano(amount: float) -> int:
16+
def to_rems(amount: float) -> int:
1617
"""
1718
Converts from j to nano
1819
"""
1920

2021
return int(amount * (10**DECIMALS))
2122

2223

24+
class BalanceUnit(str, Enum):
25+
joule = "rems"
26+
j = "r"
27+
nano = "torus"
28+
n = "t"
29+
30+
31+
def format_balance(balance: int, unit: BalanceUnit = BalanceUnit.nano) -> str:
32+
"""
33+
Formats a balance.
34+
"""
35+
36+
match unit:
37+
case BalanceUnit.nano | BalanceUnit.n:
38+
return f"{balance}"
39+
case BalanceUnit.joule | BalanceUnit.j:
40+
in_joules = from_rems(balance)
41+
round_joules = round(in_joules, 4)
42+
return f"{round_joules:,}" + " \u2653"
43+
44+
2345
def from_horus(amount: int, subnet_tempo: int = 100) -> float:
2446
"""
2547
Converts from horus to j
@@ -35,7 +57,7 @@ def repr_j(amount: int):
3557
E.g. "103.2J".
3658
"""
3759

38-
return f"{from_nano(amount)} {UNIT_NAME}"
60+
return f"{from_rems(amount)} {UNIT_NAME}"
3961

4062

4163
T = TypeVar("T", str, int)

0 commit comments

Comments
 (0)