mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 22:25:28 +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>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="NBitcoin" Version="5.0.29" />
|
<PackageReference Include="NBitcoin" Version="5.0.30" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,8 @@ using NBXplorer;
|
||||||
using NBXplorer.Models;
|
using NBXplorer.Models;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NicolasDorier.RateLimits;
|
using NicolasDorier.RateLimits;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using NBXplorer.DerivationStrategy;
|
using NBXplorer.DerivationStrategy;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using BTCPayServer.Logging;
|
|
||||||
|
|
||||||
namespace BTCPayServer.Payments.PayJoin
|
namespace BTCPayServer.Payments.PayJoin
|
||||||
{
|
{
|
||||||
|
@ -385,18 +383,8 @@ namespace BTCPayServer.Payments.PayJoin
|
||||||
Money ourFeeContribution = Money.Zero;
|
Money ourFeeContribution = Money.Zero;
|
||||||
// We need to adjust the fee to keep a constant fee rate
|
// We need to adjust the fee to keep a constant fee rate
|
||||||
var txBuilder = network.NBitcoinNetwork.CreateTransactionBuilder();
|
var txBuilder = network.NBitcoinNetwork.CreateTransactionBuilder();
|
||||||
var coins = new List<Coin>();
|
txBuilder.AddCoins(psbt.Inputs.Select(i => i.GetSignableCoin()));
|
||||||
if (sendersInputType != ScriptPubKeyType.SegwitP2SH)
|
txBuilder.AddCoins(selectedUTXOs.Select(o => o.Value.AsCoin(derivationSchemeSettings.AccountDerivation)));
|
||||||
{
|
|
||||||
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);
|
|
||||||
Money expectedFee = txBuilder.EstimateFees(newTx, originalFeeRate);
|
Money expectedFee = txBuilder.EstimateFees(newTx, originalFeeRate);
|
||||||
Money actualFee = newTx.GetFee(txBuilder.FindSpentCoins(newTx));
|
Money actualFee = newTx.GetFee(txBuilder.FindSpentCoins(newTx));
|
||||||
Money additionalFee = expectedFee - actualFee;
|
Money additionalFee = expectedFee - actualFee;
|
||||||
|
@ -454,8 +442,6 @@ namespace BTCPayServer.Payments.PayJoin
|
||||||
var coin = selectedUtxo.AsCoin(derivationSchemeSettings.AccountDerivation);
|
var coin = selectedUtxo.AsCoin(derivationSchemeSettings.AccountDerivation);
|
||||||
signedInput.UpdateFromCoin(coin);
|
signedInput.UpdateFromCoin(coin);
|
||||||
var privateKey = accountKey.Derive(selectedUtxo.KeyPath).PrivateKey;
|
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.Sign(privateKey);
|
||||||
signedInput.FinalizeInput();
|
signedInput.FinalizeInput();
|
||||||
newTx.Inputs[signedInput.Index].WitScript = newPsbt.Inputs[(int)signedInput.Index].FinalScriptWitness;
|
newTx.Inputs[signedInput.Index].WitScript = newPsbt.Inputs[(int)signedInput.Index].FinalScriptWitness;
|
||||||
|
|
|
@ -213,31 +213,8 @@ namespace BTCPayServer.Services
|
||||||
{
|
{
|
||||||
var overPaying = sentAfter - sentBefore;
|
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)
|
if (!newPSBT.TryGetEstimatedFeeRate(out var newFeeRate) || !newPSBT.TryGetVirtualSize(out var newVirtualSize))
|
||||||
int newVirtualSize = 0;
|
throw new PayjoinSenderException("The payjoin receiver did not included UTXO information to calculate fee correctly");
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
var additionalFee = newPSBT.GetFee() - originalFee;
|
var additionalFee = newPSBT.GetFee() - originalFee;
|
||||||
if (overPaying > additionalFee)
|
if (overPaying > additionalFee)
|
||||||
|
|
Loading…
Add table
Reference in a new issue