Skip to content

Commit

Permalink
refactor(queries)!: remove Iterable prefix from query types as it's g…
Browse files Browse the repository at this point in the history
…onna be the "default"

Signed-off-by: ⭐️NINIKA⭐️ <[email protected]>
  • Loading branch information
DCNick3 committed Aug 5, 2024
1 parent 87f17aa commit 3532206
Show file tree
Hide file tree
Showing 27 changed files with 875 additions and 881 deletions.
20 changes: 9 additions & 11 deletions client/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use iroha_data_model::{
builder::{QueryBuilder, QueryExecutor},
parameters::ForwardCursor,
predicate::HasPredicateBox,
IterableQueryOutput, IterableQueryOutputBatchBox, IterableQueryWithParams, QueryRequest,
QueryResponse, SingularQuery, SingularQueryBox, SingularQueryOutputBox,
QueryOutput, QueryOutputBatchBox, QueryRequest, QueryResponse, QueryWithParams,
SingularQuery, SingularQueryBox, SingularQueryOutputBox,
},
ValidationFail,
};
Expand All @@ -22,7 +22,7 @@ use url::Url;

use crate::{
client::{join_torii_url, Client, QueryResult, ResponseReport},
data_model::query::IterableQuery,
data_model::query::Query,
http::{Method as HttpMethod, RequestBuilder},
http_default::DefaultRequestBuilder,
};
Expand Down Expand Up @@ -102,9 +102,7 @@ fn decode_singular_query_response(
Ok(resp)
}

