From 1379da74790bd63f1a5b3d9e0e2eadaae91116cc Mon Sep 17 00:00:00 2001 From: akorchyn Date: Wed, 25 Dec 2024 16:27:23 +0200 Subject: [PATCH 1/3] bugfix: fixed migration. Added migration saving to be more clear --- src/config/migrations.rs | 4 ++-- src/config/mod.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config/migrations.rs b/src/config/migrations.rs index 914c2e27..7574c1ed 100644 --- a/src/config/migrations.rs +++ b/src/config/migrations.rs @@ -49,7 +49,7 @@ impl From 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()); } @@ -112,7 +112,7 @@ impl From for NetworkConfigV2 { } } -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(serde::Serialize, serde::Deserialize, Debug)] #[serde(tag = "version")] pub enum ConfigVersion { #[serde(rename = "1")] diff --git a/src/config/mod.rs b/src/config/mod.rs index b652305a..48b9f537 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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, }, @@ -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()) } From f5bae233f7f77d0d627a4237403e4f5970ef9f3e Mon Sep 17 00:00:00 2001 From: akorchyn Date: Mon, 13 Jan 2025 13:27:57 +0200 Subject: [PATCH 2/3] review --- src/config/migrations.rs | 10 ++++++++++ src/config/mod.rs | 17 ++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/config/migrations.rs b/src/config/migrations.rs index 7574c1ed..12719c4a 100644 --- a/src/config/migrations.rs +++ b/src/config/migrations.rs @@ -123,3 +123,13 @@ pub enum ConfigVersion { #[serde(rename = "3")] V3(ConfigV3), } + +impl ConfigVersion { + pub fn is_latest_version(&self) -> bool { + // Used match instead of matches! to compile fail if new version is added + match self { + ConfigVersion::V3(_) => true, + ConfigVersion::V2(_) | ConfigVersion::V1(_) => false, + } + } +} diff --git a/src/config/mod.rs b/src/config/mod.rs index 48b9f537..b8ae7049 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -99,15 +99,12 @@ impl Config { } })?; - 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 - } - }; + let is_latest_version = config_version.is_latest_version(); + let config: Config = config_version.into(); + + if !is_latest_version { + Self::write_config_toml(config.clone())?; + } Ok(config) } else { @@ -200,9 +197,11 @@ impl From for Config { loop { config_version = match config_version { migrations::ConfigVersion::V1(config_v1) => { + eprintln!("Migrating config.toml from V1 to V2..."); migrations::ConfigVersion::V2(config_v1.into()) } migrations::ConfigVersion::V2(config_v2) => { + eprintln!("Migrating config.toml from V2 to V3..."); migrations::ConfigVersion::V3(config_v2.into()) } migrations::ConfigVersion::V3(config_v3) => { From 74e1d2b97c9aaecae3b7ce8d075b4d96bd3c645a Mon Sep 17 00:00:00 2001 From: akorchyn Date: Mon, 13 Jan 2025 13:46:58 +0200 Subject: [PATCH 3/3] clippy --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index 8f817ed3..1d3636e2 100644 --- a/src/common.rs +++ b/src/common.rs @@ -2065,7 +2065,7 @@ pub fn input_network_name( network_config .linkdrop_account_id .as_ref() - .map_or(false, |linkdrop_account_id| { + .is_some_and(|linkdrop_account_id| { account_ids.iter().any(|account_id| { account_id.as_str().ends_with(linkdrop_account_id.as_str()) })