Skip to content

Commit c079633

Browse files
author
Brent C
authored
Merge branch 'testnet3' into r
2 parents 51ab01f + a5cc47b commit c079633

File tree

5 files changed

+78
-74
lines changed

5 files changed

+78
-74
lines changed

create-aleo-app/template-extension/src/worker.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import {Account, initThreadPool, PrivateKey, ProgramManager,} from "@aleohq/sdk"
22

33
await initThreadPool();
44

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 hello_hello_program =`
6+
program hello_hello.aleo;
7+
8+
function hello:
9+
input r0 as u32.public;
10+
input r1 as u32.private;
11+
add r0 r1 into r2;
12+
output r2 as u32.private;`
1313

1414
async function localProgramExecution(program, aleoFunction, inputs) {
1515
const programManager = new ProgramManager();
@@ -19,16 +19,16 @@ async function localProgramExecution(program, aleoFunction, inputs) {
1919
programManager.setAccount(account);
2020

2121
const executionResponse = await programManager.run(
22-
hello_hello_program,
23-
"hello",
24-
["5u32", "5u32"],
22+
program,
23+
aleoFunction,
24+
inputs,
2525
false,
2626
);
2727
return executionResponse.getOutputs();
2828
}
2929

3030
const start = Date.now();
3131
console.log("Starting execute!");
32-
const result = await localProgramExecution();
32+
const result = await localProgramExecution(hello_hello_program, "hello", ["5u32", "5u32"]);
3333
console.log(result);
3434
console.log("Execute finished!", Date.now() - start);

create-aleo-app/template-nextjs-ts/src/app/worker.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ import {
77

88
await initThreadPool();
99

10-
const hello_hello_program =
11-
"program hello_hello.aleo;\n" +
12-
"\n" +
13-
"function hello:\n" +
14-
" input r0 as u32.public;\n" +
15-
" input r1 as u32.private;\n" +
16-
" add r0 r1 into r2;\n" +
17-
" output r2 as u32.private;\n";
18-
19-
async function localProgramExecution() {
20-
const programManager = new ProgramManager(undefined, undefined, undefined);
10+
const hello_hello_program =`
11+
program hello_hello.aleo;
12+
13+
function hello:
14+
input r0 as u32.public;
15+
input r1 as u32.private;
16+
add r0 r1 into r2;
17+
output r2 as u32.private;`
18+
19+
async function localProgramExecution(program: string, aleoFunction: string, inputs: string[]) {
20+
const programManager = new ProgramManager();
2121

2222
// Create a temporary account for the execution of the program
2323
const account = new Account();
2424
programManager.setAccount(account);
2525

2626
const executionResponse = await programManager.run(
27-
hello_hello_program,
28-
"hello",
29-
["5u32", "5u32"],
27+
program,
28+
aleoFunction,
29+
inputs,
3030
false,
3131
);
3232
return executionResponse.getOutputs();
@@ -38,7 +38,7 @@ function getPrivateKey() {
3838

3939
onmessage = async function (e) {
4040
if (e.data === "execute") {
41-
const result = await localProgramExecution();
41+
const result = await localProgramExecution(hello_hello_program, "hello", ["5u32", "5u32"]);
4242
postMessage({type: "execute", result: result});
4343
} else if (e.data === "key") {
4444
const result = getPrivateKey();

create-aleo-app/template-node-ts/src/index.ts

+20-18
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProvide
22

33
await initThreadPool();
44

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"
136

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();
1618

1719
// Create a temporary account for the execution of the program
1820
const account = new Account();
@@ -24,26 +26,26 @@ async function localProgramExecution() {
2426
programManager.setKeyProvider(keyProvider);
2527

2628
// 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);
2830

2931
if (keyPair instanceof Error) {
3032
throw new Error(`Failed to synthesize keys: ${keyPair.message}`);
3133
} else {
32-
programManager.keyProvider.cacheKeys("hello_hello.aleo:hello", keyPair);
34+
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
3335
}
3436

35-
programManager.keyProvider.cacheKeys("hello_hello.aleo:hello", keyPair);
37+
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
3638

3739
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
3840
// 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}`});
4042

4143
// Execute once using the key provider params defined above. This will use the cached proving keys and make
4244
// execution significantly faster.
4345
let executionResponse = await programManager.run(
44-
hello_hello_program,
45-
"hello",
46-
["5u32", "5u32"],
46+
program,
47+
aleoFunction,
48+
inputs,
4749
true,
4850
undefined,
4951
keyProviderParams,
@@ -60,5 +62,5 @@ async function localProgramExecution() {
6062

6163
const start = Date.now();
6264
console.log("Starting execute!");
63-
await localProgramExecution();
65+
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
6466
console.log("Execute finished!", Date.now() - start);

create-aleo-app/template-node/index.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProvide
22

33
await initThreadPool();
44

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";
13-
14-
async function localProgramExecution(program, aleoFunction, inputs) {
5+
const programName = "hello_hello.aleo"
6+
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) {
1517
const programManager = new ProgramManager();
1618

1719
// Create a temporary account for the execution of the program
@@ -24,19 +26,19 @@ async function localProgramExecution(program, aleoFunction, inputs) {
2426
programManager.setKeyProvider(keyProvider);
2527

2628
// 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"]);
28-
programManager.keyProvider.cacheKeys("hello_hello.aleo:hello", keyPair);
29+
const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
30+
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
2931

3032
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
3133
// that was used to cache the keys in the previous step.
32-
const keyProviderParams = new AleoKeyProviderParams({cacheKey: "hello_hello.aleo:hello"});
34+
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
3335

3436
// Execute once using the key provider params defined above. This will use the cached proving keys and make
3537
// execution significantly faster.
3638
let executionResponse = await programManager.run(
37-
hello_hello_program,
38-
"hello",
39-
["5u32", "5u32"],
39+
program,
40+
aleoFunction,
41+
inputs,
4042
true,
4143
undefined,
4244
keyProviderParams,
@@ -53,5 +55,5 @@ async function localProgramExecution(program, aleoFunction, inputs) {
5355

5456
const start = Date.now();
5557
console.log("Starting execute!");
56-
await localProgramExecution();
58+
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
5759
console.log("Execute finished!", Date.now() - start);

create-aleo-app/template-vanilla/worker.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import {
77

88
await initThreadPool();
99

10-
const hello_hello_program =
11-
"program hello_hello.aleo;\n" +
12-
"\n" +
13-
"function hello:\n" +
14-
" input r0 as u32.public;\n" +
15-
" input r1 as u32.private;\n" +
16-
" add r0 r1 into r2;\n" +
17-
" output r2 as u32.private;\n";
10+
const hello_hello_program =`
11+
program hello_hello.aleo;
12+
13+
function hello:
14+
input r0 as u32.public;
15+
input r1 as u32.private;
16+
add r0 r1 into r2;
17+
output r2 as u32.private;`
1818

1919
async function localProgramExecution(program, aleoFunction, inputs) {
2020
const programManager = new ProgramManager();
@@ -24,9 +24,9 @@ async function localProgramExecution(program, aleoFunction, inputs) {
2424
programManager.setAccount(account);
2525

2626
const executionResponse = await programManager.run(
27-
hello_hello_program,
28-
"hello",
29-
["5u32", "5u32"],
27+
program,
28+
aleoFunction,
29+
inputs,
3030
false,
3131
);
3232
return executionResponse.getOutputs();
@@ -38,7 +38,7 @@ function getPrivateKey() {
3838

3939
onmessage = async function (e) {
4040
if (e.data === "execute") {
41-
const result = await localProgramExecution();
41+
const result = await localProgramExecution(hello_hello_program, "hello", ["5u32", "5u32"]);
4242
postMessage(result);
4343
} else if (e.data === "key") {
4444
const result = getPrivateKey();

0 commit comments

Comments
 (0)