Skip to content

Commit

Permalink
chore: adapt codebase to latest Rust (1.75)
Browse files Browse the repository at this point in the history
  • Loading branch information
aesedepece committed Jan 4, 2024
1 parent fe94b53 commit d28f025
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl Handler<AddBlocks> 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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions node/src/actors/chain_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -3349,11 +3349,10 @@ pub fn run_dr_locally(dr: &DataRequestOutput) -> Result<RadonTypes, failure::Err
log::info!("Aggregation result: {:?}", aggregation_result);

// Assume that all the required witnesses will report the same value
let reported_values: Result<Vec<RadonTypes>, _> =
vec![aggregation_result; dr.witnesses.try_into()?]
.into_iter()
.map(RadonTypes::try_from)
.collect();
let reported_values: Result<Vec<RadonTypes>, _> = 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)?;
Expand Down
4 changes: 2 additions & 2 deletions node/src/actors/json_rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ pub async fn get_block(params: Params) -> Result<Value, Error> {

// 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) => {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion rad/src/operators/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions rad/src/types/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl TryInto<Value> for RadonMap {
.try_fold(
BTreeMap::<Value, Value>::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);
Expand Down
4 changes: 2 additions & 2 deletions validations/src/validations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1240,7 +1240,7 @@ pub fn validate_commit_reveal_signature<'a>(
signatures_to_verify: &mut Vec<SignaturesToVerify>,
) -> 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
Expand Down
1 change: 0 additions & 1 deletion wallet/src/actors/app/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
1 change: 0 additions & 1 deletion wallet/src/actors/worker/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
8 changes: 4 additions & 4 deletions wallet/src/actors/worker/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Worker {
let gen_fut = self.get_block_chain(0, -confirm_superblock_period);
let gen_res: Vec<ChainEntry> = 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)?;
Expand All @@ -173,7 +173,7 @@ impl Worker {
2,
);
let gen_res: Vec<ChainEntry> = 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());
Expand Down Expand Up @@ -771,7 +771,7 @@ impl Worker {
let gen_fut = self.get_block_chain(0, 1);
let gen_res: Vec<ChainEntry> = 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());
Expand All @@ -794,7 +794,7 @@ impl Worker {
let tip_res: Vec<ChainEntry> = 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");
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/repository/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;

Expand Down

0 comments on commit d28f025

Please sign in to comment.