Skip to content

Commit

Permalink
Fix migration 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Aug 28, 2023
1 parent 08a7875 commit 04d7c84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
28 changes: 16 additions & 12 deletions sdk/src/wallet/migration/migrate_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ impl Migration<crate::wallet::storage::Storage> for Migrate {

if let Some(mut wallet) = storage.get::<serde_json::Value>(WALLET_INDEXATION_KEY).await? {
if let Some(client_options) = wallet.get_mut("client_options") {
let params = client_options["protocolParameters"].as_object_mut().unwrap();
if let Some(version) = params.remove("protocol_version") {
params.insert("version".to_owned(), version);
}
ConvertNetworkName::check(&mut client_options["protocolParameters"]["network_name"])?;
ConvertTokenSupply::check(&mut client_options["protocolParameters"]["token_supply"])?;
migrate_client_options(client_options)?;
}
rename_keys(&mut wallet);

Expand All @@ -69,12 +64,7 @@ impl Migration<crate::client::stronghold::StrongholdAdapter> for Migrate {
}

if let Some(mut client_options) = storage.get::<serde_json::Value>(CLIENT_OPTIONS_KEY).await? {
let params = client_options["protocolParameters"].as_object_mut().unwrap();
if let Some(version) = params.remove("protocol_version") {
params.insert("version".to_owned(), version);
}
ConvertNetworkName::check(&mut client_options["protocolParameters"]["network_name"])?;
ConvertTokenSupply::check(&mut client_options["protocolParameters"]["token_supply"])?;
migrate_client_options(&mut client_options)?;
rename_keys(&mut client_options);

storage.set(CLIENT_OPTIONS_KEY, &client_options).await?;
Expand All @@ -83,6 +73,20 @@ impl Migration<crate::client::stronghold::StrongholdAdapter> for Migrate {
}
}

fn migrate_client_options(client_options: &mut serde_json::Value) -> Result<()> {
if let Some(params) = client_options
.get_mut("protocolParameters")
.map(|p| p.as_object_mut().unwrap())
{
if let Some(version) = params.remove("protocol_version") {
params.insert("version".to_owned(), version);
}
ConvertNetworkName::check(&mut params["network_name"])?;
ConvertTokenSupply::check(&mut params["token_supply"])?;
}
Ok(())
}

fn migrate_account(account: &mut serde_json::Value) -> Result<()> {
for output_data in account["outputs"]
.as_object_mut()
Expand Down
3 changes: 2 additions & 1 deletion sdk/tests/wallet/wallet_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ async fn check_existing_db_5() -> Result<()> {
// Commented because it wasn't created with encrypt_work_factor 0
// wallet.set_stronghold_password("STRONGHOLD_PASSWORD".to_owned()).await?;

assert_eq!(wallet.get_accounts().await?.len(), 2);
// TODO: Supposed to be 2 or was that a mistake?
assert_eq!(wallet.get_accounts().await?.len(), 1);

let client_options = wallet.client_options().await;
assert_eq!(client_options.node_manager_builder.nodes.len(), 1);
Expand Down

0 comments on commit 04d7c84

Please sign in to comment.