Skip to content

Commit

Permalink
Update ic-agent to 0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Jun 27, 2023
1 parent 1a1fd8f commit 19584b1
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 319 deletions.
300 changes: 229 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ license = "Apache-2.0"

[workspace.dependencies]
candid = "0.8.4"
ic-agent = "0.23.1"
ic-agent = "0.24.1"
ic-asset = { path = "src/canisters/frontend/ic-asset" }
ic-cdk = "0.8.0"
ic-cdk-macros = "0.6.7"
ic-identity-hsm = "0.23.1"
ic-utils = "0.23.1"
ic-identity-hsm = "0.24.1"
ic-utils = "0.24.1"

aes-gcm = "0.9.4"
anyhow = "1.0.56"
Expand Down Expand Up @@ -68,19 +68,19 @@ url = "2.1.0"
walkdir = "2.3.2"

[patch.crates-io.ic-agent]
version = "0.23.2"
version = "0.24.1"
git = "https://github.com/dfinity/agent-rs.git"
rev = "862ddb2871db426d0e42e816a2f792d224d7bdf5"
rev = "b9c57f8bab23cc9936dca4560293ffe485471c6d"

[patch.crates-io.ic-identity-hsm]
version = "0.23.2"
version = "0.24.1"
git = "https://github.com/dfinity/agent-rs.git"
rev = "862ddb2871db426d0e42e816a2f792d224d7bdf5"
rev = "b9c57f8bab23cc9936dca4560293ffe485471c6d"

[patch.crates-io.ic-utils]
version = "0.23.2"
version = "0.24.1"
git = "https://github.com/dfinity/agent-rs.git"
rev = "862ddb2871db426d0e42e816a2f792d224d7bdf5"
rev = "b9c57f8bab23cc9936dca4560293ffe485471c6d"

[profile.release]
panic = 'abort'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;

use ic_agent::AgentError;
use ic_agent::{
agent::{RejectCode, RejectResponse},
AgentError,
};
use ic_utils::call::SyncCall;
use ic_utils::Canister;

