Skip to content

Commit

Permalink
[fix] hyperledger-iroha#4014: Use method(not field) access in client (h…
Browse files Browse the repository at this point in the history
…yperledger-iroha#4015)

Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic authored Oct 26, 2023
1 parent 1ea5f31 commit 8018332
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
16 changes: 7 additions & 9 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ where

fn next(&mut self) -> Option<Self::Item> {
if self.client_cursor >= self.iter.len() {
let iroha_data_model::query::QueryRequest::Cursor(cursor) = &self.query_handler.query_request.request else {
let iroha_data_model::query::QueryRequest::Cursor(cursor) =
&self.query_handler.query_request.request
else {
return None;
};
if cursor.cursor().is_none() {
Expand Down Expand Up @@ -387,9 +389,9 @@ impl QueryRequest {

match self.request {
iroha_data_model::query::QueryRequest::Query(query_with_params) => builder
.params(Vec::from(query_with_params.sorting))
.params(Vec::from(query_with_params.pagination))
.body(query_with_params.query),
.params(Vec::from(query_with_params.sorting().clone()))
.params(Vec::from(*query_with_params.pagination()))
.body(query_with_params.query().clone()),
iroha_data_model::query::QueryRequest::Cursor(cursor) => {
builder.params(Vec::from(cursor))
}
Expand Down Expand Up @@ -809,11 +811,7 @@ impl Client {
torii_url: self.torii_url.clone(),
headers: self.headers.clone(),
request: iroha_data_model::query::QueryRequest::Query(
iroha_data_model::query::QueryWithParameters {
query: request,
pagination,
sorting,
},
iroha_data_model::query::QueryWithParameters::new(request, sorting, pagination),
),
};

Expand Down
16 changes: 8 additions & 8 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl FromStr for Metadata {

/// Client configuration wrapper. Allows getting itself from arguments from cli (from user supplied file).
#[derive(Debug, Clone)]
pub struct Configuration(pub ClientConfiguration);
struct Configuration(pub ClientConfiguration);

impl FromStr for Configuration {
type Err = Error;
Expand All @@ -62,7 +62,7 @@ impl FromStr for Configuration {
/// Iroha CLI Client provides an ability to interact with Iroha Peers Web API without direct network usage.
#[derive(StructOpt, Debug)]
#[structopt(name = "iroha_client_cli", version = concat!(env!("CARGO_PKG_VERSION")), author)]
pub struct Args {
struct Args {
/// Sets a config file path
#[structopt(short, long)]
config: Option<Configuration>,
Expand All @@ -80,7 +80,7 @@ pub struct Args {
}

#[derive(StructOpt, Debug)]
pub enum Subcommand {
enum Subcommand {
/// The subcommand related to domains
#[clap(subcommand)]
Domain(domain::Args),
Expand All @@ -105,7 +105,7 @@ pub enum Subcommand {
}

/// Context inside which command is executed
pub trait RunContext {
trait RunContext {
/// Get access to configuration
fn configuration(&self) -> &ClientConfiguration;

Expand Down Expand Up @@ -142,7 +142,7 @@ impl<W: std::io::Write> RunContext for PrintJsonContext<W> {
}

/// Runs subcommand
pub trait RunArgs {
trait RunArgs {
/// Runs command
///
/// # Errors
Expand Down Expand Up @@ -218,7 +218,7 @@ fn main() -> Result<()> {
/// # Errors
/// Fails if submitting over network fails
#[allow(clippy::shadow_unrelated)]
pub fn submit(
fn submit(
instructions: impl Into<Executable>,
metadata: UnlimitedMetadata,
context: &mut dyn RunContext,
Expand Down Expand Up @@ -307,7 +307,7 @@ mod events {
}
}

pub fn listen(filter: FilterBox, context: &mut dyn RunContext) -> Result<()> {
fn listen(filter: FilterBox, context: &mut dyn RunContext) -> Result<()> {
let iroha_client = Client::new(context.configuration())?;
eprintln!("Listening to events with filter: {filter:?}");
iroha_client
Expand Down Expand Up @@ -339,7 +339,7 @@ mod blocks {
}
}

pub fn listen(height: NonZeroU64, context: &mut dyn RunContext) -> Result<()> {
fn listen(height: NonZeroU64, context: &mut dyn RunContext) -> Result<()> {
let iroha_client = Client::new(context.configuration())?;
eprintln!("Listening to blocks from height: {height}");
iroha_client
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub mod model {

/// Query with parameters client can specify.
#[derive(
Debug, Constructor, Getters, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize,
Clone, Debug, PartialEq, Eq, Constructor, Getters, Encode, Decode, Serialize, Deserialize,
)]
#[getset(get = "pub")]
pub struct QueryWithParameters<Q> {
Expand Down
6 changes: 3 additions & 3 deletions tools/kagami/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) type Outcome = color_eyre::Result<()>;
// The reason for hard-coding this default is to ensure that the
// algorithm is matched to the public key in Ed25519 format. If
// you need to change either, you should definitely change both.
pub const DEFAULT_PUBLIC_KEY: &str =
const DEFAULT_PUBLIC_KEY: &str =
"ed01207233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0";

fn main() -> Outcome {
Expand All @@ -33,7 +33,7 @@ fn main() -> Outcome {
}

/// Trait to encapsulate common attributes of the commands and sub-commands.
pub trait RunArgs<T: Write> {
trait RunArgs<T: Write> {
/// Run the given command.
///
/// # Errors
Expand All @@ -45,7 +45,7 @@ pub trait RunArgs<T: Write> {
/// shipped with Iroha.
#[derive(Parser, Debug)]
#[command(name = "kagami", version, author)]
pub enum Args {
enum Args {
/// Generate cryptographic key pairs using the given algorithm and either private key or seed
Crypto(Box<crypto::Args>),
/// Generate the schema used for code generation in Iroha SDKs
Expand Down

0 comments on commit 8018332

Please sign in to comment.