Skip to content

Commit 6cf460f

Browse files
committed
Fix clippy::bind_instead_of_map, clippy::map_flatten, clippy::*map_identity throughout stackslib
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 8c23c0e commit 6cf460f

File tree

29 files changed

+115
-154
lines changed

29 files changed

+115
-154
lines changed

stackslib/src/burnchains/bitcoin/blocks.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ impl BitcoinMessageHandler for BitcoinBlockDownloader {
150150
None => panic!("No block header set"),
151151
Some(ref ipc_header) => {
152152
let block_hash = ipc_header.block_header.header.bitcoin_hash().clone();
153-
indexer
154-
.send_getdata(&vec![block_hash])
155-
.and_then(|_r| Ok(true))
153+
indexer.send_getdata(&vec![block_hash]).map(|_r| true)
156154
}
157155
}
158156
}

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl BitcoinIndexer {
458458
}
459459
spv_client
460460
.run(self)
461-
.and_then(|_r| Ok(spv_client.end_block_height.unwrap()))
461+
.map(|_r| spv_client.end_block_height.unwrap())
462462
}
463463

464464
#[cfg(test)]

stackslib/src/burnchains/bitcoin/network.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ impl BitcoinIndexer {
127127
// classify the message here, so we can pass it along to the handler explicitly
128128
match message {
129129
btc_message::NetworkMessage::Version(..) => {
130-
return self.handle_version(message).and_then(|_r| Ok(true));
130+
return self.handle_version(message).map(|_r| true);
131131
}
132132
btc_message::NetworkMessage::Verack => {
133-
return self.handle_verack(message).and_then(|_r| Ok(true));
133+
return self.handle_verack(message).map(|_r| true);
134134
}
135135
btc_message::NetworkMessage::Ping(..) => {
136-
return self.handle_ping(message).and_then(|_r| Ok(true));
136+
return self.handle_ping(message).map(|_r| true);
137137
}
138138
btc_message::NetworkMessage::Pong(..) => {
139-
return self.handle_pong(message).and_then(|_r| Ok(true));
139+
return self.handle_pong(message).map(|_r| true);
140140
}
141141
_ => match handler {
142142
Some(custom_handler) => custom_handler.handle_message(self, message),

stackslib/src/burnchains/bitcoin/spv.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl SpvClient {
274274
tx.execute("UPDATE db_config SET version = ?1", &[version])
275275
.map_err(db_error::SqliteError)
276276
.map_err(|e| e.into())
277-
.and_then(|_| Ok(()))
277+
.map(|_| ())
278278
}
279279

280280
#[cfg(test)]
@@ -354,7 +354,7 @@ impl SpvClient {
354354
pub fn is_initialized(&self) -> Result<(), btc_error> {
355355
fs::metadata(&self.headers_path)
356356
.map_err(btc_error::FilesystemError)
357-
.and_then(|_m| Ok(()))
357+
.map(|_m| ())
358358
}
359359

360360
/// Get the block range to scan
@@ -762,7 +762,7 @@ impl SpvClient {
762762

763763
tx.execute(sql, args)
764764
.map_err(|e| btc_error::DBError(db_error::SqliteError(e)))
765-
.and_then(|_x| Ok(()))
765+
.map(|_x| ())
766766
}
767767

768768
/// Initialize the block headers file with the genesis block hash.
@@ -1231,7 +1231,7 @@ impl BitcoinMessageHandler for SpvClient {
12311231

12321232
indexer.runtime.last_getheaders_send_time = get_epoch_time_secs();
12331233
self.send_next_getheaders(indexer, start_height)
1234-
.and_then(|_r| Ok(true))
1234+
.map(|_r| true)
12351235
}
12361236

12371237
/// Trait message handler
@@ -1298,7 +1298,7 @@ impl BitcoinMessageHandler for SpvClient {
12981298
);
12991299
}
13001300
self.send_next_getheaders(indexer, block_height)
1301-
.and_then(|_| Ok(true))
1301+
.map(|_| true)
13021302
}
13031303
x => Err(btc_error::UnhandledMessage(x)),
13041304
}

stackslib/src/burnchains/tests/affirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub fn make_reward_cycle_with_vote(
413413
new_commits.push(commits.clone());
414414
commits
415415
.into_iter()
416-
.filter_map(|cmt| cmt)
416+
.flatten()
417417
.map(|cmt| BlockstackOperationType::LeaderBlockCommit(cmt))
418418
.collect()
419419
};

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,7 @@ impl SortitionDBConn<'_> {
39363936
tip,
39373937
reward_cycle_id,
39383938
)
3939-
.and_then(|(reward_cycle_info, _anchor_sortition_id)| Ok(reward_cycle_info))
3939+
.map(|(reward_cycle_info, _anchor_sortition_id)| reward_cycle_info)
39403940
}
39413941

