From 47ea332e097265784f8540236ad4d195efc47e78 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Fri, 10 Jan 2020 15:16:04 +0100 Subject: [PATCH 1/2] dfx canister call: Keep polling when request status is Pending without this, if you use `dfx canister call` to invoke a method that does inter-canister-calls, you get the request id instead of the actual response. --- src/dfx/src/commands/canister/install.rs | 51 ++++++++++-------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/dfx/src/commands/canister/install.rs b/src/dfx/src/commands/canister/install.rs index 1be528639c..6f827943ec 100644 --- a/src/dfx/src/commands/canister/install.rs +++ b/src/dfx/src/commands/canister/install.rs @@ -8,7 +8,6 @@ use crate::lib::message::UserMessage; use crate::util::print_idl_blob; use clap::{App, Arg, ArgMatches, SubCommand}; use ic_http_agent::{Blob, RequestId}; -use std::io::Write; use std::time::{Duration, Instant}; use tokio::runtime::Runtime; @@ -72,35 +71,27 @@ pub fn wait_on_request_status(client: &Client, request_id: RequestId) -> DfxResu // the client work, and call again. We stop waiting after `REQUEST_TIMEOUT`. loop { response = runtime.block_on(request_status(client.clone(), request_id))?; - if response != ReadResponse::Unknown || start.elapsed() > REQUEST_TIMEOUT { - break; - } else { - std::thread::sleep(RETRY_PAUSE); - } - } - - match response { - ReadResponse::Pending => { - eprint!("Request ID: "); - std::io::stderr().flush()?; - println!("0x{}", String::from(request_id)); - Ok(()) - } - ReadResponse::Replied { reply } => { - if let Some(QueryResponseReply { arg: blob }) = reply { - print_idl_blob(&blob) - .map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?; - } - Ok(()) - } - ReadResponse::Rejected { - reject_code, - reject_message, - } => Err(DfxError::ClientError(reject_code, reject_message)), - ReadResponse::Unknown => Err(DfxError::TimeoutWaitingForResponse( - request_id, - REQUEST_TIMEOUT, - )), + match response { + ReadResponse::Replied { reply } => { + if let Some(QueryResponseReply { arg: blob }) = reply { + print_idl_blob(&blob) + .map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?; + } + return Ok(()) + }, + ReadResponse::Rejected { reject_code, reject_message, } => { + return Err(DfxError::ClientError(reject_code, reject_message)) + }, + ReadResponse::Pending => (), + ReadResponse::Unknown => (), + }; + if start.elapsed() > REQUEST_TIMEOUT { + return Err(DfxError::TimeoutWaitingForResponse( + request_id, + REQUEST_TIMEOUT, + )) + }; + std::thread::sleep(RETRY_PAUSE); } } From f1b95112d609e15c6c83ef6723b0f8fa198f05df Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Fri, 10 Jan 2020 15:25:29 +0100 Subject: [PATCH 2/2] cargo-fmt --- src/dfx/src/commands/canister/install.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dfx/src/commands/canister/install.rs b/src/dfx/src/commands/canister/install.rs index 6f827943ec..7b981432a7 100644 --- a/src/dfx/src/commands/canister/install.rs +++ b/src/dfx/src/commands/canister/install.rs @@ -77,11 +77,12 @@ pub fn wait_on_request_status(client: &Client, request_id: RequestId) -> DfxResu print_idl_blob(&blob) .map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?; } - return Ok(()) - }, - ReadResponse::Rejected { reject_code, reject_message, } => { - return Err(DfxError::ClientError(reject_code, reject_message)) - }, + return Ok(()); + } + ReadResponse::Rejected { + reject_code, + reject_message, + } => return Err(DfxError::ClientError(reject_code, reject_message)), ReadResponse::Pending => (), ReadResponse::Unknown => (), }; @@ -89,7 +90,7 @@ pub fn wait_on_request_status(client: &Client, request_id: RequestId) -> DfxResu return Err(DfxError::TimeoutWaitingForResponse( request_id, REQUEST_TIMEOUT, - )) + )); }; std::thread::sleep(RETRY_PAUSE); }