diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/Entry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/Entry.java index 28dfb7ec..32d88388 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/Entry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/Entry.java @@ -1,5 +1,6 @@ package com.sparrowwallet.sparrow.wallet; +import com.sparrowwallet.drongo.wallet.Wallet; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -7,19 +8,26 @@ import javafx.collections.ObservableList; import java.util.List; public abstract class Entry { + private final Wallet wallet; private final SimpleStringProperty labelProperty; private final ObservableList children; - public Entry(String label, List entries) { + public Entry(Wallet wallet, String label, List entries) { + this.wallet = wallet; this.labelProperty = new SimpleStringProperty(this, "label", label); this.children = FXCollections.observableList(entries); } - public Entry(SimpleStringProperty labelProperty, ObservableList children) { + public Entry(Wallet wallet, SimpleStringProperty labelProperty, ObservableList children) { + this.wallet = wallet; this.labelProperty = labelProperty; this.children = children; } + public Wallet getWallet() { + return wallet; + } + public String getLabel() { return labelProperty.get(); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.java index 0d2fda4b..2c0cafcc 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.java @@ -13,14 +13,12 @@ import java.util.List; import java.util.Objects; public class HashIndexEntry extends Entry implements Comparable { - private final Wallet wallet; private final BlockTransactionHashIndex hashIndex; private final Type type; private final KeyPurpose keyPurpose; public HashIndexEntry(Wallet wallet, BlockTransactionHashIndex hashIndex, Type type, KeyPurpose keyPurpose) { - super(hashIndex.getLabel(), hashIndex.getSpentBy() != null ? List.of(new HashIndexEntry(wallet, hashIndex.getSpentBy(), Type.INPUT, keyPurpose)) : Collections.emptyList()); - this.wallet = wallet; + super(wallet, hashIndex.getLabel(), hashIndex.getSpentBy() != null ? List.of(new HashIndexEntry(wallet, hashIndex.getSpentBy(), Type.INPUT, keyPurpose)) : Collections.emptyList()); this.hashIndex = hashIndex; this.type = type; this.keyPurpose = keyPurpose; @@ -31,10 +29,6 @@ public class HashIndexEntry extends Entry implements Comparable }); } - public Wallet getWallet() { - return wallet; - } - public BlockTransactionHashIndex getHashIndex() { return hashIndex; } @@ -48,7 +42,7 @@ public class HashIndexEntry extends Entry implements Comparable } public BlockTransaction getBlockTransaction() { - return wallet.getTransactions().get(hashIndex.getHash()); + return getWallet().getTransactions().get(hashIndex.getHash()); } public String getDescription() { @@ -63,7 +57,7 @@ public class HashIndexEntry extends Entry implements Comparable } public boolean isSpendable() { - return !isSpent() && (hashIndex.getHeight() > 0 || wallet.allInputsFromWallet(hashIndex.getHash())); + return !isSpent() && (hashIndex.getHeight() > 0 || getWallet().allInputsFromWallet(hashIndex.getHash())); } @Override @@ -80,7 +74,7 @@ public class HashIndexEntry extends Entry implements Comparable if (this == o) return true; if (!(o instanceof HashIndexEntry)) return false; HashIndexEntry that = (HashIndexEntry) o; - return wallet.equals(that.wallet) && + return getWallet().equals(that.getWallet()) && hashIndex.equals(that.hashIndex) && type == that.type && keyPurpose == that.keyPurpose; @@ -88,7 +82,7 @@ public class HashIndexEntry extends Entry implements Comparable @Override public int hashCode() { - return Objects.hash(wallet, hashIndex, type, keyPurpose); + return Objects.hash(getWallet(), hashIndex, type, keyPurpose); } @Override diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java index 9890d731..363f1cd0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/NodeEntry.java @@ -10,16 +10,14 @@ import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent; import java.util.stream.Collectors; public class NodeEntry extends Entry implements Comparable { - private final Wallet wallet; private final WalletNode node; public NodeEntry(Wallet wallet, WalletNode node) { - super(node.getLabel(), + super(wallet, node.getLabel(), !node.getChildren().isEmpty() ? node.getChildren().stream().map(childNode -> new NodeEntry(wallet, childNode)).collect(Collectors.toList()) : node.getTransactionOutputs().stream().map(txo -> new HashIndexEntry(wallet, txo, HashIndexEntry.Type.OUTPUT, node.getKeyPurpose())).collect(Collectors.toList())); - this.wallet = wallet; this.node = node; labelProperty().addListener((observable, oldValue, newValue) -> { @@ -28,24 +26,20 @@ public class NodeEntry extends Entry implements Comparable { }); } - public Wallet getWallet() { - return wallet; - } - public WalletNode getNode() { return node; } public Address getAddress() { - return wallet.getAddress(node); + return getWallet().getAddress(node); } public Script getOutputScript() { - return wallet.getOutputScript(node); + return getWallet().getOutputScript(node); } public String getOutputDescriptor() { - return wallet.getOutputDescriptor(node); + return getWallet().getOutputDescriptor(node); } @Override diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java index 55a9b498..fdf43c12 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java @@ -19,12 +19,10 @@ import java.util.*; import java.util.stream.Collectors; public class TransactionEntry extends Entry implements Comparable { - private final Wallet wallet; private final BlockTransaction blockTransaction; public TransactionEntry(Wallet wallet, BlockTransaction blockTransaction, Map inputs, Map outputs) { - super(blockTransaction.getLabel(), createChildEntries(wallet, inputs, outputs)); - this.wallet = wallet; + super(wallet, blockTransaction.getLabel(), createChildEntries(wallet, inputs, outputs)); this.blockTransaction = blockTransaction; labelProperty().addListener((observable, oldValue, newValue) -> { @@ -38,10 +36,6 @@ public class TransactionEntry extends Entry implements Comparable walletTxos = wallet.getWalletTxos(); + Map walletTxos = getWallet().getWalletTxos(); for(TransactionInput txInput : blockTransaction.getTransaction().getInputs()) { Optional optRef = walletTxos.keySet().stream().filter(ref -> ref.getHash().equals(txInput.getOutpoint().getHash()) && ref.getIndex() == txInput.getOutpoint().getIndex()).findFirst(); if(optRef.isPresent()) { @@ -146,12 +140,12 @@ public class TransactionEntry extends Entry implements Comparable current = getWalletTransactions(wallet).stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toList()); + List current = getWalletTransactions(getWallet()).stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toList()); List previous = new ArrayList<>(getChildren()); List entriesAdded = new ArrayList<>(current); @@ -76,7 +69,7 @@ public class WalletTransactionsEntry extends Entry { List blockTransactions = entriesAdded.stream().map(txEntry -> ((TransactionEntry)txEntry).getBlockTransaction()).collect(Collectors.toList()); long totalBlockchainValue = entriesAdded.stream().filter(txEntry -> ((TransactionEntry)txEntry).getConfirmations() > 0).mapToLong(Entry::getValue).sum(); long totalMempoolValue = entriesAdded.stream().filter(txEntry -> ((TransactionEntry)txEntry).getConfirmations() == 0).mapToLong(Entry::getValue).sum(); - EventManager.get().post(new NewWalletTransactionsEvent(wallet, blockTransactions, totalBlockchainValue, totalMempoolValue)); + EventManager.get().post(new NewWalletTransactionsEvent(getWallet(), blockTransactions, totalBlockchainValue, totalMempoolValue)); } if(entriesAdded.size() > entriesComplete.size()) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletUtxosEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletUtxosEntry.java index 45763856..6d61a64b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletUtxosEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletUtxosEntry.java @@ -6,18 +6,11 @@ import java.util.*; import java.util.stream.Collectors; public class WalletUtxosEntry extends Entry { - private final Wallet wallet; - public WalletUtxosEntry(Wallet wallet) { - super(wallet.getName(), wallet.getWalletUtxos().entrySet().stream().map(entry -> new UtxoEntry(wallet, entry.getKey(), HashIndexEntry.Type.OUTPUT, entry.getValue())).collect(Collectors.toList())); - this.wallet = wallet; + super(wallet, wallet.getName(), wallet.getWalletUtxos().entrySet().stream().map(entry -> new UtxoEntry(wallet, entry.getKey(), HashIndexEntry.Type.OUTPUT, entry.getValue())).collect(Collectors.toList())); calculateDuplicates(); } - public Wallet getWallet() { - return wallet; - } - @Override public Long getValue() { return 0L; @@ -42,7 +35,7 @@ public class WalletUtxosEntry extends Entry { } public void updateUtxos() { - List current = wallet.getWalletUtxos().entrySet().stream().map(entry -> new UtxoEntry(wallet, entry.getKey(), HashIndexEntry.Type.OUTPUT, entry.getValue())).collect(Collectors.toList()); + List current = getWallet().getWalletUtxos().entrySet().stream().map(entry -> new UtxoEntry(getWallet(), entry.getKey(), HashIndexEntry.Type.OUTPUT, entry.getValue())).collect(Collectors.toList()); List previous = new ArrayList<>(getChildren()); List entriesAdded = new ArrayList<>(current);