Skip to content

Commit 331d88e

Browse files
authored
use daemon height for new wallets if available (#591)
1 parent 7cc2f6f commit 331d88e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,11 @@ public boolean isLedger() {
929929

930930
@Override
931931
public boolean createWallet(File aFile, String password) {
932+
NodeInfo currentNode = getNode();
933+
final long restoreHeight =
934+
(currentNode != null) ? currentNode.getHeight() - 20 : -1;
932935
Wallet newWallet = WalletManager.getInstance()
933-
.createWallet(aFile, password, MNEMONIC_LANGUAGE);
936+
.createWallet(aFile, password, MNEMONIC_LANGUAGE, restoreHeight);
934937
boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
935938
if (!success) {
936939
Timber.e(newWallet.getErrorString());

app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ protected NodeInfo doInBackground(Void... params) {
440440
Collections.sort(nodesToTest, NodeInfo.BestNodeComparator);
441441
NodeInfo bestNode = nodesToTest.get(0);
442442
if (bestNode.isValid())
443-
return nodesToTest.get(0);
443+
return bestNode;
444444
else
445445
return null;
446446
}

app/src/main/java/com/m2049r/xmrwallet/model/WalletManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ private void unmanageWallet(Wallet wallet) {
9191
managedWallet = null;
9292
}
9393

94-
public Wallet createWallet(File aFile, String password, String language) {
94+
public Wallet createWallet(File aFile, String password, String language, long height) {
9595
long walletHandle = createWalletJ(aFile.getAbsolutePath(), password, language, getNetworkType().getValue());
9696
Wallet wallet = new Wallet(walletHandle);
9797
manageWallet(wallet);
9898
if (wallet.getStatus() == Wallet.Status.Status_Ok) {
9999
// (Re-)Estimate restore height based on what we know
100-
long oldHeight = wallet.getRestoreHeight();
101-
wallet.setRestoreHeight(RestoreHeight.getInstance().getHeight(new Date()));
100+
final long oldHeight = wallet.getRestoreHeight();
101+
final long restoreHeight =
102+
(height > -1) ? height : RestoreHeight.getInstance().getHeight(new Date());
103+
wallet.setRestoreHeight(restoreHeight);
102104
Timber.d("Changed Restore Height from %d to %d", oldHeight, wallet.getRestoreHeight());
103105
wallet.setPassword(password); // this rewrites the keys file (which contains the restore height)
104106
}

0 commit comments

Comments
 (0)