Skip to content

Commit 9c23f78

Browse files
committed
feature: warns users when torus storage doesnt exist
1 parent da3dde7 commit 9c23f78

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/torusdk/cli/_common.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
from dataclasses import dataclass
34
from getpass import getpass
@@ -17,7 +18,12 @@
1718
from torusdk.balance import dict_from_nano, from_rems, to_rems
1819
from torusdk.client import TorusClient
1920
from torusdk.errors import InvalidPasswordError, PasswordNotProvidedError
20-
from torusdk.key import load_keypair, resolve_key_ss58
21+
from torusdk.key import (
22+
is_ss58_address,
23+
key_path,
24+
load_keypair,
25+
resolve_key_ss58,
26+
)
2127
from torusdk.types.types import (
2228
AgentInfoWithOptionalBalance,
2329
Ss58Address,
@@ -66,6 +72,17 @@ def input_to_rems(value: float | None):
6672
return to_rems(value)
6773

6874

75+
def check_storage_exists(console: Console):
76+
root_path = key_path("").replace(".json", "")
77+
if not os.path.exists(root_path):
78+
console.print(
79+
"Torus storage not found. Did you run `torus key migrate` "
80+
"after updating your package?",
81+
style="bold red",
82+
)
83+
raise typer.Exit(code=1)
84+
85+
6986
@dataclass
7087
class ExtraCtxData:
7188
output_json: bool
@@ -200,6 +217,8 @@ def prompt_secret(self, message: str) -> str:
200217
)
201218

202219
def resolve_ss58(self, key: Ss58Address | Keypair | str):
220+
if isinstance(key, str) and not is_ss58_address(key):
221+
check_storage_exists(self.console_err)
203222
try:
204223
ss58 = resolve_key_ss58(key)
205224
return ss58
@@ -208,6 +227,9 @@ def resolve_ss58(self, key: Ss58Address | Keypair | str):
208227
raise typer.Exit(code=1)
209228

210229
def load_key(self, key: str, password: str | None = None) -> Keypair:
230+
root_path = key_path("").replace(".json", "")
231+
if not os.path.exists(root_path):
232+
check_storage_exists(self.console_err)
211233
try:
212234
keypair = load_keypair(
213235
key, password, password_provider=self.password_manager

0 commit comments

Comments
 (0)