Skip to content

Commit

Permalink
[refactor]: Derive Constructor for queries
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
  • Loading branch information
Arjentix committed Dec 10, 2023
1 parent 0fd17aa commit c5461d5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 232 deletions.
2 changes: 0 additions & 2 deletions client/tests/integration/transfer_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ fn simulate_insufficient_funds() {
)
}

// TODO add tests when the transfer uses the wrong AssetId.

fn simulate_transfer<T: Clone + Into<AssetValue>>(
starting_amount: T,
amount_to_transfer: &T,
Expand Down
231 changes: 2 additions & 229 deletions data_model/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ macro_rules! queries {
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(parity_scale_codec::Decode, parity_scale_codec::Encode)]
#[derive(serde::Deserialize, serde::Serialize)]
#[derive(derive_more::Constructor)]
#[derive(iroha_schema::IntoSchema)]
$($meta)*
$item )+
Expand Down Expand Up @@ -183,7 +184,7 @@ pub mod model {
pub struct TransactionQueryOutput {
/// The hash of the block to which `tx` belongs to
pub block_hash: HashOf<SignedBlock>,
/// Transaction. Boxed to not to have infinite size.
/// Transaction
pub transaction: Box<TransactionValue>,
}

Expand Down Expand Up @@ -358,22 +359,6 @@ pub mod role {
type Output = Role;
}

impl FindRoleByRoleId {
/// Construct [`FindRoleByRoleId`].
pub fn new(id: impl Into<RoleId>) -> Self {
Self { id: id.into() }
}
}

impl FindRolesByAccountId {
/// Construct [`FindRolesByAccountId`].
pub fn new(account_id: impl Into<AccountId>) -> Self {
Self {
id: account_id.into(),
}
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this module.
pub mod prelude {
pub use super::{FindAllRoleIds, FindAllRoles, FindRoleByRoleId, FindRolesByAccountId};
Expand Down Expand Up @@ -421,15 +406,6 @@ pub mod permission {
type Output = Vec<permission::PermissionToken>;
}

impl FindPermissionTokensByAccountId {
/// Construct [`FindPermissionTokensByAccountId`].
pub fn new(account_id: impl Into<AccountId>) -> Self {
Self {
id: account_id.into(),
}
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this module.
pub mod prelude {
pub use super::{FindPermissionTokenSchema, FindPermissionTokensByAccountId};
Expand Down Expand Up @@ -540,48 +516,6 @@ pub mod account {
type Output = Vec<Account>;
}

impl FindAccountById {
/// Construct [`FindAccountById`].
pub fn new(id: impl Into<AccountId>) -> Self {
Self { id: id.into() }
}
}

impl FindAccountKeyValueByIdAndKey {
/// Construct [`FindAccountById`].
pub fn new(id: impl Into<AccountId>, key: impl Into<Name>) -> Self {
Self {
id: id.into(),
key: key.into(),
}
}
}

impl FindAccountsByName {
/// Construct [`FindAccountsByName`].
pub fn new(name: impl Into<Name>) -> Self {
Self { name: name.into() }
}
}

impl FindAccountsByDomainId {
/// Construct [`FindAccountsByDomainId`].
pub fn new(domain_id: impl Into<DomainId>) -> Self {
Self {
domain_id: domain_id.into(),
}
}
}

impl FindAccountsWithAsset {
/// Construct [`FindAccountsWithAsset`].
pub fn new(asset_definition_id: impl Into<AssetDefinitionId>) -> Self {
Self {
asset_definition_id: asset_definition_id.into(),
}
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this crate.
pub mod prelude {
pub use super::{
Expand Down Expand Up @@ -805,101 +739,6 @@ pub mod asset {
type Output = MetadataValue;
}

impl FindAssetById {
/// Construct [`FindAssetById`].
pub fn new(id: impl Into<AssetId>) -> Self {
Self { id: id.into() }
}
}

impl FindAssetDefinitionById {
/// Construct [`FindAssetDefinitionById`].
pub fn new(id: impl Into<AssetDefinitionId>) -> Self {
Self { id: id.into() }
}
}

impl FindAssetsByName {
/// Construct [`FindAssetsByName`].
pub fn new(name: impl Into<Name>) -> Self {
Self { name: name.into() }
}
}

impl FindAssetsByAccountId {
/// Construct [`FindAssetsByAccountId`].
pub fn new(account_id: impl Into<AccountId>) -> Self {
Self {
account_id: account_id.into(),
}
}
}

impl FindAssetsByAssetDefinitionId {
/// Construct [`FindAssetsByAssetDefinitionId`].
pub fn new(asset_definition_id: impl Into<AssetDefinitionId>) -> Self {
Self {
asset_definition_id: asset_definition_id.into(),
}
}
}

impl FindAssetsByDomainId {
/// Construct [`FindAssetsByDomainId`].
pub fn new(domain_id: impl Into<DomainId>) -> Self {
Self {
domain_id: domain_id.into(),
}
}
}

impl FindAssetsByDomainIdAndAssetDefinitionId {
/// Construct [`FindAssetsByDomainIdAndAssetDefinitionId`].
pub fn new(
domain_id: impl Into<DomainId>,
asset_definition_id: impl Into<AssetDefinitionId>,
) -> Self {
Self {
domain_id: domain_id.into(),
asset_definition_id: asset_definition_id.into(),
}
}
}

impl FindAssetQuantityById {
/// Construct [`FindAssetQuantityById`].
pub fn new(id: impl Into<AssetId>) -> Self {
Self { id: id.into() }
}
}

impl FindTotalAssetQuantityByAssetDefinitionId {
/// Construct [`FindTotalAssetQuantityByAssetDefinitionId`]
pub fn new(id: impl Into<AssetDefinitionId>) -> Self {
Self { id: id.into() }
}
}

impl FindAssetKeyValueByIdAndKey {
/// Construct [`FindAssetKeyValueByIdAndKey`].
pub fn new(id: impl Into<AssetId>, key: impl Into<Name>) -> Self {
Self {
id: id.into(),
key: key.into(),
}
}
}

impl FindAssetDefinitionKeyValueByIdAndKey {
/// Construct [`FindAssetDefinitionKeyValueByIdAndKey`].
pub fn new(id: impl Into<AssetDefinitionId>, key: impl Into<Name>) -> Self {
Self {
id: id.into(),
key: key.into(),
}
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this crate.
pub mod prelude {
pub use super::{
Expand Down Expand Up @@ -968,23 +807,6 @@ pub mod domain {
type Output = MetadataValue;
}

impl FindDomainById {
/// Construct [`FindDomainById`].
pub fn new(id: impl Into<DomainId>) -> Self {
Self { id: id.into() }
}
}

impl FindDomainKeyValueByIdAndKey {
/// Construct [`FindDomainKeyValueByIdAndKey`].
pub fn new(id: impl Into<DomainId>, key: impl Into<Name>) -> Self {
Self {
id: id.into(),
key: key.into(),
}
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this crate.
pub mod prelude {
pub use super::{FindAllDomains, FindDomainById, FindDomainKeyValueByIdAndKey};
Expand Down Expand Up @@ -1107,32 +929,6 @@ pub mod trigger {
type Output = Vec<Trigger<TriggeringFilterBox>>;
}

impl FindTriggerById {
/// Construct [`FindTriggerById`].
pub fn new(id: impl Into<TriggerId>) -> Self {
Self { id: id.into() }
}
}

impl FindTriggerKeyValueByIdAndKey {
/// Construct [`FindTriggerKeyValueByIdAndKey`].
pub fn new(id: impl Into<TriggerId>, key: impl Into<Name>) -> Self {
Self {
id: id.into(),
key: key.into(),
}
}
}

impl FindTriggersByDomainId {
/// Construct [`FindTriggersByDomainId`].
pub fn new(domain_id: impl Into<DomainId>) -> Self {
Self {
domain_id: domain_id.into(),
}
}
}

pub mod prelude {
//! Prelude Re-exports most commonly used traits, structs and macros from this crate.
pub use super::{
Expand Down Expand Up @@ -1200,22 +996,6 @@ pub mod transaction {
type Output = TransactionQueryOutput;
}

impl FindTransactionsByAccountId {
/// Construct [`FindTransactionsByAccountId`].
pub fn new(account_id: impl Into<AccountId>) -> Self {
Self {
account_id: account_id.into(),
}
}
}

impl FindTransactionByHash {
/// Construct [`FindTransactionByHash`].
pub fn new(hash: impl Into<HashOf<SignedTransaction>>) -> Self {
Self { hash: hash.into() }
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this crate.
pub mod prelude {
pub use super::{FindAllTransactions, FindTransactionByHash, FindTransactionsByAccountId};
Expand Down Expand Up @@ -1275,13 +1055,6 @@ pub mod block {
type Output = BlockHeader;
}

impl FindBlockHeaderByHash {
/// Construct [`FindBlockHeaderByHash`].
pub fn new(hash: impl Into<HashOf<SignedBlock>>) -> Self {
Self { hash: hash.into() }
}
}

/// The prelude re-exports most commonly used traits, structs and macros from this crate.
pub mod prelude {
pub use super::{FindAllBlockHeaders, FindAllBlocks, FindBlockHeaderByHash};
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ mod tests {
continue;
};

assert!(start < end, "Invalid type name: {}", type_name);
assert!(start < end, "Invalid type name: {type_name}");

for generic in type_name.split(", ") {
if !is_const_generic(generic) {
Expand Down

0 comments on commit c5461d5

Please sign in to comment.