use anyhow::{Error, anyhow};
use async_trait::async_trait;
use clap::Parser;
use tari_common_types::types::{CompressedPublicKey, CompressedSignature, PrivateKey};
use tari_utilities::hex::Hex;
use super::{CommandContext, HandleCommand};
use crate::commands::parser::FromHex;
#[derive(Debug, Parser)]
pub struct Args {
public_nonce: FromHex<CompressedPublicKey>,
signature: FromHex<PrivateKey>,
}
#[async_trait]
impl HandleCommand<Args> for CommandContext {
async fn handle_command(&mut self, args: Args) -> Result<(), Error> {
let kernel_sig = CompressedSignature::new(args.public_nonce.0, args.signature.0);
self.search_kernel(kernel_sig).await
}
}
impl CommandContext {
pub async fn search_kernel(&mut self, excess_sig: CompressedSignature) -> Result<(), Error> {
let hex_sig = excess_sig.get_signature().to_hex();
let v = self
.node_service
.get_blocks_with_kernels(vec![excess_sig])
.await?
.pop()
.ok_or_else(|| anyhow!("No kernel with signature {} found", hex_sig))?;
println!("{v}");
Ok(())
}
}