From 69aea73efd12c4bd4e10451d7232256ccfda217a Mon Sep 17 00:00:00 2001 From: benhhack Date: Wed, 4 Oct 2023 10:30:57 +0100 Subject: [PATCH] IsAssetDefinitonOwner removed Signed-off-by: benhhack --- core/src/smartcontracts/isi/asset.rs | 19 +------- core/src/smartcontracts/isi/query.rs | 1 - data_model/src/lib.rs | 1 - data_model/src/query/mod.rs | 30 +----------- data_model/src/visit.rs | 3 -- docs/source/references/schema.json | 63 +++++++++---------------- schema/gen/src/lib.rs | 1 - smart_contract/validator/src/default.rs | 8 ++++ 8 files changed, 34 insertions(+), 92 deletions(-) diff --git a/core/src/smartcontracts/isi/asset.rs b/core/src/smartcontracts/isi/asset.rs index d3709c6ab59..05f6ffc114b 100644 --- a/core/src/smartcontracts/isi/asset.rs +++ b/core/src/smartcontracts/isi/asset.rs @@ -420,9 +420,10 @@ pub mod isi { /// Asset-related query implementations. pub mod query { use eyre::{Result, WrapErr as _}; + use iroha_data_model::{ asset::{Asset, AssetDefinition}, - query::{asset::IsAssetDefinitionOwner, error::QueryExecutionFail as Error, MetadataValue}, + query::{asset::FindAssetDefinitionById, error::QueryExecutionFail as Error, MetadataValue}, }; use super::*; @@ -699,20 +700,4 @@ pub mod query { } } - impl ValidQuery for IsAssetDefinitionOwner { - #[metrics("is_asset_definition_owner")] - fn execute(&self, wsv: &WorldStateView) -> Result { - let asset_definition_id = wsv - .evaluate(&self.asset_definition_id) - .wrap_err("Failed to get asset definition id") - .map_err(|e| Error::Evaluate(e.to_string()))?; - let account_id = wsv - .evaluate(&self.account_id) - .wrap_err("Failed to get account id") - .map_err(|e| Error::Evaluate(e.to_string()))?; - - let entry = wsv.asset_definition(&asset_definition_id)?; - Ok(entry.owned_by == account_id) - } - } } diff --git a/core/src/smartcontracts/isi/query.rs b/core/src/smartcontracts/isi/query.rs index 988474ef6d7..a1f6c513515 100644 --- a/core/src/smartcontracts/isi/query.rs +++ b/core/src/smartcontracts/isi/query.rs @@ -127,7 +127,6 @@ impl ValidQuery for QueryBox { FindAssetDefinitionById, FindAssetQuantityById, FindTotalAssetQuantityByAssetDefinitionId, - IsAssetDefinitionOwner, FindDomainById, FindBlockHeaderByHash, FindTransactionByHash, diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index 88713128a6a..d8d6a7b1dfe 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -137,7 +137,6 @@ mod seal { FindAssetsByDomainIdAndAssetDefinitionId, FindAssetQuantityById, FindTotalAssetQuantityByAssetDefinitionId, - IsAssetDefinitionOwner, FindAssetKeyValueByIdAndKey, FindAssetDefinitionKeyValueByIdAndKey, FindAllDomains, diff --git a/data_model/src/query/mod.rs b/data_model/src/query/mod.rs index fb0d78ad468..95cbbcb66ad 100644 --- a/data_model/src/query/mod.rs +++ b/data_model/src/query/mod.rs @@ -110,7 +110,6 @@ pub mod model { FindAssetsByDomainIdAndAssetDefinitionId(FindAssetsByDomainIdAndAssetDefinitionId), FindAssetQuantityById(FindAssetQuantityById), FindTotalAssetQuantityByAssetDefinitionId(FindTotalAssetQuantityByAssetDefinitionId), - IsAssetDefinitionOwner(IsAssetDefinitionOwner), FindAssetKeyValueByIdAndKey(FindAssetKeyValueByIdAndKey), FindAssetDefinitionKeyValueByIdAndKey(FindAssetDefinitionKeyValueByIdAndKey), FindAllDomains(FindAllDomains), @@ -672,16 +671,6 @@ pub mod asset { pub key: EvaluatesTo, } - /// [`IsAssetDefinitionOwner`] Iroha Query checks if provided account is the asset definition owner. - #[derive(Display)] - #[display(fmt = "Check if `{account_id}` is creator of `{asset_definition_id}` asset")] - #[ffi_type] - pub struct IsAssetDefinitionOwner { - /// `Id` of an [`AssetDefinition`] to check. - pub asset_definition_id: EvaluatesTo, - /// `Id` of a possible owner [`Account`]. - pub account_id: EvaluatesTo, - } } impl Query for FindAllAssets { type Output = Vec; @@ -735,10 +724,6 @@ pub mod asset { type Output = MetadataValue; } - impl Query for IsAssetDefinitionOwner { - type Output = bool; - } - impl FindAssetById { /// Construct [`FindAssetById`]. pub fn new(id: impl Into>) -> Self { @@ -837,19 +822,6 @@ pub mod asset { } } - impl IsAssetDefinitionOwner { - /// Construct [`IsAssetDefinitionOwner`]. - pub fn new( - asset_definition_id: impl Into>, - account_id: impl Into>, - ) -> Self { - Self { - asset_definition_id: asset_definition_id.into(), - account_id: account_id.into(), - } - } - } - /// The prelude re-exports most commonly used traits, structs and macros from this crate. pub mod prelude { pub use super::{ @@ -857,7 +829,7 @@ pub mod asset { FindAssetDefinitionKeyValueByIdAndKey, FindAssetKeyValueByIdAndKey, FindAssetQuantityById, FindAssetsByAccountId, FindAssetsByAssetDefinitionId, FindAssetsByDomainId, FindAssetsByDomainIdAndAssetDefinitionId, FindAssetsByName, - FindTotalAssetQuantityByAssetDefinitionId, IsAssetDefinitionOwner, + FindTotalAssetQuantityByAssetDefinitionId, }; } } diff --git a/data_model/src/visit.rs b/data_model/src/visit.rs index 0853d8188a3..bbcd47ba70e 100644 --- a/data_model/src/visit.rs +++ b/data_model/src/visit.rs @@ -106,7 +106,6 @@ pub trait Visit: ExpressionEvaluator { visit_find_trigger_by_id(&FindTriggerById), visit_find_trigger_key_value_by_id_and_key(&FindTriggerKeyValueByIdAndKey), visit_find_triggers_by_domain_id(&FindTriggersByDomainId), - visit_is_asset_definition_owner(&IsAssetDefinitionOwner), // Visit RegisterExpr visit_register_peer(Register), @@ -242,7 +241,6 @@ pub fn visit_query(visitor: &mut V, authority: &AccountId, qu visit_find_trigger_by_id(FindTriggerById), visit_find_trigger_key_value_by_id_and_key(FindTriggerKeyValueByIdAndKey), visit_find_triggers_by_domain_id(FindTriggersByDomainId), - visit_is_asset_definition_owner(IsAssetDefinitionOwner), } } @@ -782,5 +780,4 @@ leaf_visitors! { visit_find_trigger_by_id(&FindTriggerById), visit_find_trigger_key_value_by_id_and_key(&FindTriggerKeyValueByIdAndKey), visit_find_triggers_by_domain_id(&FindTriggersByDomainId), - visit_is_asset_definition_owner(&IsAssetDefinitionOwner), } diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 4e875a7cfef..94ba2b4686d 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -2643,18 +2643,6 @@ "Ipv4Predicate": "Array, 4>", "Ipv6Addr": "Array", "Ipv6Predicate": "Array, 8>", - "IsAssetDefinitionOwner": { - "Struct": [ - { - "name": "asset_definition_id", - "type": "EvaluatesTo" - }, - { - "name": "account_id", - "type": "EvaluatesTo" - } - ] - }, "LengthLimits": { "Struct": [ { @@ -3507,124 +3495,119 @@ "discriminant": 16, "type": "FindTotalAssetQuantityByAssetDefinitionId" }, - { - "tag": "IsAssetDefinitionOwner", - "discriminant": 17, - "type": "IsAssetDefinitionOwner" - }, { "tag": "FindAssetKeyValueByIdAndKey", - "discriminant": 18, + "discriminant": 17, "type": "FindAssetKeyValueByIdAndKey" }, { "tag": "FindAssetDefinitionKeyValueByIdAndKey", - "discriminant": 19, + "discriminant": 18, "type": "FindAssetDefinitionKeyValueByIdAndKey" }, { "tag": "FindAllDomains", - "discriminant": 20, + "discriminant": 19, "type": "FindAllDomains" }, { "tag": "FindDomainById", - "discriminant": 21, + "discriminant": 20, "type": "FindDomainById" }, { "tag": "FindDomainKeyValueByIdAndKey", - "discriminant": 22, + "discriminant": 21, "type": "FindDomainKeyValueByIdAndKey" }, { "tag": "FindAllPeers", - "discriminant": 23, + "discriminant": 22, "type": "FindAllPeers" }, { "tag": "FindAllBlocks", - "discriminant": 24, + "discriminant": 23, "type": "FindAllBlocks" }, { "tag": "FindAllBlockHeaders", - "discriminant": 25, + "discriminant": 24, "type": "FindAllBlockHeaders" }, { "tag": "FindBlockHeaderByHash", - "discriminant": 26, + "discriminant": 25, "type": "FindBlockHeaderByHash" }, { "tag": "FindAllTransactions", - "discriminant": 27, + "discriminant": 26, "type": "FindAllTransactions" }, { "tag": "FindTransactionsByAccountId", - "discriminant": 28, + "discriminant": 27, "type": "FindTransactionsByAccountId" }, { "tag": "FindTransactionByHash", - "discriminant": 29, + "discriminant": 28, "type": "FindTransactionByHash" }, { "tag": "FindPermissionTokensByAccountId", - "discriminant": 30, + "discriminant": 29, "type": "FindPermissionTokensByAccountId" }, { "tag": "FindPermissionTokenSchema", - "discriminant": 31, + "discriminant": 30, "type": "FindPermissionTokenSchema" }, { "tag": "FindAllActiveTriggerIds", - "discriminant": 32, + "discriminant": 31, "type": "FindAllActiveTriggerIds" }, { "tag": "FindTriggerById", - "discriminant": 33, + "discriminant": 32, "type": "FindTriggerById" }, { "tag": "FindTriggerKeyValueByIdAndKey", - "discriminant": 34, + "discriminant": 33, "type": "FindTriggerKeyValueByIdAndKey" }, { "tag": "FindTriggersByDomainId", - "discriminant": 35, + "discriminant": 34, "type": "FindTriggersByDomainId" }, { "tag": "FindAllRoles", - "discriminant": 36, + "discriminant": 35, "type": "FindAllRoles" }, { "tag": "FindAllRoleIds", - "discriminant": 37, + "discriminant": 36, "type": "FindAllRoleIds" }, { "tag": "FindRoleByRoleId", - "discriminant": 38, + "discriminant": 37, "type": "FindRoleByRoleId" }, { "tag": "FindRolesByAccountId", - "discriminant": 39, + "discriminant": 38, "type": "FindRolesByAccountId" }, { "tag": "FindAllParameters", - "discriminant": 40, + "discriminant": 39, "type": "FindAllParameters" } ] diff --git a/schema/gen/src/lib.rs b/schema/gen/src/lib.rs index c6f384f62a9..88f2ce3c292 100644 --- a/schema/gen/src/lib.rs +++ b/schema/gen/src/lib.rs @@ -240,7 +240,6 @@ types!( Ipv4Predicate, Ipv6Addr, Ipv6Predicate, - IsAssetDefinitionOwner, LengthLimits, Less, MerkleTree, diff --git a/smart_contract/validator/src/default.rs b/smart_contract/validator/src/default.rs index 167ece90e14..f1b046e65ac 100644 --- a/smart_contract/validator/src/default.rs +++ b/smart_contract/validator/src/default.rs @@ -735,6 +735,14 @@ pub mod asset_definition { } } + pub(super) fn is_asset_definition_owner( + asset_definition_id: &AssetDefinitionId, + authority: &AccountId, + ) -> Result { + let asset_definition = FindAssetDefinitionById::new(asset_definition_id.clone()).execute()?; + Ok(asset_definition.owned_by() == authority) + } + pub fn visit_unregister_asset_definition( validator: &mut V, authority: &AccountId,