mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
check history on all created tx script hashes when one is updated
This commit is contained in:
parent
82a8f08440
commit
9e5937d2fe
5 changed files with 44 additions and 12 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
|||
Subproject commit 9c6d3ec94b3c4aa961ceb1197348fd8ca3854b4e
|
||||
Subproject commit e912e8a5121f06b4a2ac913b74e51c0f7dcbb940
|
|
@ -135,9 +135,8 @@ public class ElectrumServer {
|
|||
return receiveTransactionMap;
|
||||
}
|
||||
|
||||
public Map<WalletNode, Set<BlockTransactionHash>> getHistory(Wallet wallet, WalletNode walletNode) throws ServerException {
|
||||
public Map<WalletNode, Set<BlockTransactionHash>> getHistory(Wallet wallet, Collection<WalletNode> nodes) throws ServerException {
|
||||
Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap = new TreeMap<>();
|
||||
Collection<WalletNode> nodes = Set.of(walletNode);
|
||||
subscribeWalletNodes(wallet, nodes, nodeTransactionMap, 0);
|
||||
getReferences(wallet, nodes, nodeTransactionMap);
|
||||
|
||||
|
@ -760,16 +759,16 @@ public class ElectrumServer {
|
|||
|
||||
public static class TransactionHistoryService extends Service<Boolean> {
|
||||
private final Wallet wallet;
|
||||
private final WalletNode node;
|
||||
private final Set<WalletNode> nodes;
|
||||
|
||||
public TransactionHistoryService(Wallet wallet) {
|
||||
this.wallet = wallet;
|
||||
this.node = null;
|
||||
this.nodes = null;
|
||||
}
|
||||
|
||||
public TransactionHistoryService(Wallet wallet, WalletNode node) {
|
||||
public TransactionHistoryService(Wallet wallet, Set<WalletNode> nodes) {
|
||||
this.wallet = wallet;
|
||||
this.node = node;
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -777,7 +776,7 @@ public class ElectrumServer {
|
|||
return new Task<>() {
|
||||
protected Boolean call() throws ServerException {
|
||||
ElectrumServer electrumServer = new ElectrumServer();
|
||||
Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap = (node == null ? electrumServer.getHistory(wallet) : electrumServer.getHistory(wallet, node));
|
||||
Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap = (nodes == null ? electrumServer.getHistory(wallet) : electrumServer.getHistory(wallet, nodes));
|
||||
electrumServer.getReferencedTransactions(wallet, nodeTransactionMap);
|
||||
electrumServer.calculateNodeHistory(wallet, nodeTransactionMap);
|
||||
return true;
|
||||
|
|
|
@ -601,11 +601,25 @@ public class SendController extends WalletFormController implements Initializabl
|
|||
log.debug("Creating tx " + walletTransactionProperty.get().getTransaction().getTxId() + ", expecting notifications for \ninputs \n" + nodeHashes + " and \nchange \n" + changeHash);
|
||||
}
|
||||
|
||||
addWalletTransactionNodes();
|
||||
createdWalletTransactionProperty.set(walletTransactionProperty.get());
|
||||
PSBT psbt = walletTransactionProperty.get().createPSBT();
|
||||
EventManager.get().post(new ViewPSBTEvent(label.getText(), psbt));
|
||||
}
|
||||
|
||||
private void addWalletTransactionNodes() {
|
||||
WalletTransaction walletTransaction = walletTransactionProperty.get();
|
||||
Set<WalletNode> nodes = new LinkedHashSet<>(walletTransaction.getSelectedUtxos().values());
|
||||
nodes.add(walletTransaction.getChangeNode());
|
||||
WalletNode consolidationNode = walletTransaction.getConsolidationSendNode();
|
||||
if(consolidationNode != null) {
|
||||
nodes.add(consolidationNode);
|
||||
}
|
||||
|
||||
//All wallet nodes applicable to this transaction are stored so when the subscription status for one is updated, the history for all can be fetched in one atomic update
|
||||
walletForm.addWalletTransactionNodes(nodes);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletNodesChanged(WalletNodesChangedEvent event) {
|
||||
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||
|
|
|
@ -116,13 +116,12 @@ public class TransactionEntry extends Entry implements Comparable<TransactionEnt
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
TransactionEntry that = (TransactionEntry) o;
|
||||
return wallet.equals(that.wallet) && blockTransaction.equals(that.blockTransaction) &&
|
||||
getChildren().equals(that.getChildren());
|
||||
return wallet.equals(that.wallet) && blockTransaction.equals(that.blockTransaction) && getChildren().size() == that.getChildren().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(wallet, blockTransaction, getChildren());
|
||||
return Objects.hash(wallet, blockTransaction, getChildren().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ public class WalletForm {
|
|||
private WalletTransactionsEntry walletTransactionsEntry;
|
||||
private WalletUtxosEntry walletUtxosEntry;
|
||||
private final List<NodeEntry> accountEntries = new ArrayList<>();
|
||||
private final List<Set<WalletNode>> walletTransactionNodes = new ArrayList<>();
|
||||
|
||||
public WalletForm(Storage storage, Wallet currentWallet) {
|
||||
this.storage = storage;
|
||||
|
@ -76,7 +77,7 @@ public class WalletForm {
|
|||
Wallet previousWallet = wallet.copy();
|
||||
if(wallet.isValid() && AppController.isOnline()) {
|
||||
log.debug(node == null ? "Refreshing full wallet history" : "Requesting node wallet history for " + node.getDerivationPath());
|
||||
ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(wallet, node);
|
||||
ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(wallet, getWalletTransactionNodes(node));
|
||||
historyService.setOnSucceeded(workerStateEvent -> {
|
||||
EventManager.get().post(new WalletHistoryStatusEvent(true));
|
||||
updateWallet(previousWallet, blockHeight);
|
||||
|
@ -136,6 +137,25 @@ public class WalletForm {
|
|||
return changedNodes;
|
||||
}
|
||||
|
||||
public void addWalletTransactionNodes(Set<WalletNode> transactionNodes) {
|
||||
walletTransactionNodes.add(transactionNodes);
|
||||
}
|
||||
|
||||
private Set<WalletNode> getWalletTransactionNodes(WalletNode walletNode) {
|
||||
if(walletNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<WalletNode> allNodes = new LinkedHashSet<>();
|
||||
for(Set<WalletNode> nodes : walletTransactionNodes) {
|
||||
if(nodes.contains(walletNode)) {
|
||||
allNodes.addAll(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
return allNodes.isEmpty() ? Set.of(walletNode) : allNodes;
|
||||
}
|
||||
|
||||
public NodeEntry getNodeEntry(KeyPurpose keyPurpose) {
|
||||
NodeEntry purposeEntry;
|
||||
Optional<NodeEntry> optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst();
|
||||
|
|
Loading…
Reference in a new issue