Skip to content

Commit 0868273

Browse files
authored
feat: improve scanning feedback (#7622)
Description --- Improve the scanning feddback <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Enhanced state inspection and logging for UTXO processing in wallet server operations, including mined and deletion status tracking. * Added Display formatting for transaction types to support improved debugging and logging output. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8aba8c1 commit 0868273

File tree

2 files changed

+107
-6
lines changed

2 files changed

+107
-6
lines changed

applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,13 +3198,53 @@ impl wallet_server::Wallet for WalletGrpcServer {
31983198
.await
31993199
.map_err(|e| Status::internal(format!("Failed to get output from Output Manager: {}", e)))?;
32003200
if !db_result.is_empty() {
3201+
let db_output = &db_result.first().expect("Should not be empty, this is checked").0;
32013202
debug_info.push(format!("UTXO with hash {} already exists in Output Manager", hex));
3202-
let tx = db_result
3203-
.first()
3204-
.expect("Should not be empty, this is checked")
3205-
.0
3206-
.received_in_tx_id
3207-
.unwrap_or_default();
3203+
match (db_output.mined_in_block, db_output.mined_timestamp) {
3204+
(Some(hash), Some(_)) => {
3205+
debug_info.push(format!("UTXO with hash {} is already mined in block: {}", hex, hash));
3206+
},
3207+
_ => {
3208+
debug_info.push(format!("UTXO with hash {} is unmined, according to wallet", hex));
3209+
},
3210+
}
3211+
match (db_output.marked_deleted_in_block, db_output.marked_deleted_at_height) {
3212+
(Some(hash), Some(height)) => {
3213+
debug_info.push(format!(
3214+
"UTXO with hash {} is marked deleted at height: {} in block: {}",
3215+
hex, height, hash
3216+
));
3217+
},
3218+
(None, None) => {},
3219+
_ => {
3220+
debug_info.push(format!("UTXO with hash {} is has inconsistent mined data", hex));
3221+
},
3222+
}
3223+
if let Some(tx_id) = db_output.received_in_tx_id {
3224+
let tx = tms.get_any_transaction(tx_id).await;
3225+
match tx {
3226+
Ok(Some(tx)) => {
3227+
debug_info.push(format!("UTXO is associated with transaction {}", tx));
3228+
},
3229+
Ok(None) => {
3230+
debug_info.push(format!(
3231+
"UTXO is associated with transaction id: {} but transaction not found in Transaction \
3232+
Service",
3233+
tx_id.as_u64()
3234+
));
3235+
},
3236+
Err(e) => {
3237+
debug_info.push(format!(
3238+
"Error fetching transaction id: {} associated with UTXO: {}: {}",
3239+
tx_id.as_u64(),
3240+
hex,
3241+
e
3242+
));
3243+
},
3244+
}
3245+
}
3246+
3247+
let tx = db_output.received_in_tx_id.unwrap_or_default();
32083248
results.push(ScanFeedback {
32093249
output_hash: hex,
32103250
is_found: true,

base_layer/wallet/src/transaction_service/storage/models.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ impl InboundTransaction {
8989
}
9090
}
9191

92+
impl Display for InboundTransaction {
93+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
94+
write!(
95+
fmt,
96+
"TxId: {}, Source: {}, Amount: {}, Status: {:?}, Timestamp: {}, Cancelled: {}",
97+
self.tx_id, self.source_address, self.amount, self.status, self.timestamp, self.cancelled
98+
)
99+
}
100+
}
101+
92102
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
93103
pub struct OutboundTransaction {
94104
pub tx_id: TxId,
@@ -166,6 +176,16 @@ impl OutboundTransaction {
166176
}
167177
}
168178

179+
impl Display for OutboundTransaction {
180+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
181+
write!(
182+
fmt,
183+
"TxId: {}, Destination: {}, Amount: {}, Fee: {}, Status: {:?}, Timestamp: {}, Cancelled: {}",
184+
self.tx_id, self.destination_address, self.amount, self.fee, self.status, self.timestamp, self.cancelled
185+
)
186+
}
187+
}
188+
169189
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
170190
pub struct CompletedTransaction {
171191
pub tx_id: TxId,
@@ -499,6 +519,37 @@ impl CompletedTransaction {
499519
}
500520
}
501521

522+
impl Display for CompletedTransaction {
523+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
524+
match self.cancelled {
525+
Some(cancelled_reason) => write!(
526+
fmt,
527+
"TxId: {}, Source: {}, Destination: {}, Amount: {}, Fee: {}, Status: {:?}, Timestamp: {}, Cancelled: \
528+
{}",
529+
self.tx_id,
530+
self.source_address,
531+
self.destination_address,
532+
self.amount,
533+
self.fee,
534+
self.status,
535+
self.timestamp,
536+
cancelled_reason,
537+
),
538+
None => write!(
539+
fmt,
540+
"TxId: {}, Source: {}, Destination: {}, Amount: {}, Fee: {}, Status: {:?}, Timestamp: {}",
541+
self.tx_id,
542+
self.source_address,
543+
self.destination_address,
544+
self.amount,
545+
self.fee,
546+
self.status,
547+
self.timestamp,
548+
),
549+
}
550+
}
551+
}
552+
502553
impl From<CompletedTransaction> for InboundTransaction {
503554
fn from(ct: CompletedTransaction) -> Self {
504555
Self {
@@ -657,6 +708,16 @@ impl From<WalletTransaction> for CompletedTransaction {
657708
}
658709
}
659710

711+
impl Display for WalletTransaction {
712+
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
713+
match self {
714+
WalletTransaction::PendingInbound(tx) => write!(fmt, "Pending Inbound Transaction: {}", tx),
715+
WalletTransaction::PendingOutbound(tx) => write!(fmt, "Pending Outbound Transaction: {}", tx),
716+
WalletTransaction::Completed(tx) => write!(fmt, "Completed Transaction: {}", tx),
717+
}
718+
}
719+
}
720+
660721
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
661722
pub enum TxCancellationReason {
662723
Unknown, // 0

0 commit comments

Comments
 (0)