From d4a6c0e96d5405cacf35e5d5d467805aa1bcaf00 Mon Sep 17 00:00:00 2001 From: rrruko Date: Thu, 31 Aug 2023 15:34:15 -0700 Subject: [PATCH] add missing applyDoubleCborEncoding in scriptRef handling for emulator --- src/provider/emulator.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/provider/emulator.ts b/src/provider/emulator.ts index 92758056..5e1bfbb1 100644 --- a/src/provider/emulator.ts +++ b/src/provider/emulator.ts @@ -26,6 +26,7 @@ import { fromHex, getAddressDetails, toHex, + applyDoubleCborEncoding, } from "../utils/utils.ts"; /** Concatentation of txHash + outputIndex */ @@ -464,27 +465,30 @@ export class Emulator implements Provider { } const scriptRef = entry.utxo.scriptRef; + console.log(scriptRef); if (scriptRef) { switch (scriptRef.type) { case "Native": { - const script = C.NativeScript.from_bytes(fromHex(scriptRef.script)); + const script = C.NativeScript.from_bytes(fromHex(applyDoubleCborEncoding(scriptRef.script))); nativeHashesOptional[ script.hash(C.ScriptHashNamespace.NativeScript).to_hex() ] = script; break; } case "PlutusV1": { - const script = C.PlutusScript.from_bytes(fromHex(scriptRef.script)); - plutusHashesOptional.push( - script.hash(C.ScriptHashNamespace.PlutusV1).to_hex(), - ); + console.log("PlutusV1 script of length: " + fromHex(scriptRef.script).length); + const script = C.PlutusScript.from_bytes(fromHex(applyDoubleCborEncoding(scriptRef.script))); + let it = script.hash(C.ScriptHashNamespace.PlutusV1).to_hex(); + console.log("pushing optional V1 hash from reference: " + it); + plutusHashesOptional.push(it); break; } case "PlutusV2": { - const script = C.PlutusScript.from_bytes(fromHex(scriptRef.script)); - plutusHashesOptional.push( - script.hash(C.ScriptHashNamespace.PlutusV2).to_hex(), - ); + console.log("PlutusV2 script of length: " + fromHex(scriptRef.script).length); + const script = C.PlutusScript.from_bytes(fromHex(applyDoubleCborEncoding(scriptRef.script))); + let it = script.hash(C.ScriptHashNamespace.PlutusV2).to_hex(); + console.log("pushing optional V2 hash from reference: " + it); + plutusHashesOptional.push(it); break; } }