Coverage for silkaj/account_storage.py: 91%

23 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-22 12:04 +0000

1# Copyright 2016-2025 Maël Azimi <m.a@moul.re> 

2# 

3# Silkaj is free software: you can redistribute it and/or modify 

4# it under the terms of the GNU Affero General Public License as published by 

5# the Free Software Foundation, either version 3 of the License, or 

6# (at your option) any later version. 

7# 

8# Silkaj is distributed in the hope that it will be useful, 

9# but WITHOUT ANY WARRANTY; without even the implied warranty of 

10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

11# GNU Affero General Public License for more details. 

12# 

13# You should have received a copy of the GNU Affero General Public License 

14# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. 

15 

16from pathlib import Path 

17 

18from silkaj import tools 

19from silkaj.blockchain import tools as bc_tools 

20 

21 

22class AccountStorage: 

23 xdg_data_home = ".local/share" 

24 program_name = "silkaj" 

25 revocation_file_name = "revocation.txt" 

26 authentication_v1_file_name = "authentication_file_ed25519.dewif" 

27 authentication_v2_file_name = "authentication_file_sr25519.json" 

28 

29 def __init__(self) -> None: 

30 self.account_name = tools.has_account_defined() 

31 

32 self.path = Path.home().joinpath( 

33 self.xdg_data_home, 

34 self.program_name, 

35 bc_tools.get_currency(), 

36 self.account_name, 

37 ) 

38 self.path.mkdir(parents=True, exist_ok=True) 

39 

40 def authentication_file_path(self, check_exist: bool = True) -> Path: 

41 auth_file_path = self.path.joinpath(self.authentication_v1_file_name) 

42 if check_exist and not auth_file_path.is_file(): 

43 tools.click_fail( 

44 f"{auth_file_path} not found for account name: {self.account_name}", 

45 ) 

46 return auth_file_path 

47 

48 def revocation_path(self, check_exist: bool = True) -> Path: 

49 revocation_path = self.path.joinpath(self.revocation_file_name) 

50 if check_exist and not revocation_path.is_file(): 

51 tools.click_fail( 

52 f"{revocation_path} not found for account name: {self.account_name}", 

53 ) 

54 return revocation_path