getTypesFromAbi function

Map<String, Type> getTypesFromAbi(
  1. Map<String, Type> initialTypes,
  2. Abi abi
)

Get types from abi @param initialTypes Set of types to build on. In most cases, it's best to fill this from a fresh call to getTypesFromAbi().

Implementation

Map<String, Type> getTypesFromAbi(Map<String, Type> initialTypes, Abi abi) {
  var types = Map.from(initialTypes).cast<String, Type>();
  if (abi.types != null) {
    for (var item in abi.types!) {
      types[item.new_type_name] = createType(name: item.new_type_name, aliasOfName: item.type);
    }
  }
  if (abi.structs != null) {
    for (var str in abi.structs!) {
      types[str.name!] = createType(
          name: str.name!,
          baseName: str.base ?? '',
          fields: str.fields?.map((item) => Field(name: item.name, typeName: item.type, type: null)).toList() ?? [],
          serialize: serializeStruct,
          deserialize: deserializeStruct);
    }
  }
  if (abi.variants != null) {
    for (var v in abi.variants!) {
      types[v.name!] = createType(
        name: v.name!,
        fields: v.types?.map((s) => Field(name: s, typeName: s, type: null)).toList() ?? [],
        serialize: serializeVariant,
        deserialize: deserializeVariant,
      );
    }
  }
  types.forEach((name, type) {
    if (type.baseName.isNotEmpty) {
      type.base = getType(types, type.baseName);
    }
    for (var field in type.fields) {
      field.type = getType(types, field.typeName);
    }
  });
  return types;
}