From 4bc8833c81e1ed76bb6900b28f382c41d8ccd06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Ver=C5=A1i=C4=87?= Date: Wed, 27 Mar 2024 16:32:50 +0300 Subject: [PATCH] [feature] #4390: include trigger id in trigger entrypoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marin Veršić --- .../src/lib.rs | 13 ++-- .../mint_rose_trigger/src/lib.rs | 2 +- .../integration/triggers/time_trigger.rs | 23 +++++-- config/src/parameters/actual.rs | 6 +- config/src/parameters/user.rs | 7 +- config/src/parameters/user/boilerplate.rs | 16 +++-- core/src/smartcontracts/isi/account.rs | 6 +- core/src/smartcontracts/isi/mod.rs | 2 + core/src/smartcontracts/isi/triggers/mod.rs | 66 +++++++++++++++++++ .../isi/triggers/specialized.rs | 8 +++ core/src/smartcontracts/wasm.rs | 5 +- core/src/state.rs | 7 +- data_model/src/events/data/events.rs | 7 ++ data_model/src/isi.rs | 35 +++++++++- data_model/src/lib.rs | 5 +- data_model/src/smart_contract.rs | 2 + data_model/src/visit.rs | 6 ++ .../trigger/derive/src/entrypoint.rs | 2 +- tools/kagami/src/genesis.rs | 5 +- 19 files changed, 188 insertions(+), 35 deletions(-) diff --git a/client/tests/integration/smartcontracts/create_nft_for_every_user_trigger/src/lib.rs b/client/tests/integration/smartcontracts/create_nft_for_every_user_trigger/src/lib.rs index 2a725479740..87f6fd4bf7f 100644 --- a/client/tests/integration/smartcontracts/create_nft_for_every_user_trigger/src/lib.rs +++ b/client/tests/integration/smartcontracts/create_nft_for_every_user_trigger/src/lib.rs @@ -16,7 +16,7 @@ static ALLOC: LockedAllocator = LockedAllocator::new(FreeList getrandom::register_custom_getrandom!(iroha_trigger::stub_getrandom); #[iroha_trigger::main] -fn main(_owner: AccountId, _event: Event) { +fn main(id: TriggerId, _owner: AccountId, _event: Event) { iroha_trigger::log::info!("Executing trigger"); let accounts_cursor = FindAllAccounts.execute().dbg_unwrap(); @@ -45,7 +45,7 @@ fn main(_owner: AccountId, _event: Event) { .dbg_unwrap(); metadata.insert_with_limits(name, true, limits).dbg_unwrap(); - let nft_id = generate_new_nft_id(account.id()); + let nft_id = generate_new_nft_id(id, account.id()); let nft_definition = AssetDefinition::store(nft_id.clone()) .mintable_once() .with_metadata(metadata); @@ -61,7 +61,7 @@ fn main(_owner: AccountId, _event: Event) { iroha_trigger::log::info!("Smart contract executed successfully"); } -fn generate_new_nft_id(account_id: &AccountId) -> AssetDefinitionId { +fn generate_new_nft_id(trigger_id: TriggerId, account_id: &AccountId) -> AssetDefinitionId { let assets = FindAssetsByAccountId::new(account_id.clone()) .execute() .dbg_unwrap(); @@ -73,11 +73,14 @@ fn generate_new_nft_id(account_id: &AccountId) -> AssetDefinitionId { .count() .checked_add(1) .dbg_unwrap(); + iroha_trigger::log::debug!(&format!("New number: {}", new_number)); + let prefix = FindTriggerKeyValueByIdAndKey::new(trigger_id, "PREFIX".parse().unwrap()) + .execute() + .dbg_unwrap(); format!( - "nft_number_{}_for_{}#{}", - new_number, + "{prefix}_{new_number}_for_{}#{}", account_id.name(), account_id.domain_id() ) diff --git a/client/tests/integration/smartcontracts/mint_rose_trigger/src/lib.rs b/client/tests/integration/smartcontracts/mint_rose_trigger/src/lib.rs index e3558de7c61..c44302fc9e3 100644 --- a/client/tests/integration/smartcontracts/mint_rose_trigger/src/lib.rs +++ b/client/tests/integration/smartcontracts/mint_rose_trigger/src/lib.rs @@ -17,7 +17,7 @@ getrandom::register_custom_getrandom!(iroha_trigger::stub_getrandom); /// Mint 1 rose for owner #[iroha_trigger::main] -fn main(owner: AccountId, _event: Event) { +fn main(_id: TriggerId, owner: AccountId, _event: Event) { let rose_definition_id = AssetDefinitionId::from_str("rose#wonderland") .dbg_expect("Failed to parse `rose#wonderland` asset definition id"); let rose_id = AssetId::new(rose_definition_id, owner); diff --git a/client/tests/integration/triggers/time_trigger.rs b/client/tests/integration/triggers/time_trigger.rs index 1f29a0d8ba9..f371d9c66e0 100644 --- a/client/tests/integration/triggers/time_trigger.rs +++ b/client/tests/integration/triggers/time_trigger.rs @@ -46,8 +46,9 @@ fn time_trigger_execution_count_error_should_be_less_than_15_percent() -> Result let schedule = TimeSchedule::starting_at(start_time).with_period(PERIOD); let instruction = Mint::asset_numeric(1u32, asset_id.clone()); + let trigger_id: TriggerId = "mint_rose".parse()?; let register_trigger = Register::trigger(Trigger::new( - "mint_rose".parse()?, + trigger_id.clone(), Action::new( vec![instruction], Repeats::Indefinitely, @@ -58,6 +59,7 @@ fn time_trigger_execution_count_error_should_be_less_than_15_percent() -> Result test_client.submit(register_trigger)?; submit_sample_isi_on_every_block_commit( + trigger_id, event_listener, &mut test_client, &account_id, @@ -104,8 +106,9 @@ fn change_asset_metadata_after_1_sec() -> Result<()> { let schedule = TimeSchedule::starting_at(start_time + PERIOD); let instruction = SetKeyValue::asset_definition(asset_definition_id.clone(), key.clone(), 3_u32); + let trigger_id: TriggerId = "change_rose_metadata".parse().expect("Valid"); let register_trigger = Register::trigger(Trigger::new( - "change_rose_metadata".parse().expect("Valid"), + trigger_id.clone(), Action::new( vec![instruction], Repeats::from(1_u32), @@ -115,6 +118,7 @@ fn change_asset_metadata_after_1_sec() -> Result<()> { )); test_client.submit(register_trigger)?; submit_sample_isi_on_every_block_commit( + trigger_id, event_listener, &mut test_client, &account_id, @@ -223,8 +227,9 @@ fn mint_nft_for_every_user_every_1_sec() -> Result<()> { let start_time = current_time(); let schedule = TimeSchedule::starting_at(start_time).with_period(Duration::from_millis(TRIGGER_PERIOD_MS)); + let trigger_id: TriggerId = "mint_nft_for_all".parse()?; let register_trigger = Register::trigger(Trigger::new( - "mint_nft_for_all".parse()?, + trigger_id.clone(), Action::new( WasmSmartContract::from_compiled(wasm), Repeats::Indefinitely, @@ -232,10 +237,11 @@ fn mint_nft_for_every_user_every_1_sec() -> Result<()> { TimeEventFilter::new(ExecutionTime::Schedule(schedule)), ), )); - test_client.submit(register_trigger)?; + test_client.submit_blocking(register_trigger)?; // Time trigger will be executed on block commits, so we have to produce some transactions submit_sample_isi_on_every_block_commit( + trigger_id, event_listener, &mut test_client, &alice_id, @@ -292,12 +298,15 @@ fn get_asset_value(client: &mut Client, asset_id: AssetId) -> Numeric { /// Submit some sample ISIs to create new blocks fn submit_sample_isi_on_every_block_commit( + trigger_id: TriggerId, block_committed_event_listener: impl Iterator>, test_client: &mut Client, account_id: &AccountId, timeout: Duration, times: usize, ) -> Result<()> { + let prefix = SetKeyValue::trigger(trigger_id, "PREFIX".parse()?, "nft_number".to_owned()); + for _ in block_committed_event_listener.take(times) { std::thread::sleep(timeout); // ISI just to create a new block @@ -306,7 +315,11 @@ fn submit_sample_isi_on_every_block_commit( "key".parse::()?, String::from("value"), ); - test_client.submit(sample_isi)?; + + test_client.submit_all(vec![ + InstructionBox::from(prefix.clone()), + sample_isi.into(), + ])?; } Ok(()) diff --git a/config/src/parameters/actual.rs b/config/src/parameters/actual.rs index df23be982f7..6b10b3d870b 100644 --- a/config/src/parameters/actual.rs +++ b/config/src/parameters/actual.rs @@ -177,10 +177,11 @@ pub struct ChainWide { pub block_time: Duration, pub commit_time: Duration, pub transaction_limits: TransactionLimits, - pub asset_metadata_limits: MetadataLimits, + pub domain_metadata_limits: MetadataLimits, pub asset_definition_metadata_limits: MetadataLimits, pub account_metadata_limits: MetadataLimits, - pub domain_metadata_limits: MetadataLimits, + pub asset_metadata_limits: MetadataLimits, + pub trigger_metadata_limits: MetadataLimits, pub ident_length_limits: LengthLimits, pub executor_runtime: WasmRuntime, pub wasm_runtime: WasmRuntime, @@ -204,6 +205,7 @@ impl Default for ChainWide { account_metadata_limits: defaults::chain_wide::DEFAULT_METADATA_LIMITS, asset_definition_metadata_limits: defaults::chain_wide::DEFAULT_METADATA_LIMITS, asset_metadata_limits: defaults::chain_wide::DEFAULT_METADATA_LIMITS, + trigger_metadata_limits: defaults::chain_wide::DEFAULT_METADATA_LIMITS, ident_length_limits: defaults::chain_wide::DEFAULT_IDENT_LENGTH_LIMITS, executor_runtime: WasmRuntime::default(), wasm_runtime: WasmRuntime::default(), diff --git a/config/src/parameters/user.rs b/config/src/parameters/user.rs index 1a0d7a5ced1..5afae534472 100644 --- a/config/src/parameters/user.rs +++ b/config/src/parameters/user.rs @@ -566,10 +566,11 @@ pub struct ChainWide { pub block_time: Duration, pub commit_time: Duration, pub transaction_limits: TransactionLimits, - pub asset_metadata_limits: MetadataLimits, + pub domain_metadata_limits: MetadataLimits, pub asset_definition_metadata_limits: MetadataLimits, pub account_metadata_limits: MetadataLimits, - pub domain_metadata_limits: MetadataLimits, + pub asset_metadata_limits: MetadataLimits, + pub trigger_metadata_limits: MetadataLimits, pub ident_length_limits: LengthLimits, pub executor_fuel_limit: u64, pub executor_max_memory: HumanBytes, @@ -585,6 +586,7 @@ impl ChainWide { commit_time, transaction_limits, asset_metadata_limits, + trigger_metadata_limits, asset_definition_metadata_limits, account_metadata_limits, domain_metadata_limits, @@ -601,6 +603,7 @@ impl ChainWide { commit_time, transaction_limits, asset_metadata_limits, + trigger_metadata_limits, asset_definition_metadata_limits, account_metadata_limits, domain_metadata_limits, diff --git a/config/src/parameters/user/boilerplate.rs b/config/src/parameters/user/boilerplate.rs index 2e9b8695474..b2863772d71 100644 --- a/config/src/parameters/user/boilerplate.rs +++ b/config/src/parameters/user/boilerplate.rs @@ -656,10 +656,11 @@ pub struct ChainWidePartial { pub block_time: UserField, pub commit_time: UserField, pub transaction_limits: UserField, - pub asset_metadata_limits: UserField, + pub domain_metadata_limits: UserField, pub asset_definition_metadata_limits: UserField, pub account_metadata_limits: UserField, - pub domain_metadata_limits: UserField, + pub asset_metadata_limits: UserField, + pub trigger_metadata_limits: UserField, pub ident_length_limits: UserField, pub executor_fuel_limit: UserField, pub executor_max_memory: UserField>, @@ -682,8 +683,8 @@ impl UnwrapPartial for ChainWidePartial { transaction_limits: self .transaction_limits .unwrap_or(DEFAULT_TRANSACTION_LIMITS), - asset_metadata_limits: self - .asset_metadata_limits + domain_metadata_limits: self + .domain_metadata_limits .unwrap_or(DEFAULT_METADATA_LIMITS), asset_definition_metadata_limits: self .asset_definition_metadata_limits @@ -691,8 +692,11 @@ impl UnwrapPartial for ChainWidePartial { account_metadata_limits: self .account_metadata_limits .unwrap_or(DEFAULT_METADATA_LIMITS), - domain_metadata_limits: self - .domain_metadata_limits + asset_metadata_limits: self + .asset_metadata_limits + .unwrap_or(DEFAULT_METADATA_LIMITS), + trigger_metadata_limits: self + .trigger_metadata_limits .unwrap_or(DEFAULT_METADATA_LIMITS), ident_length_limits: self .ident_length_limits diff --git a/core/src/smartcontracts/isi/account.rs b/core/src/smartcontracts/isi/account.rs index aa814e37f7a..fd238417169 100644 --- a/core/src/smartcontracts/isi/account.rs +++ b/core/src/smartcontracts/isi/account.rs @@ -285,8 +285,8 @@ pub mod isi { state_transaction .world .emit_events(Some(AccountEvent::MetadataInserted(MetadataChanged { - target_id: account_id.clone(), - key: self.key.clone(), + target_id: account_id, + key: self.key, value: self.value, }))); @@ -316,7 +316,7 @@ pub mod isi { state_transaction .world .emit_events(Some(AccountEvent::MetadataRemoved(MetadataChanged { - target_id: account_id.clone(), + target_id: account_id, key: self.key, value, }))); diff --git a/core/src/smartcontracts/isi/mod.rs b/core/src/smartcontracts/isi/mod.rs index 7d04c07c6ba..2c8dde57a15 100644 --- a/core/src/smartcontracts/isi/mod.rs +++ b/core/src/smartcontracts/isi/mod.rs @@ -181,6 +181,7 @@ impl Execute for SetKeyValueBox { Self::Account(isi) => isi.execute(authority, state_transaction), Self::AssetDefinition(isi) => isi.execute(authority, state_transaction), Self::Asset(isi) => isi.execute(authority, state_transaction), + Self::Trigger(isi) => isi.execute(authority, state_transaction), } } } @@ -196,6 +197,7 @@ impl Execute for RemoveKeyValueBox { Self::Account(isi) => isi.execute(authority, state_transaction), Self::AssetDefinition(isi) => isi.execute(authority, state_transaction), Self::Asset(isi) => isi.execute(authority, state_transaction), + Self::Trigger(isi) => isi.execute(authority, state_transaction), } } } diff --git a/core/src/smartcontracts/isi/triggers/mod.rs b/core/src/smartcontracts/isi/triggers/mod.rs index 611f87e01db..00ea4338215 100644 --- a/core/src/smartcontracts/isi/triggers/mod.rs +++ b/core/src/smartcontracts/isi/triggers/mod.rs @@ -177,6 +177,72 @@ pub mod isi { } } + impl Execute for SetKeyValue { + #[metrics(+"set_trigger_key_value")] + fn execute( + self, + _authority: &AccountId, + state_transaction: &mut StateTransaction<'_, '_>, + ) -> Result<(), Error> { + let trigger_id = self.object_id; + + let trigger_metadata_limits = state_transaction.config.account_metadata_limits; + state_transaction + .world + .triggers + .inspect_by_id_mut(&trigger_id, |action| { + action.metadata_mut().insert_with_limits( + self.key.clone(), + self.value.clone(), + trigger_metadata_limits, + ) + }) + .ok_or(FindError::Trigger(trigger_id.clone()))??; + + state_transaction + .world + .emit_events(Some(TriggerEvent::MetadataInserted(MetadataChanged { + target_id: trigger_id, + key: self.key, + value: self.value, + }))); + + Ok(()) + } + } + + impl Execute for RemoveKeyValue { + #[metrics(+"remove_trigger_key_value")] + fn execute( + self, + _authority: &AccountId, + state_transaction: &mut StateTransaction<'_, '_>, + ) -> Result<(), Error> { + let trigger_id = self.object_id; + + let value = state_transaction + .world + .triggers + .inspect_by_id_mut(&trigger_id, |action| { + action + .metadata_mut() + .remove(&self.key) + .ok_or_else(|| FindError::MetadataKey(self.key.clone())) + }) + .ok_or(FindError::Trigger(trigger_id.clone()))??; + + state_transaction + .world + .emit_events(Some(TriggerEvent::MetadataRemoved(MetadataChanged { + target_id: trigger_id, + key: self.key, + value, + }))); + + Ok(()) + } + } + impl Execute for ExecuteTrigger { #[metrics(+"execute_trigger")] fn execute( diff --git a/core/src/smartcontracts/isi/triggers/specialized.rs b/core/src/smartcontracts/isi/triggers/specialized.rs index 09e898b126d..cb0957f114c 100644 --- a/core/src/smartcontracts/isi/triggers/specialized.rs +++ b/core/src/smartcontracts/isi/triggers/specialized.rs @@ -152,6 +152,9 @@ pub trait LoadedActionTrait { /// Get action metadata fn metadata(&self) -> &Metadata; + /// Get action metadata + fn metadata_mut(&mut self) -> &mut Metadata; + /// Check if action is mintable. fn mintable(&self) -> bool; @@ -181,10 +184,15 @@ impl + Clone> LoadedActionTrait &self.authority } + /// Get action metadata fn metadata(&self) -> &Metadata { &self.metadata } + fn metadata_mut(&mut self) -> &mut Metadata { + &mut self.metadata + } + fn mintable(&self) -> bool { self.filter.mintable() } diff --git a/core/src/smartcontracts/wasm.rs b/core/src/smartcontracts/wasm.rs index dd8df4bd163..034ea428db6 100644 --- a/core/src/smartcontracts/wasm.rs +++ b/core/src/smartcontracts/wasm.rs @@ -464,6 +464,8 @@ pub mod state { /// Trigger execution state #[derive(Constructor)] pub struct Trigger { + pub(in super::super) id: TriggerId, + /// Event which activated this trigger pub(in super::super) triggering_event: Event, } @@ -985,7 +987,7 @@ impl<'wrld, 'block: 'wrld, 'state: 'block> Runtime Runtime payloads::Trigger { payloads::Trigger { + id: state.specific_state.id.clone(), owner: state.authority.clone(), event: state.specific_state.triggering_event.clone(), } diff --git a/core/src/state.rs b/core/src/state.rs index b9291530cbf..9b85eb84fa2 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -285,7 +285,7 @@ impl World { } } - /// Create struct to apply block's changes while reverting changes made in the latest block + /// Create struct to apply block's changes while reverting changes made in the latest block pub fn block_and_revert(&self) -> WorldBlock { WorldBlock { parameters: self.parameters.block_and_revert(), @@ -1333,10 +1333,11 @@ impl<'state> StateBlock<'state> { } update_params! { - WSV_ASSET_METADATA_LIMITS => self.config.asset_metadata_limits, + WSV_DOMAIN_METADATA_LIMITS => self.config.domain_metadata_limits, WSV_ASSET_DEFINITION_METADATA_LIMITS => self.config.asset_definition_metadata_limits, WSV_ACCOUNT_METADATA_LIMITS => self.config.account_metadata_limits, - WSV_DOMAIN_METADATA_LIMITS => self.config.domain_metadata_limits, + WSV_ASSET_METADATA_LIMITS => self.config.asset_metadata_limits, + WSV_TRIGGER_METADATA_LIMITS => self.config.trigger_metadata_limits, WSV_IDENT_LENGTH_LIMITS => self.config.ident_length_limits, EXECUTOR_FUEL_LIMIT => self.config.executor_runtime.fuel_limit, EXECUTOR_MAX_MEMORY => self.config.executor_runtime.max_memory_bytes, diff --git a/data_model/src/events/data/events.rs b/data_model/src/events/data/events.rs index 156be776be1..3c6fc21b909 100644 --- a/data_model/src/events/data/events.rs +++ b/data_model/src/events/data/events.rs @@ -486,6 +486,9 @@ mod trigger { pub use self::model::*; use super::*; + // type alias required by `Filter` macro + type TriggerMetadataChanged = MetadataChanged; + data_event! { #[has_origin(origin = Trigger)] pub enum TriggerEvent { @@ -495,6 +498,10 @@ mod trigger { Extended(TriggerNumberOfExecutionsChanged), #[has_origin(number_of_executions_changed => &number_of_executions_changed.trigger_id)] Shortened(TriggerNumberOfExecutionsChanged), + #[has_origin(metadata_changed => &metadata_changed.target_id)] + MetadataInserted(TriggerMetadataChanged), + #[has_origin(metadata_changed => &metadata_changed.target_id)] + MetadataRemoved(TriggerMetadataChanged), } } diff --git a/data_model/src/isi.rs b/data_model/src/isi.rs index 1ecd901aba7..fbeec030761 100644 --- a/data_model/src/isi.rs +++ b/data_model/src/isi.rs @@ -339,6 +339,21 @@ mod transparent { } } + impl SetKeyValue { + /// Constructs a new [`SetKeyValue`] for a [`Trigger`] with the given `key` and `value`. + pub fn trigger( + trigger_id: TriggerId, + key: Name, + value: impl Into, + ) -> Self { + Self { + object_id: trigger_id, + key, + value: value.into(), + } + } + } + impl_display! { SetKeyValue where @@ -353,7 +368,8 @@ mod transparent { SetKeyValue | SetKeyValue | SetKeyValue | - SetKeyValue + SetKeyValue | + SetKeyValue => SetKeyValueBox => InstructionBox[SetKeyValue], => SetKeyValueBoxRef<'a> => InstructionBoxRef<'a>[SetKeyValue] } @@ -410,6 +426,16 @@ mod transparent { } } + impl RemoveKeyValue { + /// Constructs a new [`RemoveKeyValue`] for an [`Asset`] with the given `key`. + pub fn trigger(trigger_id: TriggerId, key: Name) -> Self { + Self { + object_id: trigger_id, + key, + } + } + } + impl_display! { RemoveKeyValue where @@ -424,7 +450,8 @@ mod transparent { RemoveKeyValue | RemoveKeyValue | RemoveKeyValue | - RemoveKeyValue + RemoveKeyValue | + RemoveKeyValue => RemoveKeyValueBox => InstructionBox[RemoveKeyValue], => RemoveKeyValueBoxRef<'a> => InstructionBoxRef<'a>[RemoveKeyValue] } @@ -1059,6 +1086,8 @@ isi_box! { AssetDefinition(SetKeyValue), /// Set key value for [`Asset`]. Asset(SetKeyValue), + /// Set key value for [`Trigger`]. + Trigger(SetKeyValue), } } @@ -1078,6 +1107,8 @@ isi_box! { AssetDefinition(RemoveKeyValue), /// Remove key value from [`Asset`]. Asset(RemoveKeyValue), + /// Remove key value for [`Trigger`]. + Trigger(RemoveKeyValue), } } diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index 87352bead15..e52f53b57a5 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -231,10 +231,11 @@ pub mod parameter { pub const BLOCK_TIME: &str = "BlockTime"; pub const COMMIT_TIME_LIMIT: &str = "CommitTimeLimit"; pub const TRANSACTION_LIMITS: &str = "TransactionLimits"; - pub const WSV_ASSET_METADATA_LIMITS: &str = "WSVAssetMetadataLimits"; + pub const WSV_DOMAIN_METADATA_LIMITS: &str = "WSVDomainMetadataLimits"; pub const WSV_ASSET_DEFINITION_METADATA_LIMITS: &str = "WSVAssetDefinitionMetadataLimits"; pub const WSV_ACCOUNT_METADATA_LIMITS: &str = "WSVAccountMetadataLimits"; - pub const WSV_DOMAIN_METADATA_LIMITS: &str = "WSVDomainMetadataLimits"; + pub const WSV_ASSET_METADATA_LIMITS: &str = "WSVAssetMetadataLimits"; + pub const WSV_TRIGGER_METADATA_LIMITS: &str = "WSVTriggerMetadataLimits"; pub const WSV_IDENT_LENGTH_LIMITS: &str = "WSVIdentLengthLimits"; pub const EXECUTOR_FUEL_LIMIT: &str = "ExecutorFuelLimit"; pub const EXECUTOR_MAX_MEMORY: &str = "ExecutorMaxMemory"; diff --git a/data_model/src/smart_contract.rs b/data_model/src/smart_contract.rs index 379da0585d9..928eee6f827 100644 --- a/data_model/src/smart_contract.rs +++ b/data_model/src/smart_contract.rs @@ -17,6 +17,8 @@ pub mod payloads { /// Payload for trigger entrypoint #[derive(Debug, Clone, Encode, Decode)] pub struct Trigger { + /// Id of this trigger + pub id: TriggerId, /// Trigger owner who registered the trigger pub owner: AccountId, /// Event which triggered the execution diff --git a/data_model/src/visit.rs b/data_model/src/visit.rs index b626e8bcde7..f25fc3dc9e0 100644 --- a/data_model/src/visit.rs +++ b/data_model/src/visit.rs @@ -128,12 +128,14 @@ pub trait Visit { visit_set_account_key_value(&SetKeyValue), visit_set_asset_definition_key_value(&SetKeyValue), visit_set_asset_key_value(&SetKeyValue), + visit_set_trigger_key_value(&SetKeyValue), // Visit RemoveKeyValueBox visit_remove_domain_key_value(&RemoveKeyValue), visit_remove_account_key_value(&RemoveKeyValue), visit_remove_asset_definition_key_value(&RemoveKeyValue), visit_remove_asset_key_value(&RemoveKeyValue), + visit_remove_trigger_key_value(&RemoveKeyValue), // Visit GrantBox visit_grant_account_permission(&Grant), @@ -350,6 +352,7 @@ pub fn visit_set_key_value( visitor.visit_set_asset_definition_key_value(authority, obj) } SetKeyValueBox::Asset(obj) => visitor.visit_set_asset_key_value(authority, obj), + SetKeyValueBox::Trigger(obj) => visitor.visit_set_trigger_key_value(authority, obj), } } @@ -365,6 +368,7 @@ pub fn visit_remove_key_value( visitor.visit_remove_asset_definition_key_value(authority, obj) } RemoveKeyValueBox::Asset(obj) => visitor.visit_remove_asset_key_value(authority, obj), + RemoveKeyValueBox::Trigger(obj) => visitor.visit_remove_trigger_key_value(authority, obj), } } @@ -409,6 +413,8 @@ leaf_visitors! { visit_transfer_asset_store(&Transfer), visit_set_asset_key_value(&SetKeyValue), visit_remove_asset_key_value(&RemoveKeyValue), + visit_set_trigger_key_value(&SetKeyValue), + visit_remove_trigger_key_value(&RemoveKeyValue), visit_register_asset_definition(&Register), visit_unregister_asset_definition(&Unregister), visit_transfer_asset_definition(&Transfer), diff --git a/smart_contract/trigger/derive/src/entrypoint.rs b/smart_contract/trigger/derive/src/entrypoint.rs index a054363cdfe..fba9a75df6b 100644 --- a/smart_contract/trigger/derive/src/entrypoint.rs +++ b/smart_contract/trigger/derive/src/entrypoint.rs @@ -47,7 +47,7 @@ pub fn impl_entrypoint(emitter: &mut Emitter, item: syn::ItemFn) -> TokenStream #[doc(hidden)] unsafe extern "C" fn #main_fn_name() { let payload = ::iroha_trigger::get_trigger_payload(); - #fn_name(payload.owner, payload.event) + #fn_name(payload.trigger_id, payload.owner, payload.event) } // NOTE: Host objects are always passed by value to wasm diff --git a/tools/kagami/src/genesis.rs b/tools/kagami/src/genesis.rs index 94c851f0e91..73a1367e998 100644 --- a/tools/kagami/src/genesis.rs +++ b/tools/kagami/src/genesis.rs @@ -143,13 +143,14 @@ pub fn generate_default( Numeric::new(DEFAULT_COMMIT_TIME.as_millis(), 0), )? .add_parameter(TRANSACTION_LIMITS, DEFAULT_TRANSACTION_LIMITS)? - .add_parameter(WSV_ASSET_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)? + .add_parameter(WSV_DOMAIN_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)? .add_parameter( WSV_ASSET_DEFINITION_METADATA_LIMITS, DEFAULT_METADATA_LIMITS, )? .add_parameter(WSV_ACCOUNT_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)? - .add_parameter(WSV_DOMAIN_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)? + .add_parameter(WSV_ASSET_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)? + .add_parameter(WSV_TRIGGER_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)? .add_parameter(WSV_IDENT_LENGTH_LIMITS, DEFAULT_IDENT_LENGTH_LIMITS)? .add_parameter( EXECUTOR_FUEL_LIMIT,