From d7fc0793767c22ae34d7bd15e7bcca67a63a66c6 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 8 May 2019 15:24:20 +0900 Subject: [PATCH] RBF on by default, can disable it in Wallet Send /advanced settings. --- BTCPayServer/BTCPayNetwork.cs | 1 + BTCPayServer/BTCPayNetworkProvider.Bitcoin.cs | 3 ++- BTCPayServer/Controllers/WalletsController.cs | 14 ++++++++++---- .../WalletViewModels/WalletSendLedgerModel.cs | 1 + .../Models/WalletViewModels/WalletSendModel.cs | 3 +++ BTCPayServer/Views/Wallets/WalletSend.cshtml | 8 ++++++++ BTCPayServer/Views/Wallets/WalletSendLedger.cshtml | 1 + BTCPayServer/wwwroot/js/WalletSendLedger.js | 2 ++ 8 files changed, 28 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/BTCPayNetwork.cs b/BTCPayServer/BTCPayNetwork.cs index 685215e6b..d98852137 100644 --- a/BTCPayServer/BTCPayNetwork.cs +++ b/BTCPayServer/BTCPayNetwork.cs @@ -64,6 +64,7 @@ namespace BTCPayServer public KeyPath CoinType { get; internal set; } public int MaxTrackedConfirmation { get; internal set; } = 6; public string[] DefaultRateRules { get; internal set; } = Array.Empty(); + public bool SupportRBF { get; internal set; } public override string ToString() { diff --git a/BTCPayServer/BTCPayNetworkProvider.Bitcoin.cs b/BTCPayServer/BTCPayNetworkProvider.Bitcoin.cs index b6752d0e2..34fae7c51 100644 --- a/BTCPayServer/BTCPayNetworkProvider.Bitcoin.cs +++ b/BTCPayServer/BTCPayNetworkProvider.Bitcoin.cs @@ -25,7 +25,8 @@ namespace BTCPayServer CryptoImagePath = "imlegacy/bitcoin.svg", LightningImagePath = "imlegacy/bitcoin-lightning.svg", DefaultSettings = BTCPayDefaultSettings.GetDefaultSettings(NetworkType), - CoinType = NetworkType == NetworkType.Mainnet ? new KeyPath("0'") : new KeyPath("1'") + CoinType = NetworkType == NetworkType.Mainnet ? new KeyPath("0'") : new KeyPath("1'"), + SupportRBF = true }); } } diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 2b9b03620..5160c14bf 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -175,7 +175,7 @@ namespace BTCPayServer.Controllers model.CurrentBalance = (await balance).ToDecimal(MoneyUnit.BTC); model.RecommendedSatoshiPerByte = (int)(await recommendedFees).GetFee(1).Satoshi; model.FeeSatoshiPerByte = model.RecommendedSatoshiPerByte; - + model.SupportRBF = network.SupportRBF; using (CancellationTokenSource cts = new CancellationTokenSource()) { try @@ -212,7 +212,7 @@ namespace BTCPayServer.Controllers var network = this.NetworkProvider.GetNetwork(walletId?.CryptoCode); if (network == null) return NotFound(); - + vm.SupportRBF = network.SupportRBF; var destination = ParseDestination(vm.Destination, network.NBitcoinNetwork); if (destination == null) ModelState.AddModelError(nameof(vm.Destination), "Invalid address"); @@ -233,7 +233,8 @@ namespace BTCPayServer.Controllers Amount = vm.Amount.Value, SubstractFees = vm.SubstractFees, FeeSatoshiPerByte = vm.FeeSatoshiPerByte, - NoChange = vm.NoChange + NoChange = vm.NoChange, + DisableRBF = vm.DisableRBF }; if (command == "ledger") { @@ -254,6 +255,10 @@ namespace BTCPayServer.Controllers CreatePSBTRequest psbtRequest = new CreatePSBTRequest(); CreatePSBTDestination psbtDestination = new CreatePSBTDestination(); psbtRequest.Destinations.Add(psbtDestination); + if (network.SupportRBF) + { + psbtRequest.RBF = !sendModel.DisableRBF; + } psbtDestination.Destination = BitcoinAddress.Create(sendModel.Destination, network.NBitcoinNetwork); psbtDestination.Amount = Money.Coins(sendModel.Amount); psbtRequest.FeePreference = new FeePreference(); @@ -447,7 +452,7 @@ namespace BTCPayServer.Controllers int account = 0, // sendtoaddress bool noChange = false, - string destination = null, string amount = null, string feeRate = null, bool substractFees = false + string destination = null, string amount = null, string feeRate = null, bool substractFees = false, bool disableRBF = false ) { if (!HttpContext.WebSockets.IsWebSocketRequest) @@ -511,6 +516,7 @@ namespace BTCPayServer.Controllers model.SubstractFees = substractFees; model.NoChange = noChange; + model.DisableRBF = disableRBF; if (command == "test") { result = await hw.Test(normalOperationTimeout.Token); diff --git a/BTCPayServer/Models/WalletViewModels/WalletSendLedgerModel.cs b/BTCPayServer/Models/WalletViewModels/WalletSendLedgerModel.cs index 948903714..6c4fbb131 100644 --- a/BTCPayServer/Models/WalletViewModels/WalletSendLedgerModel.cs +++ b/BTCPayServer/Models/WalletViewModels/WalletSendLedgerModel.cs @@ -9,6 +9,7 @@ namespace BTCPayServer.Models.WalletViewModels { public int FeeSatoshiPerByte { get; set; } public bool SubstractFees { get; set; } + public bool DisableRBF { get; set; } public decimal Amount { get; set; } public string Destination { get; set; } public bool NoChange { get; set; } diff --git a/BTCPayServer/Models/WalletViewModels/WalletSendModel.cs b/BTCPayServer/Models/WalletViewModels/WalletSendModel.cs index 6668ab46d..7c12c8ba3 100644 --- a/BTCPayServer/Models/WalletViewModels/WalletSendModel.cs +++ b/BTCPayServer/Models/WalletViewModels/WalletSendModel.cs @@ -35,5 +35,8 @@ namespace BTCPayServer.Models.WalletViewModels public int Divisibility { get; set; } public string Fiat { get; set; } public string RateError { get; set; } + public bool SupportRBF { get; set; } + [Display(Name = "Disable RBF")] + public bool DisableRBF { get; set; } } } diff --git a/BTCPayServer/Views/Wallets/WalletSend.cshtml b/BTCPayServer/Views/Wallets/WalletSend.cshtml index 4759af283..8256befee 100644 --- a/BTCPayServer/Views/Wallets/WalletSend.cshtml +++ b/BTCPayServer/Views/Wallets/WalletSend.cshtml @@ -71,6 +71,14 @@ + @if (Model.SupportRBF) + { +
+ + + +
+ } diff --git a/BTCPayServer/Views/Wallets/WalletSendLedger.cshtml b/BTCPayServer/Views/Wallets/WalletSendLedger.cshtml index 9e63d9b0c..0ac7c1869 100644 --- a/BTCPayServer/Views/Wallets/WalletSendLedger.cshtml +++ b/BTCPayServer/Views/Wallets/WalletSendLedger.cshtml @@ -15,6 +15,7 @@ +

diff --git a/BTCPayServer/wwwroot/js/WalletSendLedger.js b/BTCPayServer/wwwroot/js/WalletSendLedger.js index 7d87647e8..a6c10acb5 100644 --- a/BTCPayServer/wwwroot/js/WalletSendLedger.js +++ b/BTCPayServer/wwwroot/js/WalletSendLedger.js @@ -4,6 +4,7 @@ var fee = $("#FeeSatoshiPerByte").val(); var substractFee = $("#SubstractFees").val(); var noChange = $("#NoChange").val(); + var disableRBF = $("#DisableRBF").val(); var loc = window.location, ws_uri; if (loc.protocol === "https:") { @@ -48,6 +49,7 @@ args += "&feeRate=" + fee; args += "&substractFees=" + substractFee; args += "&noChange=" + noChange; + args += "&disableRBF=" + disableRBF; if (noChange === "True") { WriteAlert("warning", 'WARNING: Because you want to make sure no change UTXO is created, you will end up sending more than the chosen amount to your destination. Please validate the transaction on your ledger');