Round down birthday calculation.

This commit is contained in:
Kevin Gorham 2020-09-25 11:41:00 -04:00
parent b6a71d535e
commit 34b01347b7
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 7 additions and 1 deletions

View File

@ -89,12 +89,18 @@ class BackupFragment : BaseFragment<FragmentBackupBinding>() {
}
}
// 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")
}