Skip to content

Commit be87e39

Browse files
committed
clippy
1 parent 3827c1b commit be87e39

File tree

6 files changed

+140
-146
lines changed

6 files changed

+140
-146
lines changed

applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,25 +2652,22 @@ impl wallet_server::Wallet for WalletGrpcServer {
26522652
let mut tms = self.get_transaction_service();
26532653

26542654
// Look up current payref
2655-
let current_tx = match tms.get_transaction_by_payref(payment_ref).await {
2656-
Ok(txn) => Some(txn),
2657-
Err(_) => None,
2658-
};
2655+
let current_tx = tms.get_transaction_by_payref(payment_ref).await.ok();
26592656

26602657
// Look up historical payrefs (from reorgs)
2661-
let historical_txs = tms.get_transaction_by_historical_payref(payment_ref).await.unwrap_or_else(|e| {
2662-
debug!(
2658+
let historical_txs = tms
2659+
.get_transaction_by_historical_payref(payment_ref)
2660+
.await
2661+
.unwrap_or_else(|e| {
2662+
debug!(
26632663
target: LOG_TARGET,
26642664
"get_payment_by_reference: Error looking up historical PayRef: {e}"
26652665
);
2666-
vec![]
2667-
});
2666+
vec![]
2667+
});
26682668

26692669
if current_tx.is_none() && historical_txs.is_empty() {
2670-
return Err(Status::not_found(format!(
2671-
"PayRef {} not found",
2672-
payment_ref.to_hex()
2673-
)));
2670+
return Err(Status::not_found(format!("PayRef {} not found", payment_ref.to_hex())));
26742671
}
26752672

26762673
let transaction = current_tx.map(|txn| {
@@ -2801,10 +2798,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
28012798
};
28022799

28032800
// Fetch historical payrefs for this transaction
2804-
let historical_payment_references = match transaction_service
2805-
.get_payref_history_by_tx_id(tx_id)
2806-
.await
2807-
{
2801+
let historical_payment_references = match transaction_service.get_payref_history_by_tx_id(tx_id).await {
28082802
Ok(history) => history
28092803
.into_iter()
28102804
.map(|(output_hash, payref)| tari_rpc::HistoricalPayRef {

base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs

Lines changed: 77 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -906,73 +906,73 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase {
906906
outputs_to_receive: &[DbWalletOutput],
907907
) -> Result<(), OutputManagerStorageError> {
908908
retry_db("short_term_encumber_outputs", || {
909-
let start = Instant::now();
910-
let mut conn = self.database_connection.get_pooled_connection()?;
911-
let acquire_lock = start.elapsed();
909+
let start = Instant::now();
910+
let mut conn = self.database_connection.get_pooled_connection()?;
911+
let acquire_lock = start.elapsed();
912912

913-
let mut commitments = Vec::with_capacity(outputs_to_send.len());
914-
for output in outputs_to_send {
915-
commitments.push(output.commitment.as_bytes());
916-
}
917-
conn.transaction::<_, _, _>(|conn| {
918-
// Any output in the list without the `Unspent` or `EncumberedToBeReceived` status will invalidate the
919-
// encumberance. `EncumberedToBeReceived` outputs are allowed because they represent pending
920-
// transaction outputs that can be spent in chained transactions (e.g. user_pay_for_fee).
921-
// Any output in the list without the `Unspent` or `EncumberedToBeReceived` status will invalidate the
922-
// encumberance. `EncumberedToBeReceived` outputs are allowed because they represent pending
923-
// transaction outputs that can be spent in chained transactions (e.g. user_pay_for_fee).
924-
if !OutputSql::find_by_commitments_excluding_statuses(
925-
commitments.clone(),
926-
&[OutputStatus::Unspent, OutputStatus::EncumberedToBeReceived],
927-
conn,
928-
)?
929-
.is_empty()
930-
{
931-
return Err(OutputManagerStorageError::OutputAlreadySpent);
932-
};
933-
934-
let count = OutputSql::update_by_commitments(
935-
commitments,
936-
UpdateOutput {
937-
status: Some(OutputStatus::ShortTermEncumberedToBeSpent),
938-
spent_in_tx_id: Some(Some(tx_id)),
939-
..Default::default()
940-
},
941-
conn,
942-
)?;
943-
if count != outputs_to_send.len() {
944-
let msg = format!(
945-
"Inconsistent short term encumbering! Lengths do not match - {} vs {}",
946-
count,
947-
outputs_to_send.len()
948-
);
949-
error!(target: LOG_TARGET, "{msg}");
950-
return Err(OutputManagerStorageError::UnexpectedResult(msg));
913+
let mut commitments = Vec::with_capacity(outputs_to_send.len());
914+
for output in outputs_to_send {
915+
commitments.push(output.commitment.as_bytes());
951916
}
917+
conn.transaction::<_, _, _>(|conn| {
918+
// Any output in the list without the `Unspent` or `EncumberedToBeReceived` status will invalidate the
919+
// encumberance. `EncumberedToBeReceived` outputs are allowed because they represent pending
920+
// transaction outputs that can be spent in chained transactions (e.g. user_pay_for_fee).
921+
// Any output in the list without the `Unspent` or `EncumberedToBeReceived` status will invalidate the
922+
// encumberance. `EncumberedToBeReceived` outputs are allowed because they represent pending
923+
// transaction outputs that can be spent in chained transactions (e.g. user_pay_for_fee).
924+
if !OutputSql::find_by_commitments_excluding_statuses(
925+
commitments.clone(),
926+
&[OutputStatus::Unspent, OutputStatus::EncumberedToBeReceived],
927+
conn,
928+
)?
929+
.is_empty()
930+
{
931+
return Err(OutputManagerStorageError::OutputAlreadySpent);
932+
};
933+
934+
let count = OutputSql::update_by_commitments(
935+
commitments,
936+
UpdateOutput {
937+
status: Some(OutputStatus::ShortTermEncumberedToBeSpent),
938+
spent_in_tx_id: Some(Some(tx_id)),
939+
..Default::default()
940+
},
941+
conn,
942+
)?;
943+
if count != outputs_to_send.len() {
944+
let msg = format!(
945+
"Inconsistent short term encumbering! Lengths do not match - {} vs {}",
946+
count,
947+
outputs_to_send.len()
948+
);
949+
error!(target: LOG_TARGET, "{msg}");
950+
return Err(OutputManagerStorageError::UnexpectedResult(msg));
951+
}
952952

953-
Ok(())
954-
})?;
953+
Ok(())
954+
})?;
955955

956-
for co in outputs_to_receive {
957-
let new_output = NewOutputSql::new(
958-
co.clone(),
959-
Some(OutputStatus::ShortTermEncumberedToBeReceived),
960-
Some(tx_id),
961-
)?;
962-
new_output.commit(&mut conn)?;
963-
}
964-
if start.elapsed().as_millis() > 0 {
965-
trace!(
966-
target: LOG_TARGET,
967-
"sqlite profile - short_term_encumber_outputs (TxId: {}): lock {} + db_op {} = {} ms",
968-
tx_id,
969-
acquire_lock.as_millis(),
970-
(start.elapsed() - acquire_lock).as_millis(),
971-
start.elapsed().as_millis()
972-
);
973-
}
956+
for co in outputs_to_receive {
957+
let new_output = NewOutputSql::new(
958+
co.clone(),
959+
Some(OutputStatus::ShortTermEncumberedToBeReceived),
960+
Some(tx_id),
961+
)?;
962+
new_output.commit(&mut conn)?;
963+
}
964+
if start.elapsed().as_millis() > 0 {
965+
trace!(
966+
target: LOG_TARGET,
967+
"sqlite profile - short_term_encumber_outputs (TxId: {}): lock {} + db_op {} = {} ms",
968+
tx_id,
969+
acquire_lock.as_millis(),
970+
(start.elapsed() - acquire_lock).as_millis(),
971+
start.elapsed().as_millis()
972+
);
973+
}
974974

975-
Ok::<_, OutputManagerStorageError>(())
975+
Ok::<_, OutputManagerStorageError>(())
976976
}) // retry_db
977977
}
978978

@@ -1405,24 +1405,23 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase {
14051405
tip_height: Option<u64>,
14061406
key_manager: &KM,
14071407
) -> Result<Vec<DbWalletOutput>, OutputManagerStorageError> {
1408-
let outputs: Vec<OutputSql> =
1409-
retry_db("fetch_unspent_outputs_for_spending", || {
1410-
let start = Instant::now();
1411-
let mut conn = self.database_connection.get_pooled_connection()?;
1412-
let acquire_lock = start.elapsed();
1408+
let outputs: Vec<OutputSql> = retry_db("fetch_unspent_outputs_for_spending", || {
1409+
let start = Instant::now();
1410+
let mut conn = self.database_connection.get_pooled_connection()?;
1411+
let acquire_lock = start.elapsed();
14131412

1414-
let outputs =
1415-
OutputSql::fetch_unspent_outputs_for_spending(selection_criteria, amount, tip_height, &mut conn)?;
1413+
let outputs =
1414+
OutputSql::fetch_unspent_outputs_for_spending(selection_criteria, amount, tip_height, &mut conn)?;
14161415

1417-
trace!(
1418-
target: LOG_TARGET,
1419-
"sqlite profile - fetch_unspent_outputs_for_spending: lock {} + db_op {} = {} ms",
1420-
acquire_lock.as_millis(),
1421-
(start.elapsed() - acquire_lock).as_millis(),
1422-
start.elapsed().as_millis()
1423-
);
1424-
Ok::<_, OutputManagerStorageError>(outputs)
1425-
})?;
1416+
trace!(
1417+
target: LOG_TARGET,
1418+
"sqlite profile - fetch_unspent_outputs_for_spending: lock {} + db_op {} = {} ms",
1419+
acquire_lock.as_millis(),
1420+
(start.elapsed() - acquire_lock).as_millis(),
1421+
start.elapsed().as_millis()
1422+
);
1423+
Ok::<_, OutputManagerStorageError>(outputs)
1424+
})?;
14261425
outputs
14271426
.iter()
14281427
.map(|o| o.clone().to_db_wallet_output(key_manager))

base_layer/wallet/src/transaction_service/handle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,8 +1989,7 @@ impl TransactionServiceHandle {
19891989
.await
19901990
.inspect_err(
19911991
|e| warn!(target: LOG_TARGET, "TransactionServiceRequest::GetTransactionByHistoricalPayref({e})"),
1992-
)??
1993-
{
1992+
)?? {
19941993
TransactionServiceResponse::HistoricalPayrefTransactions(txs) => Ok(txs),
19951994
_ => Err(TransactionServiceError::UnexpectedApiResponse(
19961995
"TransactionServiceRequest::GetTransactionByHistoricalPayref".to_string(),

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

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ use zeroize::Zeroize;
5959
use crate::{
6060
schema,
6161
schema::{
62-
completed_transactions, inbound_transactions, outbound_transactions, payref_history, payrefs, scanned_blocks,
62+
completed_transactions,
63+
inbound_transactions,
64+
outbound_transactions,
65+
payref_history,
66+
payrefs,
67+
scanned_blocks,
6368
},
6469
storage::{
6570
serializers,
@@ -872,42 +877,42 @@ impl TransactionBackend for TransactionServiceSqliteDatabase {
872877
status: LegacyTransactionStatus,
873878
) -> Result<(), TransactionStorageError> {
874879
retry_db("update_mined_height", || {
875-
let start = Instant::now();
876-
let mut conn = self.database_connection.get_pooled_connection()?;
877-
let acquire_lock = start.elapsed();
878-
let status = if must_be_confirmed {
879-
status.mined_confirm()
880-
} else {
881-
status.mined_unconfirm()
882-
};
880+
let start = Instant::now();
881+
let mut conn = self.database_connection.get_pooled_connection()?;
882+
let acquire_lock = start.elapsed();
883+
let status = if must_be_confirmed {
884+
status.mined_confirm()
885+
} else {
886+
status.mined_unconfirm()
887+
};
883888

884-
match CompletedTransactionSql::update_mined_height(
885-
tx_id,
886-
status,
887-
mined_height,
888-
mined_in_block,
889-
mined_timestamp,
890-
&mut conn,
891-
) {
892-
Ok(_) => {},
893-
Err(TransactionStorageError::DieselError(DieselError::NotFound)) => {
894-
return Err(TransactionStorageError::ValueNotFound(DbKey::CompletedTransaction(
895-
tx_id,
896-
)));
897-
},
898-
Err(e) => return Err(e),
899-
}
889+
match CompletedTransactionSql::update_mined_height(
890+
tx_id,
891+
status,
892+
mined_height,
893+
mined_in_block,
894+
mined_timestamp,
895+
&mut conn,
896+
) {
897+
Ok(_) => {},
898+
Err(TransactionStorageError::DieselError(DieselError::NotFound)) => {
899+
return Err(TransactionStorageError::ValueNotFound(DbKey::CompletedTransaction(
900+
tx_id,
901+
)));
902+
},
903+
Err(e) => return Err(e),
904+
}
900905

901-
if start.elapsed().as_millis() > 0 {
902-
trace!(
903-
target: LOG_TARGET,
904-
"sqlite profile - update_mined_height: lock {} + db_op {} = {} ms",
905-
acquire_lock.as_millis(),
906-
(start.elapsed() - acquire_lock).as_millis(),
907-
start.elapsed().as_millis()
908-
);
909-
}
910-
Ok::<_, TransactionStorageError>(())
906+
if start.elapsed().as_millis() > 0 {
907+
trace!(
908+
target: LOG_TARGET,
909+
"sqlite profile - update_mined_height: lock {} + db_op {} = {} ms",
910+
acquire_lock.as_millis(),
911+
(start.elapsed() - acquire_lock).as_millis(),
912+
start.elapsed().as_millis()
913+
);
914+
}
915+
Ok::<_, TransactionStorageError>(())
911916
}) // retry_db
912917
}
913918

@@ -2857,15 +2862,16 @@ pub struct NewPayrefHistorySql {
28572862
}
28582863

28592864
impl PayrefHistorySql {
2860-
pub fn archive_from_payref(payref_sql: &PayrefSql, conn: &mut SqliteConnection) -> Result<(), TransactionStorageError> {
2865+
pub fn archive_from_payref(
2866+
payref_sql: &PayrefSql,
2867+
conn: &mut SqliteConnection,
2868+
) -> Result<(), TransactionStorageError> {
28612869
let new = NewPayrefHistorySql {
28622870
output_hash: payref_sql.output_hash.clone(),
28632871
payref: payref_sql.payref.clone(),
28642872
tx_id: payref_sql.tx_id,
28652873
};
2866-
diesel::insert_into(payref_history::table)
2867-
.values(&new)
2868-
.execute(conn)?;
2874+
diesel::insert_into(payref_history::table).values(&new).execute(conn)?;
28692875
Ok(())
28702876
}
28712877

common_sqlite/src/util/retry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub fn is_database_locked_error(err: &dyn Display) -> bool {
4848
///
4949
/// # Arguments
5050
/// * `op_name` - A label for logging which operation is being retried.
51-
/// * `f` - The closure to execute. Called repeatedly until it succeeds or
52-
/// the error is not a "database is locked" error or retries are exhausted.
51+
/// * `f` - The closure to execute. Called repeatedly until it succeeds or the error is not a "database is locked" error
52+
/// or retries are exhausted.
5353
pub fn retry_db<T, E, F>(op_name: &str, mut f: F) -> Result<T, E>
5454
where
5555
E: Display,

integration_tests/tests/steps/wallet_steps.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,9 +3568,7 @@ async fn wallet_has_payrefs_for_all_mined_transactions(world: &mut TariWorld, wa
35683568
let mut found = false;
35693569
for retry in 0..num_retries {
35703570
let resp = client
3571-
.get_transaction_pay_refs(GetTransactionPayRefsRequest {
3572-
transaction_id: *tx_id,
3573-
})
3571+
.get_transaction_pay_refs(GetTransactionPayRefsRequest { transaction_id: *tx_id })
35743572
.await;
35753573

35763574
match resp {
@@ -3587,9 +3585,7 @@ async fn wallet_has_payrefs_for_all_mined_transactions(world: &mut TariWorld, wa
35873585
},
35883586
Err(e) => {
35893587
if retry == num_retries - 1 {
3590-
panic!(
3591-
"Failed to get PayRefs for tx {tx_id} in wallet {wallet_name}: {e}"
3592-
);
3588+
panic!("Failed to get PayRefs for tx {tx_id} in wallet {wallet_name}: {e}");
35933589
}
35943590
},
35953591
}
@@ -3622,9 +3618,7 @@ async fn wallet_has_historical_payrefs(world: &mut TariWorld, wallet_name: Strin
36223618
let num_retries = TWO_MINUTES_WITH_HALF_SECOND_SLEEP;
36233619
for retry in 0..num_retries {
36243620
let resp = client
3625-
.get_transaction_pay_refs(GetTransactionPayRefsRequest {
3626-
transaction_id: *tx_id,
3627-
})
3621+
.get_transaction_pay_refs(GetTransactionPayRefsRequest { transaction_id: *tx_id })
36283622
.await;
36293623

36303624
match resp {
@@ -3643,6 +3637,8 @@ async fn wallet_has_historical_payrefs(world: &mut TariWorld, wallet_name: Strin
36433637
"Wallet {wallet_name} tx {tx_id}: waiting for historical PayRefs (retry {}/{})",
36443638
retry, num_retries
36453639
));
3640+
} else {
3641+
// clippy
36463642
}
36473643
},
36483644
Err(e) => {

0 commit comments

Comments
 (0)