diff --git a/Cargo.lock b/Cargo.lock index c9280d663c1..e0c1750e6d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1728,8 +1728,8 @@ dependencies = [ "derive_more", "futures", "iroha_actor_derive", - "iroha_data_primitives", "iroha_logger", + "iroha_primitives", "once_cell", "petgraph", "thiserror", @@ -1776,6 +1776,7 @@ dependencies = [ "iroha_data_model", "iroha_logger", "iroha_permissions_validators", + "iroha_primitives", "iroha_telemetry", "iroha_version", "parity-scale-codec", @@ -1851,6 +1852,7 @@ dependencies = [ "iroha_logger", "iroha_macro", "iroha_p2p", + "iroha_primitives", "iroha_schema", "iroha_telemetry", "iroha_version", @@ -1876,6 +1878,7 @@ dependencies = [ "hex", "hex-literal", "iroha_ffi", + "iroha_primitives", "iroha_schema", "openssl-sys", "parity-scale-codec", @@ -1898,9 +1901,9 @@ dependencies = [ "iroha_core", "iroha_crypto", "iroha_data_model_derive", - "iroha_data_primitives", "iroha_ffi", "iroha_macro", + "iroha_primitives", "iroha_schema", "iroha_version", "parity-scale-codec", @@ -1910,7 +1913,6 @@ dependencies = [ "test_network", "thiserror", "tokio", - "trybuild", "warp", ] @@ -1923,22 +1925,6 @@ dependencies = [ "syn", ] -[[package]] -name = "iroha_data_primitives" -version = "2.0.0-pre-rc.5" -dependencies = [ - "derive_more", - "fixnum", - "iroha_macro", - "iroha_schema", - "parity-scale-codec", - "serde", - "serde_json", - "smallstr", - "smallvec", - "thiserror", -] - [[package]] name = "iroha_derive" version = "2.0.0-pre-rc.5" @@ -2054,6 +2040,23 @@ dependencies = [ "thiserror", ] +[[package]] +name = "iroha_primitives" +version = "2.0.0-pre-rc.5" +dependencies = [ + "derive_more", + "fixnum", + "iroha_macro", + "iroha_schema", + "parity-scale-codec", + "serde", + "serde_json", + "smallstr", + "smallvec", + "thiserror", + "trybuild", +] + [[package]] name = "iroha_schema" version = "2.0.0-pre-rc.5" @@ -2624,7 +2627,7 @@ dependencies = [ "iroha_core", "iroha_crypto", "iroha_data_model", - "iroha_data_primitives", + "iroha_primitives", "iroha_schema", "iroha_schema_gen", "iroha_version", @@ -3630,6 +3633,7 @@ dependencies = [ "iroha_data_model", "iroha_logger", "iroha_permissions_validators", + "iroha_primitives", "once_cell", "rand 0.8.5", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index fa683722a5e..1a6377b343d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,8 @@ members = [ "core", "core/test_network", "crypto", - "tools/kura_inspector", - "tools/parity_scale_decoder", - "tools/kagami", "data_model", - "data_model/primitives", + "primitives", "ffi", "ffi/derive", "futures", @@ -27,10 +24,13 @@ members = [ "p2p", "permissions_validators", "schema", - "schema/gen", "schema/derive", + "schema/gen", "substrate", "telemetry", + "tools/kagami", + "tools/kura_inspector", + "tools/parity_scale_decoder", "version", "version/derive", ] diff --git a/actor/Cargo.toml b/actor/Cargo.toml index 4bb7d733e96..e4f1908e176 100644 --- a/actor/Cargo.toml +++ b/actor/Cargo.toml @@ -14,7 +14,7 @@ deadlock_detection = ["petgraph"] [dependencies] iroha_actor_derive = { version = "=2.0.0-pre-rc.5", path = "derive" } iroha_logger = { version = "=2.0.0-pre-rc.5", path = "../logger" } -iroha_data_primitives = { version = "=2.0.0-pre-rc.5", path = "../data_model/primitives" } +iroha_primitives = { version = "=2.0.0-pre-rc.5", path = "../primitives" } async-trait = "0.1" once_cell = "1.8.0" diff --git a/actor/src/broker.rs b/actor/src/broker.rs index 21a1c2577bf..d011aabafee 100644 --- a/actor/src/broker.rs +++ b/actor/src/broker.rs @@ -59,7 +59,7 @@ use std::{collections::HashMap, sync::Arc}; use dashmap::{mapref::entry::Entry, DashMap}; use futures::{prelude::*, stream::FuturesUnordered}; -use iroha_data_primitives::small::{self, SmallVec}; +use iroha_primitives::small::{self, SmallVec}; use super::*; diff --git a/client/Cargo.toml b/client/Cargo.toml index 2cb73ea80cf..783da2a39a8 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -18,12 +18,13 @@ maintenance = { status = "actively-developed" } [dependencies] iroha_config = { version = "=2.0.0-pre-rc.5", path = "../config" } +iroha_core = { version = "=2.0.0-pre-rc.5", path = "../core", features = ["dev-telemetry", "telemetry"]} iroha_crypto = { version = "=2.0.0-pre-rc.5", path = "../crypto"} iroha_data_model = { version = "=2.0.0-pre-rc.5", path = "../data_model", features = ["warp"] } +iroha_primitives = { version = "=2.0.0-pre-rc.5", path = "../primitives" } iroha_logger = { version = "=2.0.0-pre-rc.5", path = "../logger"} iroha_telemetry = { version ="=2.0.0-pre-rc.5", path = "../telemetry" } iroha_version = { version = "=2.0.0-pre-rc.5", path = "../version" } -iroha_core = { version = "=2.0.0-pre-rc.5", path = "../core", features = ["dev-telemetry", "telemetry"]} attohttpc = "0.18" eyre = "0.6.5" diff --git a/client/benches/torii.rs b/client/benches/torii.rs index 94c87df6782..dac47d49627 100644 --- a/client/benches/torii.rs +++ b/client/benches/torii.rs @@ -11,6 +11,7 @@ use iroha_core::{ prelude::*, }; use iroha_data_model::prelude::*; +use iroha_primitives::small::SmallStr; use iroha_version::Encode; use test_network::{get_key_pair, Peer as TestPeer, PeerBuilder, TestRuntime}; use tokio::runtime::Runtime; @@ -65,14 +66,14 @@ fn query_requests(criterion: &mut Criterion) { let mut client_config = iroha_client::samples::get_client_config(&get_key_pair()); // TODO: We should definitely turn this into type-checked state. `String` is a terrible bodge - client_config.torii_api_url = small::SmallStr::from_string(peer.api_address.clone()); + client_config.torii_api_url = SmallStr::from_string(peer.api_address.clone()); if !client_config.torii_api_url.starts_with("http://") { client_config.torii_api_url = - small::SmallStr::from_string(format!("http://{}", client_config.torii_api_url)); + SmallStr::from_string(format!("http://{}", client_config.torii_api_url)); } if !client_config.torii_telemetry_url.starts_with("http://") { client_config.torii_telemetry_url = - small::SmallStr::from_string(format!("http://{}", client_config.torii_telemetry_url)); + SmallStr::from_string(format!("http://{}", client_config.torii_telemetry_url)); } let iroha_client = Client::new(&client_config).expect("Invalid client configuration"); thread::sleep(std::time::Duration::from_millis(5000)); @@ -149,14 +150,14 @@ fn instruction_submits(criterion: &mut Criterion) { let create_account = RegisterBox::new(Account::new(account_id.clone(), [public_key])); let asset_definition_id = AssetDefinitionId::new("xor".parse().expect("Valid"), domain_id); let mut client_config = iroha_client::samples::get_client_config(&get_key_pair()); - client_config.torii_api_url = small::SmallStr::from_string(peer.api_address.clone()); + client_config.torii_api_url = SmallStr::from_string(peer.api_address.clone()); if !client_config.torii_api_url.starts_with("http://") { client_config.torii_api_url = - small::SmallStr::from_string(format!("http://{}", client_config.torii_api_url)); + SmallStr::from_string(format!("http://{}", client_config.torii_api_url)); } if !client_config.torii_telemetry_url.starts_with("http://") { client_config.torii_telemetry_url = - small::SmallStr::from_string(format!("http://{}", client_config.torii_telemetry_url)); + SmallStr::from_string(format!("http://{}", client_config.torii_telemetry_url)); } let iroha_client = Client::new(&client_config).expect("Invalid client configuration"); thread::sleep(std::time::Duration::from_millis(5000)); diff --git a/client/src/client.rs b/client/src/client.rs index 3d0bd50e882..00eb1f9b4b5 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -12,12 +12,12 @@ use iroha_core::smartcontracts::isi::query::Error as QueryError; use iroha_crypto::{HashOf, KeyPair}; use iroha_data_model::{predicate::PredicateBox, prelude::*, query::SignedQueryRequest}; use iroha_logger::prelude::*; +use iroha_primitives::small::SmallStr; use iroha_telemetry::metrics::Status; use iroha_version::prelude::*; use parity_scale_codec::DecodeAll; use rand::Rng; use serde::de::DeserializeOwned; -use small::SmallStr; use crate::{ config::Configuration, diff --git a/client/src/config.rs b/client/src/config.rs index 5ec2da5a149..b70340de470 100644 --- a/client/src/config.rs +++ b/client/src/config.rs @@ -6,8 +6,8 @@ use iroha_config::derive::Configurable; use iroha_crypto::prelude::*; use iroha_data_model::{prelude::*, transaction}; use iroha_logger::Configuration as LoggerConfiguration; +use iroha_primitives::small::SmallStr; use serde::{Deserialize, Serialize}; -use small::SmallStr; const DEFAULT_TORII_TELEMETRY_URL: &str = "127.0.0.1:8180"; const DEFAULT_TRANSACTION_TIME_TO_LIVE_MS: u64 = 100_000; @@ -100,8 +100,8 @@ impl Default for Configuration { private_key, account_id: Self::placeholder_account(), basic_auth: None, - torii_api_url: small::SmallStr::from_str(uri::DEFAULT_API_URL), - torii_telemetry_url: small::SmallStr::from_str(DEFAULT_TORII_TELEMETRY_URL), + torii_api_url: SmallStr::from_str(uri::DEFAULT_API_URL), + torii_telemetry_url: SmallStr::from_str(DEFAULT_TORII_TELEMETRY_URL), transaction_time_to_live_ms: DEFAULT_TRANSACTION_TIME_TO_LIVE_MS, transaction_status_timeout_ms: DEFAULT_TRANSACTION_STATUS_TIMEOUT_MS, transaction_limits: TransactionLimits { diff --git a/client/src/lib.rs b/client/src/lib.rs index cc8f68be429..3f47b7b1be1 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -24,7 +24,7 @@ pub mod samples { public_key, private_key, account_id: "alice@wonderland".parse().expect("Should not fail."), - torii_api_url: iroha_data_model::small::SmallStr::from_str(uri::DEFAULT_API_URL), + torii_api_url: iroha_primitives::small::SmallStr::from_str(uri::DEFAULT_API_URL), ..Configuration::default() } } diff --git a/client/tests/integration/asset.rs b/client/tests/integration/asset.rs index b2d49f51eaa..182c332dab8 100644 --- a/client/tests/integration/asset.rs +++ b/client/tests/integration/asset.rs @@ -4,7 +4,8 @@ use std::{str::FromStr as _, thread}; use eyre::Result; use iroha_client::client; -use iroha_data_model::{fixed::Fixed, prelude::*}; +use iroha_data_model::prelude::*; +use iroha_primitives::fixed::Fixed; use test_network::*; use super::Configuration; diff --git a/client/tests/integration/multisignature_transaction.rs b/client/tests/integration/multisignature_transaction.rs index 4b84f375cca..416bd8f14d6 100644 --- a/client/tests/integration/multisignature_transaction.rs +++ b/client/tests/integration/multisignature_transaction.rs @@ -8,6 +8,7 @@ use iroha_client::{ }; use iroha_core::prelude::*; use iroha_data_model::{account::TRANSACTION_SIGNATORIES_VALUE, prelude::*}; +use iroha_primitives::small::SmallStr; use test_network::*; use super::Configuration; @@ -71,7 +72,7 @@ fn multisignature_transactions_should_wait_for_all_signatures() { thread::sleep(pipeline_time); //Then - client_configuration.torii_api_url = small::SmallStr::from_string( + client_configuration.torii_api_url = SmallStr::from_string( "http://".to_owned() + &network.peers.values().last().unwrap().api_address, ); let iroha_client_1 = Client::new(&client_configuration).expect("Invalid client configuration"); diff --git a/client/tests/integration/transfer_asset.rs b/client/tests/integration/transfer_asset.rs index e6690e41d52..e687b852fe1 100644 --- a/client/tests/integration/transfer_asset.rs +++ b/client/tests/integration/transfer_asset.rs @@ -3,6 +3,7 @@ use iroha_client::client; use iroha_core::prelude::*; use iroha_data_model::{prelude::*, Registered}; +use iroha_primitives::fixed::Fixed; use test_network::*; #[test] diff --git a/core/Cargo.toml b/core/Cargo.toml index 38e6a47c668..39ac9dab93f 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -34,17 +34,18 @@ is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/ir maintenance = { status = "actively-developed" } [dependencies] -iroha_data_model = { version = "=2.0.0-pre-rc.5", path = "../data_model", features = ["mutable_api", "warp"] } -iroha_macro = { version = "=2.0.0-pre-rc.5", path = "../macro" } -iroha_p2p = { version = "=2.0.0-pre-rc.5", path = "../p2p" } -iroha_logger = { version = "=2.0.0-pre-rc.5", path = "../logger"} -iroha_crypto = { version = "=2.0.0-pre-rc.5", path = "../crypto" } -iroha_version = { version = "=2.0.0-pre-rc.5", path = "../version", features = ["warp"] } iroha_actor = { version = "=2.0.0-pre-rc.5", path = "../actor" } iroha_config = { version = "=2.0.0-pre-rc.5", path = "../config" } +iroha_crypto = { version = "=2.0.0-pre-rc.5", path = "../crypto" } +iroha_data_model = { version = "=2.0.0-pre-rc.5", path = "../data_model", features = ["mutable_api", "warp"] } +iroha_primitives = { version = "=2.0.0-pre-rc.5", path = "../primitives" } iroha_futures = { version = "=2.0.0-pre-rc.5", path = "../futures" } -iroha_telemetry = { version = "=2.0.0-pre-rc.5", path = "../telemetry" } +iroha_logger = { version = "=2.0.0-pre-rc.5", path = "../logger"} +iroha_macro = { version = "=2.0.0-pre-rc.5", path = "../macro" } +iroha_p2p = { version = "=2.0.0-pre-rc.5", path = "../p2p" } iroha_schema = { version = "=2.0.0-pre-rc.5", path = "../schema" } +iroha_telemetry = { version = "=2.0.0-pre-rc.5", path = "../telemetry" } +iroha_version = { version = "=2.0.0-pre-rc.5", path = "../version", features = ["warp"] } async-trait = "0.1" async-stream = "0.3.2" diff --git a/core/src/genesis.rs b/core/src/genesis.rs index ba6aa4b2620..72305228327 100644 --- a/core/src/genesis.rs +++ b/core/src/genesis.rs @@ -10,9 +10,9 @@ use eyre::{eyre, Result, WrapErr}; use iroha_actor::Addr; use iroha_crypto::{KeyPair, PublicKey}; use iroha_data_model::{asset::AssetDefinition, prelude::*}; +use iroha_primitives::small::{smallvec, SmallVec}; use iroha_schema::prelude::*; use serde::{Deserialize, Serialize}; -use small::{smallvec, SmallVec}; use tokio::{time, time::Duration}; pub use self::config::GenesisConfiguration; @@ -421,7 +421,7 @@ impl RawGenesisBlockBuilder { pub fn new() -> Self { RawGenesisBlockBuilder { transaction: GenesisTransaction { - isi: iroha_data_model::small::SmallVec::new(), + isi: SmallVec::new(), }, } } diff --git a/core/src/smartcontracts/isi/asset.rs b/core/src/smartcontracts/isi/asset.rs index 0289dbdef9a..5e9710628ca 100644 --- a/core/src/smartcontracts/isi/asset.rs +++ b/core/src/smartcontracts/isi/asset.rs @@ -1,10 +1,8 @@ //! This module contains [`Asset`] structure, it's implementation and related traits and //! instructions implementations. -use iroha_data_model::{ - prelude::*, - primitives::{CheckedOp, IntoMetric}, -}; +use iroha_data_model::prelude::*; +use iroha_primitives::{fixed::Fixed, CheckedOp, IntoMetric}; use iroha_telemetry::metrics; use super::prelude::*; diff --git a/core/src/smartcontracts/isi/mod.rs b/core/src/smartcontracts/isi/mod.rs index d35b7adcb97..4ce45ad89f7 100644 --- a/core/src/smartcontracts/isi/mod.rs +++ b/core/src/smartcontracts/isi/mod.rs @@ -16,6 +16,7 @@ pub use error::*; use eyre::Result; use iroha_data_model::{expression::prelude::*, isi::*, prelude::*}; use iroha_logger::prelude::*; +use iroha_primitives::fixed::Fixed; use super::{Evaluate, Execute}; use crate::{prelude::*, wsv::WorldStateView}; @@ -30,7 +31,8 @@ pub mod error { use derive_more::Display; use iroha_crypto::HashOf; - use iroha_data_model::{fixed::FixedPointOperationError, metadata, prelude::*, trigger}; + use iroha_data_model::{metadata, prelude::*, trigger}; + use iroha_primitives::fixed::FixedPointOperationError; use iroha_schema::IntoSchema; use parity_scale_codec::{Decode, Encode}; use thiserror::Error; diff --git a/core/src/wsv.rs b/core/src/wsv.rs index e2d52668dc4..ef810adc915 100644 --- a/core/src/wsv.rs +++ b/core/src/wsv.rs @@ -11,8 +11,9 @@ use dashmap::{ use eyre::Result; use getset::Getters; use iroha_crypto::HashOf; -use iroha_data_model::{prelude::*, small::SmallVec}; +use iroha_data_model::prelude::*; use iroha_logger::prelude::*; +use iroha_primitives::small::SmallVec; use iroha_telemetry::metrics::Metrics; use tokio::{sync::broadcast, task}; diff --git a/core/test_network/Cargo.toml b/core/test_network/Cargo.toml index 91876abaeb8..fbe73f8eafc 100644 --- a/core/test_network/Cargo.toml +++ b/core/test_network/Cargo.toml @@ -15,6 +15,7 @@ iroha_actor = { version = "=2.0.0-pre-rc.5", path = "../../actor" } iroha_client = { version = "=2.0.0-pre-rc.5", path = "../../client" } iroha_core = { version = "=2.0.0-pre-rc.5", path = "../../core" } iroha_data_model = { version = "=2.0.0-pre-rc.5", path = "../../data_model" } +iroha_primitives = { version = "=2.0.0-pre-rc.5", path = "../../primitives" } iroha_logger = { version = "=2.0.0-pre-rc.5", path = "../../logger" } iroha_permissions_validators = { version = "=2.0.0-pre-rc.5", path = "../../permissions_validators" } diff --git a/core/test_network/src/lib.rs b/core/test_network/src/lib.rs index 1c354a6c45f..469dd6faf57 100644 --- a/core/test_network/src/lib.rs +++ b/core/test_network/src/lib.rs @@ -22,6 +22,7 @@ use iroha_logger::{Configuration as LoggerConfiguration, InstrumentFutures}; use iroha_permissions_validators::public_blockchain::{ burn::CanBurnAssetWithDefinition, mint::CanMintUserAssetDefinitions, }; +use iroha_primitives::small; use rand::seq::IteratorRandom; use tempfile::TempDir; use tokio::{ diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index b2aefdb8e3b..9a54ab7948f 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -17,6 +17,7 @@ vendored = ["openssl-sys"] ffi_api = ["iroha_ffi"] [dependencies] +iroha_primitives = { path = "../primitives", version = "=2.0.0-pre-rc.5", default-features = false } iroha_ffi = { path = "../ffi", version = "=2.0.0-pre-rc.5", optional = true } iroha_schema = { path = "../schema" } diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 9a65b61c88d..2d6acd31afb 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -20,6 +20,7 @@ pub use base64; use derive_more::{DebugCustom, Display}; use getset::Getters; pub use hash::*; +use iroha_primitives::conststr::ConstString; use iroha_schema::IntoSchema; pub use merkle::MerkleTree; use multihash::{DigestFunction as MultihashDigestFunction, Multihash}; @@ -282,7 +283,7 @@ impl KeyPair { /// Fails if decoding fails #[cfg(feature = "std")] pub fn generate_with_configuration(configuration: KeyGenConfiguration) -> Result { - let digest_function = configuration.algorithm.to_string(); + let digest_function: ConstString = configuration.algorithm.to_string().into(); let key_gen_option: Option = configuration .key_gen_option @@ -367,7 +368,7 @@ impl std::error::Error for KeyParseError {} pub struct PublicKey { /// Digest function #[getset(skip)] - digest_function: String, + digest_function: ConstString, /// payload of key payload: Vec, } @@ -419,7 +420,7 @@ impl From for PublicKey { }; Self { - digest_function: digest_function.to_string(), + digest_function: digest_function.to_string().into(), payload: multihash.payload, } } @@ -470,7 +471,7 @@ impl<'de> Deserialize<'de> for PublicKey { impl Decode for PublicKey { fn decode(input: &mut I) -> Result { - let digest_function = String::decode(input)?; + let digest_function = ConstString::decode(input)?; if Algorithm::from_str(&digest_function).is_err() { return Err(ScaleError::from("Algorithm not supported")); @@ -491,7 +492,7 @@ impl Decode for PublicKey { pub struct PrivateKey { /// Digest function #[getset(skip)] - digest_function: String, + digest_function: ConstString, /// key payload. WARNING! Do not use `"string".as_bytes()` to obtain the key. #[serde(with = "hex::serde")] payload: Vec, @@ -518,7 +519,7 @@ impl PrivateKey { .collect(); Ok(Self { - digest_function: digest_function.to_string(), + digest_function: digest_function.to_string().into(), payload: hex::decode(payload)?, }) } @@ -539,7 +540,7 @@ impl<'de> Deserialize<'de> for PrivateKey { #[derive(Deserialize)] struct PrivateKey { - digest_function: String, + digest_function: ConstString, #[serde(with = "hex::serde")] payload: Vec, } @@ -613,7 +614,7 @@ mod tests { format!( "{}", PublicKey { - digest_function: Algorithm::Ed25519.to_string(), + digest_function: Algorithm::Ed25519.to_string().into(), payload: hex::decode( "1509a611ad6d97b01d871e58ed00c8fd7c3917b6ca61a8c2833a19e000aac2e4" ) @@ -626,7 +627,7 @@ mod tests { format!( "{}", PublicKey { - digest_function: Algorithm::Secp256k1.to_string(), + digest_function: Algorithm::Secp256k1.to_string().into(), payload: hex::decode( "0312273e8810581e58948d3fb8f9e8ad53aaa21492ebb8703915bbb565a21b7fcc" ) @@ -639,7 +640,7 @@ mod tests { format!( "{}", PublicKey { - digest_function: Algorithm::BlsNormal.to_string(), + digest_function: Algorithm::BlsNormal.to_string().into(), payload: hex::decode( "04175b1e79b15e8a2d5893bf7f8933ca7d0863105d8bac3d6f976cb043378a0e4b885c57ed14eb85fc2fabc639adc7de7f0020c70c57acc38dee374af2c04a6f61c11de8df9034b12d849c7eb90099b0881267d0e1507d4365d838d7dcc31511e7" ) @@ -652,7 +653,7 @@ mod tests { format!( "{}", PublicKey { - digest_function: Algorithm::BlsSmall.to_string(), + digest_function: Algorithm::BlsSmall.to_string().into(), payload: hex::decode( "040cb3231f601e7245a6ec9a647b450936f707ca7dc347ed258586c1924941d8bc38576473a8ba3bb2c37e3e121130ab67103498a96d0d27003e3ad960493da79209cf024e2aa2ae961300976aeee599a31a5e1b683eaa1bcffc47b09757d20f21123c594cf0ee0baf5e1bdd272346b7dc98a8f12c481a6b28174076a352da8eae881b90911013369d7fa960716a5abc5314307463fa2285a5bf2a5b5c6220d68c2d34101a91dbfc531c5b9bbfb2245ccc0c50051f79fc6714d16907b1fc40e0c0" ) @@ -681,14 +682,14 @@ mod tests { }").expect("Failed to deserialize."), TestJson { public_key: PublicKey { - digest_function: Algorithm::Ed25519.to_string(), + digest_function: Algorithm::Ed25519.to_string().into(), payload: hex::decode( "1509a611ad6d97b01d871e58ed00c8fd7c3917b6ca61a8c2833a19e000aac2e4" ) .expect("Failed to decode public key.") }, private_key: PrivateKey { - digest_function: Algorithm::Ed25519.to_string(), + digest_function: Algorithm::Ed25519.to_string().into(), payload: hex::decode("3a7991af1abb77f3fd27cc148404a6ae4439d095a63591b77c788d53f708a02a1509a611ad6d97b01d871e58ed00c8fd7c3917b6ca61a8c2833a19e000aac2e4") .expect("Failed to decode private key"), } @@ -704,14 +705,14 @@ mod tests { }").expect("Failed to deserialize."), TestJson { public_key: PublicKey { - digest_function: Algorithm::Secp256k1.to_string(), + digest_function: Algorithm::Secp256k1.to_string().into(), payload: hex::decode( "0312273e8810581e58948d3fb8f9e8ad53aaa21492ebb8703915bbb565a21b7fcc" ) .expect("Failed to decode public key.") }, private_key: PrivateKey { - digest_function: Algorithm::Secp256k1.to_string(), + digest_function: Algorithm::Secp256k1.to_string().into(), payload: hex::decode("4df4fca10762d4b529fe40a2188a60ca4469d2c50a825b5f33adc2cb78c69445") .expect("Failed to decode private key"), } @@ -727,14 +728,14 @@ mod tests { }").expect("Failed to deserialize."), TestJson { public_key: PublicKey { - digest_function: Algorithm::BlsNormal.to_string(), + digest_function: Algorithm::BlsNormal.to_string().into(), payload: hex::decode( "04175b1e79b15e8a2d5893bf7f8933ca7d0863105d8bac3d6f976cb043378a0e4b885c57ed14eb85fc2fabc639adc7de7f0020c70c57acc38dee374af2c04a6f61c11de8df9034b12d849c7eb90099b0881267d0e1507d4365d838d7dcc31511e7" ) .expect("Failed to decode public key.") }, private_key: PrivateKey { - digest_function: Algorithm::BlsNormal.to_string(), + digest_function: Algorithm::BlsNormal.to_string().into(), payload: hex::decode("000000000000000000000000000000002f57460183837efbac6aa6ab3b8dbb7cffcfc59e9448b7860a206d37d470cba3") .expect("Failed to decode private key"), } @@ -750,14 +751,14 @@ mod tests { }").expect("Failed to deserialize."), TestJson { public_key: PublicKey { - digest_function: Algorithm::BlsSmall.to_string(), + digest_function: Algorithm::BlsSmall.to_string().into(), payload: hex::decode( "040cb3231f601e7245a6ec9a647b450936f707ca7dc347ed258586c1924941d8bc38576473a8ba3bb2c37e3e121130ab67103498a96d0d27003e3ad960493da79209cf024e2aa2ae961300976aeee599a31a5e1b683eaa1bcffc47b09757d20f21123c594cf0ee0baf5e1bdd272346b7dc98a8f12c481a6b28174076a352da8eae881b90911013369d7fa960716a5abc5314307463fa2285a5bf2a5b5c6220d68c2d34101a91dbfc531c5b9bbfb2245ccc0c50051f79fc6714d16907b1fc40e0c0" ) .expect("Failed to decode public key.") }, private_key: PrivateKey { - digest_function: Algorithm::BlsSmall.to_string(), + digest_function: Algorithm::BlsSmall.to_string().into(), payload: hex::decode("0000000000000000000000000000000060f3c1ac9addbbed8db83bc1b2ef22139fb049eecb723a557a41ca1a4b1fed63") .expect("Failed to decode private key"), } diff --git a/data_model/Cargo.toml b/data_model/Cargo.toml index 86dbacedada..a78b6a2f0fd 100644 --- a/data_model/Cargo.toml +++ b/data_model/Cargo.toml @@ -21,7 +21,7 @@ default = ["std"] # Enable static linkage of the rust standard library. # Disabled for WASM interoperability, to reduce the binary size. # Please refer to https://docs.rust-embedded.org/book/intro/no-std.html -std = ["iroha_macro/std", "iroha_version/std", "iroha_version/warp", "iroha_crypto/std", "iroha_data_primitives/std", "thiserror", "strum/std", "dashmap", "tokio"] +std = ["iroha_macro/std", "iroha_version/std", "iroha_version/warp", "iroha_crypto/std", "iroha_primitives/std", "thiserror", "strum/std", "dashmap", "tokio"] # Expose FFI API to facilitate dynamic linking ffi_api = ["iroha_ffi", "iroha_crypto/ffi_api"] @@ -29,7 +29,7 @@ ffi_api = ["iroha_ffi", "iroha_crypto/ffi_api"] mutable_api = [] [dependencies] -iroha_data_primitives = { path = "primitives", version = "=2.0.0-pre-rc.5", default-features = false } +iroha_primitives = { path = "../primitives", version = "=2.0.0-pre-rc.5", default-features = false } iroha_data_model_derive = { path = "derive", version = "=2.0.0-pre-rc.5" } iroha_crypto = { path = "../crypto", version = "=2.0.0-pre-rc.5", default-features = false } iroha_macro = { path = "../macro", version = "=2.0.0-pre-rc.5", default-features = false } @@ -57,7 +57,6 @@ hex = { version = "0.4.0", default-features = false, features = ["alloc", "serde test_network = { path = "../core/test_network", version = "=2.0.0-pre-rc.5" } tokio = { version = "1.6.0", features = ["rt", "rt-multi-thread"]} -trybuild = "1.0.53" criterion = "0.3" [[bench]] diff --git a/data_model/src/asset.rs b/data_model/src/asset.rs index 8e0a60d0133..8fe7ba6850e 100644 --- a/data_model/src/asset.rs +++ b/data_model/src/asset.rs @@ -10,14 +10,15 @@ use std::collections::btree_map; use derive_more::Display; use getset::{Getters, MutGetters, Setters}; use iroha_macro::FromVariant; +use iroha_primitives::{fixed, fixed::Fixed}; use iroha_schema::IntoSchema; use parity_scale_codec::{Decode, Encode}; use serde::{Deserialize, Serialize}; use strum::EnumString; use crate::{ - account::prelude::*, domain::prelude::*, fixed, fixed::Fixed, metadata::Metadata, HasMetadata, - Identifiable, Name, ParseError, Registered, TryAsMut, TryAsRef, Value, + account::prelude::*, domain::prelude::*, metadata::Metadata, HasMetadata, Identifiable, Name, + ParseError, Registered, TryAsMut, TryAsRef, Value, }; /// [`AssetsMap`] provides an API to work with collection of key ([`Id`]) - value diff --git a/data_model/src/domain.rs b/data_model/src/domain.rs index c86c62fd7e2..091f0cdd423 100644 --- a/data_model/src/domain.rs +++ b/data_model/src/domain.rs @@ -14,6 +14,7 @@ use getset::{Getters, MutGetters}; use iroha_crypto::PublicKey; #[cfg(feature = "ffi_api")] use iroha_ffi::ffi_bindgen; +use iroha_primitives::conststr::ConstString; use iroha_schema::IntoSchema; use parity_scale_codec::{Decode, Encode, Input}; use serde::{Deserialize, Serialize}; @@ -340,7 +341,7 @@ impl FromIterator for crate::Value { /// Represents path in IPFS. Performs checks to ensure path validity. /// Construct using [`FromStr::from_str`] method. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Serialize, IntoSchema)] -pub struct IpfsPath(String); +pub struct IpfsPath(ConstString); impl FromStr for IpfsPath { type Err = ParseError; @@ -377,7 +378,7 @@ impl FromStr for IpfsPath { Self::check_cid(path)?; } - Ok(IpfsPath(String::from(string))) + Ok(IpfsPath(ConstString::from(string))) } } @@ -421,7 +422,7 @@ impl<'de> Deserialize<'de> for IpfsPath { impl Decode for IpfsPath { fn decode(input: &mut I) -> Result { - let name = String::decode(input)?; + let name = ConstString::decode(input)?; Self::from_str(&name).map_err(|error| error.reason.into()) } } @@ -517,7 +518,7 @@ mod tests { #[test] fn deserialize_ipfs() { for invalid_ipfs in INVALID_IPFS { - let invalid_ipfs = IpfsPath(invalid_ipfs.to_owned()); + let invalid_ipfs = IpfsPath(invalid_ipfs.into()); let serialized = serde_json::to_string(&invalid_ipfs).expect("Valid"); let ipfs = serde_json::from_str::(serialized.as_str()); @@ -528,7 +529,7 @@ mod tests { #[test] fn decode_ipfs() { for invalid_ipfs in INVALID_IPFS { - let invalid_ipfs = IpfsPath(invalid_ipfs.to_owned()); + let invalid_ipfs = IpfsPath(invalid_ipfs.into()); let bytes = invalid_ipfs.encode(); let ipfs = IpfsPath::decode(&mut &bytes[..]); diff --git a/data_model/src/events/data/events.rs b/data_model/src/events/data/events.rs index 010445b0a14..44311915c7e 100644 --- a/data_model/src/events/data/events.rs +++ b/data_model/src/events/data/events.rs @@ -1,7 +1,7 @@ //! This module contains data events use iroha_data_model_derive::Filter; -use iroha_data_primitives::small::SmallVec; +use iroha_primitives::small::SmallVec; use super::*; diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index 72c920ea9bf..74a1e64b97b 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -23,9 +23,8 @@ 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_primitives::{fixed, small, small::SmallVec}; use iroha_schema::{IntoSchema, MetaMap}; use parity_scale_codec::{Decode, Encode}; use prelude::TransactionQueryResult; @@ -873,7 +872,6 @@ pub mod prelude { asset::prelude::*, block_value::prelude::*, domain::prelude::*, - fixed::prelude::*, name::prelude::*, pagination::{prelude::*, Pagination}, peer::prelude::*, @@ -884,7 +882,6 @@ pub mod prelude { }; pub use crate::{ events::prelude::*, expression::prelude::*, isi::prelude::*, metadata::prelude::*, - permissions::prelude::*, query::prelude::*, small, transaction::prelude::*, - trigger::prelude::*, + permissions::prelude::*, query::prelude::*, transaction::prelude::*, trigger::prelude::*, }; } diff --git a/data_model/src/name.rs b/data_model/src/name.rs index f014834cd38..2d3125bfe36 100644 --- a/data_model/src/name.rs +++ b/data_model/src/name.rs @@ -5,7 +5,7 @@ use alloc::{format, string::String, vec::Vec}; use core::{ops::RangeInclusive, str::FromStr}; use derive_more::{DebugCustom, Display}; -use iroha_data_primitives::conststr::ConstString; +use iroha_primitives::conststr::ConstString; use iroha_schema::IntoSchema; use parity_scale_codec::{Decode, Encode, Input}; use serde::{Deserialize, Serialize}; @@ -22,7 +22,7 @@ use crate::{ParseError, ValidationError}; pub struct Name(ConstString); impl Name { - /// Check if `range` contains the number of chars in the inner `String` of this [`Name`]. + /// Check if `range` contains the number of chars in the inner `ConstString` of this [`Name`]. /// /// # Errors /// Fails if `range` does not diff --git a/data_model/src/predicate.rs b/data_model/src/predicate.rs index 4f22d148bd8..71d8587e743 100644 --- a/data_model/src/predicate.rs +++ b/data_model/src/predicate.rs @@ -414,7 +414,7 @@ pub mod numerical { //! Numerical predicates. use core::cmp::{max, min}; - use iroha_data_primitives::fixed::Fixed; + use iroha_primitives::fixed::Fixed; use super::*; @@ -536,6 +536,8 @@ pub mod numerical { mod tests { #![allow(clippy::print_stdout, clippy::use_debug)] + use iroha_primitives::fixed::Fixed; + use super::*; #[test] @@ -564,7 +566,6 @@ pub mod numerical { #[test] #[allow(clippy::panic_in_result_fn)] // ? for syntax simplicity. fn semi_interval_semantics_fixed() -> Result<(), fixed::FixedPointOperationError> { - use crate::prelude::Fixed; let pred = Range::Fixed((Fixed::try_from(1_f64)?, Fixed::try_from(100_f64)?).into()); assert!(pred.applies(&Value::Fixed(Fixed::try_from(1_f64)?))); @@ -588,7 +589,6 @@ pub mod numerical { #[test] fn upper_bounds() { - use crate::prelude::Fixed; { let pred = Range::Fixed(SemiInterval::starting(Fixed::ZERO)); // Technically the maximum itself is never included in the range. diff --git a/data_model/src/trigger/mod.rs b/data_model/src/trigger/mod.rs index 878b962044a..5f7ba5adf98 100644 --- a/data_model/src/trigger/mod.rs +++ b/data_model/src/trigger/mod.rs @@ -215,7 +215,7 @@ impl FromStr for Id { pub mod action { //! Contains trigger action and common trait for all actions - use iroha_data_primitives::atomic::AtomicU32; + use iroha_primitives::atomic::AtomicU32; use super::*; use crate::HasMetadata; diff --git a/data_model/tests/data_model.rs b/data_model/tests/data_model.rs index f38e1ac444a..baeb4723eb7 100644 --- a/data_model/tests/data_model.rs +++ b/data_model/tests/data_model.rs @@ -9,7 +9,7 @@ use iroha_core::{ prelude::*, }; use iroha_data_model::{prelude::*, ParseError}; -use small::SmallStr; +use iroha_primitives::small::SmallStr; use test_network::{prepare_test_for_nextest, Peer as TestPeer, PeerBuilder, TestRuntime}; use tokio::runtime::Runtime; diff --git a/data_model/primitives/Cargo.toml b/primitives/Cargo.toml similarity index 87% rename from data_model/primitives/Cargo.toml rename to primitives/Cargo.toml index 8afaacab8c9..b2be2680196 100644 --- a/data_model/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "iroha_data_primitives" +name = "iroha_primitives" version = "2.0.0-pre-rc.5" authors = ["Iroha 2 team "] edition = "2021" @@ -23,8 +23,8 @@ default = ["std"] std = ["iroha_macro/std", "fixnum/std", "thiserror"] [dependencies] -iroha_macro = { path = "../../macro", version = "=2.0.0-pre-rc.5", default-features = false } -iroha_schema = { path = "../../schema", version = "=2.0.0-pre-rc.5", default-features = false } +iroha_macro = { path = "../macro", version = "=2.0.0-pre-rc.5", default-features = false } +iroha_schema = { path = "../schema", version = "=2.0.0-pre-rc.5", default-features = false } parity-scale-codec = { version = "2.3.1", default-features = false, features = ["derive"] } fixnum = { version = "0.6.1", default-features = false, features = ["serde", "parity", "i64"]} @@ -36,3 +36,4 @@ thiserror = { version = "1.0.28", optional = true } [dev-dependencies] serde_json = { version = "1.0.59", default-features = false, features = ["alloc"] } +trybuild = "1.0.53" diff --git a/data_model/primitives/src/atomic.rs b/primitives/src/atomic.rs similarity index 100% rename from data_model/primitives/src/atomic.rs rename to primitives/src/atomic.rs diff --git a/data_model/primitives/src/conststr.rs b/primitives/src/conststr.rs similarity index 100% rename from data_model/primitives/src/conststr.rs rename to primitives/src/conststr.rs diff --git a/data_model/primitives/src/fixed.rs b/primitives/src/fixed.rs similarity index 100% rename from data_model/primitives/src/fixed.rs rename to primitives/src/fixed.rs diff --git a/data_model/primitives/src/lib.rs b/primitives/src/lib.rs similarity index 100% rename from data_model/primitives/src/lib.rs rename to primitives/src/lib.rs diff --git a/data_model/primitives/src/small.rs b/primitives/src/small.rs similarity index 100% rename from data_model/primitives/src/small.rs rename to primitives/src/small.rs diff --git a/data_model/tests/ui.rs b/primitives/tests/ui.rs similarity index 100% rename from data_model/tests/ui.rs rename to primitives/tests/ui.rs diff --git a/data_model/tests/ui_fail/fix_num_private.rs b/primitives/tests/ui_fail/fix_num_private.rs similarity index 63% rename from data_model/tests/ui_fail/fix_num_private.rs rename to primitives/tests/ui_fail/fix_num_private.rs index 313d9701b33..d383abec4f7 100644 --- a/data_model/tests/ui_fail/fix_num_private.rs +++ b/primitives/tests/ui_fail/fix_num_private.rs @@ -1,4 +1,4 @@ -use iroha_data_model::fixed::{Fixed, FixNum}; +use iroha_primitives::fixed::{Fixed, FixNum}; fn main() { let quantity = Fixed(FixNum::try_from(-123.45_f64).unwrap()); diff --git a/data_model/tests/ui_fail/fix_num_private.stderr b/primitives/tests/ui_fail/fix_num_private.stderr similarity index 54% rename from data_model/tests/ui_fail/fix_num_private.stderr rename to primitives/tests/ui_fail/fix_num_private.stderr index 717fb913e95..070f500cc2c 100644 --- a/data_model/tests/ui_fail/fix_num_private.stderr +++ b/primitives/tests/ui_fail/fix_num_private.stderr @@ -5,18 +5,7 @@ error[E0423]: cannot initialize a tuple struct which contains private fields | ^^^^^ | note: constructor is not visible here due to private fields - --> primitives/src/fixed.rs + --> src/fixed.rs | | pub struct Fixed(FixNum); | ^^^^^^ private field -help: consider importing one of these items instead - | -1 | use iroha_core::tx::AssetValue::Fixed; - | -1 | use iroha_core::tx::AssetValueType::Fixed; - | -1 | use iroha_core::tx::Value::Fixed; - | -1 | use iroha_data_model::Value::Fixed; - | - and 3 other candidates diff --git a/data_model/tests/ui_fail/neg_one_private.rs b/primitives/tests/ui_fail/neg_one_private.rs similarity index 59% rename from data_model/tests/ui_fail/neg_one_private.rs rename to primitives/tests/ui_fail/neg_one_private.rs index ed2766be6e1..fa8bf005808 100644 --- a/data_model/tests/ui_fail/neg_one_private.rs +++ b/primitives/tests/ui_fail/neg_one_private.rs @@ -1,4 +1,4 @@ -use iroha_data_model::fixed::Fixed; +use iroha_primitives::fixed::Fixed; fn main() { let qty = Fixed::negative_one(); diff --git a/data_model/tests/ui_fail/neg_one_private.stderr b/primitives/tests/ui_fail/neg_one_private.stderr similarity index 63% rename from data_model/tests/ui_fail/neg_one_private.stderr rename to primitives/tests/ui_fail/neg_one_private.stderr index 56836d21c68..a6c38892157 100644 --- a/data_model/tests/ui_fail/neg_one_private.stderr +++ b/primitives/tests/ui_fail/neg_one_private.stderr @@ -1,5 +1,5 @@ -error[E0599]: no function or associated item named `negative_one` found for struct `iroha_data_model::prelude::Fixed` in the current scope +error[E0599]: no function or associated item named `negative_one` found for struct `Fixed` in the current scope --> tests/ui_fail/neg_one_private.rs:4:22 | 4 | let qty = Fixed::negative_one(); - | ^^^^^^^^^^^^ function or associated item not found in `iroha_data_model::prelude::Fixed` + | ^^^^^^^^^^^^ function or associated item not found in `Fixed` diff --git a/data_model/tests/ui_fail/no_conversion.rs b/primitives/tests/ui_fail/no_conversion.rs similarity index 52% rename from data_model/tests/ui_fail/no_conversion.rs rename to primitives/tests/ui_fail/no_conversion.rs index 855c3c5514f..ea90ca34843 100644 --- a/data_model/tests/ui_fail/no_conversion.rs +++ b/primitives/tests/ui_fail/no_conversion.rs @@ -1,4 +1,4 @@ -use iroha_data_model::fixed::Fixed; +use iroha_primitives::fixed::Fixed; fn main() { Fixed::from(-1_f64); diff --git a/data_model/tests/ui_fail/no_conversion.stderr b/primitives/tests/ui_fail/no_conversion.stderr similarity index 53% rename from data_model/tests/ui_fail/no_conversion.stderr rename to primitives/tests/ui_fail/no_conversion.stderr index d698f64258b..b277bbd9280 100644 --- a/data_model/tests/ui_fail/no_conversion.stderr +++ b/primitives/tests/ui_fail/no_conversion.stderr @@ -2,4 +2,4 @@ error[E0308]: mismatched types --> tests/ui_fail/no_conversion.rs:4:17 | 4 | Fixed::from(-1_f64); - | ^^^^^^ expected struct `iroha_data_model::prelude::Fixed`, found `f64` + | ^^^^^^ expected struct `Fixed`, found `f64` diff --git a/tools/parity_scale_decoder/Cargo.toml b/tools/parity_scale_decoder/Cargo.toml index 7149c65d226..7f361b0acab 100644 --- a/tools/parity_scale_decoder/Cargo.toml +++ b/tools/parity_scale_decoder/Cargo.toml @@ -13,7 +13,7 @@ no-color = ["colored/no-color"] [dependencies] iroha_data_model = { version = "=2.0.0-pre-rc.5", path = "../../data_model", features = ["warp"]} -iroha_data_primitives = { version = "=2.0.0-pre-rc.5", path = "../../data_model/primitives", default-features = false } +iroha_primitives = { version = "=2.0.0-pre-rc.5", path = "../../primitives", default-features = false } iroha_schema = { version = "=2.0.0-pre-rc.5", path = "../../schema"} iroha_core = { version = "=2.0.0-pre-rc.5", path = "../../core"} iroha_crypto = { version = "=2.0.0-pre-rc.5", path = "../../crypto", default-features = false } diff --git a/tools/parity_scale_decoder/src/generate_map.rs b/tools/parity_scale_decoder/src/generate_map.rs index a0dd7db5c0d..8909f85d4d9 100644 --- a/tools/parity_scale_decoder/src/generate_map.rs +++ b/tools/parity_scale_decoder/src/generate_map.rs @@ -5,7 +5,7 @@ use std::collections::BTreeSet; use iroha_core::*; use iroha_crypto::*; use iroha_data_model::{prelude::*, query::SignedQueryRequest, *}; -use iroha_data_primitives::atomic::*; +use iroha_primitives::{atomic::*, fixed}; use iroha_schema::IntoSchema; use iroha_version::*; @@ -355,7 +355,7 @@ pub fn generate_map() -> DumpDecodedMap { 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::numerical::SemiInterval, iroha_data_model::predicate::string::Predicate,