use anyhow::Error;
use async_trait::async_trait;
use clap::Parser;
use qrcode::{QrCode, render::unicode};
use tari_utilities::hex::Hex;
use super::{CommandContext, HandleCommand};
#[derive(Debug, Parser)]
pub struct Args {}
#[async_trait]
impl HandleCommand<Args> for CommandContext {
async fn handle_command(&mut self, _: Args) -> Result<(), Error> {
self.whoami()
}
}
impl CommandContext {
pub fn whoami(&self) -> Result<(), Error> {
println!("{}", self.base_node_identity);
let peer = format!(
"{}::{}",
self.base_node_identity.public_key().to_hex(),
self.base_node_identity
.public_addresses()
.iter()
.map(|addr| addr.to_string())
.collect::<Vec<_>>()
.join("::")
);
let network = self.config.network();
let qr_link = format!(
"tari://{}/base_nodes/add?name={}&peer={}",
network,
self.base_node_identity.node_id(),
peer
);
let code = QrCode::new(qr_link).unwrap();
let image = code
.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Dark)
.light_color(unicode::Dense1x2::Light)
.build()
.lines()
.skip(1)
.fold("".to_string(), |acc, l| format!("{acc}{l}\n"));
println!("{image}");
Ok(())
}
}