feat(one_shot): actually getting properly applied contracts
Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
parent
a82cedbd92
commit
79fd6b4828
|
@ -13,6 +13,9 @@ export interface AppProps {
|
||||||
export default function App({ validators }: AppProps) {
|
export default function App({ validators }: AppProps) {
|
||||||
const [lucid, setLucid] = useState<Lucid | null>(null);
|
const [lucid, setLucid] = useState<Lucid | null>(null);
|
||||||
const [tokenName, setTokenName] = useState<string>("");
|
const [tokenName, setTokenName] = useState<string>("");
|
||||||
|
const [parameterizedContracts, setParameterizedContracts] = useState<
|
||||||
|
{ lock: string; mint: string } | null
|
||||||
|
>(null);
|
||||||
|
|
||||||
const setupLucid = async (blockfrostApiKey: string) => {
|
const setupLucid = async (blockfrostApiKey: string) => {
|
||||||
const lucid = await Lucid.new(
|
const lucid = await Lucid.new(
|
||||||
|
@ -42,15 +45,22 @@ export default function App({ validators }: AppProps) {
|
||||||
|
|
||||||
const utxos = await lucid?.wallet.getUtxos()!;
|
const utxos = await lucid?.wallet.getUtxos()!;
|
||||||
|
|
||||||
|
console.log(utxos);
|
||||||
|
|
||||||
const utxo = utxos[0];
|
const utxo = utxos[0];
|
||||||
const outputReference = {
|
const outputReference = {
|
||||||
txHash: utxo.txHash,
|
txHash: utxo.txHash,
|
||||||
outputIndex: utxo.outputIndex,
|
outputIndex: utxo.outputIndex,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { lock, mint } = applyParams(tokenName, outputReference, validators);
|
const contracts = applyParams(
|
||||||
|
tokenName,
|
||||||
|
outputReference,
|
||||||
|
validators,
|
||||||
|
lucid!,
|
||||||
|
);
|
||||||
|
|
||||||
console.log(lock, mint);
|
setParameterizedContracts(contracts);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -90,6 +100,19 @@ export default function App({ validators }: AppProps) {
|
||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
)}
|
)}
|
||||||
|
{parameterizedContracts && (
|
||||||
|
<>
|
||||||
|
<h3 class="mt-4 mb-2">Lock</h3>
|
||||||
|
<pre class="bg-gray-200 p-2 rounded overflow-x-scroll">
|
||||||
|
{parameterizedContracts.lock}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h3 class="mt-4 mb-2">Mint</h3>
|
||||||
|
<pre class="bg-gray-200 p-2 rounded overflow-x-scroll">
|
||||||
|
{parameterizedContracts.mint}
|
||||||
|
</pre>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import {
|
import {
|
||||||
applyDoubleCborEncoding,
|
applyDoubleCborEncoding,
|
||||||
applyParamsToScript,
|
applyParamsToScript,
|
||||||
|
C,
|
||||||
|
Constr,
|
||||||
Data,
|
Data,
|
||||||
|
fromText,
|
||||||
Lucid,
|
Lucid,
|
||||||
MintingPolicy,
|
MintingPolicy,
|
||||||
OutRef,
|
OutRef,
|
||||||
|
@ -48,18 +51,22 @@ export function applyParams(
|
||||||
tokenName: string,
|
tokenName: string,
|
||||||
outputReference: OutRef,
|
outputReference: OutRef,
|
||||||
validators: Validators,
|
validators: Validators,
|
||||||
|
lucid: Lucid,
|
||||||
): { lock: string; mint: string } {
|
): { lock: string; mint: string } {
|
||||||
const mint = applyParamsToScript(validators.mint.script, [
|
const outRef = new Constr(0, [
|
||||||
tokenName,
|
new Constr(0, [outputReference.txHash]),
|
||||||
outputReference,
|
BigInt(outputReference.outputIndex),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const lucid = new Lucid();
|
const mint = applyParamsToScript(validators.mint.script, [
|
||||||
|
fromText(tokenName),
|
||||||
|
outRef,
|
||||||
|
]);
|
||||||
|
|
||||||
const policyId = lucid.utils.validatorToScriptHash(validators.mint);
|
const policyId = lucid.utils.validatorToScriptHash(validators.mint);
|
||||||
|
|
||||||
const lock = applyParamsToScript(validators.lock.script, [
|
const lock = applyParamsToScript(validators.lock.script, [
|
||||||
tokenName,
|
fromText(tokenName),
|
||||||
policyId,
|
policyId,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue