diff --git a/BTCPayServer.Client/BTCPayServer.Client.csproj b/BTCPayServer.Client/BTCPayServer.Client.csproj
index 035d01c9b..d1e7df665 100644
--- a/BTCPayServer.Client/BTCPayServer.Client.csproj
+++ b/BTCPayServer.Client/BTCPayServer.Client.csproj
@@ -5,7 +5,7 @@
-
+
diff --git a/BTCPayServer/Payments/PayJoin/PayJoinEndpointController.cs b/BTCPayServer/Payments/PayJoin/PayJoinEndpointController.cs
index 6efdc22d9..c79e15d7a 100644
--- a/BTCPayServer/Payments/PayJoin/PayJoinEndpointController.cs
+++ b/BTCPayServer/Payments/PayJoin/PayJoinEndpointController.cs
@@ -19,10 +19,8 @@ using NBXplorer;
using NBXplorer.Models;
using Newtonsoft.Json.Linq;
using NicolasDorier.RateLimits;
-using Microsoft.Extensions.Logging;
using NBXplorer.DerivationStrategy;
using System.Diagnostics.CodeAnalysis;
-using BTCPayServer.Logging;
namespace BTCPayServer.Payments.PayJoin
{
@@ -385,18 +383,8 @@ namespace BTCPayServer.Payments.PayJoin
Money ourFeeContribution = Money.Zero;
// We need to adjust the fee to keep a constant fee rate
var txBuilder = network.NBitcoinNetwork.CreateTransactionBuilder();
- var coins = new List();
- if (sendersInputType != ScriptPubKeyType.SegwitP2SH)
- {
- coins.AddRange(psbt.Inputs.Select(i => i.GetCoin()));
- coins.AddRange(selectedUTXOs.Select(o => o.Value.AsCoin()));
- }
- else
- {
- coins.AddRange(psbt.Inputs.Select(i =>i.GetCoin().ToScriptCoin(PayToScriptHashTemplate.Instance.ExtractScriptSigParameters(i.FinalScriptSig).RedeemScript)));
- coins.AddRange(selectedUTXOs.Select(pair => pair.Value.AsCoin(derivationSchemeSettings.AccountDerivation)));
- }
- txBuilder.AddCoins(coins);
+ txBuilder.AddCoins(psbt.Inputs.Select(i => i.GetSignableCoin()));
+ txBuilder.AddCoins(selectedUTXOs.Select(o => o.Value.AsCoin(derivationSchemeSettings.AccountDerivation)));
Money expectedFee = txBuilder.EstimateFees(newTx, originalFeeRate);
Money actualFee = newTx.GetFee(txBuilder.FindSpentCoins(newTx));
Money additionalFee = expectedFee - actualFee;
@@ -454,8 +442,6 @@ namespace BTCPayServer.Payments.PayJoin
var coin = selectedUtxo.AsCoin(derivationSchemeSettings.AccountDerivation);
signedInput.UpdateFromCoin(coin);
var privateKey = accountKey.Derive(selectedUtxo.KeyPath).PrivateKey;
- //hack until UpdateFromCoin is fixed in NBitcoin when the coin is p2sh
- signedInput.WitnessUtxo = coin.TxOut;
signedInput.Sign(privateKey);
signedInput.FinalizeInput();
newTx.Inputs[signedInput.Index].WitScript = newPsbt.Inputs[(int)signedInput.Index].FinalScriptWitness;
diff --git a/BTCPayServer/Services/PayjoinClient.cs b/BTCPayServer/Services/PayjoinClient.cs
index 17e95dcc9..964d91a80 100644
--- a/BTCPayServer/Services/PayjoinClient.cs
+++ b/BTCPayServer/Services/PayjoinClient.cs
@@ -213,31 +213,8 @@ namespace BTCPayServer.Services
{
var overPaying = sentAfter - sentBefore;
- //hack until GetAllCoins is fixed in NBitcoin when the coin is p2sh (redeem needs to be loaded from RedeemScript and fallback to i.FinalScriptSig extraction)
- int newVirtualSize = 0;
- if (type == ScriptPubKeyType.SegwitP2SH)
- {
- if (!newPSBT.TryGetFee(out var fee))
- {
- throw new PayjoinSenderException("The payjoin receiver did not included UTXO information to calculate fee correctly");
- }
- var transactionBuilder = originalTx.Network.CreateTransactionBuilder();
- transactionBuilder.AddCoins(newPSBT.Inputs.Select(i =>i.GetCoin().ToScriptCoin(i.RedeemScript??PayToScriptHashTemplate.Instance.ExtractScriptSigParameters(i.FinalScriptSig).RedeemScript)));
- try
- {
- newVirtualSize = transactionBuilder.EstimateSize(newPSBT.GetGlobalTransaction(), true);
- }
- catch
- {
- throw new PayjoinSenderException("The payjoin receiver did not included UTXO information to calculate fee correctly");
- }
-
- }
- else
- {
- if (!newPSBT.TryGetEstimatedFeeRate(out var newFeeRate) || !newPSBT.TryGetVirtualSize(out newVirtualSize))
- throw new PayjoinSenderException("The payjoin receiver did not included UTXO information to calculate fee correctly");
- }
+ if (!newPSBT.TryGetEstimatedFeeRate(out var newFeeRate) || !newPSBT.TryGetVirtualSize(out var newVirtualSize))
+ throw new PayjoinSenderException("The payjoin receiver did not included UTXO information to calculate fee correctly");
var additionalFee = newPSBT.GetFee() - originalFee;
if (overPaying > additionalFee)