diff --git a/client/src/client.rs b/client/src/client.rs index f0d2d11181e..19a7b7574ff 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -390,8 +390,8 @@ impl QueryRequest { match self.request { iroha_data_model::query::QueryRequest::Query(query_with_params) => builder - .params(Vec::from(query_with_params.sorting().clone())) - .params(Vec::from(*query_with_params.pagination())) + .params(query_with_params.sorting().clone().into_query_parameters()) + .params(query_with_params.pagination().into_query_parameters()) .body(query_with_params.query().clone()), iroha_data_model::query::QueryRequest::Cursor(cursor) => { builder.params(Vec::from(cursor)) @@ -972,7 +972,7 @@ impl Client { retry_in: Duration, pagination: Pagination, ) -> Result> { - let pagination: Vec<_> = pagination.into(); + let pagination = pagination.into_query_parameters(); for _ in 0..retry_count { let response = DefaultRequestBuilder::new( HttpMethod::GET, @@ -980,7 +980,7 @@ impl Client { .join(uri::PENDING_TRANSACTIONS) .expect("Valid URI"), ) - .params(pagination.clone()) + .params(&pagination) .headers(self.headers.clone()) .build()? .send()?; diff --git a/data_model/src/query/pagination.rs b/data_model/src/query/pagination.rs index f93a1dadc25..970c07ddf5e 100644 --- a/data_model/src/query/pagination.rs +++ b/data_model/src/query/pagination.rs @@ -38,9 +38,12 @@ pub struct Pagination { pub start: Option, } -impl From for Vec<(&'static str, NonZeroU64)> { - fn from(pagination: Pagination) -> Self { - match (pagination.start, pagination.limit) { +impl Pagination { + /// Converts self to Vec of tuples to be used in queries + /// + /// The length of the output Vec is not constant and it's in (0..3) + pub fn into_query_parameters(self) -> Vec<(&'static str, NonZeroU64)> { + match (self.start, self.limit) { (Some(start), Some(limit)) => { vec![(PAGINATION_LIMIT, limit.into()), (PAGINATION_START, start)] } diff --git a/data_model/src/query/sorting.rs b/data_model/src/query/sorting.rs index 015aeb3f34d..850f10e4199 100644 --- a/data_model/src/query/sorting.rs +++ b/data_model/src/query/sorting.rs @@ -38,13 +38,13 @@ impl Sorting { } } -impl From for Vec<(&'static str, Name)> { - fn from(sorting: Sorting) -> Self { - if let Some(key) = sorting.sort_by_metadata_key { - return vec![(SORT_BY_KEY, key)]; - } - - Vec::new() +impl Sorting { + /// Converts self to Vec of tuples to be used in queries + /// + /// The length of the output Vec is not constant and it's in (0..3) + pub fn into_query_parameters(self) -> Vec<(&'static str, Name)> { + self.sort_by_metadata_key + .map_or(Vec::new(), |key| vec![(SORT_BY_KEY, key)]) } }