zkcloudworker 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.zkCloudWorkerClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
- const mina_1 = require("../utils/mina");
9
+ const utils_1 = require("../utils/utils");
10
10
  const local_1 = require("../cloud/local");
11
11
  const config_1 = __importDefault(require("../config"));
12
12
  const { ZKCLOUDWORKER_AUTH, ZKCLOUDWORKER_API } = config_1.default;
@@ -312,7 +312,7 @@ class zkCloudWorkerClient {
312
312
  result: undefined,
313
313
  };
314
314
  }
315
- await (0, mina_1.sleep)(errorDelay * errors);
315
+ await (0, utils_1.sleep)(errorDelay * errors);
316
316
  }
317
317
  else {
318
318
  if (this.isError(result.data))
@@ -335,7 +335,7 @@ class zkCloudWorkerClient {
335
335
  result: result.data,
336
336
  };
337
337
  }
338
- await (0, mina_1.sleep)(interval);
338
+ await (0, utils_1.sleep)(interval);
339
339
  }
340
340
  attempts++;
341
341
  }
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- import type { Cache } from "o1js";
3
2
  import { blockchain } from "../networks";
4
3
  import { JobData } from "./job";
5
4
  export interface DeployedSmartContract {
@@ -25,7 +24,7 @@ export declare abstract class Cloud {
25
24
  readonly jobId: string;
26
25
  readonly stepId: string;
27
26
  readonly taskId: string;
28
- readonly cache: Cache;
27
+ readonly cache: string;
29
28
  readonly developer: string;
30
29
  readonly repo: string;
31
30
  readonly task?: string;
@@ -39,7 +38,7 @@ export declare abstract class Cloud {
39
38
  jobId: string;
40
39
  stepId: string;
41
40
  taskId: string;
42
- cache: Cache;
41
+ cache: string;
43
42
  developer: string;
44
43
  repo: string;
45
44
  task?: string;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- import { Cache } from "o1js";
3
2
  import { Cloud, zkCloudWorker } from "./cloud";
4
3
  import { JobData } from "./job";
5
4
  import { TaskData } from "./task";
@@ -11,7 +10,7 @@ export declare class LocalCloud extends Cloud {
11
10
  constructor(params: {
12
11
  job: JobData;
13
12
  chain: blockchain;
14
- cache?: Cache;
13
+ cache?: string;
15
14
  stepId?: string;
16
15
  localWorker: (cloud: Cloud) => Promise<zkCloudWorker>;
17
16
  });
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LocalStorage = exports.LocalCloud = void 0;
4
- const o1js_1 = require("o1js");
5
4
  const cloud_1 = require("./cloud");
6
- const mina_1 = require("../utils/mina");
5
+ const utils_1 = require("../utils/utils");
7
6
  const files_1 = require("./files");
8
7
  class LocalCloud extends cloud_1.Cloud {
9
8
  constructor(params) {
@@ -14,7 +13,7 @@ class LocalCloud extends cloud_1.Cloud {
14
13
  jobId: jobId,
15
14
  stepId: stepId ?? "stepId",
16
15
  taskId: taskId ?? "taskId",
17
- cache: cache ?? o1js_1.Cache.FileSystem("./cache"),
16
+ cache: cache ?? "./cache",
18
17
  developer: developer,
19
18
  repo: repo,
20
19
  task: task,
@@ -27,17 +26,18 @@ class LocalCloud extends cloud_1.Cloud {
27
26
  this.localWorker = localWorker;
28
27
  }
29
28
  async getDeployer() {
30
- const deployer = process.env.DEPLOYER;
29
+ const privateKey = process.env.DEPLOYER_PRIVATE_KEY;
30
+ const publicKey = process.env.DEPLOYER_PUBLIC_KEY;
31
31
  try {
32
- return deployer === undefined
32
+ return privateKey === undefined || publicKey === undefined
33
33
  ? undefined
34
34
  : {
35
- privateKey: deployer,
36
- publicKey: o1js_1.PrivateKey.fromBase58(deployer).toPublicKey().toBase58(),
35
+ privateKey,
36
+ publicKey,
37
37
  };
38
38
  }
39
39
  catch (error) {
40
- console.error(`getDeployer: process.env.DEPLOYER has wrong encoding, should be base58 private key ("EKE...")`, error);
40
+ console.error(`getDeployer: error getting deployer key pair: ${error}`, error);
41
41
  return undefined;
42
42
  }
43
43
  }
@@ -68,7 +68,7 @@ class LocalCloud extends cloud_1.Cloud {
68
68
  throw new Error("Method not implemented.");
69
69
  }
70
70
  static generateId() {
71
- return "local." + Date.now().toString() + "." + (0, mina_1.makeString)(32);
71
+ return "local." + Date.now().toString() + "." + (0, utils_1.makeString)(32);
72
72
  }
73
73
  static async addTransactions(transactions) {
74
74
  const timeReceived = Date.now();
@@ -4,10 +4,10 @@ export declare function fetchMinaAccount(params: {
4
4
  tokenId?: string | Field | undefined;
5
5
  force?: boolean;
6
6
  }): Promise<{
7
+ account: undefined;
8
+ } | {
7
9
  account: import("o1js/dist/node/bindings/mina-transaction/gen/transaction").Account;
8
10
  error: undefined;
9
- } | {
10
- account: undefined;
11
11
  }>;
12
12
  export declare function fetchMinaActions(publicKey: PublicKey, fromActionState: Field, endActionState?: Field): Promise<{
13
13
  actions: string[][];
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkMinaZkappTransaction = exports.fetchMinaActions = exports.fetchMinaAccount = void 0;
4
4
  const o1js_1 = require("o1js");
5
- const mina_1 = require("./mina");
5
+ const utils_1 = require("./utils");
6
6
  async function fetchMinaAccount(params) {
7
7
  const { publicKey, tokenId, force } = params;
8
8
  const timeout = 1000 * 60 * 2; // 2 minutes
@@ -34,7 +34,7 @@ async function fetchMinaAccount(params) {
34
34
  return result;
35
35
  }
36
36
  }
37
- await (0, mina_1.sleep)(1000 * 5);
37
+ await (0, utils_1.sleep)(1000 * 5);
38
38
  }
39
39
  if (force === true)
40
40
  throw new Error(`fetchMinaAccount timeout
@@ -65,7 +65,7 @@ async function fetchMinaActions(publicKey, fromActionState, endActionState) {
65
65
  catch (error) {
66
66
  console.log("Error in fetchMinaActions", error.toString().substring(0, 300));
67
67
  }
68
- await (0, mina_1.sleep)(1000 * 60 * 2);
68
+ await (0, utils_1.sleep)(1000 * 60 * 2);
69
69
  }
70
70
  console.log("Timeout in fetchMinaActions");
71
71
  return undefined;
@@ -4,3 +4,4 @@ export * from "./fields";
4
4
  export * from "./graphql";
5
5
  export * from "./fee";
6
6
  export * from "./mina";
7
+ export * from "./utils";
@@ -20,3 +20,4 @@ __exportStar(require("./fields"), exports);
20
20
  __exportStar(require("./graphql"), exports);
21
21
  __exportStar(require("./fee"), exports);
22
22
  __exportStar(require("./mina"), exports);
23
+ __exportStar(require("./utils"), exports);
@@ -1,4 +1,4 @@
1
- export { initBlockchain, Memory, makeString, sleep, accountBalance, accountBalanceMina, formatTime, MinaNetworkInstance, currentNetwork, getNetworkIdHash, getCurrentNetwork, getDeployer, };
1
+ export { initBlockchain, accountBalance, accountBalanceMina, MinaNetworkInstance, currentNetwork, getNetworkIdHash, getCurrentNetwork, getDeployer, };
2
2
  import { Mina, PublicKey, UInt64, Field } from "o1js";
3
3
  import { blockchain, MinaNetwork } from "../networks";
4
4
  interface MinaNetworkInstance {
@@ -13,11 +13,3 @@ declare function getDeployer(): Mina.TestPublicKey | undefined;
13
13
  declare function initBlockchain(instance: blockchain, deployersNumber?: number): Promise<MinaNetworkInstance>;
14
14
  declare function accountBalance(address: PublicKey): Promise<UInt64>;
15
15
  declare function accountBalanceMina(address: PublicKey): Promise<number>;
16
- declare function sleep(ms: number): Promise<unknown>;
17
- declare function makeString(length: number): string;
18
- declare function formatTime(ms: number): string;
19
- declare class Memory {
20
- static rss: number;
21
- constructor();
22
- static info(description?: string, fullInfo?: boolean): void;
23
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDeployer = exports.getCurrentNetwork = exports.getNetworkIdHash = exports.currentNetwork = exports.formatTime = exports.accountBalanceMina = exports.accountBalance = exports.sleep = exports.makeString = exports.Memory = exports.initBlockchain = void 0;
3
+ exports.getDeployer = exports.getCurrentNetwork = exports.getNetworkIdHash = exports.currentNetwork = exports.accountBalanceMina = exports.accountBalance = exports.initBlockchain = void 0;
4
4
  const o1js_1 = require("o1js");
5
5
  const networks_1 = require("../networks");
6
6
  let currentNetwork = undefined;
@@ -108,67 +108,3 @@ async function accountBalanceMina(address) {
108
108
  return Number((await accountBalance(address)).toBigInt()) / 1e9;
109
109
  }
110
110
  exports.accountBalanceMina = accountBalanceMina;
111
- function sleep(ms) {
112
- return new Promise((resolve) => setTimeout(resolve, ms));
113
- }
114
- exports.sleep = sleep;
115
- function makeString(length) {
116
- // eslint-disable-next-line @typescript-eslint/no-inferrable-types
117
- let outString = ``;
118
- // eslint-disable-next-line @typescript-eslint/no-inferrable-types
119
- const inOptions = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`;
120
- for (let i = 0; i < length; i++) {
121
- outString += inOptions.charAt(Math.floor(Math.random() * inOptions.length));
122
- }
123
- return outString;
124
- }
125
- exports.makeString = makeString;
126
- function formatTime(ms) {
127
- if (ms === undefined)
128
- return "";
129
- if (ms < 1000)
130
- return ms.toString() + " ms";
131
- if (ms < 60 * 1000)
132
- return parseInt((ms / 1000).toString()).toString() + " sec";
133
- if (ms < 60 * 60 * 1000) {
134
- const minutes = parseInt((ms / 1000 / 60).toString());
135
- const seconds = parseInt(((ms - minutes * 60 * 1000) / 1000).toString());
136
- return minutes.toString() + " min " + seconds.toString() + " sec";
137
- }
138
- else {
139
- const hours = parseInt((ms / 1000 / 60 / 60).toString());
140
- const minutes = parseInt(((ms - hours * 60 * 60 * 1000) / 1000 / 60).toString());
141
- return hours.toString() + " h " + minutes.toString() + " min";
142
- }
143
- }
144
- exports.formatTime = formatTime;
145
- class Memory {
146
- constructor() {
147
- Memory.rss = 0;
148
- }
149
- // eslint-disable-next-line @typescript-eslint/no-inferrable-types
150
- static info(description = ``, fullInfo = false) {
151
- const memoryData = process.memoryUsage();
152
- const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024)} MB`;
153
- const oldRSS = Memory.rss;
154
- Memory.rss = Math.round(memoryData.rss / 1024 / 1024);
155
- const memoryUsage = fullInfo
156
- ? {
157
- step: `${description}:`,
158
- rssDelta: `${(oldRSS === 0
159
- ? 0
160
- : Memory.rss - oldRSS).toString()} MB -> Resident Set Size memory change`,
161
- rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated`,
162
- heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
163
- heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
164
- external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
165
- }
166
- : `RSS memory ${description}: ${formatMemoryUsage(memoryData.rss)}${oldRSS === 0
167
- ? ``
168
- : `, changed by ` + (Memory.rss - oldRSS).toString() + ` MB`}`;
169
- console.log(memoryUsage);
170
- }
171
- }
172
- exports.Memory = Memory;
173
- // eslint-disable-next-line @typescript-eslint/no-inferrable-types
174
- Memory.rss = 0;
@@ -0,0 +1,8 @@
1
+ export declare function sleep(ms: number): Promise<unknown>;
2
+ export declare function makeString(length: number): string;
3
+ export declare function formatTime(ms: number): string;
4
+ export declare class Memory {
5
+ static rss: number;
6
+ constructor();
7
+ static info(description?: string, fullInfo?: boolean): void;
8
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Memory = exports.formatTime = exports.makeString = exports.sleep = void 0;
4
+ function sleep(ms) {
5
+ return new Promise((resolve) => setTimeout(resolve, ms));
6
+ }
7
+ exports.sleep = sleep;
8
+ function makeString(length) {
9
+ // eslint-disable-next-line @typescript-eslint/no-inferrable-types
10
+ let outString = ``;
11
+ // eslint-disable-next-line @typescript-eslint/no-inferrable-types
12
+ const inOptions = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`;
13
+ for (let i = 0; i < length; i++) {
14
+ outString += inOptions.charAt(Math.floor(Math.random() * inOptions.length));
15
+ }
16
+ return outString;
17
+ }
18
+ exports.makeString = makeString;
19
+ function formatTime(ms) {
20
+ if (ms === undefined)
21
+ return "";
22
+ if (ms < 1000)
23
+ return ms.toString() + " ms";
24
+ if (ms < 60 * 1000)
25
+ return parseInt((ms / 1000).toString()).toString() + " sec";
26
+ if (ms < 60 * 60 * 1000) {
27
+ const minutes = parseInt((ms / 1000 / 60).toString());
28
+ const seconds = parseInt(((ms - minutes * 60 * 1000) / 1000).toString());
29
+ return minutes.toString() + " min " + seconds.toString() + " sec";
30
+ }
31
+ else {
32
+ const hours = parseInt((ms / 1000 / 60 / 60).toString());
33
+ const minutes = parseInt(((ms - hours * 60 * 60 * 1000) / 1000 / 60).toString());
34
+ return hours.toString() + " h " + minutes.toString() + " min";
35
+ }
36
+ }
37
+ exports.formatTime = formatTime;
38
+ class Memory {
39
+ constructor() {
40
+ Memory.rss = 0;
41
+ }
42
+ // eslint-disable-next-line @typescript-eslint/no-inferrable-types
43
+ static info(description = ``, fullInfo = false) {
44
+ const memoryData = process.memoryUsage();
45
+ const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024)} MB`;
46
+ const oldRSS = Memory.rss;
47
+ Memory.rss = Math.round(memoryData.rss / 1024 / 1024);
48
+ const memoryUsage = fullInfo
49
+ ? {
50
+ step: `${description}:`,
51
+ rssDelta: `${(oldRSS === 0
52
+ ? 0
53
+ : Memory.rss - oldRSS).toString()} MB -> Resident Set Size memory change`,
54
+ rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated`,
55
+ heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
56
+ heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
57
+ external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
58
+ }
59
+ : `RSS memory ${description}: ${formatMemoryUsage(memoryData.rss)}${oldRSS === 0
60
+ ? ``
61
+ : `, changed by ` + (Memory.rss - oldRSS).toString() + ` MB`}`;
62
+ console.log(memoryUsage);
63
+ }
64
+ }
65
+ exports.Memory = Memory;
66
+ // eslint-disable-next-line @typescript-eslint/no-inferrable-types
67
+ Memory.rss = 0;