avoid passing Wallet instance
MODIFY
WalletWasabi.Fluent/Helpers/TransactionHelpers.cs
WalletWasabi.Fluent/Helpers/TransactionHelpers.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using NBitcoin;
using WalletWasabi.Blockchain.Analysis.Clustering;
+using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionBuilding;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Blockchain.Transactions;
@@ -118,6 +119,51 @@ public static class TransactionHelpers
return false;
}
+ public static bool TryBuildTransaction(
+ KeyManager keyManager,
+ TransactionInfo transactionInfo,
+ BitcoinAddress destination,
+ ICoinsView allCoins,
+ IEnumerable<SmartCoin> allowedCoins,
+ string password,
+ out Money minimumAmount)
+ {
+ minimumAmount = Money.Zero;
+
+ try
+ {
+ var intent = new PaymentIntent(
+ destination: destination,
+ amount: transactionInfo.Amount,
+ subtractFee: transactionInfo.SubtractFee,
+ label: transactionInfo.UserLabels);
+
+ var bitcoinStore = Services.BitcoinStore;
+
+ var builder = new TransactionFactory(Network.TestNet, keyManager, allCoins, bitcoinStore.TransactionStore, password, true);
+
+ builder.BuildTransaction(
+ intent,
+ feeRateFetcher: () => transactionInfo.FeeRate,
+ allowedCoins.Select(x => x.OutPoint),
+ lockTimeSelector: () =>
+ {
+ var currentTipHeight = bitcoinStore.SmartHeaderChain.TipHeight;
+ return LockTimeSelector.Instance.GetLockTimeBasedOnDistribution(currentTipHeight);
+ },
+ transactionInfo.PayJoinClient,
+ tryToSign: false);
+
+ return true;
+ }
+ catch (InsufficientBalanceException ex)
+ {
+ minimumAmount = ex.Minimum;
+ }
+
+ return false;
+ }
+
public static async Task<SmartTransaction> ParseTransactionAsync(string path, Network network)
{
var psbtBytes = await File.ReadAllBytesAsync(path);

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/LabelSelectionViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/LabelSelectionViewModel.cs
@@ -5,6 +5,7 @@ using System.Linq;
using NBitcoin;
using ReactiveUI;
using WalletWasabi.Blockchain.Analysis.Clustering;
+using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Helpers;
@@ -15,7 +16,8 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send;
public partial class LabelSelectionViewModel : ViewModelBase
{
- private readonly Wallet _wallet;
+ private readonly KeyManager _keyManager;
+ private readonly string _password;
private readonly TransactionInfo _info;
private readonly BitcoinAddress _destination;
private readonly Money _targetAmount;
@@ -28,9 +30,10 @@ public partial class LabelSelectionViewModel : ViewModelBase
private Pocket _semiPrivatePocket = Pocket.Empty;
private Pocket[] _allPockets = Array.Empty<Pocket>();
- public LabelSelectionViewModel(Wallet wallet, TransactionInfo info, BitcoinAddress destination)
+ public LabelSelectionViewModel(KeyManager keyManager, string password, TransactionInfo info, BitcoinAddress destination)
{
- _wallet = wallet;
+ _keyManager = keyManager;
+ _password = password;
_info = info;
_destination = destination;
_targetAmount = _info.MinimumRequiredAmount == Money.Zero ? _info.Amount : _info.MinimumRequiredAmount;
@@ -54,7 +57,16 @@ public partial class LabelSelectionViewModel : ViewModelBase
return false;
}
- return TransactionHelpers.TryBuildTransaction(_wallet, _info, _destination, coins, out _);
+ var allCoins = Pocket.Merge(_allPockets).Coins;
+
+ return TransactionHelpers.TryBuildTransaction(
+ keyManager: _keyManager,
+ transactionInfo: _info,
+ destination: _destination,
+ allCoins: new CoinsView(allCoins),
+ allowedCoins: coins,
+ password: _password,
+ minimumAmount: out _);
}
public Pocket[] AutoSelectPockets(SmartLabel recipient)

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/PrivacyControlViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/PrivacyControlViewModel.cs
@@ -27,7 +27,7 @@ public partial class PrivacyControlViewModel : DialogViewModelBase<IEnumerable<S
_isSilent = isSilent;
_usedCoins = usedCoins;
- LabelSelection = new LabelSelectionViewModel(wallet, _transactionInfo, destination);
+ LabelSelection = new LabelSelectionViewModel(wallet.KeyManager, wallet.Kitchen.SaltSoup(), _transactionInfo, destination);
SetupCancel(enableCancel: false, enableCancelOnEscape: true, enableCancelOnPressed: false);
EnableBack = true;

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
@@ -523,7 +523,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
var usedCoins = transaction.SpentCoins;
var pockets = _wallet.GetPockets().ToArray();
- var labelSelection = new LabelSelectionViewModel(_wallet, _info, _destination);
+ var labelSelection = new LabelSelectionViewModel(_wallet.KeyManager, _wallet.Kitchen.SaltSoup(), _info, _destination);
labelSelection.Reset(pockets);
_info.IsOtherPocketSelectionPossible = labelSelection.IsOtherSelectionPossible(usedCoins, _info.UserLabels);

avoid passing Wallet instance