Skip to content

Commit

Permalink
[fix] #2416: Fix lints on macOS arm (#2452)
Browse files Browse the repository at this point in the history
Signed-off-by: Ales Tsurko <ales.tsurko@gmail.com>
  • Loading branch information
ales-tsurko committed Jul 14, 2022
1 parent bf01205 commit 5ff6b67
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 21 deletions.
3 changes: 1 addition & 2 deletions core/src/smartcontracts/isi/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use super::*;
impl ValidQuery for FindAllBlocks {
#[metrics(+"find_all_blocks")]
fn execute(&self, wsv: &WorldStateView) -> Result<Self::Output, query::Error> {
let mut blocks: Vec<Box<BlockValue>> = wsv
let mut blocks: Vec<BlockValue> = wsv
.blocks()
.map(|blk| blk.clone())
.map(VersionedCommittedBlock::into_value)
.map(Box::new)
.collect();
blocks.reverse();
Ok(blocks)
Expand Down
2 changes: 1 addition & 1 deletion data_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
92 changes: 86 additions & 6 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -341,8 +343,68 @@ pub enum Value {
/// [`struct@Hash`]
Hash(Hash),
/// Block
// Boxed because of M1 issues
Block(Box<BlockValue>),
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<BlockValue>);

#[cfg(target_arch = "aarch64")]
impl From<BlockValueWrapper> 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 {
Expand Down Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -408,6 +470,12 @@ impl Value {
}
}

impl From<BlockValue> for Value {
fn from(block_value: BlockValue) -> Self {
Value::Block(block_value.into())
}
}

impl<A: small::Array> From<SmallVec<A>> for Value
where
A::Item: Into<Value>,
Expand Down Expand Up @@ -617,6 +685,18 @@ where
}
}

impl TryFrom<Value> for BlockValue {
type Error = ErrorTryFromEnum<Value, Self>;

fn try_from(value: Value) -> Result<Self, Self::Error> {
if let Value::Block(block_value) = value {
return Ok(block_value.into());
}

Err(Self::Error::default())
}
}

impl<A: small::Array> TryFrom<Value> for small::SmallVec<A>
where
Value: TryInto<A::Item>,
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ pub mod block {
pub struct FindAllBlocks;

impl Query for FindAllBlocks {
type Output = Vec<Box<BlockValue>>;
type Output = Vec<BlockValue>;
}

impl FindAllBlocks {
Expand Down
22 changes: 11 additions & 11 deletions tools/parity_scale_decoder/src/generate_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ pub fn generate_map() -> DumpDecodedMap {
Vec<SignatureOf<transaction::Payload>>,
Vec<Value>,
Vec<events::Event>,
Vec<iroha_data_model::predicate::PredicateBox>,
Vec<isi::Instruction>,
Vec<permissions::PermissionToken>,
Vec<sumeragi::view_change::Proof>,
Expand Down Expand Up @@ -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_primitives::fixed::Fixed>,
iroha_data_model::predicate::numerical::SemiInterval<u128>,
iroha_data_model::predicate::numerical::SemiInterval<u32>,
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,
Expand All @@ -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::PredicateBox,
iroha_data_model::predicate::value::ValueOfKey,
iroha_data_model::predicate::numerical::Range,
iroha_data_model::predicate::numerical::SemiInterval<u32>,
iroha_data_model::predicate::numerical::SemiInterval<u128>,
iroha_data_model::predicate::numerical::SemiInterval<iroha_data_primitives::fixed::Fixed>,
iroha_data_model::predicate::string::Predicate,
iroha_data_model::predicate::value::AtIndex,
iroha_data_model::predicate::value::Predicate,
u128,
u32,
u64,
Expand Down

0 comments on commit 5ff6b67

Please sign in to comment.