Skip to content

Commit 93ed5e1

Browse files
committed
Pacify clippy
1 parent d54882f commit 93ed5e1

19 files changed

Lines changed: 251 additions & 274 deletions

File tree

api-server/api-server-common/src/storage/impls/in_memory/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,10 +1038,10 @@ impl ApiServerInMemoryStorage {
10381038

10391039
// Handle a degenerate case when the block is stored several times using different heights
10401040
// (to be consistent with the postgres implementation).
1041-
if let Some(previously_stored_height) = previously_stored_height {
1042-
if previously_stored_height != block_height {
1043-
self.main_chain_blocks_table.remove(&previously_stored_height);
1044-
}
1041+
if let Some(previously_stored_height) = previously_stored_height
1042+
&& previously_stored_height != block_height
1043+
{
1044+
self.main_chain_blocks_table.remove(&previously_stored_height);
10451045
}
10461046

10471047
Ok(())

chainstate/src/detail/query.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ impl<'a, S: BlockchainStorageRead, V: TransactionVerificationStrategy> Chainstat
314314
let mut best_height = BlockHeight::new(0);
315315

316316
for block_id in locator.iter() {
317-
if let Some(block_index) = self.chainstate_ref.get_gen_block_index(block_id)? {
318-
if self.chainstate_ref.is_block_in_main_chain(block_id)? {
319-
best_height = block_index.block_height();
320-
break;
321-
}
317+
if let Some(block_index) = self.chainstate_ref.get_gen_block_index(block_id)?
318+
&& self.chainstate_ref.is_block_in_main_chain(block_id)?
319+
{
320+
best_height = block_index.block_height();
321+
break;
322322
}
323323
}
324324

chainstate/test-framework/src/framework.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ impl TestFramework {
198198
// persistence flag set.
199199
assert_eq!(was_persisted, is_persisted);
200200

201-
if let Some(new_block_index) = &new_block_index_opt {
202-
if orig_block_index_opt.is_none() {
203-
assert!(!new_block_index.status().is_ok());
204-
}
201+
if let Some(new_block_index) = &new_block_index_opt
202+
&& orig_block_index_opt.is_none()
203+
{
204+
assert!(!new_block_index.status().is_ok());
205205
}
206206

207207
assert_gen_block_index_identical_to(&new_best_block_index, &orig_best_block_index);

chainstate/test-framework/src/random_tx_maker.rs

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -980,34 +980,31 @@ impl<'a> RandomTxMaker<'a> {
980980
// create order to exchange part of available coins for tokens
981981
if let Some((token_id, token_supply)) =
982982
get_random_token(rng, self.tokens_store, tokens_cache)
983+
&& token_supply > Amount::ZERO
983984
{
984-
if token_supply > Amount::ZERO {
985-
let ask_amount =
986-
Amount::from_atoms(rng.random_range(1u128..=token_supply.into_atoms()));
987-
let give_amount =
988-
Amount::from_atoms(rng.random_range(1u128..=atoms_to_spend));
989-
let order_data = OrderData::new(
990-
Destination::AnyoneCanSpend,
991-
OutputValue::TokenV1(token_id, ask_amount),
992-
OutputValue::Coin(give_amount),
993-
);
994-
let change = (amount_to_spend - give_amount).unwrap();
985+
let ask_amount =
986+
Amount::from_atoms(rng.random_range(1u128..=token_supply.into_atoms()));
987+
let give_amount = Amount::from_atoms(rng.random_range(1u128..=atoms_to_spend));
988+
let order_data = OrderData::new(
989+
Destination::AnyoneCanSpend,
990+
OutputValue::TokenV1(token_id, ask_amount),
991+
OutputValue::Coin(give_amount),
992+
);
993+
let change = (amount_to_spend - give_amount).unwrap();
995994

996-
// Transfer output is created intentionally besides order output to not waste utxo
997-
// (e.g. single genesis output on issuance)
998-
let outputs = vec![
999-
TxOutput::CreateOrder(Box::new(order_data)),
1000-
TxOutput::Transfer(
1001-
OutputValue::Coin(change),
1002-
key_manager
1003-
.new_destination(self.chainstate.get_chain_config(), rng),
1004-
),
1005-
];
995+
// Transfer output is created intentionally besides order output to not waste utxo
996+
// (e.g. single genesis output on issuance)
997+
let outputs = vec![
998+
TxOutput::CreateOrder(Box::new(order_data)),
999+
TxOutput::Transfer(
1000+
OutputValue::Coin(change),
1001+
key_manager.new_destination(self.chainstate.get_chain_config(), rng),
1002+
),
1003+
];
10061004

1007-
self.order_can_be_created = false;
1005+
self.order_can_be_created = false;
10081006

1009-
result_outputs.extend_from_slice(&outputs);
1010-
}
1007+
result_outputs.extend_from_slice(&outputs);
10111008
}
10121009
} else if switch == 3 && !self.account_command_used {
10131010
// try fill order
@@ -1019,28 +1016,27 @@ impl<'a> RandomTxMaker<'a> {
10191016
calculate_filled_order_value(&orders_cache, order_id, amount_to_spend)
10201017
.unwrap();
10211018

1022-
if let Some(filled_value) = filled_value {
1023-
if !is_frozen_token(&filled_value, tokens_cache)
1024-
&& !is_frozen_order(&orders_cache, order_id)
1025-
{
1026-
let input = TxInput::OrderAccountCommand(
1027-
OrderAccountCommand::FillOrder(order_id, amount_to_spend),
1028-
);
1019+
if let Some(filled_value) = filled_value
1020+
&& !is_frozen_token(&filled_value, tokens_cache)
1021+
&& !is_frozen_order(&orders_cache, order_id)
1022+
{
1023+
let input = TxInput::OrderAccountCommand(OrderAccountCommand::FillOrder(
1024+
order_id,
1025+
amount_to_spend,
1026+
));
10291027

1030-
let output = TxOutput::Transfer(
1031-
filled_value,
1032-
key_manager
1033-
.new_destination(self.chainstate.get_chain_config(), rng),
1034-
);
1028+
let output = TxOutput::Transfer(
1029+
filled_value,
1030+
key_manager.new_destination(self.chainstate.get_chain_config(), rng),
1031+
);
10351032

1036-
let _ = orders_cache
1037-
.fill_order(order_id, amount_to_spend, OrdersVersion::V1)
1038-
.unwrap();
1039-
self.account_command_used = true;
1033+
let _ = orders_cache
1034+
.fill_order(order_id, amount_to_spend, OrdersVersion::V1)
1035+
.unwrap();
1036+
self.account_command_used = true;
10401037

1041-
result_inputs.push(input);
1042-
result_outputs.push(output);
1043-
}
1038+
result_inputs.push(input);
1039+
result_outputs.push(output);
10441040
}
10451041
}
10461042
} else if switch == 6 {
@@ -1136,17 +1132,17 @@ impl<'a> RandomTxMaker<'a> {
11361132
result_outputs.push(output);
11371133

11381134
// Occasionally create new delegation id
1139-
if rng.random::<bool>() && self.delegation_can_be_created {
1140-
if let Some((pool_id, _)) =
1135+
if rng.random::<bool>()
1136+
&& self.delegation_can_be_created
1137+
&& let Some((pool_id, _)) =
11411138
get_random_pool_data(rng, self.pos_accounting_store, &pos_accounting_cache)
1142-
{
1143-
self.delegation_can_be_created = false;
1139+
{
1140+
self.delegation_can_be_created = false;
11441141

1145-
result_outputs.push(TxOutput::CreateDelegationId(
1146-
key_manager.new_destination(self.chainstate.get_chain_config(), rng),
1147-
*pool_id,
1148-
));
1149-
}
1142+
result_outputs.push(TxOutput::CreateDelegationId(
1143+
key_manager.new_destination(self.chainstate.get_chain_config(), rng),
1144+
*pool_id,
1145+
));
11501146
}
11511147
}
11521148
}
@@ -1244,32 +1240,24 @@ impl<'a> RandomTxMaker<'a> {
12441240
)
12451241
.unwrap();
12461242

1247-
if let Some(filled_value) = filled_value {
1248-
if !is_frozen_token(&filled_value, tokens_cache)
1249-
&& !is_frozen_order(orders_cache, order_id)
1250-
{
1251-
result_outputs.push(TxOutput::Transfer(
1252-
filled_value,
1253-
key_manager
1254-
.new_destination(self.chainstate.get_chain_config(), rng),
1255-
));
1256-
1257-
result_inputs.push(TxInput::OrderAccountCommand(
1258-
OrderAccountCommand::FillOrder(
1259-
order_id,
1260-
Amount::from_atoms(atoms),
1261-
),
1262-
));
1263-
1264-
let _ = orders_cache
1265-
.fill_order(
1266-
order_id,
1267-
Amount::from_atoms(atoms),
1268-
OrdersVersion::V1,
1269-
)
1270-
.unwrap();
1271-
self.account_command_used = true;
1272-
}
1243+
if let Some(filled_value) = filled_value
1244+
&& !is_frozen_token(&filled_value, tokens_cache)
1245+
&& !is_frozen_order(orders_cache, order_id)
1246+
{
1247+
result_outputs.push(TxOutput::Transfer(
1248+
filled_value,
1249+
key_manager
1250+
.new_destination(self.chainstate.get_chain_config(), rng),
1251+
));
1252+
1253+
result_inputs.push(TxInput::OrderAccountCommand(
1254+
OrderAccountCommand::FillOrder(order_id, Amount::from_atoms(atoms)),
1255+
));
1256+
1257+
let _ = orders_cache
1258+
.fill_order(order_id, Amount::from_atoms(atoms), OrdersVersion::V1)
1259+
.unwrap();
1260+
self.account_command_used = true;
12731261
}
12741262
}
12751263
}

chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -169,58 +169,57 @@ fn randomized_test(#[case] seed: Seed) {
169169
did_something = true;
170170
}
171171
1 => {
172-
if rng.random_bool(0.5) {
173-
if let Some(pool_id) = test_data.random_pool_id(&mut rng) {
174-
test_data.decommission_pool(&mut tf, &mut rng, &pool_id);
175-
did_something = true;
176-
}
172+
if rng.random_bool(0.5)
173+
&& let Some(pool_id) = test_data.random_pool_id(&mut rng)
174+
{
175+
test_data.decommission_pool(&mut tf, &mut rng, &pool_id);
176+
did_something = true;
177177
}
178178
}
179179
2 => {
180-
if rng.random_bool(0.5) {
181-
if let Some(pool_id) = test_data.random_pool_id(&mut rng) {
182-
let _ = test_data.create_delegation(&mut tf, &mut rng, &pool_id);
183-
did_something = true;
184-
}
180+
if rng.random_bool(0.5)
181+
&& let Some(pool_id) = test_data.random_pool_id(&mut rng)
182+
{
183+
let _ = test_data.create_delegation(&mut tf, &mut rng, &pool_id);
184+
did_something = true;
185185
}
186186
}
187187
3 => {
188-
if rng.random_bool(0.5) {
189-
if let Some((pool_id, delegation_id)) =
188+
if rng.random_bool(0.5)
189+
&& let Some((pool_id, delegation_id)) =
190190
test_data.random_pool_and_delegation_id(&mut rng)
191-
{
192-
let _ = test_data.withdraw_from_delegation(
193-
&mut tf,
194-
&mut rng,
195-
&pool_id,
196-
&delegation_id,
197-
);
198-
did_something = true;
199-
}
191+
{
192+
let _ = test_data.withdraw_from_delegation(
193+
&mut tf,
194+
&mut rng,
195+
&pool_id,
196+
&delegation_id,
197+
);
198+
did_something = true;
200199
}
201200
}
202201
_ => {
203-
if rng.random_bool(0.5) {
204-
if let Some((pool_id, delegation_id)) =
202+
if rng.random_bool(0.5)
203+
&& let Some((pool_id, delegation_id)) =
205204
test_data.random_pool_and_delegation_id(&mut rng)
206-
{
207-
let _ = test_data.add_to_delegation(
208-
&mut tf,
209-
&mut rng,
210-
&pool_id,
211-
&delegation_id,
212-
);
213-
did_something = true;
214-
}
205+
{
206+
let _ = test_data.add_to_delegation(
207+
&mut tf,
208+
&mut rng,
209+
&pool_id,
210+
&delegation_id,
211+
);
212+
did_something = true;
215213
}
216214
}
217215
}
218216

219-
if !did_something && rng.random_bool(0.5) {
220-
if let Some(pool_id) = test_data.random_pool_id(&mut rng) {
221-
test_data.produce_trivial_block_with_pool(&mut tf, &mut rng, &pool_id);
222-
did_something = true;
223-
}
217+
if !did_something
218+
&& rng.random_bool(0.5)
219+
&& let Some(pool_id) = test_data.random_pool_id(&mut rng)
220+
{
221+
test_data.produce_trivial_block_with_pool(&mut tf, &mut rng, &pool_id);
222+
did_something = true;
224223
}
225224

226225
if !did_something {

dns-server/src/crawler_p2p/crawler_manager/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ where
290290
ConnectivityEvent::Message { peer_id, message } => {
291291
let result = self.handle_conn_message(peer_id, message);
292292

293-
if let Err(error) = result {
294-
if error.ban_score() > 0 {
295-
self.send_crawler_event(CrawlerEvent::Misbehaved { peer_id, error });
296-
}
293+
if let Err(error) = result
294+
&& error.ban_score() > 0
295+
{
296+
self.send_crawler_event(CrawlerEvent::Misbehaved { peer_id, error });
297297
}
298298
}
299299
ConnectivityEvent::OutboundAccepted {

networking/src/transport/message_codec.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ impl<Msg> MessageCodec<Msg> {
4242
}
4343

4444
fn check_encoded_message_size(&self, size: usize) -> Result<()> {
45-
if let Some(max_message_size) = self.max_encoded_message_size {
46-
if size > max_message_size {
47-
return Err(MessageCodecError::MessageTooLarge {
48-
actual_size: size,
49-
max_size: max_message_size,
50-
}
51-
.into());
45+
if let Some(max_message_size) = self.max_encoded_message_size
46+
&& size > max_message_size
47+
{
48+
return Err(MessageCodecError::MessageTooLarge {
49+
actual_size: size,
50+
max_size: max_message_size,
5251
}
52+
.into());
5353
}
5454

5555
Ok(())

p2p/src/net/default_backend/peer/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,15 @@ async fn maybe_send_will_disconnect<S: PeerStream>(
398398
peer_protocol_version: ProtocolVersion,
399399
socket_writer: &mut MessageWriter<S, Message>,
400400
) -> crate::Result<()> {
401-
if can_send_will_disconnect(peer_protocol_version) {
402-
if let Some(reason) = reason {
403-
log::debug!("Sending WillDisconnect, reason: {:?}", reason);
404-
socket_writer
405-
.send(Message::WillDisconnect(WillDisconnectMessage {
406-
reason: reason.to_string(),
407-
}))
408-
.await?;
409-
}
401+
if can_send_will_disconnect(peer_protocol_version)
402+
&& let Some(reason) = reason
403+
{
404+
log::debug!("Sending WillDisconnect, reason: {:?}", reason);
405+
socket_writer
406+
.send(Message::WillDisconnect(WillDisconnectMessage {
407+
reason: reason.to_string(),
408+
}))
409+
.await?;
410410
}
411411

412412
Ok(())

0 commit comments

Comments
 (0)