This commit is contained in:
Kukks
2023-11-14 15:56:58 +01:00
parent 37897c1bed
commit 206875b133
6 changed files with 34 additions and 16 deletions

View File

@@ -104,7 +104,9 @@ public class BTCPayCoinjoinCoinSelector : IRoundCoinSelector
utxoSelectionParameters); utxoSelectionParameters);
var fullyPrivate = remainingCoins.All(coin => coin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green); var fullyPrivate = remainingCoins.All(coin => coin.CoinColor(_wallet.AnonScoreTarget) == AnonsetType.Green);
var coinjoiningOnlyForPayments = fullyPrivate && remainingPendingPayments.Any(); var coinjoiningOnlyForPayments = fullyPrivate && remainingPendingPayments.Any();
if (fullyPrivate && !coinjoiningOnlyForPayments) var isMixingToOther = !_wallet.WabisabiStoreSettings.PlebMode &&
!string.IsNullOrEmpty(_wallet.WabisabiStoreSettings.MixToOtherWallet);
if (fullyPrivate && !coinjoiningOnlyForPayments && !isMixingToOther)
{ {
var rand = Random.Shared.Next(1, 1001); var rand = Random.Shared.Next(1, 1001);
if (rand > _wallet.WabisabiStoreSettings.ExtraJoinProbability) if (rand > _wallet.WabisabiStoreSettings.ExtraJoinProbability)

View File

@@ -378,7 +378,8 @@ public class BTCPayWallet : IWallet, IDestinationProvider
continue; continue;
} }
scriptInfos.Add((txout, ExplorerClient.GetKeyInformationAsync(BlockchainAnalyzer.StdDenoms.Contains(txout.TxOut.Value)?utxoDerivationScheme:DerivationScheme, script.ScriptPubKey))); var privateEnough = result.Coins.All(c => c.AnonymitySet >= WabisabiStoreSettings.AnonymitySetTarget );
scriptInfos.Add((txout, ExplorerClient.GetKeyInformationAsync(BlockchainAnalyzer.StdDenoms.Contains(txout.TxOut.Value)&& privateEnough?utxoDerivationScheme:DerivationScheme, script.ScriptPubKey)));
} }
await Task.WhenAll(scriptInfos.Select(t => t.Item2)); await Task.WhenAll(scriptInfos.Select(t => t.Item2));
@@ -441,6 +442,10 @@ public class BTCPayWallet : IWallet, IDestinationProvider
Outpoint = new OutPoint(result.UnsignedCoinJoin, pair.Key.N).ToString() Outpoint = new OutPoint(result.UnsignedCoinJoin, pair.Key.N).ToString()
})).ToArray() })).ToArray()
}; };
foreach (var smartTxWalletOutput in smartTx.WalletOutputs)
{
Smartifier.SetIsSufficientlyDistancedFromExternalKeys(smartTxWalletOutput, cjData);
}
var attachments = new List<Attachment>() var attachments = new List<Attachment>()
{ {
@@ -585,9 +590,9 @@ public class BTCPayWallet : IWallet, IDestinationProvider
// Logger.LogTrace($"unlocked utxos: {string.Join(',', unlocked)}"); // Logger.LogTrace($"unlocked utxos: {string.Join(',', unlocked)}");
// } // }
public async Task<IEnumerable<IDestination>> GetNextDestinationsAsync(int count, bool mixedOutputs) public async Task<IEnumerable<IDestination>> GetNextDestinationsAsync(int count, bool mixedOutputs, bool privateEnough)
{ {
if (!WabisabiStoreSettings.PlebMode && !string.IsNullOrEmpty(WabisabiStoreSettings.MixToOtherWallet) && mixedOutputs) if (!WabisabiStoreSettings.PlebMode && !string.IsNullOrEmpty(WabisabiStoreSettings.MixToOtherWallet) && mixedOutputs && privateEnough)
{ {
try try
{ {

View File

@@ -13,6 +13,7 @@ using NBitcoin;
using NBXplorer; using NBXplorer;
using NBXplorer.DerivationStrategy; using NBXplorer.DerivationStrategy;
using NBXplorer.Models; using NBXplorer.Models;
using WalletWasabi.Blockchain.Analysis;
using WalletWasabi.Blockchain.Analysis.Clustering; using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.Keys; using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs; using WalletWasabi.Blockchain.TransactionOutputs;
@@ -85,6 +86,7 @@ public class Smartifier
public async Task<TransactionInformation?> GetTransactionInfo(uint256 hash) public async Task<TransactionInformation?> GetTransactionInfo(uint256 hash)
{ {
return await GetOrCreate(TransactionInformations , hash, () => _explorerClient.GetTransactionAsync(DerivationScheme, hash), _logger); return await GetOrCreate(TransactionInformations , hash, () => _explorerClient.GetTransactionAsync(DerivationScheme, hash), _logger);
} }
@@ -199,20 +201,32 @@ public class Smartifier
hdPubKey.SetAnonymitySet(labels.anonset); hdPubKey.SetAnonymitySet(labels.anonset);
var c = new SmartCoin(tx, coin.OutPoint.N, hdPubKey); var c = new SmartCoin(tx, coin.OutPoint.N, hdPubKey);
c.IsSufficientlyDistancedFromExternalKeys = labels.coinjoinData is not null; if (labels.coinjoinData is not null)
{
SetIsSufficientlyDistancedFromExternalKeys(c, labels.coinjoinData);
}
c.PropertyChanged += CoinPropertyChanged; c.PropertyChanged += CoinPropertyChanged;
return c; return c;
}); });
utxoLabels.TryGetValue(coin.OutPoint, out var labels); utxoLabels.TryGetValue(coin.OutPoint, out var labels);
smartCoin.HdPubKey.SetLabel(new LabelsArray(labels.labels ?? new HashSet<string>())); smartCoin.HdPubKey.SetLabel(new LabelsArray(labels.labels ?? new HashSet<string>()));
smartCoin.HdPubKey.SetKeyState(current == 1 ? KeyState.Clean : KeyState.Used); smartCoin.HdPubKey.SetKeyState(current == 1 ? KeyState.Clean : KeyState.Used);
smartCoin.HdPubKey.SetAnonymitySet(labels.anonset); smartCoin.HdPubKey.SetAnonymitySet(labels.anonset);
if (labels.coinjoinData is not null)
{
SetIsSufficientlyDistancedFromExternalKeys(smartCoin, labels.coinjoinData);
}
tx.TryAddWalletOutput(smartCoin); tx.TryAddWalletOutput(smartCoin);
} }
} }
public static void SetIsSufficientlyDistancedFromExternalKeys(SmartCoin c, BTCPayWallet.CoinjoinData coinjoinData)
{
c.IsSufficientlyDistancedFromExternalKeys = coinjoinData.CoinsIn.All(dataCoin => dataCoin.AnonymitySet >1);
}
private void CoinPropertyChanged(object sender, PropertyChangedEventArgs e) private void CoinPropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (sender is SmartCoin smartCoin && e.PropertyName == nameof(SmartCoin.CoinJoinInProgress)) if (sender is SmartCoin smartCoin && e.PropertyName == nameof(SmartCoin.CoinJoinInProgress))

