TransactionOutput.deserialize constructor

TransactionOutput.deserialize(
  1. CborObject cbor
)

Deserializes a TransactionOutput instance from a CBOR object.

Implementation

factory TransactionOutput.deserialize(CborObject cbor) {
  if (cbor is CborListValue) {
    final address = AdaAddressUtils.encodeBytes(cbor.getIndex<List<int>>(0));
    return TransactionOutput(
        address: address,
        amount: Value.deserialize(cbor.getIndex<CborObject>(1)),
        plutusData: cbor
            .getIndex<CborObject?>(2)
            ?.castTo<DataOption, CborObject>(
                (e) => DataOption.deserialize(e)),
        scriptRef: cbor
            .getIndex<CborObject?>(3)
            ?.castTo<ScriptRef, CborListValue>(
                (e) => ScriptRef.deserialize(e)));
  }
  final CborMapValue<CborObject, CborObject> cborMap = cbor.cast();
  final address =
      AdaAddressUtils.encodeBytes(cborMap.getValueFromIntKey<List<int>>(0));
  return TransactionOutput(
      address: address,
      amount: Value.deserialize(cborMap.getValueFromIntKey(1)),
      plutusData: cborMap
          .getValueFromIntKey<CborObject?>(2)
          ?.castTo<DataOption, CborObject>((e) => DataOption.deserialize(e)),
      scriptRef: cborMap
          .getValueFromIntKey<CborTagValue?>(3)
          ?.castTo<ScriptRef, CborTagValue>((e) => ScriptRef.deserialize(e)));
}