toCbor method

  1. @override
CborObject toCbor()
override

Converts the object to a CBOR object.

Implementation

@override
CborObject toCbor() {
  final Map<CborIntValue, CborObject> data = {
    if (inputs != null) CborIntValue(0): inputs!.toCbor(),
    if (outputs != null) CborIntValue(1): outputs!.toCbor(),
    CborIntValue(2): CborUnsignedValue.u64(fee),
    if (ttl != null) ...{const CborIntValue(3): CborUnsignedValue.u64(ttl!)},
    if (certificates != null) ...{
      const CborIntValue(4): certificates!.toCbor()
    },
    if (withdrawals != null) ...{
      const CborIntValue(5): withdrawals!.toCbor(),
    },
    if (update != null) ...{const CborIntValue(6): update!.toCbor()},
    if (auxiliaryDataHash != null) ...{
      CborIntValue(7): auxiliaryDataHash!.toCbor()
    },
    if (validityStartInterval != null) ...{
      const CborIntValue(8): CborUnsignedValue.u64(validityStartInterval!)
    },
    if (mint != null) ...{const CborIntValue(9): mint!.toCbor()},
    if (scriptDataHash != null) ...{
      const CborIntValue(11): scriptDataHash!.toCbor()
    },
    if (collateral != null) const CborIntValue(13): collateral!.toCbor(),
    if (requiredSigners != null)
      const CborIntValue(14): requiredSigners!.toCbor(),
    if (network != null) ...{
      const CborIntValue(15): CborIntValue(network!.value),
    },
    if (collateralReturn != null) ...{
      const CborIntValue(16): collateralReturn!.toCbor()
    },
    if (totalCollateral != null) ...{
      const CborIntValue(17): CborUnsignedValue.u64(totalCollateral!),
    },
    if (referenceInputs != null)
      const CborIntValue(18): referenceInputs!.toCbor(),
    if (votingProcedures != null) ...{
      const CborIntValue(19): votingProcedures!.toCbor()
    },
    if (votingProposals != null) ...{
      const CborIntValue(20): votingProposals!.toCbor()
    },
    if (currentTreasuryValue != null) ...{
      const CborIntValue(21): CborUnsignedValue.u64(currentTreasuryValue!),
    },
    if (donation != null) ...{
      const CborIntValue(22): CborUnsignedValue.u64(donation!),
    },
  };
  Map<CborIntValue, CborObject> sort = {};
  final order = serializationConfig.keyOrder;
  if (order == null) {
    sort = data;
  } else {
    for (final i in order) {
      final key = CborIntValue(i);
      assert(data.containsKey(key), "key does not exists $i");
      if (!data.containsKey(key)) continue;
      sort[key] = data[key]!;
    }
  }

  return CborMapValue.definite(sort);
}