mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
Rely on NBitcoin to get the expected hash
This commit is contained in:
parent
f8b2b18c6e
commit
47f16aadd5
@ -5,7 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NBitcoin" Version="5.0.30" />
|
||||
<PackageReference Include="NBitcoin" Version="5.0.31" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -460,7 +460,7 @@ namespace BTCPayServer.Payments.PayJoin
|
||||
originalPaymentData.ConfirmationCount = -1;
|
||||
originalPaymentData.PayjoinInformation = new PayjoinInformation()
|
||||
{
|
||||
CoinjoinTransactionHash = GetExpectedHash(newPsbt, sendersInputType, coins),
|
||||
CoinjoinTransactionHash = GetExpectedHash(newPsbt, coins),
|
||||
CoinjoinValue = originalPaymentValue - ourFeeContribution,
|
||||
ContributedOutPoints = selectedUTXOs.Select(o => o.Key).ToArray()
|
||||
};
|
||||
@ -487,25 +487,13 @@ namespace BTCPayServer.Payments.PayJoin
|
||||
return Ok(newTx.ToHex());
|
||||
}
|
||||
|
||||
private uint256 GetExpectedHash(PSBT psbt, ScriptPubKeyType? sendersInputType, Coin[] coins)
|
||||
private uint256 GetExpectedHash(PSBT psbt, Coin[] coins)
|
||||
{
|
||||
var tx = psbt.GetGlobalTransaction();
|
||||
if (sendersInputType is ScriptPubKeyType.Segwit)
|
||||
return tx.GetHash();
|
||||
else if (sendersInputType is ScriptPubKeyType.SegwitP2SH)
|
||||
{
|
||||
for (int i = 0; i < psbt.Inputs.Count; i++)
|
||||
{
|
||||
|
||||
tx.Inputs[i].ScriptSig = PayToScriptHashTemplate.Instance.GenerateScriptSig(Array.Empty<byte[]>(), ((ScriptCoin)coins.Single(coin => coin.Outpoint == psbt.Inputs[i].PrevOut)).GetP2SHRedeem());
|
||||
}
|
||||
return tx.GetHash();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
psbt = psbt.Clone();
|
||||
psbt.AddCoins(coins);
|
||||
if (!psbt.TryGetFinalizedHash(out var hash))
|
||||
throw new InvalidOperationException("Unable to get the finalized hash");
|
||||
return hash;
|
||||
}
|
||||
|
||||
private JObject CreatePayjoinError(int httpCode, string errorCode, string friendlyMessage)
|
||||
|
Loading…
Reference in New Issue
Block a user