Guest User

Untitled

a guest
Jun 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2. using Nethereum.Util;
  3.  
  4. namespace SupplyChain.BlockChain.Validation
  5. {
  6. /// <inheritdoc cref="IAddressValidator"/>
  7. public class AddressValidator : IAddressValidator
  8. {
  9. private static readonly Regex AddressRegex = new Regex("^0[xX]([A-Fa-f0-9]{40})$");
  10. private static readonly AddressUtil AddressUtil = new AddressUtil();
  11.  
  12. /// <inheritdoc cref="IAddressValidator.IsValid(string)"/>
  13. public bool IsValid(string address)
  14. {
  15. // Doesn't match length, prefix and hex
  16. if (!AddressRegex.IsMatch(address))
  17. {
  18. return false;
  19. }
  20.  
  21. // It's all lowercase, so no checksum needed
  22. if (address == address.ToLower())
  23. {
  24. return true;
  25. }
  26.  
  27. // Do checksum
  28. return AddressUtil.IsChecksumAddress(address);
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment