Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 205 additions & 141 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ members = [
]

[patch.crates-io]
ic-types = { git = "ssh://git@github.com/dfinity-lab/agent-rust.git", branch = "next", version = "0.1.1" }
ic-types = { git = "ssh://git@github.com/p-shahi/agent-rs.git", branch = "pshahi/setcontroller", version = "0.1.1" }
20 changes: 13 additions & 7 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ chrono = "0.4.9"
clap = "2.33.0"
console = "0.7.7"
crossbeam = "0.7.3"
delay = "0.2.0"
delay = "0.3.0"
dialoguer = "0.6.2"
erased-serde = "0.3.10"
flate2 = "1.0.11"
Expand Down Expand Up @@ -68,15 +68,21 @@ wasmparser = "0.45.0"

[dependencies.ic-agent]
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "9d611f08cb55923fc6ff5bf0136e8f4b848dd2cc"
git = "ssh://git@github.com/p-shahi/agent-rs.git"
branch = "pshahi/setcontroller"
rev = "3ed014da213d9119997a1735f4808a0bb2b9782a"

[dependencies.ic-types]
version = "0.1.1"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "9d611f08cb55923fc6ff5bf0136e8f4b848dd2cc"
git = "ssh://git@github.com/p-shahi/agent-rs.git"
branch = "pshahi/setcontroller"
rev = "3ed014da213d9119997a1735f4808a0bb2b9782a"

[dependencies.ic-utils]
version = "0.1.0"
git = "ssh://git@github.com/p-shahi/agent-rs.git"
branch = "pshahi/setcontroller"
rev = "3ed014da213d9119997a1735f4808a0bb2b9782a"


[dev-dependencies]
Expand Down
8 changes: 6 additions & 2 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
let timeout = expiry_duration();

