Skip to content

Commit f8db79b

Browse files
committed
wip: redo everything?
1 parent 16d705f commit f8db79b

File tree

7 files changed

+288
-263
lines changed

7 files changed

+288
-263
lines changed

dfx/src/commands/call.rs

+20-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::lib::api_client::*;
1+
use crate::lib::api_client::Blob;
22
use crate::lib::env::ClientEnv;
33
use crate::lib::error::{DfxError, DfxResult};
44
use clap::{App, Arg, ArgMatches, SubCommand};
@@ -30,31 +30,25 @@ where
3030
let name = args.value_of(NAME_ARG).unwrap();
3131
let client = env.get_client();
3232

33-
let query = query(
34-
client,
35-
CanisterQueryCall {
36-
canister_id: 42,
37-
method_name: "greet".to_string(),
38-
arg: Blob(Vec::from(name)),
39-
},
40-
)
41-
.and_then(|r| match r {
42-
ReadResponse::Pending => {
43-
println!("Pending");
44-
ok(())
45-
}
46-
ReadResponse::Replied {
47-
reply: QueryResponseReply { arg: Blob(blob) },
48-
} => {
49-
println!("{}", String::from_utf8_lossy(&blob));
50-
ok(())
51-
}
52-
ReadResponse::Rejected {
53-
reject_code,
54-
reject_message,
55-
} => err(DfxError::ClientError(reject_code, reject_message)),
56-
ReadResponse::Unknown => err(DfxError::Unknown("Unknown response".to_owned())),
57-
});
33+
let query = client
34+
.query(42, "greet".to_string(), Blob(Vec::from(name)))
35+
.and_then(|r| match r {
36+
ReadResponse::Pending => {
37+
println!("Pending");
38+
ok(())
39+
}
40+
ReadResponse::Replied {
41+
reply: QueryResponseReply { arg: Blob(blob) },
42+
} => {
43+
println!("{}", String::from_utf8_lossy(&blob));
44+
ok(())
45+
}
46+
ReadResponse::Rejected {
47+
reject_code,
48+
reject_message,
49+
} => err(DfxError::ClientError(reject_code, reject_message)),
50+
ReadResponse::Unknown => err(DfxError::Unknown("Unknown response".to_owned())),
51+
});
5852

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

dfx/src/commands/canister/install.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::lib::api_client::{install_code, Blob, Client, ClientConfig};
1+
//use crate::lib::api_client::{install_code, Blob, Client};
22
use crate::lib::env::{ClientEnv, ProjectConfigEnv};
33
use crate::lib::error::DfxResult;
44
use clap::{App, Arg, ArgMatches, SubCommand};
5-
use std::path::PathBuf;
6-
use tokio::runtime::Runtime;
5+
//use std::path::PathBuf;
6+
//use tokio::runtime::Runtime;
77

88
fn is_number(v: String) -> Result<(), String> {
99
v.parse::<u64>()
@@ -32,24 +32,24 @@ pub fn exec<T>(env: &T, args: &ArgMatches<'_>) -> DfxResult
3232
where
3333
T: ClientEnv + ProjectConfigEnv,
3434
{
35-
// Read the config.
36-
let config = env.get_config().unwrap();
37-
let project_root = config.get_path().parent().unwrap();
38-
39-
let canister_id = args.value_of("canister").unwrap().parse::<u64>()?;
40-
let url = "http://localhost:8080";
41-
let wasm_path = args.value_of("wasm").unwrap();
42-
let wasm_path = PathBuf::from(project_root).join(wasm_path);
43-
44-
let wasm = std::fs::read(wasm_path)?;
45-
let client = Client::new(ClientConfig {
46-
url: url.to_string(),
47-
});
48-
49-
let install = install_code(client, canister_id, Blob(wasm), None);
50-
51-
let mut runtime = Runtime::new().expect("Unable to create a runtime");
52-
runtime.block_on(install)?;
53-
35+
// // Read the config.
36+
// let config = env.get_config().unwrap();
37+
// let project_root = config.get_path().parent().unwrap();
38+
//
39+
// let canister_id = args.value_of("canister").unwrap().parse::<u64>()?;
40+
// let url = "http://localhost:8080";
41+
// let wasm_path = args.value_of("wasm").unwrap();
42+
// let wasm_path = PathBuf::from(project_root).join(wasm_path);
43+
//
44+
// let wasm = std::fs::read(wasm_path)?;
45+
// let client = Client::new(ClientConfig {
46+
// url: url.to_string(),
47+
// });
48+
//
49+
// let install = install_code(client, canister_id, Blob(wasm), None);
50+
//
51+
// let mut runtime = Runtime::new().expect("Unable to create a runtime");
52+
// runtime.block_on(install)?;
53+
//
5454
Ok(())
5555
}

dfx/src/commands/start.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::lib::api_client::{ping, Client, ClientConfig};
2-
use crate::lib::env::BinaryResolverEnv;
1+
use crate::lib::env::{BinaryResolverEnv, ClientEnv};
32
use crate::lib::error::{DfxError, DfxResult};
43
use clap::{App, Arg, ArgMatches, SubCommand};
54
use indicatif::{ProgressBar, ProgressDrawTarget};
5+
use std::net::SocketAddr;
66
use std::time::{Duration, Instant};
77
use tokio::prelude::FutureExt;
88
use tokio::runtime::Runtime;
@@ -22,7 +22,7 @@ pub fn construct() -> App<'static, 'static> {
2222

2323
pub fn exec<T>(env: &T, args: &ArgMatches<'_>) -> DfxResult
2424
where
25-
T: BinaryResolverEnv,
25+
T: ClientEnv + BinaryResolverEnv,
2626
{
2727
let b = ProgressBar::new_spinner();
2828
b.set_draw_target(ProgressDrawTarget::stderr());
@@ -46,14 +46,13 @@ where
4646
let url = String::from(args.value_of("host").unwrap_or("http://localhost:8080"));
4747

4848
let mut runtime = Runtime::new().expect("Unable to create a runtime");
49+
let client = env.get_client(url);
4950

5051
// Try to ping for 1 second, then timeout after 5 seconds if ping hasn't succeeded.
5152
let start = Instant::now();
5253
while {
53-
let client = Client::new(ClientConfig { url: url.clone() });
54-
5554
runtime
56-
.block_on(ping(client).timeout(Duration::from_millis(TIMEOUT_IN_SECS * 1000 / 4)))
55+
.block_on(client.ping().timeout(Duration::from_secs(1)))
5756
.is_err()
5857
} {
5958
if Instant::now().duration_since(start) > Duration::from_secs(TIMEOUT_IN_SECS) {

0 commit comments

Comments
 (0)