From c6dad5609afd55fcd6a76ac82d4d3cdfa3477805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Ver=C5=A1i=C4=87?= Date: Wed, 13 Dec 2023 15:26:47 +0300 Subject: [PATCH] [refactor]: Export iroha_crypto through iroha_client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marin Veršić --- Cargo.lock | 1 - client/benches/torii.rs | 3 +-- client/benches/tps/utils.rs | 3 ++- client/examples/tutorial.rs | 2 +- client/src/client.rs | 18 +++++++++--------- client/src/lib.rs | 4 +++- client/tests/integration/asset.rs | 3 +-- client/tests/integration/asset_propagation.rs | 3 +-- client/tests/integration/burn_public_keys.rs | 2 +- client/tests/integration/domain_owner.rs | 6 ++++-- client/tests/integration/events/pipeline.rs | 12 +++++++----- .../integration/multiple_blocks_created.rs | 3 +-- .../integration/multisignature_account.rs | 2 +- .../integration/multisignature_transaction.rs | 2 +- client/tests/integration/permissions.rs | 9 +++++---- client/tests/integration/queries/asset.rs | 4 ++-- client/tests/integration/roles.rs | 3 ++- client/tests/integration/transfer_asset.rs | 5 ++--- client/tests/integration/unregister_peer.rs | 2 +- client/tests/integration/upgrade.rs | 2 +- client_cli/Cargo.toml | 1 - smart_contract/executor/derive/src/validate.rs | 6 +++++- 22 files changed, 51 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff9e1f49ce9..66eeddd28c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2720,7 +2720,6 @@ dependencies = [ "erased-serde", "iroha_client", "iroha_config", - "iroha_crypto", "iroha_primitives", "json5", "once_cell", diff --git a/client/benches/torii.rs b/client/benches/torii.rs index 95b6be46304..4ca452b930f 100644 --- a/client/benches/torii.rs +++ b/client/benches/torii.rs @@ -6,10 +6,9 @@ use criterion::{criterion_group, criterion_main, Criterion, Throughput}; use iroha::samples::{construct_executor, get_config}; use iroha_client::{ client::{asset, Client}, + crypto::KeyPair, data_model::prelude::*, }; -use iroha_crypto::KeyPair; -use iroha_data_model::isi::InstructionBox; use iroha_genesis::{GenesisNetwork, RawGenesisBlockBuilder}; use iroha_primitives::unique_vec; use iroha_version::Encode; diff --git a/client/benches/tps/utils.rs b/client/benches/tps/utils.rs index 5c37499ce51..045a95527fe 100644 --- a/client/benches/tps/utils.rs +++ b/client/benches/tps/utils.rs @@ -163,7 +163,8 @@ impl MeasurerUnit { /// Submit initial transactions for measurement fn ready(self) -> Result { - let keypair = iroha_crypto::KeyPair::generate().expect("Failed to generate KeyPair."); + let keypair = + iroha_client::crypto::KeyPair::generate().expect("Failed to generate KeyPair."); let account_id = account_id(self.name); let asset_id = asset_id(self.name); diff --git a/client/examples/tutorial.rs b/client/examples/tutorial.rs index 5cc86cd8495..b22b0d1be52 100644 --- a/client/examples/tutorial.rs +++ b/client/examples/tutorial.rs @@ -114,12 +114,12 @@ fn account_registration_test(config: &Configuration) -> Result<(), Error> { // #region register_account_crates use iroha_client::{ client::Client, + crypto::KeyPair, data_model::{ metadata::UnlimitedMetadata, prelude::{Account, AccountId, InstructionBox, Register}, }, }; - use iroha_crypto::KeyPair; // #endregion register_account_crates // Create an Iroha client diff --git a/client/src/client.rs b/client/src/client.rs index e057a8c7c58..a33b9f6a8d4 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -14,7 +14,6 @@ use eyre::{eyre, Result, WrapErr}; use futures_util::StreamExt; use http_default::{AsyncWebSocketStream, WebSocketStream}; use iroha_config::{client::Configuration, client_api::ConfigurationDTO, torii::uri}; -use iroha_crypto::{HashOf, KeyPair}; use iroha_logger::prelude::*; use iroha_telemetry::metrics::Status; use iroha_version::prelude::*; @@ -24,6 +23,7 @@ use url::Url; use self::{blocks_api::AsyncBlockStream, events_api::AsyncEventStream}; use crate::{ + crypto::{HashOf, KeyPair}, data_model::{ block::SignedBlock, isi::Instruction, @@ -69,15 +69,15 @@ pub trait Sign { /// Fails if signature creation fails fn sign( self, - key_pair: iroha_crypto::KeyPair, - ) -> Result; + key_pair: crate::crypto::KeyPair, + ) -> Result; } impl Sign for TransactionBuilder { fn sign( self, - key_pair: iroha_crypto::KeyPair, - ) -> Result { + key_pair: crate::crypto::KeyPair, + ) -> Result { self.sign(key_pair) } } @@ -85,8 +85,8 @@ impl Sign for TransactionBuilder { impl Sign for SignedTransaction { fn sign( self, - key_pair: iroha_crypto::KeyPair, - ) -> Result { + key_pair: crate::crypto::KeyPair, + ) -> Result { self.sign(key_pair) } } @@ -1699,8 +1699,8 @@ mod tests { .parse() .expect("Public key not in mulithash format"), ), - private_key: Some(iroha_crypto::PrivateKey::from_hex( - iroha_crypto::Algorithm::Ed25519, + private_key: Some(crate::crypto::PrivateKey::from_hex( + crate::crypto::Algorithm::Ed25519, "9AC47ABF59B356E0BD7DCBBBB4DEC080E302156A48CA907E47CB6AEA1D32719E7233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0" ).expect("Private key not hex encoded")), account_id: Some( diff --git a/client/src/lib.rs b/client/src/lib.rs index 3d12fef5365..c33fd84f409 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -13,7 +13,8 @@ pub mod samples { client::{Configuration, ConfigurationProxy}, torii::uri::DEFAULT_API_ADDR, }; - use iroha_crypto::KeyPair; + + use crate::crypto::KeyPair; /// Get sample client configuration. pub fn get_client_config(key_pair: &KeyPair) -> Configuration { @@ -38,4 +39,5 @@ pub mod samples { } } +pub use iroha_crypto as crypto; pub use iroha_data_model as data_model; diff --git a/client/tests/integration/asset.rs b/client/tests/integration/asset.rs index 2cd3cab768f..5744827d134 100644 --- a/client/tests/integration/asset.rs +++ b/client/tests/integration/asset.rs @@ -3,10 +3,9 @@ use std::{str::FromStr as _, thread}; use eyre::Result; use iroha_client::{ client::{self, QueryResult}, + crypto::{KeyPair, PublicKey}, data_model::prelude::*, }; -use iroha_crypto::{KeyPair, PublicKey}; -use iroha_data_model::isi::InstructionBox; use iroha_primitives::fixed::Fixed; use serde_json::json; use test_network::*; diff --git a/client/tests/integration/asset_propagation.rs b/client/tests/integration/asset_propagation.rs index de7a5238418..4e35ef266a1 100644 --- a/client/tests/integration/asset_propagation.rs +++ b/client/tests/integration/asset_propagation.rs @@ -3,13 +3,12 @@ use std::{str::FromStr as _, thread}; use eyre::Result; use iroha_client::{ client::{self, QueryResult}, + crypto::KeyPair, data_model::{ parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, prelude::*, }, }; -use iroha_crypto::KeyPair; -use iroha_data_model::isi::InstructionBox; use test_network::*; use super::Configuration; diff --git a/client/tests/integration/burn_public_keys.rs b/client/tests/integration/burn_public_keys.rs index fb4c54b2251..f207894995d 100644 --- a/client/tests/integration/burn_public_keys.rs +++ b/client/tests/integration/burn_public_keys.rs @@ -1,8 +1,8 @@ use iroha_client::{ client::{account, transaction, Client}, + crypto::{HashOf, KeyPair, PublicKey}, data_model::{isi::Instruction, prelude::*, transaction::TransactionPayload}, }; -use iroha_crypto::{HashOf, KeyPair, PublicKey}; use test_network::*; fn submit( diff --git a/client/tests/integration/domain_owner.rs b/client/tests/integration/domain_owner.rs index b420d5e81c2..eeeb881b324 100644 --- a/client/tests/integration/domain_owner.rs +++ b/client/tests/integration/domain_owner.rs @@ -1,6 +1,8 @@ use eyre::Result; -use iroha_client::data_model::{account::SignatureCheckCondition, prelude::*}; -use iroha_crypto::KeyPair; +use iroha_client::{ + crypto::KeyPair, + data_model::{account::SignatureCheckCondition, prelude::*}, +}; use serde_json::json; use test_network::*; diff --git a/client/tests/integration/events/pipeline.rs b/client/tests/integration/events/pipeline.rs index 966a922f6e0..35b8e16629a 100644 --- a/client/tests/integration/events/pipeline.rs +++ b/client/tests/integration/events/pipeline.rs @@ -1,11 +1,13 @@ use std::thread::{self, JoinHandle}; use eyre::Result; -use iroha_client::data_model::{ - parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, - prelude::*, +use iroha_client::{ + crypto::HashOf, + data_model::{ + parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, + prelude::*, + }, }; -use iroha_crypto::HashOf; use test_network::*; use super::Configuration; @@ -75,7 +77,7 @@ fn test_with_instruction_and_status_and_port( #[derive(Clone)] struct Checker { listener: iroha_client::client::Client, - hash: iroha_crypto::HashOf, + hash: HashOf, } impl Checker { diff --git a/client/tests/integration/multiple_blocks_created.rs b/client/tests/integration/multiple_blocks_created.rs index aa3f3a551ba..f0d28bb4a26 100644 --- a/client/tests/integration/multiple_blocks_created.rs +++ b/client/tests/integration/multiple_blocks_created.rs @@ -3,13 +3,12 @@ use std::thread; use eyre::Result; use iroha_client::{ client::{self, Client, QueryResult}, + crypto::KeyPair, data_model::{ parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, prelude::*, }, }; -use iroha_crypto::KeyPair; -use iroha_data_model::isi::InstructionBox; use test_network::*; use super::Configuration; diff --git a/client/tests/integration/multisignature_account.rs b/client/tests/integration/multisignature_account.rs index 9f35fb9bbfa..515920dad3c 100644 --- a/client/tests/integration/multisignature_account.rs +++ b/client/tests/integration/multisignature_account.rs @@ -3,9 +3,9 @@ use std::thread; use eyre::Result; use iroha_client::{ client::{self, Client, QueryResult}, + crypto::KeyPair, data_model::prelude::*, }; -use iroha_crypto::KeyPair; use test_network::*; use super::Configuration; diff --git a/client/tests/integration/multisignature_transaction.rs b/client/tests/integration/multisignature_transaction.rs index 280a07751f3..c3bbaf7a1be 100644 --- a/client/tests/integration/multisignature_transaction.rs +++ b/client/tests/integration/multisignature_transaction.rs @@ -3,13 +3,13 @@ use std::{str::FromStr as _, thread, time::Duration}; use eyre::Result; use iroha_client::{ client::{self, Client, QueryResult}, + crypto::KeyPair, data_model::{ parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, prelude::*, }, }; use iroha_config::client::Configuration as ClientConfiguration; -use iroha_crypto::KeyPair; use test_network::*; use super::Configuration; diff --git a/client/tests/integration/permissions.rs b/client/tests/integration/permissions.rs index fb829ed2ce3..da443789009 100644 --- a/client/tests/integration/permissions.rs +++ b/client/tests/integration/permissions.rs @@ -3,6 +3,7 @@ use std::{str::FromStr as _, thread, time::Duration}; use eyre::Result; use iroha_client::{ client::{self, Client, QueryResult}, + crypto::KeyPair, data_model::prelude::*, }; use iroha_genesis::GenesisNetwork; @@ -80,7 +81,7 @@ fn permissions_disallow_asset_transfer() { let asset_definition_id: AssetDefinitionId = "xor#wonderland".parse().expect("Valid"); let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); - let mouse_keypair = iroha_crypto::KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); let alice_start_assets = get_assets(&iroha_client, &alice_id); iroha_client @@ -134,7 +135,7 @@ fn permissions_disallow_asset_burn() { let asset_definition_id = AssetDefinitionId::from_str("xor#wonderland").expect("Valid"); let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); - let mouse_keypair = iroha_crypto::KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); let alice_start_assets = get_assets(&iroha_client, &alice_id); @@ -204,7 +205,7 @@ fn permissions_differ_not_only_by_names() { let alice_id: AccountId = "alice@wonderland".parse().expect("Valid"); let mouse_id: AccountId = "mouse@wonderland".parse().expect("Valid"); - let mouse_keypair = iroha_crypto::KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); // Registering `Store` asset definitions let hat_definition_id: AssetDefinitionId = "hat#wonderland".parse().expect("Valid"); @@ -300,7 +301,7 @@ fn stored_vs_granted_token_payload() -> Result<()> { let create_asset = Register::asset_definition(AssetDefinition::store(asset_definition_id.clone())); let mouse_id: AccountId = "mouse@wonderland".parse().expect("Valid"); - let mouse_keypair = iroha_crypto::KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); let new_mouse_account = Account::new(mouse_id.clone(), [mouse_keypair.public_key().clone()]); let instructions: [InstructionBox; 2] = [ Register::account(new_mouse_account).into(), diff --git a/client/tests/integration/queries/asset.rs b/client/tests/integration/queries/asset.rs index bb34d302158..6046c8cbf88 100644 --- a/client/tests/integration/queries/asset.rs +++ b/client/tests/integration/queries/asset.rs @@ -1,14 +1,14 @@ use eyre::Result; use iroha_client::{ client::{Client, ClientQueryError}, + crypto::KeyPair, data_model::{ asset::AssetValue, + isi::Instruction, prelude::*, query::{asset::FindTotalAssetQuantityByAssetDefinitionId, error::QueryExecutionFail}, }, }; -use iroha_crypto::KeyPair; -use iroha_data_model::isi::Instruction; use iroha_primitives::fixed::Fixed; use test_network::*; diff --git a/client/tests/integration/roles.rs b/client/tests/integration/roles.rs index 8523cfb39b6..ef1884806a3 100644 --- a/client/tests/integration/roles.rs +++ b/client/tests/integration/roles.rs @@ -3,6 +3,7 @@ use std::str::FromStr as _; use eyre::Result; use iroha_client::{ client::{self, QueryResult}, + crypto::KeyPair, data_model::prelude::*, }; use serde_json::json; @@ -52,7 +53,7 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> { let mouse_id = AccountId::from_str("mouse@wonderland")?; // Registering Mouse - let mouse_key_pair = iroha_crypto::KeyPair::generate()?; + let mouse_key_pair = KeyPair::generate()?; let register_mouse = Register::account(Account::new( mouse_id.clone(), [mouse_key_pair.public_key().clone()], diff --git a/client/tests/integration/transfer_asset.rs b/client/tests/integration/transfer_asset.rs index cbc23b190fa..be37310c5cd 100644 --- a/client/tests/integration/transfer_asset.rs +++ b/client/tests/integration/transfer_asset.rs @@ -1,9 +1,8 @@ use iroha_client::{ client::{self, QueryResult}, - data_model::{prelude::*, Registered}, + crypto::KeyPair, + data_model::{isi::Instruction, prelude::*, Registered}, }; -use iroha_crypto::KeyPair; -use iroha_data_model::isi::Instruction; use iroha_primitives::fixed::Fixed; use test_network::*; diff --git a/client/tests/integration/unregister_peer.rs b/client/tests/integration/unregister_peer.rs index 84a2e4fa5b3..e8246a38514 100644 --- a/client/tests/integration/unregister_peer.rs +++ b/client/tests/integration/unregister_peer.rs @@ -3,12 +3,12 @@ use std::thread; use eyre::Result; use iroha_client::{ client::{self, QueryResult}, + crypto::KeyPair, data_model::{ parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder}, prelude::*, }, }; -use iroha_crypto::KeyPair; use test_network::*; use super::Configuration; diff --git a/client/tests/integration/upgrade.rs b/client/tests/integration/upgrade.rs index cfa822046c2..3ec49a84600 100644 --- a/client/tests/integration/upgrade.rs +++ b/client/tests/integration/upgrade.rs @@ -3,9 +3,9 @@ use std::{path::Path, str::FromStr as _}; use eyre::Result; use iroha_client::{ client::{self, Client, QueryResult}, + crypto::KeyPair, data_model::prelude::*, }; -use iroha_crypto::KeyPair; use iroha_logger::info; use serde_json::json; use test_network::*; diff --git a/client_cli/Cargo.toml b/client_cli/Cargo.toml index 12d6ffa40c5..c5725467446 100644 --- a/client_cli/Cargo.toml +++ b/client_cli/Cargo.toml @@ -25,7 +25,6 @@ maintenance = { status = "actively-developed" } [dependencies] iroha_client = { workspace = true } iroha_primitives = { workspace = true } -iroha_crypto = { workspace = true } iroha_config = { workspace = true } color-eyre = { workspace = true } diff --git a/smart_contract/executor/derive/src/validate.rs b/smart_contract/executor/derive/src/validate.rs index 8a6a890b695..e552005dbf1 100644 --- a/smart_contract/executor/derive/src/validate.rs +++ b/smart_contract/executor/derive/src/validate.rs @@ -58,7 +58,11 @@ impl FromAttributes for ValidateAttribute { continue; } - let Some(list) = accumulator.handle(attr.meta.require_list().map_err(darling::Error::from)) else { continue; }; + let Some(list) = + accumulator.handle(attr.meta.require_list().map_err(darling::Error::from)) + else { + continue; + }; let tokens = &list.tokens; if path.is_ident("validate") {