Skip to content

Commit

Permalink
clean up storage constant usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Sep 27, 2023
1 parent d4e7d66 commit 9a0557d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
2 changes: 1 addition & 1 deletion sdk/src/wallet/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ pub(crate) mod dto {
#[cfg(feature = "storage")]
use crate::{client::secret::SecretManage, wallet::storage::StorageOptions};

#[derive(Debug, Deserialize)]
#[derive(Default, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WalletBuilderDto {
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
19 changes: 10 additions & 9 deletions sdk/src/wallet/core/operations/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ mod storage_stub {
storage: &impl StorageAdapter<Error = crate::wallet::Error>,
) -> crate::wallet::Result<Option<Self>> {
log::debug!("get_wallet_data");
if let Some(data) = storage.get::<WalletBuilderDto>(WALLET_INDEXATION_KEY).await? {
log::debug!("get_wallet_data {data:?}");
let data = storage.get::<WalletBuilderDto>(WALLET_INDEXATION_KEY).await?;
log::debug!("get_wallet_data {data:?}");

let secret_manager_dto = storage.get(SECRET_MANAGER_KEY).await?;
log::debug!("get_secret_manager {secret_manager_dto:?}");
let secret_manager_dto = storage.get(SECRET_MANAGER_KEY).await?;
log::debug!("get_secret_manager {secret_manager_dto:?}");

Ok(Some(Self::from(data).with_secret_manager(
secret_manager_dto.map(|dto| S::from_config(&dto)).transpose()?,
)))
} else {
Ok(None)
if data.is_none() && secret_manager_dto.is_none() {
return Ok(None);
}

Ok(Some(Self::from(data.unwrap_or_default()).with_secret_manager(
secret_manager_dto.map(|dto| S::from_config(&dto)).transpose()?,
)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use std::{collections::HashMap, path::Path, sync::atomic::Ordering};

use crate::{
client::{
constants::IOTA_COIN_TYPE, secret::SecretManagerConfig, storage::StorageAdapter, stronghold::StrongholdAdapter,
Error as ClientError,
secret::SecretManagerConfig, storage::StorageAdapter, stronghold::StrongholdAdapter, Error as ClientError,
},
types::TryFromDto,
wallet::{
Expand All @@ -19,7 +18,6 @@ use crate::{
},
};

pub(crate) const WALLET_INDEXATION_KEY: &str = "iota-wallet-account-manager";
pub(crate) const CLIENT_OPTIONS_KEY: &str = "client_options";
pub(crate) const COIN_TYPE_KEY: &str = "coin_type";
pub(crate) const SECRET_MANAGER_KEY: &str = "secret_manager";
Expand Down Expand Up @@ -176,13 +174,6 @@ pub(crate) async fn migrate_snapshot_from_chrysalis_to_stardust(
.await?;

if let Some(secret_manager_dto) = secret_manager_dto {
// This is required for the secret manager to be loaded
stronghold_adapter
.set(
WALLET_INDEXATION_KEY,
format!("{{ \"coinType\": {IOTA_COIN_TYPE}}}").as_bytes(),
)
.await?;
stronghold_adapter
.set_bytes(SECRET_MANAGER_KEY, secret_manager_dto.as_bytes())
.await?;
Expand Down
11 changes: 1 addition & 10 deletions sdk/src/wallet/migration/chrysalis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ pub(crate) mod rocksdb {
wallet::{
migration::{MigrationData, MIGRATION_VERSION_KEY},
storage::{
constants::{
ACCOUNTS_INDEXATION_KEY, ACCOUNT_INDEXATION_KEY, SECRET_MANAGER_KEY, WALLET_INDEXATION_KEY,
},
constants::{ACCOUNTS_INDEXATION_KEY, ACCOUNT_INDEXATION_KEY, SECRET_MANAGER_KEY},
StorageManager,
},
},
Expand Down Expand Up @@ -281,13 +279,6 @@ pub(crate) mod rocksdb {
}

if let Some(secret_manager_dto) = secret_manager_dto {
// This is required for the secret manager to be loaded
stardust_storage
.set(
WALLET_INDEXATION_KEY,
&serde_json::from_str::<Value>(&format!("{{ \"coinType\": {IOTA_COIN_TYPE}}}"))?,
)
.await?;
stardust_storage
.set(SECRET_MANAGER_KEY, &serde_json::from_str::<Value>(&secret_manager_dto)?)
.await?;
Expand Down

0 comments on commit 9a0557d

Please sign in to comment.