Skip to content

Commit

Permalink
refactor: avoid using block_on when we already have an async runtime (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop authored Sep 12, 2024
1 parent 079889d commit 0739cd5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 2 additions & 0 deletions extensions/sns/e2e/tests/sns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ SNS_CONFIG_FILE_NAME="sns_init.yaml"
dfx nns install
echo "===== 7 ====="
dfx nns import
echo "===== 8 ====="
dfx sns import
echo "===== 9 ====="
ls candid
echo "===== 10 ====="
Expand Down
5 changes: 2 additions & 3 deletions extensions/sns/src/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ pub struct SnsDownloadOpts {
}

/// Executes the command line `dfx sns import`.
pub fn exec(opts: SnsDownloadOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
let runtime = Runtime::new().expect("Unable to create a runtime");
pub async fn exec(opts: SnsDownloadOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
let ic_commit = if let Some(ic_commit) = opts.ic_commit {
ic_commit
} else {
replica_rev(dfx_cache_path)?
};
runtime.block_on(download_sns_wasms(&ic_commit, &opts.wasms_dir))?;
download_sns_wasms(&ic_commit, &opts.wasms_dir).await?;
Ok(())
}
9 changes: 4 additions & 5 deletions extensions/sns/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use dfx_extensions_utils::{
};

use clap::Parser;
use tokio::runtime::Runtime;

/// Imports the sns canisters
#[derive(Parser)]
Expand All @@ -23,7 +22,7 @@ pub struct SnsImportOpts {
}

/// Executes the command line `dfx sns import`.
pub fn exec(opts: SnsImportOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
pub async fn exec(opts: SnsImportOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {
let config = Config::from_current_dir(None)?;
if config.is_none() {
anyhow::bail!(crate::errors::DFXJSON_NOT_FOUND);
Expand All @@ -33,21 +32,21 @@ pub fn exec(opts: SnsImportOpts, dfx_cache_path: &Path) -> anyhow::Result<()> {

let network_mappings = get_network_mappings(&opts.network_mapping)?;

let runtime = Runtime::new().expect("Unable to create a runtime");
let ic_commit = if let Ok(v) = std::env::var("DFX_IC_COMMIT") {
v
} else {
replica_rev(dfx_cache_path)?
};
let their_dfx_json_location =
format!("https://raw.githubusercontent.com/dfinity/ic/{ic_commit}/rs/sns/cli/dfx.json");
runtime.block_on(import_canister_definitions(
import_canister_definitions(
&logger,
&mut config,
&their_dfx_json_location,
None,
None,
&network_mappings,
))?;
)
.await?;
Ok(())
}
4 changes: 2 additions & 2 deletions extensions/sns/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ async fn main() -> anyhow::Result<()> {
"Missing path to dfx cache. Pass it as CLI argument: `--dfx-cache-path=PATH`",
)
})?;
return commands::import::exec(v, dfx_cache_path);
return commands::import::exec(v, dfx_cache_path).await;
}
SubCommand::Download(v) => {
let dfx_cache_path = &opts.dfx_cache_path.ok_or_else(|| {
anyhow::Error::msg(
"Missing path to dfx cache. Pass it as CLI argument: `--dfx-cache-path=PATH`",
)
})?;
return commands::download::exec(v, dfx_cache_path);
return commands::download::exec(v, dfx_cache_path).await;
}
};

Expand Down

0 comments on commit 0739cd5

Please sign in to comment.