Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed Jan 10, 2025
1 parent a932d19 commit 1fd0565
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
26 changes: 13 additions & 13 deletions wallet/src/de/schildbach/wallet/transactions/WalletObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WalletObserver(private val wallet: Wallet) {
observeTxConfidence: Boolean,
vararg filters: TransactionFilter
): Flow<Transaction> = callbackFlow {
log.info("PERF: observing transactions start {}", this@WalletObserver)
log.info("observing transactions start {}", this@WalletObserver)
try {
Context.propagate(wallet.context)
Threading.USER_THREAD.execute {
Expand All @@ -80,7 +80,7 @@ class WalletObserver(private val wallet: Wallet) {
Looper.prepare()
}
} catch (e: Exception) {
log.error("PERF: Error during threading setup", e)
log.error("Error during threading setup", e)
close(e) // Propagate error to Flow
}
}
Expand All @@ -92,38 +92,38 @@ class WalletObserver(private val wallet: Wallet) {
try {
val oneHourAgo = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)
if (tx != null && (filters.isEmpty() || filters.any { it.matches(tx) })) {
// log.info("PERF: observing transaction sent: {} [=====] {}", tx.txId, this@WalletObserver)
// log.info("observing transaction sent: {} [=====] {}", tx.txId, this@WalletObserver)
if (tx.updateTime.time > oneHourAgo && observeTxConfidence) {
transactions[tx.txId] = tx
tx.confidence.addEventListener(Threading.USER_THREAD, transactionConfidenceListener)
// log.info("observing transaction: start listening to {}", tx.txId)
}
trySend(tx).onFailure {
log.error("PERF: Failed to send transaction sent event", it)
log.error("Failed to send transaction sent event", it)
}
}
} catch (e: Exception) {
log.error("PERF: Error in coinsSentListener", e)
log.error("Error in coinsSentListener", e)
close(e)
}
}

val coinsReceivedListener = WalletCoinsReceivedEventListener { _, tx: Transaction?, _, _ ->
try {
if (tx != null && (filters.isEmpty() || filters.any { it.matches(tx) })) {
// log.info("observing transaction received: {} [=====] {}", tx.txId, this@WalletObserver)
// log.info("observing transaction received: {} [=====] {}", tx.txId, this@WalletObserver)
val oneHourAgo = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(1)
if (tx.updateTime.time > oneHourAgo && observeTxConfidence) {
transactions[tx.txId] = tx
tx.confidence.addEventListener(Threading.USER_THREAD, transactionConfidenceListener)
// log.info("observing transaction: start listening to {}", tx.txId)
}
trySend(tx).onFailure {
log.error("PERF: Failed to send transaction received event", it)
log.error("Failed to send transaction received event", it)
}
}
} catch (e: Exception) {
log.error("PERF: Error in coinsReceivedListener", e)
log.error("Error in coinsReceivedListener", e)
close(e)
}
}
Expand All @@ -133,9 +133,9 @@ class WalletObserver(private val wallet: Wallet) {
try {
val tx = transactions[transactionConfidence.transactionHash]
if (tx != null && (filters.isEmpty() || filters.any { it.matches(tx) })) {
// log.info("observing transaction conf {} [=====] {}", tx.txId, this@WalletObserver)
// log.info("observing transaction conf {} [=====] {}", tx.txId, this@WalletObserver)
trySend(tx).onFailure {
log.error("PERF: Failed to send transaction confidence event", it)
log.error("Failed to send transaction confidence event", it)
}
}
val shouldStopListening = when (changeReason) {
Expand All @@ -150,7 +150,7 @@ class WalletObserver(private val wallet: Wallet) {
transactions.remove(transactionConfidence.transactionHash)
}
} catch (e: Exception) {
log.error("PERF: Error in transactionConfidenceChangedListener", e)
log.error("Error in transactionConfidenceChangedListener", e)
close(e)
}
}
Expand All @@ -160,7 +160,7 @@ class WalletObserver(private val wallet: Wallet) {
wallet.addCoinsReceivedEventListener(Threading.USER_THREAD, coinsReceivedListener)

awaitClose {
log.info("PERF: observing transactions stop: {}", this@WalletObserver)
log.info("observing transactions stop: {}", this@WalletObserver)
wallet.removeCoinsSentEventListener(coinsSentListener)
wallet.removeCoinsReceivedEventListener(coinsReceivedListener)
if (observeTxConfidence) {
Expand All @@ -172,7 +172,7 @@ class WalletObserver(private val wallet: Wallet) {
}
}
} catch (e: Exception) {
log.error("PERF: Error setting up transaction observation", e)
log.error("Error setting up transaction observation", e)
close(e)
}
}
Expand Down
6 changes: 1 addition & 5 deletions wallet/src/de/schildbach/wallet/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,7 @@ class MainViewModel @Inject constructor(
).filter { it.passesFilter(filter, metadata) }
.sortedByDescending { it.groupDate }

log.info("PERF: wrapAllTransactions: {} ms", watch.elapsed(TimeUnit.MILLISECONDS))
watch.reset()
watch.start()
log.info("wrapAllTransactions: {} ms", watch.elapsed(TimeUnit.MILLISECONDS))

val txByHash = mutableMapOf<String, TransactionRowView>()
val allTransactionViews = allTransactionWrapped
Expand Down Expand Up @@ -543,8 +541,6 @@ class MainViewModel @Inject constructor(
transactions.sortedByDescending { it.time }
}

log.info("PERF: refreshTransactions map: {} ms", watch.elapsed(TimeUnit.MILLISECONDS))

viewModelScope.launch {
_transactions.value = allTransactionViews
this@MainViewModel.txByHash = txByHash
Expand Down

0 comments on commit 1fd0565

Please sign in to comment.