Better offline estimation of restore height (#398)

* 2018-09-01 blockheight

* better offline restore height estimate for new wallets
This commit is contained in:
m2049r 2018-09-04 00:25:18 +02:00 committed by GitHub
parent 8b016f93dc
commit 4215a8bf9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View File

@ -417,8 +417,8 @@ Java_com_m2049r_xmrwallet_model_WalletManager_verifyWalletPassword(JNIEnv *env,
//virtual int queryWalletHardware(const std::string &keys_file_name, const std::string &password) const = 0;
JNIEXPORT jint JNICALL
Java_com_m2049r_xmrwallet_model_WalletManager_queryWalletHardware(JNIEnv *env, jobject instance,
jstring keys_file_name,
jstring password) {
jstring keys_file_name,
jstring password) {
const char *_keys_file_name = env->GetStringUTFChars(keys_file_name, NULL);
const char *_password = env->GetStringUTFChars(password, NULL);
int hardwareId =
@ -686,7 +686,13 @@ Java_com_m2049r_xmrwallet_model_Wallet_initJ(JNIEnv *env, jobject instance,
}
// virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
// virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
JNIEXPORT void JNICALL
Java_com_m2049r_xmrwallet_model_Wallet_setRestoreHeight(JNIEnv *env, jobject instance,
jlong height) {
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
wallet->setRefreshFromBlockHeight((uint64_t) height);
}
JNIEXPORT jlong JNICALL
Java_com_m2049r_xmrwallet_model_Wallet_getRestoreHeight(JNIEnv *env, jobject instance) {

View File

@ -151,6 +151,8 @@ public class Wallet {
// virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
// virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
public native void setRestoreHeight(long height);
public native long getRestoreHeight();
// virtual void setRecoveringFromSeed(bool recoveringFromSeed) = 0;

View File

@ -18,6 +18,7 @@ package com.m2049r.xmrwallet.model;
import com.m2049r.xmrwallet.data.WalletNode;
import com.m2049r.xmrwallet.ledger.Ledger;
import com.m2049r.xmrwallet.util.RestoreHeight;
import java.io.BufferedReader;
import java.io.File;
@ -25,6 +26,7 @@ import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import timber.log.Timber;
@ -76,6 +78,13 @@ public class WalletManager {
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()));
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)
}
return wallet;
}

View File

@ -94,6 +94,7 @@ public class RestoreHeight {
blockheight.put("2018-06-01", 1585135L);
blockheight.put("2018-07-01", 1606715L);
blockheight.put("2018-08-01", 1629017L);
blockheight.put("2018-09-01", 1651347L);
}
public long getHeight(String date) {