Skip to content

Commit 5a1024b

Browse files
committed
Fix clippy::redundant_closure throughout stackslib
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 8e2c660 commit 5a1024b

File tree

32 files changed

+91
-112
lines changed

32 files changed

+91
-112
lines changed

stackslib/src/blockstack_cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ fn main_handler(mut argv: Vec<String>) -> Result<String, CliError> {
864864
if let Some(custom_chain_id) = flag.split('=').nth(1) {
865865
// Attempt to parse the custom chain ID from hex
866866
chain_id = u32::from_str_radix(custom_chain_id.trim_start_matches("0x"), 16)
867-
.map_err(|err| CliError::InvalidChainId(err))?;
867+
.map_err(CliError::InvalidChainId)?;
868868
} else {
869869
// Use the default testnet chain ID
870870
chain_id = CHAIN_ID_TESTNET;

stackslib/src/burnchains/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl BurnchainDBTransaction<'_> {
393393
let args = params![u64_to_sql(target_reward_cycle)?];
394394
self.sql_tx
395395
.execute(sql, args)
396-
.map_err(|e| DBError::SqliteError(e))?;
396+
.map_err(DBError::SqliteError)?;
397397

398398
let sql = "UPDATE block_commit_metadata SET anchor_block = ?1 WHERE burn_block_hash = ?2 AND txid = ?3";
399399
let args = params![
@@ -424,7 +424,7 @@ impl BurnchainDBTransaction<'_> {
424424
self.sql_tx
425425
.execute(sql, args)
426426
.map(|_| ())
427-
.map_err(|e| DBError::SqliteError(e))
427+
.map_err(DBError::SqliteError)
428428
}
429429

430430
/// Calculate a burnchain block's block-commits' descendancy information.

stackslib/src/burnchains/tests/affirmation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub fn make_reward_cycle_with_vote(
419419
commits
420420
.into_iter()
421421
.filter_map(|cmt| cmt)
422-
.map(|cmt| BlockstackOperationType::LeaderBlockCommit(cmt))
422+
.map(BlockstackOperationType::LeaderBlockCommit)
423423
.collect()
424424
};
425425

@@ -1617,7 +1617,7 @@ fn test_update_pox_affirmation_maps_unique_anchor_block() {
16171617
let cmt_ops: Vec<BlockstackOperationType> = cmts
16181618
.iter()
16191619
.filter_map(|op| op.clone())
1620-
.map(|op| BlockstackOperationType::LeaderBlockCommit(op))
1620+
.map(BlockstackOperationType::LeaderBlockCommit)
16211621
.collect();
16221622

16231623
burnchain_db

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ impl FromRow<MissedBlockCommit> for MissedBlockCommit {
117117
fn from_row(row: &Row) -> Result<MissedBlockCommit, db_error> {
118118
let intended_sortition = SortitionId::from_column(row, "intended_sortition_id")?;
119119
let input_json: String = row.get_unwrap("input");
120-
let input =
121-
serde_json::from_str(&input_json).map_err(|e| db_error::SerializationError(e))?;
120+
let input = serde_json::from_str(&input_json).map_err(db_error::SerializationError)?;
122121
let txid = Txid::from_column(row, "txid")?;
123122

124123
Ok(MissedBlockCommit {
@@ -264,11 +263,10 @@ impl FromRow<LeaderBlockCommitOp> for LeaderBlockCommitOp {
264263

265264
let memo = memo_bytes.to_vec();
266265

267-
let input =
268-
serde_json::from_str(&input_json).map_err(|e| db_error::SerializationError(e))?;
266+
let input = serde_json::from_str(&input_json).map_err(db_error::SerializationError)?;
269267

270-
let apparent_sender = serde_json::from_str(&apparent_sender_json)
271-
.map_err(|e| db_error::SerializationError(e))?;
268+
let apparent_sender =
269+
serde_json::from_str(&apparent_sender_json).map_err(db_error::SerializationError)?;
272270

273271
let burn_fee = burn_fee_str
274272
.parse::<u64>()
@@ -285,8 +283,8 @@ impl FromRow<LeaderBlockCommitOp> for LeaderBlockCommitOp {
285283
.as_deref()
286284
.map(serde_json::from_str)
287285
.transpose()
288-
.map_err(|e| db_error::SerializationError(e))?
289-
.unwrap_or_else(|| vec![]);
286+
.map_err(db_error::SerializationError)?
287+
.unwrap_or_default();
290288

291289
let block_commit = LeaderBlockCommitOp {
292290
block_header_hash,
@@ -4446,7 +4444,7 @@ impl SortitionDB {
44464444
sortition_id: &SortitionId,
44474445
) -> Result<u64, BurnchainError> {
44484446
let db_handle = self.index_handle(sortition_id);
4449-
SortitionDB::get_max_arrival_index(&db_handle).map_err(|e| BurnchainError::from(e))
4447+
SortitionDB::get_max_arrival_index(&db_handle).map_err(BurnchainError::from)
44504448
}
44514449

44524450
/// Get a burn blockchain snapshot, given a burnchain configuration struct.
@@ -5761,12 +5759,12 @@ impl SortitionHandleTx<'_> {
57615759
assert!(block_commit.block_height < BLOCK_HEIGHT_MAX);
57625760

57635761
// serialize tx input to JSON
5764-
let tx_input_str = serde_json::to_string(&block_commit.input)
5765-
.map_err(|e| db_error::SerializationError(e))?;
5762+
let tx_input_str =
5763+
serde_json::to_string(&block_commit.input).map_err(db_error::SerializationError)?;
57665764

57675765
// serialize apparent sender to JSON
57685766
let apparent_sender_str = serde_json::to_string(&block_commit.apparent_sender)
5769-
.map_err(|e| db_error::SerializationError(e))?;
5767+
.map_err(db_error::SerializationError)?;
57705768

57715769
// find parent block commit's snapshot's sortition ID.
57725770
// If the parent_block_ptr doesn't point to a valid snapshot, then store an empty
@@ -5833,7 +5831,7 @@ impl SortitionHandleTx<'_> {
58335831
fn insert_missed_block_commit(&mut self, op: &MissedBlockCommit) -> Result<(), db_error> {
58345832
// serialize tx input to JSON
58355833
let tx_input_str =
5836-
serde_json::to_string(&op.input).map_err(|e| db_error::SerializationError(e))?;
5834+
serde_json::to_string(&op.input).map_err(db_error::SerializationError)?;
58375835

58385836
let args = params![op.txid, op.intended_sortition, tx_input_str];
58395837

@@ -6921,7 +6919,7 @@ pub mod tests {
69216919
sender: &BurnchainSigner,
69226920
) -> Result<Option<LeaderBlockCommitOp>, db_error> {
69236921
let apparent_sender_str =
6924-
serde_json::to_string(sender).map_err(|e| db_error::SerializationError(e))?;
6922+
serde_json::to_string(sender).map_err(db_error::SerializationError)?;
69256923
let sql = "SELECT * FROM block_commits WHERE apparent_sender = ?1 ORDER BY block_height DESC LIMIT 1";
69266924
let args = params![apparent_sender_str];
69276925
query_row(conn, sql, args)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,28 +227,28 @@ impl StacksMessageCodec for DelegateStxOp {
227227
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
228228
write_next(fd, &(Opcodes::DelegateStx as u8))?;
229229
fd.write_all(&self.delegated_ustx.to_be_bytes())
230-
.map_err(|e| codec_error::WriteError(e))?;
230+
.map_err(codec_error::WriteError)?;
231231

232232
if let Some((index, _)) = self.reward_addr {
233233
fd.write_all(&(1 as u8).to_be_bytes())
234-
.map_err(|e| codec_error::WriteError(e))?;
234+
.map_err(codec_error::WriteError)?;
235235
fd.write_all(&index.to_be_bytes())
236-
.map_err(|e| codec_error::WriteError(e))?;
236+
.map_err(codec_error::WriteError)?;
237237
} else {
238238
fd.write_all(&(0 as u8).to_be_bytes())
239-
.map_err(|e| codec_error::WriteError(e))?;
239+
.map_err(codec_error::WriteError)?;
240240
fd.write_all(&(0 as u32).to_be_bytes())
241-
.map_err(|e| codec_error::WriteError(e))?;
241+
.map_err(codec_error::WriteError)?;
242242
}
243243

244244
if let Some(height) = self.until_burn_height {
245245
fd.write_all(&(1 as u8).to_be_bytes())
246-
.map_err(|e| codec_error::WriteError(e))?;
246+
.map_err(codec_error::WriteError)?;
247247
fd.write_all(&height.to_be_bytes())
248-
.map_err(|e| codec_error::WriteError(e))?;
248+
.map_err(codec_error::WriteError)?;
249249
} else {
250250
fd.write_all(&(0 as u8).to_be_bytes())
251-
.map_err(|e| codec_error::WriteError(e))?;
251+
.map_err(codec_error::WriteError)?;
252252
}
253253
Ok(())
254254
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl StacksMessageCodec for StackStxOp {
374374
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
375375
write_next(fd, &(Opcodes::StackStx as u8))?;
376376
fd.write_all(&self.stacked_ustx.to_be_bytes())
377-
.map_err(|e| codec_error::WriteError(e))?;
377+
.map_err(codec_error::WriteError)?;
378378
write_next(fd, &self.num_cycles)?;
379379

380380
if let Some(signer_key) = &self.signer_key {
@@ -383,11 +383,11 @@ impl StacksMessageCodec for StackStxOp {
383383
}
384384
if let Some(max_amount) = &self.max_amount {
385385
fd.write_all(&max_amount.to_be_bytes())
386-
.map_err(|e| codec_error::WriteError(e))?;
386+
.map_err(codec_error::WriteError)?;
387387
}
388388
if let Some(auth_id) = &self.auth_id {
389389
fd.write_all(&auth_id.to_be_bytes())
390-
.map_err(|e| codec_error::WriteError(e))?;
390+
.map_err(codec_error::WriteError)?;
391391
}
392392
Ok(())
393393
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ impl StacksMessageCodec for TransferStxOp {
213213
}
214214
write_next(fd, &(Opcodes::TransferStx as u8))?;
215215
fd.write_all(&self.transfered_ustx.to_be_bytes())
216-
.map_err(|e| codec_error::WriteError(e))?;
217-
fd.write_all(&self.memo)
218-
.map_err(|e| codec_error::WriteError(e))?;
216+
.map_err(codec_error::WriteError)?;
217+
fd.write_all(&self.memo).map_err(codec_error::WriteError)?;
219218
Ok(())
220219
}
221220

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ impl StacksMessageCodec for VoteForAggregateKeyOp {
202202

203203
write_next(fd, &(Opcodes::VoteForAggregateKey as u8))?;
204204
fd.write_all(&self.signer_index.to_be_bytes())
205-
.map_err(|e| codec_error::WriteError(e))?;
205+
.map_err(codec_error::WriteError)?;
206206
fd.write_all(self.aggregate_key.as_bytes())
207-
.map_err(|e| codec_error::WriteError(e))?;
207+
.map_err(codec_error::WriteError)?;
208208
fd.write_all(&self.round.to_be_bytes())
209-
.map_err(|e| codec_error::WriteError(e))?;
209+
.map_err(codec_error::WriteError)?;
210210
fd.write_all(&self.reward_cycle.to_be_bytes())
211-
.map_err(|e| codec_error::WriteError(e))?;
211+
.map_err(codec_error::WriteError)?;
212212

213213
Ok(())
214214
}

stackslib/src/chainstate/coordinator/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ pub fn get_next_recipients<U: RewardSetProvider>(
742742
)?;
743743
sort_db
744744
.get_next_block_recipients(burnchain, sortition_tip, reward_cycle_info.as_ref())
745-
.map_err(|e| Error::from(e))
745+
.map_err(Error::from)
746746
}
747747

748748
/// returns None if this burnchain block is _not_ the start of a reward cycle
@@ -2097,9 +2097,7 @@ impl<
20972097
// by holding this lock as long as we do, we ensure that the sortition DB's
20982098
// view of the canonical stacks chain tip can't get changed (since no
20992099
// Stacks blocks can be processed).
2100-
chainstate_db_tx
2101-
.commit()
2102-
.map_err(|e| DBError::SqliteError(e))?;
2100+
chainstate_db_tx.commit().map_err(DBError::SqliteError)?;
21032101

21042102
let highest_valid_snapshot = SortitionDB::get_block_snapshot(
21052103
&self.sortition_db.conn(),
@@ -2786,9 +2784,7 @@ impl<
27862784
invalidation_height,
27872785
)?;
27882786
}
2789-
chainstate_db_tx
2790-
.commit()
2791-
.map_err(|e| DBError::SqliteError(e))?;
2787+
chainstate_db_tx.commit().map_err(DBError::SqliteError)?;
27922788
}
27932789

27942790
let sortition_id = next_snapshot.sortition_id;

stackslib/src/chainstate/nakamoto/signer_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl NakamotoSigners {
441441
coinbase_height,
442442
)
443443
})
444-
.map(|calculation| Some(calculation))
444+
.map(Some)
445445
}
446446

447447
/// Make the contract name for a signers DB contract

0 commit comments

Comments
 (0)