From 3e0db34a985790998afdde16807b7d94102bba29 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 29 Sep 2022 11:09:04 +0200 Subject: [PATCH 1/6] Show which canister_ids file is being used --- src/dfx/src/lib/models/canister_id_store.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dfx/src/lib/models/canister_id_store.rs b/src/dfx/src/lib/models/canister_id_store.rs index 14f43a1a84..1ce98f82d3 100644 --- a/src/dfx/src/lib/models/canister_id_store.rs +++ b/src/dfx/src/lib/models/canister_id_store.rs @@ -177,6 +177,10 @@ impl CanisterIdStore { } self.save_ids() } + + pub fn path(&self) -> Option<&PathBuf> { + self.path.as_ref() + } } #[context("Failed to get remote ids.")] From e6b0484f5f33b7862ae44ecb2208af8a090a3ef2 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 29 Sep 2022 13:31:54 +0200 Subject: [PATCH 2/6] Leave that for now --- src/dfx/src/lib/models/canister_id_store.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/dfx/src/lib/models/canister_id_store.rs b/src/dfx/src/lib/models/canister_id_store.rs index 1ce98f82d3..14f43a1a84 100644 --- a/src/dfx/src/lib/models/canister_id_store.rs +++ b/src/dfx/src/lib/models/canister_id_store.rs @@ -177,10 +177,6 @@ impl CanisterIdStore { } self.save_ids() } - - pub fn path(&self) -> Option<&PathBuf> { - self.path.as_ref() - } } #[context("Failed to get remote ids.")] From 40cc2bf48f00461970e1f42b7c1d861daa688dcd Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 29 Sep 2022 13:56:43 +0200 Subject: [PATCH 3/6] Specify the candid file to use --- src/dfx/src/lib/sns/deploy.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/dfx/src/lib/sns/deploy.rs b/src/dfx/src/lib/sns/deploy.rs index dc251b416d..664eebdf5c 100644 --- a/src/dfx/src/lib/sns/deploy.rs +++ b/src/dfx/src/lib/sns/deploy.rs @@ -1,4 +1,5 @@ //! Code for creating an SNS. +use anyhow::bail; use fn_error_context::context; use std::ffi::OsString; use std::path::Path; @@ -10,10 +11,17 @@ use crate::Environment; /// Creates an SNS. This requires funds but no proposal. #[context("Failed to deploy SNS with config: {}", path.display())] pub fn deploy_sns(env: &dyn Environment, path: &Path) -> DfxResult { + let did_file = "candid/nns-sns-wasm.did"; + if !Path::new(did_file).exists() { + bail!("Missing did file at '{did_file}'. Please run 'dfx nns import' to get the file."); + } + let args = vec![ OsString::from("deploy"), OsString::from("--init-config-file"), OsString::from(path), + OsString::from("--candid"), + OsString::from(did_file), ]; call_sns_cli(env, &args).map(|stdout| format!("Deployed SNS: {}\n{}", path.display(), stdout)) } From 7cb026dc627e636525881c563e2e1bf716959ab7 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 29 Sep 2022 14:27:47 +0200 Subject: [PATCH 4/6] Add test --- e2e/tests-dfx/sns.bash | 5 +++++ src/dfx/src/commands/sns/deploy.rs | 2 +- src/dfx/src/lib/sns/deploy.rs | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/e2e/tests-dfx/sns.bash b/e2e/tests-dfx/sns.bash index 08417e8228..7cf574da47 100755 --- a/e2e/tests-dfx/sns.bash +++ b/e2e/tests-dfx/sns.bash @@ -76,4 +76,9 @@ SNS_CONFIG_FILE_NAME="sns.yml" install_asset sns/valid dfx sns config validate dfx sns deploy + # SNS canister IDs should be saved + dfx canister id sns_governance + dfx canister id sns_ledger + dfx canister id sns_root + dfx canister id sns_swap } diff --git a/src/dfx/src/commands/sns/deploy.rs b/src/dfx/src/commands/sns/deploy.rs index 3fd5764864..a8512f2f47 100644 --- a/src/dfx/src/commands/sns/deploy.rs +++ b/src/dfx/src/commands/sns/deploy.rs @@ -19,6 +19,6 @@ pub fn exec(env: &dyn Environment, _opts: DeployOpts) -> DfxResult { let config = env.get_config_or_anyhow()?; let path = config.get_project_root().join(sns::CONFIG_FILE_NAME); - deploy_sns(env, &path)?; + println!("{}", deploy_sns(env, &path)?); Ok(()) } diff --git a/src/dfx/src/lib/sns/deploy.rs b/src/dfx/src/lib/sns/deploy.rs index 664eebdf5c..192c827b97 100644 --- a/src/dfx/src/lib/sns/deploy.rs +++ b/src/dfx/src/lib/sns/deploy.rs @@ -11,17 +11,33 @@ use crate::Environment; /// Creates an SNS. This requires funds but no proposal. #[context("Failed to deploy SNS with config: {}", path.display())] pub fn deploy_sns(env: &dyn Environment, path: &Path) -> DfxResult { + // Note: It MAY be possible to get the did file location using existing sdk methods. let did_file = "candid/nns-sns-wasm.did"; if !Path::new(did_file).exists() { bail!("Missing did file at '{did_file}'. Please run 'dfx nns import' to get the file."); } + // Note: The --network flag is not available at the moment, + // so this always applies to local canister IDs. + // This will have to be expanded to cover deployments to + // mainnet quite soon. + let canister_ids_file = ".dfx/local/canister_ids.json"; + let args = vec![ OsString::from("deploy"), OsString::from("--init-config-file"), OsString::from(path), OsString::from("--candid"), OsString::from(did_file), + OsString::from("--save-to"), + OsString::from(canister_ids_file), ]; - call_sns_cli(env, &args).map(|stdout| format!("Deployed SNS: {}\n{}", path.display(), stdout)) + call_sns_cli(env, &args).map(|stdout| { + format!( + "Deployed SNS:\nSNS config: {}\nCanister ID file: {}\n\n{}", + path.display(), + canister_ids_file, + stdout + ) + }) } From 7f28fdef648390d7c1744881df8f681c5706eff3 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 29 Sep 2022 15:00:04 +0200 Subject: [PATCH 5/6] Tell the user what we are doing and to be patient --- src/dfx/src/commands/sns/deploy.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dfx/src/commands/sns/deploy.rs b/src/dfx/src/commands/sns/deploy.rs index a8512f2f47..657b7c7496 100644 --- a/src/dfx/src/commands/sns/deploy.rs +++ b/src/dfx/src/commands/sns/deploy.rs @@ -16,6 +16,7 @@ pub struct DeployOpts {} /// Executes the command line `dfx sns deploy`. pub fn exec(env: &dyn Environment, _opts: DeployOpts) -> DfxResult { + println!("Creating SNS canisters. This typically takes about one minute..."); let config = env.get_config_or_anyhow()?; let path = config.get_project_root().join(sns::CONFIG_FILE_NAME); From 9a8de9c7e140fb548dfa268babe27e2d5b339868 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 10 Oct 2022 14:10:37 +0200 Subject: [PATCH 6/6] ++ --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75feea1e46..551d4a36bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## DFX +### fix: Save SNS canister IDs + +SNS canister IDs were not being parsed reliably. Now the candid file is being specified explicitly, which resolves the issue in at least some cases. + ### feat: NNS usability improvements The command line interface for nns commands has been updated to: