Skip to content

Commit e1c09f7

Browse files
authored
Merge pull request #5645 from stacks-network/fix/clippy-ci-stacks-lib-redundant-closure
Fix clippy::redundant_closure throughout stackslib
2 parents a4566b8 + 50631eb commit e1c09f7

File tree

33 files changed

+99
-126
lines changed

33 files changed

+99
-126
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
@@ -412,7 +412,7 @@ pub fn make_reward_cycle_with_vote(
412412
commits
413413
.into_iter()
414414
.flatten()
415-
.map(|cmt| BlockstackOperationType::LeaderBlockCommit(cmt))
415+
.map(BlockstackOperationType::LeaderBlockCommit)
416416
.collect()
417417
};
418418

@@ -1610,7 +1610,7 @@ fn test_update_pox_affirmation_maps_unique_anchor_block() {
16101610
let cmt_ops: Vec<BlockstackOperationType> = cmts
16111611
.iter()
16121612
.filter_map(|op| op.clone())
1613-
.map(|op| BlockstackOperationType::LeaderBlockCommit(op))
1613+
.map(BlockstackOperationType::LeaderBlockCommit)
16141614
.collect();
16151615

16161616
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,
@@ -4442,7 +4440,7 @@ impl SortitionDB {
44424440
sortition_id: &SortitionId,
44434441
) -> Result<u64, BurnchainError> {
44444442
let db_handle = self.index_handle(sortition_id);
4445-
SortitionDB::get_max_arrival_index(&db_handle).map_err(|e| BurnchainError::from(e))
4443+
SortitionDB::get_max_arrival_index(&db_handle).map_err(BurnchainError::from)
44464444
}
44474445

44484446
/// Get a burn blockchain snapshot, given a burnchain configuration struct.
@@ -5757,12 +5755,12 @@ impl SortitionHandleTx<'_> {
57575755
assert!(block_commit.block_height < BLOCK_HEIGHT_MAX);
57585756

57595757
// serialize tx input to JSON
5760-
let tx_input_str = serde_json::to_string(&block_commit.input)
5761-
.map_err(|e| db_error::SerializationError(e))?;
5758+
let tx_input_str =
5759+
serde_json::to_string(&block_commit.input).map_err(db_error::SerializationError)?;
57625760

57635761
// serialize apparent sender to JSON
57645762
let apparent_sender_str = serde_json::to_string(&block_commit.apparent_sender)
5765-
.map_err(|e| db_error::SerializationError(e))?;
5763+
.map_err(db_error::SerializationError)?;
57665764

57675765
// find parent block commit's snapshot's sortition ID.
57685766
// If the parent_block_ptr doesn't point to a valid snapshot, then store an empty
@@ -5828,7 +5826,7 @@ impl SortitionHandleTx<'_> {
58285826
fn insert_missed_block_commit(&mut self, op: &MissedBlockCommit) -> Result<(), db_error> {
58295827
// serialize tx input to JSON
58305828
let tx_input_str =
5831-
serde_json::to_string(&op.input).map_err(|e| db_error::SerializationError(e))?;
5829+
serde_json::to_string(&op.input).map_err(db_error::SerializationError)?;
58325830

58335831
let args = params![op.txid, op.intended_sortition, tx_input_str];
58345832

@@ -6910,7 +6908,7 @@ pub mod tests {
69106908
sender: &BurnchainSigner,
69116909
) -> Result<Option<LeaderBlockCommitOp>, db_error> {
69126910
let apparent_sender_str =
6913-
serde_json::to_string(sender).map_err(|e| db_error::SerializationError(e))?;
6911+
serde_json::to_string(sender).map_err(db_error::SerializationError)?;
69146912
let sql = "SELECT * FROM block_commits WHERE apparent_sender = ?1 ORDER BY block_height DESC LIMIT 1";
69156913
let args = params![apparent_sender_str];
69166914
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_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_u8.to_be_bytes())
239-
.map_err(|e| codec_error::WriteError(e))?;
239+
.map_err(codec_error::WriteError)?;
240240
fd.write_all(&0_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_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_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
@@ -743,7 +743,7 @@ pub fn get_next_recipients<U: RewardSetProvider>(
743743
)?;
744744
sort_db
745745
.get_next_block_recipients(burnchain, sortition_tip, reward_cycle_info.as_ref())
746-
.map_err(|e| Error::from(e))
746+
.map_err(Error::from)
747747
}
748748

749749
/// 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(),
@@ -2787,9 +2785,7 @@ impl<
27872785
invalidation_height,
27882786
)?;
27892787
}
2790-
chainstate_db_tx
2791-
.commit()
2792-
.map_err(|e| DBError::SqliteError(e))?;
2788+
chainstate_db_tx.commit().map_err(DBError::SqliteError)?;
27932789
}
27942790

27952791
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)