Skip to content

Commit

Permalink
Merge pull request #2 from agunde406/fix-lint
Browse files Browse the repository at this point in the history
Fix lint and clippy errors for Rust 1.75.0
  • Loading branch information
agunde406 authored Jan 31, 2024
2 parents b7b9374 + 888efe9 commit c9afdb8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
9 changes: 7 additions & 2 deletions libsawtooth/src/families/sabre/addressing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Bitwise IO, Inc.
// Copyright 2018 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt::Write;

use sha2::{Digest, Sha512};

use crate::transact::handler::ApplyError;
Expand All @@ -28,8 +31,10 @@ const CONTRACT_PREFIX: &str = "00ec02";
pub fn hash(to_hash: &str, num: usize) -> Result<String, ApplyError> {
let temp = Sha512::digest(to_hash.as_bytes())
.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>();
.fold(String::new(), |mut output, b| {
let _ = write!(output, "{b:02X}");
output
});
let hash = match temp.get(..num) {
Some(x) => x,
None => {
Expand Down
14 changes: 10 additions & 4 deletions libsawtooth/src/families/sabre/handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Bitwise IO, Inc.
// Copyright 2018 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,6 +15,8 @@

//! Provides a Sawtooth Transaction Handler for executing Sabre transactions.

use std::fmt::Write;

use sha2::{Digest, Sha512};

use crate::transact::handler::{ApplyError, TransactionContext, TransactionHandler};
Expand Down Expand Up @@ -240,10 +243,13 @@ fn create_contract(

state.set_contract(name, version, contract)?;

let contract_sha512 = Sha512::digest(payload.contract())
.iter()
.map(|b| format!("{:02x}", b))
.collect::<String>();
let contract_sha512 =
Sha512::digest(payload.contract())
.iter()
.fold(String::new(), |mut output, b| {
let _ = write!(output, "{b:02X}");
output
});

let contract_registry_version = VersionBuilder::new()
.with_version(version.into())
Expand Down
3 changes: 2 additions & 1 deletion libsawtooth/src/journal/chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2024 Bitwise IO, Inc.
* Copyright 2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -244,7 +245,7 @@ impl ChainControllerState {
chain_head.block(),
new_block.block()
);
if let Some(prior_heads_successor) = result.new_chain.get(0) {
if let Some(prior_heads_successor) = result.new_chain.first() {
if prior_heads_successor.header().previous_block_id()
!= chain_head.block().header_signature()
{
Expand Down
5 changes: 3 additions & 2 deletions libsawtooth/src/journal/validation_rule_enforcer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2024 Bitwise IO, Inc.
* Copyright 2018 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -264,7 +265,7 @@ impl FromStr for Rule {
// Example: "NofX:2,intkey" means only 2 intkey transactions are allowed per block.
"NofX" => {
let limit = rule_args
.get(0)
.first()
.ok_or_else(|| RuleParseError("found NofX rule with no arguments".into()))?
.trim()
.parse()
Expand All @@ -291,7 +292,7 @@ impl FromStr for Rule {
// transaction.
"XatY" => {
let family_name = rule_args
.get(0)
.first()
.ok_or_else(|| RuleParseError("found XatY rule with no arguments".into()))?
.trim()
.to_string();
Expand Down
2 changes: 2 additions & 0 deletions libsawtooth/src/store/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright 2024 Bitwise IO, Inc.
// Copyright 2021 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,4 +17,5 @@ mod error;
#[cfg(feature = "diesel")]
pub(crate) mod pool;

#[cfg(feature = "artifact")]
pub use error::StoreError;
1 change: 0 additions & 1 deletion libsawtooth/src/transact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
//! Transact provides optional support for smart contract engines implemented for Sawtooth through
//! the `sawtooth-compat` feature.


#[cfg(feature = "transact-context")]
mod collections;
#[cfg(feature = "transact-context")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2024 Bitwise IO, Inc.
* Copyright 2021 Cargill Incorporated
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -187,7 +188,7 @@ where
}

let parent = addition_changelog
.get(0)
.first()
.and_then(|entry| entry.parent_state_root.clone());

let change_additions = addition_changelog
Expand All @@ -206,9 +207,7 @@ where
.load::<MerkleRadixChangeLogDeletion>(conn)?
.into_iter()
.fold(HashMap::new(), |mut acc, successor| {
let hashes = acc
.entry(successor.successor_state_root)
.or_insert_with(Vec::new);
let hashes: &mut Vec<String> = acc.entry(successor.successor_state_root).or_default();
hashes.push(successor.deletion);
acc
});
Expand Down
3 changes: 2 additions & 1 deletion libsawtooth/src/transact/workload/batch_gen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2024 Bitwise IO, Inc.
* Copyright 2021 Cargill Incorporated
* Copyright 2017 Intel Corporation
*
Expand Down Expand Up @@ -150,7 +151,7 @@ impl<'a> Iterator for BatchListFeeder<'a> {
Err(err) => return Some(Err(BatchingError::InternalError(err))),
};

batches.get(0).map(|b| Ok(b.clone()))
batches.first().map(|b| Ok(b.clone()))
}
}

Expand Down

0 comments on commit c9afdb8

Please sign in to comment.