Do a TryParse pattern instead.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/TransactionBroadcasterViewModel.cs
@@ -13,6 +13,7 @@ using System.Reactive.Linq;
using System.Threading.Tasks;
using WalletWasabi.Gui.Models;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Helpers;
using WalletWasabi.Models;
namespace WalletWasabi.Gui.Controls.WalletExplorer
@@ -165,10 +166,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
ButtonText = "Broadcasting Transaction...";
SmartTransaction transaction;
- try
- {
- var signedPsbt = PSBT.Parse(TransactionString, Global.Network ?? Network.Main);
+ if (NBitcoinHelpers.TryParsePSBT(TransactionString, Global.Network, out var signedPsbt))
+ {
if (!signedPsbt.IsAllFinalized())
{
signedPsbt.Finalize();
@@ -176,13 +176,16 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
transaction = signedPsbt.ExtractSmartTransaction();
}
- catch (PSBTException psbtEx)
+ else
{
- throw new FormatException($"PSBT cannot be finalized: {psbtEx.Errors.FirstOrDefault()}");
+ if (NBitcoinHelpers.TryParseTransactionHex(TransactionString, Global.Network, out var txn))
+ {
+ transaction = new SmartTransaction(txn, WalletWasabi.Models.Height.Unknown);
}
- catch
+ else
{
- transaction = new SmartTransaction(Transaction.Parse(TransactionString, Global.Network ?? Network.Main), WalletWasabi.Models.Height.Unknown);
+ throw new FormatException($"Transaction string is invalid or cannot be finalized.");
+ }
}
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BroadcastingTransaction);

MODIFY
WalletWasabi/Helpers/NBitcoinHelpers.cs
WalletWasabi/Helpers/NBitcoinHelpers.cs
@@ -12,6 +12,42 @@ namespace WalletWasabi.Helpers
{
public static class NBitcoinHelpers
{
+ public static bool TryParsePSBT(string transactionString, Network network, out PSBT psbt)
+ {
+ try
+ {
+ psbt = PSBT.Parse(transactionString, network ?? Network.Main);
+ return true;
+ }
+ catch (PSBTException)
+ {
+ psbt = null;
+ return false;
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
+ public static bool TryParseTransactionHex(string transactionString, Network network, out Transaction txn)
+ {
+ try
+ {
+ txn = Transaction.Parse(transactionString, network ?? Network.Main);
+ return true;
+ }
+ catch (FormatException)
+ {
+ txn = null;
+ return false;
+ }
+ catch
+ {
+ throw;
+ }
+ }
+
public static string HashOutpoints(IEnumerable<OutPoint> outPoints)
{
var sb = new StringBuilder();

Do a TryParse pattern instead.