mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
save stored block on event
This commit is contained in:
parent
44be6e7203
commit
b1e8e25837
2 changed files with 21 additions and 6 deletions
|
@ -0,0 +1,16 @@
|
||||||
|
package com.sparrowwallet.sparrow.event;
|
||||||
|
|
||||||
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
|
|
||||||
|
public class WalletBlockHeightChangedEvent extends WalletChangedEvent {
|
||||||
|
private Integer blockHeight;
|
||||||
|
|
||||||
|
public WalletBlockHeightChangedEvent(Wallet wallet, Integer blockHeight) {
|
||||||
|
super(wallet);
|
||||||
|
this.blockHeight = blockHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBlockHeight() {
|
||||||
|
return blockHeight;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,10 +6,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||||
import com.sparrowwallet.sparrow.AppController;
|
import com.sparrowwallet.sparrow.AppController;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.event.ConnectionEvent;
|
import com.sparrowwallet.sparrow.event.*;
|
||||||
import com.sparrowwallet.sparrow.event.NewBlockEvent;
|
|
||||||
import com.sparrowwallet.sparrow.event.WalletChangedEvent;
|
|
||||||
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
|
||||||
import com.sparrowwallet.sparrow.io.ElectrumServer;
|
import com.sparrowwallet.sparrow.io.ElectrumServer;
|
||||||
import com.sparrowwallet.sparrow.io.Storage;
|
import com.sparrowwallet.sparrow.io.Storage;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
@ -62,7 +59,7 @@ public class WalletForm {
|
||||||
ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(wallet);
|
ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(wallet);
|
||||||
historyService.setOnSucceeded(workerStateEvent -> {
|
historyService.setOnSucceeded(workerStateEvent -> {
|
||||||
wallet.setStoredBlockHeight(blockHeight);
|
wallet.setStoredBlockHeight(blockHeight);
|
||||||
notifyIfHistoryChanged(previousWallet);
|
notifyIfChanged(previousWallet, blockHeight);
|
||||||
});
|
});
|
||||||
historyService.setOnFailed(workerStateEvent -> {
|
historyService.setOnFailed(workerStateEvent -> {
|
||||||
workerStateEvent.getSource().getException().printStackTrace();
|
workerStateEvent.getSource().getException().printStackTrace();
|
||||||
|
@ -71,13 +68,15 @@ public class WalletForm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyIfHistoryChanged(Wallet previousWallet) {
|
private void notifyIfChanged(Wallet previousWallet, Integer blockHeight) {
|
||||||
List<WalletNode> historyChangedNodes = new ArrayList<>();
|
List<WalletNode> historyChangedNodes = new ArrayList<>();
|
||||||
historyChangedNodes.addAll(getHistoryChangedNodes(previousWallet.getNode(KeyPurpose.RECEIVE).getChildren(), wallet.getNode(KeyPurpose.RECEIVE).getChildren()));
|
historyChangedNodes.addAll(getHistoryChangedNodes(previousWallet.getNode(KeyPurpose.RECEIVE).getChildren(), wallet.getNode(KeyPurpose.RECEIVE).getChildren()));
|
||||||
historyChangedNodes.addAll(getHistoryChangedNodes(previousWallet.getNode(KeyPurpose.CHANGE).getChildren(), wallet.getNode(KeyPurpose.CHANGE).getChildren()));
|
historyChangedNodes.addAll(getHistoryChangedNodes(previousWallet.getNode(KeyPurpose.CHANGE).getChildren(), wallet.getNode(KeyPurpose.CHANGE).getChildren()));
|
||||||
|
|
||||||
if(!historyChangedNodes.isEmpty()) {
|
if(!historyChangedNodes.isEmpty()) {
|
||||||
Platform.runLater(() -> EventManager.get().post(new WalletHistoryChangedEvent(wallet, historyChangedNodes)));
|
Platform.runLater(() -> EventManager.get().post(new WalletHistoryChangedEvent(wallet, historyChangedNodes)));
|
||||||
|
} else if(blockHeight != null && !blockHeight.equals(previousWallet.getStoredBlockHeight())) {
|
||||||
|
Platform.runLater(() -> EventManager.get().post(new WalletBlockHeightChangedEvent(wallet, blockHeight)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue