From 28de2d44bc1f0ae11039c55edaaeaf01dd53bf95 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Fri, 15 Dec 2023 18:03:10 +0300 Subject: [PATCH 1/2] Index by dapp --- .../WalletConnectNotify/Client/Wallet/NotifyDatabase.swift | 5 +++-- .../Types/DataStructures/NotifySubscription.swift | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyDatabase.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyDatabase.swift index 9e6110e2b..422196905 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyDatabase.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyDatabase.swift @@ -110,14 +110,15 @@ private extension NotifyDatabase { try sqlite.execute(sql: """ CREATE TABLE IF NOT EXISTS \(Table.subscriptions) ( - topic TEXT PRIMARY KEY, + topic TEXT NOT NULL, account TEXT NOT NULL, relay TEXT NOT NULL, metadata TEXT NOT NULL, scope TEXT NOT NULL, expiry TEXT NOT NULL, symKey TEXT NOT NULL, - appAuthenticationKey TEXT NOT NULL + appAuthenticationKey TEXT NOT NULL, + id TEXT PRIMARY KEY ); """) diff --git a/Sources/WalletConnectNotify/Types/DataStructures/NotifySubscription.swift b/Sources/WalletConnectNotify/Types/DataStructures/NotifySubscription.swift index 9a5ac3609..a63ef14bb 100644 --- a/Sources/WalletConnectNotify/Types/DataStructures/NotifySubscription.swift +++ b/Sources/WalletConnectNotify/Types/DataStructures/NotifySubscription.swift @@ -1,7 +1,7 @@ import Foundation import Database -public struct NotifySubscription: DatabaseObject, SqliteRow { +public struct NotifySubscription: Codable, Equatable, SqliteRow { public let topic: String public let account: Account public let relay: RelayProtocolOptions @@ -11,8 +11,8 @@ public struct NotifySubscription: DatabaseObject, SqliteRow { public let symKey: String public let appAuthenticationKey: String - public var databaseId: String { - return topic + private var id: String { + return "\(account.absoluteString)-\(metadata.url)" } public init(decoder: SqliteRowDecoder) throws { @@ -36,6 +36,7 @@ public struct NotifySubscription: DatabaseObject, SqliteRow { encoder.encodeDate(expiry, for: "expiry") encoder.encodeString(symKey, for: "symKey") encoder.encodeString(appAuthenticationKey, for: "appAuthenticationKey") + encoder.encodeString(id, for: "id") return encoder } From f9906207b3c2fd6298347647ce6d0e428ca99306 Mon Sep 17 00:00:00 2001 From: Artur Guseinov Date: Fri, 15 Dec 2023 18:11:19 +0300 Subject: [PATCH 2/2] Notify DB versioning --- .../Client/Wallet/NotifyClientFactory.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift index 99cff45c5..3a08a5727 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyClientFactory.swift @@ -7,7 +7,7 @@ public struct NotifyClientFactory { let keyserverURL = URL(string: "https://keys.walletconnect.com")! let keychainStorage = KeychainStorage(serviceIdentifier: "com.walletconnect.sdk", accessGroup: groupIdentifier) let groupKeychainService = GroupKeychainStorage(serviceIdentifier: groupIdentifier) - let databasePath = databasePath(appGroup: groupIdentifier, database: "notify.db") + let databasePath = databasePath(appGroup: groupIdentifier, database: "notify_v\(version).db") let sqlite = DiskSqlite(path: databasePath) return NotifyClientFactory.create( @@ -102,4 +102,8 @@ public struct NotifyClientFactory { return path.absoluteString } + + static var version: String { + return "1" + } }