Skip to content

Commit

Permalink
feat!: remove the old query system entirely, fix the schema and some …
Browse files Browse the repository at this point in the history
…other remaining tests

Signed-off-by: ⭐️NINIKA⭐️ <dcnick3@users.noreply.github.com>
  • Loading branch information
DCNick3 committed Jul 10, 2024
1 parent c36cac5 commit bfb2f31
Show file tree
Hide file tree
Showing 52 changed files with 1,969 additions and 4,131 deletions.
55 changes: 5 additions & 50 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,6 @@ impl Client {
transaction.sign(self.key_pair.private_key())
}

/// Signs query
///
/// # Errors
/// Fails if signature generation fails
pub fn sign_query(&self, query: ClientQueryBuilder) -> SignedQuery {
query.sign(&self.key_pair)
}

/// Instructions API entry point. Submits one Iroha Special Instruction to `Iroha` peers.
/// Returns submitted transaction's hash or error string.
///
Expand Down Expand Up @@ -980,11 +972,6 @@ pub mod account {
FindAllAccounts
}

/// Construct a query to get account by id
pub fn by_id(account_id: AccountId) -> FindAccountById {
FindAccountById::new(account_id)
}

/// 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)
Expand All @@ -1004,21 +991,6 @@ pub mod asset {
pub const fn all_definitions() -> FindAllAssetsDefinitions {
FindAllAssetsDefinitions
}

/// Construct a query to get asset definition by its id
pub fn definition_by_id(asset_definition_id: AssetDefinitionId) -> FindAssetDefinitionById {
FindAssetDefinitionById::new(asset_definition_id)
}

/// Construct a query to get all assets by account id
pub fn by_account_id(account_id: AccountId) -> FindAssetsByAccountId {
FindAssetsByAccountId::new(account_id)
}

/// Construct a query to get an asset by its id
pub fn by_id(asset_id: AssetId) -> FindAssetById {
FindAssetById::new(asset_id)
}
}

