Simplify fee subtraction.
MODIFY
WalletWasabi/WabiSabi/Client/AliceClient.cs
WalletWasabi/WabiSabi/Client/AliceClient.cs
@@ -48,34 +48,23 @@ namespace WalletWasabi.WabiSabi.Client
var amountCredentials = ArenaClient.AmountCredentialClient.Credentials;
- var remainingFee = FeeRate.GetFee(Constants.P2wpkhInputVirtualSize);
- List<Money> amounts = new();
- foreach (Money amount in Coins.Select(c => c.Amount))
- {
- Money resultAmount = amount;
- if (remainingFee > Money.Zero)
- {
- resultAmount = amount - remainingFee;
- resultAmount = resultAmount < Money.Zero ? Money.Zero : resultAmount;
-
- remainingFee -= amount;
- remainingFee = remainingFee < Money.Zero ? Money.Zero : remainingFee;
- }
- amounts.Add(resultAmount);
- }
+ var totalFeeToPay = FeeRate.GetFee(Coins.Sum(c => c.ScriptPubKey.EstimateInputVsize()));
+ var totalAmount = Coins.Sum(coin => coin.Amount);
- if (remainingFee > Money.Zero)
+ if (totalFeeToPay > totalAmount)
{
throw new InvalidOperationException($"Round({ RoundId }), Alice({ AliceId}): Not enough funds to pay for the fees.");
}
+ var amountsToRequest = new[] { totalAmount - totalFeeToPay };
+
return await ArenaClient
.ConfirmConnectionAsync(
RoundId,
AliceId,
inputRemainingWeights,
amountCredentials.ZeroValue.Take(ArenaClient.ProtocolCredentialNumber),
- amounts)
+ amountsToRequest)
.ConfigureAwait(false);
}

Simplify fee subtraction.