Skip to content

Commit e16cd32

Browse files
Merge pull request #183 from ostdotcom/develop
EnableIOSDeviceRestore flag added.
2 parents fba0b55 + 7c7a146 commit e16cd32

File tree

18 files changed

+288
-51
lines changed

18 files changed

+288
-51
lines changed

CHANGELOG.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# OST Wallet SDK Changelog
22

3+
## Version 2.3.4
4+
### Feature:
5+
* Developer can decide whether use existing keys or create new keys for User on application reinstall by setting `EnableIOSDeviceRestore` flag in `OstWalletSdk.plist`.
6+
### Bug Fix:
7+
* Fetching data from database fix.
8+
39
## Version 2.3.3
410
### Bug Fix:
511
* OstWalletSdkUI issue fixed for iOS 13.
612

13+
714
## Version 2.3.2
815
### Bug Fix:
916
* Handling of invalid OstWalletSdk config added.

OstWalletSdk.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@
20072007
"@executable_path/Frameworks",
20082008
"@loader_path/Frameworks",
20092009
);
2010-
MARKETING_VERSION = 2.3.3;
2010+
MARKETING_VERSION = 2.3.4;
20112011
PRODUCT_BUNDLE_IDENTIFIER = com.ost.OstWalletSdk;
20122012
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
20132013
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -2043,7 +2043,7 @@
20432043
"@executable_path/Frameworks",
20442044
"@loader_path/Frameworks",
20452045
);
2046-
MARKETING_VERSION = 2.3.3;
2046+
MARKETING_VERSION = "2.3.4";
20472047
PRODUCT_BUNDLE_IDENTIFIER = com.ost.OstWalletSdk;
20482048
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
20492049
PROVISIONING_PROFILE_SPECIFIER = "";

