Skip to content

Commit

Permalink
IsAssetDefinitonOwner removed
Browse files Browse the repository at this point in the history
Signed-off-by: benhhack <[email protected]>
  • Loading branch information
benhhack committed Oct 10, 2023
1 parent e73c753 commit 69aea73
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 92 deletions.
19 changes: 2 additions & 17 deletions core/src/smartcontracts/isi/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -699,20 +700,4 @@ pub mod query {
}
}

impl ValidQuery for IsAssetDefinitionOwner {
#[metrics("is_asset_definition_owner")]
fn execute(&self, wsv: &WorldStateView) -> Result<bool, Error> {
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)
}
}
}
1 change: 0 additions & 1 deletion core/src/smartcontracts/isi/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ impl ValidQuery for QueryBox {
FindAssetDefinitionById,
FindAssetQuantityById,
FindTotalAssetQuantityByAssetDefinitionId,
IsAssetDefinitionOwner,
FindDomainById,
FindBlockHeaderByHash,
FindTransactionByHash,
Expand Down
1 change: 0 additions & 1 deletion data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ mod seal {
FindAssetsByDomainIdAndAssetDefinitionId,
FindAssetQuantityById,
FindTotalAssetQuantityByAssetDefinitionId,
IsAssetDefinitionOwner,
FindAssetKeyValueByIdAndKey,
FindAssetDefinitionKeyValueByIdAndKey,
FindAllDomains,
Expand Down
30 changes: 1 addition & 29 deletions data_model/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ pub mod model {
FindAssetsByDomainIdAndAssetDefinitionId(FindAssetsByDomainIdAndAssetDefinitionId),
FindAssetQuantityById(FindAssetQuantityById),
FindTotalAssetQuantityByAssetDefinitionId(FindTotalAssetQuantityByAssetDefinitionId),
IsAssetDefinitionOwner(IsAssetDefinitionOwner),
FindAssetKeyValueByIdAndKey(FindAssetKeyValueByIdAndKey),
FindAssetDefinitionKeyValueByIdAndKey(FindAssetDefinitionKeyValueByIdAndKey),
FindAllDomains(FindAllDomains),
Expand Down Expand Up @@ -672,16 +671,6 @@ pub mod asset {
pub key: EvaluatesTo<Name>,
}

/// [`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<AssetDefinitionId>,
/// `Id` of a possible owner [`Account`].
pub account_id: EvaluatesTo<AccountId>,
}
}
impl Query for FindAllAssets {
type Output = Vec<Asset>;
Expand Down Expand Up @@ -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<EvaluatesTo<AssetId>>) -> Self {
Expand Down Expand Up @@ -837,27 +822,14 @@ pub mod asset {
}
}

impl IsAssetDefinitionOwner {
/// Construct [`IsAssetDefinitionOwner`].
pub fn new(
asset_definition_id: impl Into<EvaluatesTo<AssetDefinitionId>>,
account_id: impl Into<EvaluatesTo<AccountId>>,
) -> 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::{
FindAllAssets, FindAllAssetsDefinitions, FindAssetById, FindAssetDefinitionById,
FindAssetDefinitionKeyValueByIdAndKey, FindAssetKeyValueByIdAndKey,
FindAssetQuantityById, FindAssetsByAccountId, FindAssetsByAssetDefinitionId,
FindAssetsByDomainId, FindAssetsByDomainIdAndAssetDefinitionId, FindAssetsByName,
FindTotalAssetQuantityByAssetDefinitionId, IsAssetDefinitionOwner,
FindTotalAssetQuantityByAssetDefinitionId,
};
}
}
Expand Down
3 changes: 0 additions & 3 deletions data_model/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Peer>),
Expand Down Expand Up @@ -242,7 +241,6 @@ pub fn visit_query<V: Visit + ?Sized>(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),
}
}

Expand Down Expand Up @@ -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),
}
63 changes: 23 additions & 40 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2643,18 +2643,6 @@
"Ipv4Predicate": "Array<Interval<u8>, 4>",
"Ipv6Addr": "Array<u16, 8>",
"Ipv6Predicate": "Array<Interval<u16>, 8>",
"IsAssetDefinitionOwner": {
"Struct": [
{
"name": "asset_definition_id",
"type": "EvaluatesTo<AssetDefinitionId>"
},
{
"name": "account_id",
"type": "EvaluatesTo<AccountId>"
}
]
},
"LengthLimits": {
"Struct": [
{
Expand Down Expand Up @@ -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"
}
]
Expand Down
1 change: 0 additions & 1 deletion schema/gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ types!(
Ipv4Predicate,
Ipv6Addr,
Ipv6Predicate,
IsAssetDefinitionOwner,
LengthLimits,
Less,
MerkleTree<SignedTransaction>,
Expand Down
8 changes: 8 additions & 0 deletions smart_contract/validator/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ pub mod asset_definition {
}
}

pub(super) fn is_asset_definition_owner(
asset_definition_id: &AssetDefinitionId,
authority: &AccountId,
) -> Result<bool> {
let asset_definition = FindAssetDefinitionById::new(asset_definition_id.clone()).execute()?;
Ok(asset_definition.owned_by() == authority)
}

pub fn visit_unregister_asset_definition<V: Validate + ?Sized>(
validator: &mut V,
authority: &AccountId,
Expand Down

0 comments on commit 69aea73

Please sign in to comment.