From 331d88ebba3e1df15bf00023c1aa9cf37a814073 Mon Sep 17 00:00:00 2001 From: m2049r Date: Mon, 20 May 2019 17:17:27 +0200 Subject: [PATCH] use daemon height for new wallets if available (#591) --- app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java | 5 ++++- app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java | 2 +- .../java/com/m2049r/xmrwallet/model/WalletManager.java | 8 +++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java index 87f59ab..159b7e8 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java @@ -929,8 +929,11 @@ public class LoginActivity extends BaseActivity @Override public boolean createWallet(File aFile, String password) { + NodeInfo currentNode = getNode(); + final long restoreHeight = + (currentNode != null) ? currentNode.getHeight() - 20 : -1; Wallet newWallet = WalletManager.getInstance() - .createWallet(aFile, password, MNEMONIC_LANGUAGE); + .createWallet(aFile, password, MNEMONIC_LANGUAGE, restoreHeight); boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok); if (!success) { Timber.e(newWallet.getErrorString()); diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java index 5fa5d0a..25f6a89 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java @@ -440,7 +440,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter Collections.sort(nodesToTest, NodeInfo.BestNodeComparator); NodeInfo bestNode = nodesToTest.get(0); if (bestNode.isValid()) - return nodesToTest.get(0); + return bestNode; else return null; } 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 dc89404..bc7db4e 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java +++ b/app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java @@ -91,14 +91,16 @@ public class WalletManager { managedWallet = null; } - public Wallet createWallet(File aFile, String password, String language) { + public Wallet createWallet(File aFile, String password, String language, long height) { long walletHandle = createWalletJ(aFile.getAbsolutePath(), password, language, getNetworkType().getValue()); Wallet wallet = new Wallet(walletHandle); manageWallet(wallet); if (wallet.getStatus() == Wallet.Status.Status_Ok) { // (Re-)Estimate restore height based on what we know - long oldHeight = wallet.getRestoreHeight(); - wallet.setRestoreHeight(RestoreHeight.getInstance().getHeight(new Date())); + final long oldHeight = wallet.getRestoreHeight(); + final long restoreHeight = + (height > -1) ? height : RestoreHeight.getInstance().getHeight(new Date()); + 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) }