From 2132bc14fd980130f3f787cfbdb813b297ee2088 Mon Sep 17 00:00:00 2001 From: Kevin Gorham Date: Thu, 14 Feb 2019 16:45:49 -0500 Subject: [PATCH] Fix bugs --- .gitignore | 3 +++ build.gradle | 5 +---- .../cash/z/wallet/sdk/data/ActiveTransactionManager.kt | 3 ++- src/main/java/cash/z/wallet/sdk/data/MockSynchronizer.kt | 6 ++++-- .../cash/z/wallet/sdk/data/PollingTransactionRepository.kt | 7 ++++--- src/main/java/cash/z/wallet/sdk/exception/Exceptions.kt | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 9188fab0..041535d6 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,6 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md + +# other +DecompileChecker.kt diff --git a/build.gradle b/build.gradle index eb078b2e..0fada87f 100644 --- a/build.gradle +++ b/build.gradle @@ -74,10 +74,7 @@ android { } } } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } + kotlinOptions { // Allow the use of Result objects understanding that if the API changes, we'll have to fix it before upgrading our kotlin version freeCompilerArgs = ["-Xallow-result-return-type"] diff --git a/src/main/java/cash/z/wallet/sdk/data/ActiveTransactionManager.kt b/src/main/java/cash/z/wallet/sdk/data/ActiveTransactionManager.kt index dfe9b3f5..be9adb32 100644 --- a/src/main/java/cash/z/wallet/sdk/data/ActiveTransactionManager.kt +++ b/src/main/java/cash/z/wallet/sdk/data/ActiveTransactionManager.kt @@ -169,7 +169,7 @@ class ActiveTransactionManager( twig("transaction $transactionId HAS BEEN MINED!!! updating the corresponding active transaction.") tx.height.set(matchingDbTransaction.height) twig("active transaction height updated to ${matchingDbTransaction.height} and state updated to AwaitingConfirmations(0)") - setState(transaction, AwaitingConfirmations(0)) + setState(transaction, AwaitingConfirmations(1)) } else { twig("transaction $transactionId has still not been mined.") } @@ -217,6 +217,7 @@ class ActiveTransactionManager( created(activeSendTransaction, transactionId) uploadRawTransaction(transactionId, activeSendTransaction, transactionRaw) + //TODO: synchronously await confirmations by checking periodically inside a while loop until confirmations = 10 } private suspend fun uploadRawTransaction( diff --git a/src/main/java/cash/z/wallet/sdk/data/MockSynchronizer.kt b/src/main/java/cash/z/wallet/sdk/data/MockSynchronizer.kt index 3d5d243f..43465259 100644 --- a/src/main/java/cash/z/wallet/sdk/data/MockSynchronizer.kt +++ b/src/main/java/cash/z/wallet/sdk/data/MockSynchronizer.kt @@ -24,7 +24,9 @@ import kotlin.random.nextLong */ open class MockSynchronizer( private val transactionInterval: Long = 30_000L, - private val activeTransactionUpdateFrequency: Long = 3_000L + private val activeTransactionUpdateFrequency: Long = 3_000L, + private val isFirstRun: Boolean = Random.nextBoolean(), + private val isOutOfSync: Boolean = Random.nextBoolean() ) : Synchronizer, CoroutineScope { private val mockAddress = "ztestsaplingmock0000this0is0a0mock0address0do0not0send0funds0to0this0address0ok0thanks00" @@ -67,7 +69,7 @@ open class MockSynchronizer( } override suspend fun isFirstRun(): Boolean { - return Random.nextBoolean() + return isFirstRun } override fun getAddress() = mockAddress diff --git a/src/main/java/cash/z/wallet/sdk/data/PollingTransactionRepository.kt b/src/main/java/cash/z/wallet/sdk/data/PollingTransactionRepository.kt index 9d651f0f..ca24afd8 100644 --- a/src/main/java/cash/z/wallet/sdk/data/PollingTransactionRepository.kt +++ b/src/main/java/cash/z/wallet/sdk/data/PollingTransactionRepository.kt @@ -79,9 +79,10 @@ open class PollingTransactionRepository( twig("stopping") // when polling ends, we call stop which can result in a duplicate call to stop // So keep stop idempotent, rather than crashing with "Channel was closed" errors - if (!balanceChannel.isClosedForSend) balanceChannel.cancel() - if (!allTransactionsChannel.isClosedForSend) allTransactionsChannel.cancel() - if (!pollingJob.isCancelled) pollingJob.cancel() + // probably should make a safeCancel extension function for this and use it everywhere that we cancel a channel + try{ if (!balanceChannel.isClosedForSend) balanceChannel.cancel() }catch (t:Throwable){} + try{ if (!allTransactionsChannel.isClosedForSend) allTransactionsChannel.cancel() }catch (t:Throwable){} + try{ if (!pollingJob.isCancelled) pollingJob.cancel() }catch (t:Throwable){} } override fun balance(): ReceiveChannel { diff --git a/src/main/java/cash/z/wallet/sdk/exception/Exceptions.kt b/src/main/java/cash/z/wallet/sdk/exception/Exceptions.kt index 5742cccb..5363932e 100644 --- a/src/main/java/cash/z/wallet/sdk/exception/Exceptions.kt +++ b/src/main/java/cash/z/wallet/sdk/exception/Exceptions.kt @@ -20,7 +20,7 @@ sealed class RepositoryException(message: String, cause: Throwable? = null) : Ru } sealed class SynchronizerException(message: String, cause: Throwable? = null) : RuntimeException(message, cause) { - object FalseStart: SynchronizerException("Once a synchronizer has stopped it cannotbe restarted. Instead, a new " + + object FalseStart: SynchronizerException("Once a synchronizer has stopped it cannot be restarted. Instead, a new " + "instance should be created.") }