From 261275c73d6076e101bba92113341af8021e0d29 Mon Sep 17 00:00:00 2001 From: Stan Bondi Date: Wed, 16 Oct 2024 13:35:57 +0400 Subject: [PATCH] clippies --- Cargo.lock | 52 ------ Cargo.toml | 2 +- .../minotari_console_wallet/Cargo.toml | 6 +- .../src/automation/commands.rs | 4 +- .../src/grpc/wallet_grpc_server.rs | 4 +- .../minotari_console_wallet/src/init/mod.rs | 2 +- .../src/ui/components/network_tab.rs | 2 +- .../src/commands/command/ban_peer.rs | 2 +- .../src/commands/command/ping_peer.rs | 2 +- .../minotari_node/src/commands/status_line.rs | 6 +- .../src/grpc/base_node_grpc_server.rs | 2 +- applications/minotari_node/src/main.rs | 6 +- applications/minotari_node/src/table.rs | 2 +- .../transaction_components/test.rs | 1 + base_layer/mmr/src/merkle_proof.rs | 20 +-- base_layer/wallet/tests/support/utils.rs | 34 ++-- .../wallet_ffi/src/ffi_basenode_state.rs | 2 +- base_layer/wallet_ffi/src/lib.rs | 155 ++++++++---------- base_layer/wallet_ffi/wallet.h | 49 ------ 19 files changed, 115 insertions(+), 238 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06ab0942d4..12dc146ce5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4514,31 +4514,6 @@ dependencies = [ "tonic 0.12.3", ] -[[package]] -name = "minotari_chat_ffi" -version = "1.7.0-pre.0" -dependencies = [ - "cbindgen", - "chrono", - "libc", - "libsqlite3-sys", - "log", - "log4rs", - "minotari_app_utilities", - "openssl", - "rand", - "tari_chat_client", - "tari_common", - "tari_common_types", - "tari_contacts", - "tari_crypto", - "tari_p2p", - "tari_shutdown", - "tari_utilities", - "thiserror", - "tokio", -] - [[package]] name = "minotari_console_wallet" version = "1.7.0-pre.0" @@ -4576,7 +4551,6 @@ dependencies = [ "tari_features", "tari_hashing", "tari_key_manager", - "tari_libtor", "tari_max_size", "tari_network", "tari_p2p", @@ -7707,32 +7681,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "tari_chat_client" -version = "1.7.0-pre.0" -dependencies = [ - "anyhow", - "async-trait", - "config", - "diesel", - "lmdb-zero", - "log", - "minotari_app_utilities", - "serde", - "tari_common", - "tari_common_sqlite", - "tari_common_types", - "tari_contacts", - "tari_max_size", - "tari_network", - "tari_p2p", - "tari_service_framework", - "tari_shutdown", - "tari_storage", - "thiserror", - "tokio", -] - [[package]] name = "tari_common" version = "1.7.0-pre.0" diff --git a/Cargo.toml b/Cargo.toml index 0b604ca311..72df515efc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [workspace] members = [ - "base_layer/chat_ffi", + # "base_layer/chat_ffi", "base_layer/core", "base_layer/common_types", "base_layer/contacts", diff --git a/applications/minotari_console_wallet/Cargo.toml b/applications/minotari_console_wallet/Cargo.toml index 8441970438..cb9b770e09 100644 --- a/applications/minotari_console_wallet/Cargo.toml +++ b/applications/minotari_console_wallet/Cargo.toml @@ -15,7 +15,7 @@ tari_common_types = { path = "../../base_layer/common_types" } tari_contacts = { path = "../../base_layer/contacts" } tari_crypto = { version = "0.21.0" } tari_key_manager = { path = "../../base_layer/key_manager" } -tari_libtor = { path = "../../infrastructure/libtor", optional = true } +#tari_libtor = { path = "../../infrastructure/libtor", optional = true } tari_max_size = { path = "../../infrastructure/max_size" } tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } tari_script = { path = "../../infrastructure/tari_script" } @@ -86,10 +86,10 @@ features = ["crossterm"] tari_features = { path = "../../common/tari_features", version = "1.7.0-pre.0" } [features] -default = ["libtor", "ledger"] +default = ["ledger"] grpc = [] ledger = ["minotari_ledger_wallet_comms", "minotari_wallet/ledger"] -libtor = ["tari_libtor"] +#libtor = ["tari_libtor"] [package.metadata.cargo-machete] # We need to specify extra features for log4rs even though it is not used directly in this crate diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index 1e9f562671..24cfe263a2 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -754,7 +754,7 @@ pub async fn command_runner( println!("Command Runner"); println!("=============="); - let (_current_index, mut peer_list) = wallet + let (_current_index, peer_list) = wallet .wallet_connectivity .get_base_node_peer_manager_state() .unwrap_or_default(); @@ -1660,7 +1660,7 @@ pub async fn command_runner( }, } - temp_ban_peers(&wallet, &mut peer_list).await; + temp_ban_peers(&wallet, &peer_list).await; unban_peer_manager_peers = true; // Read session info diff --git a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs index 0e2e3cb7f3..0d3272d0dc 100644 --- a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -891,12 +891,12 @@ impl wallet_server::Wallet for WalletGrpcServer { let mut base_node_service = self.wallet.base_node_service.clone(); let status = match conns.len() { - x if x == 0 => tari_rpc::ConnectivityStatus::Offline, + 0 => tari_rpc::ConnectivityStatus::Offline, _ => tari_rpc::ConnectivityStatus::Online, }; let resp = tari_rpc::NetworkStatusResponse { - status: tari_rpc::ConnectivityStatus::from(status) as i32, + status: status as i32, avg_latency_ms: base_node_service .get_base_node_latency() .await diff --git a/applications/minotari_console_wallet/src/init/mod.rs b/applications/minotari_console_wallet/src/init/mod.rs index 00e698ad65..4f7b46f78d 100644 --- a/applications/minotari_console_wallet/src/init/mod.rs +++ b/applications/minotari_console_wallet/src/init/mod.rs @@ -589,7 +589,7 @@ pub async fn start_wallet( })?; } else { // Set the first base node connection we get - this is typically a local base node via mDNS - match wait_for_first_base_node_connection(&wallet).await? { + match wait_for_first_base_node_connection(wallet).await? { Some(pk) => { wallet .set_base_node_peer(pk, None, Some(base_nodes.to_vec())) diff --git a/applications/minotari_console_wallet/src/ui/components/network_tab.rs b/applications/minotari_console_wallet/src/ui/components/network_tab.rs index e3dec59347..d8b4a0ba3d 100644 --- a/applications/minotari_console_wallet/src/ui/components/network_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/network_tab.rs @@ -301,7 +301,7 @@ impl NetworkTab { self.previous_public_key_field = self.public_key_field.clone(); self.previous_address_field = self.address_field.clone(); - let base_node_previous = app_state.get_previous_base_node().clone(); + let base_node_previous = app_state.get_previous_base_node(); let public_key = base_node_previous.map(|p| public_key_to_string(p.public_key())); let public_address = base_node_previous.map(display_address); self.public_key_field = public_key.unwrap_or_default(); diff --git a/applications/minotari_node/src/commands/command/ban_peer.rs b/applications/minotari_node/src/commands/command/ban_peer.rs index 347270fcd8..4c67a2b1c3 100644 --- a/applications/minotari_node/src/commands/command/ban_peer.rs +++ b/applications/minotari_node/src/commands/command/ban_peer.rs @@ -83,7 +83,7 @@ impl CommandContext { if must_ban { self.network - .ban_peer(peer_id.clone(), "UI manual ban".to_string(), Some(duration)) + .ban_peer(peer_id, "UI manual ban".to_string(), Some(duration)) .await?; println!("Peer was banned in base node."); } else { diff --git a/applications/minotari_node/src/commands/command/ping_peer.rs b/applications/minotari_node/src/commands/command/ping_peer.rs index 3c92a62cb8..b178e9089f 100644 --- a/applications/minotari_node/src/commands/command/ping_peer.rs +++ b/applications/minotari_node/src/commands/command/ping_peer.rs @@ -51,7 +51,7 @@ impl CommandContext { let mut liveness_events = self.liveness.get_event_stream(); let mut liveness = self.liveness.clone(); task::spawn(async move { - if let Err(e) = liveness.send_ping(dest_peer_id.clone()).await { + if let Err(e) = liveness.send_ping(dest_peer_id).await { println!("🏓 Ping failed to send to {}: {}", dest_peer_id, e); return; } diff --git a/applications/minotari_node/src/commands/status_line.rs b/applications/minotari_node/src/commands/status_line.rs index 188ecc6037..1656d97884 100644 --- a/applications/minotari_node/src/commands/status_line.rs +++ b/applications/minotari_node/src/commands/status_line.rs @@ -43,9 +43,9 @@ impl StatusLine { Default::default() } - pub fn add(&mut self, value: T) -> &mut Self { - self.add_field("", value) - } + // pub fn add(&mut self, value: T) -> &mut Self { + // self.add_field("", value) + // } pub fn add_field(&mut self, name: &'static str, value: T) -> &mut Self { self.fields.push((name, value.to_string())); diff --git a/applications/minotari_node/src/grpc/base_node_grpc_server.rs b/applications/minotari_node/src/grpc/base_node_grpc_server.rs index d7402e9fa5..6811c2877e 100644 --- a/applications/minotari_node/src/grpc/base_node_grpc_server.rs +++ b/applications/minotari_node/src/grpc/base_node_grpc_server.rs @@ -2143,7 +2143,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer { .map_err(|err| obscure_error_if_true(report_error_flag, Status::internal(err.to_string())))?; let status = match conns.len() { - x if x == 0 => tari_rpc::ConnectivityStatus::Offline, + 0 => tari_rpc::ConnectivityStatus::Offline, _ => tari_rpc::ConnectivityStatus::Online, }; diff --git a/applications/minotari_node/src/main.rs b/applications/minotari_node/src/main.rs index 31e7dcc0c4..86f9ff623b 100644 --- a/applications/minotari_node/src/main.rs +++ b/applications/minotari_node/src/main.rs @@ -120,9 +120,9 @@ fn main_inner() -> Result<(), ExitError> { console_subscriber::init(); } - #[cfg(all(unix, feature = "libtor"))] - let mut config = ApplicationConfig::load_from(&cfg)?; - #[cfg(not(all(unix, feature = "libtor")))] + // #[cfg(all(unix, feature = "libtor"))] + // let mut config = ApplicationConfig::load_from(&cfg)?; + // #[cfg(not(all(unix, feature = "libtor")))] let config = ApplicationConfig::load_from(&cfg)?; debug!(target: LOG_TARGET, "Using base node configuration: {:?}", config); diff --git a/applications/minotari_node/src/table.rs b/applications/minotari_node/src/table.rs index 543d94975e..83e35c7a28 100644 --- a/applications/minotari_node/src/table.rs +++ b/applications/minotari_node/src/table.rs @@ -30,7 +30,7 @@ pub struct Table<'t, 's> { is_row_count_enabled: bool, } -impl<'t, 's> Table<'t, 's> { +impl<'t> Table<'t, '_> { pub fn new() -> Self { Self { titles: None, diff --git a/base_layer/core/src/transactions/transaction_components/test.rs b/base_layer/core/src/transactions/transaction_components/test.rs index 8bf9b16822..4a53e06175 100644 --- a/base_layer/core/src/transactions/transaction_components/test.rs +++ b/base_layer/core/src/transactions/transaction_components/test.rs @@ -328,6 +328,7 @@ fn kernel_metadata() { let r = PublicKey::from_hex("5c6bfaceaa1c83fa4482a816b5f82ca3975cb9b61b6e8be4ee8f01c5f1bee561").unwrap(); let sig = Signature::new(r, s); let excess = Commitment::from_hex("e0bd3f743b566272277c357075b0584fc840d79efac49e9b3b6dbaa8a351bc0c").unwrap(); + #[allow(unused_variables)] let k = KernelBuilder::new() .with_signature(sig) .with_fee(100.into()) diff --git a/base_layer/mmr/src/merkle_proof.rs b/base_layer/mmr/src/merkle_proof.rs index d695018f03..989f0bf765 100644 --- a/base_layer/mmr/src/merkle_proof.rs +++ b/base_layer/mmr/src/merkle_proof.rs @@ -254,17 +254,15 @@ impl MerkleProof { impl Display for MerkleProof { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.write_str(&format!("MMR Size: {}\n", self.mmr_size))?; - f.write_str("Siblings:\n")?; - self.path - .iter() - .enumerate() - .fold(Ok(()), |_, (i, h)| f.write_str(&format!("{:3}: {}\n", i, h.to_hex())))?; - f.write_str("Peaks:\n")?; - self.peaks - .iter() - .enumerate() - .fold(Ok(()), |_, (i, h)| f.write_str(&format!("{:3}: {}\n", i, h.to_hex())))?; + writeln!(f, "MMR size: {}", self.mmr_size)?; + writeln!(f, "Siblings:")?; + for (i, h) in self.path.iter().enumerate() { + writeln!(f, "{:3}: {}", i, h.to_hex())?; + } + writeln!(f, "Peaks:")?; + for (i, h) in self.peaks.iter().enumerate() { + writeln!(f, "{:3}: {}", i, h.to_hex())?; + } Ok(()) } } diff --git a/base_layer/wallet/tests/support/utils.rs b/base_layer/wallet/tests/support/utils.rs index e2ff34bd37..563c85e426 100644 --- a/base_layer/wallet/tests/support/utils.rs +++ b/base_layer/wallet/tests/support/utils.rs @@ -129,20 +129,20 @@ pub async fn make_input_with_features( .unwrap() } -/// This macro unlocks a Mutex or RwLock. If the lock is -/// poisoned (i.e. panic while unlocked) the last value -/// before the panic is used. -macro_rules! acquire_lock { - ($e:expr, $m:ident) => { - match $e.$m() { - Ok(lock) => lock, - Err(poisoned) => { - log::warn!(target: "wallet", "Lock has been POISONED and will be silently recovered"); - poisoned.into_inner() - }, - } - }; - ($e:expr) => { - acquire_lock!($e, lock) - }; -} +// /// This macro unlocks a Mutex or RwLock. If the lock is +// /// poisoned (i.e. panic while unlocked) the last value +// /// before the panic is used. +// macro_rules! acquire_lock { +// ($e:expr, $m:ident) => { +// match $e.$m() { +// Ok(lock) => lock, +// Err(poisoned) => { +// log::warn!(target: "wallet", "Lock has been POISONED and will be silently recovered"); +// poisoned.into_inner() +// }, +// } +// }; +// ($e:expr) => { +// acquire_lock!($e, lock) +// }; +// } diff --git a/base_layer/wallet_ffi/src/ffi_basenode_state.rs b/base_layer/wallet_ffi/src/ffi_basenode_state.rs index 997f41c5ad..ae683e006c 100644 --- a/base_layer/wallet_ffi/src/ffi_basenode_state.rs +++ b/base_layer/wallet_ffi/src/ffi_basenode_state.rs @@ -344,7 +344,7 @@ mod tests { let original_best_block = BlockHash::zero(); let boxed_state = Box::into_raw(Box::new(TariBaseNodeState { - node_id: Some(original_node_id.clone()), + node_id: Some(original_node_id), best_block_height: 123, best_block_hash: original_best_block, best_block_timestamp: 12345, diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 4d8d1dc174..cb79b32430 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -175,8 +175,8 @@ mod callback_handler; mod enums; mod error; mod ffi_basenode_state; -#[cfg(test)] -mod output_manager_service_mock; +// #[cfg(test)] +// mod output_manager_service_mock; mod tasks; mod consts { @@ -599,7 +599,7 @@ pub unsafe extern "C" fn destroy_tari_coin_preview(p: *mut TariCoinPreview) { } } -/// -------------------------------- Strings ------------------------------------------------ /// +// -------------------------------- Strings ------------------------------------------------ /// /// Frees memory for a char array /// @@ -618,9 +618,8 @@ pub unsafe extern "C" fn string_destroy(ptr: *mut c_char) { } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- Transaction Kernel ------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- Transaction Kernel ------------------------------------- /// /// Gets the excess for a TariTransactionKernel /// @@ -741,9 +740,8 @@ pub unsafe extern "C" fn transaction_kernel_destroy(x: *mut TariTransactionKerne } } -/// -------------------------------------------------------------------------------------------- /// - -/// -------------------------------- ByteVector ------------------------------------------------ /// +// -------------------------------------------------------------------------------------------- /// +// -------------------------------- ByteVector ------------------------------------------------ /// /// Creates a ByteVector /// @@ -864,9 +862,8 @@ pub unsafe extern "C" fn byte_vector_get_length(vec: *const ByteVector, error_ou (*vec).0.len() as c_uint } -/// -------------------------------------------------------------------------------------------- /// - -/// -------------------------------- Public Key ------------------------------------------------ /// +// -------------------------------------------------------------------------------------------- /// +// -------------------------------- Public Key ------------------------------------------------ /// /// Creates a TariPublicKey from a ByteVector /// @@ -1067,9 +1064,8 @@ pub unsafe extern "C" fn public_key_from_hex(key: *const c_char, error_out: *mut } } -/// -------------------------------------------------------------------------------------------- /// - -/// -------------------------------- Tari Address ---------------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// -------------------------------- Tari Address ---------------------------------------------- /// /// Creates a TariWalletAddress from a ByteVector /// @@ -1502,9 +1498,9 @@ pub unsafe extern "C" fn byte_to_emoji(byte: u8) -> *mut c_char { CString::into_raw(result) } -/// -------------------------------------------------------------------------------------------- /// -/// -/// ------------------------------- ComAndPubSignature Signature ---------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// +// ------------------------------- ComAndPubSignature Signature ---------------------------------------/// /// Creates a TariComAndPubSignature from `u_a`. `u_x`, `u_y`, `ephemeral_pubkey` and `ephemeral_commitment_bytes` /// ByteVectors @@ -1645,9 +1641,8 @@ pub unsafe extern "C" fn commitment_and_public_signature_destroy(compub_sig: *mu } } -/// -------------------------------------------------------------------------------------------- /// - -/// -------------------------------- Unblinded utxo -------------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// -------------------------------- Unblinded utxo -------------------------------------------- /// /// Creates an unblinded output /// @@ -1925,9 +1920,8 @@ pub unsafe extern "C" fn create_tari_unblinded_output_from_json( } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- TariUnblindedOutputs ------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- TariUnblindedOutputs ------------------------------------/// /// Gets the length of TariUnblindedOutputs /// @@ -2158,8 +2152,8 @@ pub unsafe extern "C" fn wallet_import_external_utxo_as_non_rewindable( }, } } -/// -------------------------------------------------------------------------------------------- /// -/// -------------------------------- Private Key ----------------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// -------------------------------- Private Key ----------------------------------------------- /// /// Creates a TariPrivateKey from a ByteVector /// @@ -2305,8 +2299,8 @@ pub unsafe extern "C" fn private_key_from_hex(key: *const c_char, error_out: *mu } } -/// -------------------------------------------------------------------------------------------- /// -/// -------------------------------- Range Proof ----------------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// -------------------------------- Range Proof ----------------------------------------------- /// /// Creates a default TariRangeProof /// @@ -2487,8 +2481,8 @@ pub unsafe extern "C" fn range_proof_destroy(proof_ptr: *mut TariRangeProof) { } } -/// -------------------------------------------------------------------------------------------- /// -/// --------------------------------------- Covenant --------------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// --------------------------------------- Covenant --------------------------------------------/// /// Creates a TariCovenant from a ByteVector containing the covenant bytes /// @@ -2544,8 +2538,8 @@ pub unsafe extern "C" fn covenant_destroy(covenant: *mut TariCovenant) { } } -/// -------------------------------------------------------------------------------------------- /// -/// --------------------------------------- EncryptedOpenings --------------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// --------------------------------------- EncryptedOpenings --------------------------------------------/// /// Creates a TariEncryptedOpenings from a ByteVector containing the encrypted_data bytes /// @@ -2634,8 +2628,8 @@ pub unsafe extern "C" fn encrypted_data_destroy(encrypted_data: *mut TariEncrypt } } -/// -------------------------------------------------------------------------------------------- /// -/// ---------------------------------- Output Features ------------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ---------------------------------- Output Features ------------------------------------------/// /// Creates a TariOutputFeatures from byte values /// @@ -2743,9 +2737,8 @@ pub unsafe extern "C" fn output_features_destroy(output_features: *mut TariOutpu } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- Seed Words ----------------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- Seed Words ----------------------------------------------/// /// Create an empty instance of TariSeedWords /// @@ -3154,9 +3147,8 @@ pub unsafe extern "C" fn seed_words_destroy(seed_words: *mut TariSeedWords) { } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- Contact -------------------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- Contact -------------------------------------------------/// /// Creates a TariContact /// @@ -3315,9 +3307,8 @@ pub unsafe extern "C" fn contact_destroy(contact: *mut TariContact) { } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- Contacts -------------------------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- Contacts -------------------------------------------------/// /// Gets the length of TariContacts /// @@ -3402,9 +3393,8 @@ pub unsafe extern "C" fn contacts_destroy(contacts: *mut TariContacts) { } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- Contacts Liveness Data ----------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- Contacts Liveness Data ----------------------------------/// /// Gets the public_key from a TariContactsLivenessData /// @@ -3449,7 +3439,6 @@ pub unsafe extern "C" fn liveness_data_get_public_key( /// # Safety /// The ```liveness_data_destroy``` method must be called when finished with a TariContactsLivenessData to prevent a /// memory leak - #[no_mangle] pub unsafe extern "C" fn liveness_data_get_latency( liveness_data: *mut TariContactsLivenessData, @@ -3611,9 +3600,8 @@ pub unsafe extern "C" fn liveness_data_destroy(liveness_data: *mut TariContactsL drop(Box::from_raw(liveness_data)) } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- CompletedTransactions ----------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- CompletedTransactions ----------------------------------- /// /// Gets the length of a TariCompletedTransactions /// @@ -3628,7 +3616,6 @@ pub unsafe extern "C" fn liveness_data_destroy(liveness_data: *mut TariContactsL /// /// # Safety /// None -// casting here is okay as we wont have more than u32 transctions #[allow(clippy::cast_possible_truncation)] #[no_mangle] pub unsafe extern "C" fn completed_transactions_get_length( @@ -3644,6 +3631,7 @@ pub unsafe extern "C" fn completed_transactions_get_length( } else { len = (*transactions).0.len(); } + // casting here is okay as we wont have more than u32 transctions len as c_uint } @@ -3703,9 +3691,8 @@ pub unsafe extern "C" fn completed_transactions_destroy(transactions: *mut TariC } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- OutboundTransactions ------------------------------------ /// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- OutboundTransactions ------------------------------------ /// /// Gets the length of a TariPendingOutboundTransactions /// @@ -3796,9 +3783,8 @@ pub unsafe extern "C" fn pending_outbound_transactions_destroy(transactions: *mu } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- InboundTransactions ------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- InboundTransactions ------------------------------------- /// /// Gets the length of a TariPendingInboundTransactions /// @@ -3888,9 +3874,8 @@ pub unsafe extern "C" fn pending_inbound_transactions_destroy(transactions: *mut } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- CompletedTransaction ------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- CompletedTransaction ------------------------------------- /// /// Gets the TransactionID of a TariCompletedTransaction /// @@ -4454,9 +4439,8 @@ pub unsafe extern "C" fn completed_transaction_destroy(transaction: *mut TariCom } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- OutboundTransaction ------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- OutboundTransaction ------------------------------------- /// /// Gets the TransactionId of a TariPendingOutboundTransaction /// @@ -4688,9 +4672,9 @@ pub unsafe extern "C" fn pending_outbound_transaction_destroy(transaction: *mut } } -/// -------------------------------------------------------------------------------------------- /// -/// -/// ----------------------------------- InboundTransaction ------------------------------------- /// +// -------------------------------------------------------------------------------------------- /// +// +// ----------------------------------- InboundTransaction ------------------------------------- /// /// Gets the TransactionId of a TariPendingInboundTransaction /// @@ -4896,9 +4880,8 @@ pub unsafe extern "C" fn pending_inbound_transaction_destroy(transaction: *mut T } } -/// -------------------------------------------------------------------------------------------- /// - -/// ----------------------------------- Transport Send Status -----------------------------------/// +// -------------------------------------------------------------------------------------------- /// +// ----------------------------------- Transport Send Status -----------------------------------/// /// Decode the transaction send status of a TariTransactionSendStatus /// @@ -5256,9 +5239,8 @@ pub unsafe extern "C" fn transaction_send_status_destroy(status: *mut TariTransa // } // } -/// ---------------------------------------------------------------------------------------------/// - -/// ----------------------------------- CommsConfig ---------------------------------------------/// +// ---------------------------------------------------------------------------------------------/// +// ----------------------------------- CommsConfig ---------------------------------------------/// /// Creates a TariCommsConfig. The result from this function is required when initializing a TariWallet. /// @@ -5378,7 +5360,7 @@ pub unsafe extern "C" fn comms_list_connected_public_keys( for conn in connections { // TODO: We always have PeerId but not public key until the peer has identified if let Some(pk) = conn.public_key { - if let Some(pk) = pk.try_into_sr25519().ok() { + if let Ok(pk) = pk.try_into_sr25519() { public_keys.push(pk.inner_key().clone()); } } @@ -5455,9 +5437,8 @@ pub unsafe extern "C" fn public_keys_get_at( Box::into_raw(Box::new(result)) } -/// ---------------------------------------------------------------------------------------------- /// - -/// ------------------------------------- Wallet -------------------------------------------------/// +// ---------------------------------------------------------------------------------------------- /// +// ------------------------------------- Wallet -------------------------------------------------/// /// Inits logging, this function is deliberately not exposed externally in the header /// @@ -5943,7 +5924,7 @@ pub unsafe extern "C" fn wallet_create( wallet_config.set_base_path(datastore_path_string); let sql_database_path = &wallet_config.db_file; - let _ignore = fs::create_dir_all(&sql_database_path.parent().expect("root paths are not valid")); + let _ignore = fs::create_dir_all(sql_database_path.parent().expect("root paths are not valid")); debug!(target: LOG_TARGET, "Running Wallet database migrations in {}", sql_database_path.display()); @@ -6760,7 +6741,7 @@ pub unsafe extern "C" fn wallet_sign_message( return result.into_raw(); } - let secret = match (&*(*wallet).wallet.network_keypair) + let secret = match (*(*wallet).wallet.network_keypair) .clone() .try_into_sr25519() .map(|kp| kp.secret().inner_key().clone()) @@ -9095,7 +9076,7 @@ pub unsafe extern "C" fn log_debug_message(msg: *const c_char, error_out: *mut c } } -/// ------------------------------------- FeePerGramStats ------------------------------------ /// +// ------------------------------------- FeePerGramStats ------------------------------------ /// /// Get the TariFeePerGramStats from a TariWallet. /// @@ -9231,9 +9212,8 @@ pub unsafe extern "C" fn fee_per_gram_stats_destroy(fee_per_gram_stats: *mut Tar } } -/// ------------------------------------------------------------------------------------------ /// - -/// ------------------------------------- FeePerGramStat ------------------------------------- /// +// ------------------------------------------------------------------------------------------ /// +// ------------------------------------- FeePerGramStat ------------------------------------- /// /// Get the order of TariFeePerGramStat /// @@ -9412,7 +9392,7 @@ pub unsafe extern "C" fn contacts_handle_destroy(contacts_handle: *mut ContactsS /// ------------------------------------------------------------------------------------------ /// #[cfg(test)] mod test { - use std::{ffi::c_void, str::from_utf8, sync::Mutex}; + use std::{ffi::c_void, str::from_utf8, sync::Mutex, time::Duration}; use minotari_wallet::{ storage::sqlite_utilities::run_migration_and_create_sqlite_connection, @@ -12430,17 +12410,16 @@ mod test { // should not be possible to do anything with the connection. let bob_comms_dial_peer = bob_wallet_runtime.block_on(async { bob_wallet_comms.dial_peer(alice_peer_id).await.unwrap().await }); - if bob_comms_dial_peer.is_ok() { - if bob_wallet_runtime + if bob_comms_dial_peer.is_ok() && + bob_wallet_runtime .block_on(bob_wallet_comms.open_substream( alice_peer_id, // TODO: this will cause this to fail even if the peer is active &StreamProtocol::new("/test/me"), )) .is_ok() - { - panic!("Connection to Alice should not be active!"); - } + { + panic!("Connection to Alice should not be active!"); } // - Bob can still retrieve messages Alice sent diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index 33c0e6903c..ec00806363 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -432,8 +432,6 @@ void destroy_tari_coin_preview(struct TariCoinPreview *p); void string_destroy(char *ptr); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- Transaction Kernel ------------------------------------- /// * Gets the excess for a TariTransactionKernel * * ## Arguments @@ -496,8 +494,6 @@ char *transaction_kernel_get_excess_signature_hex(TariTransactionKernel *kernel, void transaction_kernel_destroy(TariTransactionKernel *x); /** - * -------------------------------------------------------------------------------------------- /// - * -------------------------------- ByteVector ------------------------------------------------ /// * Creates a ByteVector * * ## Arguments @@ -571,8 +567,6 @@ unsigned int byte_vector_get_length(const struct ByteVector *vec, int *error_out); /** - * -------------------------------------------------------------------------------------------- /// - * -------------------------------- Public Key ------------------------------------------------ /// * Creates a TariPublicKey from a ByteVector * * ## Arguments @@ -689,8 +683,6 @@ TariPublicKey *public_key_from_hex(const char *key, int *error_out); /** - * -------------------------------------------------------------------------------------------- /// - * -------------------------------- Tari Address ---------------------------------------------- /// * Creates a TariWalletAddress from a ByteVector * * ## Arguments @@ -929,9 +921,6 @@ TariWalletAddress *emoji_id_to_tari_address(const char *emoji, char *byte_to_emoji(uint8_t byte); /** - * -------------------------------------------------------------------------------------------- /// - * - * ------------------------------- ComAndPubSignature Signature ---------------------------------------/// * Creates a TariComAndPubSignature from `u_a`. `u_x`, `u_y`, `ephemeral_pubkey` and `ephemeral_commitment_bytes` * ByteVectors * @@ -974,8 +963,6 @@ TariComAndPubSignature *commitment_and_public_signature_create_from_bytes(const void commitment_and_public_signature_destroy(TariComAndPubSignature *compub_sig); /** - * -------------------------------------------------------------------------------------------- /// - * -------------------------------- Unblinded utxo -------------------------------------------- /// * Creates an unblinded output * * ## Arguments @@ -1066,8 +1053,6 @@ TariUnblindedOutput *create_tari_unblinded_output_from_json(const char *output_j int *error_out); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- TariUnblindedOutputs ------------------------------------/// * Gets the length of TariUnblindedOutputs * * ## Arguments @@ -1165,8 +1150,6 @@ unsigned long long wallet_import_external_utxo_as_non_rewindable(struct TariWall int *error_out); /** - * -------------------------------------------------------------------------------------------- /// - * -------------------------------- Private Key ----------------------------------------------- /// * Creates a TariPrivateKey from a ByteVector * * ## Arguments @@ -1249,8 +1232,6 @@ TariPrivateKey *private_key_from_hex(const char *key, int *error_out); /** - * -------------------------------------------------------------------------------------------- /// - * -------------------------------- Range Proof ----------------------------------------------- /// * Creates a default TariRangeProof * * ## Arguments @@ -1384,8 +1365,6 @@ TariCovenant *covenant_create_from_bytes(const struct ByteVector *covenant_bytes void covenant_destroy(TariCovenant *covenant); /** - * -------------------------------------------------------------------------------------------- /// - * --------------------------------------- EncryptedOpenings --------------------------------------------/// * Creates a TariEncryptedOpenings from a ByteVector containing the encrypted_data bytes * * ## Arguments @@ -1434,8 +1413,6 @@ struct ByteVector *encrypted_data_as_bytes(const TariEncryptedOpenings *encrypte void encrypted_data_destroy(TariEncryptedOpenings *encrypted_data); /** - * -------------------------------------------------------------------------------------------- /// - * ---------------------------------- Output Features ------------------------------------------/// * Creates a TariOutputFeatures from byte values * * ## Arguments @@ -1477,8 +1454,6 @@ TariOutputFeatures *output_features_create_from_bytes(unsigned char version, void output_features_destroy(TariOutputFeatures *output_features); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- Seed Words ----------------------------------------------/// * Create an empty instance of TariSeedWords * * ## Arguments @@ -1609,8 +1584,6 @@ unsigned char seed_words_push_word(struct TariSeedWords *seed_words, void seed_words_destroy(struct TariSeedWords *seed_words); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- Contact -------------------------------------------------/// * Creates a TariContact * * ## Arguments @@ -1700,8 +1673,6 @@ TariWalletAddress *contact_get_tari_address(TariContact *contact, void contact_destroy(TariContact *contact); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- Contacts -------------------------------------------------/// * Gets the length of TariContacts * * ## Arguments @@ -1753,8 +1724,6 @@ TariContact *contacts_get_at(struct TariContacts *contacts, void contacts_destroy(struct TariContacts *contacts); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- Contacts Liveness Data ----------------------------------/// * Gets the public_key from a TariContactsLivenessData * * ## Arguments @@ -1930,8 +1899,6 @@ TariCompletedTransaction *completed_transactions_get_at(struct TariCompletedTran void completed_transactions_destroy(struct TariCompletedTransactions *transactions); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- OutboundTransactions ------------------------------------ /// * Gets the length of a TariPendingOutboundTransactions * * ## Arguments @@ -1985,8 +1952,6 @@ TariPendingOutboundTransaction *pending_outbound_transactions_get_at(struct Tari void pending_outbound_transactions_destroy(struct TariPendingOutboundTransactions *transactions); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- InboundTransactions ------------------------------------- /// * Gets the length of a TariPendingInboundTransactions * * ## Arguments @@ -2040,8 +2005,6 @@ TariPendingInboundTransaction *pending_inbound_transactions_get_at(struct TariPe void pending_inbound_transactions_destroy(struct TariPendingInboundTransactions *transactions); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- CompletedTransaction ------------------------------------- /// * Gets the TransactionID of a TariCompletedTransaction * * ## Arguments @@ -2339,8 +2302,6 @@ TariCompletedTransaction *create_tari_completed_transaction_from_json(const char void completed_transaction_destroy(TariCompletedTransaction *transaction); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- OutboundTransaction ------------------------------------- /// * Gets the TransactionId of a TariPendingOutboundTransaction * * ## Arguments @@ -2485,9 +2446,6 @@ int pending_outbound_transaction_get_status(TariPendingOutboundTransaction *tran void pending_outbound_transaction_destroy(TariPendingOutboundTransaction *transaction); /** - * -------------------------------------------------------------------------------------------- /// - * - * ----------------------------------- InboundTransaction ------------------------------------- /// * Gets the TransactionId of a TariPendingInboundTransaction * * ## Arguments @@ -2616,8 +2574,6 @@ int pending_inbound_transaction_get_status(TariPendingInboundTransaction *transa void pending_inbound_transaction_destroy(TariPendingInboundTransaction *transaction); /** - * -------------------------------------------------------------------------------------------- /// - * ----------------------------------- Transport Send Status -----------------------------------/// * Decode the transaction send status of a TariTransactionSendStatus * * ## Arguments @@ -2654,8 +2610,6 @@ unsigned int transaction_send_status_decode(const TariTransactionSendStatus *sta void transaction_send_status_destroy(TariTransactionSendStatus *status); /** - * ---------------------------------------------------------------------------------------------/// - * ----------------------------------- CommsConfig ---------------------------------------------/// * Creates a TariCommsConfig. The result from this function is required when initializing a TariWallet. * * ## Arguments @@ -4031,7 +3985,6 @@ void log_debug_message(const char *msg, int *error_out); /** - * ------------------------------------- FeePerGramStats ------------------------------------ /// * Get the TariFeePerGramStats from a TariWallet. * * ## Arguments @@ -4105,8 +4058,6 @@ TariFeePerGramStat *fee_per_gram_stats_get_at(TariFeePerGramStats *fee_per_gram_ void fee_per_gram_stats_destroy(TariFeePerGramStats *fee_per_gram_stats); /** - * ------------------------------------------------------------------------------------------ /// - * ------------------------------------- FeePerGramStat ------------------------------------- /// * Get the order of TariFeePerGramStat * * ## Arguments