Skip to content

Commit

Permalink
bugfix: fixed migration. Added migration saving to be more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Dec 25, 2024
1 parent 366c3ee commit 1379da7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/config/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<ConfigV2> for ConfigV3 {
.network_connection
.into_iter()
.map(|(network_name, mut network_config)| {
if network_name == "testnet" && network_config.faucet_url.is_none() {
if network_name == "testnet" && network_config.fastnear_url.is_none() {
network_config.fastnear_url =
Some("https://test.api.fastnear.com/".parse().unwrap());
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl From<NetworkConfigV1> for NetworkConfigV2 {
}
}

#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[serde(tag = "version")]
pub enum ConfigVersion {
#[serde(rename = "1")]
Expand Down
14 changes: 12 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Default for Config {
near_social_db_contract_account_id: Some("v1.social08.testnet".parse().unwrap()),
faucet_url: Some("https://helper.nearprotocol.com/account".parse().unwrap()),
meta_transaction_relayer_url: None,
fastnear_url: None,
fastnear_url: Some("https://test.api.fastnear.com/".parse().unwrap()),
staking_pools_factory_account_id: Some("pool.f863973.m0".parse().unwrap()),
coingecko_url: None,
},
Expand Down Expand Up @@ -99,7 +99,17 @@ impl Config {
}
})?;

Ok(config_version.into())
let config = match config_version {
migrations::ConfigVersion::V3(config) => config,
_ => {
eprintln!("Migrating config.toml to the latest version...");
let config: Config = config_version.into();
Self::write_config_toml(config.clone())?;
config
}
};

Ok(config)
} else {
Ok(crate::config::Config::default())
}
Expand Down

0 comments on commit 1379da7

Please sign in to comment.