Exemple #1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string address = value as string;

            if (address == null)
            {
                if (!_allowsEmpty)
                {
                    return(new ValidationResult($"Address should not be null ({validationContext.DisplayName})"));
                }
                else
                {
                    return(null);
                }
            }

            IExchangeContractService exchangeContractService = (IExchangeContractService)validationContext.GetService(typeof(IExchangeContractService));

            if (!exchangeContractService.IsValidAddress(address))
            {
                return(new ValidationResult($"Given value for ({validationContext.DisplayName}) is not a valid ethereum address"));
            }

            return(null);
        }
 public async Task <IActionResult> ValidateAsync([FromQuery] string ethAddress)
 {
     return(Ok(new IsAddressValidResponse()
     {
         IsValid = _exchangeContractService.IsValidAddress(ethAddress ?? "")
     }));
 }