@@ -2,17 +2,19 @@ import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProvide
2
2
3
3
await initThreadPool ( ) ;
4
4
5
- const hello_hello_program =
6
- "program hello_hello.aleo;\n" +
7
- "\n" +
8
- "function hello:\n" +
9
- " input r0 as u32.public;\n" +
10
- " input r1 as u32.private;\n" +
11
- " add r0 r1 into r2;\n" +
12
- " output r2 as u32.private;\n" ;
5
+ const programName = "hello_hello.aleo"
13
6
14
- async function localProgramExecution ( ) {
15
- const programManager = new ProgramManager ( undefined , undefined , undefined ) ;
7
+ const hello_hello_program = `
8
+ program ${ programName } ;
9
+
10
+ function hello:
11
+ input r0 as u32.public;
12
+ input r1 as u32.private;
13
+ add r0 r1 into r2;
14
+ output r2 as u32.private;`
15
+
16
+ async function localProgramExecution ( program , programName , aleoFunction , inputs ) {
17
+ const programManager = new ProgramManager ( ) ;
16
18
17
19
// Create a temporary account for the execution of the program
18
20
const account = new Account ( ) ;
@@ -24,26 +26,26 @@ async function localProgramExecution() {
24
26
programManager . setKeyProvider ( keyProvider ) ;
25
27
26
28
// Pre-synthesize the program keys and then cache them in memory using key provider
27
- const keyPair = await programManager . synthesizeKeys ( hello_hello_program , "hello" , [ "1u32" , "1u32" ] ) ;
29
+ const keyPair = await programManager . synthesizeKeys ( hello_hello_program , aleoFunction , inputs ) ;
28
30
29
31
if ( keyPair instanceof Error ) {
30
32
throw new Error ( `Failed to synthesize keys: ${ keyPair . message } ` ) ;
31
33
} else {
32
- programManager . keyProvider . cacheKeys ( "hello_hello.aleo:hello" , keyPair ) ;
34
+ programManager . keyProvider . cacheKeys ( ` ${ programName } : ${ aleoFunction } ` , keyPair ) ;
33
35
}
34
36
35
- programManager . keyProvider . cacheKeys ( "hello_hello.aleo:hello" , keyPair ) ;
37
+ programManager . keyProvider . cacheKeys ( ` ${ programName } : ${ aleoFunction } ` , keyPair ) ;
36
38
37
39
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
38
40
// that was used to cache the keys in the previous step.
39
- const keyProviderParams = new AleoKeyProviderParams ( { cacheKey : "hello_hello.aleo:hello" } ) ;
41
+ const keyProviderParams = new AleoKeyProviderParams ( { cacheKey : ` ${ programName } : ${ aleoFunction } ` } ) ;
40
42
41
43
// Execute once using the key provider params defined above. This will use the cached proving keys and make
42
44
// execution significantly faster.
43
45
let executionResponse = await programManager . run (
44
- hello_hello_program ,
45
- "hello" ,
46
- [ "5u32" , "5u32" ] ,
46
+ program ,
47
+ aleoFunction ,
48
+ inputs ,
47
49
true ,
48
50
undefined ,
49
51
keyProviderParams ,
@@ -60,5 +62,5 @@ async function localProgramExecution() {
60
62
61
63
const start = Date . now ( ) ;
62
64
console . log ( "Starting execute!" ) ;
63
- await localProgramExecution ( ) ;
65
+ await localProgramExecution ( hello_hello_program , programName , "hello" , [ "5u32" , "5u32" ] ) ;
64
66
console . log ( "Execute finished!" , Date . now ( ) - start ) ;
0 commit comments