Add whitelisting and admin

This commit is contained in:
2025-11-07 23:46:48 +07:00
parent 21110cd771
commit e0795677e4
17 changed files with 2280 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ public class UserService : IUserService
private readonly ILogger<UserService> _logger;
private readonly ICacheService _cacheService;
private readonly IGrainFactory _grainFactory;
private readonly IWhitelistService _whitelistService;
private readonly string[] _authorizedAddresses;
public UserService(
@@ -27,6 +28,7 @@ public class UserService : IUserService
ILogger<UserService> logger,
ICacheService cacheService,
IGrainFactory grainFactory,
IWhitelistService whitelistService,
IConfiguration configuration)
{
_evmManager = evmManager;
@@ -35,6 +37,7 @@ public class UserService : IUserService
_logger = logger;
_cacheService = cacheService;
_grainFactory = grainFactory;
_whitelistService = whitelistService;
var authorizedAddressesString = configuration["AUTHORIZED_ADDRESSES"] ?? string.Empty;
_authorizedAddresses = string.IsNullOrEmpty(authorizedAddressesString)
@@ -54,9 +57,19 @@ public class UserService : IUserService
$"Message not good : {message} - Address : {address} - User : {name} - Signature : {signature}");
}
if (!_authorizedAddresses.Any(a => string.Equals(a, recoveredAddress, StringComparison.OrdinalIgnoreCase)))
// Check if address is whitelisted first (skip authorized addresses check if whitelisted)
var isWhitelisted = await _whitelistService.IsEmbeddedWalletWhitelistedAsync(recoveredAddress);
if (!isWhitelisted)
{
throw new Exception($"Address {recoveredAddress} not authorized. Please wait for team approval.");
// Only check authorized addresses if not whitelisted
var isInAuthorizedAddresses = _authorizedAddresses.Any(a => string.Equals(a, recoveredAddress, StringComparison.OrdinalIgnoreCase));
if (!isInAuthorizedAddresses)
{
_logger.LogWarning("Address {Address} is not authorized and not whitelisted", recoveredAddress);
throw new Exception($"Address {recoveredAddress} not authorized. Please wait for team approval.");
}
}