diff --git a/node/src/actors/chain_manager/handlers.rs b/node/src/actors/chain_manager/handlers.rs index 31c74f8d3..e45a46bcb 100644 --- a/node/src/actors/chain_manager/handlers.rs +++ b/node/src/actors/chain_manager/handlers.rs @@ -339,7 +339,7 @@ impl Handler for ChainManager { return Box::pin(actix::fut::err(())); } - if let Some(block) = msg.blocks.get(0) { + if let Some(block) = msg.blocks.first() { let chain_tip = act.get_chain_beacon(); if block.block_header.beacon.checkpoint > chain_tip.checkpoint && block.block_header.beacon.hash_prev_block != chain_tip.hash_prev_block @@ -740,7 +740,7 @@ impl PeersBeacons { // TODO: is it possible to receive more than outbound_limit beacons? // (it shouldn't be possible) assert!(self.pb.len() <= outbound_limit as usize, "Received more beacons than the outbound_limit. Check the code for race conditions."); - usize::try_from(outbound_limit).unwrap() - self.pb.len() + usize::from(outbound_limit) - self.pb.len() }) // The outbound limit is set when the SessionsManager actor is initialized, so here it // cannot be None. But if it is None, set num_missing_peers to 0 in order to calculate diff --git a/node/src/actors/chain_manager/mod.rs b/node/src/actors/chain_manager/mod.rs index d8fbb7e48..bc2c48602 100644 --- a/node/src/actors/chain_manager/mod.rs +++ b/node/src/actors/chain_manager/mod.rs @@ -29,7 +29,7 @@ use std::path::PathBuf; use std::{ cmp::{max, min, Ordering}, collections::{HashMap, HashSet, VecDeque}, - convert::{TryFrom, TryInto}, + convert::TryFrom, future, net::SocketAddr, pin::Pin, @@ -3349,11 +3349,10 @@ pub fn run_dr_locally(dr: &DataRequestOutput) -> Result, _> = - vec![aggregation_result; dr.witnesses.try_into()?] - .into_iter() - .map(RadonTypes::try_from) - .collect(); + let reported_values: Result, _> = vec![aggregation_result; dr.witnesses.into()] + .into_iter() + .map(RadonTypes::try_from) + .collect(); log::info!("Running tally with values {:?}", reported_values); let tally_result = witnet_rad::run_tally(reported_values?, &dr.data_request.tally, &active_wips)?; diff --git a/node/src/actors/json_rpc/api.rs b/node/src/actors/json_rpc/api.rs index d7adf886a..a408bc48d 100644 --- a/node/src/actors/json_rpc/api.rs +++ b/node/src/actors/json_rpc/api.rs @@ -668,7 +668,7 @@ pub async fn get_block(params: Params) -> Result { // Handle parameters as an array with a first obligatory hash field plus an optional bool field if let Params::Array(params) = params { - if let Some(Value::String(hash)) = params.get(0) { + if let Some(Value::String(hash)) = params.first() { match hash.parse() { Ok(hash) => block_hash = hash, Err(e) => { @@ -1350,7 +1350,7 @@ pub async fn get_balance(params: Params) -> JsonRpcResult { // Handle parameters as an array with a first obligatory PublicKeyHash field plus an optional bool field if let Params::Array(params) = params { - if let Some(Value::String(target_param)) = params.get(0) { + if let Some(Value::String(target_param)) = params.first() { target = GetBalanceTarget::from_str(target_param).map_err(internal_error)?; } else { return Err(Error::invalid_params( diff --git a/rad/src/operators/array.rs b/rad/src/operators/array.rs index b4aac9674..a4136d9f8 100644 --- a/rad/src/operators/array.rs +++ b/rad/src/operators/array.rs @@ -167,7 +167,7 @@ pub fn filter( let unknown_filter = |code| RadError::UnknownFilter { code }; - let first_arg = args.get(0).ok_or_else(wrong_args)?; + let first_arg = args.first().ok_or_else(wrong_args)?; match first_arg { Value::Array(_arg) => { let subscript_err = |e| RadError::Subscript { diff --git a/rad/src/types/map.rs b/rad/src/types/map.rs index 41e6d4380..16c3c7c56 100644 --- a/rad/src/types/map.rs +++ b/rad/src/types/map.rs @@ -91,8 +91,8 @@ impl TryInto for RadonMap { .try_fold( BTreeMap::::new(), |mut map, (key, radon_types)| { - if let (Ok(key), Ok(value)) = ( - Value::try_from(key.to_string()), + if let (key, Ok(value)) = ( + Value::from(key.to_string()), Value::try_from(radon_types.clone()), ) { map.insert(key, value); diff --git a/validations/src/validations.rs b/validations/src/validations.rs index e01c9ef39..0e70e1d40 100644 --- a/validations/src/validations.rs +++ b/validations/src/validations.rs @@ -469,7 +469,7 @@ pub fn validate_dr_transaction<'a>( let fee = dr_transaction_fee(dr_tx, utxo_diff, epoch, epoch_constants)?; - if let Some(dr_output) = dr_tx.body.outputs.get(0) { + if let Some(dr_output) = dr_tx.body.outputs.first() { // A value transfer output cannot have zero value if dr_output.value == 0 { return Err(TransactionError::ZeroValueOutput { @@ -1240,7 +1240,7 @@ pub fn validate_commit_reveal_signature<'a>( signatures_to_verify: &mut Vec, ) -> Result<&'a KeyedSignature, failure::Error> { let tx_keyed_signature = signatures - .get(0) + .first() .ok_or(TransactionError::SignatureNotFound)?; // Commitments and reveals should only have one signature diff --git a/wallet/src/actors/app/handlers/mod.rs b/wallet/src/actors/app/handlers/mod.rs index a6a191800..9af6179c8 100644 --- a/wallet/src/actors/app/handlers/mod.rs +++ b/wallet/src/actors/app/handlers/mod.rs @@ -46,7 +46,6 @@ pub use get_utxo_info::*; pub use get_wallet_infos::*; pub use lock_wallet::*; pub use next_subscription_id::*; -pub use node_notification::*; pub use refresh_session::*; pub use resync::*; pub use run_rad_req::*; diff --git a/wallet/src/actors/worker/handlers/mod.rs b/wallet/src/actors/worker/handlers/mod.rs index d3714d0db..8a5e2f4dc 100644 --- a/wallet/src/actors/worker/handlers/mod.rs +++ b/wallet/src/actors/worker/handlers/mod.rs @@ -39,7 +39,6 @@ pub use gen_mnemonic::*; pub use get::*; pub use get_addresses::*; pub use get_balance::*; -pub use get_transaction::*; pub use get_transactions::*; pub use get_utxo_info::*; pub use handle_block::*; diff --git a/wallet/src/actors/worker/methods.rs b/wallet/src/actors/worker/methods.rs index 23b5e9a22..268daf6cf 100644 --- a/wallet/src/actors/worker/methods.rs +++ b/wallet/src/actors/worker/methods.rs @@ -149,7 +149,7 @@ impl Worker { let gen_fut = self.get_block_chain(0, -confirm_superblock_period); let gen_res: Vec = futures::executor::block_on(gen_fut)?; let gen_entry = gen_res - .get(0) + .first() .expect("It should always found a superconsolidated block"); let get_gen_future = self.get_block(gen_entry.1.clone()); let (block, _confirmed) = futures::executor::block_on(get_gen_future)?; @@ -173,7 +173,7 @@ impl Worker { 2, ); let gen_res: Vec = futures::executor::block_on(gen_fut)?; - let gen_entry = gen_res.get(0).expect( + let gen_entry = gen_res.first().expect( "It should always find a last consolidated block for a any epoch number", ); let get_gen_future = self.get_block(gen_entry.1.clone()); @@ -771,7 +771,7 @@ impl Worker { let gen_fut = self.get_block_chain(0, 1); let gen_res: Vec = futures::executor::block_on(gen_fut)?; let gen_entry = gen_res - .get(0) + .first() .expect("A Witnet chain should always have a genesis block"); let get_gen_future = self.get_block(gen_entry.1.clone()); @@ -794,7 +794,7 @@ impl Worker { let tip_res: Vec = futures::executor::block_on(tip_fut)?; let tip = CheckpointBeacon::try_from( tip_res - .get(0) + .first() .expect("A Witnet chain should always have at least one block"), ) .expect("A Witnet node should present block hashes as 64 hexadecimal characters"); diff --git a/wallet/src/repository/wallet/mod.rs b/wallet/src/repository/wallet/mod.rs index 6e401c586..451586ad0 100644 --- a/wallet/src/repository/wallet/mod.rs +++ b/wallet/src/repository/wallet/mod.rs @@ -1313,7 +1313,7 @@ where // For any other transaction type, a fresh address is generated in the internal keychain. let change_pkh = self.calculate_change_address( state, - dr_output.and_then(|_| inputs.pointers.get(0).cloned().map(Input::new)), + dr_output.and_then(|_| inputs.pointers.first().cloned().map(Input::new)), preview, )?;