mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 14:04:26 +01:00
check output sum of proposed payjoin
This commit is contained in:
@@ -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))
|
if (!string.IsNullOrEmpty(bpu) && Uri.TryCreate(bpu, UriKind.Absolute, out var endpoint))
|
||||||
{
|
{
|
||||||
@@ -192,6 +192,7 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
if (!input.TryFinalizeInput(out _))
|
if (!input.TryFinalizeInput(out _))
|
||||||
{
|
{
|
||||||
|
//a new input was provided but was invalid.
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -204,6 +205,17 @@ namespace BTCPayServer.Controllers
|
|||||||
return null;
|
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);
|
newPSBT = await UpdatePSBT(derivationSchemeSettings, newPSBT, btcPayNetwork);
|
||||||
TempData.SetStatusMessageModel(new StatusMessageModel()
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -688,7 +688,7 @@ namespace BTCPayServer.Controllers
|
|||||||
WalletId walletId, WalletSendVaultModel model)
|
WalletId walletId, WalletSendVaultModel model)
|
||||||
{
|
{
|
||||||
var network = NetworkProvider.GetNetwork<BTCPayNetwork>(walletId.CryptoCode);
|
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;
|
model.PayJoinEndpointUrl = null;
|
||||||
if (newPSBT != null)
|
if (newPSBT != null)
|
||||||
{
|
{
|
||||||
@@ -849,7 +849,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(viewModel);
|
return View(viewModel);
|
||||||
}
|
}
|
||||||
ModelState.Remove(nameof(viewModel.PSBT));
|
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;
|
viewModel.PayJoinEndpointUrl = null;
|
||||||
if (newPSBT != null)
|
if (newPSBT != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user