-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Support automatic config version migration (#331)
near-cli will try to bump user's config version to the latest, including modifying/adding/removing fields
- Loading branch information
Showing
8 changed files
with
211 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use crate::config::Config as ConfigV2; | ||
use crate::config::NetworkConfig as NetworkConfigV2; | ||
|
||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
pub struct ConfigV1 { | ||
pub credentials_home_dir: std::path::PathBuf, | ||
pub network_connection: linked_hash_map::LinkedHashMap<String, NetworkConfigV1>, | ||
} | ||
|
||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
pub struct NetworkConfigV1 { | ||
pub network_name: String, | ||
pub rpc_url: url::Url, | ||
pub rpc_api_key: Option<crate::types::api_key::ApiKey>, | ||
pub wallet_url: url::Url, | ||
pub explorer_transaction_url: url::Url, | ||
// https://github.com/near/near-cli-rs/issues/116 | ||
pub linkdrop_account_id: Option<near_primitives::types::AccountId>, | ||
// https://docs.near.org/social/contract | ||
pub near_social_db_contract_account_id: Option<near_primitives::types::AccountId>, | ||
pub faucet_url: Option<url::Url>, | ||
pub meta_transaction_relayer_url: Option<url::Url>, | ||
} | ||
|
||
impl From<ConfigV1> for ConfigV2 { | ||
fn from(config: ConfigV1) -> Self { | ||
ConfigV2 { | ||
credentials_home_dir: config.credentials_home_dir, | ||
network_connection: config | ||
.network_connection | ||
.into_iter() | ||
.map(|(network_name, network_config)| (network_name, network_config.into())) | ||
.collect(), | ||
} | ||
} | ||
} | ||
|
||
impl From<NetworkConfigV1> for NetworkConfigV2 { | ||
fn from(network_config: NetworkConfigV1) -> Self { | ||
match network_config.network_name.as_str() { | ||
"mainnet" => NetworkConfigV2 { | ||
network_name: network_config.network_name, | ||
rpc_url: network_config.rpc_url, | ||
wallet_url: network_config.wallet_url, | ||
explorer_transaction_url: network_config.explorer_transaction_url, | ||
rpc_api_key: network_config.rpc_api_key, | ||
linkdrop_account_id: network_config.linkdrop_account_id, | ||
near_social_db_contract_account_id: network_config | ||
.near_social_db_contract_account_id, | ||
faucet_url: network_config.faucet_url, | ||
meta_transaction_relayer_url: network_config.meta_transaction_relayer_url, | ||
fastnear_url: Some(String::from("https://api.fastnear.com")), | ||
staking_pools_factory_account_id: Some("poolv1.near".parse().unwrap()), | ||
}, | ||
"testnet" => NetworkConfigV2 { | ||
network_name: network_config.network_name, | ||
rpc_url: network_config.rpc_url, | ||
wallet_url: network_config.wallet_url, | ||
explorer_transaction_url: network_config.explorer_transaction_url, | ||
rpc_api_key: network_config.rpc_api_key, | ||
linkdrop_account_id: network_config.linkdrop_account_id, | ||
near_social_db_contract_account_id: network_config | ||
.near_social_db_contract_account_id, | ||
faucet_url: network_config.faucet_url, | ||
meta_transaction_relayer_url: network_config.meta_transaction_relayer_url, | ||
fastnear_url: None, | ||
staking_pools_factory_account_id: Some("pool.f863973.m0".parse().unwrap()), | ||
}, | ||
_ => NetworkConfigV2 { | ||
network_name: network_config.network_name, | ||
rpc_url: network_config.rpc_url, | ||
wallet_url: network_config.wallet_url, | ||
explorer_transaction_url: network_config.explorer_transaction_url, | ||
rpc_api_key: network_config.rpc_api_key, | ||
linkdrop_account_id: network_config.linkdrop_account_id, | ||
near_social_db_contract_account_id: network_config | ||
.near_social_db_contract_account_id, | ||
faucet_url: network_config.faucet_url, | ||
meta_transaction_relayer_url: network_config.meta_transaction_relayer_url, | ||
fastnear_url: None, | ||
staking_pools_factory_account_id: None, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
#[derive(serde::Serialize, serde::Deserialize)] | ||
#[serde(tag = "version")] | ||
pub enum ConfigVersion { | ||
#[serde(rename = "1")] | ||
V1(ConfigV1), | ||
#[serde(rename = "2")] | ||
V2(ConfigV2), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters