Explicit types.
MODIFY
WalletWasabi.Backend/Filters/IdempotentActionFilterAttributeImpl.cs
WalletWasabi.Backend/Filters/IdempotentActionFilterAttributeImpl.cs
@@ -2,6 +2,7 @@ using System;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Caching.Memory;
@@ -22,15 +23,15 @@ namespace WalletWasabi.Backend.Filters
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
- var request = context.HttpContext.Request;
+ HttpRequest request = context.HttpContext.Request;
if (context.ModelState.IsValid)
{
- if (context.ActionArguments.TryGetValue("request", out var model))
+ if (context.ActionArguments.TryGetValue("request", out object? model))
{
- var cacheKey = GetCacheEntryKey(request.Path, model);
+ string cacheKey = GetCacheEntryKey(request.Path, model);
- if (_cache.TryGetValue<ObjectResult>(cacheKey, out var cachedResponse))
+ if (_cache.TryGetValue(cacheKey, out ObjectResult? cachedResponse))
{
context.Result = cachedResponse;
context.HttpContext.Items.Remove("cached-key");
@@ -44,12 +45,13 @@ namespace WalletWasabi.Backend.Filters
throw new InvalidOperationException("Control actions marked as Idempotent must receive a 'request' argument.");
}
}
+
await next().ConfigureAwait(false);
}
public override void OnResultExecuted(ResultExecutedContext context)
{
- if (context.HttpContext.Items.TryGetValue("cached-key", out var cacheKey) && cacheKey is not null)
+ if (context.HttpContext.Items.TryGetValue("cached-key", out object? cacheKey) && cacheKey is not null)
{
_cache.Set(cacheKey, context.Result, DateTimeOffset.UtcNow.AddMinutes(5));
}
@@ -57,10 +59,10 @@ namespace WalletWasabi.Backend.Filters
private string GetCacheEntryKey(string path, object model)
{
- var json = JsonConvert.SerializeObject(model, JsonSerializationOptions.Default.Settings);
- var rawKey = string.Join(":", path, json);
+ string json = JsonConvert.SerializeObject(model, JsonSerializationOptions.Default.Settings);
+ string rawKey = string.Join(":", path, json);
using var sha256Hash = SHA256.Create();
- var bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawKey));
+ byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawKey));
return "arena-request-cache-key: " + ByteHelpers.ToHex(bytes);
}

Explicit types.