Skip to content

Commit

Permalink
Homogenize ConnectionReader functions (#349)
Browse files Browse the repository at this point in the history
* ConnectionReader.connection_end returns owned val

* Removed redundant clones, updated changelog; ready to fix #347.

Co-authored-by: CharlyCst <castes.ch@gmail.com>
  • Loading branch information
adizere and CharlyCst authored Nov 2, 2020
1 parent 5cb7b3f commit 955a3b1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased Changes

Special thanks to external contributors for this release: @CharlyCst ([#347]).

### FEATURES

- [changelog] Added "unreleased" section in `CHANGELOG.MD` to help streamline releases ([#274])
Expand All @@ -17,8 +19,10 @@
### IMPROVEMENTS

- [relayer-cli] Split tasks spawned by CLI commands into their own modules ([#331])
- [modules] Homogenize ConnectionReader trait so that all functions return owned objects ([#347])

[#331]: https://github.com/informalsystems/ibc-rs/pulls/331
[#347]: https://github.com/informalsystems/ibc-rs/issues/347

## v0.0.4
*October 19, 2020*
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::Height;
/// A context supplying all the necessary read-only dependencies for processing any `ConnectionMsg`.
pub trait ConnectionReader {
/// Returns the ConnectionEnd for the given identifier `conn_id`.
fn connection_end(&self, conn_id: &ConnectionId) -> Option<&ConnectionEnd>;
fn connection_end(&self, conn_id: &ConnectionId) -> Option<ConnectionEnd>;

/// Returns the ClientState for the given identifier `client_id`.
fn client_state(&self, client_id: &ClientId) -> Option<AnyClientState>;
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn process(
|| old_conn_end.counterparty().connection_id() == msg.counterparty_connection_id();

if state_is_consistent && counterparty_matches {
Ok(old_conn_end.clone())
Ok(old_conn_end)
} else {
// Old connection end is in incorrect state, propagate the error.
Err(Into::<Error>::into(Kind::ConnectionMismatch(
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) fn process(
msg.connection_id().clone(),
)))
} else {
Ok(old_conn_end.clone())
Ok(old_conn_end)
}
}
None => {
Expand Down
2 changes: 1 addition & 1 deletion modules/src/ics03_connection/handler/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) fn process(
&& old_conn_end.client_id_matches(msg.client_id())
{
// A ConnectionEnd already exists and all validation passed.
Ok(old_conn_end.clone())
Ok(old_conn_end)
} else {
// A ConnectionEnd already exists and validation failed.
Err(Into::<Error>::into(
Expand Down
4 changes: 2 additions & 2 deletions modules/src/mock_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl MockContext {
impl ICS26Context for MockContext {}

impl ConnectionReader for MockContext {
fn connection_end(&self, cid: &ConnectionId) -> Option<&ConnectionEnd> {
self.connections.get(cid)
fn connection_end(&self, cid: &ConnectionId) -> Option<ConnectionEnd> {
self.connections.get(cid).cloned()
}

fn client_state(&self, client_id: &ClientId) -> Option<AnyClientState> {
Expand Down

0 comments on commit 955a3b1

Please sign in to comment.