mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-11-22 07:22:26 +00:00
Revert to simplified sync
This commit is contained in:
parent
55a0c3b5ce
commit
a147faef70
3 changed files with 12 additions and 23 deletions
|
@ -113,10 +113,10 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh(long height) {
|
public void onRefresh() {
|
||||||
this.historyService.refreshHistory();
|
this.historyService.refreshHistory();
|
||||||
this.balanceService.refreshBalance();
|
this.balanceService.refreshBalance();
|
||||||
this.blockchainService.refreshBlockchain(height);
|
this.blockchainService.refreshBlockchain();
|
||||||
this.addressService.refreshAddresses();
|
this.addressService.refreshAddresses();
|
||||||
this.utxoService.refreshUtxos();
|
this.utxoService.refreshUtxos();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ public class BlockchainService extends ServiceBase {
|
||||||
public LiveData<Wallet.ConnectionStatus> connectionStatus = _connectionStatus;
|
public LiveData<Wallet.ConnectionStatus> connectionStatus = _connectionStatus;
|
||||||
private long daemonHeight = 0;
|
private long daemonHeight = 0;
|
||||||
private long lastDaemonHeightUpdateTimeMs = 0;
|
private long lastDaemonHeightUpdateTimeMs = 0;
|
||||||
public static long GETHEIGHT_FETCH = -1;
|
|
||||||
|
|
||||||
public BlockchainService(MoneroHandlerThread thread) {
|
public BlockchainService(MoneroHandlerThread thread) {
|
||||||
super(thread);
|
super(thread);
|
||||||
|
@ -25,8 +24,8 @@ public class BlockchainService extends ServiceBase {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBlockchain(long height) {
|
public void refreshBlockchain() {
|
||||||
_currentHeight.postValue(height == GETHEIGHT_FETCH ? getCurrentHeight() : height);
|
_currentHeight.postValue(getCurrentHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCurrentHeight() {
|
public long getCurrentHeight() {
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void start() {
|
public synchronized void start() {
|
||||||
super.start();
|
super.start();
|
||||||
this.listener.onRefresh(BlockchainService.GETHEIGHT_FETCH);
|
this.listener.onRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,17 +92,13 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newBlock(long height) {
|
public void newBlock(long height) {
|
||||||
if(isEveryNthBlock(height, 1)) { // refresh services every 5 blocks downloaded
|
refresh();
|
||||||
refresh(height);
|
|
||||||
} else if(isEveryNthBlock(height, 5)) { // save wallet every 5 blocks (~10 minutes), we also save upon finishing sync (in refreshed())
|
|
||||||
wallet.store();
|
|
||||||
}
|
|
||||||
BlockchainService.getInstance().setDaemonHeight(wallet.isSynchronized() ? height : 0);
|
BlockchainService.getInstance().setDaemonHeight(wallet.isSynchronized() ? height : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updated() {
|
public void updated() {
|
||||||
refresh(BlockchainService.GETHEIGHT_FETCH);
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,20 +112,19 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
||||||
listener.onConnectionFail();
|
listener.onConnectionFail();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
long height = wallet.getDaemonBlockChainHeight();
|
BlockchainService.getInstance().setDaemonHeight(wallet.getDaemonBlockChainHeight());
|
||||||
BlockchainService.getInstance().setDaemonHeight(height);
|
|
||||||
wallet.setSynchronized();
|
wallet.setSynchronized();
|
||||||
wallet.store();
|
wallet.store();
|
||||||
refresh(height);
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockchainService.getInstance().setConnectionStatus(status);
|
BlockchainService.getInstance().setConnectionStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(long height) {
|
private void refresh() {
|
||||||
wallet.refreshHistory();
|
wallet.refreshHistory();
|
||||||
wallet.refreshCoins();
|
wallet.refreshCoins();
|
||||||
listener.onRefresh(height);
|
listener.onRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PendingTransaction createTx(String address, String amountStr, boolean sendAll, PendingTransaction.Priority feePriority, ArrayList<String> selectedUtxos) throws Exception {
|
public PendingTransaction createTx(String address, String amountStr, boolean sendAll, PendingTransaction.Priority feePriority, ArrayList<String> selectedUtxos) throws Exception {
|
||||||
|
@ -226,10 +221,6 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
||||||
return pendingTx.commit("", true);
|
return pendingTx.commit("", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEveryNthBlock(long height, long interval) {
|
|
||||||
return height % interval == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private float getRandomDonateAmount(float min, float max) {
|
private float getRandomDonateAmount(float min, float max) {
|
||||||
SecureRandom rand = new SecureRandom();
|
SecureRandom rand = new SecureRandom();
|
||||||
return rand.nextFloat() * (max - min) + min;
|
return rand.nextFloat() * (max - min) + min;
|
||||||
|
@ -241,8 +232,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
void onRefresh(long height);
|
void onRefresh();
|
||||||
|
|
||||||
void onConnectionFail();
|
void onConnectionFail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue