Skip to content

Commit

Permalink
chore: minor clippy fixes (#3576)
Browse files Browse the repository at this point in the history
Description
---
- remove unnecessary vec copy in protobuf conversion 
- clippy fixes
- remove duplicate utility function

Motivation and Context
---
Fix some minor clippy warnings 

How Has This Been Tested?
---
Existing tests pass
  • Loading branch information
sdbondi authored Nov 21, 2021
1 parent c0d625c commit 038b9a6
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::convert::TryFrom;
use tari_core::{proto::utils::try_convert_all, transactions::aggregated_body::AggregateBody};
use tari_core::{tari_utilities::convert::try_convert_all, transactions::aggregated_body::AggregateBody};

use crate::tari_rpc as grpc;

Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ mod block;
#[cfg(any(feature = "base_node", feature = "base_node_proto"))]
mod block_header;
#[cfg(any(feature = "base_node", feature = "base_node_proto"))]
pub mod utils;
mod utils;
2 changes: 1 addition & 1 deletion base_layer/core/src/proto/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl TryFrom<proto::types::TransactionOutput> for TransactionOutput {
let sender_offset_public_key =
PublicKey::from_bytes(output.sender_offset_public_key.as_bytes()).map_err(|err| format!("{:?}", err))?;

let script = TariScript::from_bytes(&output.script.to_vec()).map_err(|err| err.to_string())?;
let script = TariScript::from_bytes(&output.script).map_err(|err| err.to_string())?;

let metadata_signature = output
.metadata_signature
Expand Down
15 changes: 0 additions & 15 deletions base_layer/core/src/proto/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,8 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use prost_types::Timestamp;
use std::convert::TryInto;
use tari_crypto::tari_utilities::epoch_time::EpochTime;

/// Tries to convert a series of `T`s to `U`s, returning an error at the first failure
pub fn try_convert_all<T, U, I>(into_iter: I) -> Result<Vec<U>, T::Error>
where
I: IntoIterator<Item = T>,
T: TryInto<U>,
{
let iter = into_iter.into_iter();
let mut result = Vec::with_capacity(iter.size_hint().0);
for item in iter {
result.push(item.try_into()?);
}
Ok(result)
}

/// Utility function that converts a `prost::Timestamp` to a `chrono::DateTime`
pub(crate) fn timestamp_to_datetime(timestamp: Timestamp) -> EpochTime {
(timestamp.seconds as u64).into()
Expand Down

0 comments on commit 038b9a6

Please sign in to comment.