Skip to content

Commit ea3038e

Browse files
committed
o1js integrated
1 parent 2529ad0 commit ea3038e

21 files changed

+888
-122
lines changed

frontend/package-lock.json

Lines changed: 28 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"watch": "ng build --watch --configuration development",
1111
"tests": "npx cypress open --config baseUrl=http://localhost:4200",
1212
"tests:headless": "npx cypress run --headless --config baseUrl=http://localhost:4200",
13-
"docker": "npm run build:prod && docker buildx build --platform linux/amd64 -t openmina/frontend:latest . && docker push openmina/frontend:latest"
13+
"docker": "npm run build:prod && docker buildx build --platform linux/amd64 -t openmina/frontend:latest . && docker push openmina/frontend:latest",
14+
"replace-assertion": "node replace-assertion.js"
1415
},
1516
"private": true,
1617
"dependencies": {
@@ -38,7 +39,7 @@
3839
"mathjs": "^12.3.0",
3940
"mina-signer": "^3.0.7",
4041
"ngx-json-viewer": "^3.2.1",
41-
"o1js": "^1.7.0",
42+
"o1js": "^1.8.0",
4243
"rxjs": "~7.8.0",
4344
"tslib": "^2.3.0",
4445
"zone.js": "~0.13.0"

frontend/replace-assertion.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const filePath = path.join(__dirname, 'src', 'assets', 'o1js', 'main.js');
5+
6+
fs.readFile(filePath, 'utf8', (err, data) => {
7+
if (err) {
8+
console.error('Error reading file:', err);
9+
process.exit(1);
10+
}
11+
12+
console.log('Replacement already done.');
13+
const updatedContent = data.replace(
14+
/if\(!g\)throw Error/g,
15+
'if(!g)new Error'
16+
);
17+
18+
fs.writeFile(filePath, updatedContent, 'utf8', (err) => {
19+
if (err) {
20+
console.error('Error writing file:', err);
21+
process.exit(1);
22+
}
23+
console.log('Replacement completed successfully.');
24+
});
25+
});

frontend/src/app/app.component.ts

Lines changed: 113 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@ import { AppSelectors } from '@app/app.state';
88
import { AppActions } from '@app/app.actions';
99
import { Observable, timer } from 'rxjs';
1010
import { CONFIG } from '@shared/constants/config';
11-
import { AccountUpdate, declareMethods, Field, method, Mina, PrivateKey, SmartContract, State, state } from 'o1js';
12-
13-
export class Square extends SmartContract {
14-
@state(Field) num = State<Field>();
15-
16-
override init() {
17-
super.init();
18-
this.num.set(Field(3));
19-
}
20-
21-
// @method
22-
async update(square: Field) {
23-
const currentState = this.num.get();
24-
this.num.requireEquals(currentState);
25-
square.assertEquals(currentState.mul(currentState));
26-
this.num.set(square);
27-
}
28-
}
11+
// import { AccountUpdate, declareMethods, Field, method, Mina, PrivateKey, SmartContract, State, state } from 'o1js';
12+
//
13+
// export class Square extends SmartContract {
14+
// @state(Field) num = State<Field>();
15+
//
16+
// override init() {
17+
// super.init();
18+
// this.num.set(Field(3));
19+
// }
20+
//
21+
// // @method
22+
// async update(square: Field) {
23+
// const currentState = this.num.get();
24+
// this.num.requireEquals(currentState);
25+
// square.assertEquals(currentState.mul(currentState));
26+
// this.num.set(square);
27+
// }
28+
// }
29+
30+
declare const $: any;
2931

3032
@Component({
3133
selector: 'app-root',
@@ -49,84 +51,108 @@ export class AppComponent extends ManualDetection implements OnInit {
4951
}
5052
}
5153

52-
ngOnInit(): void {
54+
async ngOnInit() {
5355
if (!this.hideToolbar && !CONFIG.hideNodeStats) {
5456
this.scheduleNodeUpdates();
5557
}
5658
this.listenToWindowResizing();
57-
console.log('Start');
58-
this.startZK();
59-
console.log('Finish!');
59+
// console.log('Start');
60+
// // this.startZK();
61+
// console.log('Finish!');
62+
// try {
63+
// await this.loadScript('assets/o1js/main.js');
64+
// // Now the script is loaded, and you can access the exported variable
65+
// if (typeof (window as any).$ !== 'undefined') {
66+
// const $ = (window as any).$;
67+
// console.log('Script loaded:', $);
68+
// // Use $ here
69+
// $.default.gql4();
70+
// } else {
71+
// console.error('$ is not defined after loading the script');
72+
// }
73+
// } catch (error) {
74+
// console.error('Error loading script:', error);
75+
// }
6076
}
6177

62-
async startZK() {
63-
//@ts-ignore
64-
declareMethods(Square, { update: [Field] });
65-
66-
const useProof = false;
67-
68-
const Local = await Mina.LocalBlockchain({ proofsEnabled: useProof });
69-
Mina.setActiveInstance(Local);
70-
71-
const deployerAccount = Local.testAccounts[0];
72-
const deployerKey = deployerAccount.key;
73-
const senderAccount = Local.testAccounts[1];
74-
const senderKey = senderAccount.key;
75-
// ----------------------------------------------------
76-
77-
// Create a public/private key pair. The public key is your address and where you deploy the zkApp to
78-
const zkAppPrivateKey = PrivateKey.random();
79-
const zkAppAddress = zkAppPrivateKey.toPublicKey();
80-
81-
// create an instance of Square - and deploy it to zkAppAddress
82-
const zkAppInstance = new Square(zkAppAddress);
83-
const deployTxn = await Mina.transaction(deployerAccount, async () => {
84-
AccountUpdate.fundNewAccount(deployerAccount);
85-
await zkAppInstance.deploy();
78+
loadScript(scriptUrl: string): Promise<void> {
79+
return new Promise((resolve, reject) => {
80+
const script = document.createElement('script');
81+
script.src = scriptUrl;
82+
script.onload = () => resolve();
83+
script.onerror = (error) => reject(error);
84+
document.body.appendChild(script);
8685
});
87-
await deployTxn.sign([deployerKey, zkAppPrivateKey]).send();
88-
89-
// get the initial state of Square after deployment
90-
const num0 = zkAppInstance.num.get();
91-
console.log('state after init:', num0.toString());
92-
93-
// ----------------------------------------------------
94-
95-
const txn1 = await Mina.transaction(senderAccount, async () => {
96-
await zkAppInstance.update(Field(9));
97-
});
98-
await txn1.prove();
99-
await txn1.sign([senderKey]).send();
100-
101-
const num1 = zkAppInstance.num.get();
102-
console.log('state after txn1:', num1.toString());
103-
104-
// ----------------------------------------------------
105-
106-
try {
107-
const txn2 = await Mina.transaction(senderAccount, async () => {
108-
await zkAppInstance.update(Field(75));
109-
});
110-
await txn2.prove();
111-
await txn2.sign([senderKey]).send();
112-
} catch (error: any) {
113-
console.log(error.message);
114-
}
115-
const num2 = zkAppInstance.num.get();
116-
console.log('state after txn2:', num2.toString());
117-
118-
// ----------------------------------------------------
119-
120-
const txn3 = await Mina.transaction(senderAccount, async () => {
121-
await zkAppInstance.update(Field(81));
122-
});
123-
await txn3.prove();
124-
await txn3.sign([senderKey]).send();
125-
126-
const num3 = zkAppInstance.num.get();
127-
console.log('state after txn3:', num3.toString());
12886
}
12987

88+
// async startZK() {
89+
// //@ts-ignore
90+
// declareMethods(Square, { update: [Field] });
91+
//
92+
// const useProof = false;
93+
//
94+
// const Local = await Mina.LocalBlockchain({ proofsEnabled: useProof });
95+
// Mina.setActiveInstance(Local);
96+
//
97+
// const deployerAccount = Local.testAccounts[0];
98+
// const deployerKey = deployerAccount.key;
99+
// const senderAccount = Local.testAccounts[1];
100+
// const senderKey = senderAccount.key;
101+
// // ----------------------------------------------------
102+
//
103+
// // Create a public/private key pair. The public key is your address and where you deploy the zkApp to
104+
// const zkAppPrivateKey = PrivateKey.random();
105+
// const zkAppAddress = zkAppPrivateKey.toPublicKey();
106+
//
107+
// // create an instance of Square - and deploy it to zkAppAddress
108+
// const zkAppInstance = new Square(zkAppAddress);
109+
// const deployTxn = await Mina.transaction(deployerAccount, async () => {
110+
// AccountUpdate.fundNewAccount(deployerAccount);
111+
// await zkAppInstance.deploy();
112+
// });
113+
// await deployTxn.sign([deployerKey, zkAppPrivateKey]).send();
114+
//
115+
// // get the initial state of Square after deployment
116+
// const num0 = zkAppInstance.num.get();
117+
// console.log('state after init:', num0.toString());
118+
//
119+
// // ----------------------------------------------------
120+
//
121+
// const txn1 = await Mina.transaction(senderAccount, async () => {
122+
// await zkAppInstance.update(Field(9));
123+
// });
124+
// await txn1.prove();
125+
// await txn1.sign([senderKey]).send();
126+
//
127+
// const num1 = zkAppInstance.num.get();
128+
// console.log('state after txn1:', num1.toString());
129+
//
130+
// // ----------------------------------------------------
131+
//
132+
// try {
133+
// const txn2 = await Mina.transaction(senderAccount, async () => {
134+
// await zkAppInstance.update(Field(75));
135+
// });
136+
// await txn2.prove();
137+
// await txn2.sign([senderKey]).send();
138+
// } catch (error: any) {
139+
// console.log(error.message);
140+
// }
141+
// const num2 = zkAppInstance.num.get();
142+
// console.log('state after txn2:', num2.toString());
143+
//
144+
// // ----------------------------------------------------
145+
//
146+
// const txn3 = await Mina.transaction(senderAccount, async () => {
147+
// await zkAppInstance.update(Field(81));
148+
// });
149+
// await txn3.prove();
150+
// await txn3.sign([senderKey]).send();
151+
//
152+
// const num3 = zkAppInstance.num.get();
153+
// console.log('state after txn3:', num3.toString());
154+
// }
155+
130156
private scheduleNodeUpdates(): void {
131157
timer(1000, 5000).subscribe(() => this.store.dispatch(AppActions.getNodeDetails()));
132158
}

frontend/src/app/features/benchmarks/wallets/benchmarks-wallets-toolbar/benchmarks-wallets-toolbar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<form [formGroup]="formGroup" class="h-xl fx-row-vert-cent pl-12 pr-12 secondary shrink-0">
55
<button (click)="send()"
66
class="live-button active"
7-
[class.disabled]="streamSending">Send
7+
[class.disabled]="streamSending">Send Payment
88
</button>
99
<input type="number" class="mina-input border-rad-4 mr-8 ml-8 text-center" formControlName="batch">
1010
<div>transactions with</div>

frontend/src/app/features/benchmarks/wallets/benchmarks-wallets-toolbar/benchmarks-wallets-toolbar.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@import 'openmina';
22

3+
.live-button {
4+
width: 110px;
5+
}
6+
37
.mina-input[formcontrolname='batch'] {
48
width: 55px;
59
}

0 commit comments

Comments
 (0)