mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Payjoin: Randomly round the payment output if it is one input tx
This commit is contained in:
@@ -98,7 +98,7 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Selenium", "Selenium")]
|
[Trait("Selenium", "Selenium")]
|
||||||
public async Task CanUsePayjoinViaUI()
|
public async Task CanUsePayjoinViaUI()
|
||||||
|
|||||||
@@ -341,6 +341,22 @@ namespace BTCPayServer.Payments.PayJoin
|
|||||||
{
|
{
|
||||||
var change = await explorer.GetUnusedAsync(derivationSchemeSettings.AccountDerivation, DerivationFeature.Change);
|
var change = await explorer.GetUnusedAsync(derivationSchemeSettings.AccountDerivation, DerivationFeature.Change);
|
||||||
var randomChangeAmount = RandomUtils.GetUInt64() % (ulong)contributedAmount.Satoshi;
|
var randomChangeAmount = RandomUtils.GetUInt64() % (ulong)contributedAmount.Satoshi;
|
||||||
|
|
||||||
|
// Randomly round the amount to make the payment output look like a change output
|
||||||
|
var roundMultiple = (ulong)Math.Pow(10, (ulong)Math.Log10(randomChangeAmount));
|
||||||
|
while (roundMultiple > 1_000UL)
|
||||||
|
{
|
||||||
|
if (RandomUtils.GetUInt32() % 2 == 0)
|
||||||
|
{
|
||||||
|
roundMultiple = roundMultiple / 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
randomChangeAmount = (randomChangeAmount / roundMultiple) * roundMultiple;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var fakeChange = newTx.Outputs.CreateNewTxOut(randomChangeAmount, change.ScriptPubKey);
|
var fakeChange = newTx.Outputs.CreateNewTxOut(randomChangeAmount, change.ScriptPubKey);
|
||||||
if (fakeChange.IsDust(minRelayTxFee))
|
if (fakeChange.IsDust(minRelayTxFee))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user