From 45a512807f3a08d3933db5bcae5b45087874af9e Mon Sep 17 00:00:00 2001 From: LiangShuang Date: Wed, 2 Aug 2023 08:20:01 +0800 Subject: [PATCH] replace process.env beforehand and add code for meowhero --- ui/src/services/files/run.ts | 11 ++++++----- ui/src/services/playgroundPacker.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ui/src/services/files/run.ts b/ui/src/services/files/run.ts index 3d74b59..80c44f4 100644 --- a/ui/src/services/files/run.ts +++ b/ui/src/services/files/run.ts @@ -3,25 +3,25 @@ import { fetchAccount, Mina, PrivateKey, PublicKey, Field } from 'snarkyjs'; import { CONTRACTNAME } from './contract.js'; const endpointUrl = - process.env.ENDPOINT_URL ?? 'https://proxy.berkeley.minaexplorer.com/graphql'; + penv.ENDPOINT_URL ?? 'https://proxy.berkeley.minaexplorer.com/graphql'; const Berkeley = Mina.Network(endpointUrl); Mina.setActiveInstance(Berkeley); const deployTransactionFee = 100_000_000; await (async function run() { - if (!process.env.CONTRACT_ID) { + if (!penv.CONTRACT_ID) { console.log('set CONTRACT_ID in .env file first.'); return; } - if (!process.env.PRIVATE_KEY) { + if (!penv.PRIVATE_KEY) { console.log('set PRIVATE_KEY in .env file first.'); return; } - const zkAppPublicKey = PublicKey.fromBase58(process.env.CONTRACT_ID); - const deployerPrivateKey = PrivateKey.fromBase58(process.env.PRIVATE_KEY); + const zkAppPublicKey = PublicKey.fromBase58(penv.CONTRACT_ID); + const deployerPrivateKey = PrivateKey.fromBase58(penv.PRIVATE_KEY); const deployerPublicKey = deployerPrivateKey.toPublicKey(); const zkapp = new CONTRACTNAME(zkAppPublicKey); @@ -60,6 +60,7 @@ await (async function run() { await CONTRACTNAME.compile(); console.log('Creating transaction for zkapp', zkAppPublicKey.toBase58()); + /* COMPLEMENT_CODE */ const transaction = await Mina.transaction( { sender: deployerPublicKey, fee: deployTransactionFee }, () => { diff --git a/ui/src/services/playgroundPacker.ts b/ui/src/services/playgroundPacker.ts index d56e2ee..b6a9534 100644 --- a/ui/src/services/playgroundPacker.ts +++ b/ui/src/services/playgroundPacker.ts @@ -42,10 +42,36 @@ export async function packPlaygroundProject( zip.file( 'src/run.ts', runStr + .replaceAll( + '/* COMPLEMENT_CODE */\n', + contract == 'meowhero' + ? ` + const genesisMeow = new Meow({ + power: UInt64.from(INIT_POINT), + magic: UInt64.from(INIT_POINT), + speed: UInt64.from(INIT_POINT), + lucky: UInt64.from(INIT_POINT), + charm: UInt64.from(INIT_POINT), + }); + const meowList = [genesisMeow, genesisMeow]; + const tree = new MerkleTree(LEGION_TREE_HEIGHT); + tree.setLeaf(0n, genesisMeow.hash()); + tree.setLeaf(1n, genesisMeow.hash()); + const path1 = new LegionMerkleWitness(tree.getWitness(0n)); + const path2 = new LegionMerkleWitness(tree.getWitness(1n)); + const babyPath = new LegionMerkleWitness(tree.getWitness(BigInt(meowList.length))); +` + : '' + ) + .replaceAll('penv', 'process.env') .replaceAll('CONTRACTNAME', contractName) .replaceAll( 'zkapp.play();', - `zkapp.play(${Array(c.parameterNumber).fill('Field(0)').join(', ')});` + contract == 'meowhero' + ? 'zkapp.breed(genesisMeow, path1, genesisMeow, path2, babyPath);' + : `zkapp.play(${Array(c.parameterNumber) + .fill('Field(0)') + .join(', ')});` ) ); zip.file('src/contract.ts', contractContent);