parseHex<T> static method

T parseHex<T>({
  1. required Object? value,
  2. required String name,
})

Implementation

static T parseHex<T>({required Object? value, required String name}) {
  if (<int>[] is! T) {
    throw const TronPluginException(
        "Invalid type casting for String parser.");
  }
  if (value == null && null is T) return null as T;
  if (value == null) {
    throw TronPluginException("Missing parameter: $name.");
  }
  if (value is String) {
    final parse = BytesUtils.tryFromHexString(value);
    if (parse != null) {
      return parse as T;
    }
  }
  throw TronPluginException("Invalid Hex bytes value for parameter: $name.");
}