normalizedTypeToMoveTypeSignatureBody function

dynamic normalizedTypeToMoveTypeSignatureBody(
  1. dynamic type
)

Implementation

dynamic normalizedTypeToMoveTypeSignatureBody(
	SuiMoveNormalizedType type
) {
	if (type is String) {
		switch (type) {
			case 'Address':
				return 'address';
			case 'Bool':
				return 'bool';
			case 'U8':
				return 'u8';
			case 'U16':
				return 'u16';
			case 'U32':
				return 'u32';
			case 'U64':
				return 'u64';
			case 'U128':
				return 'u128';
			case 'U256':
				return 'u256';
			default:
				throw ArgumentError("Unexpected type $type");
		}
	}

	if (type['Vector'] != null) {
		return { "vector": normalizedTypeToMoveTypeSignatureBody(type["Vector"]) };
	}

	if (type['Struct'] != null) {
		return {
			"datatype": {
				"package": type["Struct"]["address"],
				"module": type["Struct"]["module"],
				"type": type["Struct"]["name"],
				"typeParameters": type["Struct"]["typeArguments"].map(normalizedTypeToMoveTypeSignatureBody),
			},
		};
	}

	if (type['TypeParameter'] != null) {
		return { "typeParameter": type["TypeParameter"] };
	}

	throw ArgumentError("Unexpected type $type");
}