Skip to content

Commit

Permalink
feat: allow setting agent identity after construction (#379)
Browse files Browse the repository at this point in the history
* feat: allow setting agent identity after construction

This change adds Agent::set_identity method allowing to modify the
identity after constructing the agent.

Motivation: I am writing a test suite where I need to send messages to
the same canister from different identities. Being able to
Agent::clone() followed by Agent::set_identity() would significantly
simplify (and speed up) my code.

* Update CHANGELOG
  • Loading branch information
roman-kashitsyn authored Aug 31, 2022
1 parent 3d95cb4 commit 5bd26b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Changelog

All notable changes to this project will be documented in this file.
Expand All @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Switched to `miracl_core_bls12381` crate for bls
* Added new `hyper` transport `HyperReplicaV2Transport`
* Added Agent::set_identity method (#379)

## [0.20.0] - 2022-07-14

Expand Down
12 changes: 12 additions & 0 deletions ic-agent/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ impl Agent {
self.transport = Arc::new(transport);
}

/// Set the 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_identity<I>(&mut self, identity: I)
where
I: 'static + Identity,
{
self.identity = Arc::new(identity);
}

/// By default, the agent is configured to talk to the main Internet Computer, and verifies
/// responses using a hard-coded public key.
///
Expand Down

0 comments on commit 5bd26b8

Please sign in to comment.