Skip to content

Commit 5bf0421

Browse files
committed
chore: adapt codebase to latest Rust (1.75)
1 parent fe94b53 commit 5bf0421

File tree

11 files changed

+25
-28
lines changed

11 files changed

+25
-28
lines changed

Cargo.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/src/actors/chain_manager/handlers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl Handler<AddBlocks> for ChainManager {
339339
return Box::pin(actix::fut::err(()));
340340
}
341341

342-
if let Some(block) = msg.blocks.get(0) {
342+
if let Some(block) = msg.blocks.first() {
343343
let chain_tip = act.get_chain_beacon();
344344
if block.block_header.beacon.checkpoint > chain_tip.checkpoint
345345
&& block.block_header.beacon.hash_prev_block != chain_tip.hash_prev_block
@@ -740,7 +740,7 @@ impl PeersBeacons {
740740
// TODO: is it possible to receive more than outbound_limit beacons?
741741
// (it shouldn't be possible)
742742
assert!(self.pb.len() <= outbound_limit as usize, "Received more beacons than the outbound_limit. Check the code for race conditions.");
743-
usize::try_from(outbound_limit).unwrap() - self.pb.len()
743+
usize::from(outbound_limit) - self.pb.len()
744744
})
745745
// The outbound limit is set when the SessionsManager actor is initialized, so here it
746746
// cannot be None. But if it is None, set num_missing_peers to 0 in order to calculate

node/src/actors/chain_manager/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::path::PathBuf;
2929
use std::{
3030
cmp::{max, min, Ordering},
3131
collections::{HashMap, HashSet, VecDeque},
32-
convert::{TryFrom, TryInto},
32+
convert::TryFrom,
3333
future,
3434
net::SocketAddr,
3535
pin::Pin,
@@ -3349,11 +3349,10 @@ pub fn run_dr_locally(dr: &DataRequestOutput) -> Result<RadonTypes, failure::Err
33493349
log::info!("Aggregation result: {:?}", aggregation_result);
33503350

33513351
// Assume that all the required witnesses will report the same value
3352-
let reported_values: Result<Vec<RadonTypes>, _> =
3353-
vec![aggregation_result; dr.witnesses.try_into()?]
3354-
.into_iter()
3355-
.map(RadonTypes::try_from)
3356-
.collect();
3352+
let reported_values: Result<Vec<RadonTypes>, _> = vec![aggregation_result; dr.witnesses.into()]
3353+
.into_iter()
3354+
.map(RadonTypes::try_from)
3355+
.collect();
33573356
log::info!("Running tally with values {:?}", reported_values);
33583357
let tally_result =
33593358
witnet_rad::run_tally(reported_values?, &dr.data_request.tally, &active_wips)?;

node/src/actors/json_rpc/api.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ pub async fn get_block(params: Params) -> Result<Value, Error> {
668668

669669
// Handle parameters as an array with a first obligatory hash field plus an optional bool field
670670
if let Params::Array(params) = params {
671-
if let Some(Value::String(hash)) = params.get(0) {
671+
if let Some(Value::String(hash)) = params.first() {
672672
match hash.parse() {
673673
Ok(hash) => block_hash = hash,
674674
Err(e) => {
@@ -1350,7 +1350,7 @@ pub async fn get_balance(params: Params) -> JsonRpcResult {
13501350

13511351
// Handle parameters as an array with a first obligatory PublicKeyHash field plus an optional bool field
13521352
if let Params::Array(params) = params {
1353-
if let Some(Value::String(target_param)) = params.get(0) {
1353+
if let Some(Value::String(target_param)) = params.first() {
13541354
target = GetBalanceTarget::from_str(target_param).map_err(internal_error)?;
13551355
} else {
13561356
return Err(Error::invalid_params(

rad/src/operators/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn filter(
167167

168168
let unknown_filter = |code| RadError::UnknownFilter { code };
169169

170-
let first_arg = args.get(0).ok_or_else(wrong_args)?;
170+
let first_arg = args.first().ok_or_else(wrong_args)?;
171171
match first_arg {
172172
Value::Array(_arg) => {
173173
let subscript_err = |e| RadError::Subscript {

rad/src/types/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ impl TryInto<Value> for RadonMap {
9191
.try_fold(
9292
BTreeMap::<Value, Value>::new(),
9393
|mut map, (key, radon_types)| {
94-
if let (Ok(key), Ok(value)) = (
95-
Value::try_from(key.to_string()),
94+
if let (key, Ok(value)) = (
95+
Value::from(key.to_string()),
9696
Value::try_from(radon_types.clone()),
9797
) {
9898
map.insert(key, value);

validations/src/validations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ pub fn validate_dr_transaction<'a>(
469469

470470
let fee = dr_transaction_fee(dr_tx, utxo_diff, epoch, epoch_constants)?;
471471

472-
if let Some(dr_output) = dr_tx.body.outputs.get(0) {
472+
if let Some(dr_output) = dr_tx.body.outputs.first() {
473473
// A value transfer output cannot have zero value
474474
if dr_output.value == 0 {
475475
return Err(TransactionError::ZeroValueOutput {
@@ -1240,7 +1240,7 @@ pub fn validate_commit_reveal_signature<'a>(
12401240
signatures_to_verify: &mut Vec<SignaturesToVerify>,
12411241
) -> Result<&'a KeyedSignature, failure::Error> {
12421242
let tx_keyed_signature = signatures
1243-
.get(0)
1243+
.first()
12441244
.ok_or(TransactionError::SignatureNotFound)?;
12451245

12461246
// Commitments and reveals should only have one signature

wallet/src/actors/app/handlers/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub use get_utxo_info::*;
4646
pub use get_wallet_infos::*;
4747
pub use lock_wallet::*;
4848
pub use next_subscription_id::*;
49-
pub use node_notification::*;
5049
pub use refresh_session::*;
5150
pub use resync::*;
5251
pub use run_rad_req::*;

wallet/src/actors/worker/handlers/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub use gen_mnemonic::*;
3939
pub use get::*;
4040
pub use get_addresses::*;
4141
pub use get_balance::*;
42-
pub use get_transaction::*;
4342
pub use get_transactions::*;
4443
pub use get_utxo_info::*;
4544
pub use handle_block::*;

wallet/src/actors/worker/methods.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Worker {
149149
let gen_fut = self.get_block_chain(0, -confirm_superblock_period);
150150
let gen_res: Vec<ChainEntry> = futures::executor::block_on(gen_fut)?;
151151
let gen_entry = gen_res
152-
.get(0)
152+
.first()
153153
.expect("It should always found a superconsolidated block");
154154
let get_gen_future = self.get_block(gen_entry.1.clone());
155155
let (block, _confirmed) = futures::executor::block_on(get_gen_future)?;
@@ -173,7 +173,7 @@ impl Worker {
173173
2,
174174
);
175175
let gen_res: Vec<ChainEntry> = futures::executor::block_on(gen_fut)?;
176-
let gen_entry = gen_res.get(0).expect(
176+
let gen_entry = gen_res.first().expect(
177177
"It should always find a last consolidated block for a any epoch number",
178178
);
179179
let get_gen_future = self.get_block(gen_entry.1.clone());
@@ -771,7 +771,7 @@ impl Worker {
771771
let gen_fut = self.get_block_chain(0, 1);
772772
let gen_res: Vec<ChainEntry> = futures::executor::block_on(gen_fut)?;
773773
let gen_entry = gen_res
774-
.get(0)
774+
.first()
775775
.expect("A Witnet chain should always have a genesis block");
776776

777777
let get_gen_future = self.get_block(gen_entry.1.clone());
@@ -794,7 +794,7 @@ impl Worker {
794794
let tip_res: Vec<ChainEntry> = futures::executor::block_on(tip_fut)?;
795795
let tip = CheckpointBeacon::try_from(
796796
tip_res
797-
.get(0)
797+
.first()
798798
.expect("A Witnet chain should always have at least one block"),
799799
)
800800
.expect("A Witnet node should present block hashes as 64 hexadecimal characters");

wallet/src/repository/wallet/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ where
13131313
// For any other transaction type, a fresh address is generated in the internal keychain.
13141314
let change_pkh = self.calculate_change_address(
13151315
state,
1316-
dr_output.and_then(|_| inputs.pointers.get(0).cloned().map(Input::new)),
1316+
dr_output.and_then(|_| inputs.pointers.first().cloned().map(Input::new)),
13171317
preview,
13181318
)?;
13191319

0 commit comments

Comments
 (0)