getAddress function

String getAddress(
  1. String address
)

Implementation

String getAddress(String address) {
  String result;

  if (RegExp(r'^(0x)?[0-9a-fA-F]{40}$').hasMatch(address)) {
    if (address.substring(0, 2) != '0x') {
      address = '0x$address';
    }
    result = getChecksumAddress(address);
    if (RegExp(r'([A-F].*[a-f])|([a-f].*[A-F])').hasMatch(address) &&
        result != address) {
      throw ArgumentError('bad address checksum');
    }
  } else if (RegExp(r'^XE[0-9]{2}[0-9A-Za-z]{30,31}$').hasMatch(address)) {
    if (address.substring(2, 4) != ibanChecksum(address)) {
      throw ArgumentError('bad icap checksum');
    }
    result = base36To16(address.substring(4)).toString();
    while (result.length < 40) {
      result = '0$result';
    }
    result = getChecksumAddress('0x$result');
  } else {
    throw ArgumentError('invalid address');
  }
  return result;
}