Coverage for silkaj/blockchain/information.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-17 17:03 +0000

1# Copyright 2016-2024 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 

16import rich_click as click 

17from pendulum import from_timestamp 

18 

19from silkaj.blockchain.tools import get_head_block 

20from silkaj.constants import ALL 

21from silkaj.network import determine_endpoint 

22from silkaj.tools import get_currency_symbol 

23 

24 

25@click.command("info", help="Display information about currency") 

26def currency_info() -> None: 

27 head_block = get_head_block() 

28 ep = determine_endpoint() 

29 current_time = from_timestamp(head_block["time"], tz="local") 

30 mediantime = from_timestamp(head_block["medianTime"], tz="local") 

31 print( 

32 "Connected to node:", 

33 ep.host, 

34 ep.port, 

35 "\nCurrent block number:", 

36 head_block["number"], 

37 "\nCurrency name:", 

38 get_currency_symbol(), 

39 "\nNumber of members:", 

40 head_block["membersCount"], 

41 "\nMinimal Proof-of-Work:", 

42 head_block["powMin"], 

43 "\nCurrent time:", 

44 current_time.format(ALL), 

45 "\nMedian time:", 

46 mediantime.format(ALL), 

47 "\nDifference time:", 

48 current_time.diff_for_humans(mediantime, True), 

49 )