Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove module-based api from client #5184

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 0 additions & 128 deletions crates/iroha/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,134 +972,6 @@ mod blocks_api {
pub type AsyncBlockStream = stream_api::AsyncStream<flow::Events>;
}

pub mod account {
//! Module with queries for account
use super::*;

/// Construct a query to get all accounts
pub const fn all() -> FindAccounts {
FindAccounts
}

/// Construct a query to get all accounts containing specified asset
pub fn all_with_asset(asset_definition_id: AssetDefinitionId) -> FindAccountsWithAsset {
FindAccountsWithAsset::new(asset_definition_id)
}
}

pub mod asset {
//! Module with queries for assets
use super::*;

/// Construct a query to get all assets
pub const fn all() -> FindAssets {
FindAssets
}

/// Construct a query to get all asset definitions
pub const fn all_definitions() -> FindAssetsDefinitions {
FindAssetsDefinitions
}
}

pub mod block {
//! Module with queries related to blocks

use super::*;

/// Construct a query to find all blocks
pub const fn all() -> FindBlocks {
FindBlocks
}

/// Construct a query to find all block headers
pub const fn all_headers() -> FindBlockHeaders {
FindBlockHeaders
}
}

pub mod domain {
//! Module with queries for domains
use super::*;

/// Construct a query to get all domains
pub const fn all() -> FindDomains {
FindDomains
}
}

pub mod transaction {
//! Module with queries for transactions

use super::*;

/// Construct a query to find all transactions
pub fn all() -> FindTransactions {
FindTransactions
}
}

pub mod trigger {
//! Module with queries for triggers
use super::*;

/// Construct a query to get all active trigger ids
pub fn all_ids() -> FindActiveTriggerIds {
FindActiveTriggerIds
}
}

pub mod permission {
//! Module with queries for permission tokens
use super::*;

/// Construct a query to get all [`Permission`] granted
/// to account with given [`Id`][AccountId]
pub fn by_account_id(account_id: AccountId) -> FindPermissionsByAccountId {
FindPermissionsByAccountId::new(account_id)
}
}

pub mod role {
//! Module with queries for roles
use super::*;

/// Construct a query to retrieve all roles
pub const fn all() -> FindRoles {
FindRoles
}

/// Construct a query to retrieve all role ids
pub const fn all_ids() -> FindRoleIds {
FindRoleIds
}

/// Construct a query to retrieve all roles for an account
pub fn by_account_id(account_id: AccountId) -> FindRolesByAccountId {
FindRolesByAccountId::new(account_id)
}
}

pub mod parameter {
//! Module with queries for config parameters
use super::*;

/// Construct a query to retrieve all config parameters
pub const fn all() -> FindParameters {
FindParameters
}
}

pub mod executor {
//! Queries for executor entities
use super::*;

/// Retrieve executor data model
pub const fn data_model() -> FindExecutorDataModel {
FindExecutorDataModel
}
}

