From 4ef1ba69de9735538e37b28a681e09d49ce88f2f Mon Sep 17 00:00:00 2001 From: KtorZ Date: Tue, 14 Feb 2023 09:16:30 +0100 Subject: [PATCH] Use blueprint in hello-world example. --- examples/hello_world/hello_world-lock.ts | 7 ++++--- examples/hello_world/hello_world-unlock.ts | 9 +++++---- examples/hello_world/plutus.json | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/hello_world/hello_world-lock.ts b/examples/hello_world/hello_world-lock.ts index 8cc7efe3..2cb1d00f 100644 --- a/examples/hello_world/hello_world-lock.ts +++ b/examples/hello_world/hello_world-lock.ts @@ -20,14 +20,15 @@ const lucid = await Lucid.new( lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk")); -const validator = await readValidator("./assets/hello_world/spend/script.cbor"); +const validator = await readValidator(); // --- Supporting functions -async function readValidator(filepath: String): Promise { +async function readValidator(): Promise { + const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0]; return { type: "PlutusV2", - script: toHex(cbor.encode(fromHex(await Deno.readTextFile(filepath)))), + script: toHex(cbor.encode(fromHex(validator.compiledCode))), }; } diff --git a/examples/hello_world/hello_world-unlock.ts b/examples/hello_world/hello_world-unlock.ts index ab753762..646cfc12 100644 --- a/examples/hello_world/hello_world-unlock.ts +++ b/examples/hello_world/hello_world-unlock.ts @@ -21,7 +21,7 @@ const lucid = await Lucid.new( lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk")); -const validator = await readValidator("./assets/hello_world/spend/script.cbor"); +const validator = await readValidator(); const utxo = { txHash: Deno.args[0], outputIndex: 0 }; @@ -55,9 +55,10 @@ async function unlock(ref, { from, using }): Promise { return signedTx.submit(); } -async function readValidator(filepath: String): Promise { +async function readValidator(): Promise { + const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0]; return { - type: "PlutusV2", - script: toHex(cbor.encode(fromHex(await Deno.readTextFile(filepath)))), + type: "PlutusV2", + script: toHex(cbor.encode(fromHex(validator.compiledCode))), }; } diff --git a/examples/hello_world/plutus.json b/examples/hello_world/plutus.json index 3e4e8b09..d456df61 100644 --- a/examples/hello_world/plutus.json +++ b/examples/hello_world/plutus.json @@ -40,8 +40,8 @@ } ] }, - "compiledCode": "58ad0100003232322225333004323253330063372e646e64004dd7198009801002240009210d48656c6c6f2c20576f726c64210013233300100137586600460066600460060089000240206eb8cc008c00c019200022253335573e004294054ccc024cdc79bae300a00200114a226660060066016004002294088c8ccc0040052000003222333300a3370e008004016466600800866e0000d2002300d001001235573c6ea8004526165734ae855d11", - "hash": "5e1e8fa84f2b557ddc362329413caa3fd89a1be26bfd24be05ce0a02" + "compiledCode": "58e10100003232323232323232222533300632323232533300a002100114a06464660026eb0cc010c014cc010c014019200048040dd7198021802804240006002002444a66601e00429404c8c94ccc038cdc78010018a5113330050050010033012003375c602000466e5cc8dcc8009bae330013002004480012410d48656c6c6f2c20576f726c64210022323330010014800000c888cccc030cdc3802001008119980200219b8000348008c0480040048c024dd50008a4c2c6002002444a66600e004293099802980098040011998018019804801000ab9a5736aae7955cfaba15745", + "hash": "287233442cf812fafd74ab135d665f110de89ac12775204ad741f220" } ] } \ No newline at end of file