diff --git a/app/src/main/java/cash/z/ecc/android/ui/setup/BackupFragment.kt b/app/src/main/java/cash/z/ecc/android/ui/setup/BackupFragment.kt index 64aef46..5bf9cd2 100644 --- a/app/src/main/java/cash/z/ecc/android/ui/setup/BackupFragment.kt +++ b/app/src/main/java/cash/z/ecc/android/ui/setup/BackupFragment.kt @@ -89,12 +89,18 @@ class BackupFragment : BaseFragment() { } } + // TODO: move this into the SDK private suspend fun calculateBirthday(): Int { var storedBirthday: Int = 0 var oldestTransactionHeight:Int = 0 try { - storedBirthday = walletSetup.loadBirthdayHeight() + storedBirthday = walletSetup.loadBirthdayHeight() ?: 0 oldestTransactionHeight = mainActivity?.synchronizerComponent?.synchronizer()?.receivedTransactions?.first()?.last()?.minedHeight ?: 0 + // to be safe adjust for reorgs (and generally a little cushion is good for privacy) + // so we round down to the nearest 100 and then subtract 100 to ensure that the result is always at least 100 blocks away + oldestTransactionHeight = ZcashSdk.MAX_REORG_SIZE.let { boundary -> + oldestTransactionHeight.let { it - it.rem(boundary) - boundary } + } } catch (t: Throwable) { twig("failed to calculate birthday due to: $t") }