Organize a bit better the code changes
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendControlViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendControlViewModel.cs
@@ -228,14 +228,10 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
AmountText = url.Amount.ToString(false, true);
}
- if (url.UnknowParameters.TryGetValue("bpu", out var endPoint) || url.UnknowParameters.TryGetValue("pj", out endPoint))
- {
- PayjoinEndPoint = endPoint;
- }
- else
- {
- PayjoinEndPoint = null;
- }
+ PayjoinEndPoint = url.UnknowParameters.TryGetValue("bpu", out var endPoint)
+ || url.UnknowParameters.TryGetValue("pj", out endPoint)
+ ? endPoint
+ : null;
});
_isPayjoinEndPointVisible = this.WhenAnyValue(x => x.PayjoinEndPoint)
@@ -376,13 +372,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
}
}
- IPayjoinClient payjoinClient = new NullPayjoinClient();
- if (CanUsePayjoin && PayjoinEndPoint is {})
- {
- var payjoinEndPointUri = new Uri(PayjoinEndPoint);
- payjoinClient = new PayjoinClient(payjoinEndPointUri, Global.TorManager.TorSocks5EndPoint);
- }
- BuildTransactionResult result = await Task.Run(() => Wallet.BuildTransaction(Password, intent, feeStrategy, allowUnconfirmed: true, allowedInputs: selectedCoinReferences, payjoinClient: payjoinClient));
+ BuildTransactionResult result = await Task.Run(() => Wallet.BuildTransaction(Password, intent, feeStrategy, allowUnconfirmed: true, allowedInputs: selectedCoinReferences, GetPayjoinClient()));
await DoAfterBuildTransaction(result);
}
@@ -673,6 +663,17 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
AmountText = "0.0";
}
+ private IPayjoinClient GetPayjoinClient()
+ {
+ if (CanUsePayjoin && PayjoinEndPoint is {})
+ {
+ var payjoinEndPointUri = new Uri(PayjoinEndPoint);
+ return new PayjoinClient(payjoinEndPointUri, Global.TorManager.TorSocks5EndPoint);
+ }
+
+ return new NullPayjoinClient();
+ }
+
private void SetAmountWatermark(Money amount)
{
if (amount == Money.Zero)
@@ -939,7 +940,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
return ErrorDescriptors.Empty;
}
- if (AddressStringParser.TryParseBitcoinUrl(Address, Global.Network, out var url))
+ if (AddressStringParser.TryParseBitcoinUrl(Address, Global.Network, out _))
{
return ErrorDescriptors.Empty;
}

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
WalletWasabi/Blockchain/Transactions/TransactionFactory.cs
@@ -228,37 +228,10 @@ namespace WalletWasabi.Blockchain.Transactions
builder.SetLockTime(lockTimeSelector());
builder.SignPSBT(psbt);
- if (KeyManager.MasterFingerprint is HDFingerprint fp)
- {
- foreach (var coin in spentCoins)
- {
- var rootKeyPath = new RootedKeyPath(fp, coin.HdPubKey.FullKeyPath);
- psbt.AddKeyPath(coin.HdPubKey.PubKey, rootKeyPath, coin.ScriptPubKey);
- }
- if (changeHdPubKey is {})
- {
- var rootKeyPath = new RootedKeyPath(fp, changeHdPubKey.FullKeyPath);
- psbt.AddKeyPath(changeHdPubKey.PubKey, rootKeyPath, changeHdPubKey.P2wpkhScript);
- }
- }
+ UpdatePSBTInfo(psbt, spentCoins, changeHdPubKey);
// Try to pay using payjoin
- try
- {
- psbt = payjoinClient.RequestPayjoin(psbt,
- KeyManager.ExtPubKey,
- new RootedKeyPath(KeyManager.MasterFingerprint.Value, KeyManager.DefaultAccountKeyPath),
- CancellationToken.None).GetAwaiter().GetResult();
- builder.SignPSBT(psbt);
- }
- catch (HttpRequestException e)
- {
- Logger.LogWarning($"Payjoin server responded with {e.ToTypeMessageString()}. Ignoring...");
- }
- catch (PayjoinException e)
- {
- Logger.LogWarning($"Payjoin server responded with {e.Message}. Ignoring...");
- }
+ psbt = TryNegociatePayjoin(payjoinClient, builder, psbt);
psbt.Finalize();
tx = psbt.ExtractTransaction();
@@ -327,5 +300,44 @@ namespace WalletWasabi.Blockchain.Transactions
var spendsUnconfirmed = spentCoins.Any(c => !c.Confirmed);
return new BuildTransactionResult(new SmartTransaction(tx, Height.Unknown), psbt, spendsUnconfirmed, sign, fee, feePc, outerWalletOutputs, innerWalletOutputs, spentCoins);
}
+
+ private PSBT TryNegociatePayjoin(IPayjoinClient payjoinClient, TransactionBuilder builder, PSBT psbt)
+ {
+ try
+ {
+ psbt = payjoinClient.RequestPayjoin(psbt,
+ KeyManager.ExtPubKey,
+ new RootedKeyPath(KeyManager.MasterFingerprint.Value, KeyManager.DefaultAccountKeyPath),
+ CancellationToken.None).GetAwaiter().GetResult();
+ builder.SignPSBT(psbt);
+ }
+ catch (HttpRequestException e)
+ {
+ Logger.LogWarning($"Payjoin server responded with {e.ToTypeMessageString()}. Ignoring...");
+ }
+ catch (PayjoinException e)
+ {
+ Logger.LogWarning($"Payjoin server responded with {e.Message}. Ignoring...");
+ }
+
+ return psbt;
+ }
+
+ private void UpdatePSBTInfo(PSBT psbt, SmartCoin[] spentCoins, HdPubKey changeHdPubKey)
+ {
+ if (KeyManager.MasterFingerprint is HDFingerprint fp)
+ {
+ foreach (var coin in spentCoins)
+ {
+ var rootKeyPath = new RootedKeyPath(fp, coin.HdPubKey.FullKeyPath);
+ psbt.AddKeyPath(coin.HdPubKey.PubKey, rootKeyPath, coin.ScriptPubKey);
+ }
+ if (changeHdPubKey is { })
+ {
+ var rootKeyPath = new RootedKeyPath(fp, changeHdPubKey.FullKeyPath);
+ psbt.AddKeyPath(changeHdPubKey.PubKey, rootKeyPath, changeHdPubKey.P2wpkhScript);
+ }
+ }
+ }
}
}

Organize a bit better the code changes