Skip to content
Draft
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
23 changes: 19 additions & 4 deletions crates/cli/src/commands/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use rrelayer_core::{
common_types::EvmAddress,
relayer::RelayerId,
transaction::types::{
Transaction, TransactionData, TransactionId, TransactionSpeed, TransactionValue,
Transaction, TransactionData, TransactionHash, TransactionId, TransactionSpeed,
TransactionValue,
},
};
use std::io::{self, Write};
Expand Down Expand Up @@ -218,7 +219,7 @@ async fn handle_withdraw(

println!("ERC-20 token withdrawal transaction sent..");
println!("Transaction id: {}", tx.id);
println!("Transaction hash: {}", tx.hash);
println!("Transaction hash: {}", format_transaction_hash(tx.hash));
}
None => {
let tx = client
Expand All @@ -238,7 +239,7 @@ async fn handle_withdraw(

println!("ETH withdrawal transaction sent..");
println!("Transaction id: {}", tx.id);
println!("Transaction hash: {}", tx.hash);
println!("Transaction hash: {}", format_transaction_hash(tx.hash));
}
}

Expand Down Expand Up @@ -369,11 +370,15 @@ async fn handle_send(

println!("Transaction sent..");
println!("Transaction id: {}", tx.id);
println!("Transaction hash: {}", tx.hash);
println!("Transaction hash: {}", format_transaction_hash(tx.hash));

Ok(())
}

fn format_transaction_hash(hash: Option<TransactionHash>) -> String {
hash.map_or_else(|| "<pending>".to_string(), |hash| hash.to_string())
}

async fn handle_fund(
relayer_id: &RelayerId,
amount: &str,
Expand Down Expand Up @@ -619,3 +624,13 @@ fn log_transactions(transactions: Vec<Transaction>) -> Result<(), TransactionErr
fn format_time(time: &DateTime<Utc>) -> String {
time.format("%Y-%m-%d %H:%M:%S UTC").to_string()
}

#[cfg(test)]
mod tests {
use super::format_transaction_hash;

#[test]
fn accepted_submission_without_hash_is_printed_as_pending() {
assert_eq!(format_transaction_hash(None), "<pending>");
}
}
Loading