Skip to content

Commit

Permalink
Merge pull request #1050 from stratisproject/fixlistunspent
Browse files Browse the repository at this point in the history
RPC: Filter ListUnspent transactions for duplicates
  • Loading branch information
fassadlr authored Sep 6, 2022
2 parents 0dbf584 + 6cd9dd7 commit d6ae2b6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Stratis.Bitcoin.Features.Wallet/WalletRPCController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ public UnspentCoinModel[] ListUnspent(int minConfirmations = 1, int maxConfirmat
continue;

WalletAccountReference accountReference = new WalletAccountReference(walletName, account.Name);

IEnumerable<UnspentOutputReference> spendableTransactions = this.walletManager.GetSpendableTransactionsInAccount(accountReference, minConfirmations);

foreach (var spendableTx in spendableTransactions)
Expand All @@ -783,6 +783,11 @@ public UnspentCoinModel[] ListUnspent(int minConfirmations = 1, int maxConfirmat
if (addresses.Any() && !addresses.Contains(BitcoinAddress.Create(spendableTx.Address.Address, this.FullNode.Network)))
continue;

// Check if the transaction is already in the list.
// The node operator could be using the wallet for both "actual" and watch only accounts.
if (unspentCoins.Any(u => u.Id == spendableTx.Transaction.Id && u.Index == spendableTx.Transaction.Index))
continue;

unspentCoins.Add(new UnspentCoinModel()
{
Account = accountReference.AccountName,
Expand Down

0 comments on commit d6ae2b6

Please sign in to comment.