Skip to content

Commit

Permalink
chore: reorganize data_model crates
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Oct 31, 2024
1 parent 007d2e3 commit 3a0b20c
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 84 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down Expand Up @@ -199,7 +198,9 @@ clippy.wildcard_dependencies = "deny"
[workspace]
resolver = "2"
members = [
"crates/*"
"crates/*",
"data_model/libs/*",
"data_model/samples/*"
]

[profile.deploy]
Expand Down
7 changes: 5 additions & 2 deletions crates/iroha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha/tests/triggers/by_call_trigger.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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()
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 14 additions & 0 deletions data_model/samples/mint_rose_trigger_data_model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Arguments to mint rose with args trigger
#![no_std]

use iroha_data_model::prelude::Json;
use serde::{Deserialize, Serialize};
Expand Down
7 changes: 4 additions & 3 deletions wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 7 additions & 4 deletions wasm/samples/create_nft_for_every_user_trigger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@ 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;

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(),
"genesis".parse().dbg_unwrap(),
"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()) {
Expand Down
1 change: 1 addition & 0 deletions wasm/samples/mint_rose_trigger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions wasm/samples/mint_rose_trigger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<MintRoseArgs>()
.map(|args| args.val)
.and_then(|_| {
host.query_single(FindTriggerMetadata::new(context.id, "VAL".parse().unwrap()))
.dbg_unwrap()
.try_into_any::<u32>()
})
.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");
Expand Down
22 changes: 0 additions & 22 deletions wasm/samples/mint_rose_trigger_args/Cargo.toml

This file was deleted.

37 changes: 0 additions & 37 deletions wasm/samples/mint_rose_trigger_args/src/lib.rs

This file was deleted.

0 comments on commit 3a0b20c

Please sign in to comment.