Skip to content

Commit

Permalink
[refactor] hyperledger-iroha#4063: use DTO naming
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Balashov <[email protected]>
  • Loading branch information
0x009922 committed Dec 5, 2023
1 parent 0849e4b commit 4ea1549
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use eyre::{eyre, WrapErr};
use futures::TryStreamExt;
use iroha_config::{client_api::ConfigurationSubset, iroha::Configuration, torii::uri};
use iroha_config::{client_api::ConfigurationDTO, iroha::Configuration, torii::uri};
use iroha_core::{
query::{pagination::Paginate, store::LiveQueryStoreHandle},
smartcontracts::query::ValidQueryRequest,
Expand Down Expand Up @@ -165,14 +165,14 @@ async fn handle_pending_transactions(

#[iroha_futures::telemetry_future]
async fn handle_get_configuration(iroha_cfg: Configuration) -> Result<Json> {
let subset = ConfigurationSubset::from(&iroha_cfg);
let subset = ConfigurationDTO::from(&iroha_cfg);
Ok(reply::json(&subset))
}

#[iroha_futures::telemetry_future]
async fn handle_post_configuration(
iroha_cfg: Configuration,
value: ConfigurationSubset,
value: ConfigurationDTO,
) -> Result<impl Reply> {
value.update_base(&iroha_cfg)?;
Ok(reply::reply())
Expand Down
9 changes: 4 additions & 5 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use derive_more::{DebugCustom, Display};
use eyre::{eyre, Result, WrapErr};
use futures_util::StreamExt;
use http_default::{AsyncWebSocketStream, WebSocketStream};
use iroha_config::{client::Configuration, client_api::ConfigurationSubset, torii::uri};
use iroha_config::{client::Configuration, client_api::ConfigurationDTO, torii::uri};
use iroha_crypto::{HashOf, KeyPair};
use iroha_logger::prelude::*;
use iroha_telemetry::metrics::Status;
Expand Down Expand Up @@ -1076,7 +1076,7 @@ impl Client {
///
/// # Errors
/// Fails if sending request or decoding fails
pub fn get_config(&self) -> Result<ConfigurationSubset> {
pub fn get_config(&self) -> Result<ConfigurationDTO> {
let resp = DefaultRequestBuilder::new(
HttpMethod::GET,
self.torii_url.join(uri::CONFIGURATION).expect("Valid URI"),
Expand All @@ -1099,9 +1099,8 @@ impl Client {
///
/// # Errors
/// If sending request or decoding fails
pub fn set_config(&self, config: ConfigurationSubset) -> Result<bool> {
let body =
serde_json::to_vec(&config).wrap_err(format!("Failed to serialize {config:?}"))?;
pub fn set_config(&self, dto: ConfigurationDTO) -> Result<bool> {
let body = serde_json::to_vec(&dto).wrap_err(format!("Failed to serialize {dto:?}"))?;
let url = self.torii_url.join(uri::CONFIGURATION).expect("Valid URI");
let resp = DefaultRequestBuilder::new(HttpMethod::POST, url)
.header(http::header::CONTENT_TYPE, APPLICATION_JSON)
Expand Down
12 changes: 6 additions & 6 deletions config/src/client_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//!
//! Intended usage:
//!
//! - Create [`Root`] from [`crate::iroha::Configuration`] and serialize it for the client
//! - Deserialize [`Root`] from the client and use [`Root::apply_update()`] to update the configuration
//! - Create [`ConfigurationDTO`] from [`crate::iroha::Configuration`] and serialize it for the client
//! - Deserialize [`ConfigurationDTO`] from the client and use [`ConfigurationDTO::apply_update()`] to update the configuration
// TODO: Currently logic here is not generalised and handles only `logger.max_log_level` parameter. In future, when
// other parts of configuration are refactored and there is a solid foundation e.g. as a general
// configuration-related crate, this part should be re-written in a clean way.
Expand All @@ -17,19 +17,19 @@ use super::{iroha::Configuration as BaseConfiguration, logger::Configuration as

/// Subset of [`super::iroha`] configuration.
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub struct ConfigurationSubset {
pub struct ConfigurationDTO {
logger: Logger,
}

impl From<&'_ BaseConfiguration> for ConfigurationSubset {
impl From<&'_ BaseConfiguration> for ConfigurationDTO {
fn from(value: &'_ BaseConfiguration) -> Self {
Self {
logger: value.logger.as_ref().into(),
}
}
}

impl ConfigurationSubset {
impl ConfigurationDTO {
/// Update the base configuration with the values stored in [`Self`].
pub fn update_base(&self, target: &BaseConfiguration) -> Result<(), ReloadError> {
target
Expand Down Expand Up @@ -60,7 +60,7 @@ mod test {

#[test]
fn snapshot_serialized_form() {
let value = ConfigurationSubset {
let value = ConfigurationDTO {
logger: Logger {
max_log_level: Level::TRACE,
},
Expand Down

0 comments on commit 4ea1549

Please sign in to comment.