Improve sanity check
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -70,7 +70,15 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
var address = BitcoinAddress.Create(Address, Global.Network);
var script = address.ScriptPubKey;
- var amount = IsMax ? Money.Zero : Money.Parse(Amount);
+ var amount = Money.Zero;
+ if (!IsMax)
+ {
+ amount = Money.Parse(Amount);
+ if (amount == Money.Zero)
+ {
+ throw new FormatException($"Invalid {nameof(Amount)}");
+ }
+ }
var operation = new WalletService.Operation(script, amount, Label);
var result = await Task.Run(async () => await Global.WalletService.BuildTransactionAsync(Password, new[] { operation }, Fee, allowUnconfirmed: true, allowedInputs: selectedCoins));
@@ -134,6 +142,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Amount = "";
_ignoreAmountChanges = false;
}
+
public CoinListViewModel CoinList
{
get { return _coinList; }

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1067,7 +1067,7 @@ namespace WalletWasabi.Tests
// covers:
// customchange
// feePc > 1
- res = await wallet.BuildTransactionAsync(password, new[] { new WalletService.Operation(new Key().ScriptPubKey, Money.Coins(0.0001m), "outgoing") }, 2, customChange: new Key().ScriptPubKey);
+ res = await wallet.BuildTransactionAsync(password, new[] { new WalletService.Operation(new Key().ScriptPubKey, Money.Coins(0.0003m), "outgoing") }, 2, customChange: new Key().ScriptPubKey);
Assert.True(res.FeePercentOfSent > 1);

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -625,10 +625,6 @@ namespace WalletWasabi.Services
{
throw new ArgumentException($"{nameof(toSend)} cannot contain negative element.");
}
- if (toSend.Any(x => x.Amount != Money.Zero && x.Amount < new Money(0.00001m, MoneyUnit.BTC)))
- {
- throw new InvalidOperationException($"Sanity check failed. One of the output is < 0.00001 BTC.");
- }
long sum = toSend.Select(x => x.Amount).Sum().Satoshi;
if (sum < 0 || sum > Constants.MaximumNumberOfSatoshis)
@@ -787,8 +783,9 @@ namespace WalletWasabi.Services
}
// 6. Do some checks
- Money totalOutgoingAmount = realToSend.Select(x => x.amount).Sum() + fee;
- decimal feePc = (100 * fee.ToDecimal(MoneyUnit.BTC)) / totalOutgoingAmount.ToDecimal(MoneyUnit.BTC);
+ Money totalOutgoingAmountNoFee = realToSend.Select(x => x.amount).Sum();
+ Money totalOutgoingAmount = totalOutgoingAmountNoFee + fee;
+ decimal feePc = (100 * fee.ToDecimal(MoneyUnit.BTC)) / totalOutgoingAmountNoFee.ToDecimal(MoneyUnit.BTC);
if (feePc > 1)
{
@@ -796,6 +793,10 @@ namespace WalletWasabi.Services
+ Environment.NewLine + $"Sending:\t {totalOutgoingAmount.ToString(fplus: false, trimExcessZero: true)} BTC."
+ Environment.NewLine + $"Fee:\t\t {fee.ToString(fplus: false, trimExcessZero: true)} BTC.");
}
+ if (feePc > 100)
+ {
+ throw new InvalidOperationException($"The transaction fee is more than twice as much as your transaction amount: {feePc:0.#}%.");
+ }
var confirmedAvailableAmount = allowedSmartCoinInputs.Where(x => x.Confirmed).Select(x => x.Amount).Sum();
var spendsUnconfirmed = false;

Improve sanity check