From 20355324ab0005a744f5a46978292e2a4a03e2c1 Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Wed, 31 Jan 2024 08:17:47 -0600 Subject: [PATCH 1/5] Fix lint added when removing hyperledger link Signed-off-by: Andrea Gunderson --- libsawtooth/src/transact/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libsawtooth/src/transact/mod.rs b/libsawtooth/src/transact/mod.rs index ecdbdf630..0bc2f3dc2 100644 --- a/libsawtooth/src/transact/mod.rs +++ b/libsawtooth/src/transact/mod.rs @@ -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")] From 9f9a37e9ee924aaae75986cf4460e1f26bb90c72 Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Wed, 31 Jan 2024 08:29:41 -0600 Subject: [PATCH 2/5] Fix format_collect clippy error Fixes the following error introduced in Rust 1.73.0 https://rust-lang.github.io/rust-clippy/master/index.html#/format_collect Signed-off-by: Andrea Gunderson --- libsawtooth/src/families/sabre/addressing.rs | 9 +++++++-- libsawtooth/src/families/sabre/handler.rs | 14 ++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libsawtooth/src/families/sabre/addressing.rs b/libsawtooth/src/families/sabre/addressing.rs index 634f31da0..f6e25c9d8 100644 --- a/libsawtooth/src/families/sabre/addressing.rs +++ b/libsawtooth/src/families/sabre/addressing.rs @@ -1,3 +1,4 @@ +// Copyright 2024 Bitwise IO, Inc. // Copyright 2018 Cargill Incorporated // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -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; @@ -28,8 +31,10 @@ const CONTRACT_PREFIX: &str = "00ec02"; pub fn hash(to_hash: &str, num: usize) -> Result { let temp = Sha512::digest(to_hash.as_bytes()) .iter() - .map(|b| format!("{:02x}", b)) - .collect::(); + .fold(String::new(), |mut output, b| { + let _ = write!(output, "{b:02X}"); + output + }); let hash = match temp.get(..num) { Some(x) => x, None => { diff --git a/libsawtooth/src/families/sabre/handler.rs b/libsawtooth/src/families/sabre/handler.rs index a08ff2abf..465c339cb 100644 --- a/libsawtooth/src/families/sabre/handler.rs +++ b/libsawtooth/src/families/sabre/handler.rs @@ -1,3 +1,4 @@ +// Copyright 2024 Bitwise IO, Inc. // Copyright 2018 Cargill Incorporated // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -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}; @@ -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::(); + 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()) From b4d8b96cb131e6d5ab878a48e8f83be5b296c267 Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Wed, 31 Jan 2024 08:44:44 -0600 Subject: [PATCH 3/5] Fix clippy error get_first Replaces uses of .get(0) with .first() https://rust-lang.github.io/rust-clippy/master/index.html#/get_first Signed-off-by: Andrea Gunderson --- libsawtooth/src/journal/chain.rs | 3 ++- libsawtooth/src/journal/validation_rule_enforcer.rs | 5 +++-- .../state/merkle/sql/store/operations/prune_entries.rs | 3 ++- libsawtooth/src/transact/workload/batch_gen.rs | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libsawtooth/src/journal/chain.rs b/libsawtooth/src/journal/chain.rs index e67d60312..27b9e2c3c 100644 --- a/libsawtooth/src/journal/chain.rs +++ b/libsawtooth/src/journal/chain.rs @@ -1,4 +1,5 @@ /* + * Copyright 2024 Bitwise IO, Inc. * Copyright 2018 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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() { diff --git a/libsawtooth/src/journal/validation_rule_enforcer.rs b/libsawtooth/src/journal/validation_rule_enforcer.rs index f268446d8..12b5f8b69 100644 --- a/libsawtooth/src/journal/validation_rule_enforcer.rs +++ b/libsawtooth/src/journal/validation_rule_enforcer.rs @@ -1,4 +1,5 @@ /* + * Copyright 2024 Bitwise IO, Inc. * Copyright 2018 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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() @@ -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(); diff --git a/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs b/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs index 546edc026..6e6089b93 100644 --- a/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs +++ b/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs @@ -1,4 +1,5 @@ /* + * Copyright 2024 Bitwise IO, Inc. * Copyright 2021 Cargill Incorporated * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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 diff --git a/libsawtooth/src/transact/workload/batch_gen.rs b/libsawtooth/src/transact/workload/batch_gen.rs index 14f64e575..96316baa5 100644 --- a/libsawtooth/src/transact/workload/batch_gen.rs +++ b/libsawtooth/src/transact/workload/batch_gen.rs @@ -1,4 +1,5 @@ /* + * Copyright 2024 Bitwise IO, Inc. * Copyright 2021 Cargill Incorporated * Copyright 2017 Intel Corporation * @@ -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())) } } From 283c9a4d335a97db08add8cca25902798b7c7f8a Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Wed, 31 Jan 2024 08:50:10 -0600 Subject: [PATCH 4/5] Fix clippy error unwarp_or_default https://rust-lang.github.io/rust-clippy/master/index.html#/unwrap_or_default Signed-off-by: Andrea Gunderson --- .../state/merkle/sql/store/operations/prune_entries.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs b/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs index 6e6089b93..9df8f5d08 100644 --- a/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs +++ b/libsawtooth/src/transact/state/merkle/sql/store/operations/prune_entries.rs @@ -207,9 +207,7 @@ where .load::(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 = acc.entry(successor.successor_state_root).or_default(); hashes.push(successor.deletion); acc }); From 888efe901a010dc414265b2b67f8c6e7c1e94105 Mon Sep 17 00:00:00 2001 From: Andrea Gunderson Date: Wed, 31 Jan 2024 09:08:40 -0600 Subject: [PATCH 5/5] Fix unused import error Adds a feature guard to fix the error. Import is only used by artifact. Signed-off-by: Andrea Gunderson --- libsawtooth/src/store/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsawtooth/src/store/mod.rs b/libsawtooth/src/store/mod.rs index ec75bbdfb..5cd1c61cc 100644 --- a/libsawtooth/src/store/mod.rs +++ b/libsawtooth/src/store/mod.rs @@ -1,3 +1,4 @@ +// Copyright 2024 Bitwise IO, Inc. // Copyright 2021 Cargill Incorporated // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,4 +17,5 @@ mod error; #[cfg(feature = "diesel")] pub(crate) mod pool; +#[cfg(feature = "artifact")] pub use error::StoreError;