Fix UInt32 conversions to SQL in PendingTransactionDao

This commit is contained in:
Kris Nuttycombe 2022-10-19 14:13:18 -06:00
parent fae15ce268
commit 849083ffd9
3 changed files with 7 additions and 10 deletions

View File

@ -102,13 +102,13 @@ struct PendingTransaction: PendingTransactionEntity, Decodable, Encodable {
let container = try decoder.container(keyedBy: CodingKeys.self)
let toAddress: String? = try container.decodeIfPresent(String.self, forKey: .toAddress)
let toInternalAccount: UInt32? = try container.decode(UInt32.self, forKey: .toInternalAccount)
let toInternalAccount: Int? = try container.decodeIfPresent(Int.self, forKey: .toInternalAccount)
switch (toAddress, toInternalAccount) {
case let (.some(address), nil):
self.recipient = .address(Recipient.forEncodedAddress(encoded: address)!.0)
case let (nil, .some(accountId)):
self.recipient = .internalAccount(accountId)
self.recipient = .internalAccount(UInt32(accountId))
default:
throw StorageError.malformedEntity(fields: ["toAddress", "toInternalAccount"])
}
@ -135,14 +135,12 @@ struct PendingTransaction: PendingTransactionEntity, Decodable, Encodable {
var container = encoder.container(keyedBy: CodingKeys.self)
var toAddress: String?
var accountId: UInt32?
var accountId: Int?
switch (self.recipient) {
case .address(let recipient):
toAddress = recipient.stringEncoded
case .internalAccount(let acct):
accountId = acct
default:
break
accountId = Int(acct)
}
try container.encode(toAddress, forKey: .toAddress)
try container.encode(accountId, forKey: .toInternalAccount)

View File

@ -301,14 +301,14 @@ public class Initializer {
checks if the provided address is a valid sapling address
*/
public func isValidSaplingAddress(_ address: String) -> Bool {
(try? rustBackend.isValidSaplingAddress(address, networkType: network.networkType)) ?? false
rustBackend.isValidSaplingAddress(address, networkType: network.networkType)
}
/**
checks if the provided address is a transparent zAddress
*/
public func isValidTransparentAddress(_ address: String) -> Bool {
(try? rustBackend.isValidTransparentAddress(address, networkType: network.networkType)) ?? false
rustBackend.isValidTransparentAddress(address, networkType: network.networkType)
}
func isSpendParameterPresent() -> Bool {

View File

@ -20,10 +20,9 @@ class PendingTransactionRepositoryTests: XCTestCase {
super.setUp()
cleanUpDb()
let pendingDbProvider = SimpleConnectionProvider(path: try! TestDbBuilder.pendingTransactionsDbURL().absoluteString)
let dao = PendingTransactionSQLDAO(dbProvider: pendingDbProvider)
let migrations = try! MigrationManager(cacheDbConnection: InMemoryDbProvider(), pendingDbConnection: pendingDbProvider, networkType: .testnet)
try! migrations.performMigration()
pendingRepository = dao
pendingRepository = PendingTransactionSQLDAO(dbProvider: pendingDbProvider)
}
override func tearDown() {