fn decode_iterable_query_response(
resp: &http::Response<Vec<u8>>,
) -> QueryResult<IterableQueryOutput> {
fn decode_iterable_query_response(resp: &http::Response<Vec<u8>>) -> QueryResult<QueryOutput> {
let QueryResponse::Iterable(resp) = decode_query_response(resp)? else {
return Err(eyre!(
"Got unexpected type of query response from the node (expected iterable)"
Expand Down Expand Up @@ -160,8 +158,8 @@ impl QueryExecutor for Client {

fn start_query(
&self,
query: IterableQueryWithParams,
) -> Result<(IterableQueryOutputBatchBox, Option<Self::Cursor>), Self::Error> {
query: QueryWithParams,
) -> Result<(QueryOutputBatchBox, Option<Self::Cursor>), Self::Error> {
let request_head = self.get_query_request_head();

let request = QueryRequest::StartIterable(query);
Expand All @@ -181,7 +179,7 @@ impl QueryExecutor for Client {

fn continue_query(
cursor: Self::Cursor,
) -> Result<(IterableQueryOutputBatchBox, Option<Self::Cursor>), Self::Error> {
) -> Result<(QueryOutputBatchBox, Option<Self::Cursor>), Self::Error> {
let ClientQueryCursor {
request_head,
cursor,
Expand Down Expand Up @@ -241,9 +239,9 @@ impl Client {
pub fn query<Q>(
&self,
query: Q,
) -> QueryBuilder<Self, Q, <<Q as IterableQuery>::Item as HasPredicateBox>::PredicateBoxType>
) -> QueryBuilder<Self, Q, <<Q as Query>::Item as HasPredicateBox>::PredicateBoxType>
where
Q: IterableQuery,
Q: Query,
{
QueryBuilder::new(self, query)
}
Expand Down
8 changes: 4 additions & 4 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ mod json {
use std::io::{BufReader, Read as _};

use clap::Subcommand;
use iroha::data_model::query::QueryBox;
use iroha::data_model::query::AnyQueryBox;

use super::*;

Expand Down Expand Up @@ -1162,17 +1162,17 @@ mod json {
}
Variant::Query => {
let client = Client::new(context.configuration().clone());
let query: QueryBox = json5::from_str(&string_content)?;
let query: AnyQueryBox = json5::from_str(&string_content)?;

match query {
QueryBox::Singular(query) => {
AnyQueryBox::Singular(query) => {
let result = client
.query_single(query)
.wrap_err("Failed to query response")?;

context.print_data(&result)?;
}
QueryBox::Iterable(query) => {
AnyQueryBox::Iterable(query) => {
// we can't really do type-erased iterable queries in a nice way right now...
use iroha::data_model::query::builder::QueryExecutor;

Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use iroha_data_model::{
account::AccountId,
executor as data_model_executor,
isi::InstructionBox,
query::{QueryBox, QueryRequest},
query::{AnyQueryBox, QueryRequest},
transaction::{Executable, SignedTransaction},
ValidationFail,
};
Expand Down Expand Up @@ -206,8 +206,8 @@ impl Executor {
trace!("Running query validation");

let query = match query {
QueryRequest::Singular(singular) => QueryBox::Singular(singular.clone()),
QueryRequest::StartIterable(iterable) => QueryBox::Iterable(iterable.clone()),
QueryRequest::Singular(singular) => AnyQueryBox::Singular(singular.clone()),
QueryRequest::StartIterable(iterable) => AnyQueryBox::Iterable(iterable.clone()),
QueryRequest::ContinueIterable(_) => {
// The iterable query was already validated when it started
return Ok(());
Expand Down
12 changes: 6 additions & 6 deletions core/src/query/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use std::{
};

use derive_more::Display;
use iroha_data_model::query::IterableQueryOutputBatchBox;
use iroha_data_model::query::QueryOutputBatchBox;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

trait BatchedTrait {
fn next_batch(
&mut self,
cursor: u64,
) -> Result<(IterableQueryOutputBatchBox, Option<NonZeroU64>), UnknownCursor>;
) -> Result<(QueryOutputBatchBox, Option<NonZeroU64>), UnknownCursor>;
}

struct BatchedInner<I> {
Expand All @@ -26,12 +26,12 @@ struct BatchedInner<I> {
impl<I> BatchedTrait for BatchedInner<I>
where
I: Iterator,
IterableQueryOutputBatchBox: From<Vec<I::Item>>,
QueryOutputBatchBox: From<Vec<I::Item>>,
{
fn next_batch(
&mut self,
cursor: u64,
) -> Result<(IterableQueryOutputBatchBox, Option<NonZeroU64>), UnknownCursor> {
) -> Result<(QueryOutputBatchBox, Option<NonZeroU64>), UnknownCursor> {
let Some(server_cursor) = self.cursor else {
// the server is done with the iterator
return Err(UnknownCursor);
Expand Down Expand Up @@ -104,7 +104,7 @@ impl QueryBatchedErasedIterator {
pub fn new<I>(iter: I, batch_size: NonZeroU32) -> Self
where
I: Iterator + Send + Sync + 'static,
IterableQueryOutputBatchBox: From<Vec<I::Item>>,
QueryOutputBatchBox: From<Vec<I::Item>>,
{
Self {
inner: Box::new(BatchedInner {
Expand All @@ -128,7 +128,7 @@ impl QueryBatchedErasedIterator {
pub fn next_batch(
&mut self,
cursor: u64,
) -> Result<(IterableQueryOutputBatchBox, Option<NonZeroU64>), UnknownCursor> {
) -> Result<(QueryOutputBatchBox, Option<NonZeroU64>), UnknownCursor> {
self.inner.next_batch(cursor)
}
}
20 changes: 10 additions & 10 deletions core/src/query/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use iroha_config::parameters::actual::LiveQueryStore as Config;
use iroha_data_model::{
account::AccountId,
query::{
parameters::{ForwardCursor, QueryId},
error::QueryExecutionFail,
IterableQueryOutput, IterableQueryOutputBatchBox,
parameters::{ForwardCursor, QueryId},
QueryOutput, QueryOutputBatchBox,
},
};
use iroha_logger::{trace, warn};
Expand Down Expand Up @@ -189,7 +189,7 @@ impl LiveQueryStore {
&self,
query_id: QueryId,
cursor: NonZeroU64,
) -> Result<(IterableQueryOutputBatchBox, Option<NonZeroU64>)> {
) -> Result<(QueryOutputBatchBox, Option<NonZeroU64>)> {
trace!(%query_id, "Advancing existing query");
let QueryInfo {
mut live_query,
Expand Down Expand Up @@ -242,7 +242,7 @@ impl LiveQueryStoreHandle {
&self,
mut live_query: QueryBatchedErasedIterator,
authority: &AccountId,
) -> Result<IterableQueryOutput> {
) -> Result<QueryOutput> {
let query_id = uuid::Uuid::new_v4().to_string();

let curr_cursor = 0;
Expand All @@ -264,7 +264,7 @@ impl LiveQueryStoreHandle {
pub fn handle_iter_continue(
&self,
ForwardCursor { query, cursor }: ForwardCursor,
) -> Result<IterableQueryOutput> {
) -> Result<QueryOutput> {
let (batch, next_cursor) = self.store.get_query_next_batch(query.clone(), cursor)?;

Ok(Self::construct_query_response(batch, query, next_cursor))
Expand All @@ -276,11 +276,11 @@ impl LiveQueryStoreHandle {
}

fn construct_query_response(
batch: IterableQueryOutputBatchBox,
batch: QueryOutputBatchBox,
query_id: QueryId,
cursor: Option<NonZeroU64>,
) -> IterableQueryOutput {
IterableQueryOutput::new(
) -> QueryOutput {
QueryOutput::new(
batch,
cursor.map(|cursor| ForwardCursor {
query: query_id,
Expand All @@ -294,7 +294,7 @@ impl LiveQueryStoreHandle {
mod tests {
use iroha_data_model::{
permission::Permission,
query::parameters::{FetchSize, IterableQueryParams, Pagination, Sorting},
query::parameters::{FetchSize, Pagination, QueryParams, Sorting},
};
use iroha_primitives::json::JsonString;
use nonzero_ext::nonzero;
Expand All @@ -315,7 +315,7 @@ mod tests {
};
let sorting = Sorting::default();

let query_params = IterableQueryParams {
let query_params = QueryParams {
pagination,
sorting,
fetch_size,
Expand Down
10 changes: 5 additions & 5 deletions core/src/smartcontracts/isi/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ pub mod query {
use iroha_primitives::json::JsonString;

use super::*;
use crate::{smartcontracts::ValidIterableQuery, state::StateReadOnly};
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};

impl ValidIterableQuery for FindRolesByAccountId {
impl ValidQuery for FindRolesByAccountId {
#[metrics(+"find_roles_by_account_id")]
fn execute<'state>(
self,
Expand All @@ -513,7 +513,7 @@ pub mod query {
}
}

impl ValidIterableQuery for FindPermissionsByAccountId {
impl ValidQuery for FindPermissionsByAccountId {
#[metrics(+"find_permissions_by_account_id")]
fn execute<'state>(
self,
Expand All @@ -529,7 +529,7 @@ pub mod query {
}
}

impl ValidIterableQuery for FindAccounts {
impl ValidQuery for FindAccounts {
#[metrics(+"find_accounts")]
fn execute<'state>(
self,
Expand Down Expand Up @@ -558,7 +558,7 @@ pub mod query {
}
}

impl ValidIterableQuery for FindAccountsWithAsset {
impl ValidQuery for FindAccountsWithAsset {
#[metrics(+"find_accounts_with_asset")]
fn execute<'state>(
self,
Expand Down
6 changes: 3 additions & 3 deletions core/src/smartcontracts/isi/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ pub mod query {
use iroha_primitives::json::JsonString;

use super::*;
use crate::{smartcontracts::ValidIterableQuery, state::StateReadOnly};
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};

impl ValidIterableQuery for FindAssets {
impl ValidQuery for FindAssets {
#[metrics(+"find_assets")]
fn execute<'state>(
self,
Expand All @@ -451,7 +451,7 @@ pub mod query {
.cloned())
}
}
impl ValidIterableQuery for FindAssetsDefinitions {
impl ValidQuery for FindAssetsDefinitions {
#[metrics(+"find_asset_definitions")]
fn execute<'state>(
self,
Expand Down
6 changes: 3 additions & 3 deletions core/src/smartcontracts/isi/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use iroha_data_model::{
use iroha_telemetry::metrics;

use super::*;
use crate::{smartcontracts::ValidIterableQuery, state::StateReadOnly};
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};

impl ValidIterableQuery for FindBlocks {
impl ValidQuery for FindBlocks {
#[metrics(+"find_blocks")]
fn execute<'state>(
self,
Expand All @@ -31,7 +31,7 @@ impl ValidIterableQuery for FindBlocks {
}
}

impl ValidIterableQuery for FindBlockHeaders {
impl ValidQuery for FindBlockHeaders {
#[metrics(+"find_block_headers")]
fn execute<'state>(
self,
Expand Down
4 changes: 2 additions & 2 deletions core/src/smartcontracts/isi/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ pub mod query {
use iroha_primitives::json::JsonString;

use super::*;
use crate::{smartcontracts::ValidIterableQuery, state::StateReadOnly};
use crate::{smartcontracts::ValidQuery, state::StateReadOnly};

impl ValidIterableQuery for FindDomains {
impl ValidQuery for FindDomains {
#[metrics(+"find_domains")]
fn execute<'state>(
self,
Expand Down
Loading

0 comments on commit 3532206

Please sign in to comment.