22import re
33import warnings
44from collections import defaultdict
5- from enum import Enum
65from typing import Any , Callable , Mapping , TypeVar
76
87from pydantic import SecretStr
98from 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+ )
1516SS58_FORMAT = 42
1617
1718
18- def extract_ipfs ():
19- pass
20-
21-
2219def 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
4441def 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
5653def 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-
9066K = TypeVar ("K" )
9167V = TypeVar ("V" )
9268Z = TypeVar ("Z" )
0 commit comments