Skip to content

Commit

Permalink
Merge pull request #46 from dan-da/fix_clippy_warnings_pr
Browse files Browse the repository at this point in the history
Fix clippy warnings pr
  • Loading branch information
Sword-Smith authored Sep 20, 2023
2 parents 0d2fdf1 + 54c3dd0 commit 939d392
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 34 deletions.
7 changes: 3 additions & 4 deletions src/bin/dashboard_src/history_screen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
cell::RefCell,
cmp::{max, min},
sync::{Arc, Mutex},
time::{Duration, UNIX_EPOCH},
Expand Down Expand Up @@ -33,7 +32,7 @@ pub struct HistoryScreen {
in_focus: bool,
data: Arc<std::sync::Mutex<Vec<BalanceUpdate>>>,
server: Arc<RPCClient>,
poll_thread: Option<Arc<RefCell<JoinHandle<()>>>>,
poll_thread: Option<Arc<Mutex<JoinHandle<()>>>>,
escalatable_event: Arc<std::sync::Mutex<Option<DashboardEvent>>>,
}

Expand Down Expand Up @@ -104,15 +103,15 @@ impl Screen for HistoryScreen {
let server_arc = self.server.clone();
let data_arc = self.data.clone();
let escalatable_event_arc = self.escalatable_event.clone();
self.poll_thread = Some(Arc::new(RefCell::new(tokio::spawn(async move {
self.poll_thread = Some(Arc::new(Mutex::new(tokio::spawn(async move {
HistoryScreen::run_polling_loop(server_arc, data_arc, escalatable_event_arc).await;
}))));
}

fn deactivate(&mut self) {
self.active = false;
if let Some(thread_handle) = &self.poll_thread {
thread_handle.borrow_mut().abort();
(*thread_handle.lock().unwrap()).abort();
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/bin/dashboard_src/overview_screen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::net::SocketAddr;
use std::time::SystemTime;
use std::{
cell::RefCell,
cmp::min,
sync::{Arc, Mutex},
time::Duration,
Expand Down Expand Up @@ -138,7 +137,7 @@ pub struct OverviewScreen {
in_focus: bool,
data: Arc<std::sync::Mutex<OverviewData>>,
server: Arc<RPCClient>,
poll_thread: Option<Arc<RefCell<JoinHandle<()>>>>,
poll_thread: Option<Arc<Mutex<JoinHandle<()>>>>,
escalatable_event: Arc<std::sync::Mutex<Option<DashboardEvent>>>,
}

Expand Down Expand Up @@ -259,15 +258,15 @@ impl Screen for OverviewScreen {
let server_arc = self.server.clone();
let data_arc = self.data.clone();
let escalatable_event_arc = self.escalatable_event.clone();
self.poll_thread = Some(Arc::new(RefCell::new(tokio::spawn(async move {
self.poll_thread = Some(Arc::new(Mutex::new(tokio::spawn(async move {
OverviewScreen::run_polling_loop(server_arc, data_arc, escalatable_event_arc).await;
}))));
}

fn deactivate(&mut self) {
self.active = false;
if let Some(thread_handle) = &self.poll_thread {
thread_handle.borrow_mut().abort();
(*thread_handle.lock().unwrap()).abort();
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/bin/dashboard_src/peers_screen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
cell::RefCell,
cmp::{max, min},
sync::{Arc, Mutex},
time::Duration,
Expand Down Expand Up @@ -27,7 +26,7 @@ pub struct PeersScreen {
in_focus: bool,
data: Arc<std::sync::Mutex<Vec<PeerInfo>>>,
server: Arc<RPCClient>,
poll_thread: Option<Arc<RefCell<JoinHandle<()>>>>,
poll_thread: Option<Arc<Mutex<JoinHandle<()>>>>,
escalatable_event: Arc<std::sync::Mutex<Option<DashboardEvent>>>,
}

Expand Down Expand Up @@ -113,15 +112,15 @@ impl Screen for PeersScreen {
let server_arc = self.server.clone();
let data_arc = self.data.clone();
let escalatable_event_arc = self.escalatable_event.clone();
self.poll_thread = Some(Arc::new(RefCell::new(tokio::spawn(async move {
self.poll_thread = Some(Arc::new(Mutex::new(tokio::spawn(async move {
PeersScreen::run_polling_loop(server_arc, data_arc, escalatable_event_arc).await;
}))));
}

fn deactivate(&mut self) {
self.active = false;
if let Some(thread_handle) = &self.poll_thread {
thread_handle.borrow_mut().abort();
(*thread_handle.lock().unwrap()).abort();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ impl MainLoopHandler {

// List of digests, ordered after which block we would like to find descendents from,
// from highest to lowest.
let most_canonical_digests = vec![vec![tip_digest], most_canonical_digests].concat();
let most_canonical_digests = [vec![tip_digest], most_canonical_digests].concat();

// Send message to the relevant peer loop to request the blocks
let chosen_peer = chosen_peer.unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/models/blockchain/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ impl Transaction {
};

let merged_kernel = TransactionKernel {
inputs: vec![self.kernel.inputs, other.kernel.inputs].concat(),
outputs: vec![self.kernel.outputs, other.kernel.outputs].concat(),
pubscript_hashes_and_inputs: vec![
inputs: [self.kernel.inputs, other.kernel.inputs].concat(),
outputs: [self.kernel.outputs, other.kernel.outputs].concat(),
pubscript_hashes_and_inputs: [
self.kernel.pubscript_hashes_and_inputs,
other.kernel.pubscript_hashes_and_inputs,
]
Expand All @@ -291,27 +291,27 @@ impl Transaction {
let merged_witness = match (&self.witness, &other.witness) {
(Witness::Primitive(self_witness), Witness::Primitive(other_witness)) => {
Witness::Primitive(PrimitiveWitness {
input_utxos: vec![
input_utxos: [
self_witness.input_utxos.clone(),
other_witness.input_utxos.clone(),
]
.concat(),
lock_script_witnesses: vec![
lock_script_witnesses: [
self_witness.lock_script_witnesses.clone(),
other_witness.lock_script_witnesses.clone(),
]
.concat(),
input_membership_proofs: vec![
input_membership_proofs: [
self_witness.input_membership_proofs.clone(),
other_witness.input_membership_proofs.clone(),
]
.concat(),
output_utxos: vec![
output_utxos: [
self_witness.output_utxos.clone(),
other_witness.output_utxos.clone(),
]
.concat(),
pubscripts: vec![
pubscripts: [
self_witness.pubscripts.clone(),
other_witness.pubscripts.clone(),
]
Expand Down
4 changes: 2 additions & 2 deletions src/models/blockchain/transaction/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl LockScript {
pub fn anyone_can_spend() -> Self {
Self {
program: Program::new(
&vec![triton_asm![read_io; DIGEST_LENGTH], triton_asm!(halt)].concat(),
&[triton_asm![read_io; DIGEST_LENGTH], triton_asm!(halt)].concat(),
),
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ mod utxo_tests {
.filter(|name| !difficult_instructions.contains(name))
.collect_vec();

let generators = vec![vec!["simple"], difficult_instructions].concat();
let generators = [vec!["simple"], difficult_instructions].concat();
// Test difficult instructions more frequently.
let weights = vec![simple_instructions.len(), 2, 6, 6, 2, 10];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ mod tests {
// test against rust shadow
let rust_index_sets = items
.into_iter()
.zip(membership_proofs.into_iter())
.zip(membership_proofs)
.map(|(item, mp)| {
get_swbf_indices::<Hash>(
&item,
Expand Down
2 changes: 1 addition & 1 deletion src/models/state/archival_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ impl ArchivalState {
block_db_lock,
)
};
let forwards = vec![forwards, vec![new_block.hash]].concat();
let forwards = [forwards, vec![new_block.hash]].concat();

for digest in backwards {
// Roll back mutator set
Expand Down
4 changes: 2 additions & 2 deletions src/models/state/wallet/address/generation_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl ReceivingAddress {
let mut ciphertext = vec![GENERATION_FLAG, self.receiver_identifier];
ciphertext.append(&mut self.encrypt(utxo, sender_randomness)?);

let pubscript = vec![triton_asm![read_io; ciphertext.len()], triton_asm!(halt)].concat();
let pubscript = [triton_asm![read_io; ciphertext.len()], triton_asm!(halt)].concat();

Ok((pubscript.into(), ciphertext))
}
Expand Down Expand Up @@ -379,7 +379,7 @@ impl ReceivingAddress {
// ]
// .concat();

let mut instructions = vec![
let mut instructions = [
vec![triton_instr!(divine); DIGEST_LENGTH],
triton_asm!(hash),
vec![triton_instr!(pop); DIGEST_LENGTH],
Expand Down
2 changes: 1 addition & 1 deletion src/models/state/wallet/wallet_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl WalletState {
// TODO: These spending keys should probably be derived dynamically from some
// state in the wallet. And we should allow for other types than just generation
// addresses.
let spending_keys = vec![self.wallet_secret.nth_generation_spending_key(0)];
let spending_keys = [self.wallet_secret.nth_generation_spending_key(0)];

// get recognized UTXOs
let recognized_utxos = spending_keys
Expand Down
2 changes: 1 addition & 1 deletion src/util_types/mutator_set/ms_membership_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<H: AlgebraicHasher + BFieldCodec> MsMembershipProof<H> {

// Gather the indices the are returned. These indices indicate which membership
// proofs that have been mutated.
let mut all_mutated_mp_indices: Vec<usize> = vec![
let mut all_mutated_mp_indices: Vec<usize> = [
swbf_mutated_indices,
indices_for_updated_mps,
mps_for_new_chunk_dictionary_entry,
Expand Down
6 changes: 1 addition & 5 deletions src/util_types/test_shared/mutator_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,7 @@ pub fn pseudorandom_mmra_with_mps<H: AlgebraicHasher>(
(original_index, mmr_index, mt_index, peak_index)
})
.collect_vec();
let leafs_and_indices = leafs
.iter()
.copied()
.zip(leaf_indices.into_iter())
.collect_vec();
let leafs_and_indices = leafs.iter().copied().zip(leaf_indices).collect_vec();

// iterate over all trees
let mut peaks = vec![];
Expand Down

0 comments on commit 939d392

Please sign in to comment.