From a6b0dce61de498e76490d918455f48d88f29b209 Mon Sep 17 00:00:00 2001 From: Shunkichi Sato <49983831+s8sato@users.noreply.github.com> Date: Sun, 3 Nov 2024 06:07:29 +0900 Subject: [PATCH] chore: remove `CanRegisterAnyTrigger` `CanUnregisterAnyTrigger` permissions Signed-off-by: Shunkichi Sato <49983831+s8sato@users.noreply.github.com> --- crates/iroha_executor/src/default.rs | 20 +++-------- crates/iroha_executor/src/permission.rs | 34 ++----------------- .../src/permission.rs | 10 ------ crates/iroha_genesis/src/lib.rs | 5 --- crates/iroha_schema_gen/src/lib.rs | 8 ----- defaults/genesis.json | 22 ------------ docs/source/references/schema.json | 2 -- 7 files changed, 7 insertions(+), 94 deletions(-) diff --git a/crates/iroha_executor/src/default.rs b/crates/iroha_executor/src/default.rs index 778ae28b12e..91aacb31d9e 100644 --- a/crates/iroha_executor/src/default.rs +++ b/crates/iroha_executor/src/default.rs @@ -368,9 +368,7 @@ pub mod domain { AnyPermission::CanRegisterTrigger(permission) => { permission.authority.domain() == domain_id } - AnyPermission::CanRegisterAnyTrigger(_) - | AnyPermission::CanUnregisterAnyTrigger(_) - | AnyPermission::CanUnregisterTrigger(_) + AnyPermission::CanUnregisterTrigger(_) | AnyPermission::CanExecuteTrigger(_) | AnyPermission::CanModifyTrigger(_) | AnyPermission::CanModifyTriggerMetadata(_) @@ -548,9 +546,7 @@ pub mod account { AnyPermission::CanBurnAsset(permission) => permission.asset.account() == account_id, AnyPermission::CanTransferAsset(permission) => permission.asset.account() == account_id, AnyPermission::CanRegisterTrigger(permission) => permission.authority == *account_id, - AnyPermission::CanRegisterAnyTrigger(_) - | AnyPermission::CanUnregisterAnyTrigger(_) - | AnyPermission::CanUnregisterTrigger(_) + AnyPermission::CanUnregisterTrigger(_) | AnyPermission::CanExecuteTrigger(_) | AnyPermission::CanModifyTrigger(_) | AnyPermission::CanModifyTriggerMetadata(_) @@ -816,8 +812,6 @@ pub mod asset_definition { AnyPermission::CanUnregisterAccount(_) | AnyPermission::CanRegisterAsset(_) | AnyPermission::CanModifyAccountMetadata(_) - | AnyPermission::CanRegisterAnyTrigger(_) - | AnyPermission::CanUnregisterAnyTrigger(_) | AnyPermission::CanRegisterTrigger(_) | AnyPermission::CanUnregisterTrigger(_) | AnyPermission::CanExecuteTrigger(_) @@ -1342,8 +1336,8 @@ pub mod role { pub mod trigger { use iroha_executor_data_model::permission::trigger::{ - CanExecuteTrigger, CanModifyTrigger, CanModifyTriggerMetadata, CanRegisterAnyTrigger, - CanRegisterTrigger, CanUnregisterAnyTrigger, CanUnregisterTrigger, + CanExecuteTrigger, CanModifyTrigger, CanModifyTriggerMetadata, CanRegisterTrigger, + CanUnregisterTrigger, }; use iroha_smart_contract::data_model::trigger::Trigger; @@ -1377,7 +1371,6 @@ pub mod trigger { can_register_user_trigger_token .is_owned_by(&executor.context().authority, executor.host()) } - || CanRegisterAnyTrigger.is_owned_by(&executor.context().authority, executor.host()) { execute!(executor, isi) } @@ -1402,7 +1395,6 @@ pub mod trigger { can_unregister_user_trigger_token .is_owned_by(&executor.context().authority, executor.host()) } - || CanUnregisterAnyTrigger.is_owned_by(&executor.context().authority, executor.host()) { let mut err = None; for (owner_id, permission) in accounts_permissions(executor.host()) { @@ -1584,9 +1576,7 @@ pub mod trigger { AnyPermission::CanModifyTriggerMetadata(permission) => { &permission.trigger == trigger_id } - AnyPermission::CanRegisterAnyTrigger(_) - | AnyPermission::CanUnregisterAnyTrigger(_) - | AnyPermission::CanRegisterTrigger(_) + AnyPermission::CanRegisterTrigger(_) | AnyPermission::CanManagePeers(_) | AnyPermission::CanRegisterDomain(_) | AnyPermission::CanUnregisterDomain(_) diff --git a/crates/iroha_executor/src/permission.rs b/crates/iroha_executor/src/permission.rs index ed65e8185a0..ebe7a873d0f 100644 --- a/crates/iroha_executor/src/permission.rs +++ b/crates/iroha_executor/src/permission.rs @@ -117,8 +117,6 @@ declare_permissions! { iroha_executor_data_model::permission::parameter::{CanSetParameters}, iroha_executor_data_model::permission::role::{CanManageRoles}, - iroha_executor_data_model::permission::trigger::{CanRegisterAnyTrigger}, - iroha_executor_data_model::permission::trigger::{CanUnregisterAnyTrigger}, iroha_executor_data_model::permission::trigger::{CanRegisterTrigger}, iroha_executor_data_model::permission::trigger::{CanUnregisterTrigger}, iroha_executor_data_model::permission::trigger::{CanModifyTrigger}, @@ -756,8 +754,8 @@ pub mod account { pub mod trigger { //! Module with pass conditions for trigger related tokens use iroha_executor_data_model::permission::trigger::{ - CanExecuteTrigger, CanModifyTrigger, CanModifyTriggerMetadata, CanRegisterAnyTrigger, - CanRegisterTrigger, CanUnregisterAnyTrigger, CanUnregisterTrigger, + CanExecuteTrigger, CanModifyTrigger, CanModifyTriggerMetadata, CanRegisterTrigger, + CanUnregisterTrigger, }; use super::*; @@ -821,34 +819,6 @@ pub mod trigger { } } - impl ValidateGrantRevoke for CanRegisterAnyTrigger { - fn validate_grant(&self, authority: &AccountId, context: &Context, host: &Iroha) -> Result { - OnlyGenesis::from(self).validate(authority, host, context) - } - fn validate_revoke( - &self, - authority: &AccountId, - context: &Context, - host: &Iroha, - ) -> Result { - OnlyGenesis::from(self).validate(authority, host, context) - } - } - - impl ValidateGrantRevoke for CanUnregisterAnyTrigger { - fn validate_grant(&self, authority: &AccountId, context: &Context, host: &Iroha) -> Result { - OnlyGenesis::from(self).validate(authority, host, context) - } - fn validate_revoke( - &self, - authority: &AccountId, - context: &Context, - host: &Iroha, - ) -> Result { - OnlyGenesis::from(self).validate(authority, host, context) - } - } - impl ValidateGrantRevoke for CanRegisterTrigger { fn validate_grant(&self, authority: &AccountId, context: &Context, host: &Iroha) -> Result { super::account::Owner::from(self).validate(authority, host, context) diff --git a/crates/iroha_executor_data_model/src/permission.rs b/crates/iroha_executor_data_model/src/permission.rs index dc950a197bb..27778496268 100644 --- a/crates/iroha_executor_data_model/src/permission.rs +++ b/crates/iroha_executor_data_model/src/permission.rs @@ -178,16 +178,6 @@ pub mod asset { pub mod trigger { use super::*; - permission! { - #[derive(Copy)] - pub struct CanRegisterAnyTrigger; - } - - permission! { - #[derive(Copy)] - pub struct CanUnregisterAnyTrigger; - } - permission! { pub struct CanRegisterTrigger { pub authority: AccountId, diff --git a/crates/iroha_genesis/src/lib.rs b/crates/iroha_genesis/src/lib.rs index 10bfd5301cb..a931693c0a6 100644 --- a/crates/iroha_genesis/src/lib.rs +++ b/crates/iroha_genesis/src/lib.rs @@ -12,9 +12,6 @@ use derive_more::Constructor; use eyre::{eyre, Result, WrapErr}; use iroha_crypto::KeyPair; use iroha_data_model::{block::SignedBlock, parameter::Parameter, prelude::*}; -use iroha_executor_data_model::permission::trigger::{ - CanRegisterAnyTrigger, CanUnregisterAnyTrigger, -}; use iroha_schema::IntoSchema; use parity_scale_codec::{Decode, Encode}; use serde::{Deserialize, Serialize}; @@ -254,8 +251,6 @@ impl GenesisBuilder { let instructions = vec![ Register::domain(Domain::new(SYSTEM_DOMAIN_ID.clone())).into(), Register::account(Account::new(SYSTEM_ACCOUNT_ID.clone())).into(), - Grant::account_permission(CanRegisterAnyTrigger, SYSTEM_ACCOUNT_ID.clone()).into(), - Grant::account_permission(CanUnregisterAnyTrigger, SYSTEM_ACCOUNT_ID.clone()).into(), ]; let wasm_triggers = vec![]; diff --git a/crates/iroha_schema_gen/src/lib.rs b/crates/iroha_schema_gen/src/lib.rs index 91a69e73a42..c99a1a1ccd0 100644 --- a/crates/iroha_schema_gen/src/lib.rs +++ b/crates/iroha_schema_gen/src/lib.rs @@ -85,8 +85,6 @@ pub fn build_schemas() -> MetaMap { permission::asset::CanModifyAssetMetadata, permission::parameter::CanSetParameters, permission::role::CanManageRoles, - permission::trigger::CanRegisterAnyTrigger, - permission::trigger::CanUnregisterAnyTrigger, permission::trigger::CanRegisterTrigger, permission::trigger::CanExecuteTrigger, permission::trigger::CanUnregisterTrigger, @@ -627,12 +625,6 @@ mod tests { insert_into_test_map!(iroha_executor_data_model::permission::asset::CanModifyAssetMetadata); insert_into_test_map!(iroha_executor_data_model::permission::parameter::CanSetParameters); insert_into_test_map!(iroha_executor_data_model::permission::role::CanManageRoles); - insert_into_test_map!( - iroha_executor_data_model::permission::trigger::CanRegisterAnyTrigger - ); - insert_into_test_map!( - iroha_executor_data_model::permission::trigger::CanUnregisterAnyTrigger - ); insert_into_test_map!(iroha_executor_data_model::permission::trigger::CanRegisterTrigger); insert_into_test_map!(iroha_executor_data_model::permission::trigger::CanExecuteTrigger); insert_into_test_map!(iroha_executor_data_model::permission::trigger::CanUnregisterTrigger); diff --git a/defaults/genesis.json b/defaults/genesis.json index fb90e53d4ae..4194ea0f4f8 100644 --- a/defaults/genesis.json +++ b/defaults/genesis.json @@ -41,28 +41,6 @@ } } }, - { - "Grant": { - "Permission": { - "object": { - "name": "CanRegisterAnyTrigger", - "payload": null - }, - "destination": "ed0120D8B64D62FD8E09B9F29FE04D9C63E312EFB1CB29F1BF6AF00EBC263007AE75F7@system" - } - } - }, - { - "Grant": { - "Permission": { - "object": { - "name": "CanUnregisterAnyTrigger", - "payload": null - }, - "destination": "ed0120D8B64D62FD8E09B9F29FE04D9C63E312EFB1CB29F1BF6AF00EBC263007AE75F7@system" - } - } - }, { "Register": { "Domain": { diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 2b9aaf7edf1..4420ce213d1 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -872,7 +872,6 @@ } ] }, - "CanRegisterAnyTrigger": null, "CanRegisterAsset": { "Struct": [ { @@ -930,7 +929,6 @@ } ] }, - "CanUnregisterAnyTrigger": null, "CanUnregisterAsset": { "Struct": [ {