Skip to content

Commit

Permalink
Fix clippy::redundant_closure throughout stackslib
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Jan 3, 2025
1 parent 8e2c660 commit 5a1024b
Show file tree
Hide file tree
Showing 32 changed files with 91 additions and 112 deletions.
2 changes: 1 addition & 1 deletion stackslib/src/blockstack_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ fn main_handler(mut argv: Vec<String>) -> Result<String, CliError> {
if let Some(custom_chain_id) = flag.split('=').nth(1) {
// Attempt to parse the custom chain ID from hex
chain_id = u32::from_str_radix(custom_chain_id.trim_start_matches("0x"), 16)
.map_err(|err| CliError::InvalidChainId(err))?;
.map_err(CliError::InvalidChainId)?;
} else {
// Use the default testnet chain ID
chain_id = CHAIN_ID_TESTNET;
Expand Down
4 changes: 2 additions & 2 deletions stackslib/src/burnchains/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl BurnchainDBTransaction<'_> {
let args = params![u64_to_sql(target_reward_cycle)?];
self.sql_tx
.execute(sql, args)
.map_err(|e| DBError::SqliteError(e))?;
.map_err(DBError::SqliteError)?;

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

/// Calculate a burnchain block's block-commits' descendancy information.
Expand Down
4 changes: 2 additions & 2 deletions stackslib/src/burnchains/tests/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ pub fn make_reward_cycle_with_vote(
commits
.into_iter()
.filter_map(|cmt| cmt)
.map(|cmt| BlockstackOperationType::LeaderBlockCommit(cmt))
.map(BlockstackOperationType::LeaderBlockCommit)
.collect()
};

Expand Down Expand Up @@ -1617,7 +1617,7 @@ fn test_update_pox_affirmation_maps_unique_anchor_block() {
let cmt_ops: Vec<BlockstackOperationType> = cmts
.iter()
.filter_map(|op| op.clone())
.map(|op| BlockstackOperationType::LeaderBlockCommit(op))
.map(BlockstackOperationType::LeaderBlockCommit)
.collect();

burnchain_db
Expand Down
26 changes: 12 additions & 14 deletions stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ impl FromRow<MissedBlockCommit> for MissedBlockCommit {
fn from_row(row: &Row) -> Result<MissedBlockCommit, db_error> {
let intended_sortition = SortitionId::from_column(row, "intended_sortition_id")?;
let input_json: String = row.get_unwrap("input");
let input =
serde_json::from_str(&input_json).map_err(|e| db_error::SerializationError(e))?;
let input = serde_json::from_str(&input_json).map_err(db_error::SerializationError)?;
let txid = Txid::from_column(row, "txid")?;

Ok(MissedBlockCommit {
Expand Down Expand Up @@ -264,11 +263,10 @@ impl FromRow<LeaderBlockCommitOp> for LeaderBlockCommitOp {

let memo = memo_bytes.to_vec();

let input =
serde_json::from_str(&input_json).map_err(|e| db_error::SerializationError(e))?;
let input = serde_json::from_str(&input_json).map_err(db_error::SerializationError)?;

let apparent_sender = serde_json::from_str(&apparent_sender_json)
.map_err(|e| db_error::SerializationError(e))?;
let apparent_sender =
serde_json::from_str(&apparent_sender_json).map_err(db_error::SerializationError)?;

let burn_fee = burn_fee_str
.parse::<u64>()
Expand All @@ -285,8 +283,8 @@ impl FromRow<LeaderBlockCommitOp> for LeaderBlockCommitOp {
.as_deref()
.map(serde_json::from_str)
.transpose()
.map_err(|e| db_error::SerializationError(e))?
.unwrap_or_else(|| vec![]);
.map_err(db_error::SerializationError)?
.unwrap_or_default();

let block_commit = LeaderBlockCommitOp {
block_header_hash,
Expand Down Expand Up @@ -4446,7 +4444,7 @@ impl SortitionDB {
sortition_id: &SortitionId,
) -> Result<u64, BurnchainError> {
let db_handle = self.index_handle(sortition_id);
SortitionDB::get_max_arrival_index(&db_handle).map_err(|e| BurnchainError::from(e))
SortitionDB::get_max_arrival_index(&db_handle).map_err(BurnchainError::from)
}

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

// serialize tx input to JSON
let tx_input_str = serde_json::to_string(&block_commit.input)
.map_err(|e| db_error::SerializationError(e))?;
let tx_input_str =
serde_json::to_string(&block_commit.input).map_err(db_error::SerializationError)?;

// serialize apparent sender to JSON
let apparent_sender_str = serde_json::to_string(&block_commit.apparent_sender)
.map_err(|e| db_error::SerializationError(e))?;
.map_err(db_error::SerializationError)?;

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

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

Expand Down Expand Up @@ -6921,7 +6919,7 @@ pub mod tests {
sender: &BurnchainSigner,
) -> Result<Option<LeaderBlockCommitOp>, db_error> {
let apparent_sender_str =
serde_json::to_string(sender).map_err(|e| db_error::SerializationError(e))?;
serde_json::to_string(sender).map_err(db_error::SerializationError)?;
let sql = "SELECT * FROM block_commits WHERE apparent_sender = ?1 ORDER BY block_height DESC LIMIT 1";
let args = params![apparent_sender_str];
query_row(conn, sql, args)
Expand Down
16 changes: 8 additions & 8 deletions stackslib/src/chainstate/burn/operations/delegate_stx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,28 @@ impl StacksMessageCodec for DelegateStxOp {
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
write_next(fd, &(Opcodes::DelegateStx as u8))?;
fd.write_all(&self.delegated_ustx.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;

if let Some((index, _)) = self.reward_addr {
fd.write_all(&(1 as u8).to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(&index.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
} else {
fd.write_all(&(0 as u8).to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(&(0 as u32).to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
}

if let Some(height) = self.until_burn_height {
fd.write_all(&(1 as u8).to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(&height.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
} else {
fd.write_all(&(0 as u8).to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions stackslib/src/chainstate/burn/operations/stack_stx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl StacksMessageCodec for StackStxOp {
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
write_next(fd, &(Opcodes::StackStx as u8))?;
fd.write_all(&self.stacked_ustx.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
write_next(fd, &self.num_cycles)?;

if let Some(signer_key) = &self.signer_key {
Expand All @@ -383,11 +383,11 @@ impl StacksMessageCodec for StackStxOp {
}
if let Some(max_amount) = &self.max_amount {
fd.write_all(&max_amount.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
}
if let Some(auth_id) = &self.auth_id {
fd.write_all(&auth_id.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
}
Ok(())
}
Expand Down
5 changes: 2 additions & 3 deletions stackslib/src/chainstate/burn/operations/transfer_stx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ impl StacksMessageCodec for TransferStxOp {
}
write_next(fd, &(Opcodes::TransferStx as u8))?;
fd.write_all(&self.transfered_ustx.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
fd.write_all(&self.memo)
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(&self.memo).map_err(codec_error::WriteError)?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ impl StacksMessageCodec for VoteForAggregateKeyOp {

write_next(fd, &(Opcodes::VoteForAggregateKey as u8))?;
fd.write_all(&self.signer_index.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(self.aggregate_key.as_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(&self.round.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;
fd.write_all(&self.reward_cycle.to_be_bytes())
.map_err(|e| codec_error::WriteError(e))?;
.map_err(codec_error::WriteError)?;

Ok(())
}
Expand Down
10 changes: 3 additions & 7 deletions stackslib/src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ pub fn get_next_recipients<U: RewardSetProvider>(
)?;
sort_db
.get_next_block_recipients(burnchain, sortition_tip, reward_cycle_info.as_ref())
.map_err(|e| Error::from(e))
.map_err(Error::from)
}

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

let highest_valid_snapshot = SortitionDB::get_block_snapshot(
&self.sortition_db.conn(),
Expand Down Expand Up @@ -2786,9 +2784,7 @@ impl<
invalidation_height,
)?;
}
chainstate_db_tx
.commit()
.map_err(|e| DBError::SqliteError(e))?;
chainstate_db_tx.commit().map_err(DBError::SqliteError)?;
}

let sortition_id = next_snapshot.sortition_id;
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/nakamoto/signer_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl NakamotoSigners {
coinbase_height,
)
})
.map(|calculation| Some(calculation))
.map(Some)
}

/// Make the contract name for a signers DB contract
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/nakamoto/tenure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl NakamotoChainState {
headers_conn.sqlite(),
&block_header.parent_block_id,
)?
.map(|parent_version| NakamotoBlockHeader::is_shadow_block_version(parent_version))
.map(NakamotoBlockHeader::is_shadow_block_version)
.unwrap_or(false);

if !is_parent_shadow_block && !prev_sn.sortition {
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/nakamoto/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ fn test_make_miners_stackerdb_config() {
miners
.clone()
.into_iter()
.map(|miner| BlockstackOperationType::LeaderKeyRegister(miner))
.map(BlockstackOperationType::LeaderKeyRegister)
.collect()
} else {
// subsequent ones include block-commits
Expand Down
6 changes: 3 additions & 3 deletions stackslib/src/chainstate/stacks/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ pub mod test {
.unwrap(),
];

let addrs: Vec<StacksAddress> = keys.iter().map(|pk| key_to_stacks_addr(pk)).collect();
let addrs: Vec<StacksAddress> = keys.iter().map(key_to_stacks_addr).collect();

let balances: Vec<(PrincipalData, u64)> = addrs
.clone()
Expand Down Expand Up @@ -2341,7 +2341,7 @@ pub mod test {
let addr_tuple = Value::Tuple(pox_addr.as_clarity_tuple().unwrap());
let signature = signature_opt
.map(|sig| Value::some(Value::buff_from(sig).unwrap()).unwrap())
.unwrap_or_else(|| Value::none());
.unwrap_or_else(Value::none);
let payload = TransactionPayload::new_contract_call(
boot_code_test_addr(),
POX_4_NAME,
Expand Down Expand Up @@ -2372,7 +2372,7 @@ pub mod test {
) -> StacksTransaction {
let signature = signature_opt
.map(|sig| Value::some(Value::buff_from(sig).unwrap()).unwrap())
.unwrap_or_else(|| Value::none());
.unwrap_or_else(Value::none);
let payload = TransactionPayload::new_contract_call(
boot_code_test_addr(),
POX_4_NAME,
Expand Down
8 changes: 4 additions & 4 deletions stackslib/src/chainstate/stacks/boot/pox_4_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5179,8 +5179,8 @@ fn balances_from_keys(
keys: &[Secp256k1PrivateKey],
) -> Vec<STXBalance> {
keys.iter()
.map(|key| key_to_stacks_addr(key))
.map(|addr| PrincipalData::from(addr))
.map(key_to_stacks_addr)
.map(PrincipalData::from)
.map(|principal| get_stx_account_at(peer, tip, &principal))
.collect()
}
Expand Down Expand Up @@ -6766,7 +6766,7 @@ pub fn pox_4_scenario_test_setup_nakamoto<'a>(

let private_key = StacksPrivateKey::from_seed(&[2]);
let test_signers = TestSigners::new(test_keys.clone());
let addrs: Vec<StacksAddress> = test_keys.iter().map(|pk| key_to_stacks_addr(pk)).collect();
let addrs: Vec<StacksAddress> = test_keys.iter().map(key_to_stacks_addr).collect();
let initial_stacker_balance = initial_balances
.get(0)
.expect("Expected at least 1 initial balance")
Expand Down Expand Up @@ -8843,7 +8843,7 @@ pub fn prepare_pox4_test<'a>(
.with_test_signers(test_signers.clone())
.with_private_key(private_key);
boot_plan.add_default_balance = false;
let addrs: Vec<StacksAddress> = keys.iter().map(|pk| key_to_stacks_addr(pk)).collect();
let addrs: Vec<StacksAddress> = keys.iter().map(key_to_stacks_addr).collect();

let balances: Vec<(PrincipalData, u64)> = addrs
.clone()
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/db/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl StacksChainState {
) -> Result<Vec<MinerReward>, Error> {
let sql = "SELECT * FROM matured_rewards WHERE parent_index_block_hash = ?1 AND child_index_block_hash = ?2 AND vtxindex = 0";
let args = params![parent_block_id.0, child_block_id.0];
let ret: Vec<MinerReward> = query_rows(conn, sql, args).map_err(|e| Error::DBError(e))?;
let ret: Vec<MinerReward> = query_rows(conn, sql, args).map_err(Error::DBError)?;
Ok(ret)
}

Expand Down
10 changes: 5 additions & 5 deletions stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ impl StacksChainState {
// gather
let mut blobs = vec![];

while let Some(row) = rows.next().map_err(|e| db_error::SqliteError(e))? {
while let Some(row) = rows.next().map_err(db_error::SqliteError)? {
let next_blob: Vec<u8> = row.get_unwrap(0);
blobs.push(next_blob);
}
Expand Down Expand Up @@ -1733,7 +1733,7 @@ impl StacksChainState {

// gather
let mut row_data: Vec<i64> = vec![];
while let Some(row) = rows.next().map_err(|e| db_error::SqliteError(e))? {
while let Some(row) = rows.next().map_err(db_error::SqliteError)? {
let val_opt: Option<i64> = row.get_unwrap(0);
if let Some(val) = val_opt {
row_data.push(val);
Expand Down Expand Up @@ -3863,7 +3863,7 @@ impl StacksChainState {
.query(NO_PARAMS)
.map_err(|e| Error::DBError(db_error::SqliteError(e)))?;

while let Some(row) = rows.next().map_err(|e| db_error::SqliteError(e))? {
while let Some(row) = rows.next().map_err(db_error::SqliteError)? {
let mut candidate = StagingBlock::from_row(&row).map_err(Error::DBError)?;

// block must correspond to a valid PoX snapshot
Expand Down Expand Up @@ -6675,7 +6675,7 @@ impl StacksChainState {
let epoch = clarity_connection.get_epoch().clone();

StacksChainState::process_transaction_precheck(&chainstate_config, &tx, epoch)
.map_err(|e| MemPoolRejection::FailedToValidate(e))?;
.map_err(MemPoolRejection::FailedToValidate)?;

// 3: it must pay a tx fee
let fee = tx.get_tx_fee();
Expand Down Expand Up @@ -6867,7 +6867,7 @@ impl StacksChainState {
epoch,
clarity_version,
)
.map_err(|e| MemPoolRejection::BadFunctionArgument(e))
.map_err(MemPoolRejection::BadFunctionArgument)
})?;
}
TransactionPayload::SmartContract(
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ impl StacksChainState {
test_debug!("Open MARF index at {}", marf_path);
let mut open_opts = MARFOpenOpts::default();
open_opts.external_blobs = true;
let marf = MARF::from_path(marf_path, open_opts).map_err(|e| db_error::IndexError(e))?;
let marf = MARF::from_path(marf_path, open_opts).map_err(db_error::IndexError)?;
Ok(marf)
}

Expand Down
Loading

0 comments on commit 5a1024b

Please sign in to comment.