@@ -8,24 +8,26 @@ import { AppSelectors } from '@app/app.state';
88import { AppActions } from '@app/app.actions' ;
99import { Observable , timer } from 'rxjs' ;
1010import { 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 }
0 commit comments