rewrite Wallet.isSynchronized() (#774)

This commit is contained in:
m2049r 2021-08-07 11:04:18 +02:00 committed by GitHub
parent 54e54b2a8a
commit 002dfd5d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 15 deletions

View File

@ -914,7 +914,7 @@ Java_com_m2049r_xmrwallet_model_Wallet_refreshAsync(JNIEnv *env, jobject instanc
//virtual void rescanBlockchainAsync() = 0;
JNIEXPORT void JNICALL
Java_com_m2049r_xmrwallet_model_Wallet_rescanBlockchainAsync(JNIEnv *env, jobject instance) {
Java_com_m2049r_xmrwallet_model_Wallet_rescanBlockchainAsyncJ(JNIEnv *env, jobject instance) {
Bitmonero::Wallet *wallet = getHandle<Bitmonero::Wallet>(env, instance);
wallet->rescanBlockchainAsync();
}

View File

@ -578,7 +578,6 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
try {
final WalletFragment walletFragment = getWalletFragment();
if (wallet.isSynchronized()) {
Timber.d("onRefreshed() synced");
releaseWakeLock(RELEASE_WAKE_LOCK_DELAY); // the idea is to stay awake until synced
if (!synced) { // first sync
onProgress(-1);

View File

@ -273,12 +273,14 @@ public class Wallet {
public native long getDaemonBlockChainTargetHeight();
public native boolean isSynchronizedJ();
boolean synced = false;
public boolean isSynchronized() {
final long daemonHeight = getDaemonBlockChainHeight();
if (daemonHeight == 0) return false;
return isSynchronizedJ() && (getBlockChainHeight() == daemonHeight);
return synced;
}
public void setSynchronized() {
this.synced = true;
}
public static native String getDisplayAmount(long amount);
@ -309,7 +311,12 @@ public class Wallet {
public native void refreshAsync();
public native void rescanBlockchainAsync();
public native void rescanBlockchainAsyncJ();
public void rescanBlockchainAsync() {
synced = false;
rescanBlockchainAsyncJ();
}
//TODO virtual void setAutoRefreshInterval(int millis) = 0;
//TODO virtual int autoRefreshInterval() const = 0;

View File

@ -112,7 +112,7 @@ public class WalletService extends Service {
int lastTxCount = 0;
public void newBlock(long height) {
Wallet wallet = getWallet();
final Wallet wallet = getWallet();
if (wallet == null) throw new IllegalStateException("No wallet!");
// don't flood with an update for every block ...
if (lastBlockTime < System.currentTimeMillis() - 2000) {
@ -145,13 +145,13 @@ public class WalletService extends Service {
updated = true;
}
public void refreshed() {
public void refreshed() { // this means it's synced
Timber.d("refreshed()");
Wallet wallet = getWallet();
final Wallet wallet = getWallet();
if (wallet == null) throw new IllegalStateException("No wallet!");
wallet.setSynchronized();
if (updated) {
if (observer != null) {
updateDaemonState(wallet, 0);
updateDaemonState(wallet, wallet.getBlockChainHeight());
wallet.getHistory().refreshWithNotes(wallet);
if (observer != null) {
updated = !observer.onRefreshed(wallet, true);
@ -159,7 +159,6 @@ public class WalletService extends Service {
}
}
}
}
private long lastDaemonStatusUpdate = 0;
private long daemonHeight = 0;