Skip to content

Commit

Permalink
validate table name only during initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Nov 27, 2024
1 parent 5e89b9f commit 1fec24f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
6 changes: 0 additions & 6 deletions mm2src/kdf_walletconnect/src/storage/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl WalletConnectStorageOps for SqliteSessionStorage {
async fn is_initialized(&self) -> MmResult<bool, Self::Error> {
let lock = self.lock_db().await;
validate_table_name(SESSION_TABLE_NAME).map_err(AsyncConnError::from)?;

lock.call(move |conn| {
let initialized = query_single_row(conn, CHECK_TABLE_EXISTS_SQL, [SESSION_TABLE_NAME], string_from_row)?;
Ok(initialized.is_some())
Expand All @@ -76,7 +75,6 @@ impl WalletConnectStorageOps for SqliteSessionStorage {

async fn save_session(&self, session: &Session) -> MmResult<(), Self::Error> {
debug!("[{}] Saving WalletConnect session to storage", session.topic);
validate_table_name(SESSION_TABLE_NAME).map_err(AsyncConnError::from)?;
let lock = self.lock_db().await;

let session = session.clone();
Expand All @@ -102,7 +100,6 @@ impl WalletConnectStorageOps for SqliteSessionStorage {

async fn get_session(&self, topic: &Topic) -> MmResult<Option<Session>, Self::Error> {
debug!("[{topic}] Retrieving WalletConnect session from storage");
validate_table_name(SESSION_TABLE_NAME).map_err(AsyncConnError::from)?;
let lock = self.lock_db().await;
let topic = topic.clone();
let session_str = lock
Expand All @@ -121,7 +118,6 @@ impl WalletConnectStorageOps for SqliteSessionStorage {

async fn get_all_sessions(&self) -> MmResult<Vec<Session>, Self::Error> {
debug!("Loading WalletConnect sessions from storage");
validate_table_name(SESSION_TABLE_NAME).map_err(AsyncConnError::from)?;
let lock = self.lock_db().await;
let sessions_str = lock
.call(move |conn| {
Expand All @@ -145,7 +141,6 @@ impl WalletConnectStorageOps for SqliteSessionStorage {

async fn delete_session(&self, topic: &Topic) -> MmResult<(), Self::Error> {
debug!("[{topic}] Deleting WalletConnect session from storage");
validate_table_name(SESSION_TABLE_NAME).map_err(AsyncConnError::from)?;
let topic = topic.clone();
let lock = self.lock_db().await;
lock.call(move |conn| {
Expand All @@ -161,7 +156,6 @@ impl WalletConnectStorageOps for SqliteSessionStorage {

async fn update_session(&self, session: &Session) -> MmResult<(), Self::Error> {
debug!("[{}] Updating WalletConnect session in storage", session.topic);
validate_table_name(SESSION_TABLE_NAME).map_err(AsyncConnError::from)?;
let session = session.clone();
let lock = self.lock_db().await;
lock.call(move |conn| {
Expand Down
3 changes: 2 additions & 1 deletion mm2src/mm2_main/src/rpc/wc_commands/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ pub async fn set_active_session(
ctx: MmArc,
req: GetSessionRequest,
) -> MmResult<SessionResponse, WalletConnectRpcError> {
let ctx = WalletConnectCtx::from_ctx(&ctx).mm_err(|err| WalletConnectRpcError::InitializationError(err.to_string()))?;
let ctx =
WalletConnectCtx::from_ctx(&ctx).mm_err(|err| WalletConnectRpcError::InitializationError(err.to_string()))?;
ctx.session_manager
.set_active_session(&req.topic.into())
.await
Expand Down

0 comments on commit 1fec24f

Please sign in to comment.