diff --git a/BTCPayServer.Common/BTCPayServer.Common.csproj b/BTCPayServer.Common/BTCPayServer.Common.csproj index 0c5a12120..f0a8011e3 100644 --- a/BTCPayServer.Common/BTCPayServer.Common.csproj +++ b/BTCPayServer.Common/BTCPayServer.Common.csproj @@ -5,6 +5,6 @@ - + diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index 7294f666b..3de9cc25d 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -76,7 +76,7 @@ services: - customer_lnd - merchant_lnd nbxplorer: - image: nicolasdorier/nbxplorer:2.0.0.66 + image: nicolasdorier/nbxplorer:2.1.1 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 48de86cb0..5ea4e2d9d 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -252,7 +252,7 @@ namespace BTCPayServer.Controllers vm.Id = tx.TransactionId.ToString(); vm.Link = string.Format(CultureInfo.InvariantCulture, paymentMethod.Network.BlockExplorerLink, vm.Id); vm.Timestamp = tx.Timestamp; - vm.Positive = tx.BalanceChange >= Money.Zero; + vm.Positive = tx.BalanceChange.GetValue(wallet.Network) >= 0; vm.Balance = tx.BalanceChange.ToString(); vm.IsConfirmed = tx.Confirmations != 0; @@ -313,7 +313,7 @@ namespace BTCPayServer.Controllers var feeProvider = _feeRateProvider.CreateFeeProvider(network); var recommendedFees = feeProvider.GetFeeRateAsync(); var balance = _walletProvider.GetWallet(network).GetBalance(paymentMethod.AccountDerivation); - model.CurrentBalance = (await balance).ToDecimal(MoneyUnit.BTC); + model.CurrentBalance = await balance; model.RecommendedSatoshiPerByte = (int)(await recommendedFees).GetFee(1).Satoshi; model.FeeSatoshiPerByte = model.RecommendedSatoshiPerByte; model.SupportRBF = network.SupportRBF; @@ -912,7 +912,7 @@ namespace BTCPayServer.Controllers } else if (command == "prune") { - var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode).PruneAsync(derivationScheme.AccountDerivation, cancellationToken); + var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode).PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken); if (result.TotalPruned == 0) { TempData[WellKnownTempData.SuccessMessage] = $"The wallet is already pruned"; diff --git a/BTCPayServer/Extensions/MoneyExtensions.cs b/BTCPayServer/Extensions/MoneyExtensions.cs new file mode 100644 index 000000000..3a4b5c653 --- /dev/null +++ b/BTCPayServer/Extensions/MoneyExtensions.cs @@ -0,0 +1,29 @@ +using System; +using NBitcoin; + +namespace BTCPayServer +{ + public static class MoneyExtensions + { + public static decimal GetValue(this IMoney m, BTCPayNetwork network = null) + { + switch (m) + { + case Money money: + return money.ToDecimal(MoneyUnit.BTC); +// case MoneyBag mb: +// return mb.Select(money => money.GetValue(network)).Sum(); +// case AssetMoney assetMoney: +// if (network is ElementsBTCPayNetwork elementsBTCPayNetwork) +// { +// return elementsBTCPayNetwork.AssetId == assetMoney.AssetId +// ? new Money(assetMoney.Quantity) +// : Money.Zero; +// } +// throw new NotSupportedException("IMoney type not supported"); + default: + throw new NotSupportedException("IMoney type not supported"); + } + } + } +} diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs index 3ded51cbb..c742b8cb7 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentData.cs @@ -20,10 +20,10 @@ namespace BTCPayServer.Payments.Bitcoin { } - public BitcoinLikePaymentData(Coin coin, bool rbf) + public BitcoinLikePaymentData(TxOut txout, OutPoint outpoint, bool rbf) { - Outpoint = coin.Outpoint; - Output = coin.TxOut; + Outpoint = outpoint; + Output = txout; ConfirmationCount = 0; RBF = rbf; } diff --git a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs index e0bb76c3e..072fa983f 100644 --- a/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs +++ b/BTCPayServer/Payments/Bitcoin/NBXplorerListener.cs @@ -157,7 +157,7 @@ namespace BTCPayServer.Payments.Bitcoin var invoice = (await _InvoiceRepository.GetInvoicesFromAddresses(new [] {key})).FirstOrDefault(); if (invoice != null) { - var paymentData = new BitcoinLikePaymentData(txCoin, evt.TransactionData.Transaction.RBF); + var paymentData = new BitcoinLikePaymentData(txCoin.TxOut, txCoin.Outpoint, evt.TransactionData.Transaction.RBF); var alreadyExist = GetAllBitcoinPaymentData(invoice).Where(c => c.GetPaymentId() == paymentData.GetPaymentId()).Any(); if (!alreadyExist) { @@ -338,7 +338,7 @@ namespace BTCPayServer.Payments.Bitcoin foreach (var coin in coins.Where(c => !alreadyAccounted.Contains(c.Coin.Outpoint))) { var transaction = await wallet.GetTransactionAsync(coin.Coin.Outpoint.Hash); - var paymentData = new BitcoinLikePaymentData(coin.Coin, transaction.Transaction.RBF); + var paymentData = new BitcoinLikePaymentData(coin.Coin.TxOut, coin.Coin.Outpoint, transaction.Transaction.RBF); var payment = await _InvoiceRepository.AddPayment(invoice.Id, coin.Timestamp, paymentData, network).ConfigureAwait(false); alreadyAccounted.Add(coin.Coin.Outpoint); if (payment != null) diff --git a/BTCPayServer/Services/Wallets/BTCPayWallet.cs b/BTCPayServer/Services/Wallets/BTCPayWallet.cs index c21ed79b8..612a22551 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWallet.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWallet.cs @@ -178,10 +178,10 @@ namespace BTCPayServer.Services.Wallets }).ToArray(); } - public async Task GetBalance(DerivationStrategyBase derivationStrategy, CancellationToken cancellation = default(CancellationToken)) + public async Task GetBalance(DerivationStrategyBase derivationStrategy, CancellationToken cancellation = default(CancellationToken)) { - UTXOChanges changes = await GetUTXOChanges(derivationStrategy, cancellation); - return changes.GetUnspentUTXOs().Select(c => c.Value).Sum(); + var result = await _Client.GetBalanceAsync(derivationStrategy, cancellation); + return result.Total.GetValue(_Network); } } }