From a4c5bc2c6c08a5d09b58f13ed9acf561e55478fc Mon Sep 17 00:00:00 2001 From: Brian Pearce Date: Fri, 12 Jan 2024 15:31:57 +0100 Subject: [PATCH] feat: add tari address as valid string for discovering a peer (#6075) Description --- Allow the use of a TariAddress as well as public key or node id when discovering new peers in the wallet or base node. Motivation and Context --- Easier to manage expectations. When selecting your wallet address it's shows as a TariAddress, so someone needs to be able to do something with that. How Has This Been Tested? --- locally Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify --- applications/minotari_app_utilities/src/utilities.rs | 8 ++++++++ applications/minotari_console_wallet/README.md | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/applications/minotari_app_utilities/src/utilities.rs b/applications/minotari_app_utilities/src/utilities.rs index cbc6a22438..b6daff88d2 100644 --- a/applications/minotari_app_utilities/src/utilities.rs +++ b/applications/minotari_app_utilities/src/utilities.rs @@ -27,6 +27,7 @@ use log::*; use tari_common::exit_codes::{ExitCode, ExitError}; use tari_common_types::{ emoji::EmojiId, + tari_address::TariAddress, types::{BlockHash, PublicKey}, }; use tari_comms::{peer_manager::NodeId, types::CommsPublicKey}; @@ -82,6 +83,8 @@ impl FromStr for UniPublicKey { Ok(Self(emoji_id.to_public_key())) } else if let Ok(public_key) = PublicKey::from_hex(key) { Ok(Self(public_key)) + } else if let Ok(tari_address) = TariAddress::from_hex(key) { + Ok(Self(tari_address.public_key().clone())) } else { Err(UniIdError::UnknownIdType) } @@ -98,6 +101,7 @@ impl From for PublicKey { pub enum UniNodeId { PublicKey(PublicKey), NodeId(NodeId), + TariAddress(TariAddress), } #[derive(Debug, Error)] @@ -118,6 +122,8 @@ impl FromStr for UniNodeId { Ok(Self::PublicKey(public_key)) } else if let Ok(node_id) = NodeId::from_hex(key) { Ok(Self::NodeId(node_id)) + } else if let Ok(tari_address) = TariAddress::from_hex(key) { + Ok(Self::TariAddress(tari_address)) } else { Err(UniIdError::UnknownIdType) } @@ -130,6 +136,7 @@ impl TryFrom for PublicKey { fn try_from(id: UniNodeId) -> Result { match id { UniNodeId::PublicKey(public_key) => Ok(public_key), + UniNodeId::TariAddress(tari_address) => Ok(tari_address.public_key().clone()), UniNodeId::NodeId(_) => Err(UniIdError::Nonconvertible), } } @@ -140,6 +147,7 @@ impl From for NodeId { match id { UniNodeId::PublicKey(public_key) => NodeId::from_public_key(&public_key), UniNodeId::NodeId(node_id) => node_id, + UniNodeId::TariAddress(tari_address) => NodeId::from_public_key(tari_address.public_key()), } } } diff --git a/applications/minotari_console_wallet/README.md b/applications/minotari_console_wallet/README.md index a296987fdb..69ab53b4d3 100644 --- a/applications/minotari_console_wallet/README.md +++ b/applications/minotari_console_wallet/README.md @@ -226,7 +226,7 @@ Maximum value UTXO : 5538.616395 T Discover a peer on the network by public key or emoji id. -`minotari_console_wallet --command "discover-peer "` +`minotari_console_wallet --command "discover-peer "` example output: