Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"watch": "ng build --watch --configuration development",
"tests": "npx cypress open --config baseUrl=http://localhost:4200",
"tests:headless": "npx cypress run --headless --config baseUrl=http://localhost:4200",
"docker": "npm run build:prod && docker buildx build --platform linux/amd64 -t openmina/frontend:latest . && docker push openmina/frontend:latest"
"docker": "npm run build:prod && docker buildx build --platform linux/amd64 -t openmina/frontend:latest . && docker push openmina/frontend:latest",
"replace-assertion": "node replace-assertion.js"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -38,7 +39,7 @@
"mathjs": "^12.3.0",
"mina-signer": "^3.0.7",
"ngx-json-viewer": "^3.2.1",
"o1js": "^1.7.0",
"o1js": "^1.8.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
Expand Down
25 changes: 25 additions & 0 deletions frontend/replace-assertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');

const filePath = path.join(__dirname, 'src', 'assets', 'o1js', 'main.js');

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
process.exit(1);
}

console.log('Replacement already done.');
const updatedContent = data.replace(
/if\(!g\)throw Error/g,
'if(!g)new Error'
);

fs.writeFile(filePath, updatedContent, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
process.exit(1);
}
console.log('Replacement completed successfully.');
});
});
200 changes: 113 additions & 87 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import { AppSelectors } from '@app/app.state';
import { AppActions } from '@app/app.actions';
import { Observable, timer } from 'rxjs';
import { CONFIG } from '@shared/constants/config';
import { AccountUpdate, declareMethods, Field, method, Mina, PrivateKey, SmartContract, State, state } from 'o1js';

export class Square extends SmartContract {
@state(Field) num = State<Field>();

override init() {
super.init();
this.num.set(Field(3));
}

// @method
async update(square: Field) {
const currentState = this.num.get();
this.num.requireEquals(currentState);
square.assertEquals(currentState.mul(currentState));
this.num.set(square);
}
}
// import { AccountUpdate, declareMethods, Field, method, Mina, PrivateKey, SmartContract, State, state } from 'o1js';
//
// export class Square extends SmartContract {
// @state(Field) num = State<Field>();
//
// override init() {
// super.init();
// this.num.set(Field(3));
// }
//
// // @method
// async update(square: Field) {
// const currentState = this.num.get();
// this.num.requireEquals(currentState);
// square.assertEquals(currentState.mul(currentState));
// this.num.set(square);
// }
// }

declare const $: any;