pub mod block {
Expand Down Expand Up @@ -1050,11 +1022,6 @@ pub mod domain {
pub const fn all() -> FindAllDomains {
FindAllDomains
}

/// Construct a query to get all domain by id
pub fn by_id(domain_id: DomainId) -> FindDomainById {
FindDomainById::new(domain_id)
}
}

pub mod transaction {
Expand Down Expand Up @@ -1082,22 +1049,15 @@ pub mod trigger {
//! Module with queries for triggers
use super::*;

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

/// Construct a query to get a trigger by its id
pub fn by_id(trigger_id: TriggerId) -> FindTriggerById {
FindTriggerById::new(trigger_id)
}

/// Construct a query to find all triggers executable
/// on behalf of the given account.
pub fn by_authority(account_id: AccountId) -> FindTriggersByAuthorityId {
FindTriggersByAuthorityId::new(account_id)
}

/// Construct a query to find all triggers executable
/// on behalf of any account belonging to the given domain.
pub fn by_domain_of_authority(domain_id: DomainId) -> FindTriggersByAuthorityDomainId {
FindTriggersByAuthorityDomainId::new(domain_id)
}
}

pub mod permission {
Expand Down Expand Up @@ -1125,11 +1085,6 @@ pub mod role {
FindAllRoleIds
}

/// Construct a query to retrieve a role by its id
pub fn by_id(role_id: RoleId) -> FindRoleByRoleId {
FindRoleByRoleId::new(role_id)
}

/// Construct a query to retrieve all roles for an account
pub fn by_account_id(account_id: AccountId) -> FindRolesByAccountId {
FindRolesByAccountId::new(account_id)
Expand Down
28 changes: 14 additions & 14 deletions client/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(unused, missing_docs)]
#![warn(missing_docs)]

use std::{collections::HashMap, fmt::Debug};

Expand All @@ -9,10 +9,10 @@ use iroha_data_model::{
account::AccountId,
query::{
builder::{IterableQueryBuilder, QueryExecutor, SingleQueryError},
error::QueryExecutionFail,
parameters::ForwardCursor,
predicate::HasPredicateBox,
ForwardCursor, IterableQueryOutput, IterableQueryOutputBatchBox, IterableQueryWithParams,
QueryRequest2, QueryResponse2, SingularQuery, SingularQueryBox, SingularQueryOutputBox,
IterableQueryOutput, IterableQueryOutputBatchBox, IterableQueryWithParams, QueryRequest,
QueryResponse, SingularQuery, SingularQueryBox, SingularQueryOutputBox,
},
ValidationFail,
};
Expand All @@ -36,7 +36,7 @@ struct ClientQueryRequestHead {
}

impl ClientQueryRequestHead {
pub fn assemble(&self, query: QueryRequest2) -> DefaultRequestBuilder {
pub fn assemble(&self, query: QueryRequest) -> DefaultRequestBuilder {
// authorize and sign the query
let query = query
.with_authority(self.account_id.clone())
Expand All @@ -52,10 +52,10 @@ impl ClientQueryRequestHead {
}

/// Decode a raw response from the node's query endpoint
fn decode_query_response(resp: &http::Response<Vec<u8>>) -> QueryResult<QueryResponse2> {
fn decode_query_response(resp: &http::Response<Vec<u8>>) -> QueryResult<QueryResponse> {
match resp.status() {
StatusCode::OK => {
let res = QueryResponse2::decode_all(&mut resp.body().as_slice());
let res = QueryResponse::decode_all(&mut resp.body().as_slice());
res.wrap_err(
"Failed to decode response from Iroha. \
You are likely using a version of the client library \
Expand Down Expand Up @@ -93,7 +93,7 @@ fn decode_query_response(resp: &http::Response<Vec<u8>>) -> QueryResult<QueryRes
fn decode_singular_query_response(
resp: &http::Response<Vec<u8>>,
) -> QueryResult<SingularQueryOutputBox> {
let QueryResponse2::Singular(resp) = decode_query_response(resp)? else {
let QueryResponse::Singular(resp) = decode_query_response(resp)? else {
return Err(eyre!(
"Got unexpected type of query response from the node (expected singular)"
)
Expand All @@ -105,7 +105,7 @@ fn decode_singular_query_response(
fn decode_iterable_query_response(
resp: &http::Response<Vec<u8>>,
) -> QueryResult<IterableQueryOutput> {
let QueryResponse2::Iterable(resp) = decode_query_response(resp)? else {
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 @@ -153,7 +153,7 @@ impl QueryExecutor for Client {
) -> Result<SingularQueryOutputBox, Self::Error> {
let request_head = self.get_query_request_head();

let request = QueryRequest2::Singular(query);
let request = QueryRequest::Singular(query);

let response = request_head.assemble(request).build()?.send()?;
let response = decode_singular_query_response(&response)?;
Expand All @@ -167,7 +167,7 @@ impl QueryExecutor for Client {
) -> Result<(IterableQueryOutputBatchBox, Option<Self::Cursor>), Self::Error> {
let request_head = self.get_query_request_head();

let request = QueryRequest2::StartIterable(query);
let request = QueryRequest::StartIterable(query);

let response = request_head.assemble(request).build()?.send()?;
let response = decode_iterable_query_response(&response)?;
Expand All @@ -190,7 +190,7 @@ impl QueryExecutor for Client {
cursor,
} = cursor;

let request = QueryRequest2::ContinueIterable(cursor);
let request = QueryRequest::ContinueIterable(cursor);

let response = request_head.assemble(request).build()?.send()?;
let response = decode_iterable_query_response(&response)?;
Expand Down Expand Up @@ -249,10 +249,10 @@ impl Client {
pub fn raw_continue_iterable_query(
&self,
cursor: ForwardCursor,
) -> Result<QueryResponse2, ClientQueryError> {
) -> Result<QueryResponse, ClientQueryError> {
let request_head = self.get_query_request_head();

let request = QueryRequest2::ContinueIterable(cursor);
let request = QueryRequest::ContinueIterable(cursor);

let response = request_head.assemble(request).build()?.send()?;
let response = decode_query_response(&response)?;
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/pagination.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use eyre::Result;
use iroha::{
client::{asset, Client},
data_model::{asset::AssetDefinition, prelude::*, query::Pagination},
data_model::{asset::AssetDefinition, prelude::*},
};
use nonzero_ext::nonzero;
use test_network::*;
Expand Down
6 changes: 2 additions & 4 deletions client/tests/integration/queries/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use iroha::{
client::{self, ClientQueryError},
data_model::{
prelude::*,
query::{error::QueryExecutionFail, MAX_FETCH_SIZE},
},
data_model::{prelude::*, query::error::QueryExecutionFail},
};
use iroha_data_model::query::parameters::MAX_FETCH_SIZE;
use test_network::*;

mod account;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ mod expression {

use iroha_data_model::{
isi::InstructionBox,
prelude::{
FindAssetQuantityById, FindTotalAssetQuantityByAssetDefinitionId, Numeric, QueryBox,
},
prelude::{FindAssetQuantityById, FindTotalAssetQuantityByAssetDefinitionId, Numeric},
};
use iroha_schema::{IntoSchema, TypeId};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -295,12 +293,7 @@ mod expression {
mod evaluate {
use alloc::string::ToString;

use iroha_data_model::{
isi::error::InstructionExecutionError,
prelude::Numeric,
query::{QueryBox, SingularQuery, SingularQueryBox},
ValidationFail,
};
use iroha_data_model::{isi::error::InstructionExecutionError, ValidationFail};

use crate::complex_isi::{
expression::{EvaluatesTo, Expression, Greater, Value},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ extern crate panic_halt;

use executor_custom_data_model::simple_isi::{CustomInstructionBox, MintAssetForAllAccounts};
use iroha_executor::{
data_model::isi::CustomInstruction,
debug::DebugExpectExt,
prelude::*,
smart_contract::{iter_query, SmartContractSingularQueryError},
data_model::isi::CustomInstruction, debug::DebugExpectExt, prelude::*,
smart_contract::iter_query,
};
use lol_alloc::{FreeListAllocator, LockedAllocator};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use core::str::FromStr as _;
use executor_custom_data_model::mint_rose_args::MintRoseArgs;
use iroha_trigger::{debug::dbg_panic, prelude::*};
use lol_alloc::{FreeListAllocator, LockedAllocator};
use serde::{Deserialize, Serialize};

#[global_allocator]
static ALLOC: LockedAllocator<FreeListAllocator> = LockedAllocator::new(FreeListAllocator::new());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ extern crate alloc;

use iroha_smart_contract::{
data_model::query::{
builder::QueryExecutor, cursor::ForwardCursor, predicate::CompoundPredicate,
IterableQueryParams, IterableQueryWithFilter, IterableQueryWithParams,
builder::QueryExecutor,
parameters::{ForwardCursor, IterableQueryParams},
predicate::CompoundPredicate,
IterableQueryWithFilter, IterableQueryWithParams,
},
prelude::*,
SmartContractQueryExecutor,
Expand All @@ -34,14 +36,14 @@ fn main(owner: AccountId) {
}

let (_batch, cursor) = SmartContractQueryExecutor
.start_iterable_query(IterableQueryWithParams {
query: IterableQueryWithFilter::new(FindAllAssets, CompoundPredicate::PASS).into(),
params: IterableQueryParams {
pagination: Default::default(),
sorting: Default::default(),
fetch_size: FetchSize::new(Some(nonzero!(1_u32))),
},
})
.start_iterable_query(IterableQueryWithParams::new(
IterableQueryWithFilter::new(FindAllAssets, CompoundPredicate::PASS).into(),
IterableQueryParams::new(
Default::default(),
Default::default(),
FetchSize::new(Some(nonzero!(1_u32))),
),
))
.dbg_unwrap();

// break encapsulation by serializing and deserializing into a compatible type
Expand Down
6 changes: 1 addition & 5 deletions client/tests/integration/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use eyre::{Result, WrapErr as _};
use iroha::{
client::{self, QueryResult},
crypto::KeyPair,
data_model::{
account::Account,
prelude::*,
query::{Pagination, Sorting},
},
data_model::{account::Account, prelude::*},
};
use iroha_data_model::query::predicate::predicate_atoms::asset::AssetPredicateBox;
use nonzero_ext::nonzero;
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/tx_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{str::FromStr as _, thread};
use eyre::Result;
use iroha::{
client::transaction,
data_model::{prelude::*, query::Pagination},
data_model::{prelude::*, query::parameters::Pagination},
};
use iroha_config::parameters::actual::Root as Config;
use nonzero_ext::nonzero;
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 @@ -1066,7 +1066,7 @@ mod json {
use std::io::{BufReader, Read as _};

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

use super::*;

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

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

context.print_data(&result)?;
}
QueryBox2::Iterable(query) => {
QueryBox::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.
14 changes: 5 additions & 9 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::{QueryBox2, QueryRequest2},
query::{QueryBox, QueryRequest},
transaction::{Executable, SignedTransaction},
ValidationFail,
};
Expand Down Expand Up @@ -201,18 +201,14 @@ impl Executor {
&self,
state_ro: &S,
authority: &AccountId,
query: &QueryRequest2,
query: &QueryRequest,
) -> Result<(), ValidationFail> {
trace!("Running query validation");

// TODO: actually validate the query request

// Ok(())

let query = match query {
QueryRequest2::Singular(singular) => QueryBox2::Singular(singular.clone()),
QueryRequest2::StartIterable(iterable) => QueryBox2::Iterable(iterable.clone()),
QueryRequest2::ContinueIterable(_) => {
QueryRequest::Singular(singular) => QueryBox::Singular(singular.clone()),
QueryRequest::StartIterable(iterable) => QueryBox::Iterable(iterable.clone()),
QueryRequest::ContinueIterable(_) => {
// The iterable query was already validated when it started
return Ok(());
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub mod prelude {

#[doc(inline)]
pub use crate::{
smartcontracts::ValidQuery,
smartcontracts::ValidSingularQuery,
state::{StateReadOnly, StateView, World, WorldReadOnly},
tx::AcceptedTransaction,
};
Expand Down
Loading

0 comments on commit bfb2f31

Please sign in to comment.