ScriptRef.deserialize constructor

ScriptRef.deserialize(
  1. CborObject cbor
)

Deserializes a ScriptRef instance from CBOR.

Implementation

factory ScriptRef.deserialize(CborObject cbor) {
  if (cbor.hasType<CborTagValue>()) {
    final cborTag = cbor.cast<CborTagValue>();
    if (!BytesUtils.bytesEqual(cborTag.tags, _tag)) {
      throw MessageException("Invalid ScriptRef cbor tag.",
          details: {"Excepted": _tag, "Tag": cborTag.tags});
    }
    cbor = CborObject.fromCbor(cborTag.getValue<List<int>>()).cast();
  }
  final CborListValue cborList = cbor.cast();
  final type = ScriptRefType.deserialize(cborList.getIndex(0));
  if (type == ScriptRefType.plutusScript) {
    return ScriptRefPlutusScript.deserialize(cborList);
  }
  return ScriptRefNativeScript.deserialize(cborList);
}