Use blueprint in hello-world example.

This commit is contained in:
KtorZ 2023-02-14 09:16:30 +01:00
parent 3b3ec7d95c
commit 4ef1ba69de
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 11 additions and 9 deletions

View File

@ -20,14 +20,15 @@ const lucid = await Lucid.new(
lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk")); lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk"));
const validator = await readValidator("./assets/hello_world/spend/script.cbor"); const validator = await readValidator();
// --- Supporting functions // --- Supporting functions
async function readValidator(filepath: String): Promise<SpendingValidator> { async function readValidator(): Promise<SpendingValidator> {
const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
return { return {
type: "PlutusV2", type: "PlutusV2",
script: toHex(cbor.encode(fromHex(await Deno.readTextFile(filepath)))), script: toHex(cbor.encode(fromHex(validator.compiledCode))),
}; };
} }

View File

@ -21,7 +21,7 @@ const lucid = await Lucid.new(
lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./key.sk")); 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 }; const utxo = { txHash: Deno.args[0], outputIndex: 0 };
@ -55,9 +55,10 @@ async function unlock(ref, { from, using }): Promise<TxHash> {
return signedTx.submit(); return signedTx.submit();
} }
async function readValidator(filepath: String): Promise<SpendingValidator> { async function readValidator(): Promise<SpendingValidator> {
const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
return { return {
type: "PlutusV2", type: "PlutusV2",
script: toHex(cbor.encode(fromHex(await Deno.readTextFile(filepath)))), script: toHex(cbor.encode(fromHex(validator.compiledCode))),
}; };
} }

View File

@ -40,8 +40,8 @@
} }
] ]
}, },
"compiledCode": "58ad0100003232322225333004323253330063372e646e64004dd7198009801002240009210d48656c6c6f2c20576f726c64210013233300100137586600460066600460060089000240206eb8cc008c00c019200022253335573e004294054ccc024cdc79bae300a00200114a226660060066016004002294088c8ccc0040052000003222333300a3370e008004016466600800866e0000d2002300d001001235573c6ea8004526165734ae855d11", "compiledCode": "58e10100003232323232323232222533300632323232533300a002100114a06464660026eb0cc010c014cc010c014019200048040dd7198021802804240006002002444a66601e00429404c8c94ccc038cdc78010018a5113330050050010033012003375c602000466e5cc8dcc8009bae330013002004480012410d48656c6c6f2c20576f726c64210022323330010014800000c888cccc030cdc3802001008119980200219b8000348008c0480040048c024dd50008a4c2c6002002444a66600e004293099802980098040011998018019804801000ab9a5736aae7955cfaba15745",
"hash": "5e1e8fa84f2b557ddc362329413caa3fd89a1be26bfd24be05ce0a02" "hash": "287233442cf812fafd74ab135d665f110de89ac12775204ad741f220"
} }
] ]
} }