Skip to content
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

chore: update agent-rust latest #986

Merged
merged 3 commits into from
Sep 2, 2020
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ wasmparser = "0.45.0"
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "e443ef550c102a3956a024800aa98c82466d6f31"
rev = "e61e646c7a810c13c1b3d898d1d2ed7366b67a0a"

[dependencies.ic-types]
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "e443ef550c102a3956a024800aa98c82466d6f31"
rev = "e61e646c7a810c13c1b3d898d1d2ed7366b67a0a"


[dev-dependencies]
Expand Down
14 changes: 7 additions & 7 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
.ok_or(DfxError::CommandMustBeRunInAProject)?;
let mut runtime = Runtime::new().expect("Unable to create a runtime");
if is_query {
let blob = runtime.block_on(client.query(&canister_id, method_name, &arg_value))?;
let blob = runtime.block_on(client.query_raw(&canister_id, method_name, &arg_value))?;
print_idl_blob(&blob, output_type, &method_type)
.map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?;
} else if args.is_present("async") {
Expand All @@ -140,12 +140,12 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult {
eprint!("Request ID: ");
println!("0x{}", String::from(request_id));
} else {
let blob = runtime.block_on(client.update_and_wait(
&canister_id,
method_name,
&arg_value,
create_waiter(),
))?;
let blob = runtime.block_on(
client
.update(&canister_id, &method_name)
.with_arg(&arg_value)
.call_and_wait(create_waiter()),
)?;

print_idl_blob(&blob, output_type, &method_type)
.map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?;
Expand Down
8 changes: 3 additions & 5 deletions src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use crate::lib::models::canister_id_store::CanisterIdStore;
use crate::lib::waiter::create_waiter;

use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{
Agent, Blob, CanisterAttributes, ComputeAllocation, InstallMode, ManagementCanister,
};
use ic_agent::{Agent, CanisterAttributes, ComputeAllocation, InstallMode, ManagementCanister};
use slog::info;
use std::convert::TryFrom;
use std::str::FromStr;
Expand Down Expand Up @@ -86,8 +84,8 @@ async fn install_canister(
create_waiter(),
&canister_id,
mode,
&Blob::from(wasm),
&Blob::empty(),
&wasm,
&[],
&CanisterAttributes { compute_allocation },
)
.await
Expand Down
30 changes: 28 additions & 2 deletions src/dfx/src/commands/canister/request_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::lib::waiter::create_waiter;
use crate::util::clap::validators;
use crate::util::print_idl_blob;
use clap::{App, Arg, ArgMatches, SubCommand};
use ic_agent::{Replied, RequestId};
use delay::Waiter;
use ic_agent::{AgentError, Replied, RequestId, RequestStatusResponse};
use std::str::FromStr;
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -34,8 +35,33 @@ 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 Replied::CallReplied(blob) = runtime
.block_on(agent.request_status_and_wait(&request_id, create_waiter()))
.block_on(async {
waiter.start();
loop {
match agent.request_status_raw(&request_id).await? {
RequestStatusResponse::Replied { reply } => return Ok(reply),
RequestStatusResponse::Rejected {
reject_code,
reject_message,
} => {
return Err(DfxError::AgentError(AgentError::ReplicaError {
reject_code,
reject_message,
}))
}
RequestStatusResponse::Unknown => (),
RequestStatusResponse::Received => (),
RequestStatusResponse::Processing => (),
};

waiter
.wait()
.map_err(|_| DfxError::AgentError(AgentError::TimeoutWaitingForResponse()))?;
}
})
.map_err(DfxError::from)?;
print_idl_blob(&blob, None, &None)
.map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?;
Expand Down
8 changes: 4 additions & 4 deletions src/dfx/src/lib/identity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ic_agent::{Blob, Signature};
use ic_agent::Signature;
use ic_types::principal::Principal;
use std::path::PathBuf;

Expand All @@ -24,8 +24,8 @@ impl ic_agent::Identity for Identity {
fn sign(&self, blob: &[u8], _: &Principal) -> Result<Signature, String> {
let signature_tuple = self.0.sign(blob).map_err(|e| e.to_string())?;

let signature = Blob::from(signature_tuple.signature.clone());
let public_key = Blob::from(signature_tuple.public_key);
let signature = signature_tuple.signature;
let public_key = signature_tuple.public_key;
Ok(Signature {
public_key,
signature,
Expand All @@ -50,7 +50,7 @@ mod test {
let request_id = RequestId::new(&[4; 32]);
let mut buf = vec![];
buf.extend_from_slice(domain_separator);
buf.extend_from_slice(Blob::from(request_id).as_slice());
buf.extend_from_slice(request_id.as_slice());
buf
};
let signature = signer.sign(&msg, &sender).expect("Failed to sign.");
Expand Down
6 changes: 3 additions & 3 deletions src/dfx/src/lib/installers/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::lib::error::DfxResult;
use crate::lib::waiter::create_waiter;
use candid::Encode;
use ic_agent::Agent;
use ic_agent::Blob;
use std::path::Path;
use walkdir::WalkDir;

Expand All @@ -23,12 +22,13 @@ pub async fn post_install_store_assets(info: &CanisterInfo, agent: &Agent) -> Df
let content = &std::fs::read(&source)?;
let path = relative.to_string_lossy().to_string();
let blob = candid::Encode!(&path, &content)?;
let blob = Blob::from(&blob);

let canister_id = info.get_canister_id().expect("Could not find canister ID.");
let method_name = String::from("store");
agent
.update_and_wait(&canister_id, &method_name, &blob, create_waiter())
.update(&canister_id, &method_name)
.with_arg(&blob)
.call_and_wait(create_waiter())
.await?;
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/dfx/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@ use crate::lib::error::{DfxError, DfxResult};
use candid::parser::typing::{check_prog, TypeEnv};
use candid::types::{Function, Type};
use candid::{parser::value::IDLValue, IDLArgs, IDLProg};
use ic_agent::Blob;

pub mod assets;
pub mod clap;

/// Deserialize and print return values from canister method.
pub fn print_idl_blob(
blob: &Blob,
blob: &[u8],
output_type: Option<&str>,
method_type: &Option<(TypeEnv, Function)>,
) -> DfxResult<()> {
let output_type = output_type.unwrap_or("idl");
match output_type {
"raw" => {
let hex_string = hex::encode(&(*blob.0));
let hex_string = hex::encode(blob);
println!("{}", hex_string);
}
"idl" => {
let result = match method_type {
None => candid::IDLArgs::from_bytes(&(*blob.0)),
Some((env, func)) => {
candid::IDLArgs::from_bytes_with_types(&(*blob.0), &env, &func.rets)
}
None => candid::IDLArgs::from_bytes(blob),
Some((env, func)) => candid::IDLArgs::from_bytes_with_types(blob, &env, &func.rets),
};
if result.is_err() {
let hex_string = hex::encode(&(*blob.0));
let hex_string = hex::encode(blob);
eprintln!("Error deserializing blob 0x{}", hex_string);
}
println!("{}", result?);
Expand Down Expand Up @@ -62,7 +59,7 @@ pub fn blob_from_arguments(
arguments: Option<&str>,
arg_type: Option<&str>,
method_type: &Option<(TypeEnv, Function)>,
) -> DfxResult<Blob> {
) -> DfxResult<Vec<u8>> {
let arg_type = arg_type.unwrap_or("idl");
match arg_type {
"raw" => {
Expand Down Expand Up @@ -115,5 +112,4 @@ pub fn blob_from_arguments(
}
v => Err(DfxError::Unknown(format!("Invalid type: {}", v))),
}
.map(Blob::from)
}
4 changes: 2 additions & 2 deletions src/ic_identity_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ serde = { version = "1.0", features = ["derive"] }
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "e443ef550c102a3956a024800aa98c82466d6f31"
rev = "e61e646c7a810c13c1b3d898d1d2ed7366b67a0a"

[dependencies.ic-types]
version = "0.1.0"
git = "ssh://git@github.com/dfinity-lab/agent-rust.git"
branch = "next"
rev = "e443ef550c102a3956a024800aa98c82466d6f31"
rev = "e61e646c7a810c13c1b3d898d1d2ed7366b67a0a"

[dev-dependencies]
serde_cbor = "0.10"