mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
check output sum of proposed payjoin
This commit is contained in:
parent
065be9be64
commit
64717328f6
2 changed files with 15 additions and 3 deletions
|
@ -159,7 +159,7 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
|
||||
|
||||
private async Task<PSBT> TryGetBPProposedTX(string bpu, PSBT psbt, DerivationSchemeSettings derivationSchemeSettings, BTCPayNetwork btcPayNetwork)
|
||||
private async Task<PSBT> TryGetPayjoinProposedTX(string bpu, PSBT psbt, DerivationSchemeSettings derivationSchemeSettings, BTCPayNetwork btcPayNetwork)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(bpu) && Uri.TryCreate(bpu, UriKind.Absolute, out var endpoint))
|
||||
{
|
||||
|
@ -192,6 +192,7 @@ namespace BTCPayServer.Controllers
|
|||
|
||||
if (!input.TryFinalizeInput(out _))
|
||||
{
|
||||
//a new input was provided but was invalid.
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
@ -204,6 +205,17 @@ namespace BTCPayServer.Controllers
|
|||
return null;
|
||||
}
|
||||
|
||||
//check if output sum to self is the same.
|
||||
var signingAccountKeySettings = derivationSchemeSettings.GetSigningAccountKeySettings();
|
||||
var newOutputSumToSelfSum = newPSBT.Outputs.CoinsFor(derivationSchemeSettings.AccountDerivation, signingAccountKeySettings.AccountKey,
|
||||
signingAccountKeySettings.GetRootedKeyPath()).Sum(output => output.Value);
|
||||
|
||||
var originalOutputSumToSelf = psbt.Outputs.Sum(output => output.Value);
|
||||
if (originalOutputSumToSelf < newOutputSumToSelfSum)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
newPSBT = await UpdatePSBT(derivationSchemeSettings, newPSBT, btcPayNetwork);
|
||||
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||
{
|
||||
|
|
|
@ -688,7 +688,7 @@ namespace BTCPayServer.Controllers
|
|||
WalletId walletId, WalletSendVaultModel model)
|
||||
{
|
||||
var network = NetworkProvider.GetNetwork<BTCPayNetwork>(walletId.CryptoCode);
|
||||
var newPSBT = await TryGetBPProposedTX(model.PayJoinEndpointUrl, PSBT.Parse(model.PSBT, network.NBitcoinNetwork), GetDerivationSchemeSettings(walletId), network);
|
||||
var newPSBT = await TryGetPayjoinProposedTX(model.PayJoinEndpointUrl, PSBT.Parse(model.PSBT, network.NBitcoinNetwork), GetDerivationSchemeSettings(walletId), network);
|
||||
model.PayJoinEndpointUrl = null;
|
||||
if (newPSBT != null)
|
||||
{
|
||||
|
@ -849,7 +849,7 @@ namespace BTCPayServer.Controllers
|
|||
return View(viewModel);
|
||||
}
|
||||
ModelState.Remove(nameof(viewModel.PSBT));
|
||||
var newPSBT = await TryGetBPProposedTX(viewModel.PayJoinEndpointUrl,psbt, GetDerivationSchemeSettings(walletId), network);
|
||||
var newPSBT = await TryGetPayjoinProposedTX(viewModel.PayJoinEndpointUrl,psbt, GetDerivationSchemeSettings(walletId), network);
|
||||
viewModel.PayJoinEndpointUrl = null;
|
||||
if (newPSBT != null)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue