From b67a962d1253bdacc7452c19c34d0efb9f1c898e Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 2 Mar 2018 14:16:16 -0500 Subject: [PATCH] Make sure the txrelayfee is correctly set --- BTCPayServer.Tests/docker-compose.yml | 2 +- BTCPayServer/Controllers/StoresController.BTCLike.cs | 5 ++++- BTCPayServer/Controllers/StoresController.cs | 4 ++++ BTCPayServer/Services/HardwareWalletService.cs | 4 +++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index 76f5448db..548e5a6b4 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -40,7 +40,7 @@ services: - lightning-charged nbxplorer: - image: nicolasdorier/nbxplorer:1.0.1.16 + image: nicolasdorier/nbxplorer:1.0.1.17 ports: - "32838:32838" expose: diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index 43ec9976e..bb02856ea 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -224,17 +224,20 @@ namespace BTCPayServer.Controllers if (command == "sendtoaddress") { + if(!_Dashboard.IsFullySynched(network.CryptoCode, out var summary)) + throw new Exception($"{network.CryptoCode}: not started or fully synched"); var strategy = GetDirectDerivationStrategy(store, network); var strategyBase = GetDerivationStrategy(store, network); var wallet = _WalletProvider.GetWallet(network); var change = wallet.GetChangeAddressAsync(strategyBase); + var unspentCoins = await wallet.GetUnspentCoins(strategyBase); var changeAddress = await change; var transaction = await hw.SendToAddress(strategy, unspentCoins, network, new[] { (destinationAddress as IDestination, amountBTC, subsctractFeesValue) }, feeRateValue, changeAddress.Item1, - changeAddress.Item2); + changeAddress.Item2, summary.Status.BitcoinStatus.MinRelayTxFee); try { var broadcastResult = await wallet.BroadcastTransactionsAsync(new List() { transaction }); diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 3871be0ed..4e5a57824 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -1,6 +1,7 @@ using BTCPayServer.Authentication; using BTCPayServer.Configuration; using BTCPayServer.Data; +using BTCPayServer.HostedServices; using BTCPayServer.Models; using BTCPayServer.Models.StoreViewModels; using BTCPayServer.Services; @@ -31,6 +32,7 @@ namespace BTCPayServer.Controllers public partial class StoresController : Controller { public StoresController( + NBXplorerDashboard dashboard, IServiceProvider serviceProvider, BTCPayServerOptions btcpayServerOptions, BTCPayServerEnvironment btcpayEnv, @@ -45,6 +47,7 @@ namespace BTCPayServer.Controllers IFeeProviderFactory feeRateProvider, IHostingEnvironment env) { + _Dashboard = dashboard; _Repo = repo; _TokenRepository = tokenRepo; _UserManager = userManager; @@ -59,6 +62,7 @@ namespace BTCPayServer.Controllers _BtcpayServerOptions = btcpayServerOptions; _BTCPayEnv = btcpayEnv; } + NBXplorerDashboard _Dashboard; BTCPayServerOptions _BtcpayServerOptions; BTCPayServerEnvironment _BTCPayEnv; IServiceProvider _ServiceProvider; diff --git a/BTCPayServer/Services/HardwareWalletService.cs b/BTCPayServer/Services/HardwareWalletService.cs index 622977fb4..e30fa5cf5 100644 --- a/BTCPayServer/Services/HardwareWalletService.cs +++ b/BTCPayServer/Services/HardwareWalletService.cs @@ -152,7 +152,8 @@ namespace BTCPayServer.Services (IDestination destination, Money amount, bool substractFees)[] send, FeeRate feeRate, IDestination changeAddress, - KeyPath changeKeyPath) + KeyPath changeKeyPath, + FeeRate minTxRelayFee) { if (strategy == null) throw new ArgumentNullException(nameof(strategy)); @@ -185,6 +186,7 @@ namespace BTCPayServer.Services } TransactionBuilder builder = new TransactionBuilder(); + builder.StandardTransactionPolicy.MinRelayTxFee = minTxRelayFee; builder.AddCoins(coins.Select(c=>c.Coin).ToArray()); foreach (var element in send)