-
Notifications
You must be signed in to change notification settings - Fork 100
First Public Spec library draft and Request ID calculation in Rust #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cfa54a1
ce5921d
a93dc67
3ea467d
e682058
5bf7261
f39b5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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" | ||
| ] |
| 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> { | ||
|
|
@@ -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.") | ||
|
|
@@ -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)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(()) | ||
| } | ||
| } | ||
| 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..])?; | ||
paulyoung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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), | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.