diff --git a/BTCPayServer/Services/Wallets/BTCPayWallet.cs b/BTCPayServer/Services/Wallets/BTCPayWallet.cs index f87dc77db..90956226c 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWallet.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWallet.cs @@ -108,9 +108,17 @@ namespace BTCPayServer.Services.Wallets public async Task GetBalance(DerivationStrategyBase derivationStrategy) { var result = await _Client.SyncAsync(derivationStrategy, null, true); - return result.Confirmed.UTXOs.Select(u => u.Value) - .Concat(result.Unconfirmed.UTXOs.Select(u => u.Value)) - .Sum(); + + Dictionary received = new Dictionary(); + foreach(var utxo in result.Confirmed.UTXOs.Concat(result.Unconfirmed.UTXOs)) + { + received.TryAdd(utxo.Outpoint, utxo); + } + foreach (var utxo in result.Confirmed.SpentOutpoints.Concat(result.Unconfirmed.SpentOutpoints)) + { + received.Remove(utxo); + } + return received.Values.Select(c => c.Value).Sum(); } } }