Unverified Commit 196b0466 authored by Vera Abramova's avatar Vera Abramova
Browse files

feat: show specs

parent 65879e0a
......@@ -378,6 +378,7 @@ impl ErrorSource for Active {
CommandNeedArgument::MetaDefaultFileName => "`-name`",
CommandNeedArgument::MetaDefaultFileVersion => "`-version`",
CommandNeedArgument::CheckFile => "check_file",
CommandNeedArgument::ShowSpecsTitle => "`show -specs`",
};
format!("{} must be followed by an agrument.", insert)
},
......@@ -1756,6 +1757,9 @@ pub enum CommandNeedArgument {
/// Command `check_file` must be followed by the file path
CheckFile,
/// Command `show -specs` must be followed by the network address book title
ShowSpecsTitle,
}
/// Unsuitable argument for the key in `generate_message` command
......
......@@ -231,7 +231,7 @@ use parser::{Command, Show};
mod remove;
use remove::remove_info;
mod show;
use show::{check_file, show_metadata, show_networks};
use show::{check_file, show_metadata, show_networks, show_specs};
mod specs;
use specs::gen_add_specs;
......@@ -242,6 +242,7 @@ pub fn full_run(command: Command) -> Result<(), ErrorActive> {
Command::Show(x) => match x {
Show::Metadata => show_metadata(),
Show::Networks => show_networks(),
Show::Specs(title) => show_specs(title),
Show::CheckFile(path) => check_file(path),
},
Command::Types => prep_types::<Active>(HOT_DB_NAME)?.write(TYLO),
......
......@@ -43,6 +43,14 @@ pub enum Command {
/// - network title as it will be displayed in Signer, from
/// [`NetworkSpecsToSend`](definitions::network_specs::NetworkSpecsToSend)
///
/// # Show network specs for a network, as they are recorded in the hot database
///
/// `$ cargo run show -specs <network address book title>`
///
/// Function prints network address book title and corresponding
/// [`NetworkSpecsToSend`](definitions::network_specs::NetworkSpecsToSend)
/// from [`SPECSTREEPREP`] tree of the hot database.
///
/// # Check external file with hex-encoded metadata
///
/// `$ cargo run check_file <path>`
......@@ -445,8 +453,13 @@ pub enum Show {
/// Show all hot database [`ADDRESS_BOOK`](constants::ADDRESS_BOOK) entries
Networks,
/// Show network specs from [`SPECSTREEPREP`](constants::SPECSTREEPREP)
/// entry. Associated data is user-entered network address book title.
Specs(String),
/// Check that external file is valid network metadata and search for
/// similar entry in hot database [`METATREE`](constants::METATREE)
/// similar entry in hot database [`METATREE`](constants::METATREE).
/// Associated data is user-provided path to the metadata file.
CheckFile(String),
}
......@@ -718,6 +731,22 @@ impl Command {
Ok(Command::Show(Show::Networks))
}
}
"-specs" => match args.next() {
Some(title) => {
if args.next().is_some() {
Err(ErrorActive::CommandParser(
CommandParser::UnexpectedKeyArgumentSequence,
))
} else {
Ok(Command::Show(Show::Specs(title)))
}
}
None => {
Err(ErrorActive::CommandParser(CommandParser::NeedArgument(
CommandNeedArgument::ShowSpecsTitle,
)))
}
},
_ => Err(ErrorActive::CommandParser(
CommandParser::UnexpectedKeyArgumentSequence,
)),
......
......@@ -8,7 +8,7 @@ use definitions::{
metadata::MetaValues,
};
use crate::helpers::{address_book_content, network_specs_from_entry};
use crate::helpers::{address_book_content, network_specs_from_entry, network_specs_from_title};
/// Display all metadata currenty stored in the hot database
///
......@@ -168,3 +168,24 @@ pub fn check_file(path: String) -> Result<(), ErrorActive> {
fn hash_string(meta: &[u8]) -> String {
hex::encode(blake2b(32, &[], meta).as_bytes())
}
/// Show network specs for user-entered address book title
pub fn show_specs(title: String) -> Result<(), ErrorActive> {
let specs = network_specs_from_title(&title)?;
println!(
"address book title: {}\nbase58 prefix: {}\ncolor: {}\ndecimals: {}\nencryption: {}\ngenesis_hash: {}\nlogo: {}\nname: {}\npath_id: {}\nsecondary_color: {}\ntitle: {}\nunit: {}",
title,
specs.base58prefix,
specs.color,
specs.decimals,
specs.encryption.show(),
hex::encode(specs.genesis_hash),
specs.logo,
specs.name,
specs.path_id,
specs.secondary_color,
specs.title,
specs.unit
);
Ok(())
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment