From 79fd6b48284b9f040e20d73197999db4505a5cb6 Mon Sep 17 00:00:00 2001 From: rvcas Date: Sat, 11 Mar 2023 00:41:19 -0500 Subject: [PATCH] feat(one_shot): actually getting properly applied contracts Co-authored-by: Kasey White --- examples/one_shot/islands/App.tsx | 27 +++++++++++++++++++++++++-- examples/one_shot/utils.ts | 17 ++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/examples/one_shot/islands/App.tsx b/examples/one_shot/islands/App.tsx index 70ec12c4..e09bfc56 100644 --- a/examples/one_shot/islands/App.tsx +++ b/examples/one_shot/islands/App.tsx @@ -13,6 +13,9 @@ export interface AppProps { export default function App({ validators }: AppProps) { const [lucid, setLucid] = useState(null); const [tokenName, setTokenName] = useState(""); + const [parameterizedContracts, setParameterizedContracts] = useState< + { lock: string; mint: string } | null + >(null); const setupLucid = async (blockfrostApiKey: string) => { const lucid = await Lucid.new( @@ -42,15 +45,22 @@ export default function App({ validators }: AppProps) { const utxos = await lucid?.wallet.getUtxos()!; + console.log(utxos); + const utxo = utxos[0]; const outputReference = { txHash: utxo.txHash, outputIndex: utxo.outputIndex, }; - const { lock, mint } = applyParams(tokenName, outputReference, validators); + const contracts = applyParams( + tokenName, + outputReference, + validators, + lucid!, + ); - console.log(lock, mint); + setParameterizedContracts(contracts); }; return ( @@ -90,6 +100,19 @@ export default function App({ validators }: AppProps) { )} )} + {parameterizedContracts && ( + <> +

Lock

+
+            {parameterizedContracts.lock}
+          
+ +

Mint

+
+            {parameterizedContracts.mint}
+          
+ + )} ); } diff --git a/examples/one_shot/utils.ts b/examples/one_shot/utils.ts index 7199d745..94583ddd 100644 --- a/examples/one_shot/utils.ts +++ b/examples/one_shot/utils.ts @@ -1,7 +1,10 @@ import { applyDoubleCborEncoding, applyParamsToScript, + C, + Constr, Data, + fromText, Lucid, MintingPolicy, OutRef, @@ -48,18 +51,22 @@ export function applyParams( tokenName: string, outputReference: OutRef, validators: Validators, + lucid: Lucid, ): { lock: string; mint: string } { - const mint = applyParamsToScript(validators.mint.script, [ - tokenName, - outputReference, + const outRef = new Constr(0, [ + new Constr(0, [outputReference.txHash]), + BigInt(outputReference.outputIndex), ]); - const lucid = new Lucid(); + const mint = applyParamsToScript(validators.mint.script, [ + fromText(tokenName), + outRef, + ]); const policyId = lucid.utils.validatorToScriptHash(validators.mint); const lock = applyParamsToScript(validators.lock.script, [ - tokenName, + fromText(tokenName), policyId, ]);