fix: get-peer command works with public key again
Description
Fix regression on get-peer, arg takes (partial) node id and a public key/emojiid
Motivation and Context
get-peer should work with full pk
How Has This Been Tested?
Manually
@@ -32,7 +32,7 @@ use std::{
sync::Arc,
time::{Duration, Instant},
};
-use tari_app_utilities::consts;
+use tari_app_utilities::{consts, utilities::parse_emoji_id_or_public_key};
use tari_common::GlobalConfig;
use tari_common_types::{
emoji::EmojiId,
@@ -417,12 +417,27 @@ impl CommandHandler {
let peer_manager = self.peer_manager.clone();
self.executor.spawn(async move {
- match peer_manager.find_all_starts_with(&partial).await {
+ let peer = match peer_manager.find_all_starts_with(&partial).await {
Ok(peers) if peers.is_empty() => {
+ if let Some(pk) = parse_emoji_id_or_public_key(&original_str) {
+ if let Ok(peer) = peer_manager.find_by_public_key(&pk).await {
+ peer
+ } else {
+ println!("No peer matching '{}'", original_str);
+ return;
+ }
+ } else {
println!("No peer matching '{}'", original_str);
+ return;
+ }
},
- Ok(peers) => {
- let peer = peers.first().unwrap();
+ Ok(mut peers) => peers.remove(0),
+ Err(err) => {
+ println!("{}", err);
+ return;
+ },
+ };
+
let eid = EmojiId::from_pubkey(&peer.public_key);
println!("Emoji ID: {}", eid);
println!("Public Key: {}", peer.public_key);
@@ -443,11 +458,6 @@ impl CommandHandler {
if let Some(dt) = peer.last_seen() {
println!("Last seen: {}", dt);
}
- },
- Err(err) => {
- println!("{}", err);
- },
- }
});
}