OstWalletSdk/Database/DBQueries/OstBaseDbQueries.swift

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ class OstBaseDbQueries {
1919
static let STATUS = "status"
2020
static let UTS = "uts"
2121

22-
static let queue = DispatchQueue(label: "db", qos: .background, attributes: .concurrent)
22+
static let dbUpdateQueue = DispatchQueue(label: "com.ost.sdk.db", qos: .background, attributes: .concurrent)
23+
static let dbSelectQueue = DispatchQueue(label: "com.ost.sdk.db.select", qos: .userInitiated, attributes: .concurrent)
2324
weak var dbQueue: FMDatabaseQueue?
2425
weak var db: FMDatabase?
25-
26+
27+
static let _writeQueue: OperationQueue = OperationQueue()
28+
static let _writeQueueLock: NSRecursiveLock = NSRecursiveLock()
29+
30+
private let maxConcurrentOperationCount = 1
31+
private var selectQueryCount = 0
2632
/// Initializer
2733
init() {
2834
db = getDb()
2935
dbQueue = getDbQueue()
36+
OstBaseDbQueries._writeQueue.maxConcurrentOperationCount = 1
3037
}
3138

3239
/// Get DB instance
@@ -99,15 +106,31 @@ class OstBaseDbQueries {
99106
/// - Returns: Array<[String: Any?]>, Array of dictionary
100107
/// - Throws: OstError
101108
func executeQuery(_ query: String) throws -> Array<[String: Any?]>? {
102-
do {
103-
if let resultSet: FMResultSet = try db?.executeQuery(query, values: nil) ?? nil {
104-
let result = getEntityDataFromResultSet(resultSet)
105-
return result
109+
var result:Array<[String: Any?]>? = nil;
110+
var err:OstError? = nil;
111+
selectQueryCount += 1
112+
if selectQueryCount == 1 {
113+
OstBaseDbQueries._writeQueueLock.lock()
114+
}
115+
OstBaseDbQueries.dbSelectQueue.sync {
116+
do {
117+
if let resultSet: FMResultSet = try db?.executeQuery(query, values: nil) ?? nil {
118+
result = self.getEntityDataFromResultSet(resultSet)
119+
}
120+
} catch {
121+
err = OstError("d_dbq_bdq_eq_1", .dbExecutionFailed)
106122
}
107-
return nil
108-
} catch {
109-
throw OstError("d_dbq_bdq_eq_1", .dbExecutionFailed)
110123
}
124+
125+
if nil != err {
126+
throw err!
127+
}
128+
129+
selectQueryCount -= 1
130+
if selectQueryCount == 0 {
131+
OstBaseDbQueries._writeQueueLock.unlock()
132+
}
133+
return result;
111134
}
112135

113136
/// Execute batch statements
@@ -125,10 +148,21 @@ class OstBaseDbQueries {
125148
/// - values: Value that needs to be updated
126149
/// - Returns: `true` if succcessful otherwise `false`
127150
func executeUpdate(_ query: String, values: [String: Any], onUpdate:@escaping ((Bool) -> Void)){
128-
dbQueue?.inTransaction({ (fmdb, nil) in
151+
// OstBaseDbQueries.dbUpdateQueue.sync {
152+
OstBaseDbQueries._writeQueue.addOperation {
153+
OstBaseDbQueries._writeQueueLock.lock()
154+
// self.dbQueue?.inDatabase({ (fmdb) in
155+
self.dbQueue?.inTransaction({ (fmdb, nil) in
156+
129157
let updateResult:Bool = fmdb.executeUpdate(query, withParameterDictionary: values)
158+
if !updateResult {
159+
160+
}
130161
onUpdate(updateResult)
131-
})
162+
OstBaseDbQueries._writeQueueLock.unlock()
163+
})
164+
}
165+
// }
132166
}
133167

134168
// MARK: - Database Structure

OstWalletSdk/Models/Entities/OstUser.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class OstUser: OstBaseEntity {
2020
/// User status
2121
enum Status: String {
2222
case CREATED = "CREATED"
23+
case REGISTERED = "REGISTERED"
2324
case ACTIVATING = "ACTIVATING"
2425
case ACTIVATED = "ACTIVATED"
2526
}

OstWalletSdk/Models/Impls/OstBaseModelCacheRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212

1313
class OstBaseModelCacheRepository: OstBaseModelRepository {
1414
/// Max entity cache count
15-
private static let MAX_CACHE_COUNT = 5
15+
private static let MAX_CACHE_COUNT = 100
1616

1717
/// Cache object
1818
private var entityCache: NSCache<NSString, OstBaseEntity>?

OstWalletSdk/Models/Impls/OstRuleModelRepository.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Foundation
1212

1313
class OstRuleModelRepository: OstBaseModelCacheRepository{
1414
static let sharedRule = OstRuleModelRepository()
15+
static var tokenRules:[String:Set<String>] = [:];
1516

1617
//MARK: - overrider
1718

@@ -30,4 +31,45 @@ class OstRuleModelRepository: OstBaseModelCacheRepository{
3031
override func getEntity(_ data: [String : Any?]) throws -> OstRule {
3132
return try OstRule(data as [String : Any])
3233
}
34+
35+
override func insertOrUpdateEntity(_ entity: OstBaseEntity, _ isSynchronous: Bool = false) {
36+
super.insertOrUpdateEntity( entity, isSynchronous );
37+
if ( nil == entity.parentId) {
38+
// Just for peace of mind.
39+
return;
40+
}
41+
42+
var ruleAddresses:Set<String>? = OstRuleModelRepository.tokenRules[entity.parentId!];
43+
if ( nil == ruleAddresses) {
44+
// Create a new set.
45+
ruleAddresses = Set();
46+
}
47+
// Insert into set.
48+
ruleAddresses!.insert(entity.id);
49+
50+
OstRuleModelRepository.tokenRules[entity.parentId!] = ruleAddresses;
51+
}
52+
53+
54+
override func getByParentId(_ parentId: String) throws -> [OstBaseEntity]? {
55+
56+
let ruleAddresses:Set<String>? = OstRuleModelRepository.tokenRules[parentId];
57+
if ( nil == ruleAddresses ) {
58+
// Get from DB.
59+
return try super.getByParentId( parentId );
60+
}
61+
62+
var results:[OstBaseEntity] = [];
63+
for ruleAddress in ruleAddresses! {
64+
let rule = try self.getById( ruleAddress );
65+
if ( nil == rule ) {
66+
continue;
67+
}
68+
69+
results.append( rule! );
70+
}
71+
72+
return results;
73+
}
74+
3375
}

OstWalletSdk/Network/OstAPIBase.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,3 @@ class OstAPIBase {
219219
return url?.host
220220
}
221221
}
222-

OstWalletSdk/Network/OstAPIDevice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OstAPIDevice: OstAPIBase {
3636

3737
// Get current device
3838
guard let currentDevice = user.getCurrentDevice() else {
39-
throw OstError("n_ad_gcd_1", .deviceNotSet)
39+
throw OstError("n_ad_gcd_2", .deviceNotSet)
4040
}
4141
try self.getDevice(deviceAddress: currentDevice.address!, onSuccess: onSuccess, onFailure: onFailure)
4242
}

OstWalletSdk/OstConfig.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class OstConfig {
4343
private static var sessionBufferTime: Double?
4444
private static var useSeedPassword: Bool?
4545
private static var noOfSessionsOnActivateUser: Int?
46+
private static var enableIOSDeviceRestore: Bool?
4647

4748
//Defaults
4849
private static let blockGenerationTimeDefault = 3
@@ -52,7 +53,7 @@ class OstConfig {
5253
private static let sessionBufferTimeDefault = Double(3600)
5354
private static let useSeedPasswordDefault = false
5455
private static let noOfSessionsOnActivateUserDefault = 1
55-
56+
private static let enableIOSDeviceRestoreDefault = false
5657

5758
class func loadConfig(config: [String: Any]?) throws {
5859
var appConfig: [String: Any]? = config
@@ -126,6 +127,9 @@ class OstConfig {
126127
let canUseSeedPassword = getConfigValueForUseSeedPassword(appConfig: appConfig!) as? Bool
127128
useSeedPassword = canUseSeedPassword
128129

130+
let canUseEnableIOSDeviceRestore = getConfigValueForEnableIOSDeviceRestore(appConfig: appConfig!) as? Bool
131+
enableIOSDeviceRestore = canUseEnableIOSDeviceRestore
132+
129133
if let noOfSessionsOnActivateUserCount = getConfigValueForNoOfSessionsOnActivateUser(appConfig: appConfig!) {
130134
if noOfSessionsOnActivateUserCount is Int {
131135
let nosoauc = noOfSessionsOnActivateUserCount as! Int
@@ -183,6 +187,13 @@ class OstConfig {
183187
return appConfig["USE_SEED_PASSWORD"]
184188
}
185189

190+
class func getConfigValueForEnableIOSDeviceRestore(appConfig: [String: Any]) -> Any?{
191+
if let val = appConfig["EnableIOSDeviceRestore"] {
192+
return val
193+
}
194+
return appConfig["ENABLE_IOS_DEVICE_RESTORE"]
195+
}
196+
186197
class func getConfigValueForNoOfSessionsOnActivateUser(appConfig: [String: Any]) -> Any?{
187198
if let val = appConfig["NoOfSessionsOnActivateUser"] {
188199
return val
@@ -215,6 +226,10 @@ class OstConfig {
215226
return useSeedPassword ?? useSeedPasswordDefault
216227
}
217228

229+
class func shouldUseEnableIOSDeviceRestoreValues() -> Bool {
230+
return enableIOSDeviceRestore ?? enableIOSDeviceRestoreDefault
231+
}
232+
218233
class func noOfSessionsOnActivateUserCount() -> Int {
219234
return noOfSessionsOnActivateUser ?? noOfSessionsOnActivateUserDefault
220235
}

OstWalletSdk/Security/ECKeyInteract/DeviceManagerSigner/OstDeviceManagerSignerBase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class OstDeviceManagerSignerBase {
5454
let encodedABIHex = try getEncodedABI()
5555

5656
guard let toAddress = getToAddress() else {
57-
throw OstError("w_a_ab_a_1", .toAddressNotFound)
57+
throw OstError("s_ecki_dms_dmsb_gap_3", .toAddressNotFound)
5858
}
5959

6060
let typedDataInput: [String: Any] = try GnosisSafe().getSafeTxData(verifyingContract: self.deviceManager!.address!,
@@ -80,12 +80,12 @@ class OstDeviceManagerSignerBase {
8080

8181
if (nil == signature
8282
|| signature!.isEmpty) {
83-
throw OstError("q_a_ab_a_2", .signatureGenerationFailed)
83+
throw OstError("s_ecki_dms_dmsb_gap_4", .signatureGenerationFailed)
8484
}
8585

8686
if (nil == signerAddress
8787
|| signerAddress!.isEmpty) {
88-
throw OstError("q_a_ab_a_2", .signerAddressNotFound)
88+
throw OstError("s_ecki_dms_dmsb_gap_5", .signerAddressNotFound)
8989
}
9090

9191
let rawCallData: String = getRawCallData()

0 commit comments

Comments
 (0)