parseFromStr static method

dynamic parseFromStr(
  1. String str, [
  2. bool normalizeAddress = false
])

Implementation

static TypeTag parseFromStr(String str, [bool normalizeAddress = false]) {
  if (str == "address" ||
      str == "bool" ||
      str == "u8" ||
      str == "u16" ||
      str == "u32" ||
      str == "u64" ||
      str == "u128" ||
      str == "u256" ||
      str == "signer") {
    return { str: null };
  }

  final vectorMatch = VECTOR_REGEX.firstMatch(str);
  if (vectorMatch != null) {
    return {
      "vector": TypeTagSerializer.parseFromStr(
        vectorMatch.group(1)!,
        normalizeAddress,
      ),
    };
  }

  final structMatch = STRUCT_REGEX.firstMatch(str);
  if (structMatch != null) {
    final address = normalizeAddress
      ? normalizeSuiAddress(structMatch.group(1)!)
      : structMatch.group(1);
    return {
      "struct": {
        "address": address,
        "module": structMatch.group(2),
        "name": structMatch.group(3),
        "typeParams":
          structMatch.group(5) == null
            ? []
            : TypeTagSerializer.parseStructTypeArgs(
                structMatch.group(5)!,
                normalizeAddress,
              ),
      },
    };
  }

  throw ArgumentError(
    "Encountered unexpected token when parsing type args for $str",
  );
}