Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
},
"dfinity": {
"repo": "ssh://git@github.com/dfinity-lab/dfinity",
"rev": "70434f1ecac5227dc8e5d30635f7aceb7c257e3f",
"tag": "release-2020-09-04.RC00",
"rev": "ed4b1ae420f863a7b8393af058a2d62deebba2ed",
"tag": "release-2020-09-15.RC00",
"type": "git"
},
"ic-ref": {
"repo": "ssh://git@github.com/dfinity-lab/ic-ref",
"rev": "493f0862ddd9970b8fb09e4e97f95fab1764b18e",
"tag": "release-0.9",
"rev": "7d453c4b09f78b3fa1f06df6a3ff00e51b11ca3e",
"branch": "release-0.10",
"type": "git"
},
"motoko": {
Expand Down
6 changes: 4 additions & 2 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ lazy-init = "0.3.0"
lazy_static = "1.4.0"
libflate = "0.1.27"
hotwatch = "0.4.3"
humanize-rs = "0.1.5"
mockall = "0.6.0"
pem = "0.7.0"
petgraph = "0.5.0"
Expand Down Expand Up @@ -69,13 +70,14 @@ wasmparser = "0.45.0"
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "35a0f9851cf8cceea34acf405ba50c84ab5fbc5e"
rev = "9d611f08cb55923fc6ff5bf0136e8f4b848dd2cc"

[dependencies.ic-types]
version = "0.1.1"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "35a0f9851cf8cceea34acf405ba50c84ab5fbc5e"
rev = "9d611f08cb55923fc6ff5bf0136e8f4b848dd2cc"


[dev-dependencies]
env_logger = "0.6"
Expand Down
26 changes: 17 additions & 9 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::lib::environment::Environment;
use crate::lib::error::{DfxError, DfxResult};
use crate::lib::message::UserMessage;
use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::lib::waiter::create_waiter;
use crate::util::{blob_from_arguments, get_candid_type, print_idl_blob};
use crate::lib::waiter::waiter_with_timeout;
use crate::util::{blob_from_arguments, expiry_duration, get_candid_type, print_idl_blob};
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_types::principal::Principal as CanisterId;
use std::option::Option;
Expand Down Expand Up @@ -125,26 +125,34 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
// Get the argument, get the type, convert the argument to the type and return
// an error if any of it doesn't work.
let arg_value = blob_from_arguments(arguments, arg_type, &method_type)?;
let client = env
let agent = env
.get_agent()
.ok_or(DfxError::CommandMustBeRunInAProject)?;
let mut runtime = Runtime::new().expect("Unable to create a runtime");

let timeout = expiry_duration();

if is_query {
let blob = runtime.block_on(client.query_raw(&canister_id, method_name, &arg_value))?;
let blob =
runtime.block_on(agent.query_raw(&canister_id, method_name, &arg_value, None))?;
print_idl_blob(&blob, output_type, &method_type)
.map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?;
} else if args.is_present("async") {
let request_id =
runtime.block_on(client.update_raw(&canister_id, method_name, &arg_value))?;

let request_id = runtime.block_on(
agent
.update(&canister_id, &method_name)
.with_arg(&arg_value)
.call(),
)?;
eprint!("Request ID: ");
println!("0x{}", String::from(request_id));
} else {
let blob = runtime.block_on(
client
agent
.update(&canister_id, &method_name)
.with_arg(&arg_value)
.call_and_wait(create_waiter()),
.expire_after(timeout)
.call_and_wait(waiter_with_timeout(timeout)),
)?;

print_idl_blob(&blob, output_type, &method_type)
Expand Down
7 changes: 5 additions & 2 deletions src/dfx/src/commands/canister/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::lib::environment::Environment;
use crate::lib::error::{DfxError, DfxResult};
use crate::lib::message::UserMessage;
use crate::lib::operations::canister::create_canister;
use crate::util::expiry_duration;

use clap::{App, Arg, ArgMatches, SubCommand};

Expand Down Expand Up @@ -29,14 +30,16 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
.get_config()
.ok_or(DfxError::CommandMustBeRunInAProject)?;

let timeout = expiry_duration();

if let Some(canister_name) = args.value_of("canister_name") {
create_canister(env, canister_name)?;
create_canister(env, canister_name, timeout)?;
Ok(())
} else if args.is_present("all") {
// Create all canisters.
if let Some(canisters) = &config.get_config().canisters {
for canister_name in canisters.keys() {
create_canister(env, canister_name)?;
create_canister(env, canister_name, timeout)?;
}
}
Ok(())
Expand Down
19 changes: 14 additions & 5 deletions src/dfx/src/commands/canister/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use crate::lib::environment::Environment;
use crate::lib::error::{DfxError, DfxResult};
use crate::lib::message::UserMessage;
use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::lib::waiter::create_waiter;
use crate::lib::waiter::waiter_with_timeout;
use crate::util::expiry_duration;

use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{Agent, ManagementCanister};
use slog::info;
use std::time::Duration;
use tokio::runtime::Runtime;

pub fn construct() -> App<'static, 'static> {
Expand All @@ -28,7 +30,12 @@ pub fn construct() -> App<'static, 'static> {
)
}

async fn delete_canister(env: &dyn Environment, agent: &Agent, canister_name: &str) -> DfxResult {
async fn delete_canister(
env: &dyn Environment,
agent: &Agent,
canister_name: &str,
timeout: Duration,
) -> DfxResult {
let mgr = ManagementCanister::new(agent);
let log = env.get_logger();
let mut canister_id_store = CanisterIdStore::for_env(env)?;
Expand All @@ -40,7 +47,7 @@ async fn delete_canister(env: &dyn Environment, agent: &Agent, canister_name: &s
canister_id.to_text(),
);

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

Expand All @@ -57,15 +64,17 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
.get_agent()
.ok_or(DfxError::CommandMustBeRunInAProject)?;

let timeout = expiry_duration();

let mut runtime = Runtime::new().expect("Unable to create a runtime");

if let Some(canister_name) = args.value_of("canister_name") {
runtime.block_on(delete_canister(env, &agent, &canister_name))?;
runtime.block_on(delete_canister(env, &agent, &canister_name, timeout))?;
Ok(())
} else if args.is_present("all") {
if let Some(canisters) = &config.get_config().canisters {
for canister_name in canisters.keys() {
runtime.block_on(delete_canister(env, &agent, &canister_name))?;
runtime.block_on(delete_canister(env, &agent, &canister_name, timeout))?;
}
}
Ok(())
Expand Down
37 changes: 36 additions & 1 deletion src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use crate::lib::error::{DfxError, DfxResult};
use crate::lib::message::UserMessage;
use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::lib::operations::canister::install_canister;
use crate::util::expiry_duration;

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

use std::convert::TryFrom;
use std::str::FromStr;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -51,6 +54,14 @@ pub fn construct() -> App<'static, 'static> {
.takes_value(true)
.validator(compute_allocation_validator),
)
.arg(
Arg::with_name("memory-allocation")
.help(UserMessage::InstallMemoryAllocation.to_str())
.long("memory-allocation")
.default_value("8GB")
.takes_value(true)
.validator(memory_allocation_validator),
)
}

fn compute_allocation_validator(compute_allocation: String) -> Result<(), String> {
Expand All @@ -62,18 +73,38 @@ fn compute_allocation_validator(compute_allocation: String) -> Result<(), String
Err("Must be a percent between 0 and 100".to_string())
}

fn memory_allocation_validator(memory_allocation: String) -> Result<(), String> {
let limit = Bytes::new(256, Unit::TByte).map_err(|_| "Parse Overflow.")?;
if let Ok(bytes) = memory_allocation.parse::<Bytes>() {
if bytes.size() <= limit.size() {
return Ok(());
}
}
Err("Must be a value between 0..256 TB inclusive.".to_string())
}

pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
let config = env
.get_config()
.ok_or(DfxError::CommandMustBeRunInAProject)?;

let timeout = expiry_duration();

let agent = env
.get_agent()
.ok_or(DfxError::CommandMustBeRunInAProject)?;

let compute_allocation = args.value_of("compute-allocation").map(|arg| {
ComputeAllocation::try_from(arg.parse::<u64>().unwrap())
.expect("Compute Allocation must be a percentage.")
});

let memory_allocation: Option<MemoryAllocation> =
args.value_of("memory-allocation").map(|arg| {
MemoryAllocation::try_from(u64::try_from(arg.parse::<Bytes>().unwrap().size()).unwrap())
.expect("Memory allocation must be between 0 and 2^48 (i.e 256TB), inclusively.")
});

let mode = InstallMode::from_str(args.value_of("mode").unwrap())?;

let mut runtime = Runtime::new().expect("Unable to create a runtime");
Expand All @@ -90,6 +121,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
&canister_info,
compute_allocation,
mode,
memory_allocation,
timeout,
))?;
Ok(())
} else if args.is_present("all") {
Expand All @@ -105,6 +138,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
&canister_info,
compute_allocation,
mode.clone(),
memory_allocation,
timeout,
))?;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/dfx/src/commands/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub fn construct() -> App<'static, 'static> {

pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
let subcommand = args.subcommand();

let agent_env = create_agent_environment(env, args)?;

if let (name, Some(subcommand_args)) = subcommand {
Expand Down
15 changes: 11 additions & 4 deletions src/dfx/src/commands/canister/request_status.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::lib::environment::Environment;
use crate::lib::error::{DfxError, DfxResult};
use crate::lib::message::UserMessage;
use crate::lib::waiter::create_waiter;
use crate::lib::waiter::waiter_with_timeout;
use crate::util::clap::validators;
use crate::util::print_idl_blob;
use crate::util::{expiry_duration, print_idl_blob};
use clap::{App, Arg, ArgMatches, SubCommand};
use delay::Waiter;
use ic_agent::{AgentError, Replied, RequestId, RequestStatusResponse};
Expand Down Expand Up @@ -35,13 +35,15 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
.ok_or(DfxError::CommandMustBeRunInAProject)?;
let mut runtime = Runtime::new().expect("Unable to create a runtime");

let mut waiter = create_waiter();
let timeout = expiry_duration();

let mut waiter = waiter_with_timeout(timeout);

let Replied::CallReplied(blob) = runtime
.block_on(async {
waiter.start();
loop {
match agent.request_status_raw(&request_id).await? {
match agent.request_status_raw(&request_id, None).await? {
RequestStatusResponse::Replied { reply } => return Ok(reply),
RequestStatusResponse::Rejected {
reject_code,
Expand All @@ -55,6 +57,11 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
RequestStatusResponse::Unknown => (),
RequestStatusResponse::Received => (),
RequestStatusResponse::Processing => (),
RequestStatusResponse::Done => {
return Err(DfxError::AgentError(AgentError::RequestStatusDoneNoReply(
String::from(request_id),
)))
}
};

waiter
Expand Down
Loading