zkcloudworker 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { zkCloudWorker, Cloud } from "../cloud/cloud";
2
2
  import { blockchain } from "../networks";
3
- export type ApiCommand = "recursiveProof" | "execute" | "sendTransaction" | "jobResult" | "deploy" | "queryBilling";
3
+ export type ApiCommand = "recursiveProof" | "execute" | "sendTransaction" | "jobResult" | "deploy" | "getBalance" | "queryBilling";
4
4
  /**
5
5
  * API class for interacting with the zkCloudWorker
6
6
  * @property jwt The jwt token for authentication, get it at https://t.me/minanft_bot?start=auth
@@ -128,7 +128,9 @@ export declare class zkCloudWorkerClient {
128
128
  * if the job is not found, the result will be undefined and error will be set
129
129
  */
130
130
  deploy(data: {
131
- packageName: string;
131
+ repo: string;
132
+ developer: string;
133
+ packageManager: string;
132
134
  }): Promise<{
133
135
  success: boolean;
134
136
  error?: string;
@@ -144,6 +146,16 @@ export declare class zkCloudWorkerClient {
144
146
  error?: string;
145
147
  result?: any;
146
148
  }>;
149
+ /**
150
+ * Gets the remaining balance
151
+ * @returns { success: boolean, error?: string, result?: any }
152
+ * where result is the billing report
153
+ */
154
+ getBalance(): Promise<{
155
+ success: boolean;
156
+ error?: string;
157
+ result?: any;
158
+ }>;
147
159
  /**
148
160
  * Waits for the job to finish
149
161
  * @param data the data for the waitForJobResult call
@@ -23,7 +23,7 @@ class zkCloudWorkerClient {
23
23
  const { jwt, zkcloudworker, chain, webhook } = params;
24
24
  this.jwt = jwt;
25
25
  this.endpoint = ZKCLOUDWORKER_API;
26
- this.chain = chain ?? "berkeley";
26
+ this.chain = chain ?? "devnet";
27
27
  this.webhook = webhook;
28
28
  if (jwt === "local") {
29
29
  if (zkcloudworker === undefined)
@@ -152,7 +152,12 @@ class zkCloudWorkerClient {
152
152
  */
153
153
  async deploy(data) {
154
154
  // TODO: encrypt env.json
155
- const result = await this.apiHub("deploy", data);
155
+ const { repo, developer, packageManager } = data;
156
+ const result = await this.apiHub("deploy", {
157
+ developer,
158
+ repo,
159
+ args: packageManager,
160
+ });
156
161
  if (result.data === "error")
157
162
  return {
158
163
  success: false,
@@ -185,6 +190,26 @@ class zkCloudWorkerClient {
185
190
  result: result.data,
186
191
  };
187
192
  }
193
+ /**
194
+ * Gets the remaining balance
195
+ * @returns { success: boolean, error?: string, result?: any }
196
+ * where result is the billing report
197
+ */
198
+ async getBalance() {
199
+ const result = await this.apiHub("getBalance", {});
200
+ if (this.isError(result.data))
201
+ return {
202
+ success: false,
203
+ error: result.error,
204
+ result: result.data,
205
+ };
206
+ else
207
+ return {
208
+ success: result.success,
209
+ error: result.error,
210
+ result: result.data,
211
+ };
212
+ }
188
213
  /**
189
214
  * Waits for the job to finish
190
215
  * @param data the data for the waitForJobResult call
@@ -65,6 +65,7 @@ export declare abstract class Cloud {
65
65
  }): Promise<string>;
66
66
  abstract addTask(data: {
67
67
  task: string;
68
+ startTime?: number;
68
69
  userId?: string;
69
70
  args?: string;
70
71
  metadata?: string;
@@ -12,6 +12,9 @@ export interface JobData {
12
12
  metadata?: string;
13
13
  chain: blockchain;
14
14
  webhook?: string;
15
+ cloudhook?: string;
16
+ cloudIteration?: number;
17
+ previousJob?: JobData;
15
18
  filename?: string;
16
19
  txNumber: number;
17
20
  timeCreated: number;
@@ -58,6 +58,7 @@ export declare class LocalCloud extends Cloud {
58
58
  jobResult(jobId: string): Promise<JobData | undefined>;
59
59
  addTask(data: {
60
60
  task: string;
61
+ startTime?: number;
61
62
  userId?: string;
62
63
  args?: string;
63
64
  metadata?: string;
@@ -196,6 +196,8 @@ class LocalCloud extends cloud_1.Cloud {
196
196
  const data = LocalStorage.tasks[taskId];
197
197
  const jobId = LocalCloud.generateId();
198
198
  const timeCreated = Date.now();
199
+ if (data.startTime !== undefined && data.startTime < timeCreated)
200
+ continue;
199
201
  const job = {
200
202
  id: "local",
201
203
  jobId: jobId,
@@ -2,6 +2,7 @@ import { blockchain } from "../networks";
2
2
  export interface TaskData {
3
3
  id: string;
4
4
  taskId: string;
5
+ startTime?: number;
5
6
  timeCreated: number;
6
7
  developer: string;
7
8
  repo: string;
@@ -10,5 +11,4 @@ export interface TaskData {
10
11
  args?: string;
11
12
  metadata?: string;
12
13
  chain: blockchain;
13
- webhook?: string;
14
14
  }
@@ -1,4 +1,4 @@
1
- export { initBlockchain, Memory, makeString, sleep, accountBalance, accountBalanceMina, formatTime, MinaNetworkInstance, currentNetwork, getNetworkIdHash, getDeployer, };
1
+ export { initBlockchain, Memory, makeString, sleep, accountBalance, accountBalanceMina, formatTime, MinaNetworkInstance, currentNetwork, getNetworkIdHash, getCurrentNetwork, getDeployer, };
2
2
  import { PublicKey, PrivateKey, UInt64, Field } from "o1js";
3
3
  import { blockchain, MinaNetwork } from "./networks";
4
4
  interface MinaNetworkInstance {
@@ -11,8 +11,9 @@ interface MinaNetworkInstance {
11
11
  }
12
12
  declare let currentNetwork: MinaNetworkInstance | undefined;
13
13
  declare function getNetworkIdHash(): Field;
14
+ declare function getCurrentNetwork(): MinaNetworkInstance;
14
15
  declare function getDeployer(): PrivateKey | undefined;
15
- declare function initBlockchain(instance: blockchain, deployersNumber?: number): MinaNetworkInstance;
16
+ declare function initBlockchain(instance: blockchain, deployersNumber?: number): Promise<MinaNetworkInstance>;
16
17
  declare function accountBalance(address: PublicKey): Promise<UInt64>;
17
18
  declare function accountBalanceMina(address: PublicKey): Promise<number>;
18
19
  declare function sleep(ms: number): Promise<unknown>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDeployer = 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.formatTime = exports.accountBalanceMina = exports.accountBalance = exports.sleep = exports.makeString = exports.Memory = exports.initBlockchain = void 0;
4
4
  const o1js_1 = require("o1js");
5
5
  const networks_1 = require("./networks");
6
6
  let currentNetwork = undefined;
@@ -12,6 +12,13 @@ function getNetworkIdHash() {
12
12
  return currentNetwork.networkIdHash;
13
13
  }
14
14
  exports.getNetworkIdHash = getNetworkIdHash;
15
+ function getCurrentNetwork() {
16
+ if (currentNetwork === undefined) {
17
+ throw new Error("Network is not initialized");
18
+ }
19
+ return currentNetwork;
20
+ }
21
+ exports.getCurrentNetwork = getCurrentNetwork;
15
22
  function getDeployer() {
16
23
  if (currentNetwork === undefined) {
17
24
  throw new Error("Network is not initialized");
@@ -19,50 +26,21 @@ function getDeployer() {
19
26
  return currentNetwork.keys[0]?.privateKey;
20
27
  }
21
28
  exports.getDeployer = getDeployer;
22
- /*function getNetworkIdHash(params: {
23
- chainId?: blockchain;
24
- verbose?: boolean;
25
- }): Field {
26
- const { chainId, verbose } = params;
27
- if (chainId !== undefined) {
28
- if (verbose) console.log(`Chain ID: ${chainId}`);
29
- return CircuitString.fromString(chainId).hash();
30
- }
31
- const networkId = Mina.getNetworkId();
32
- if (verbose) console.log(`Network ID: ${networkId}`);
33
- if (networkId === "testnet")
34
- throw new Error(
35
- "Network ID is not set, please call initBlockchain() first"
36
- );
37
-
38
- if (networkId === "mainnet")
39
- return CircuitString.fromString("mainnet").hash();
40
- else {
41
- if (
42
- networkId.custom === undefined ||
43
- typeof networkId.custom !== "string"
44
- ) {
45
- throw new Error(
46
- "Network ID is not set, please call initBlockchain() first"
47
- );
48
- }
49
- return CircuitString.fromString(networkId.custom).hash();
50
- }
51
- }
52
- */
53
- function initBlockchain(instance, deployersNumber = 0) {
29
+ async function initBlockchain(instance, deployersNumber = 0) {
54
30
  if (instance === "mainnet") {
55
31
  throw new Error("Mainnet is not supported yet by zkApps");
56
32
  }
33
+ const networkIdHash = o1js_1.Poseidon.hash(o1js_1.Encoding.stringToFields(instance));
34
+ // await used for compatibility with future versions of o1js
57
35
  if (instance === "local") {
58
- const local = o1js_1.Mina.LocalBlockchain({
36
+ const local = await o1js_1.Mina.LocalBlockchain({
59
37
  proofsEnabled: true,
60
38
  });
61
- o1js_1.Mina.setActiveInstance(local);
39
+ await o1js_1.Mina.setActiveInstance(local);
62
40
  exports.currentNetwork = currentNetwork = {
63
41
  keys: local.testAccounts,
64
42
  network: networks_1.Local,
65
- networkIdHash: o1js_1.CircuitString.fromString("local").hash(),
43
+ networkIdHash,
66
44
  };
67
45
  return currentNetwork;
68
46
  }
@@ -75,7 +53,7 @@ function initBlockchain(instance, deployersNumber = 0) {
75
53
  archive: network.archive,
76
54
  lightnetAccountManager: network.accountManager,
77
55
  });
78
- o1js_1.Mina.setActiveInstance(networkInstance);
56
+ await o1js_1.Mina.setActiveInstance(networkInstance);
79
57
  const keys = [];
80
58
  if (deployersNumber > 0) {
81
59
  if (instance === "lighnet") {
@@ -97,7 +75,7 @@ function initBlockchain(instance, deployersNumber = 0) {
97
75
  exports.currentNetwork = currentNetwork = {
98
76
  keys,
99
77
  network,
100
- networkIdHash: o1js_1.CircuitString.fromString(instance).hash(),
78
+ networkIdHash,
101
79
  };
102
80
  return currentNetwork;
103
81
  }
@@ -1,5 +1,5 @@
1
- export { blockchain, MinaNetwork, networks, Mainnet, Berkeley, Devnet, Zeko, TestWorld2, Lightnet, Local, };
2
- type blockchain = "local" | "berkeley" | "devnet" | "lighnet" | "mainnet" | "testworld2" | "zeko";
1
+ export { blockchain, MinaNetwork, networks, Mainnet, Devnet, Zeko, Lightnet, Local, };
2
+ type blockchain = "local" | "devnet" | "lighnet" | "mainnet" | "zeko" | "mainnet";
3
3
  interface MinaNetwork {
4
4
  mina: string[];
5
5
  archive: string[];
@@ -11,9 +11,7 @@ interface MinaNetwork {
11
11
  }
12
12
  declare const Mainnet: MinaNetwork;
13
13
  declare const Local: MinaNetwork;
14
- declare const Berkeley: MinaNetwork;
15
14
  declare const Devnet: MinaNetwork;
16
15
  declare const Zeko: MinaNetwork;
17
- declare const TestWorld2: MinaNetwork;
18
16
  declare const Lightnet: MinaNetwork;
19
17
  declare const networks: MinaNetwork[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Local = exports.Lightnet = exports.TestWorld2 = exports.Zeko = exports.Devnet = exports.Berkeley = exports.Mainnet = exports.networks = void 0;
3
+ exports.Local = exports.Lightnet = exports.Zeko = exports.Devnet = exports.Mainnet = exports.networks = void 0;
4
4
  const Mainnet = {
5
5
  mina: [],
6
6
  archive: [],
@@ -13,21 +13,6 @@ const Local = {
13
13
  chainId: "local",
14
14
  };
15
15
  exports.Local = Local;
16
- const Berkeley = {
17
- mina: [
18
- "https://api.minascan.io/node/berkeley/v1/graphql",
19
- "https://proxy.berkeley.minaexplorer.com/graphql",
20
- ],
21
- archive: [
22
- "https://api.minascan.io/archive/berkeley/v1/graphql",
23
- "https://archive.berkeley.minaexplorer.com",
24
- ],
25
- explorerAccountUrl: "https://minascan.io/berkeley/account/",
26
- explorerTransactionUrl: "https://minascan.io/berkeley/tx/",
27
- chainId: "berkeley",
28
- name: "Berkeley",
29
- };
30
- exports.Berkeley = Berkeley;
31
16
  const Devnet = {
32
17
  mina: [
33
18
  "https://api.minascan.io/node/devnet/v1/graphql",
@@ -49,15 +34,6 @@ const Zeko = {
49
34
  chainId: "zeko",
50
35
  };
51
36
  exports.Zeko = Zeko;
52
- const TestWorld2 = {
53
- mina: ["https://api.minascan.io/node/testworld/v1/graphql"],
54
- archive: ["https://archive.testworld.minaexplorer.com"],
55
- explorerAccountUrl: "https://minascan.io/testworld/account/",
56
- explorerTransactionUrl: "https://minascan.io/testworld/tx/",
57
- chainId: "testworld2",
58
- name: "TestWorld2",
59
- };
60
- exports.TestWorld2 = TestWorld2;
61
37
  const Lightnet = {
62
38
  mina: ["http://localhost:8080/graphql"],
63
39
  archive: ["http://localhost:8282"],
@@ -66,13 +42,34 @@ const Lightnet = {
66
42
  name: "Lightnet",
67
43
  };
68
44
  exports.Lightnet = Lightnet;
69
- const networks = [
70
- Mainnet,
71
- Local,
72
- Berkeley,
73
- Devnet,
74
- Zeko,
75
- TestWorld2,
76
- Lightnet,
77
- ];
45
+ const networks = [Mainnet, Local, Devnet, Zeko, Lightnet];
78
46
  exports.networks = networks;
47
+ /*
48
+
49
+ // not supported by o1js 0.18.0
50
+
51
+ const Berkeley: MinaNetwork = {
52
+ mina: [
53
+ "https://api.minascan.io/node/berkeley/v1/graphql",
54
+ "https://proxy.berkeley.minaexplorer.com/graphql",
55
+ ],
56
+ archive: [
57
+ "https://api.minascan.io/archive/berkeley/v1/graphql",
58
+ "https://archive.berkeley.minaexplorer.com",
59
+ ],
60
+ explorerAccountUrl: "https://minascan.io/berkeley/account/",
61
+ explorerTransactionUrl: "https://minascan.io/berkeley/tx/",
62
+ chainId: "berkeley",
63
+ name: "Berkeley",
64
+ };
65
+
66
+ const TestWorld2: MinaNetwork = {
67
+ mina: ["https://api.minascan.io/node/testworld/v1/graphql"],
68
+ archive: ["https://archive.testworld.minaexplorer.com"],
69
+ explorerAccountUrl: "https://minascan.io/testworld/account/",
70
+ explorerTransactionUrl: "https://minascan.io/testworld/tx/",
71
+ chainId: "testworld2",
72
+ name: "TestWorld2",
73
+ };
74
+
75
+ */