Skip to content

Commit

Permalink
small improvements and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Jul 18, 2023
1 parent 7014dcc commit 3079f05
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 deletions.
6 changes: 5 additions & 1 deletion sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Migrated storage types field casing to uniform camelCase;
- Removed inappropriate serde impls from `AccountDetails` and `WalletBuilder`, and added fn impls for conversion;
- Replaced inappropriate serde impls from `AccountDetails` and `WalletBuilder` with fn impls for conversion;

### Removed

- `ProtocolParametersDto`, `NetworkInfoDto`, `OutputMetadataDto` in favor of base types;

### Fixed

Expand Down
1 change: 1 addition & 0 deletions sdk/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl ClientBuilder {

/// Struct containing network and PoW related information
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkInfo {
/// Protocol parameters.
#[serde(default)]
Expand Down
32 changes: 6 additions & 26 deletions sdk/src/wallet/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::{
use std::{collections::HashSet, sync::atomic::Ordering};

use futures::{future::try_join_all, FutureExt};
use serde::Serialize;
use tokio::sync::RwLock;

use super::operations::storage::SaveLoadWallet;
Expand All @@ -27,12 +28,14 @@ use crate::{
};

/// Builder for the wallet.
#[derive(Debug)]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WalletBuilder<S: SecretManage = SecretManager> {
pub(crate) client_options: Option<ClientOptions>,
pub(crate) coin_type: Option<u32>,
#[cfg(feature = "storage")]
pub(crate) storage_options: Option<StorageOptions>,
#[serde(skip)]
pub(crate) secret_manager: Option<Arc<RwLock<S>>>,
}

Expand Down Expand Up @@ -282,12 +285,12 @@ fn unlock_unused_inputs(accounts: &mut [AccountDetails]) -> crate::wallet::Resul
}

pub mod dto {
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use super::*;
use crate::{client::secret::SecretManage, wallet::storage::StorageOptions};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WalletBuilderDto {
pub(crate) client_options: Option<ClientOptions>,
Expand All @@ -296,29 +299,6 @@ pub mod dto {
pub(crate) storage_options: Option<StorageOptions>,
}

// TODO: This duplication can be streamlined using Borrowed or Owned enum
impl<S: SecretManage> From<&WalletBuilder<S>> for WalletBuilderDto {
fn from(value: &WalletBuilder<S>) -> Self {
Self {
client_options: value.client_options.clone(),
coin_type: value.coin_type,
#[cfg(feature = "storage")]
storage_options: value.storage_options.clone(),
}
}
}

impl<S: SecretManage> From<WalletBuilder<S>> for WalletBuilderDto {
fn from(value: WalletBuilder<S>) -> Self {
Self {
client_options: value.client_options,
coin_type: value.coin_type,
#[cfg(feature = "storage")]
storage_options: value.storage_options,
}
}
}

impl WalletBuilderDto {
pub(crate) fn into_builder<S: SecretManage>(self, secret_manager: Option<S>) -> WalletBuilder<S> {
WalletBuilder {
Expand Down
8 changes: 2 additions & 6 deletions sdk/src/wallet/core/operations/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ mod storage_stub {
{
async fn save(&self, storage: &impl StorageAdapter<Error = crate::wallet::Error>) -> crate::wallet::Result<()> {
log::debug!("save_wallet_data");
storage
.set(WALLET_INDEXATION_KEY, &WalletBuilderDto::from(self))
.await?;
storage.set(WALLET_INDEXATION_KEY, self).await?;

if let Some(secret_manager) = &self.secret_manager {
let secret_manager = secret_manager.read().await;
Expand Down Expand Up @@ -73,9 +71,7 @@ mod storage_stub {
impl SaveLoadWallet for WalletBuilder<MnemonicSecretManager> {
async fn save(&self, storage: &impl StorageAdapter<Error = crate::wallet::Error>) -> crate::wallet::Result<()> {
log::debug!("save_wallet_data");
storage
.set(WALLET_INDEXATION_KEY, &WalletBuilderDto::from(self))
.await?;
storage.set(WALLET_INDEXATION_KEY, self).await?;
Ok(())
}

Expand Down

0 comments on commit 3079f05

Please sign in to comment.