From b8f7dd8831d590fc83347ea53aee1aed237430d9 Mon Sep 17 00:00:00 2001 From: Yan Chen <48968912+chenyan-dfinity@users.noreply.github.com> Date: Fri, 25 Aug 2023 09:27:00 -0700 Subject: [PATCH] chore: QoL improvements (#462) --- CHANGELOG.md | 3 +++ ic-agent/src/agent/agent_error.rs | 6 ++++++ ic-agent/src/agent/mod.rs | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc307e24..aed5e19b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +* Add `From` trait to coerce `candid::Error` into `ic_agent::AgentError`. +* Add `Agent::set_arc_identity` method to switch identity. + ## [0.26.1] - 2023-08-22 Switched from rustls crate to rustls-webpki fork to address https://rustsec.org/advisories/RUSTSEC-2023-0052 diff --git a/ic-agent/src/agent/agent_error.rs b/ic-agent/src/agent/agent_error.rs index eda22e9a..e48e4053 100644 --- a/ic-agent/src/agent/agent_error.rs +++ b/ic-agent/src/agent/agent_error.rs @@ -180,6 +180,12 @@ impl Display for RejectResponse { } } +impl From for AgentError { + fn from(e: candid::Error) -> AgentError { + AgentError::CandidError(e.into()) + } +} + /// A HTTP error from the replica. pub struct HttpErrorPayload { /// The HTTP status code. diff --git a/ic-agent/src/agent/mod.rs b/ic-agent/src/agent/mod.rs index 5e0c7b0a..3ca2c759 100644 --- a/ic-agent/src/agent/mod.rs +++ b/ic-agent/src/agent/mod.rs @@ -285,6 +285,14 @@ impl Agent { { self.identity = Arc::new(identity); } + /// Set the arc identity provider for signing messages. + /// + /// NOTE: if you change the identity while having update calls in + /// flight, you will not be able to [Agent::poll] the status of these + /// messages. + pub fn set_arc_identity(&mut self, identity: Arc) { + self.identity = identity; + } /// By default, the agent is configured to talk to the main Internet Computer, and verifies /// responses using a hard-coded public key.