From 3a0b20c2a50833fb608c20ee1ea3ace5644989fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Ver=C5=A1i=C4=87?= Date: Tue, 29 Oct 2024 08:07:35 +0100 Subject: [PATCH] chore: reorganize `data_model` crates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marin Veršić --- Cargo.lock | 10 +++++ Cargo.toml | 11 +++--- crates/iroha/Cargo.toml | 7 +++- .../iroha/tests/triggers/by_call_trigger.rs | 4 +- .../iroha_multisig_data_model/Cargo.toml | 0 .../iroha_multisig_data_model/src/lib.rs | 0 .../executor_custom_data_model/Cargo.toml | 0 .../src/complex_isi.rs | 0 .../executor_custom_data_model/src/lib.rs | 1 - .../src/parameters.rs | 0 .../src/permissions.rs | 0 .../src/simple_isi.rs | 0 .../mint_rose_trigger_data_model/Cargo.toml | 14 +++++++ .../mint_rose_trigger_data_model/src/lib.rs | 1 + wasm/Cargo.toml | 7 ++-- .../src/lib.rs | 11 ++++-- wasm/samples/mint_rose_trigger/Cargo.toml | 1 + wasm/samples/mint_rose_trigger/src/lib.rs | 30 +++++++++++---- .../samples/mint_rose_trigger_args/Cargo.toml | 22 ----------- .../samples/mint_rose_trigger_args/src/lib.rs | 37 ------------------- 20 files changed, 72 insertions(+), 84 deletions(-) rename {crates => data_model/libs}/iroha_multisig_data_model/Cargo.toml (100%) rename {crates => data_model/libs}/iroha_multisig_data_model/src/lib.rs (100%) rename {wasm => data_model}/samples/executor_custom_data_model/Cargo.toml (100%) rename {wasm => data_model}/samples/executor_custom_data_model/src/complex_isi.rs (100%) rename {wasm => data_model}/samples/executor_custom_data_model/src/lib.rs (88%) rename {wasm => data_model}/samples/executor_custom_data_model/src/parameters.rs (100%) rename {wasm => data_model}/samples/executor_custom_data_model/src/permissions.rs (100%) rename {wasm => data_model}/samples/executor_custom_data_model/src/simple_isi.rs (100%) create mode 100644 data_model/samples/mint_rose_trigger_data_model/Cargo.toml rename wasm/samples/executor_custom_data_model/src/mint_rose_args.rs => data_model/samples/mint_rose_trigger_data_model/src/lib.rs (98%) delete mode 100644 wasm/samples/mint_rose_trigger_args/Cargo.toml delete mode 100644 wasm/samples/mint_rose_trigger_args/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index bd767492c6..1eea68b0d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2931,6 +2931,7 @@ dependencies = [ "iroha_test_samples", "iroha_torii_const", "iroha_version", + "mint_rose_trigger_data_model", "nonzero_ext", "parity-scale-codec", "rand", @@ -4166,6 +4167,15 @@ dependencies = [ "adler2", ] +[[package]] +name = "mint_rose_trigger_data_model" +version = "2.0.0-rc.1.0" +dependencies = [ + "iroha_data_model", + "serde", + "serde_json", +] + [[package]] name = "mio" version = "0.8.11" diff --git a/Cargo.toml b/Cargo.toml index 8569c51c1e..2d994741bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ iroha_macro_utils = { version = "=2.0.0-rc.1.0", path = "crates/iroha_macro_util iroha_telemetry = { version = "=2.0.0-rc.1.0", path = "crates/iroha_telemetry" } iroha_p2p = { version = "=2.0.0-rc.1.0", path = "crates/iroha_p2p" } iroha_primitives = { version = "=2.0.0-rc.1.0", path = "crates/iroha_primitives", default-features = false } -iroha_data_model = { version = "=2.0.0-rc.1.0", path = "crates/iroha_data_model", default-features = false } iroha_config = { version = "=2.0.0-rc.1.0", path = "crates/iroha_config" } iroha_config_base = { version = "=2.0.0-rc.1.0", path = "crates/iroha_config_base" } iroha_schema_gen = { version = "=2.0.0-rc.1.0", path = "crates/iroha_schema_gen" } @@ -42,11 +41,11 @@ iroha_wasm_builder = { version = "=2.0.0-rc.1.0", path = "crates/iroha_wasm_buil iroha_smart_contract = { version = "=2.0.0-rc.1.0", path = "crates/iroha_smart_contract" } iroha_smart_contract_utils = { version = "=2.0.0-rc.1.0", path = "crates/iroha_smart_contract_utils" } - iroha_executor = { version = "=2.0.0-rc.1.0", path = "crates/iroha_executor" } -iroha_executor_data_model = { version = "=2.0.0-rc.1.0", path = "crates/iroha_executor_data_model" } -iroha_multisig_data_model = { version = "=2.0.0-rc.1.0", path = "crates/iroha_multisig_data_model" } +iroha_data_model = { version = "=2.0.0-rc.1.0", path = "crates/iroha_data_model", default-features = false } +iroha_multisig_data_model = { version = "=2.0.0-rc.1.0", path = "data_model/libs/iroha_multisig_data_model" } +iroha_executor_data_model = { version = "=2.0.0-rc.1.0", path = "crates/iroha_executor_data_model" } iroha_test_network = { version = "=2.0.0-rc.1.0", path = "crates/iroha_test_network" } iroha_test_samples = { version = "=2.0.0-rc.1.0", path = "crates/iroha_test_samples" } @@ -199,7 +198,9 @@ clippy.wildcard_dependencies = "deny" [workspace] resolver = "2" members = [ - "crates/*" + "crates/*", + "data_model/libs/*", + "data_model/samples/*" ] [profile.deploy] diff --git a/crates/iroha/Cargo.toml b/crates/iroha/Cargo.toml index 13ece91a78..20d8709c9b 100644 --- a/crates/iroha/Cargo.toml +++ b/crates/iroha/Cargo.toml @@ -51,12 +51,13 @@ tls-rustls-webpki-roots = [ iroha_config = { workspace = true } iroha_config_base = { workspace = true } iroha_crypto = { workspace = true } -iroha_data_model = { workspace = true, features = ["http"] } iroha_primitives = { workspace = true } iroha_logger = { workspace = true } iroha_telemetry = { workspace = true } iroha_torii_const = { workspace = true } iroha_version = { workspace = true } + +iroha_data_model = { workspace = true, features = ["http"] } iroha_multisig_data_model = { workspace = true } attohttpc = { version = "0.28.0", default-features = false } @@ -84,8 +85,10 @@ nonzero_ext = { workspace = true } iroha_genesis = { workspace = true } iroha_test_samples = { workspace = true } iroha_test_network = { workspace = true } + +mint_rose_trigger_data_model = { path = "../../data_model/samples/mint_rose_trigger_data_model" } +executor_custom_data_model = { path = "../../data_model/samples/executor_custom_data_model" } iroha_executor_data_model = { workspace = true } -executor_custom_data_model = { version = "=2.0.0-rc.1.0", path = "../../wasm/samples/executor_custom_data_model" } tokio = { workspace = true, features = ["rt-multi-thread"] } reqwest = { version = "0.12.7", features = ["json"] } diff --git a/crates/iroha/tests/triggers/by_call_trigger.rs b/crates/iroha/tests/triggers/by_call_trigger.rs index 81dd9adcfe..f16fa25c38 100644 --- a/crates/iroha/tests/triggers/by_call_trigger.rs +++ b/crates/iroha/tests/triggers/by_call_trigger.rs @@ -1,6 +1,5 @@ use std::{sync::mpsc, thread, time::Duration}; -use executor_custom_data_model::mint_rose_args::MintRoseArgs; use eyre::{eyre, Result, WrapErr}; use iroha::{ crypto::KeyPair, @@ -13,6 +12,7 @@ use iroha::{ use iroha_executor_data_model::permission::trigger::CanRegisterTrigger; use iroha_test_network::*; use iroha_test_samples::{load_sample_wasm, ALICE_ID}; +use mint_rose_trigger_data_model::MintRoseArgs; use crate::triggers::get_asset_value; @@ -621,7 +621,7 @@ fn call_execute_trigger_with_args() -> Result<()> { let trigger = Trigger::new( trigger_id.clone(), Action::new( - load_sample_wasm("mint_rose_trigger_args"), + load_sample_wasm("mint_rose_trigger"), Repeats::Indefinitely, account_id.clone(), ExecuteTriggerEventFilter::new() diff --git a/crates/iroha_multisig_data_model/Cargo.toml b/data_model/libs/iroha_multisig_data_model/Cargo.toml similarity index 100% rename from crates/iroha_multisig_data_model/Cargo.toml rename to data_model/libs/iroha_multisig_data_model/Cargo.toml diff --git a/crates/iroha_multisig_data_model/src/lib.rs b/data_model/libs/iroha_multisig_data_model/src/lib.rs similarity index 100% rename from crates/iroha_multisig_data_model/src/lib.rs rename to data_model/libs/iroha_multisig_data_model/src/lib.rs diff --git a/wasm/samples/executor_custom_data_model/Cargo.toml b/data_model/samples/executor_custom_data_model/Cargo.toml similarity index 100% rename from wasm/samples/executor_custom_data_model/Cargo.toml rename to data_model/samples/executor_custom_data_model/Cargo.toml diff --git a/wasm/samples/executor_custom_data_model/src/complex_isi.rs b/data_model/samples/executor_custom_data_model/src/complex_isi.rs similarity index 100% rename from wasm/samples/executor_custom_data_model/src/complex_isi.rs rename to data_model/samples/executor_custom_data_model/src/complex_isi.rs diff --git a/wasm/samples/executor_custom_data_model/src/lib.rs b/data_model/samples/executor_custom_data_model/src/lib.rs similarity index 88% rename from wasm/samples/executor_custom_data_model/src/lib.rs rename to data_model/samples/executor_custom_data_model/src/lib.rs index ea920f09c1..4db9f68bde 100644 --- a/wasm/samples/executor_custom_data_model/src/lib.rs +++ b/data_model/samples/executor_custom_data_model/src/lib.rs @@ -5,7 +5,6 @@ extern crate alloc; pub mod complex_isi; -pub mod mint_rose_args; pub mod parameters; pub mod permissions; pub mod simple_isi; diff --git a/wasm/samples/executor_custom_data_model/src/parameters.rs b/data_model/samples/executor_custom_data_model/src/parameters.rs similarity index 100% rename from wasm/samples/executor_custom_data_model/src/parameters.rs rename to data_model/samples/executor_custom_data_model/src/parameters.rs diff --git a/wasm/samples/executor_custom_data_model/src/permissions.rs b/data_model/samples/executor_custom_data_model/src/permissions.rs similarity index 100% rename from wasm/samples/executor_custom_data_model/src/permissions.rs rename to data_model/samples/executor_custom_data_model/src/permissions.rs diff --git a/wasm/samples/executor_custom_data_model/src/simple_isi.rs b/data_model/samples/executor_custom_data_model/src/simple_isi.rs similarity index 100% rename from wasm/samples/executor_custom_data_model/src/simple_isi.rs rename to data_model/samples/executor_custom_data_model/src/simple_isi.rs diff --git a/data_model/samples/mint_rose_trigger_data_model/Cargo.toml b/data_model/samples/mint_rose_trigger_data_model/Cargo.toml new file mode 100644 index 0000000000..3ac89bf6b2 --- /dev/null +++ b/data_model/samples/mint_rose_trigger_data_model/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "mint_rose_trigger_data_model" + +edition.workspace = true +version.workspace = true +authors.workspace = true + +license.workspace = true + +[dependencies] +iroha_data_model.workspace = true + +serde.workspace = true +serde_json.workspace = true diff --git a/wasm/samples/executor_custom_data_model/src/mint_rose_args.rs b/data_model/samples/mint_rose_trigger_data_model/src/lib.rs similarity index 98% rename from wasm/samples/executor_custom_data_model/src/mint_rose_args.rs rename to data_model/samples/mint_rose_trigger_data_model/src/lib.rs index d9a8da2724..67f08036d1 100644 --- a/wasm/samples/executor_custom_data_model/src/mint_rose_args.rs +++ b/data_model/samples/mint_rose_trigger_data_model/src/lib.rs @@ -1,4 +1,5 @@ //! Arguments to mint rose with args trigger +#![no_std] use iroha_data_model::prelude::Json; use serde::{Deserialize, Serialize}; diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 8a4be9978d..a6b1f37da0 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -24,15 +24,16 @@ opt-level = "z" # Optimize for size vs speed with "s"/"z"(removes vectorizat codegen-units = 1 # Further reduces binary size but increases compilation time [workspace.dependencies] -executor_custom_data_model = { path = "samples/executor_custom_data_model" } - iroha_smart_contract = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_smart_contract", features = ["debug"] } iroha_trigger = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_trigger", features = ["debug"] } iroha_executor = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_executor", features = ["debug"] } iroha_schema = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_schema" } + iroha_data_model = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_data_model", default-features = false } +iroha_multisig_data_model = { version = "=2.0.0-rc.1.0", path = "../data_model/libs/iroha_multisig_data_model" } iroha_executor_data_model = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_executor_data_model" } -iroha_multisig_data_model = { version = "=2.0.0-rc.1.0", path = "../crates/iroha_multisig_data_model" } +mint_rose_trigger_data_model = { path = "../data_model/samples/mint_rose_trigger_data_model" } +executor_custom_data_model = { path = "../data_model/samples/executor_custom_data_model" } parity-scale-codec = { version = "3.2.1", default-features = false } anyhow = { version = "1.0.71", default-features = false } diff --git a/wasm/samples/create_nft_for_every_user_trigger/src/lib.rs b/wasm/samples/create_nft_for_every_user_trigger/src/lib.rs index 355261b4c7..0d9113e0fd 100644 --- a/wasm/samples/create_nft_for_every_user_trigger/src/lib.rs +++ b/wasm/samples/create_nft_for_every_user_trigger/src/lib.rs @@ -8,7 +8,7 @@ extern crate panic_halt; use alloc::{format, string::ToString}; use dlmalloc::GlobalDlmalloc; -use iroha_trigger::prelude::*; +use iroha_trigger::{debug::dbg_panic, prelude::*}; #[global_allocator] static ALLOC: GlobalDlmalloc = GlobalDlmalloc; @@ -16,9 +16,12 @@ static ALLOC: GlobalDlmalloc = GlobalDlmalloc; getrandom::register_custom_getrandom!(iroha_trigger::stub_getrandom); #[iroha_trigger::main] -fn main(host: Iroha, _context: Context) { +fn main(host: Iroha, context: Context) { iroha_trigger::log::info!("Executing trigger"); - let accounts_cursor = host.query(FindAccounts).execute().dbg_unwrap(); + + if !matches!(context.event, EventBox::Time(_)) { + dbg_panic("Only work as a by call trigger"); + }; let bad_domain_ids: [DomainId; 3] = [ "system".parse().dbg_unwrap(), @@ -26,7 +29,7 @@ fn main(host: Iroha, _context: Context) { "garden_of_live_flowers".parse().dbg_unwrap(), ]; - for account in accounts_cursor { + for account in host.query(FindAccounts).execute().dbg_unwrap() { let account = account.dbg_unwrap(); if bad_domain_ids.contains(account.id().domain()) { diff --git a/wasm/samples/mint_rose_trigger/Cargo.toml b/wasm/samples/mint_rose_trigger/Cargo.toml index 2a8bc1163f..9a4fda69c6 100644 --- a/wasm/samples/mint_rose_trigger/Cargo.toml +++ b/wasm/samples/mint_rose_trigger/Cargo.toml @@ -11,6 +11,7 @@ license.workspace = true crate-type = ['cdylib'] [dependencies] +mint_rose_trigger_data_model = { version = "=2.0.0-rc.1.0", path = "../../../data_model/samples/mint_rose_trigger_data_model" } iroha_trigger.workspace = true panic-halt.workspace = true diff --git a/wasm/samples/mint_rose_trigger/src/lib.rs b/wasm/samples/mint_rose_trigger/src/lib.rs index 3aab88a3c7..22dd16c6df 100644 --- a/wasm/samples/mint_rose_trigger/src/lib.rs +++ b/wasm/samples/mint_rose_trigger/src/lib.rs @@ -6,7 +6,11 @@ extern crate panic_halt; use dlmalloc::GlobalDlmalloc; -use iroha_trigger::{debug::DebugExpectExt as _, prelude::*}; +use iroha_trigger::{ + debug::{dbg_panic, DebugExpectExt as _}, + prelude::*, +}; +use mint_rose_trigger_data_model::MintRoseArgs; #[global_allocator] static ALLOC: GlobalDlmalloc = GlobalDlmalloc; @@ -16,13 +20,23 @@ getrandom::register_custom_getrandom!(iroha_trigger::stub_getrandom); /// Mint 1 rose for owner #[iroha_trigger::main] fn main(host: Iroha, context: Context) { - let rose_id = AssetId::new("rose#wonderland".parse().unwrap(), context.authority); - - let val: u32 = host - .query_single(FindTriggerMetadata::new(context.id, "VAL".parse().unwrap())) - .dbg_unwrap() - .try_into_any() - .dbg_unwrap(); + let EventBox::ExecuteTrigger(event) = context.event else { + dbg_panic("Only work as a by call trigger"); + }; + + let val = event + .args() + .try_into_any::() + .map(|args| args.val) + .and_then(|_| { + host.query_single(FindTriggerMetadata::new(context.id, "VAL".parse().unwrap())) + .dbg_unwrap() + .try_into_any::() + }) + .dbg_expect("Failed get mint value"); + + let rose_definition_id = "rose#wonderland".parse().unwrap(); + let rose_id = AssetId::new(rose_definition_id, context.authority); host.submit(&Mint::asset_numeric(val, rose_id)) .dbg_expect("Failed to mint rose"); diff --git a/wasm/samples/mint_rose_trigger_args/Cargo.toml b/wasm/samples/mint_rose_trigger_args/Cargo.toml deleted file mode 100644 index 9fe349eac2..0000000000 --- a/wasm/samples/mint_rose_trigger_args/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "mint_rose_args" - -edition.workspace = true -version.workspace = true -authors.workspace = true - -license.workspace = true - -[lib] -crate-type = ['cdylib'] - -[dependencies] -iroha_trigger.workspace = true -executor_custom_data_model.workspace = true - -panic-halt.workspace = true -dlmalloc.workspace = true -getrandom.workspace = true - -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true, default-features = false } diff --git a/wasm/samples/mint_rose_trigger_args/src/lib.rs b/wasm/samples/mint_rose_trigger_args/src/lib.rs deleted file mode 100644 index 37e57b57ba..0000000000 --- a/wasm/samples/mint_rose_trigger_args/src/lib.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! trigger which mints rose for its owner based on input args. - -#![no_std] - -#[cfg(not(test))] -extern crate panic_halt; - -use dlmalloc::GlobalDlmalloc; -use executor_custom_data_model::mint_rose_args::MintRoseArgs; -use iroha_trigger::{ - debug::{dbg_panic, DebugExpectExt as _}, - prelude::*, -}; - -#[global_allocator] -static ALLOC: GlobalDlmalloc = GlobalDlmalloc; - -getrandom::register_custom_getrandom!(iroha_trigger::stub_getrandom); - -/// Mint 1 rose for owner -#[iroha_trigger::main] -fn main(host: Iroha, context: Context) { - let EventBox::ExecuteTrigger(event) = context.event else { - dbg_panic("Only work as by call trigger"); - }; - - let args: MintRoseArgs = event - .args() - .try_into_any() - .dbg_expect("Failed to parse args"); - - let rose_definition_id = "rose#wonderland".parse().unwrap(); - let rose_id = AssetId::new(rose_definition_id, context.authority); - - host.submit(&Mint::asset_numeric(args.val, rose_id)) - .dbg_expect("Failed to mint rose"); -}