use crate::*; use bs58; /// define cesium subcommands #[derive(Clone, Default, Debug, clap::Parser)] pub enum Subcommand { // Nothing #[default] #[clap(hide = true)] Nothing, /// Analyse a base58 pubkey and gives it in all its form Pubkey { pubkey: String }, /// Prompt for cesium input Prompt, } /// handle blockchain commands pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), GcliError> { match command { Subcommand::Nothing => {} Subcommand::Pubkey { pubkey } => { let raw_pubkey = bs58::decode(pubkey).into_vec().unwrap(); let raw_pubkey: [u8; 32] = if raw_pubkey.len() > 32 { return Err(GcliError::Input("invalid pubkey size".to_string())); } else { [vec![0; 32 - raw_pubkey.len()], raw_pubkey] .concat() .try_into() .unwrap() }; println!("Pubkey (hex): 0x{}", hex::encode(raw_pubkey)); let address: AccountId = sp_core::ed25519::Public::from_raw(raw_pubkey).into(); println!("Address (SS58): {}", address); } Subcommand::Prompt => { let pair = prompt_secret_cesium(); let public = pair.public(); println!("Pubkey: {}", bs58::encode(public).into_string()); let address: AccountId = public.into(); println!("Address: {}", address); } } Ok(()) }