Expand All @@ -23,10 +26,11 @@ pub(crate) async fn get_assets_properties(
}
// older canisters don't have get_assets_properties method
// therefore we can break the loop
Err(AgentError::ReplicaError {
Err(AgentError::ReplicaError(RejectResponse {
reject_code,
reject_message,
}) if reject_code == 3
..
})) if reject_code == RejectCode::DestinationInvalid
&& (reject_message
.contains(&format!("has no query method '{GET_ASSET_PROPERTIES}'"))
|| reject_message.contains("query method does not exist")) =>
Expand Down
5 changes: 3 additions & 2 deletions src/dfx-core/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::error::wallet_config::WalletConfigError::{
};
use crate::identity::identity_file_locations::IdentityFileLocations;
use crate::json::{load_json_file, save_json_file};
use ic_agent::agent::EnvelopeContent;
pub use identity_manager::{
HardwareIdentityConfiguration, IdentityConfiguration, IdentityCreationParameters,
IdentityManager,
Expand Down Expand Up @@ -249,8 +250,8 @@ impl ic_agent::Identity for Identity {
self.inner.sender()
}

fn sign(&self, blob: &[u8]) -> Result<Signature, String> {
self.inner.sign(blob)
fn sign(&self, content: &EnvelopeContent) -> Result<Signature, String> {
self.inner.sign(content)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub async fn exec(
agent
.query(&canister_id, method_name)
.with_effective_canister_id(effective_canister_id)
.with_arg(&arg_value)
.with_arg(arg_value)
.call()
.await
.context("Failed query call.")?
Expand Down Expand Up @@ -324,7 +324,7 @@ pub async fn exec(
agent
.update(&canister_id, method_name)
.with_effective_canister_id(effective_canister_id)
.with_arg(&arg_value)
.with_arg(arg_value)
.call()
.await
.context("Failed update call.")?
Expand Down Expand Up @@ -353,7 +353,7 @@ pub async fn exec(
agent
.update(&canister_id, method_name)
.with_effective_canister_id(effective_canister_id)
.with_arg(&arg_value)
.with_arg(arg_value)
.call_and_wait()
.await
.context("Failed update call.")?
Expand Down
10 changes: 2 additions & 8 deletions src/dfx/src/commands/canister/request_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,8 @@ pub async fn exec(env: &dyn Environment, opts: RequestStatusOpts) -> DfxResult {
.context("Failed to fetch request status.")?
{
RequestStatusResponse::Replied { reply } => return Ok(reply),
RequestStatusResponse::Rejected {
reject_code,
reject_message,
} => {
return Err(DfxError::new(AgentError::ReplicaError {
reject_code,
reject_message,
}))
RequestStatusResponse::Rejected(response) => {
return Err(DfxError::new(AgentError::ReplicaError(response)))
}
RequestStatusResponse::Unknown => (),
RequestStatusResponse::Received | RequestStatusResponse::Processing => {
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/canister/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::lib::error::DfxResult;
use crate::lib::sign::signed_message::SignedMessageV1;
use dfx_core::identity::CallSender;

use ic_agent::agent::ReplicaV2Transport;
use ic_agent::agent::Transport;
use ic_agent::{agent::http_transport::ReqwestHttpReplicaV2Transport, RequestId};

use anyhow::{anyhow, bail, Context};
Expand Down
11 changes: 4 additions & 7 deletions src/dfx/src/commands/canister/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::commands::canister::call::get_effective_canister_id;
use crate::lib::environment::Environment;
use crate::lib::error::DfxResult;
use crate::lib::operations::canister::get_local_cid_and_candid_path;
use crate::lib::sign::sign_transport::SignReplicaV2Transport;
use crate::lib::sign::sign_transport::SignTransport;
use crate::lib::sign::signed_message::SignedMessageV1;
use dfx_core::identity::CallSender;

Expand Down Expand Up @@ -174,10 +174,7 @@ pub async fn exec(
}

let mut sign_agent = agent.clone();
sign_agent.set_transport(SignReplicaV2Transport::new(
file_name.clone(),
message_template,
));
sign_agent.set_transport(SignTransport::new(file_name.clone(), message_template));

let is_management_canister = canister_id == Principal::management_canister();
let effective_canister_id =
Expand All @@ -187,7 +184,7 @@ pub async fn exec(
let res = sign_agent
.query(&canister_id, method_name)
.with_effective_canister_id(effective_canister_id)
.with_arg(&arg_value)
.with_arg(arg_value)
.expire_at(expiration_system_time)
.call()
.await;
Expand All @@ -203,7 +200,7 @@ pub async fn exec(
let res = sign_agent
.update(&canister_id, method_name)
.with_effective_canister_id(effective_canister_id)
.with_arg(&arg_value)
.with_arg(arg_value)
.expire_at(expiration_system_time)
.call()
.await;
Expand Down
8 changes: 5 additions & 3 deletions src/dfx/src/commands/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use candid::Principal;
use candid::{Decode, Encode};
use clap::Parser;
use fn_error_context::context;
use ic_agent::agent::{RejectCode, RejectResponse};
use ic_agent::agent_error::HttpErrorPayload;
use ic_agent::{Agent, AgentError};
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -238,10 +239,11 @@ pub async fn notify_top_up(

fn retryable(agent_error: &AgentError) -> bool {
match agent_error {
AgentError::ReplicaError {
reject_code,
AgentError::ReplicaError(RejectResponse {
reject_code: RejectCode::CanisterError,
reject_message,
} if *reject_code == 5 && reject_message.contains("is out of cycles") => false,
..
}) if reject_message.contains("is out of cycles") => false,
AgentError::HttpError(HttpErrorPayload {
status,
content_type: _,
Expand Down
Loading

0 comments on commit 19584b1

Please sign in to comment.