Skip to content

Commit

Permalink
Removed IsAssetDefinitionOwner
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 dc28e66
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 125 deletions.
Binary file modified configs/peer/validator.wasm
Binary file not shown.
21 changes: 3 additions & 18 deletions core/src/smartcontracts/isi/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ 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 @@ -698,21 +700,4 @@ pub mod query {
.map(Into::into)
}
}

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
15 changes: 12 additions & 3 deletions data_model/derive/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@ enum EventVariant {
impl FromVariant for EventVariant {
fn from_variant(variant: &Variant) -> darling::Result<Self> {
let syn2::Fields::Unnamed(fields) = &variant.fields else {
return Err(darling::Error::custom("Expected an enum with unnamed fields").with_span(&variant.fields));
return Err(
darling::Error::custom("Expected an enum with unnamed fields")
.with_span(&variant.fields),
);
};
// note: actually, we have only one field in the event variants
// this is not enforced by this macro, but by `IntoSchema`
let Some(first_field_ty) = fields.unnamed.first().map(|v| &v.ty) else {
return Err(darling::Error::custom("Expected at least one field").with_span(&fields));
};
let syn2::Type::Path(path) = first_field_ty else {
return Err(darling::Error::custom("Only identifiers supported as event types").with_span(first_field_ty));
return Err(
darling::Error::custom("Only identifiers supported as event types")
.with_span(first_field_ty),
);
};
let Some(first_field_ty_name) = path.path.get_ident() else {
return Err(darling::Error::custom("Only identifiers supported as event types").with_span(first_field_ty));
return Err(
darling::Error::custom("Only identifiers supported as event types")
.with_span(first_field_ty),
);
};

// What clippy suggests is much less readable in this case
Expand Down
4 changes: 3 additions & 1 deletion data_model/derive/src/has_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl FromDeriveInput for HasOriginEnum {
let ident = input.ident.clone();
let generics = input.generics.clone();

let Some(variants) = darling::ast::Data::<HasOriginVariant, ()>::try_from(&input.data)?.take_enum() else {
let Some(variants) =
darling::ast::Data::<HasOriginVariant, ()>::try_from(&input.data)?.take_enum()
else {
return Err(darling::Error::custom("Expected enum"));
};

Expand Down
2 changes: 1 addition & 1 deletion data_model/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ pub fn has_origin_derive(input: TokenStream) -> TokenStream {
let mut emitter = Emitter::new();

let Some(input) = emitter.handle(syn2::parse2(input)) else {
return emitter.finish_token_stream()
return emitter.finish_token_stream();
};

let result = has_origin::impl_has_origin(&mut emitter, &input);
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),
}
14 changes: 13 additions & 1 deletion docs/source/references/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ The following is the default configuration used by Iroha.
"MAX_TRANSACTIONS_IN_BLOCK": 512,
"ACTOR_CHANNEL_CAPACITY": 100,
"GOSSIP_BATCH_SIZE": 500,
"GOSSIP_PERIOD_MS": 1000
"GOSSIP_PERIOD_MS": 1000,
"DEBUG_FORCE_SOFT_FORK": false
},
"TORII": {
"P2P_ADDR": null,
Expand Down Expand Up @@ -500,6 +501,7 @@ Has type `Option<sumeragi::ConfigurationProxy>`[^1]. Can be configured via envir
"ACTOR_CHANNEL_CAPACITY": 100,
"BLOCK_TIME_MS": 2000,
"COMMIT_TIME_LIMIT_MS": 4000,
"DEBUG_FORCE_SOFT_FORK": false,
"GOSSIP_BATCH_SIZE": 500,
"GOSSIP_PERIOD_MS": 1000,
"KEY_PAIR": null,
Expand Down Expand Up @@ -539,6 +541,16 @@ Has type `Option<u64>`[^1]. Can be configured via environment variable `SUMERAGI
4000
```

### `sumeragi.debug_force_soft_fork`

Only used in testing. Causes the genesis peer to withhold blocks when it

Has type `Option<bool>`[^1]. Can be configured via environment variable `SUMERAGI_DEBUG_FORCE_SOFT_FORK`

```json
false
```

### `sumeragi.gossip_batch_size`

max number of transactions in tx gossip batch message. While configuring this, pay attention to `p2p` max message size.
Expand Down
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
Loading

0 comments on commit dc28e66

Please sign in to comment.