Skip to content

Commit

Permalink
refactor get_full_sessions to get_sessions_topic_and_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Jan 20, 2025
1 parent 45a5961 commit c697e3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion mm2src/kdf_walletconnect/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ impl SessionManager {
self.read().clone().into_values().map(|session| session.into())
}

pub(crate) fn get_sessions_full(&self) -> impl Iterator<Item = Session> { self.read().clone().into_values() }
/// Retrieves all active session topic with their controller.
pub(crate) fn get_sessions_topic_and_controller(&self) -> Vec<(Topic, Controller)> {
self.read()
.iter()
.map(|(topic, session)| (topic.clone(), session.controller.clone()))
.collect::<Vec<(Topic, Controller)>>()
}

/// Updates the expiry time of the session associated with the given topic to the specified timestamp.
/// If the session does not exist, this method does nothing.
Expand Down
10 changes: 5 additions & 5 deletions mm2src/kdf_walletconnect/src/session/rpc/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ pub(crate) async fn reply_session_settle_request(
.mm_err(|err| WalletConnectError::StorageError(err.to_string()))?;

// Delete other sessions with same controller
let sessions = ctx.session_manager.get_sessions_full();
for session in sessions
let sessions = ctx.session_manager.get_sessions_topic_and_controller();
for (topic, _) in sessions
.into_iter()
.filter(|session| session.controller == current_session.controller && session.topic != current_session.topic)
.filter(|(topic, controller)| controller == &current_session.controller && topic != &current_session.topic)
{
ctx.drop_session(&session.topic).await?;
debug!("[{}] session deleted", session.topic);
ctx.drop_session(&topic).await?;
debug!("[{topic}] session deleted");
}

info!("[{topic}] Session successfully settled for topic");
Expand Down

0 comments on commit c697e3c

Please sign in to comment.