1+ import os
12import re
23from dataclasses import dataclass
34from getpass import getpass
1718from torusdk .balance import dict_from_nano , from_rems , to_rems
1819from torusdk .client import TorusClient
1920from 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+ )
2127from 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
7087class 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