ScriptRef.deserialize constructor
ScriptRef.deserialize(
- CborObject cbor
Deserializes a ScriptRef instance from CBOR.
Implementation
factory ScriptRef.deserialize(CborObject cbor) {
if (cbor.hasType<CborTagValue>()) {
final cborTag = cbor.as<CborTagValue>();
if (!BytesUtils.bytesEqual(cborTag.tags, _tag)) {
throw ADAPluginException('Invalid ScriptRef cbor tag.',
details: {'expected': _tag, 'Tag': cborTag.tags});
}
cbor = CborObject.fromCbor(
cborTag.valueAs<CborBytesValue>("ScriptRef").value);
}
final CborListValue cborList = cbor.as("ScriptRef");
final type = ScriptRefType.deserialize(cborList.elementAt<CborIntValue>(0));
switch (type) {
case ScriptRefType.nativeScript:
return ScriptRefNativeScript.deserialize(cborList);
case ScriptRefType.plutusScriptV1:
case ScriptRefType.plutusScriptV2:
case ScriptRefType.plutusScriptV3:
return ScriptRefPlutusScript.deserialize(cborList);
default:
throw ADAPluginException('Invalid ScriptRef type.');
}
}