39423942
/// Get the prepare phase start sortition ID of a reward cycle. This is the first prepare
@@ -4048,25 +4048,23 @@ impl SortitionDB {
40484048
}
40494049

40504050
fn parse_last_anchor_block_hash(s: Option<String>) -> Option<BlockHeaderHash> {
4051-
s.map(|s| {
4051+
s.and_then(|s| {
40524052
if s.is_empty() {
40534053
None
40544054
} else {
40554055
Some(BlockHeaderHash::from_hex(&s).expect("BUG: Bad BlockHeaderHash stored in DB"))
40564056
}
40574057
})
4058-
.flatten()
40594058
}
40604059

40614060
fn parse_last_anchor_block_txid(s: Option<String>) -> Option<Txid> {
4062-
s.map(|s| {
4061+
s.and_then(|s| {
40634062
if s.is_empty() {
40644063
None
40654064
} else {
40664065
Some(Txid::from_hex(&s).expect("BUG: Bad Txid stored in DB"))
40674066
}
40684067
})
4069-
.flatten()
40704068
}
40714069

40724070
/// Mark a Stacks block snapshot as valid again, but update its memoized canonical Stacks tip

stackslib/src/chainstate/burn/operations/leader_key_register.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl LeaderKeyRegisterOp {
7272
/// Interpret the first 20 bytes of the key registration's memo field as the Hash160 of
7373
/// of the public key that will sign this miner's nakamoto blocks.
7474
pub fn interpret_nakamoto_signing_key(&self) -> Option<Hash160> {
75-
self.memo.get(0..20).map(Hash160::from_bytes).flatten()
75+
self.memo.get(0..20).and_then(Hash160::from_bytes)
7676
}
7777

7878
/// Set the miner public key hash160 for block-signing

stackslib/src/chainstate/burn/sortition.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ impl BlockSnapshot {
731731
winning_block.key_vtxindex.into(),
732732
&parent_snapshot.sortition_id,
733733
)?
734-
.map(|key_op| key_op.interpret_nakamoto_signing_key())
735-
.flatten();
734+
.and_then(|key_op| key_op.interpret_nakamoto_signing_key());
736735

737736
Ok(BlockSnapshot {
738737
block_height,

stackslib/src/chainstate/coordinator/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,11 +2411,11 @@ impl<
24112411
// burnchain has not yet advanced to epoch 3.0
24122412
return self
24132413
.handle_new_epoch2_burnchain_block(&mut HashSet::new())
2414-
.and_then(|block_hash_opt| {
2414+
.map(|block_hash_opt| {
24152415
if let Some(block_hash) = block_hash_opt {
2416-
Ok(NewBurnchainBlockStatus::WaitForPox2x(block_hash))
2416+
NewBurnchainBlockStatus::WaitForPox2x(block_hash)
24172417
} else {
2418-
Ok(NewBurnchainBlockStatus::Ready)
2418+
NewBurnchainBlockStatus::Ready
24192419
}
24202420
});
24212421
}
@@ -2444,12 +2444,12 @@ impl<
24442444

24452445
// proceed to process sortitions in epoch 3.0
24462446
self.handle_new_nakamoto_burnchain_block()
2447-
.and_then(|can_proceed| {
2447+
.map(|can_proceed| {
24482448
if can_proceed {
2449-
Ok(NewBurnchainBlockStatus::Ready)
2449+
NewBurnchainBlockStatus::Ready
24502450
} else {
24512451
// missing PoX anchor block, but unlike in 2.x, we don't know what it is!
2452-
Ok(NewBurnchainBlockStatus::WaitForPoxNakamoto)
2452+
NewBurnchainBlockStatus::WaitForPoxNakamoto
24532453
}
24542454
})
24552455
}

stackslib/src/chainstate/nakamoto/miner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl NakamotoBlockBuilder {
596596
tenure_info.coinbase_tx.clone(),
597597
]
598598
.into_iter()
599-
.filter_map(|x| x)
599+
.flatten()
600600
.collect();
601601

602602
// TODO: update this mempool check to prioritize signer vote transactions over other transactions

0 commit comments

Comments
 (0)