mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 06:21:44 +01:00
remove hacks
This commit is contained in:
parent
51db617584
commit
0077105a2d
3 changed files with 5 additions and 42 deletions
|
@ -5,7 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NBitcoin" Version="5.0.29" />
|
||||
<PackageReference Include="NBitcoin" Version="5.0.30" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -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<Coin>();
|
||||
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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue