diff --git a/drongo b/drongo index 9c6d3ec9..e912e8a5 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 9c6d3ec94b3c4aa961ceb1197348fd8ca3854b4e +Subproject commit e912e8a5121f06b4a2ac913b74e51c0f7dcbb940 diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index 4b9e1d35..dfe9999e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -135,9 +135,8 @@ public class ElectrumServer { return receiveTransactionMap; } - public Map> getHistory(Wallet wallet, WalletNode walletNode) throws ServerException { + public Map> getHistory(Wallet wallet, Collection nodes) throws ServerException { Map> nodeTransactionMap = new TreeMap<>(); - Collection 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 { private final Wallet wallet; - private final WalletNode node; + private final Set 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 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> nodeTransactionMap = (node == null ? electrumServer.getHistory(wallet) : electrumServer.getHistory(wallet, node)); + Map> nodeTransactionMap = (nodes == null ? electrumServer.getHistory(wallet) : electrumServer.getHistory(wallet, nodes)); electrumServer.getReferencedTransactions(wallet, nodeTransactionMap); electrumServer.calculateNodeHistory(wallet, nodeTransactionMap); return true; diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 27716d09..1d89f464 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -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 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())) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java index fd928a97..32b30efe 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java @@ -116,13 +116,12 @@ public class TransactionEntry extends Entry implements Comparable accountEntries = new ArrayList<>(); + private final List> 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 transactionNodes) { + walletTransactionNodes.add(transactionNodes); + } + + private Set getWalletTransactionNodes(WalletNode walletNode) { + if(walletNode == null) { + return null; + } + + Set allNodes = new LinkedHashSet<>(); + for(Set nodes : walletTransactionNodes) { + if(nodes.contains(walletNode)) { + allNodes.addAll(nodes); + } + } + + return allNodes.isEmpty() ? Set.of(walletNode) : allNodes; + } + public NodeEntry getNodeEntry(KeyPurpose keyPurpose) { NodeEntry purposeEntry; Optional optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst();