Skip to content

Commit

Permalink
use daemon height for new wallets if available (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2049r authored May 20, 2019
1 parent 7cc2f6f commit 331d88e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,11 @@ public boolean isLedger() {

@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());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/m2049r/xmrwallet/LoginFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ protected NodeInfo doInBackground(Void... params) {
Collections.sort(nodesToTest, NodeInfo.BestNodeComparator);
NodeInfo bestNode = nodesToTest.get(0);
if (bestNode.isValid())
return nodesToTest.get(0);
return bestNode;
else
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ private void unmanageWallet(Wallet wallet) {
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)
}
Expand Down

0 comments on commit 331d88e

Please sign in to comment.