check history on all created tx script hashes when one is updated

This commit is contained in:
Craig Raw 2020-10-02 15:18:12 +02:00
parent 82a8f08440
commit 9e5937d2fe
5 changed files with 44 additions and 12 deletions

2
drongo

@ -1 +1 @@
Subproject commit 9c6d3ec94b3c4aa961ceb1197348fd8ca3854b4e Subproject commit e912e8a5121f06b4a2ac913b74e51c0f7dcbb940

View file

@ -135,9 +135,8 @@ public class ElectrumServer {
return receiveTransactionMap; 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<>(); Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap = new TreeMap<>();
Collection<WalletNode> nodes = Set.of(walletNode);
subscribeWalletNodes(wallet, nodes, nodeTransactionMap, 0); subscribeWalletNodes(wallet, nodes, nodeTransactionMap, 0);
getReferences(wallet, nodes, nodeTransactionMap); getReferences(wallet, nodes, nodeTransactionMap);
@ -760,16 +759,16 @@ public class ElectrumServer {
public static class TransactionHistoryService extends Service<Boolean> { public static class TransactionHistoryService extends Service<Boolean> {
private final Wallet wallet; private final Wallet wallet;
private final WalletNode node; private final Set<WalletNode> nodes;
public TransactionHistoryService(Wallet wallet) { public TransactionHistoryService(Wallet wallet) {
this.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.wallet = wallet;
this.node = node; this.nodes = nodes;
} }
@Override @Override
@ -777,7 +776,7 @@ public class ElectrumServer {
return new Task<>() { return new Task<>() {
protected Boolean call() throws ServerException { protected Boolean call() throws ServerException {
ElectrumServer electrumServer = new ElectrumServer(); 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.getReferencedTransactions(wallet, nodeTransactionMap);
electrumServer.calculateNodeHistory(wallet, nodeTransactionMap); electrumServer.calculateNodeHistory(wallet, nodeTransactionMap);
return true; return true;

View file

@ -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); log.debug("Creating tx " + walletTransactionProperty.get().getTransaction().getTxId() + ", expecting notifications for \ninputs \n" + nodeHashes + " and \nchange \n" + changeHash);
} }
addWalletTransactionNodes();
createdWalletTransactionProperty.set(walletTransactionProperty.get()); createdWalletTransactionProperty.set(walletTransactionProperty.get());
PSBT psbt = walletTransactionProperty.get().createPSBT(); PSBT psbt = walletTransactionProperty.get().createPSBT();
EventManager.get().post(new ViewPSBTEvent(label.getText(), psbt)); 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 @Subscribe
public void walletNodesChanged(WalletNodesChangedEvent event) { public void walletNodesChanged(WalletNodesChangedEvent event) {
if(event.getWallet().equals(walletForm.getWallet())) { if(event.getWallet().equals(walletForm.getWallet())) {

View file

@ -116,13 +116,12 @@ public class TransactionEntry extends Entry implements Comparable<TransactionEnt
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
TransactionEntry that = (TransactionEntry) o; TransactionEntry that = (TransactionEntry) o;
return wallet.equals(that.wallet) && blockTransaction.equals(that.blockTransaction) && return wallet.equals(that.wallet) && blockTransaction.equals(that.blockTransaction) && getChildren().size() == that.getChildren().size();
getChildren().equals(that.getChildren());
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(wallet, blockTransaction, getChildren()); return Objects.hash(wallet, blockTransaction, getChildren().size());
} }
@Override @Override

View file

@ -27,6 +27,7 @@ public class WalletForm {
private WalletTransactionsEntry walletTransactionsEntry; private WalletTransactionsEntry walletTransactionsEntry;
private WalletUtxosEntry walletUtxosEntry; private WalletUtxosEntry walletUtxosEntry;
private final List<NodeEntry> accountEntries = new ArrayList<>(); private final List<NodeEntry> accountEntries = new ArrayList<>();
private final List<Set<WalletNode>> walletTransactionNodes = new ArrayList<>();
public WalletForm(Storage storage, Wallet currentWallet) { public WalletForm(Storage storage, Wallet currentWallet) {
this.storage = storage; this.storage = storage;
@ -76,7 +77,7 @@ public class WalletForm {
Wallet previousWallet = wallet.copy(); Wallet previousWallet = wallet.copy();
if(wallet.isValid() && AppController.isOnline()) { if(wallet.isValid() && AppController.isOnline()) {
log.debug(node == null ? "Refreshing full wallet history" : "Requesting node wallet history for " + node.getDerivationPath()); 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 -> { historyService.setOnSucceeded(workerStateEvent -> {
EventManager.get().post(new WalletHistoryStatusEvent(true)); EventManager.get().post(new WalletHistoryStatusEvent(true));
updateWallet(previousWallet, blockHeight); updateWallet(previousWallet, blockHeight);
@ -136,6 +137,25 @@ public class WalletForm {
return changedNodes; 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) { public NodeEntry getNodeEntry(KeyPurpose keyPurpose) {
NodeEntry purposeEntry; NodeEntry purposeEntry;
Optional<NodeEntry> optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst(); Optional<NodeEntry> optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst();