Skip to content

Commit

Permalink
feat!: change tar address to use base58 and not hex (#6372)
Browse files Browse the repository at this point in the history
Description
---
Remove hex display from tari address
Use Base 58 encoding instead. 
Keeps the network and features human readable

Motivation and Context
---
reduces the display size from 134 chars, down to 92

How Has This Been Tested?
---
unit tests and manual
  • Loading branch information
SWvheerden authored Jun 25, 2024
1 parent fbcc80c commit f42a838
Show file tree
Hide file tree
Showing 33 changed files with 421 additions and 156 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/minotari_app_utilities/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ 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) {
} else if let Ok(tari_address) = TariAddress::from_base58(key) {
Ok(Self::TariAddress(tari_address))
} else {
Err(UniIdError::UnknownIdType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.into_inner()
.recipient
.ok_or_else(|| Status::internal("Request is malformed".to_string()))?;
let address = TariAddress::from_hex(&message.address)
let address = TariAddress::from_base58(&message.address)
.map_err(|_| Status::internal("Destination address is malformed".to_string()))?;

let mut transaction_service = self.get_transaction_service();
Expand Down Expand Up @@ -496,7 +496,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
.into_iter()
.enumerate()
.map(|(idx, dest)| -> Result<_, String> {
let address = TariAddress::from_hex(&dest.address)
let address = TariAddress::from_base58(&dest.address)
.map_err(|_| format!("Destination address at index {} is malformed", idx))?;
Ok((
dest.address,
Expand Down
8 changes: 4 additions & 4 deletions applications/minotari_console_wallet/src/notifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ fn args_from_complete(tx: &CompletedTransaction, event: &str, confirmations: Opt
amount,
tx.tx_id.to_string(),
tx.message.clone(),
tx.source_address.to_hex(),
tx.destination_address.to_hex(),
tx.source_address.to_base58(),
tx.destination_address.to_base58(),
status,
excess,
public_nonce,
Expand All @@ -331,7 +331,7 @@ fn args_from_outbound(tx: &OutboundTransaction, event: &str) -> Vec<String> {
amount,
tx.tx_id.to_string(),
tx.message.clone(),
tx.destination_address.to_hex(),
tx.destination_address.to_base58(),
status,
"outbound".to_string(),
]
Expand All @@ -347,7 +347,7 @@ fn args_from_inbound(tx: &InboundTransaction, event: &str) -> Vec<String> {
amount,
tx.tx_id.to_string(),
tx.message.clone(),
tx.source_address.to_hex(),
tx.source_address.to_base58(),
status,
"inbound".to_string(),
]
Expand Down
41 changes: 13 additions & 28 deletions applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
collections::{HashMap, VecDeque},
path::PathBuf,
str::FromStr,
sync::Arc,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -61,7 +62,7 @@ use tari_core::transactions::{
weight::TransactionWeight,
};
use tari_shutdown::ShutdownSignal;
use tari_utilities::hex::{from_hex, Hex};
use tari_utilities::hex::Hex;
use tokio::{
sync::{broadcast, watch, RwLock},
task,
Expand Down Expand Up @@ -229,11 +230,7 @@ impl AppState {
pub async fn upsert_contact(&mut self, alias: String, tari_emoji: String) -> Result<(), UiError> {
let mut inner = self.inner.write().await;

let address = match TariAddress::from_emoji_string(&tari_emoji) {
Ok(address) => address,
Err(_) => TariAddress::from_bytes(&from_hex(&tari_emoji).map_err(|_| UiError::PublicKeyParseError)?)
.map_err(|_| UiError::PublicKeyParseError)?,
};
let address = TariAddress::from_str(&tari_emoji).map_err(|_| UiError::PublicKeyParseError)?;

let contact = Contact::new(alias, address, None, None, false);
inner.wallet.contacts_service.upsert_contact(contact).await?;
Expand All @@ -246,26 +243,22 @@ impl AppState {

// Return alias or pub key if the contact is not in the list.
pub fn get_alias(&self, address: &TariAddress) -> String {
let address_hex = address.to_hex();
let address_string = address.to_base58();

match self
.cached_data
.contacts
.iter()
.find(|&contact| contact.address.eq(&address_hex))
.find(|&contact| contact.address.eq(&address_string))
{
Some(contact) => contact.alias.clone(),
None => address_hex,
None => address_string,
}
}

pub async fn delete_contact(&mut self, tari_emoji: String) -> Result<(), UiError> {
let mut inner = self.inner.write().await;
let address = match TariAddress::from_emoji_string(&tari_emoji) {
Ok(address) => address,
Err(_) => TariAddress::from_bytes(&from_hex(&tari_emoji).map_err(|_| UiError::PublicKeyParseError)?)
.map_err(|_| UiError::PublicKeyParseError)?,
};
let address = TariAddress::from_str(&tari_emoji).map_err(|_| UiError::PublicKeyParseError)?;

inner.wallet.contacts_service.remove_contact(address).await?;

Expand Down Expand Up @@ -301,11 +294,7 @@ impl AppState {
result_tx: watch::Sender<UiTransactionSendStatus>,
) -> Result<(), UiError> {
let inner = self.inner.write().await;
let address = match TariAddress::from_emoji_string(&address) {
Ok(address) => address,
Err(_) => TariAddress::from_bytes(&from_hex(&address).map_err(|_| UiError::PublicKeyParseError)?)
.map_err(|_| UiError::PublicKeyParseError)?,
};
let address = TariAddress::from_str(&address).map_err(|_| UiError::PublicKeyParseError)?;

let output_features = OutputFeatures { ..Default::default() };

Expand Down Expand Up @@ -336,11 +325,7 @@ impl AppState {
result_tx: watch::Sender<UiTransactionSendStatus>,
) -> Result<(), UiError> {
let inner = self.inner.write().await;
let address = match TariAddress::from_emoji_string(&address) {
Ok(address) => address,
Err(_) => TariAddress::from_bytes(&from_hex(&address).map_err(|_| UiError::PublicKeyParseError)?)
.map_err(|_| UiError::PublicKeyParseError)?,
};
let address = TariAddress::from_str(&address).map_err(|_| UiError::PublicKeyParseError)?;
let payment_id_u64: u64 = payment_id_hex
.parse::<u64>()
.map_err(|_| UiError::HexError("Could not convert payment_id to bytes".to_string()))?;
Expand Down Expand Up @@ -912,7 +897,7 @@ impl AppStateInner {
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_id.network(),
wallet_id.address.to_hex()
wallet_id.address.to_base58()
);
let code = QrCode::new(qr_link).unwrap();
let image = code
Expand All @@ -924,7 +909,7 @@ impl AppStateInner {
.skip(1)
.fold("".to_string(), |acc, l| format!("{}{}\n", acc, l));
let identity = MyIdentity {
tari_address: wallet_id.address.to_hex(),
tari_address: wallet_id.address.to_base58(),
network_address: wallet_id
.node_identity
.public_addresses()
Expand Down Expand Up @@ -1249,7 +1234,7 @@ impl AppStateData {
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_identity.network(),
wallet_identity.address.to_hex()
wallet_identity.address.to_base58()
);
let code = QrCode::new(qr_link).unwrap();
let image = code
Expand All @@ -1262,7 +1247,7 @@ impl AppStateData {
.fold("".to_string(), |acc, l| format!("{}{}\n", acc, l));

let identity = MyIdentity {
tari_address: wallet_identity.address.to_hex(),
tari_address: wallet_identity.address.to_base58(),
network_address: wallet_identity
.node_identity
.public_addresses()
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/ui/ui_contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl From<Contact> for UiContact {
fn from(c: Contact) -> Self {
Self {
alias: c.alias,
address: c.address.to_hex(),
address: c.address.to_base58(),
emoji_id: c.address.to_emoji_string(),
last_seen: match c.last_seen {
Some(val) => DateTime::<Local>::from_naive_utc_and_offset(val, Local::now().offset().to_owned())
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,15 @@ mod test {
discover-peer f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665
send-minotari --message Our_secret! 125T \
2603fed9cf87097105913096da423ae4e3096e44a172185742ce5bc00d27016cd81118
f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb
burn-minotari --message Ups_these_funds_will_be_burned! 100T
coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499
make-it-rain --duration 100 --transactions-per-second 10 --start-amount 0.009200T --increase-amount 0T \
--start-time now --message Stressing_it_a_bit...!_(from_Feeling-a-bit-Generous) \
2603fed9cf87097105913096da423ae4e3096e44a172185742ce5bc00d27016cd81118
f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb
export-tx 123456789 --output-file pie.txt
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Default for MergeMiningProxyConfig {
coinbase_extra: "tari_merge_mining_proxy".to_string(),
network: Default::default(),
config_dir: PathBuf::from("config/merge_mining_proxy"),
wallet_payment_address: TariAddress::default().to_hex(),
wallet_payment_address: TariAddress::default().to_base58(),
stealth_payment: true,
range_proof_type: RangeProofType::RevealedValue,
}
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_miner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Default for MinerConfig {
network: Default::default(),
wait_timeout_on_error: 10,
config_dir: PathBuf::from("config/miner"),
wallet_payment_address: TariAddress::default().to_hex(),
wallet_payment_address: TariAddress::default().to_base58(),
stealth_payment: true,
range_proof_type: RangeProofType::RevealedValue,
}
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
let mut kernel_message = [0; 32];
let mut last_kernel = Default::default();
for coinbase in coinbases {
let address = TariAddress::from_hex(&coinbase.address)
let address = TariAddress::from_base58(&coinbase.address)
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
let range_proof_type = if coinbase.revealed_value_proof {
RangeProofType::RevealedValue
Expand Down Expand Up @@ -1033,7 +1033,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
let mut kernel_message = [0; 32];
let mut last_kernel = Default::default();
for coinbase in coinbases {
let address = TariAddress::from_hex(&coinbase.address)
let address = TariAddress::from_base58(&coinbase.address)
.map_err(|e| obscure_error_if_true(report_error_flag, Status::internal(e.to_string())))?;
let range_proof_type = if coinbase.revealed_value_proof {
RangeProofType::RevealedValue
Expand Down
6 changes: 4 additions & 2 deletions base_layer/chat_ffi/src/contacts_liveness_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ mod test {

#[test]
fn test_reading_address() {
let address =
TariAddress::from_hex("2603fed9cf87097105913096da423ae4e3096e44a172185742ce5bc00d27016cd81118").unwrap();
let address = TariAddress::from_base58(
"f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb",
)
.unwrap();
let liveness = ContactsLivenessData::new(
address.clone(),
Default::default(),
Expand Down
12 changes: 8 additions & 4 deletions base_layer/chat_ffi/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,14 @@ mod test {

#[test]
fn test_reading_message_address() {
let receiver_address =
TariAddress::from_hex("2602742c39084e62565e1416f9f97ff34bd91fc3ccd35bb7e6cf916cb757066c816966").unwrap();
let sender_address =
TariAddress::from_hex("2602764460f2fff434446cab6e03a5ea2a4c1dc4984c1749a4af8371ceecd8da1d0c01").unwrap();
let receiver_address = TariAddress::from_base58(
"f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb",
)
.unwrap();
let sender_address = TariAddress::from_base58(
"f425UWsDp714RiN53c1G6ek57rfFnotB5NCMyrn4iDgbR8i2sXVHa4xSsedd66o9KmkRgErQnyDdCaAdNLzcKrj7eUb",
)
.unwrap();
let message = MessageBuilder::new()
.receiver_address(receiver_address.clone())
.sender_address(sender_address.clone())
Expand Down
2 changes: 1 addition & 1 deletion base_layer/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ minotari_ledger_wallet_comms = { path = "../../applications/minotari_ledger_wall
tari_crypto = { version = "0.20.1" }
tari_utilities = { version = "0.7" }
tari_common = { path = "../../common", version = "1.0.0-pre.14" }

chacha20poly1305 = "0.10.1"
bitflags = { version = "2.4", features = ["serde"] }
borsh = "1.2"
bs58 = "0.5.1"
digest = "0.10"
newtype-ops = "0.1"
once_cell = "1.8.0"
Expand Down
Loading

0 comments on commit f42a838

Please sign in to comment.