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
45 changes: 45 additions & 0 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
[root]
name = "dfinity-sdk"
version = "0.2.1"

[workspace]
members = [
"dfx",
"lib/dfx_derive",
"lib/dfx_info",
"lib/ic_http_agent",
"lib/serde_idl"
]
2 changes: 2 additions & 0 deletions dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ clap = "2.33.0"
console = "0.7.7"
flate2 = "1.0.11"
futures = "0.1.28"
hex = "0.3.2"
ic-http-agent = { "path" = "../lib/ic_http_agent" }
indicatif = "0.12.0"
rand = "0.7.2"
reqwest = "0.9.20"
Expand Down
42 changes: 37 additions & 5 deletions dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::lib::api_client::{call, Blob};
use crate::lib::api_client::{call, request_status, QueryResponseReply, ReadResponse};
use crate::lib::env::ClientEnv;
use crate::lib::error::DfxResult;
use crate::lib::CanisterId;
use crate::lib::error::{DfxError, DfxResult};
use crate::util::clap::validators;
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_http_agent::{Blob, CanisterId};
use tokio::runtime::Runtime;

pub fn construct() -> App<'static, 'static> {
Expand All @@ -21,6 +21,13 @@ pub fn construct() -> App<'static, 'static> {
.help("The method name file to use.")
.required(true),
)
.arg(
Arg::with_name("wait")
.help("Wait for the result of the call, by polling the client.")
.long("wait")
.short("w")
.takes_value(false),
)
.arg(
Arg::with_name("arguments")
.help("Arguments to pass to the method.")
Expand All @@ -47,7 +54,32 @@ where
);

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

Ok(())
if args.is_present("wait") {
let request_status = request_status(env.get_client(), request_id);
let mut runtime = Runtime::new().expect("Unable to create a runtime");
match runtime.block_on(request_status) {
Ok(ReadResponse::Pending) => {
println!("Pending");
Ok(())
}
Ok(ReadResponse::Replied { reply }) => {
if let Some(QueryResponseReply { arg: Blob(blob) }) = reply {
println!("{}", String::from_utf8_lossy(&blob));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is work in progress since polling isn't implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses a single poll, but there's nothing preventing us from putting this in a loop. Do you want this here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily, but the spec says to expect a response with a status of "unknown" and/or "pending" before we get "replied" so we need to account for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a follow-up PR. I have a branch in progress to start on the api_client anyway, and it will be doing the typing properly (or better than currently in any case).

}
Ok(())
}
Ok(ReadResponse::Rejected {
reject_code,
reject_message,
}) => Err(DfxError::ClientError(reject_code, reject_message)),
// TODO(SDK-446): remove this when moving api_client to ic_http_agent.
Ok(ReadResponse::Unknown) => Err(DfxError::Unknown("Unknown response".to_owned())),
Err(x) => Err(x),
}
} else {
println!("0x{}", String::from(request_id));
Ok(())
}
}
4 changes: 2 additions & 2 deletions dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::lib::api_client::{install_code, Blob};
use crate::lib::api_client::install_code;
use crate::lib::env::{ClientEnv, ProjectConfigEnv};
use crate::lib::error::DfxResult;
use crate::lib::CanisterId;
use crate::util::clap::validators;
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_http_agent::{Blob, CanisterId};
use std::path::PathBuf;
use tokio::runtime::Runtime;

Expand Down
2 changes: 2 additions & 0 deletions dfx/src/commands/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use clap::{App, ArgMatches, SubCommand};
mod call;
mod install;
mod query;
mod request_status;

fn builtins<T>() -> Vec<CliCommand<T>>
where
Expand All @@ -15,6 +16,7 @@ where
CliCommand::new(call::construct(), call::exec),
CliCommand::new(install::construct(), install::exec),
CliCommand::new(query::construct(), query::exec),
CliCommand::new(request_status::construct(), request_status::exec),
]
}

Expand Down
14 changes: 7 additions & 7 deletions dfx/src/commands/canister/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::lib::api_client::{query, Blob, QueryResponseReply, ReadResponse};
use crate::lib::api_client::{query, QueryResponseReply, ReadResponse};
use crate::lib::env::ClientEnv;
use crate::lib::error::{DfxError, DfxResult};
use crate::lib::CanisterId;
use crate::util::clap::validators;
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_http_agent::{Blob, CanisterId};
use tokio::runtime::Runtime;

pub fn construct() -> App<'static, 'static> {
Expand Down Expand Up @@ -52,17 +52,17 @@ where
println!("Pending");
Ok(())
}
Ok(ReadResponse::Replied {
reply: QueryResponseReply { arg: Blob(blob) },
}) => {
println!("{}", String::from_utf8_lossy(&blob));
Ok(ReadResponse::Replied { reply }) => {
if let Some(QueryResponseReply { arg: Blob(blob) }) = reply {
println!("{}", String::from_utf8_lossy(&blob));
}
Ok(())
}
Ok(ReadResponse::Rejected {
reject_code,
reject_message,
}) => Err(DfxError::ClientError(reject_code, reject_message)),
// TODO: remove this when moving to ic_http_api.
// TODO(SDK-446): remove this when moving api_client to ic_http_agent.
Ok(ReadResponse::Unknown) => Err(DfxError::Unknown("Unknown response".to_owned())),
Err(x) => Err(x),
}
Expand Down
48 changes: 48 additions & 0 deletions dfx/src/commands/canister/request_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::lib::api_client::{request_status, QueryResponseReply, ReadResponse};
use crate::lib::env::ClientEnv;
use crate::lib::error::{DfxError, DfxResult};
use crate::util::clap::validators;
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_http_agent::{Blob, RequestId};
use std::str::FromStr;
use tokio::runtime::Runtime;

pub fn construct() -> App<'static, 'static> {
SubCommand::with_name("request-status")
.about("Request the status of a call to a canister.")
.arg(
Arg::with_name("request_id")
.takes_value(true)
.help("The request ID to call. This is an hexadecimal string starting with 0x.")
.required(true)
.validator(validators::is_request_id),
)
}

pub fn exec<T>(env: &T, args: &ArgMatches<'_>) -> DfxResult
where
T: ClientEnv,
{
let request_id = RequestId::from_str(&args.value_of("request_id").unwrap()[2..])?;
let request_status = request_status(env.get_client(), request_id);
let mut runtime = Runtime::new().expect("Unable to create a runtime");
match runtime.block_on(request_status) {
Ok(ReadResponse::Pending) => {
println!("Pending");
Ok(())
}
Ok(ReadResponse::Replied { reply }) => {
if let Some(QueryResponseReply { arg: Blob(blob) }) = reply {
println!("{}", String::from_utf8_lossy(&blob));
}
Ok(())
}
Ok(ReadResponse::Rejected {
reject_code,
reject_message,
}) => Err(DfxError::ClientError(reject_code, reject_message)),
// TODO(SDK-446): remove this when moving api_client to ic_http_agent.
Ok(ReadResponse::Unknown) => Err(DfxError::Unknown("Unknown response".to_owned())),
Err(x) => Err(x),
}
}
1 change: 0 additions & 1 deletion dfx/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ where
b.set_message("Looking for latest version...");
b.enable_steady_tick(80);

std::thread::sleep(std::time::Duration::from_secs(1));
if !env.is_installed()? {
env.install()?;
b.finish_with_message(
Expand Down
Loading