diff --git a/MobileWallet/Backup/ICloudBackup.swift b/MobileWallet/Backup/ICloudBackup.swift index c4dd115f..8e4dd31f 100644 --- a/MobileWallet/Backup/ICloudBackup.swift +++ b/MobileWallet/Backup/ICloudBackup.swift @@ -180,7 +180,7 @@ class ICloudBackup: NSObject { try? startObserveReachability() if FileManager.default.ubiquityIdentityToken == nil { - iCloudBackupsIsOn = false + UserDefaults.Key.iCloudBackupsIsOn.set(false) } } diff --git a/MobileWallet/TariLib/TariLib.swift b/MobileWallet/TariLib/TariLib.swift index 62c09675..1d305cbe 100644 --- a/MobileWallet/TariLib/TariLib.swift +++ b/MobileWallet/TariLib/TariLib.swift @@ -289,7 +289,6 @@ class TariLib { tariWallet = try Wallet(commsConfig: config, loggingFilePath: loggingFilePath) try setBasenode(syncAfterSetting: false) - //try setBasenode(try BaseNode(TariSettings.shared.defaultBaseNodePool["t-tbn-seoul"]!)) TariEventBus.postToMainThread(.walletServiceStarted) diff --git a/MobileWallet/TariLib/Wrappers/Utils/TariSettings.swift b/MobileWallet/TariLib/Wrappers/Utils/TariSettings.swift index 0fe83066..5d165533 100644 --- a/MobileWallet/TariLib/Wrappers/Utils/TariSettings.swift +++ b/MobileWallet/TariLib/Wrappers/Utils/TariSettings.swift @@ -90,14 +90,10 @@ struct TariSettings { let bugReportEmail = "bug_reports@tari.com" let defaultBaseNodePool: [String: String] = [ - "faucet": "2e93c460df49d8cfbbf7a06dd9004c25a84f92584f7d0ac5e30bd8e0beee9a43::/onion3/nuuq3e2olck22rudimovhmrdwkmjncxvwdgbvfxhz6myzcnx2j4rssyd:18141", - "t-tbn-nvir": "06e98e9c5eb52bd504836edec1878eccf12eb9f26a5fe5ec0e279423156e657a::/onion3/bsmuof2cn4y2ysz253gzsvg3s72fcgh4f3qcm3hdlxdtcwe6al2dicyd:18141", - "t-tbn-ncal": "3a5081a0c9ff72b2d5cf52f8d78cc5a206d643259cdeb7d934512f519e090e6c::/onion3/gfynjxfm7rcxcekhu6jwuhvyyfdjvmruvvehurmlte565v74oinv2lad:18141", - "t-tbn-oregon": "e6f3c83dc592af45ede5424974f52c776e9e6859e530066e57c1b0dd59d9b61c::/onion3/ixihtmcbvr2q53bj23bsla5hi7ek37odnsxzkapr7znyfneqxzhq7zad:18141", - "t-tbn-london": "ce2254825d0e0294d31a86c6aac18f83c9a7b3d01d9cdb6866b4b2af8fd3fd17::/onion3/gm7kxmr4cyjg5fhcw4onav2ofa3flscrocfxiiohdcys3kshdhcjeuyd:18141", - "t-tbn-stockholm": "461d4d7be657521969896f90e3f611f0c4e902ca33d3b808c03357ad86fd7801::/onion3/4me2aw6auq2ucql34uuvsegtjxmvsmcyk55qprtrpqxvu3whxajvb5ad:18141", - "t-tbn-seoul": "d440b328e69b20dd8ee6c4a61aeb18888939f0f67cf96668840b7f72055d834c::/onion3/j5x7xkcxnrich5lcwibwszd5kylclbf6a5unert5sy6ykio2kphnopad:18141", - "t-tbn-sydney": "b81b4071f72418cc410166d9baf0c6ef7a8c309e64671fafbbed88f7e1ee7709::/onion3/lwwcv4nq7epgem5vdcawom4mquqsw2odbwfcjzv3j6sksx4gr24e52ad:18141" + "t-tbn-nvir": "30c9e74dcf2a3f967457cf10f09b0cb2d0b112b6e98fc76bf64cf27597a6961f::/onion3/zyjmhhwj572dnizdbe672vzzyqfmlzjs4k4mp4bmso6wysn2megndzad:18141", + "t-tbn-oregon": "e856839057aac496b9e25f10821116d02b58f20129e9b9ba681b830568e47c4d::/onion3/exe2zgehnw3tvrbef3ep6taiacr6sdyeb54be2s25fpru357r4skhtad:18141", + "t-tbn-stockholm": "106ca872ec83bc2522bce7e4b35b86c4a598297312cf46ce38caf0b497cf6748::/onion3/hf3n3btfh4tfh2n6afvxs5m6lqkyjlqlj3bm4todjjdcngapa4phhoyd:18141", + "t-tbn-sydney": "ac7fba427913a653a27b69c05549e14d9e87cb7849ea0c740d6c8a5855a3882a::/onion3/avteohvrvvfy4fff7ona2wy6yhb7i4ss4aklp74v64knofvev3vd5yyd:18141" ] var pushServerApiKey: String? diff --git a/MobileWallet/TariLib/Wrappers/Wallet.swift b/MobileWallet/TariLib/Wrappers/Wallet.swift index dbe14fe3..3e96006a 100644 --- a/MobileWallet/TariLib/Wrappers/Wallet.swift +++ b/MobileWallet/TariLib/Wrappers/Wallet.swift @@ -600,6 +600,53 @@ class Wallet { return result } + func setKeyValue(key: String, value: String) throws -> Bool { + var errorCode: Int32 = -1 + let keyPointer = (key as NSString).utf8String + let valuePointer = (value as NSString).utf8String + + let result = withUnsafeMutablePointer(to: &errorCode) { + error in + wallet_set_key_value(ptr, keyPointer, valuePointer, error) + } + guard errorCode == 0 else { + throw WalletErrors.generic(errorCode) + } + return result + } + + func getKeyValue(key: String) throws -> String { + var errorCode: Int32 = -1 + let keyPointer = (key as NSString).utf8String + let resultPtr = withUnsafeMutablePointer(to: &errorCode) { + error in + wallet_get_value(ptr, keyPointer, error) + } + guard errorCode == 0 else { + throw WalletErrors.generic(errorCode) + } + + let result = String(cString: resultPtr!) + let mutable = UnsafeMutablePointer(mutating: resultPtr!) + string_destroy(mutable) + + return result + } + + func removeKeyValue(key: String) throws -> Bool { + var errorCode: Int32 = -1 + let keyPointer = (key as NSString).utf8String + + let result = withUnsafeMutablePointer(to: &errorCode) { + error in + wallet_clear_value(ptr, keyPointer, error) + } + guard errorCode == 0 else { + throw WalletErrors.generic(errorCode) + } + return result + } + deinit { TariLogger.warn("Wallet destroy") wallet_destroy(ptr) diff --git a/MobileWallet/TariLib/wallet.h b/MobileWallet/TariLib/wallet.h index 488a7496..425b9d9a 100644 --- a/MobileWallet/TariLib/wallet.h +++ b/MobileWallet/TariLib/wallet.h @@ -75,6 +75,12 @@ struct TariSeedWords; struct EmojiSet; +struct TariExcess; + +struct TariExcessPublicNonce; + +struct TariExcessSignature; + /// -------------------------------- Transport Types ----------------------------------------------- /// // Creates a memory transport type @@ -237,6 +243,24 @@ bool completed_transaction_is_outbound(struct TariCompletedTransaction *tx,int* // Frees memory for a TariCompletedTransaction void completed_transaction_destroy(struct TariCompletedTransaction *transaction); +// Gets the TariExcess of a TariCompletedTransaction +struct TariExcess *completed_transaction_get_excess(struct TariCompletedTransaction *transaction,int* error_out); + +// Gets the TariExcessPublicNonce of a TariCompletedTransaction +struct TariExcessPublicNonce *completed_transaction_get_public_nonce(struct TariCompletedTransaction *transaction,int* error_out); + +// Gets the TariExcessSignature of a TariCompletedTransaction +struct TariExcessSignature *completed_transaction_get_signature(struct TariCompletedTransaction *transaction,int* error_out); + +// Frees memory for a TariExcess +void excess_destroy(struct TariExcess *excess); + +// Frees memory for a TariExcessPublicNonce +void nonce_destroy(struct TariExcessPublicNonce *nonce); + +// Frees memory for a TariExcessSignature +void signature_destroy(struct TariExcessSignature *signature); + /// -------------------------------- CompletedTransactions ------------------------------------------------------ /// // Gets number of elements in TariCompletedTransactions @@ -515,6 +539,56 @@ void wallet_apply_encryption(struct TariWallet *wallet, const char *passphrase, // be removed. If it is not encrypted then this function will still succeed to make the operation idempotent void wallet_remove_encryption(struct TariWallet *wallet, int* error_out); +/// Set a Key Value in the Wallet storage used for Client Key Value store +/// +/// ## Arguments +/// `wallet` - The TariWallet pointer. +/// `key` - The pointer to a Utf8 string representing the Key +/// `value` - The pointer to a Utf8 string representing the Value ot be stored +/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions +/// as an out parameter. +/// +/// ## Returns +/// `bool` - Return a boolean value indicating the operation's success or failure. The error_ptr will hold the error +/// code if there was a failure +/// +/// # Safety +/// None +bool wallet_set_key_value(struct TariWallet *wallet, const char* key, const char* value, int* error_out); + +/// get a stored Value that was previously stored in the Wallet storage used for Client Key Value store +/// +/// ## Arguments +/// `wallet` - The TariWallet pointer. +/// `key` - The pointer to a Utf8 string representing the Key +/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions +/// as an out parameter. +/// +/// ## Returns +/// `*mut c_char` - Returns a pointer to a char array of the Value string. Note that it returns an null pointer if an +/// error occured. +/// +/// # Safety +/// The ```string_destroy``` method must be called when finished with a string from rust to prevent a memory leak +const char *wallet_get_value(struct TariWallet *wallet, const char* key, int* error_out); + +/// Clears a Value for the provided Key Value in the Wallet storage used for Client Key Value store +/// +/// ## Arguments +/// `wallet` - The TariWallet pointer. +/// `key` - The pointer to a Utf8 string representing the Key +/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions +/// as an out parameter. +/// +/// ## Returns +/// `bool` - Return a boolean value indicating the operation's success or failure. The error_ptr will hold the error +/// code if there was a failure +/// +/// # Safety +/// None +bool wallet_clear_value(struct TariWallet *wallet, const char* key, int* error_out); + + // Frees memory for a TariWallet void wallet_destroy(struct TariWallet *wallet); diff --git a/MobileWalletTests/MobileWalletTests.swift b/MobileWalletTests/MobileWalletTests.swift index 9b70c5ba..4b3e95b2 100644 --- a/MobileWalletTests/MobileWalletTests.swift +++ b/MobileWalletTests/MobileWalletTests.swift @@ -85,8 +85,17 @@ class MobileWalletTests: XCTestCase { /* Today Date Test */ - XCTAssertEqual(Date().addingTimeInterval(-120).relativeDayFromToday(), "2m ago") - XCTAssertEqual(Date().addingTimeInterval(-(60 * 60 * 2)).relativeDayFromToday(), "2h ago") + let calendar = NSCalendar.autoupdatingCurrent + let twoMinutesAgo = Date().addingTimeInterval(-120) + XCTAssertEqual( + twoMinutesAgo.relativeDayFromToday(), + calendar.isDateInYesterday(twoMinutesAgo) ? "Yesterday" : "2m ago" + ) + let twoHoursAgo = Date().addingTimeInterval(-(60 * 60 * 2)) + XCTAssertEqual( + twoHoursAgo.relativeDayFromToday(), + calendar.isDateInYesterday(twoHoursAgo) ? "Yesterday" : "2h ago" + ) /* Yesterday Date Test diff --git a/MobileWalletTests/TariLibWrapperTests.swift b/MobileWalletTests/TariLibWrapperTests.swift index 86a0306b..8ca4ab66 100644 --- a/MobileWalletTests/TariLibWrapperTests.swift +++ b/MobileWalletTests/TariLibWrapperTests.swift @@ -347,6 +347,22 @@ class TariLibWrapperTests: XCTestCase { XCTAssertThrowsError(try MicroTari(decimalValue: 0.123456789)) } + func testKeyValueStorage() { + TariLogger.info("TEST KEY VALUE STORAGE") + let (wallet, _) = createWallet(privateHex: nil) + // random key + let key = "7SXVVFERUP" + let value = "DQORS7M0EO_⚽🧣👂🤝🏧_X6IZFL5OG3" + // store value + XCTAssert(try wallet.setKeyValue(key: key, value: value)) + // get value + XCTAssertEqual(value, try wallet.getKeyValue(key: key)) + // clear value + XCTAssert(try wallet.removeKeyValue(key: key)) + // value cleared, "get" should throw error + XCTAssertThrowsError(try wallet.getKeyValue(key: key)) + } + func restoreWallet(completion: @escaping ((_ wallet: Wallet?, _ error: Error?) -> Void)) { ICloudBackup.shared.restoreWallet(password: backupPassword, completion: { error in var commsConfig: CommsConfig? diff --git a/dependencies.env b/dependencies.env index 8290eadf..f9adcd27 100644 --- a/dependencies.env +++ b/dependencies.env @@ -1 +1 @@ -FFI_VERSION="0.16.4" +FFI_VERSION="0.16.9"