diff --git a/sdk/src/wallet/core/builder.rs b/sdk/src/wallet/core/builder.rs index 31e2bba876..0ee6ff7718 100644 --- a/sdk/src/wallet/core/builder.rs +++ b/sdk/src/wallet/core/builder.rs @@ -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")] diff --git a/sdk/src/wallet/core/operations/storage.rs b/sdk/src/wallet/core/operations/storage.rs index d50b42e135..6ce659ca4e 100644 --- a/sdk/src/wallet/core/operations/storage.rs +++ b/sdk/src/wallet/core/operations/storage.rs @@ -52,18 +52,19 @@ mod storage_stub { storage: &impl StorageAdapter, ) -> crate::wallet::Result> { log::debug!("get_wallet_data"); - if let Some(data) = storage.get::(WALLET_INDEXATION_KEY).await? { - log::debug!("get_wallet_data {data:?}"); + let data = storage.get::(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()?, + ))) } } diff --git a/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs b/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs index 47815afa06..613beb0c44 100644 --- a/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs +++ b/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs @@ -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::{ @@ -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"; @@ -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.to_string().as_bytes()) .await?; diff --git a/sdk/src/wallet/migration/chrysalis.rs b/sdk/src/wallet/migration/chrysalis.rs index 222633f9ac..7ca0285d12 100644 --- a/sdk/src/wallet/migration/chrysalis.rs +++ b/sdk/src/wallet/migration/chrysalis.rs @@ -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, }, }, @@ -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::(&format!("{{ \"coinType\": {IOTA_COIN_TYPE}}}"))?, - ) - .await?; stardust_storage.set(SECRET_MANAGER_KEY, &secret_manager_dto).await?; } diff --git a/sdk/tests/wallet/chrysalis_migration.rs b/sdk/tests/wallet/chrysalis_migration.rs index 0885f02043..8ff3459eac 100644 --- a/sdk/tests/wallet/chrysalis_migration.rs +++ b/sdk/tests/wallet/chrysalis_migration.rs @@ -38,6 +38,7 @@ async fn migrate_chrysalis_db() -> Result<()> { let wallet = Wallet::builder() .with_storage_path("migrate_chrysalis_db") .with_client_options(client_options) + .with_coin_type(IOTA_COIN_TYPE) .finish() .await?; @@ -128,6 +129,7 @@ async fn migrate_chrysalis_db_encrypted() -> Result<()> { let wallet = Wallet::builder() .with_storage_path("migrate_chrysalis_db_encrypted") .with_client_options(client_options) + .with_coin_type(IOTA_COIN_TYPE) .finish() .await?; @@ -214,6 +216,7 @@ async fn migrate_chrysalis_db_encrypted_encrypt_new() -> Result<()> { .with_encryption_key([0u8; 32]), ) .with_client_options(client_options) + .with_coin_type(IOTA_COIN_TYPE) .finish() .await?; @@ -401,6 +404,7 @@ async fn migrate_chrysalis_db_ledger() -> Result<()> { let wallet = Wallet::builder() .with_storage_path("migrate_chrysalis_db_ledger") .with_client_options(client_options) + .with_coin_type(IOTA_COIN_TYPE) .finish() .await?;