mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
fixes
This commit is contained in:
parent
514b695907
commit
51db617584
2 changed files with 33 additions and 5 deletions
|
@ -451,8 +451,11 @@ namespace BTCPayServer.Payments.PayJoin
|
|||
foreach (var selectedUtxo in selectedUTXOs.Select(o => o.Value))
|
||||
{
|
||||
var signedInput = newPsbt.Inputs.FindIndexedInput(selectedUtxo.Outpoint);
|
||||
signedInput.UpdateFromCoin(selectedUtxo.AsCoin());
|
||||
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;
|
||||
|
|
|
@ -34,9 +34,9 @@ namespace BTCPayServer.Services
|
|||
if (i.WitnessUtxo.ScriptPubKey.IsScriptType(ScriptType.P2WPKH))
|
||||
return ScriptPubKeyType.Segwit;
|
||||
if (i.WitnessUtxo.ScriptPubKey.IsScriptType(ScriptType.P2SH) &&
|
||||
i.FinalScriptWitness.GetSigner().ScriptPubKey.IsScriptType(ScriptType.P2WPKH))
|
||||
PayToWitPubKeyHashTemplate.Instance.ExtractWitScriptParameters(i.FinalScriptWitness) is {})
|
||||
return ScriptPubKeyType.SegwitP2SH;
|
||||
return null as ScriptPubKeyType?;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,8 +212,33 @@ namespace BTCPayServer.Services
|
|||
if (sentAfter > sentBefore)
|
||||
{
|
||||
var overPaying = sentAfter - sentBefore;
|
||||
if (!newPSBT.TryGetEstimatedFeeRate(out var newFeeRate) || !newPSBT.TryGetVirtualSize(out var newVirtualSize))
|
||||
|
||||
//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");
|
||||
}
|
||||
|
||||
var additionalFee = newPSBT.GetFee() - originalFee;
|
||||
if (overPaying > additionalFee)
|
||||
throw new PayjoinSenderException("The payjoin receiver is sending more money to himself");
|
||||
|
|
Loading…
Add table
Reference in a new issue