Skip to content

Commit

Permalink
refactor: convert BlockchainService to Kotlin to address ANR's (#1336)
Browse files Browse the repository at this point in the history
* feat: show platform version on AboutActivity

* chore: update to dashj 21.1.3-SNAPSHOT

* Rename .java to .kt

* refactor: convert BlockchainServiceImpl to Java

* refactor: use serviceScope for onStartCommand, onDestroy, onReceive

* fix: various fixes

* fix: propogate context

* refactor: update based on changes to dash-sdk-kotlin

* fix: update copyright year to 2024

* fix: use DashSystem instead of Context

* fix: wait for shutdown when starting again after blockchain rescan

* refactor: simplify Injected fields

* fix: update to v11.0.5 sync fix

* Rename .java to .kt

* fix: delete old files

* fix: more proguard rules

* fix: log date format attempted fix

* fix: attempting to fix log date format

* fix: add logback to proguard

* chore: cleanup

* fix: proper isComplete check for CrowdNode tx set

* fix: change the way topup tx observed for CrowdNode

* fix: build error - missing file

* fix: update some function calls to include chainLockHeight

* fix: make sure that onDestroy doesn't start before onCreate is finished.

* chore: update dpp to v1.7.1-SNAPSHOT

* fix: use the refactored context dashj

---------

Co-authored-by: Andrei Ashikhmin <[email protected]>
  • Loading branch information
HashEngineering and Syn-McJ authored Jan 22, 2025
1 parent 2bbfb45 commit 165a194
Show file tree
Hide file tree
Showing 32 changed files with 1,742 additions and 1,645 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ buildscript {
kotlin_version = '1.9.24'
coroutinesVersion = '1.6.4'
ok_http_version = '4.9.1'
dashjVersion = '21.1.5-SNAPSHOT'
dppVersion = "1.7.0-SNAPSHOT"
dashjVersion = '21.1.5-RC-SNAPSHOT'
dppVersion = "1.7.1-SNAPSHOT"
hiltVersion = '2.51'
hiltCompilerVersion = '1.2.0'
hiltWorkVersion = '1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion wallet/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string name="blockchain_state_progress_days">%1$s, %2$d tagoj malantaŭ</string>
<string name="blockchain_state_progress_weeks">%1$s, %2$d semajnoj malantaŭ</string>
<string name="blockchain_state_progress_months">%1$s, %2$d monatoj malantaŭ</string>
<string name="blockchain_state_progress_downloading">Sinkronigado kun reto</string>
<string name="blockchain_state_progress_downloading">Sinkronigado kun reto (%1$s%%)</string>
<string name="blockchain_state_progress_stalled">Sinkronigo stagnis</string>
<string name="blockchain_state_progress_problem_storage">Sinkronigado: Stokante problemo</string>
<string name="blockchain_state_progress_problem_network">Sinkronigado: Reta problemo</string>
Expand Down
2 changes: 1 addition & 1 deletion wallet/res/values-he/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string name="blockchain_state_progress_days">%1$s, %2$d ימי איחור</string>
<string name="blockchain_state_progress_weeks">%1$s, %2$d שבועות איחור</string>
<string name="blockchain_state_progress_months">%1$s, %2$d חודשי איחור</string>
<string name="blockchain_state_progress_downloading">מסנכרן רשת</string>
<string name="blockchain_state_progress_downloading">(%1$s%%) מסנכרן רשת</string>
<string name="blockchain_state_progress_stalled">סינכרון עוקב</string>
<string name="blockchain_state_progress_problem_storage">סינכרון: בעיית אחסון</string>
<string name="blockchain_state_progress_problem_network">סינכרון:בעיית רשת</string>
Expand Down
2 changes: 1 addition & 1 deletion wallet/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="blockchain_state_progress_days">%1$s, %2$d dani iza</string>
<string name="blockchain_state_progress_weeks">%1$s, %2$d tjedana iza</string>
<string name="blockchain_state_progress_months">%1$s, %2$d mjeseci iza</string>
<string name="blockchain_state_progress_downloading">Sinkroniziranje sa mrežom</string>
<string name="blockchain_state_progress_downloading">Sinkroniziranje sa mrežom (%1$s%%)</string>
<string name="blockchain_state_progress_stalled">Sinkronizacija u zastoju</string>
<string name="blockchain_state_progress_problem_storage">Sinkroniziranje: Spremišni problem</string>
<string name="blockchain_state_progress_problem_network">Sinkroniziranje: Mrežni problem</string>
Expand Down
2 changes: 1 addition & 1 deletion wallet/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string name="blockchain_state_progress_days">%1$s, %2$d ימי איחור</string>
<string name="blockchain_state_progress_weeks">%1$s, %2$d שבועות איחור</string>
<string name="blockchain_state_progress_months">%1$s, %2$d חודשי איחור</string>
<string name="blockchain_state_progress_downloading">מסנכרן רשת</string>
<string name="blockchain_state_progress_downloading">מסנכרן רשת (%1$s%%)</string>
<string name="blockchain_state_progress_stalled">סינכרון עוקב</string>
<string name="blockchain_state_progress_problem_storage">סינכרון: בעיית אחסון</string>
<string name="blockchain_state_progress_problem_network">סינכרון:בעיית רשת</string>
Expand Down
2 changes: 1 addition & 1 deletion wallet/res/values-mk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string name="blockchain_state_progress_days">%1$s, %2$d денови заостанува</string>
<string name="blockchain_state_progress_weeks">%1$s, %2$d недели заостанува</string>
<string name="blockchain_state_progress_months">%1$s, %2$d месеци заостанува</string>
<string name="blockchain_state_progress_downloading">Се синхронизира со мрежата</string>
<string name="blockchain_state_progress_downloading">Се синхронизира со мрежата (%1$s%%)</string>
<string name="blockchain_state_progress_stalled">Синхронизацијата застана</string>
<string name="blockchain_state_progress_problem_storage">Се синхронизира: Проблем со простор за складирање</string>
<string name="blockchain_state_progress_problem_network">Се синхронизира: Проблем со мрежата</string>
Expand Down
2 changes: 1 addition & 1 deletion wallet/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string name="blockchain_state_progress_days">siku %1$s, %2$d mwishoni mwa</string>
<string name="blockchain_state_progress_weeks">wiki %1$s, %2$d marehemu</string>
<string name="blockchain_state_progress_months">miezi %1$s, %2$d marehemu</string>
<string name="blockchain_state_progress_downloading">Sambamba na mtandao</string>
<string name="blockchain_state_progress_downloading">Sambamba na mtandao (%1$s%%)</string>
<string name="blockchain_state_progress_stalled">Sambamba kusimamishwa</string>
<string name="blockchain_state_progress_problem_storage">Haitoshi disc nafasi</string>
<string name="blockchain_state_progress_problem_network">Hakuna signal wa mtandao</string>
Expand Down
14 changes: 11 additions & 3 deletions wallet/src/de/schildbach/wallet/WalletApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.bitcoinj.core.TransactionBag;
import org.bitcoinj.core.VerificationException;
import org.bitcoinj.crypto.LinuxSecureRandom;
import org.bitcoinj.manager.DashSystem;
import org.bitcoinj.utils.Threading;
import org.bitcoinj.core.VersionMessage;
import org.bitcoinj.crypto.IKey;
Expand Down Expand Up @@ -91,6 +92,7 @@
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
import ch.qos.logback.core.util.FileSize;
import de.schildbach.wallet.service.BlockchainStateDataProvider;
import de.schildbach.wallet.service.DashSystemService;
import de.schildbach.wallet.service.PackageInfoProvider;
import de.schildbach.wallet.service.WalletFactory;
import de.schildbach.wallet.transactions.MasternodeObserver;
Expand Down Expand Up @@ -173,7 +175,6 @@ public class WalletApplication extends MultiDexApplication

private File walletFile;
private Wallet wallet;

public static final String ACTION_WALLET_REFERENCE_CHANGED = WalletApplication.class.getPackage().getName()
+ ".wallet_reference_changed";

Expand All @@ -191,6 +192,7 @@ public class WalletApplication extends MultiDexApplication

private AutoLogout autoLogout;
private AnrSupervisor anrSupervisor;
private Function0 afterWipeFunction;

@Inject
RestartService restartService;
Expand All @@ -212,6 +214,8 @@ public class WalletApplication extends MultiDexApplication
PackageInfoProvider packageInfoProvider;
@Inject
WalletFactory walletFactory;
@Inject
DashSystemService dashSystemService;

@Override
protected void attachBaseContext(Context base) {
Expand Down Expand Up @@ -433,7 +437,7 @@ public void saveWalletAndFinalizeInitialization() {
}

public void finalizeInitialization() {
wallet.getContext().initDash(true, true, Constants.SYNC_FLAGS, Constants.VERIFY_FLAGS);
dashSystemService.getSystem().initDash(true, true, Constants.SYNC_FLAGS, Constants.VERIFY_FLAGS);

if (config.versionCodeCrossed(packageInfoProvider.getVersionCode(), VERSION_CODE_SHOW_BACKUP_REMINDER)
&& !wallet.getImportedKeys().isEmpty()) {
Expand Down Expand Up @@ -992,8 +996,9 @@ else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
/**
* Removes all the data and restarts the app showing onboarding screen.
*/
public void triggerWipe() {
public void triggerWipe(Function0 afterWipeFunction) {
log.info("Removing all the data and restarting the app.");
this.afterWipeFunction = afterWipeFunction;
startService(new Intent(BlockchainService.ACTION_WIPE_WALLET, null, this, BlockchainServiceImpl.class));
}

Expand Down Expand Up @@ -1036,6 +1041,9 @@ public void finalizeWipe() {
// wallet must be null for the OnboardingActivity flow
log.info("removing wallet from memory during wipe");
wallet = null;
if (afterWipeFunction != null)
afterWipeFunction.invoke();
afterWipeFunction = null;
}

public AnalyticsService getAnalyticsService() {
Expand Down
4 changes: 4 additions & 0 deletions wallet/src/de/schildbach/wallet/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ abstract class AppModule {
@Binds
@Singleton
abstract fun bindZenLedgerClient(zenLedgerClient: ZenLedgerClient): ZenLedgerApi

@Singleton
@Binds
abstract fun provideDashSystemService(dashSystemService: DashSystemServiceImpl): DashSystemService
}
Loading

0 comments on commit 165a194

Please sign in to comment.