Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: blockchainservice ANR's #1336

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
58b6a2b
feat: show platform version on AboutActivity
HashEngineering Nov 20, 2024
5125d25
chore: update to dashj 21.1.3-SNAPSHOT
HashEngineering Nov 20, 2024
17a214d
Rename .java to .kt
HashEngineering Nov 21, 2024
9127169
refactor: convert BlockchainServiceImpl to Java
HashEngineering Nov 21, 2024
4d7a378
refactor: use serviceScope for onStartCommand, onDestroy, onReceive
HashEngineering Nov 21, 2024
655d2e6
fix: various fixes
HashEngineering Nov 21, 2024
55e26c8
fix: propogate context
HashEngineering Nov 23, 2024
5474f28
refactor: update based on changes to dash-sdk-kotlin
HashEngineering Nov 23, 2024
9237a1c
fix: update copyright year to 2024
HashEngineering Nov 23, 2024
c9248c3
Merge branch 'bugfix-sync-stuck-31' into bugfix-sync-anr
HashEngineering Nov 25, 2024
837e7b7
fix: use DashSystem instead of Context
HashEngineering Nov 25, 2024
9a9f3e2
Merge branch 'master' of https://github.com/dashevo/dash-wallet into …
HashEngineering Dec 3, 2024
ae43499
fix: wait for shutdown when starting again after blockchain rescan
HashEngineering Dec 3, 2024
1044859
refactor: simplify Injected fields
HashEngineering Dec 3, 2024
51d7e55
feat: update tx list with observeTransactions
HashEngineering Dec 5, 2024
1f118ab
fix: adding tx in wrapper
HashEngineering Dec 12, 2024
eea84d3
fix: attempt to update tx lists
HashEngineering Dec 13, 2024
62ddb04
fix: attempt to update tx lists
HashEngineering Dec 13, 2024
70d5851
fix: attempt to update tx lists
HashEngineering Dec 13, 2024
0bde26c
fix: attempt to update tx lists
HashEngineering Dec 13, 2024
0504d80
fix: attempt to update tx lists
HashEngineering Dec 13, 2024
ea5e6d8
Merge branch 'master' of https://github.com/dashevo/dash-wallet into …
HashEngineering Dec 16, 2024
a799907
fix: improve WalletBalanceObserver
HashEngineering Dec 17, 2024
cbef776
fix: remove update functions from TransactionRowView
HashEngineering Dec 17, 2024
a934818
fix: use TransactionRowViewList
HashEngineering Dec 17, 2024
d2a1ea4
fix: improve TX details
HashEngineering Dec 17, 2024
61dc67d
fix: more improvements to MainViewModel
HashEngineering Dec 17, 2024
dce5f3d
fix: problems showing Tx details and going to home screen afterwards
HashEngineering Dec 20, 2024
3188687
Merge branch 'master' of https://github.com/dashevo/dash-wallet into …
HashEngineering Dec 20, 2024
8f31dd7
fix: always submit a new list for the UI
HashEngineering Dec 23, 2024
89ddbd3
fix: add reset listener
HashEngineering Dec 23, 2024
5065024
fix: add reset listener
HashEngineering Dec 23, 2024
2460673
fix: batch updates
HashEngineering Dec 23, 2024
5cf9bfe
fix: replace batch updates method and only process tx confidence chan…
HashEngineering Dec 24, 2024
0b2de89
fix: update dashj to 21.1.5-SNAPSHOT
HashEngineering Dec 24, 2024
63523d0
chore: refactor telephony manager usage
Syn-McJ Dec 26, 2024
d6ba862
chore: upgrade gradle & AGP
Syn-McJ Dec 27, 2024
9614e45
fix: mixing icon and row view id type
Syn-McJ Dec 30, 2024
a9b82e4
chore: upgrade kotlin & ksp to fix deadlock
Syn-McJ Dec 30, 2024
c5237a6
feat: performance, uncoupling metadata & contacts
Syn-McJ Jan 2, 2025
cea69eb
fix: confirmation dialog UI with contact
Syn-McJ Jan 3, 2025
f04c016
fix: observing contacts bugs
Syn-McJ Jan 3, 2025
9b533b0
fix: send to contact from send tab
Syn-McJ Jan 4, 2025
13bc173
fix: sticky info panel on EnterAmountFragment
Syn-McJ Jan 4, 2025
832e61f
chore: cleanup
Syn-McJ Jan 4, 2025
ad09410
fix: improve wipe function
HashEngineering Jan 5, 2025
4673895
chore: update dashj
HashEngineering Jan 5, 2025
586853f
Merge branch 'master' of https://github.com/dashevo/dash-wallet into …
HashEngineering Jan 5, 2025
dcb15c6
fix: update to v11.0.5 sync fix
HashEngineering Jan 5, 2025
70da95a
Rename .java to .kt
HashEngineering Jan 5, 2025
e17c2e1
fix: delete old files
HashEngineering Jan 5, 2025
c2c3b71
Merge branch 'master' into bugfix-observe-tx-improvements
Syn-McJ Jan 5, 2025
377b6d0
fix: more proguard rules
Syn-McJ Jan 5, 2025
3517048
fix: log date format attempted fix
Syn-McJ Jan 5, 2025
473b4e0
fix: attempting to fix log date format
Syn-McJ Jan 5, 2025
a932d19
fix: add logback to proguard
Syn-McJ Jan 5, 2025
1fd0565
chore: cleanup
Syn-McJ Jan 10, 2025
4eb98b1
fix: proper isComplete check for CrowdNode tx set
Syn-McJ Jan 12, 2025
f36d7e3
fix: change the way topup tx observed for CrowdNode
Syn-McJ Jan 13, 2025
b990fa0
fix: build error - missing file
Syn-McJ Jan 13, 2025
c8e1439
Merge branch 'bugfix-observe-tx-improvements' of https://github.com/d…
HashEngineering Jan 13, 2025
4a6107b
fix: update some function calls to include chainLockHeight
HashEngineering Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
buildscript {
ext {
kotlin_version = '1.9.23'
kotlin_version = '1.9.24'
coroutinesVersion = '1.6.4'
ok_http_version = '4.9.1'
dashjVersion = '21.1.4'
dashjVersion = '21.1.5-SNAPSHOT'
dppVersion = "1.5.2"
hiltVersion = '2.51'
hiltCompilerVersion = '1.2.0'
Expand Down Expand Up @@ -52,10 +52,10 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.android.tools.build:gradle:8.7.3'
classpath 'com.google.gms:google-services:4.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2' // Crashlytics
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2' // Crashlytics
classpath "com.google.dagger:hilt-android-gradle-plugin:$hiltVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"
Expand All @@ -64,7 +64,7 @@ buildscript {
}

plugins {
id 'com.google.devtools.ksp' version '1.9.23-1.0.19' apply false
id 'com.google.devtools.ksp' version '1.9.24-1.0.20' apply false
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.11"
kotlinCompilerExtensionVersion = "1.5.14"
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ interface WalletDataProvider {

fun observeWalletChanged(): Flow<Unit>

fun observeWalletReset(): Flow<Unit>

fun observeBalance(
balanceType: Wallet.BalanceType = Wallet.BalanceType.ESTIMATED,
coinSelector: CoinSelector? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,4 @@ class TransactionComparator: Comparator<Transaction> {

return tx1.txId.compareTo(tx2.txId)
}
}

class TransactionWrapperComparator: Comparator<TransactionWrapper> {
private val txComparator = TransactionComparator()

override fun compare(wrapper1: TransactionWrapper, wrapper2: TransactionWrapper): Int {
return txComparator.compare(wrapper1.transactions.last(), wrapper2.transactions.last())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.dash.wallet.common.transactions

import kotlinx.coroutines.suspendCancellableCoroutine
import org.bitcoinj.core.Transaction
import org.bitcoinj.core.TransactionConfidence
import org.bitcoinj.utils.Threading
import org.dash.wallet.common.transactions.filters.TransactionFilter
import kotlin.coroutines.resume

suspend fun Transaction.waitToMatchFilters(vararg filters: TransactionFilter) {
return suspendCancellableCoroutine { continuation ->
var transactionConfidenceListener: TransactionConfidence.Listener? = null
transactionConfidenceListener = TransactionConfidence.Listener { _, _ ->
if (filters.isEmpty() || filters.any { it.matches(this) }) {
confidence.removeEventListener(transactionConfidenceListener)
continuation.resume(Unit)
}
}

// Check if already matches
if (filters.isEmpty() || filters.any { it.matches(this) }) {
continuation.resume(Unit)
return@suspendCancellableCoroutine
}

this.confidence.addEventListener(Threading.USER_THREAD, transactionConfidenceListener)

continuation.invokeOnCancellation {
confidence.removeEventListener(transactionConfidenceListener)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

@file:OptIn(FlowPreview::class)

package org.dash.wallet.common.transactions

import android.util.Log
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.sample
import org.bitcoinj.core.Address
import org.bitcoinj.core.Sha256Hash
import org.bitcoinj.core.Transaction
import org.bitcoinj.core.TransactionBag
import org.bitcoinj.script.ScriptException
import java.util.concurrent.ConcurrentHashMap

object TransactionUtils {
fun getWalletAddressOfReceived(tx: Transaction, bag: TransactionBag): Address? {
Expand Down Expand Up @@ -118,4 +129,21 @@ object TransactionUtils {
}
return result
}
}
}

fun Flow<Transaction>.batchAndFilterUpdates(timeInterval: Long = 500): Flow<List<Transaction>> {
val latestTransactions = ConcurrentHashMap<Sha256Hash, Transaction>()

return this
.onEach { transaction ->
// Update the latest transaction for the hash
latestTransactions[transaction.txId] = transaction
}
.sample(timeInterval) // Emit events every [timeInterval]
.map {
latestTransactions.values.toList().also {
latestTransactions.clear()
}
}
.filter { it.isNotEmpty() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
package org.dash.wallet.common.transactions

import org.bitcoinj.core.Coin
import org.bitcoinj.core.Sha256Hash
import org.bitcoinj.core.Transaction
import org.bitcoinj.core.TransactionBag
import java.time.LocalDate

interface TransactionWrapper {
val transactions: Set<Transaction>
val id: String
val transactions: HashMap<Sha256Hash, Transaction>
val groupDate: LocalDate
fun tryInclude(tx: Transaction): Boolean
fun getValue(bag: TransactionBag): Coin
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.dash.wallet.common.transactions
import org.bitcoinj.core.Transaction

interface TransactionWrapperFactory {
fun tryInclude(tx: Transaction): Pair<Boolean, TransactionWrapper?>
val averageTransactions: Long
val wrappers: List<TransactionWrapper>
fun tryInclude(tx: Transaction): Pair<Boolean, TransactionWrapper?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ package org.dash.wallet.common.transactions.filters
import org.bitcoinj.core.Sha256Hash
import org.bitcoinj.core.Transaction
import org.bitcoinj.core.TransactionConfidence
import org.dash.wallet.common.transactions.filters.TransactionFilter

class LockedTransaction(private val topUpTxId: Sha256Hash): TransactionFilter {
class LockedTransaction(private val topUpTxId: Sha256Hash? = null): TransactionFilter {
constructor() : this(null)

override fun matches(tx: Transaction): Boolean {
val confidence = tx.confidence
val type = confidence.confidenceType
val isLocked = confidence.isTransactionLocked ||
type == TransactionConfidence.ConfidenceType.BUILDING ||
(type == TransactionConfidence.ConfidenceType.PENDING && confidence.numBroadcastPeers() > 1)

return tx.txId == topUpTxId && isLocked
return if (topUpTxId != null) {
tx.txId == topUpTxId && isLocked
} else {
isLocked
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,6 @@ class EnterAmountFragment : Fragment(R.layout.fragment_enter_amount) {

fun setMessage(message: String) {
binding.messageText.text = message
binding.messageText.isVisible = message.isNotEmpty()
}
}
29 changes: 29 additions & 0 deletions common/src/main/java/org/dash/wallet/common/util/FlowExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.AbstractFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import kotlin.time.Duration

Expand Down Expand Up @@ -41,3 +42,31 @@ fun <T> Flow<T>.observe(lifecycleOwner: LifecycleOwner, collector: FlowCollector
}
}
}

/** from ChatGPT */
fun <T> Flow<T>.window(intervalMillis: Long): Flow<List<T>> = flow {
val buffer = mutableListOf<T>()
val lock = Any()
var lastEmitTime = System.currentTimeMillis()

[email protected] { value ->
var batchToEmit: List<T>? = null

synchronized(lock) {
buffer.add(value)
val currentTime = System.currentTimeMillis()
if (currentTime - lastEmitTime >= intervalMillis) {
batchToEmit = buffer.toList()
buffer.clear()
lastEmitTime = currentTime
}
}

batchToEmit?.let { emit(it) }
}

val finalBatch = synchronized(lock) {
if (buffer.isNotEmpty()) buffer.toList() else null
}
finalBatch?.let { emit(it) }
}
1 change: 1 addition & 0 deletions common/src/main/res/layout/fragment_enter_amount.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
android:layout_marginHorizontal="20dp"
android:paddingHorizontal="8dp"
android:gravity="center_horizontal"
android:visibility="gone"
android:background="@drawable/gray_button_background"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx4G
org.gradle.daemon=true
org.gradle.parallel=true
kotlin.incremental=true
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon Oct 02 18:25:36 ICT 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading