save the freeze status and labels of nested wallet outputs to the wallet that stores them
What changed, and why it matters
This commit fixes a bookkeeping bug in Sparrow Wallet for users who have a main wallet with nested sub-wallets (for example, PayNym-style wallets). Previously, when you froze an unspent coin or changed its label, the change was recorded against the master wallet even if the coin actually belonged to a nested wallet. The patch makes sure the freeze status and label are saved to the wallet that truly owns the coin. It is a correctness and data-integrity fix rather than a remote hack, but it could affect which coins are spendable or how balances are displayed.
Treat as a routine bug-fix commit. Reviewers should verify that `getOwningWallet()` is correctly populated in all entry-creation paths and that no remaining call sites still use `getWallet()` for persistence. Users relying on nested wallets should upgrade to ensure freeze/label state is preserved correctly.
Security signals we found
State-persistence bug: freeze/label changes for nested-wallet UTXOs were saved to the wrong wallet
UI/event routing now keyed by owning wallet rather than display wallet
New unit tests added to assert correct ownership semantics
No cryptographic, network, or input-validation changes observed
Evidence from the diff
The diff introduces an owningWallet concept on Entry, HashIndexEntry, and TransactionEntry, distinct from the wallet field that already represented the display wallet (master for nested wallets). All call sites that previously used entry.getWallet() to persist UTXO status/label changes now use entry.getOwningWallet(). Freeze/unfreeze and label-change events are grouped by owning wallet and emitted per wallet. A new test file verifies that nested outputs are shown under the master but owned by the nested wallet, and that shared transaction children are owned by the wallet storing each output. The change is localized to wallet-state persistence and UI refresh logic.
Changed components
Wallet state persistence (freeze status, labels)UTXO list UI and context menusTransaction entry rendering for nested/master walletsWalletLabels import/exportTerminal UTXOs dialogInspect captured patch +116 / −26
### src/main/java/com/sparrowwallet/sparrow/control/AddressCell.java
@@ -83,7 +83,7 @@ public static Hyperlink getDustAttackHyperlink(UtxoEntry utxoEntry) {
if(utxoEntry.getHashIndex().getStatus() != Status.FROZEN) {
hyperlink.setText("");
utxoEntry.getHashIndex().setStatus(Status.FROZEN);
- EventManager.get().post(new WalletUtxoStatusChangedEvent(utxoEntry.getWallet(), Collections.singletonList(utxoEntry.getHashIndex())));
+ EventManager.get().post(new WalletUtxoStatusChangedEvent(utxoEntry.getOwningWallet(), Collections.singletonList(utxoEntry.getHashIndex())));
}
});
### src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java
@@ -495,23 +495,22 @@ private static void sendSelectedUtxos(TreeTableView<Entry> treeTableView, HashIn
}
private static void freezeUtxo(TreeTableView<Entry> treeTableView, HashIndexEntry hashIndexEntry) {
- List<BlockTransactionHashIndex> utxos = getMenuUtxoEntries(treeTableView, hashIndexEntry, e -> !e.getHashIndex().isSpent()).stream()
- .map(HashIndexEntry::getHashIndex)
- .filter(ref -> ref.getStatus() != Status.FROZEN)
- .collect(Collectors.toList());
-
- utxos.forEach(ref -> ref.setStatus(Status.FROZEN));
- EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), utxos));
+ setUtxoStatus(getMenuUtxoEntries(treeTableView, hashIndexEntry, e -> !e.getHashIndex().isSpent() && e.getHashIndex().getStatus() != Status.FROZEN), Status.FROZEN);
}
private static void unfreezeUtxo(TreeTableView<Entry> treeTableView, HashIndexEntry hashIndexEntry) {
- List<BlockTransactionHashIndex> utxos = getMenuUtxoEntries(treeTableView, hashIndexEntry, e -> !e.getHashIndex().isSpent()).stream()
- .map(HashIndexEntry::getHashIndex)
- .filter(ref -> ref.getStatus() == Status.FROZEN)
- .collect(Collectors.toList());
+ setUtxoStatus(getMenuUtxoEntries(treeTableView, hashIndexEntry, e -> !e.getHashIndex().isSpent() && e.getHashIndex().getStatus() == Status.FROZEN), null);
+ }
+
+ //A selection can span a wallet and its nested wallets, and each change is saved by the wallet that stores the output
+ private static void setUtxoStatus(List<HashIndexEntry> utxoEntries, Status status) {
+ Map<Wallet, List<BlockTransactionHashIndex>> walletUtxos = new LinkedHashMap<>();
+ for(HashIndexEntry utxoEntry : utxoEntries) {
+ utxoEntry.getHashIndex().setStatus(status);
+ walletUtxos.computeIfAbsent(utxoEntry.getOwningWallet(), wallet -> new ArrayList<>()).add(utxoEntry.getHashIndex());
+ }
- utxos.forEach(ref -> ref.setStatus(null));
- EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), utxos));
+ walletUtxos.forEach((wallet, utxos) -> EventManager.get().post(new WalletUtxoStatusChangedEvent(wallet, utxos)));
}
private String getTooltip(TransactionEntry transactionEntry) {
@@ -765,7 +764,7 @@ public AddressContextMenu(Address address, String outputDescriptor, Wallet walle
freezeUtxos.setOnAction(AE -> {
hide();
unfrozenUtxos.forEach(utxo -> utxo.setStatus(Status.FROZEN));
- EventManager.get().post(new WalletUtxoStatusChangedEvent(wallet, unfrozenUtxos));
+ EventManager.get().post(new WalletUtxoStatusChangedEvent(node.getWallet(), unfrozenUtxos));
});
getItems().add(freezeUtxos);
}
@@ -777,7 +776,7 @@ public AddressContextMenu(Address address, String outputDescriptor, Wallet walle
unfreezeUtxos.setOnAction(AE -> {
hide();
frozenUtxos.forEach(utxo -> utxo.setStatus(null));
- EventManager.get().post(new WalletUtxoStatusChangedEvent(wallet, frozenUtxos));
+ EventManager.get().post(new WalletUtxoStatusChangedEvent(node.getWallet(), frozenUtxos));
});
getItems().add(unfreezeUtxos);
}
### src/main/java/com/sparrowwallet/sparrow/io/WalletLabels.java
@@ -351,12 +351,12 @@ private static void updateHashIndexEntryLabel(Label label, Entry entry) {
}
private static void addChangedEntry(Map<Wallet, List<Entry>> changedEntries, Entry entry) {
- List<Entry> entries = changedEntries.computeIfAbsent(entry.getWallet(), wallet -> new ArrayList<>());
+ List<Entry> entries = changedEntries.computeIfAbsent(entry.getOwningWallet(), wallet -> new ArrayList<>());
entries.add(entry);
}
private static void addChangedUtxo(Map<Wallet, List<BlockTransactionHashIndex>> changedUtxos, TransactionHashIndexEntry utxoEntry) {
- List<BlockTransactionHashIndex> utxos = changedUtxos.computeIfAbsent(utxoEntry.getWallet(), w -> new ArrayList<>());
+ List<BlockTransactionHashIndex> utxos = changedUtxos.computeIfAbsent(utxoEntry.getOwningWallet(), w -> new ArrayList<>());
utxos.add(utxoEntry.getHashIndex());
}
### src/main/java/com/sparrowwallet/sparrow/terminal/wallet/UtxosDialog.java
@@ -62,7 +62,7 @@ public UtxosDialog(WalletForm walletForm) {
if(dateCell.getEntry() instanceof UtxoEntry utxoEntry) {
utxoEntry.getHashIndex().setStatus(utxoEntry.getHashIndex().getStatus() == Status.FROZEN ? null : Status.FROZEN);
utxos.invalidate();
- EventManager.get().post(new WalletUtxoStatusChangedEvent(utxoEntry.getWallet(), List.of(utxoEntry.getHashIndex())));
+ EventManager.get().post(new WalletUtxoStatusChangedEvent(utxoEntry.getOwningWallet(), List.of(utxoEntry.getHashIndex())));
}
}
}
### src/main/java/com/sparrowwallet/sparrow/wallet/Entry.java
@@ -28,6 +28,13 @@ public Wallet getWallet() {
return wallet;
}
+ /**
+ * The wallet that stores the object of this entry, which is a nested wallet where the entry is shown under its master.
+ */
+ public Wallet getOwningWallet() {
+ return wallet;
+ }
+
public String getLabel() {
return labelProperty.get();
}
### src/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.java
@@ -15,12 +15,14 @@
import java.util.Objects;
public class HashIndexEntry extends Entry implements Comparable<HashIndexEntry> {
+ private final Wallet owningWallet;
private final BlockTransactionHashIndex hashIndex;
private final Type type;
private final KeyPurpose keyPurpose;
public HashIndexEntry(Wallet wallet, BlockTransactionHashIndex hashIndex, Type type, KeyPurpose keyPurpose) {
super(wallet.isNested() ? wallet.getMasterWallet() : wallet, hashIndex.getLabel(), hashIndex.getSpentBy() != null ? List.of(new HashIndexEntry(wallet, hashIndex.getSpentBy(), Type.INPUT, keyPurpose)) : Collections.emptyList());
+ this.owningWallet = wallet;
this.hashIndex = hashIndex;
this.type = type;
this.keyPurpose = keyPurpose;
@@ -33,6 +35,11 @@ public HashIndexEntry(Wallet wallet, BlockTransactionHashIndex hashIndex, Type t
});
}
+ @Override
+ public Wallet getOwningWallet() {
+ return owningWallet;
+ }
+
public BlockTransactionHashIndex getHashIndex() {
return hashIndex;
}
### src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java
@@ -24,10 +24,21 @@
public class TransactionEntry extends Entry implements Comparable<TransactionEntry> {
private static final Logger log = LoggerFactory.getLogger(TransactionEntry.class);
+ private final Wallet owningWallet;
private final BlockTransaction blockTransaction;
public TransactionEntry(Wallet wallet, BlockTransaction blockTransaction, Map<BlockTransactionHashIndex, KeyPurpose> inputs, Map<BlockTransactionHashIndex, KeyPurpose> outputs) {
- super(wallet.isNested() ? wallet.getMasterWallet() : wallet, blockTransaction.getLabel(), createChildEntries(wallet, inputs, outputs));
+ this(wallet, blockTransaction, inputs, outputs, Collections.emptyMap());
+ }
+
+ /**
+ * Creates an entry whose inputs and outputs may belong to other wallets of the same master, as for a transaction between a wallet and its nested
+ * wallets, with the wallet storing each given where it is not the transaction's own.
+ */
+ public TransactionEntry(Wallet wallet, BlockTransaction blockTransaction, Map<BlockTransactionHashIndex, KeyPurpose> inputs, Map<BlockTransactionHashIndex, KeyPurpose> outputs,
+ Map<BlockTransactionHashIndex, Wallet> owningWallets) {
+ super(wallet.isNested() ? wallet.getMasterWallet() : wallet, blockTransaction.getLabel(), createChildEntries(wallet, inputs, outputs, owningWallets));
+ this.owningWallet = wallet;
this.blockTransaction = blockTransaction;
labelProperty().addListener((observable, oldValue, newValue) -> {
@@ -50,6 +61,11 @@ public String getName() {
};
}
+ @Override
+ public Wallet getOwningWallet() {
+ return owningWallet;
+ }
+
public BlockTransaction getBlockTransaction() {
return blockTransaction;
}
@@ -135,9 +151,12 @@ private Set<HashIndex> getChildHashIndexes(HashIndexEntry.Type type) {
.map(entry -> new HashIndex(entry.getHashIndex().getHash(), entry.getHashIndex().getIndex())).collect(Collectors.toSet());
}
- private static List<Entry> createChildEntries(Wallet wallet, Map<BlockTransactionHashIndex, KeyPurpose> incoming, Map<BlockTransactionHashIndex, KeyPurpose> outgoing) {
- List<Entry> incomingOutputEntries = incoming.entrySet().stream().map(input -> new TransactionHashIndexEntry(wallet, input.getKey(), HashIndexEntry.Type.OUTPUT, input.getValue())).collect(Collectors.toList());
- List<Entry> outgoingInputEntries = outgoing.entrySet().stream().map(output -> new TransactionHashIndexEntry(wallet, output.getKey(), HashIndexEntry.Type.INPUT, output.getValue())).collect(Collectors.toList());
+ private static List<Entry> createChildEntries(Wallet wallet, Map<BlockTransactionHashIndex, KeyPurpose> incoming, Map<BlockTransactionHashIndex, KeyPurpose> outgoing,
+ Map<BlockTransactionHashIndex, Wallet> owningWallets) {
+ List<Entry> incomingOutputEntries = incoming.entrySet().stream().map(input -> new TransactionHashIndexEntry(owningWallets.getOrDefault(input.getKey(), wallet),
+ input.getKey(), HashIndexEntry.Type.OUTPUT, input.getValue())).collect(Collectors.toList());
+ List<Entry> outgoingInputEntries = outgoing.entrySet().stream().map(output -> new TransactionHashIndexEntry(owningWallets.getOrDefault(output.getKey(), wallet),
+ output.getKey(), HashIndexEntry.Type.INPUT, output.getValue())).collect(Collectors.toList());
List<Entry> childEntries = new ArrayList<>();
childEntries.addAll(incomingOutputEntries);
### src/main/java/com/sparrowwallet/sparrow/wallet/TransactionsController.java
@@ -265,7 +265,7 @@ private void connectionFailed(ConnectionFailedEvent event) {
@Subscribe
public void walletUtxoStatusChanged(WalletUtxoStatusChangedEvent event) {
- if(event.getWallet().equals(getWalletForm().getWallet())) {
+ if(event.fromThisOrNested(getWalletForm().getWallet())) {
transactionsTable.refresh();
}
}
### src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java
@@ -790,7 +790,7 @@ public void walletDeleted(WalletDeletedEvent event) {
@Subscribe
public void walletUtxoStatusChanged(WalletUtxoStatusChangedEvent event) {
- if(event.getWallet() == wallet) {
+ if(event.fromThisOrNested(wallet)) {
Platform.runLater(() -> EventManager.get().post(new WalletDataChangedEvent(wallet)));
}
}
### src/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.java
@@ -163,6 +163,7 @@ private static void getWalletTransactions(Wallet wallet, Map<BlockTransaction, W
walletTransactionMap.put(inputTx, inputWalletTx);
}
inputWalletTx.incoming.put(hashIndex, keyPurpose);
+ inputWalletTx.owningWallets.put(hashIndex, wallet);
if(hashIndex.getSpentBy() != null) {
BlockTransaction outputTx = transactionsWallet.getWalletTransaction(hashIndex.getSpentBy().getHash());
@@ -173,6 +174,7 @@ private static void getWalletTransactions(Wallet wallet, Map<BlockTransaction, W
walletTransactionMap.put(outputTx, outputWalletTx);
}
outputWalletTx.outgoing.put(hashIndex.getSpentBy(), keyPurpose);
+ outputWalletTx.owningWallets.put(hashIndex.getSpentBy(), wallet);
}
}
}
@@ -259,14 +261,15 @@ private static class WalletTransaction implements Comparable<WalletTransaction>
private final BlockTransaction blockTransaction;
private final Map<BlockTransactionHashIndex, KeyPurpose> incoming = new TreeMap<>();
private final Map<BlockTransactionHashIndex, KeyPurpose> outgoing = new TreeMap<>();
+ private final Map<BlockTransactionHashIndex, Wallet> owningWallets = new IdentityHashMap<>();
public WalletTransaction(Wallet wallet, BlockTransaction blockTransaction) {
this.wallet = wallet;
this.blockTransaction = blockTransaction;
}
public TransactionEntry getTransactionEntry() {
- return new TransactionEntry(wallet, blockTransaction, incoming, outgoing);
+ return new TransactionEntry(wallet, blockTransaction, incoming, outgoing, owningWallets);
}
public long getValue() {
### src/test/java/com/sparrowwallet/sparrow/wallet/EntryOwningWalletTest.java
@@ -0,0 +1,55 @@
+package com.sparrowwallet.sparrow.wallet;
+
+import com.sparrowwallet.drongo.KeyPurpose;
+import com.sparrowwallet.drongo.protocol.Sha256Hash;
+import com.sparrowwallet.drongo.protocol.Transaction;
+import com.sparrowwallet.drongo.wallet.*;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+public class EntryOwningWalletTest {
+ private static Wallet nestedWallet(Wallet masterWallet) {
+ Wallet nested = new Wallet("PayNym");
+ Keystore keystore = new Keystore();
+ keystore.setSource(KeystoreSource.SW_PAYMENT_CODE);
+ nested.getKeystores().add(keystore);
+ nested.setMasterWallet(masterWallet);
+ masterWallet.getChildWallets().add(nested);
+ Assertions.assertTrue(nested.isNested());
+ return nested;
+ }
+
+ @Test
+ public void nestedOutputIsShownUnderTheMasterAndOwnedByTheNestedWallet() {
+ Wallet master = new Wallet("Master");
+ Wallet nested = nestedWallet(master);
+
+ BlockTransactionHashIndex output = new BlockTransactionHashIndex(Sha256Hash.ZERO_HASH, 100, null, null, 0, 1000);
+ HashIndexEntry entry = new HashIndexEntry(nested, output, HashIndexEntry.Type.OUTPUT, KeyPurpose.RECEIVE);
+ Assertions.assertSame(master, entry.getWallet());
+ Assertions.assertSame(nested, entry.getOwningWallet());
+ }
+
+ @Test
+ public void sharedTransactionChildrenAreOwnedByTheWalletStoringEachOutput() {
+ Wallet master = new Wallet("Master");
+ master.setStoredBlockHeight(200);
+ Wallet nested = nestedWallet(master);
+
+ BlockTransactionHashIndex masterOutput = new BlockTransactionHashIndex(Sha256Hash.ZERO_HASH, 100, null, null, 0, 1000);
+ BlockTransactionHashIndex nestedOutput = new BlockTransactionHashIndex(Sha256Hash.ZERO_HASH, 100, null, null, 1, 2000);
+ Map<BlockTransactionHashIndex, KeyPurpose> incoming = new TreeMap<>(Map.of(masterOutput, KeyPurpose.RECEIVE, nestedOutput, KeyPurpose.RECEIVE));
+ BlockTransaction blockTransaction = new BlockTransaction(Sha256Hash.ZERO_HASH, 100, null, null, new Transaction());
+
+ TransactionEntry transactionEntry = new TransactionEntry(master, blockTransaction, incoming, new TreeMap<>(), Map.of(nestedOutput, nested));
+ Assertions.assertSame(master, transactionEntry.getOwningWallet());
+ for(Entry child : transactionEntry.getChildren()) {
+ HashIndexEntry hashIndexEntry = (HashIndexEntry)child;
+ Assertions.assertSame(master, hashIndexEntry.getWallet());
+ Assertions.assertSame(hashIndexEntry.getHashIndex() == nestedOutput ? nested : master, hashIndexEntry.getOwningWallet());
+ }
+ }
+}Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.