#[cfg(test)]
mod tests {
use iroha_primitives::small::SmallStr;
Expand Down
19 changes: 9 additions & 10 deletions crates/iroha/tests/asset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use eyre::Result;
use iroha::{
client,
crypto::KeyPair,
data_model::{
asset::{AssetId, AssetType, AssetValue},
Expand Down Expand Up @@ -41,7 +40,7 @@ fn client_register_asset_should_add_asset_once_but_not_twice() -> Result<()> {
// Registering an asset to an account which doesn't have one
// should result in asset being created
let asset = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id))
.execute_all()?
.into_iter()
Expand Down Expand Up @@ -76,7 +75,7 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> {

// Check for asset to be registered
let assets = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?;

Expand All @@ -88,7 +87,7 @@ fn unregister_asset_should_remove_asset_from_account() -> Result<()> {

// ... and check that it is removed after Unregister
let assets = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?;

Expand Down Expand Up @@ -125,7 +124,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() ->
test_client.submit_transaction_blocking(&tx)?;

let asset = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id))
.execute_all()?
.into_iter()
Expand Down Expand Up @@ -159,7 +158,7 @@ fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount(
test_client.submit_transaction_blocking(&tx)?;

let asset = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id))
.execute_all()?
.into_iter()
Expand Down Expand Up @@ -194,7 +193,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
test_client.submit_transaction_blocking(&tx)?;

let asset = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.into_iter()
Expand All @@ -215,7 +214,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
test_client.submit_blocking(mint)?;

let asset = test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id))
.execute_all()?
.into_iter()
Expand Down Expand Up @@ -339,7 +338,7 @@ fn transfer_asset_definition() {
.expect("Failed to submit transaction");

let asset_definition = test_client
.query(client::asset::all_definitions())
.query(FindAllAssetDefinitions::new())
.filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id.clone()))
.execute_single()
.expect("Failed to execute Iroha Query");
Expand All @@ -354,7 +353,7 @@ fn transfer_asset_definition() {
.expect("Failed to submit transaction");

let asset_definition = test_client
.query(client::asset::all_definitions())
.query(FindAllAssetDefinitions::new())
.filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id))
.execute_single()
.expect("Failed to execute Iroha Query");
Expand Down
7 changes: 2 additions & 5 deletions crates/iroha/tests/asset_propagation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use eyre::Result;
use iroha::{
client,
data_model::{parameter::BlockParameter, prelude::*},
};
use iroha::data_model::{parameter::BlockParameter, prelude::*};
use iroha_test_network::*;
use iroha_test_samples::gen_account_in;
use nonzero_ext::nonzero;
Expand Down Expand Up @@ -46,7 +43,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a
// Then
let asset = peer_b
.client()
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id))
.execute_all()?
.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn multiple_blocks_created() -> Result<()> {
let definition = asset_definition_id.clone();
let assets = spawn_blocking(move || {
client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| {
asset.id.account.eq(account_id) & asset.id.definition_id.eq(definition)
})
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha/tests/extra_functional/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn transactions_should_be_applied() -> Result<()> {
iroha.submit_blocking(mint_asset)?;

iroha
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.eq(asset_id))
.execute_single()?;

Expand Down
2 changes: 1 addition & 1 deletion crates/iroha/tests/extra_functional/offline_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> {
.client();
spawn_blocking(move || -> Result<()> {
let assets = client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(alice_id))
.execute_all()?;
let asset = assets
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha/tests/extra_functional/restart_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn restarted_peer_should_restore_its_state() -> Result<()> {
let client = peer_b.client();
let asset = spawn_blocking(move || {
client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(ALICE_ID.clone()))
.execute_all()
})
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha/tests/extra_functional/unregister_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async fn find_asset(
let client = client.clone();
let asset = spawn_blocking(move || {
client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()
})
Expand Down
5 changes: 2 additions & 3 deletions crates/iroha/tests/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::BTreeMap;
use executor_custom_data_model::multisig::{MultisigArgs, MultisigRegisterArgs};
use eyre::Result;
use iroha::{
client,
crypto::KeyPair,
data_model::{
asset::{AssetDefinition, AssetDefinitionId},
Expand Down Expand Up @@ -120,7 +119,7 @@ fn mutlisig() -> Result<()> {

// Check that asset definition isn't created yet
let err = test_client
.query(client::asset::all_definitions())
.query(FindAllAssetDefinitions::new())
.filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id.clone()))
.execute_single()
.expect_err("asset definition shouldn't be created before enough votes are collected");
Expand All @@ -138,7 +137,7 @@ fn mutlisig() -> Result<()> {

// Check that new asset definition was created and multisig account is owner
let asset_definition = test_client
.query(client::asset::all_definitions())
.query(FindAllAssetDefinitions::new())
.filter_with(|asset_definition| asset_definition.id.eq(asset_definition_id.clone()))
.execute_single()
.expect("asset definition should be created after enough votes are collected");
Expand Down
11 changes: 4 additions & 7 deletions crates/iroha/tests/non_mintable.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use eyre::Result;
use iroha::{
client,
data_model::{isi::InstructionBox, prelude::*},
};
use iroha::data_model::{isi::InstructionBox, prelude::*};
use iroha_test_network::*;
use iroha_test_samples::ALICE_ID;

Expand Down Expand Up @@ -33,7 +30,7 @@ fn non_mintable_asset_can_be_minted_once_but_not_twice() -> Result<()> {
// We can register and mint the non-mintable token
test_client.submit_transaction_blocking(&tx)?;
assert!(test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.iter()
Expand Down Expand Up @@ -72,7 +69,7 @@ fn non_mintable_asset_cannot_be_minted_if_registered_with_non_zero_value() -> Re
register_asset.clone().into(),
])?;
assert!(test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.iter()
Expand Down Expand Up @@ -116,7 +113,7 @@ fn non_mintable_asset_can_be_minted_if_registered_with_zero_value() -> Result<()
mint.into(),
])?;
assert!(test_client
.query(client::asset::all())
.query(FindAssets::new())
.filter_with(|asset| asset.id.account.eq(account_id.clone()))
.execute_all()?
.iter()
Expand Down
8 changes: 4 additions & 4 deletions crates/iroha/tests/pagination.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use eyre::Result;
use iroha::{
client::{asset, Client},
client::Client,
data_model::{asset::AssetDefinition, prelude::*},
};
use iroha_test_network::*;
Expand All @@ -14,7 +14,7 @@ fn limits_should_work() -> Result<()> {
register_assets(&client)?;

let vec = client
.query(asset::all_definitions())
.query(FindAllAssetDefinitions::new())
.with_pagination(Pagination {
limit: Some(nonzero!(7_u64)),
offset: 1,
Expand All @@ -32,7 +32,7 @@ fn reported_length_should_be_accurate() -> Result<()> {
register_assets(&client)?;

let mut iter = client
.query(asset::all_definitions())
.query(FindAllAssetDefinitions::new())
.with_pagination(Pagination {
limit: Some(nonzero!(7_u64)),
offset: 1,
Expand Down Expand Up @@ -66,7 +66,7 @@ fn fetch_size_should_work() -> Result<()> {
register_assets(&client)?;

let query = QueryWithParams::new(
QueryWithFilter::new(asset::all_definitions(), CompoundPredicate::PASS).into(),
QueryWithFilter::new(FindAllAssetDefinitions::new(), CompoundPredicate::PASS).into(),
QueryParams::new(
Pagination {
limit: Some(nonzero!(7_u64)),
Expand Down
Loading
Loading