use of com.sparrowwallet.sparrow.event.NewWalletTransactionsEvent in project sparrow by sparrowwallet.
the class WalletTransactionsEntry method updateTransactions.
public void updateTransactions() {
Map<HashIndex, BlockTransactionHashIndex> walletTxos = getWallet().getWalletTxos().entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> new HashIndex(entry.getKey().getHash(), entry.getKey().getIndex()), Map.Entry::getKey));
List<Entry> current = getWalletTransactions(getWallet()).stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toList());
List<Entry> previous = new ArrayList<>(getChildren());
List<Entry> entriesAdded = new ArrayList<>(current);
entriesAdded.removeAll(previous);
getChildren().addAll(entriesAdded);
List<Entry> entriesRemoved = new ArrayList<>(previous);
entriesRemoved.removeAll(current);
getChildren().removeAll(entriesRemoved);
calculateBalances(true);
List<Entry> entriesComplete = entriesAdded.stream().filter(txEntry -> ((TransactionEntry) txEntry).isComplete(walletTxos)).collect(Collectors.toList());
if (!entriesComplete.isEmpty()) {
EventManager.get().post(new NewWalletTransactionsEvent(getWallet(), entriesAdded.stream().map(entry -> (TransactionEntry) entry).collect(Collectors.toList())));
}
if (entriesAdded.size() > entriesComplete.size()) {
entriesAdded.removeAll(entriesComplete);
for (Entry entry : entriesAdded) {
TransactionEntry txEntry = (TransactionEntry) entry;
getChildren().remove(txEntry);
log.warn("Removing and not notifying incomplete entry " + ((TransactionEntry) entry).getBlockTransaction().getHashAsString() + " value " + txEntry.getValue() + " children " + entry.getChildren().stream().map(e -> e.getEntryType() + " " + ((HashIndexEntry) e).getHashIndex()).collect(Collectors.toList()));
}
}
}
Aggregations