From 0f0b9a38c7bd6382c33ae45ed2c26c5ee570877f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kartal=20Kaan=20Bozdo=C4=9Fan?= Date: Fri, 5 Aug 2022 02:09:10 +0300 Subject: [PATCH] Fix new wallet restore height (#858) * New wallets: set current block height as the restore height. Go back 4 days for estimated heights --- app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java | 4 ++-- .../main/java/com/m2049r/xmrwallet/model/WalletManager.java | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java index 418dfb96..0cb29915 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java @@ -916,9 +916,9 @@ public class LoginActivity extends BaseActivity @Override public boolean createWallet(File aFile, String password) { NodeInfo currentNode = getNode(); - // get it from the connected node if we have one, and go back ca. 4 days + // get it from the connected node if we have one final long restoreHeight = - (currentNode != null) ? currentNode.getHeight() - 2000 : -1; + (currentNode != null) ? currentNode.getHeight() : -1; Wallet newWallet = WalletManager.getInstance() .createWallet(aFile, password, MNEMONIC_LANGUAGE, restoreHeight); return checkAndCloseWallet(newWallet); diff --git a/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java b/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java index 555a1796..f5aa743c 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java +++ b/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java @@ -24,6 +24,7 @@ import com.m2049r.xmrwallet.util.RestoreHeight; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -96,8 +97,11 @@ public class WalletManager { if (wallet.getStatus().isOk()) { // (Re-)Estimate restore height based on what we know final long oldHeight = wallet.getRestoreHeight(); + // Go back 4 days if we don't have a precise restore height + Calendar restoreDate = Calendar.getInstance(); + restoreDate.add(Calendar.DAY_OF_MONTH, -4); final long restoreHeight = - (height > -1) ? height : RestoreHeight.getInstance().getHeight(new Date()); + (height > -1) ? height : RestoreHeight.getInstance().getHeight(restoreDate.getTime()); wallet.setRestoreHeight(restoreHeight); Timber.d("Changed Restore Height from %d to %d", oldHeight, wallet.getRestoreHeight()); wallet.setPassword(password); // this rewrites the keys file (which contains the restore height)