diff --git a/wallet/src/de/schildbach/wallet/service/CoinJoinService.kt b/wallet/src/de/schildbach/wallet/service/CoinJoinService.kt index 73f8a9471..daa05a415 100644 --- a/wallet/src/de/schildbach/wallet/service/CoinJoinService.kt +++ b/wallet/src/de/schildbach/wallet/service/CoinJoinService.kt @@ -234,6 +234,15 @@ class CoinJoinMixingService @Inject constructor( } } + suspend fun getCurrentTimeSkew(): Long { + return try { + getTimeSkew() + } catch (e: Exception) { + log.info("timeshew problem", e) + return 0L + } + } + suspend fun updateTimeSkewInternal(timeSkew: Long) { updateState(config.getMode(), timeSkew, hasAnonymizableBalance, networkStatus, isSynced, blockChain) } @@ -270,7 +279,7 @@ class CoinJoinMixingService @Inject constructor( ) updateState( config.getMode(), - getTimeSkew(), + getCurrentTimeSkew(), hasBalanceLeftToMix, networkStatus, isSynced, @@ -295,7 +304,7 @@ class CoinJoinMixingService @Inject constructor( log.info( "coinjoin-new-state: $mode, $timeSkew ms, $hasAnonymizableBalance, $networkStatus, synced: $isSynced, ${blockChain != null}" ) - log.info("coinjoin-Current timeskew: ${getTimeSkew()}") + log.info("coinjoin-Current timeskew: ${getCurrentTimeSkew()}") this.networkStatus = networkStatus this.hasAnonymizableBalance = hasAnonymizableBalance this.isSynced = isSynced @@ -363,7 +372,7 @@ class CoinJoinMixingService @Inject constructor( configureMixing() updateBalance(walletDataProvider.wallet!!.getBalance(Wallet.BalanceType.AVAILABLE)) } - val currentTimeSkew = getTimeSkew() + val currentTimeSkew = getCurrentTimeSkew() updateState(mode, currentTimeSkew, hasAnonymizableBalance, networkStatus, isSynced, blockChain) } diff --git a/wallet/src/de/schildbach/wallet/util/TimeUtils.kt b/wallet/src/de/schildbach/wallet/util/TimeUtils.kt index d9aca9b3d..f3238fbe8 100644 --- a/wallet/src/de/schildbach/wallet/util/TimeUtils.kt +++ b/wallet/src/de/schildbach/wallet/util/TimeUtils.kt @@ -50,12 +50,19 @@ suspend fun getTimeSkew(): Long { // swallow, the next block will use alternate method } if (networkTime == null) { - var result = Constants.HTTP_CLIENT.head("https://www.dash.org/") - - networkTime = result.headers.getDate("date")?.time - if (networkTime == null) { - result = Constants.HTTP_CLIENT.head("https://insight.dash.org/insight") + try { + val result = Constants.HTTP_CLIENT.head("https://www.dash.org/") networkTime = result.headers.getDate("date")?.time + } catch (e: Exception) { + // swallow + } + if (networkTime == null) { + try { + val result = Constants.HTTP_CLIENT.head("https://insight.dash.org/insight") + networkTime = result.headers.getDate("date")?.time + } catch (e: Exception) { + // swallow + } } requireNotNull(networkTime) }