Remove redundancies due to required attribute usage
MODIFY
WalletWasabi.Backend/Controllers/BatchController.cs
WalletWasabi.Backend/Controllers/BatchController.cs
@@ -35,13 +35,9 @@ namespace WalletWasabi.Backend.Controllers
[HttpGet("synchronize")]
public async Task<IActionResult> GetSynchronizeAsync([FromQuery, Required]string bestKnownBlockHash, [FromQuery, Required]int maxNumberOfFilters, [FromQuery]string estimateSmartFeeMode)
{
- if (string.IsNullOrWhiteSpace(bestKnownBlockHash))
- {
- return BadRequest("Invalid block hash is provided.");
- }
- if (maxNumberOfFilters <= 0)
+ if (!ModelState.IsValid)
{
- return BadRequest("Invalid maxNumberOfFilters is provided.");
+ return BadRequest("Wrong body is provided.");
}
bool estimateSmartFee = !string.IsNullOrWhiteSpace(estimateSmartFeeMode);
@@ -54,11 +50,6 @@ namespace WalletWasabi.Backend.Controllers
}
}
- if (!ModelState.IsValid)
- {
- return BadRequest("Wrong body is provided.");
- }
-
var knownHash = new uint256(bestKnownBlockHash);
(Height bestHeight, IEnumerable<string> filters) = Global.IndexBuilderService.GetFilterLinesExcluding(knownHash, maxNumberOfFilters, out bool found);

MODIFY
WalletWasabi.Backend/Controllers/BlockchainController.cs
WalletWasabi.Backend/Controllers/BlockchainController.cs
@@ -119,7 +119,7 @@ namespace WalletWasabi.Backend.Controllers
[ResponseCache(Duration = 300, Location = ResponseCacheLocation.Client)]
public async Task<IActionResult> GetAllFeesAsync([FromQuery, Required]string estimateSmartFeeMode)
{
- if (!ModelState.IsValid || string.IsNullOrWhiteSpace(estimateSmartFeeMode) || !Enum.TryParse(estimateSmartFeeMode, ignoreCase: true, out EstimateSmartFeeMode mode))
+ if (!ModelState.IsValid || !Enum.TryParse(estimateSmartFeeMode, ignoreCase: true, out EstimateSmartFeeMode mode))
{
return BadRequest("Invalid estimation mode is provided, possible values: ECONOMICAL/CONSERVATIVE.");
}
@@ -164,7 +164,7 @@ namespace WalletWasabi.Backend.Controllers
[ProducesResponseType(400)]
public async Task<IActionResult> BroadcastAsync([FromBody, Required]string hex)
{
- if (string.IsNullOrWhiteSpace(hex) || !ModelState.IsValid)
+ if (!ModelState.IsValid)
{
return BadRequest("Invalid hex.");
}
@@ -222,7 +222,7 @@ namespace WalletWasabi.Backend.Controllers
[ProducesResponseType(404)]
public IActionResult GetFilters([FromQuery, Required]string bestKnownBlockHash, [FromQuery, Required]int count)
{
- if (string.IsNullOrWhiteSpace(bestKnownBlockHash) || count <= 0 || !ModelState.IsValid)
+ if (count <= 0 || !ModelState.IsValid)
{
return BadRequest("Invalid block hash or count is provided.");
}

MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -105,10 +105,6 @@ namespace WalletWasabi.Backend.Controllers
{
// Validate request.
if (!ModelState.IsValid
- || request is null
- || string.IsNullOrWhiteSpace(request.BlindedOutputScriptHex)
- || string.IsNullOrWhiteSpace(request.ChangeOutputAddress)
- || request.Inputs is null
|| !request.Inputs.Any()
|| request.Inputs.Any(x => x.Input == default(TxoRef)
|| x.Input.TransactionId is null
@@ -456,9 +452,6 @@ namespace WalletWasabi.Backend.Controllers
public async Task<IActionResult> PostOutputAsync([FromQuery, Required]long roundId, [FromBody, Required]OutputRequest request)
{
if (roundId < 0
- || request is null
- || string.IsNullOrWhiteSpace(request.OutputAddress)
- || string.IsNullOrWhiteSpace(request.SignatureHex)
|| !ModelState.IsValid)
{
return BadRequest();
@@ -584,7 +577,6 @@ namespace WalletWasabi.Backend.Controllers
public async Task<IActionResult> PostSignaturesAsync([FromQuery, Required]string uniqueId, [FromQuery, Required]long roundId, [FromBody, Required]IDictionary<int, string> signatures)
{
if (roundId <= 0
- || signatures is null
|| !signatures.Any()
|| signatures.Any(x => x.Key < 0 || string.IsNullOrWhiteSpace(x.Value))
|| !ModelState.IsValid)

Remove redundancies due to required attribute usage