Skip to content

Commit

Permalink
Merge pull request #1259 from WalletConnect/feature/subscriptions-ind…
Browse files Browse the repository at this point in the history
…ex-by-app

[Notify] Subscriptions index by app
  • Loading branch information
flypaper0 authored Dec 21, 2023
2 parents 8218573 + f990620 commit 12dc74c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -102,4 +102,8 @@ public struct NotifyClientFactory {

return path.absoluteString
}

static var version: String {
return "1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
""")

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 12dc74c

Please sign in to comment.