if is_query {
let blob =
runtime.block_on(agent.query_raw(&canister_id, method_name, &arg_value, None))?;
let blob = runtime.block_on(
agent
.query(&canister_id, method_name)
.with_arg(&arg_value)
.call(),
)?;
print_idl_blob(&blob, output_type, &method_type)
.map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?;
} else if args.is_present("async") {
Expand Down
12 changes: 7 additions & 5 deletions src/dfx/src/commands/canister/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::lib::waiter::waiter_with_timeout;
use crate::util::expiry_duration;

use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{Agent, ManagementCanister};
use ic_agent::Agent;
use ic_utils::call::AsyncCall;
use ic_utils::interfaces::ManagementCanister;
use slog::info;
use std::time::Duration;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -36,7 +38,7 @@ async fn delete_canister(
canister_name: &str,
timeout: Duration,
) -> DfxResult {
let mgr = ManagementCanister::new(agent);
let mgr = ManagementCanister::create(agent);
let log = env.get_logger();
let mut canister_id_store = CanisterIdStore::for_env(env)?;
let canister_id = canister_id_store.get(canister_name)?;
Expand All @@ -47,9 +49,9 @@ async fn delete_canister(
canister_id.to_text(),
);

mgr.delete_canister(waiter_with_timeout(timeout), &canister_id)
.await
.map_err(DfxError::from)?;
mgr.delete_canister(&canister_id)
.call_and_wait(waiter_with_timeout(timeout))
.await?;

canister_id_store.remove(canister_name)?;

Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::util::{blob_from_arguments, expiry_duration, get_candid_init_type};

use clap::{App, Arg, ArgMatches, SubCommand};
use humanize_rs::bytes::{Bytes, Unit};
use ic_agent::{ComputeAllocation, InstallMode, MemoryAllocation};

use ic_utils::interfaces::management_canister::{ComputeAllocation, InstallMode, MemoryAllocation};
use std::convert::TryFrom;
use std::str::FromStr;
use tokio::runtime::Runtime;
Expand Down
2 changes: 2 additions & 0 deletions src/dfx/src/commands/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod delete;
mod id;
mod install;
mod request_status;
mod set_controller;
mod start;
mod status;
mod stop;
Expand All @@ -23,6 +24,7 @@ fn builtins() -> Vec<CliCommand> {
CliCommand::new(id::construct(), id::exec),
CliCommand::new(install::construct(), install::exec),
CliCommand::new(request_status::construct(), request_status::exec),
CliCommand::new(set_controller::construct(), set_controller::exec),
CliCommand::new(start::construct(), start::exec),
CliCommand::new(status::construct(), status::exec),
CliCommand::new(stop::construct(), stop::exec),
Expand Down
3 changes: 2 additions & 1 deletion src/dfx/src/commands/canister/request_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::util::clap::validators;
use crate::util::{expiry_duration, print_idl_blob};
use clap::{App, Arg, ArgMatches, SubCommand};
use delay::Waiter;
use ic_agent::{AgentError, Replied, RequestId, RequestStatusResponse};
use ic_agent::agent::{Replied, RequestStatusResponse};
use ic_agent::{AgentError, RequestId};
use std::str::FromStr;
use tokio::runtime::Runtime;

Expand Down
63 changes: 63 additions & 0 deletions src/dfx/src/commands/canister/set_controller.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use crate::lib::environment::Environment;
use crate::lib::error::{DfxError, DfxResult};
use crate::lib::identity::identity_manager::IdentityManager;
use crate::lib::message::UserMessage;
use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::lib::waiter::waiter_with_timeout;
use crate::util::expiry_duration;
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::Identity;
use ic_types::principal::Principal as CanisterId;
use ic_utils::call::AsyncCall;
use ic_utils::interfaces::ManagementCanister;
use tokio::runtime::Runtime;

pub fn construct() -> App<'static, 'static> {
SubCommand::with_name("set-controller")
.about(UserMessage::SetController.to_str())
.arg(
Arg::with_name("canister")
.takes_value(true)
.help(UserMessage::SetControllerCanister.to_str())
.long("canister")
.required(true),
)
.arg(
Arg::with_name("new-controller")
.takes_value(true)
.help(UserMessage::NewController.to_str())
.long("new-controller")
.required(true),
)
}

pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
let canister = args.value_of("canister").unwrap();
let canister_id = match CanisterId::from_text(canister) {
Ok(id) => id,
Err(_) => CanisterIdStore::for_env(env)?.get(canister)?,
};

let new_controller = args.value_of("new-controller").unwrap();
let controller_principal = match CanisterId::from_text(new_controller) {
Ok(principal) => principal,
Err(_) => IdentityManager::new(env)?
.instantiate_identity_from_name(new_controller)?
.sender()?,
};

let timeout = expiry_duration();

let mgr = ManagementCanister::create(
env.get_agent()
.ok_or(DfxError::CommandMustBeRunInAProject)?,
);

let mut runtime = Runtime::new().expect("Unable to create a runtime");
runtime.block_on(
mgr.set_controller(&canister_id, &controller_principal)
.call_and_wait(waiter_with_timeout(timeout)),
)?;

Ok(())
}
9 changes: 6 additions & 3 deletions src/dfx/src/commands/canister/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::lib::waiter::waiter_with_timeout;
use crate::util::expiry_duration;

use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{Agent, ManagementCanister};
use ic_agent::Agent;
use ic_utils::call::AsyncCall;
use ic_utils::interfaces::ManagementCanister;
use slog::info;
use std::time::Duration;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -36,7 +38,7 @@ async fn start_canister(
canister_name: &str,
timeout: Duration,
) -> DfxResult {
let mgr = ManagementCanister::new(agent);
let mgr = ManagementCanister::create(agent);
let log = env.get_logger();
let canister_id_store = CanisterIdStore::for_env(env)?;
let canister_id = canister_id_store.get(canister_name)?;
Expand All @@ -48,7 +50,8 @@ async fn start_canister(
canister_id.to_text(),
);

mgr.start_canister(waiter_with_timeout(timeout), &canister_id)
mgr.start_canister(&canister_id)
.call_and_wait(waiter_with_timeout(timeout))
.await
.map_err(DfxError::from)?;

Expand Down
11 changes: 7 additions & 4 deletions src/dfx/src/commands/canister/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::lib::waiter::waiter_with_timeout;
use crate::util::expiry_duration;

use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{Agent, ManagementCanister};
use ic_agent::Agent;
use ic_utils::call::AsyncCall;
use ic_utils::interfaces::ManagementCanister;
use slog::info;
use std::time::Duration;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -36,13 +38,14 @@ async fn canister_status(
canister_name: &str,
timeout: Duration,
) -> DfxResult {
let mgr = ManagementCanister::new(agent);
let mgr = ManagementCanister::create(agent);
let log = env.get_logger();
let canister_id_store = CanisterIdStore::for_env(env)?;
let canister_id = canister_id_store.get(canister_name)?;

let status = mgr
.canister_status(waiter_with_timeout(timeout), &canister_id)
let (status,) = mgr
.canister_status(&canister_id)
.call_and_wait(waiter_with_timeout(timeout))
.await
.map_err(DfxError::from)?;
info!(log, "Canister {}'s status is {}.", canister_name, status);
Expand Down
9 changes: 6 additions & 3 deletions src/dfx/src/commands/canister/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::lib::waiter::waiter_with_timeout;
use crate::util::expiry_duration;

use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{Agent, ManagementCanister};
use ic_agent::Agent;
use ic_utils::call::AsyncCall;
use ic_utils::interfaces::ManagementCanister;
use slog::info;
use std::time::Duration;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -36,7 +38,7 @@ async fn stop_canister(
canister_name: &str,
timeout: Duration,
) -> DfxResult {
let mgr = ManagementCanister::new(agent);
let mgr = ManagementCanister::create(agent);
let log = env.get_logger();
let canister_id_store = CanisterIdStore::for_env(env)?;
let canister_id = canister_id_store.get(canister_name)?;
Expand All @@ -48,7 +50,8 @@ async fn stop_canister(
canister_id.to_text(),
);

mgr.stop_canister(waiter_with_timeout(timeout), &canister_id)
mgr.stop_canister(&canister_id)
.call_and_wait(waiter_with_timeout(timeout))
.await
.map_err(DfxError::from)?;

Expand Down
1 change: 1 addition & 0 deletions src/dfx/src/commands/identity/principal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::lib::error::DfxResult;
use crate::lib::identity::identity_manager::IdentityManager;
use crate::lib::message::UserMessage;
use clap::{App, ArgMatches, SubCommand};
use ic_agent::Identity;

pub fn construct() -> App<'static, 'static> {
SubCommand::with_name("get-principal").about(UserMessage::GetPrincipalId.to_str())
Expand Down
7 changes: 2 additions & 5 deletions src/dfx/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crossbeam::channel::{Receiver, Sender};
use crossbeam::unbounded;
use delay::{Delay, Waiter};
use futures::executor::block_on;
use ic_agent::{Agent, AgentConfig};
use ic_agent::Agent;
use indicatif::{ProgressBar, ProgressDrawTarget};
use std::fs;
use std::io::{Error, ErrorKind};
Expand Down Expand Up @@ -51,10 +51,7 @@ pub fn construct() -> App<'static, 'static> {
fn ping_and_wait(frontend_url: &str) -> DfxResult {
let mut runtime = Runtime::new().expect("Unable to create a runtime");

let agent = Agent::new(AgentConfig {
url: frontend_url.to_string(),
..AgentConfig::default()
})?;
let agent = Agent::builder().with_url(frontend_url).build()?;

// wait for frontend to come up
let mut waiter = Delay::builder()
Expand Down
20 changes: 10 additions & 10 deletions src/dfx/src/lib/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::lib::identity::identity_manager::IdentityManager;
use crate::lib::network::network_descriptor::NetworkDescriptor;
use crate::lib::progress_bar::ProgressBar;

use ic_agent::{Agent, AgentConfig, Identity};
use ic_agent::Agent;
use semver::Version;
use slog::{Logger, Record};
use std::collections::BTreeMap;
Expand All @@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::Duration;

use ic_agent::identity::BasicIdentity;
#[cfg(test)]
use mockall::automock;

Expand Down Expand Up @@ -412,19 +413,18 @@ impl ic_agent::PasswordManager for AgentClient {
fn create_agent(
logger: Logger,
url: &str,
identity: Box<dyn Identity + Send + Sync>,
identity: BasicIdentity,
timeout: Duration,
) -> Option<Agent> {
AgentClient::new(logger, url.to_string())
.ok()
.and_then(|executor| {
Agent::new(AgentConfig {
url: url.to_string(),
identity,
password_manager: Some(Box::new(executor)),
ingress_expiry_duration: Some(timeout),
..AgentConfig::default()
})
.ok()
Agent::builder()
.with_url(url)
.with_identity(identity)
.with_password_manager(executor)
.with_ingress_expiry(Some(timeout))
.build()
.ok()
})
}
2 changes: 1 addition & 1 deletion src/dfx/src/lib/error/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ pub enum IdentityErrorKind {
CannotFindUserHomeDirectory(),

#[error("An error occurred while reading {1}: {0}")]
AgentPemError(ic_agent::PemError, PathBuf),
AgentPemError(ic_agent::identity::PemError, PathBuf),
}
Loading