From 5ff6b67d392a0f8238d483918ea36e82d9a22937 Mon Sep 17 00:00:00 2001 From: Ales Tsurko Date: Thu, 14 Jul 2022 17:41:40 +0300 Subject: [PATCH] [fix] #2416: Fix lints on macOS arm (#2452) Signed-off-by: Ales Tsurko --- core/src/smartcontracts/isi/block.rs | 3 +- data_model/Cargo.toml | 2 +- data_model/src/lib.rs | 92 +++++++++++++++++-- data_model/src/query.rs | 2 +- .../parity_scale_decoder/src/generate_map.rs | 22 ++--- 5 files changed, 100 insertions(+), 21 deletions(-) diff --git a/core/src/smartcontracts/isi/block.rs b/core/src/smartcontracts/isi/block.rs index 656f0e9aba8..ccef1412b23 100644 --- a/core/src/smartcontracts/isi/block.rs +++ b/core/src/smartcontracts/isi/block.rs @@ -7,11 +7,10 @@ use super::*; impl ValidQuery for FindAllBlocks { #[metrics(+"find_all_blocks")] fn execute(&self, wsv: &WorldStateView) -> Result { - let mut blocks: Vec> = wsv + let mut blocks: Vec = wsv .blocks() .map(|blk| blk.clone()) .map(VersionedCommittedBlock::into_value) - .map(Box::new) .collect(); blocks.reverse(); Ok(blocks) diff --git a/data_model/Cargo.toml b/data_model/Cargo.toml index 8d9e4b6e901..86dbacedada 100644 --- a/data_model/Cargo.toml +++ b/data_model/Cargo.toml @@ -40,7 +40,7 @@ iroha_ffi = { path = "../ffi", version = "=2.0.0-pre-rc.5", optional = true } dashmap = { version = "4.0", optional = true} tokio = { version = "1.6.0", features = ["sync", "rt-multi-thread"], optional = true} parity-scale-codec = { version = "2.3.1", default-features = false, features = ["derive"] } -derive_more = { version = "0.99.16", default-features = false, features = ["display", "constructor", "from_str"] } +derive_more = { version = "0.99.16", default-features = false, features = ["as_ref", "display", "constructor", "from_str", "from", "into"] } serde = { version = "1.0", default-features = false, features = ["derive"] } serde_json = { version = "1.0.59", default-features = false } warp = { version = "0.3", default-features = false, optional = true } diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index 0665f3208aa..4781cce90cb 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -15,16 +15,18 @@ use alloc::{ string::{String, ToString}, vec::Vec, }; -use core::{fmt, fmt::Debug, ops::RangeInclusive}; +use core::{convert::AsRef, fmt, fmt::Debug, ops::RangeInclusive}; use block_value::BlockValue; -use derive_more::Display; +#[cfg(not(target_arch = "aarch64"))] +use derive_more::Into; +use derive_more::{AsRef, Deref, Display, From}; use events::FilterBox; use iroha_crypto::{Hash, PublicKey}; use iroha_data_primitives::small::SmallVec; pub use iroha_data_primitives::{self as primitives, fixed, small}; use iroha_macro::{error::ErrorTryFromEnum, FromVariant}; -use iroha_schema::IntoSchema; +use iroha_schema::{IntoSchema, MetaMap}; use parity_scale_codec::{Decode, Encode}; use prelude::TransactionQueryResult; use serde::{Deserialize, Serialize}; @@ -341,8 +343,68 @@ pub enum Value { /// [`struct@Hash`] Hash(Hash), /// Block - // Boxed because of M1 issues - Block(Box), + Block(BlockValueWrapper), +} + +/// Cross-platform wrapper for `BlockValue`. +#[cfg(not(target_arch = "aarch64"))] +#[derive( + AsRef, + Clone, + Debug, + Decode, + Deref, + Deserialize, + Encode, + Eq, + From, + Into, + Ord, + PartialEq, + PartialOrd, + Serialize, +)] +#[serde(transparent)] +pub struct BlockValueWrapper(BlockValue); + +/// Cross-platform wrapper for `BlockValue`. +#[cfg(target_arch = "aarch64")] +#[derive( + AsRef, + Clone, + Debug, + Decode, + Deref, + Deserialize, + Encode, + Eq, + From, + Ord, + PartialEq, + PartialOrd, + Serialize, +)] +#[as_ref(forward)] +#[deref(forward)] +#[from(forward)] +#[serde(transparent)] +pub struct BlockValueWrapper(Box); + +#[cfg(target_arch = "aarch64")] +impl From for BlockValue { + fn from(block_value: BlockValueWrapper) -> Self { + *block_value.0 + } +} + +impl IntoSchema for BlockValueWrapper { + fn type_name() -> String { + BlockValue::type_name() + } + + fn schema(map: &mut MetaMap) { + BlockValue::schema(map); + } } impl fmt::Display for Value { @@ -374,7 +436,7 @@ impl fmt::Display for Value { Value::TransactionQueryResult(_) => write!(f, "TransactionQueryResult"), Value::PermissionToken(v) => fmt::Display::fmt(&v, f), Value::Hash(v) => fmt::Display::fmt(&v, f), - Value::Block(v) => fmt::Display::fmt(&v, f), + Value::Block(v) => fmt::Display::fmt(&**v, f), } } } @@ -408,6 +470,12 @@ impl Value { } } +impl From for Value { + fn from(block_value: BlockValue) -> Self { + Value::Block(block_value.into()) + } +} + impl From> for Value where A::Item: Into, @@ -617,6 +685,18 @@ where } } +impl TryFrom for BlockValue { + type Error = ErrorTryFromEnum; + + fn try_from(value: Value) -> Result { + if let Value::Block(block_value) = value { + return Ok(block_value.into()); + } + + Err(Self::Error::default()) + } +} + impl TryFrom for small::SmallVec where Value: TryInto, diff --git a/data_model/src/query.rs b/data_model/src/query.rs index 150086a68f1..208d08c7a68 100644 --- a/data_model/src/query.rs +++ b/data_model/src/query.rs @@ -1514,7 +1514,7 @@ pub mod block { pub struct FindAllBlocks; impl Query for FindAllBlocks { - type Output = Vec>; + type Output = Vec; } impl FindAllBlocks { diff --git a/tools/parity_scale_decoder/src/generate_map.rs b/tools/parity_scale_decoder/src/generate_map.rs index f129e621872..0f0a5964473 100644 --- a/tools/parity_scale_decoder/src/generate_map.rs +++ b/tools/parity_scale_decoder/src/generate_map.rs @@ -289,6 +289,7 @@ pub fn generate_map() -> DumpDecodedMap { Vec>, Vec, Vec, + Vec, Vec, Vec, Vec, @@ -349,6 +350,16 @@ pub fn generate_map() -> DumpDecodedMap { fixed::FixNum, fixed::Fixed, i64, + iroha_data_model::predicate::PredicateBox, + iroha_data_model::predicate::numerical::Range, + iroha_data_model::predicate::numerical::SemiInterval, + iroha_data_model::predicate::numerical::SemiInterval, + iroha_data_model::predicate::numerical::SemiInterval, + iroha_data_model::predicate::string::Predicate, + iroha_data_model::predicate::value::AtIndex, + iroha_data_model::predicate::value::Container, + iroha_data_model::predicate::value::Predicate, + iroha_data_model::predicate::value::ValueOfKey, query::Payload, role::NewRole, smartcontracts::isi::error::FindError, @@ -366,17 +377,6 @@ pub fn generate_map() -> DumpDecodedMap { transaction::Payload, transaction::TransactionLimitError, transaction::WasmSmartContract, - iroha_data_model::predicate::value::Container, - Vec, - iroha_data_model::predicate::PredicateBox, - iroha_data_model::predicate::value::ValueOfKey, - iroha_data_model::predicate::numerical::Range, - iroha_data_model::predicate::numerical::SemiInterval, - iroha_data_model::predicate::numerical::SemiInterval, - iroha_data_model::predicate::numerical::SemiInterval, - iroha_data_model::predicate::string::Predicate, - iroha_data_model::predicate::value::AtIndex, - iroha_data_model::predicate::value::Predicate, u128, u32, u64,