Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up storage constant usage #1341

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.to_string().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, &secret_manager_dto).await?;
}

Expand Down
4 changes: 4 additions & 0 deletions sdk/tests/wallet/chrysalis_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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?;

Expand Down
Loading