Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tari address as valid string for discovering a peer #6075

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions applications/minotari_app_utilities/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
Expand All @@ -98,6 +101,7 @@ impl From<UniPublicKey> for PublicKey {
pub enum UniNodeId {
PublicKey(PublicKey),
NodeId(NodeId),
TariAddress(TariAddress),
}

#[derive(Debug, Error)]
Expand All @@ -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)
}
Expand All @@ -130,6 +136,7 @@ impl TryFrom<UniNodeId> for PublicKey {
fn try_from(id: UniNodeId) -> Result<Self, Self::Error> {
match id {
UniNodeId::PublicKey(public_key) => Ok(public_key),
UniNodeId::TariAddress(tari_address) => Ok(tari_address.public_key().clone()),
UniNodeId::NodeId(_) => Err(UniIdError::Nonconvertible),
}
}
Expand All @@ -140,6 +147,7 @@ impl From<UniNodeId> 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()),
}
}
}
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <public key or emoji id>"`
`minotari_console_wallet --command "discover-peer <public key or emoji id or tari address>"`

example output:

Expand Down
Loading