View File

@@ -158,7 +158,8 @@ const config = {
`${coin.score.toFixed(2)} anonset`, `${coin.score.toFixed(2)} anonset`,
`${coin.confirmed ? "confirmed" : "unconfirmed"}`, `${coin.confirmed ? "confirmed" : "unconfirmed"}`,
coin.isPrivate ? "private" : "not private", coin.isPrivate ? "private" : "not private",
...(coin.coinjoinInProgress ? ["mixing"] : []) ...(coin.coinjoinInProgress ? ["mixing"] : []),
...(!coin.isPrivate && coin.score >= data.targetScore? ["Coin too close to entry to deem private just yet"] : [])
]; ];
}, },
title: function (context) { title: function (context) {
@@ -215,8 +216,8 @@ const config = {
const totalPrivateValueSum = data.coins.filter(coin => coin.isPrivate).reduce((sum, coin) => sum + coin.value, 0); const totalPrivateValueSum = data.coins.filter(coin => coin.isPrivate).reduce((sum, coin) => sum + coin.value, 0);
if (totalPrivateSum > 0) if (totalPrivateSum > 0)
lineTexts.push(`${totalPrivateSum} coins(${totalPrivateValueSum.toFixed(8)}BTC) private`); lineTexts.push(`${totalPrivateSum} coins(${totalPrivateValueSum.toFixed(8)}BTC) private`);
const totalNonPrivateSum = data.coins.filter(coin => !coin.isPrivate && !coin.coinjoinInProgress).length; const totalNonPrivateSum = data.coins.filter(coin => !coin.isPrivate).length;
const totalNonPrivateValueSum = data.coins.filter(coin => !coin.isPrivate && !coin.coinjoinInProgress).reduce((sum, coin) => sum + coin.value, 0); const totalNonPrivateValueSum = data.coins.filter(coin => !coin.isPrivate).reduce((sum, coin) => sum + coin.value, 0);
if (totalNonPrivateSum > 0) if (totalNonPrivateSum > 0)
lineTexts.push(`${totalNonPrivateSum} coins(${totalNonPrivateValueSum.toFixed(8)}BTC) semi/not private`); lineTexts.push(`${totalNonPrivateSum} coins(${totalNonPrivateValueSum.toFixed(8)}BTC) semi/not private`);
const totalInProgressSum = data.coins.filter(coin => coin.coinjoinInProgress).length; const totalInProgressSum = data.coins.filter(coin => coin.coinjoinInProgress).length;

View File

@@ -1,17 +1,13 @@
@using BTCPayServer.Security 
@using NBitcoin @using NBitcoin
@using BTCPayServer.Abstractions.Contracts @using BTCPayServer.Abstractions.Contracts
@using BTCPayServer.Plugins.Wabisabi @using BTCPayServer.Plugins.Wabisabi
@using WalletWasabi.Blockchain.Analysis @using WalletWasabi.Blockchain.Analysis
@model BTCPayServer.Models.WalletViewModels.WalletSendModel @model BTCPayServer.Models.WalletViewModels.WalletSendModel
@inject ContentSecurityPolicies contentSecurityPolicies
@inject WalletProvider _walletProvider @inject WalletProvider _walletProvider
@inject IScopeProvider ScopeProvider @inject IScopeProvider ScopeProvider
@{ @{
var nonce = RandomUtils.GetUInt256().ToString().Substring(0, 32);
contentSecurityPolicies.Add("script-src", $"'nonce-{nonce}'");
contentSecurityPolicies.AllowUnsafeHashes();
var storeId = ScopeProvider.GetCurrentStoreId(); var storeId = ScopeProvider.GetCurrentStoreId();
var w = await _walletProvider.GetWalletAsync(storeId); var w = await _walletProvider.GetWalletAsync(storeId);
} }
@@ -40,7 +36,7 @@
</datalist> </datalist>
<script type="text/javascript" nonce="@nonce"> <script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
const amountElements = document.querySelectorAll("[name^='Outputs'][name$='Amount']"); const amountElements = document.querySelectorAll("[name^='Outputs'][name$='Amount']");