languageViewEncoding method

CborObject languageViewEncoding()

Encodes the language view into a CBOR map value.

Implementation

CborObject languageViewEncoding() {
  final sortedKeys = value.keys.toList()
    ..sort(
      (a, b) {
        final lenOrder = PlutusDataUtils.costModelKeyLength(a)
            .compareTo(PlutusDataUtils.costModelKeyLength(b));
        return lenOrder == 0 ? a.value.compareTo(b.value) : lenOrder;
      },
    );
  final Map<CborObject, CborObject> cborValues = {};
  for (final key in sortedKeys) {
    cborValues.addAll({
      key.toCbor(key == Language.plutusV1):
          value[key]!.toCbor(key == Language.plutusV1)
    });
  }
  return CborMapValue.fixedLength(cborValues);
}