Skip to content

Commit

Permalink
replace process.env beforehand and add code for meowhero
Browse files Browse the repository at this point in the history
  • Loading branch information
wizicer committed Aug 2, 2023
1 parent 4d466c9 commit 45a5128
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
11 changes: 6 additions & 5 deletions ui/src/services/files/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 },
() => {
Expand Down
28 changes: 27 additions & 1 deletion ui/src/services/playgroundPacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 45a5128

Please sign in to comment.