@Component({
selector: 'app-root',
Expand All @@ -49,84 +51,108 @@ export class AppComponent extends ManualDetection implements OnInit {
}
}

ngOnInit(): void {
async ngOnInit() {
if (!this.hideToolbar && !CONFIG.hideNodeStats) {
this.scheduleNodeUpdates();
}
this.listenToWindowResizing();
console.log('Start');
this.startZK();
console.log('Finish!');
// console.log('Start');
// // this.startZK();
// console.log('Finish!');
// try {
// await this.loadScript('assets/o1js/main.js');
// // Now the script is loaded, and you can access the exported variable
// if (typeof (window as any).$ !== 'undefined') {
// const $ = (window as any).$;
// console.log('Script loaded:', $);
// // Use $ here
// $.default.gql4();
// } else {
// console.error('$ is not defined after loading the script');
// }
// } catch (error) {
// console.error('Error loading script:', error);
// }
}

async startZK() {
//@ts-ignore
declareMethods(Square, { update: [Field] });

const useProof = false;

const Local = await Mina.LocalBlockchain({ proofsEnabled: useProof });
Mina.setActiveInstance(Local);

const deployerAccount = Local.testAccounts[0];
const deployerKey = deployerAccount.key;
const senderAccount = Local.testAccounts[1];
const senderKey = senderAccount.key;
// ----------------------------------------------------

// Create a public/private key pair. The public key is your address and where you deploy the zkApp to
const zkAppPrivateKey = PrivateKey.random();
const zkAppAddress = zkAppPrivateKey.toPublicKey();

// create an instance of Square - and deploy it to zkAppAddress
const zkAppInstance = new Square(zkAppAddress);
const deployTxn = await Mina.transaction(deployerAccount, async () => {
AccountUpdate.fundNewAccount(deployerAccount);
await zkAppInstance.deploy();
loadScript(scriptUrl: string): Promise<void> {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = scriptUrl;
script.onload = () => resolve();
script.onerror = (error) => reject(error);
document.body.appendChild(script);
});
await deployTxn.sign([deployerKey, zkAppPrivateKey]).send();

// get the initial state of Square after deployment
const num0 = zkAppInstance.num.get();
console.log('state after init:', num0.toString());

// ----------------------------------------------------

const txn1 = await Mina.transaction(senderAccount, async () => {
await zkAppInstance.update(Field(9));
});
await txn1.prove();
await txn1.sign([senderKey]).send();

const num1 = zkAppInstance.num.get();
console.log('state after txn1:', num1.toString());

// ----------------------------------------------------

try {
const txn2 = await Mina.transaction(senderAccount, async () => {
await zkAppInstance.update(Field(75));
});
await txn2.prove();
await txn2.sign([senderKey]).send();
} catch (error: any) {
console.log(error.message);
}
const num2 = zkAppInstance.num.get();
console.log('state after txn2:', num2.toString());

// ----------------------------------------------------

const txn3 = await Mina.transaction(senderAccount, async () => {
await zkAppInstance.update(Field(81));
});
await txn3.prove();
await txn3.sign([senderKey]).send();

const num3 = zkAppInstance.num.get();
console.log('state after txn3:', num3.toString());
}

// async startZK() {
// //@ts-ignore
// declareMethods(Square, { update: [Field] });
//
// const useProof = false;
//
// const Local = await Mina.LocalBlockchain({ proofsEnabled: useProof });
// Mina.setActiveInstance(Local);
//
// const deployerAccount = Local.testAccounts[0];
// const deployerKey = deployerAccount.key;
// const senderAccount = Local.testAccounts[1];
// const senderKey = senderAccount.key;
// // ----------------------------------------------------
//
// // Create a public/private key pair. The public key is your address and where you deploy the zkApp to
// const zkAppPrivateKey = PrivateKey.random();
// const zkAppAddress = zkAppPrivateKey.toPublicKey();
//
// // create an instance of Square - and deploy it to zkAppAddress
// const zkAppInstance = new Square(zkAppAddress);
// const deployTxn = await Mina.transaction(deployerAccount, async () => {
// AccountUpdate.fundNewAccount(deployerAccount);
// await zkAppInstance.deploy();
// });
// await deployTxn.sign([deployerKey, zkAppPrivateKey]).send();
//
// // get the initial state of Square after deployment
// const num0 = zkAppInstance.num.get();
// console.log('state after init:', num0.toString());
//
// // ----------------------------------------------------
//
// const txn1 = await Mina.transaction(senderAccount, async () => {
// await zkAppInstance.update(Field(9));
// });
// await txn1.prove();
// await txn1.sign([senderKey]).send();
//
// const num1 = zkAppInstance.num.get();
// console.log('state after txn1:', num1.toString());
//
// // ----------------------------------------------------
//
// try {
// const txn2 = await Mina.transaction(senderAccount, async () => {
// await zkAppInstance.update(Field(75));
// });
// await txn2.prove();
// await txn2.sign([senderKey]).send();
// } catch (error: any) {
// console.log(error.message);
// }
// const num2 = zkAppInstance.num.get();
// console.log('state after txn2:', num2.toString());
//
// // ----------------------------------------------------
//
// const txn3 = await Mina.transaction(senderAccount, async () => {
// await zkAppInstance.update(Field(81));
// });
// await txn3.prove();
// await txn3.sign([senderKey]).send();
//
// const num3 = zkAppInstance.num.get();
// console.log('state after txn3:', num3.toString());
// }

private scheduleNodeUpdates(): void {
timer(1000, 5000).subscribe(() => this.store.dispatch(AppActions.getNodeDetails()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<form [formGroup]="formGroup" class="h-xl fx-row-vert-cent pl-12 pr-12 secondary shrink-0">
<button (click)="send()"
class="live-button active"
[class.disabled]="streamSending">Send
[class.disabled]="streamSending">Send Payment
</button>
<input type="number" class="mina-input border-rad-4 mr-8 ml-8 text-center" formControlName="batch">
<div>transactions with</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import 'openmina';

.live-button {
width: 110px;
}

.mina-input[formcontrolname='batch'] {
width: 55px;
}
Expand Down
Loading
Loading