@cartesi/cli 2.0.0-alpha.2 → 2.0.0-alpha.21

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.
Files changed (169) hide show
  1. package/dist/base.d.ts +28 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/base.js +109 -0
  4. package/dist/builder/directory.d.ts +2 -2
  5. package/dist/builder/directory.d.ts.map +1 -1
  6. package/dist/builder/directory.js +5 -3
  7. package/dist/builder/docker.d.ts +2 -2
  8. package/dist/builder/docker.d.ts.map +1 -1
  9. package/dist/builder/docker.js +39 -37
  10. package/dist/builder/empty.d.ts +1 -1
  11. package/dist/builder/empty.d.ts.map +1 -1
  12. package/dist/builder/empty.js +1 -1
  13. package/dist/builder/none.d.ts +1 -1
  14. package/dist/builder/none.d.ts.map +1 -1
  15. package/dist/builder/none.js +1 -1
  16. package/dist/builder/tar.d.ts +1 -1
  17. package/dist/builder/tar.d.ts.map +1 -1
  18. package/dist/builder/tar.js +1 -1
  19. package/dist/commands/address-book.d.ts +5 -8
  20. package/dist/commands/address-book.d.ts.map +1 -1
  21. package/dist/commands/address-book.js +18 -14
  22. package/dist/commands/build.d.ts +7 -11
  23. package/dist/commands/build.d.ts.map +1 -1
  24. package/dist/commands/build.js +82 -58
  25. package/dist/commands/clean.d.ts +2 -7
  26. package/dist/commands/clean.d.ts.map +1 -1
  27. package/dist/commands/clean.js +9 -10
  28. package/dist/commands/create.d.ts +6 -15
  29. package/dist/commands/create.d.ts.map +1 -1
  30. package/dist/commands/create.js +25 -54
  31. package/dist/commands/deploy/build.d.ts +2 -14
  32. package/dist/commands/deploy/build.d.ts.map +1 -1
  33. package/dist/commands/deploy/build.js +8 -61
  34. package/dist/commands/deploy.d.ts +3 -0
  35. package/dist/commands/deploy.d.ts.map +1 -0
  36. package/dist/commands/deploy.js +12 -0
  37. package/dist/commands/deposit/erc1155.d.ts +18 -0
  38. package/dist/commands/deposit/erc1155.d.ts.map +1 -0
  39. package/dist/commands/deposit/erc1155.js +254 -0
  40. package/dist/commands/deposit/erc20.d.ts +10 -0
  41. package/dist/commands/deposit/erc20.d.ts.map +1 -0
  42. package/dist/commands/deposit/erc20.js +125 -0
  43. package/dist/commands/deposit/erc721.d.ts +10 -0
  44. package/dist/commands/deposit/erc721.d.ts.map +1 -0
  45. package/dist/commands/deposit/erc721.js +143 -0
  46. package/dist/commands/deposit/ether.d.ts +10 -0
  47. package/dist/commands/deposit/ether.d.ts.map +1 -0
  48. package/dist/commands/deposit/ether.js +65 -0
  49. package/dist/commands/deposit.d.ts +9 -0
  50. package/dist/commands/deposit.d.ts.map +1 -0
  51. package/dist/commands/deposit.js +37 -0
  52. package/dist/commands/doctor.d.ts +2 -12
  53. package/dist/commands/doctor.d.ts.map +1 -1
  54. package/dist/commands/doctor.js +90 -91
  55. package/dist/commands/hash.d.ts +4 -9
  56. package/dist/commands/hash.d.ts.map +1 -1
  57. package/dist/commands/hash.js +14 -14
  58. package/dist/commands/logs.d.ts +9 -0
  59. package/dist/commands/logs.d.ts.map +1 -0
  60. package/dist/commands/logs.js +34 -0
  61. package/dist/commands/run.d.ts +14 -20
  62. package/dist/commands/run.d.ts.map +1 -1
  63. package/dist/commands/run.js +193 -182
  64. package/dist/commands/send.d.ts +10 -0
  65. package/dist/commands/send.d.ts.map +1 -0
  66. package/dist/commands/send.js +130 -0
  67. package/dist/commands/shell.d.ts +6 -14
  68. package/dist/commands/shell.d.ts.map +1 -1
  69. package/dist/commands/shell.js +34 -51
  70. package/dist/commands/status.d.ts +6 -0
  71. package/dist/commands/status.d.ts.map +1 -0
  72. package/dist/commands/status.js +50 -0
  73. package/dist/compose/default.env +36 -0
  74. package/dist/compose/docker-compose-anvil.yaml +39 -0
  75. package/dist/compose/docker-compose-bundler.yaml +71 -0
  76. package/dist/{node → compose}/docker-compose-database.yaml +4 -2
  77. package/dist/compose/docker-compose-explorer.yaml +96 -0
  78. package/dist/compose/docker-compose-node-cpus.yaml +6 -0
  79. package/dist/compose/docker-compose-node-memory.yaml +6 -0
  80. package/dist/compose/docker-compose-node.yaml +50 -0
  81. package/dist/compose/docker-compose-passkey-server.yaml +37 -0
  82. package/dist/compose/docker-compose-paymaster.yaml +40 -0
  83. package/dist/compose/docker-compose-proxy.yaml +24 -0
  84. package/dist/config.d.ts +30 -9
  85. package/dist/config.d.ts.map +1 -1
  86. package/dist/config.js +93 -53
  87. package/dist/contracts.d.ts +1695 -1636
  88. package/dist/contracts.d.ts.map +1 -1
  89. package/dist/contracts.js +632 -592
  90. package/dist/exec/cartesi-machine.d.ts +2 -2
  91. package/dist/exec/cartesi-machine.d.ts.map +1 -1
  92. package/dist/exec/cartesi-machine.js +3 -5
  93. package/dist/exec/genext2fs.d.ts +6 -3
  94. package/dist/exec/genext2fs.d.ts.map +1 -1
  95. package/dist/exec/genext2fs.js +5 -5
  96. package/dist/exec/index.d.ts +0 -1
  97. package/dist/exec/index.d.ts.map +1 -1
  98. package/dist/exec/index.js +0 -1
  99. package/dist/exec/mksquashfs.d.ts +2 -2
  100. package/dist/exec/mksquashfs.d.ts.map +1 -1
  101. package/dist/exec/mksquashfs.js +4 -2
  102. package/dist/exec/rollups.d.ts +105 -0
  103. package/dist/exec/rollups.d.ts.map +1 -0
  104. package/dist/exec/rollups.js +375 -0
  105. package/dist/exec/util.d.ts +1 -16
  106. package/dist/exec/util.d.ts.map +1 -1
  107. package/dist/exec/util.js +3 -50
  108. package/dist/index.d.ts +2 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +57 -1
  111. package/dist/machine.d.ts +8 -2
  112. package/dist/machine.d.ts.map +1 -1
  113. package/dist/machine.js +26 -16
  114. package/dist/prompts.d.ts +13 -2
  115. package/dist/prompts.d.ts.map +1 -1
  116. package/dist/prompts.js +60 -26
  117. package/dist/template.d.ts +3 -0
  118. package/dist/template.d.ts.map +1 -0
  119. package/dist/template.js +16 -0
  120. package/dist/wallet.d.ts +9222 -21
  121. package/dist/wallet.d.ts.map +1 -1
  122. package/dist/wallet.js +35 -198
  123. package/package.json +39 -57
  124. package/bin/dev.cmd +0 -3
  125. package/bin/dev.js +0 -25
  126. package/bin/run.cmd +0 -3
  127. package/bin/run.js +0 -8
  128. package/dist/baseCommand.d.ts +0 -22
  129. package/dist/baseCommand.d.ts.map +0 -1
  130. package/dist/baseCommand.js +0 -92
  131. package/dist/commands/deploy/index.d.ts +0 -12
  132. package/dist/commands/deploy/index.d.ts.map +0 -1
  133. package/dist/commands/deploy/index.js +0 -78
  134. package/dist/commands/send/erc20.d.ts +0 -14
  135. package/dist/commands/send/erc20.d.ts.map +0 -1
  136. package/dist/commands/send/erc20.js +0 -70
  137. package/dist/commands/send/erc721.d.ts +0 -14
  138. package/dist/commands/send/erc721.d.ts.map +0 -1
  139. package/dist/commands/send/erc721.js +0 -73
  140. package/dist/commands/send/ether.d.ts +0 -13
  141. package/dist/commands/send/ether.d.ts.map +0 -1
  142. package/dist/commands/send/ether.js +0 -32
  143. package/dist/commands/send/generic.d.ts +0 -15
  144. package/dist/commands/send/generic.d.ts.map +0 -1
  145. package/dist/commands/send/generic.js +0 -119
  146. package/dist/commands/send/index.d.ts +0 -28
  147. package/dist/commands/send/index.d.ts.map +0 -1
  148. package/dist/commands/send/index.js +0 -102
  149. package/dist/exec/crane.d.ts +0 -15
  150. package/dist/exec/crane.d.ts.map +0 -1
  151. package/dist/exec/crane.js +0 -17
  152. package/dist/flags.d.ts +0 -17
  153. package/dist/flags.d.ts.map +0 -1
  154. package/dist/flags.js +0 -28
  155. package/dist/node/DockerfileDeploy.txt +0 -4
  156. package/dist/node/default.env +0 -27
  157. package/dist/node/docker-compose-anvil.yaml +0 -50
  158. package/dist/node/docker-compose-bundler.yaml +0 -57
  159. package/dist/node/docker-compose-envfile.yaml +0 -4
  160. package/dist/node/docker-compose-explorer.yaml +0 -88
  161. package/dist/node/docker-compose-host.yaml +0 -30
  162. package/dist/node/docker-compose-paymaster.yaml +0 -33
  163. package/dist/node/docker-compose-prompt.yaml +0 -17
  164. package/dist/node/docker-compose-proxy.yaml +0 -48
  165. package/dist/node/docker-compose-snapshot-volume.yaml +0 -8
  166. package/dist/node/docker-compose-validator-cpus.yaml +0 -6
  167. package/dist/node/docker-compose-validator-memory.yaml +0 -6
  168. package/dist/node/docker-compose-validator.yaml +0 -59
  169. package/oclif.manifest.json +0 -876
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/commands/hash.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW,CAAC,OAAO,WAAW,CAAC;IACpE,MAAM,CAAC,OAAO,SAA0D;IAExE,MAAM,CAAC,WAAW,SAC2F;IAE7G,OAAc,cAAc,UAAQ;IAEvB,GAAG;;;CAgBnB"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/commands/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,iBAAiB;;MAsB7B,CAAC"}
@@ -1,22 +1,22 @@
1
+ import { Command } from "@commander-js/extra-typings";
1
2
  import chalk from "chalk";
2
- import { BaseCommand } from "../baseCommand.js";
3
- class HashCommand extends BaseCommand {
4
- async run() {
5
- const hash = this.getMachineHash();
3
+ import { getMachineHash } from "../base.js";
4
+ export const createHashCommand = () => {
5
+ return new Command("hash")
6
+ .description("Converts the binary generated by the build command to hexadecimal and prints out the result to console.")
7
+ .option("--json", "Format output as json.")
8
+ .action(async ({ json }, command) => {
9
+ const hash = getMachineHash();
6
10
  if (hash) {
7
- if (!this.jsonEnabled()) {
8
- process.stdout.write(`${chalk.green("?")} Cartesi machine templateHash ${chalk.cyan(hash)}\n`);
11
+ if (!json) {
12
+ console.log(`${chalk.green("?")} Cartesi machine templateHash ${chalk.cyan(hash)}\n`);
9
13
  }
10
14
  else {
11
- return { hash };
15
+ process.stdout.write(JSON.stringify({ hash }));
12
16
  }
13
17
  }
14
18
  else {
15
- this.error(`Cartesi machine snapshot not found, run '${this.config.bin} build'`);
19
+ command.error(`Cartesi machine snapshot not found, run 'build'`);
16
20
  }
17
- }
18
- }
19
- HashCommand.summary = "Prints out image hash generated by the build command";
20
- HashCommand.description = "Converts the binary generated by the build command to hexadecimal and prints out the result to console";
21
- HashCommand.enableJsonFlag = true;
22
- export default HashCommand;
21
+ });
22
+ };
@@ -0,0 +1,9 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createLogsCommand: () => Command<[], {
3
+ projectName?: string | undefined;
4
+ follow?: true | undefined;
5
+ since?: string | undefined;
6
+ tail: string;
7
+ until?: string | undefined;
8
+ }, {}>;
9
+ //# sourceMappingURL=logs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/commands/logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,iBAAiB;;;;;;MA6C7B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import { execa } from "execa";
3
+ import { getProjectName, getServiceInfo } from "../base.js";
4
+ export const createLogsCommand = () => {
5
+ return new Command("logs")
6
+ .description("Show logs of a local environment.")
7
+ .option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
8
+ .option("-f, --follow", "Follow log output")
9
+ .option("--since <string>", "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)")
10
+ .option("-n, --tail <string>", "Number of lines to show from the end of the logs", "all")
11
+ .option("--until <string>", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)")
12
+ .configureHelp({ showGlobalOptions: true })
13
+ .action(async (options) => {
14
+ const { follow, since, tail, until } = options;
15
+ const projectName = getProjectName(options);
16
+ const logOptions = [];
17
+ if (follow)
18
+ logOptions.push("--follow");
19
+ if (since)
20
+ logOptions.push("--since", since);
21
+ if (tail)
22
+ logOptions.push("--tail", tail);
23
+ if (until)
24
+ logOptions.push("--until", until);
25
+ const serviceInfo = await getServiceInfo({
26
+ projectName,
27
+ service: "rollups-node",
28
+ });
29
+ if (!serviceInfo) {
30
+ throw new Error(`service rollups-node not found`);
31
+ }
32
+ await execa("docker", ["container", "logs", ...logOptions, serviceInfo.ID], { stdio: "inherit" });
33
+ });
34
+ };
@@ -1,21 +1,15 @@
1
- import { BaseCommand } from "../baseCommand.js";
2
- export default class Run extends BaseCommand<typeof Run> {
3
- static summary: string;
4
- static description: string;
5
- static examples: string[];
6
- static flags: {
7
- "block-time": import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- "disable-explorer": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
- "disable-bundler": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
10
- "disable-paymaster": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
11
- "epoch-length": import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
- "no-backend": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
13
- verbose: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
14
- "listen-port": import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
15
- cpus: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
16
- memory: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
17
- "dry-run": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
18
- };
19
- run(): Promise<void>;
20
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createRunCommand: () => Command<[], {
3
+ blockTime: number;
4
+ cpus?: number | undefined;
5
+ defaultBlock: "latest" | "pending" | "safe" | "finalized";
6
+ dryRun: boolean;
7
+ memory?: number | undefined;
8
+ epochLength: number;
9
+ port?: number | undefined;
10
+ runtimeVersion: string;
11
+ projectName?: string | undefined;
12
+ services: string[];
13
+ verbose: boolean;
14
+ }, {}>;
21
15
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,WAAW,CAAC,OAAO,GAAG,CAAC;IACpD,MAAM,CAAC,OAAO,SAA2B;IAEzC,MAAM,CAAC,WAAW,SAAmD;IAErE,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,KAAK;;;;;;;;;;;;MAyDV;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAoJpC"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EAGV,MAAM,6BAA6B,CAAC;AA8JrC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;MA4J5B,CAAC"}
@@ -1,191 +1,202 @@
1
- import { Flags } from "@oclif/core";
2
- import { execa } from "execa";
3
- import fs from "fs-extra";
4
- import path from "path";
5
- import { BaseCommand } from "../baseCommand.js";
6
- class Run extends BaseCommand {
7
- async run() {
8
- const { flags } = await this.parse(Run);
9
- let projectName;
10
- if (flags["no-backend"]) {
11
- projectName = "cartesi-node";
12
- }
13
- else {
14
- // get machine hash
15
- const hash = this.getMachineHash();
16
- // Check if snapshot exists
17
- if (!hash) {
18
- throw new Error(`Cartesi machine snapshot not found, run '${this.config.bin} build'`);
1
+ import { Command, Option, } from "@commander-js/extra-typings";
2
+ import { ExitPromptError } from "@inquirer/core";
3
+ import chalk from "chalk";
4
+ import { ExecaError } from "execa";
5
+ import getPort, { portNumbers } from "get-port";
6
+ import ora from "ora";
7
+ import { numberToHex } from "viem";
8
+ import { getMachineHash, getProjectName } from "../base.js";
9
+ import { DEFAULT_SDK_VERSION, PREFERRED_PORT } from "../config.js";
10
+ import { AVAILABLE_SERVICES, deployApplication, removeApplication, startEnvironment, stopEnvironment, waitHealthyEnvironment, } from "../exec/rollups.js";
11
+ import { keySelect } from "../prompts.js";
12
+ const commaSeparatedList = (value) => value.split(",");
13
+ const shell = async (options) => {
14
+ const { build, epochLength, log, projectName } = options;
15
+ // keep track of last deployment
16
+ let lastDeployment;
17
+ let salt = 0;
18
+ // deploy for the first time
19
+ const hash = getMachineHash();
20
+ if (hash) {
21
+ lastDeployment = await deploy({
22
+ epochLength,
23
+ hash,
24
+ projectName,
25
+ salt: numberToHex(salt++, { size: 32 }),
26
+ });
27
+ }
28
+ else {
29
+ console.warn(chalk.yellow("machine snapshot not found, waiting for build"));
30
+ }
31
+ while (true) {
32
+ try {
33
+ const option = await keySelect({
34
+ choices: [
35
+ { name: "View logs", value: "l" },
36
+ { name: "Build and redeploy", value: "b" },
37
+ { name: "Quit", value: "q" },
38
+ ],
39
+ }, {});
40
+ switch (option) {
41
+ case "l": {
42
+ try {
43
+ await log?.parseAsync(["--project-name", projectName, "--follow"], {
44
+ from: "user",
45
+ });
46
+ }
47
+ catch (error) {
48
+ if (error instanceof ExecaError) {
49
+ // just continue gracefully
50
+ if (error.exitCode === 130) {
51
+ break;
52
+ }
53
+ throw error;
54
+ }
55
+ }
56
+ break;
57
+ }
58
+ case "b": {
59
+ // build
60
+ await build?.parseAsync([], { from: "user" });
61
+ // redeploy
62
+ const hash = getMachineHash();
63
+ if (hash) {
64
+ if (lastDeployment) {
65
+ await undeploy({ projectName });
66
+ }
67
+ lastDeployment = await deploy({
68
+ consensus: lastDeployment?.consensus,
69
+ epochLength,
70
+ hash,
71
+ projectName,
72
+ salt: numberToHex(salt++, { size: 32 }),
73
+ });
74
+ }
75
+ break;
76
+ }
77
+ case "q": {
78
+ return;
79
+ }
19
80
  }
20
- projectName = hash.substring(2, 10);
21
- }
22
- // path of the tool instalation
23
- const binPath = path.join(path.dirname(new URL(import.meta.url).pathname), "..");
24
- // setup the environment variable used in docker compose
25
- const blockInterval = flags["block-time"];
26
- const epochLength = flags["epoch-length"];
27
- const listenPort = flags["listen-port"];
28
- const env = {
29
- ANVIL_VERBOSITY: flags.verbose ? "--steps-tracing" : "--silent",
30
- BLOCK_TIME: blockInterval.toString(),
31
- BLOCK_TIMEOUT: (blockInterval + 3).toString(),
32
- CARTESI_EPOCH_LENGTH: epochLength.toString(),
33
- CARTESI_EXPERIMENTAL_DISABLE_CONFIG_LOG: flags.verbose
34
- ? "false"
35
- : "true",
36
- CARTESI_EXPERIMENTAL_SERVER_MANAGER_BYPASS_LOG: flags.verbose
37
- ? "false"
38
- : "true",
39
- CARTESI_LOG_LEVEL: flags.verbose ? "info" : "error",
40
- CARTESI_SNAPSHOT_DIR: "/usr/share/rollups-node/snapshot",
41
- CARTESI_BIN_PATH: binPath,
42
- CARTESI_LISTEN_PORT: listenPort.toString(),
43
- CARTESI_VALIDATOR_CPUS: flags.cpus?.toString(),
44
- CARTESI_VALIDATOR_MEMORY: flags.memory?.toString(),
45
- };
46
- // validator
47
- const composeFiles = ["docker-compose-validator.yaml"];
48
- if (flags.cpus) {
49
- composeFiles.push("docker-compose-validator-cpus.yaml");
50
- }
51
- if (flags.memory) {
52
- composeFiles.push("docker-compose-validator-memory.yaml");
53
81
  }
54
- // prompt
55
- composeFiles.push("docker-compose-prompt.yaml");
56
- // database
57
- composeFiles.push("docker-compose-database.yaml");
58
- // proxy
59
- composeFiles.push("docker-compose-proxy.yaml");
60
- // anvil
61
- composeFiles.push("docker-compose-anvil.yaml");
62
- // explorer
63
- if (!flags["disable-explorer"]) {
64
- composeFiles.push("docker-compose-explorer.yaml");
65
- }
66
- // account abstraction
67
- if (!flags["disable-bundler"]) {
68
- composeFiles.push("docker-compose-bundler.yaml");
69
- }
70
- if (!flags["disable-paymaster"] && !flags["disable-bundler"]) {
71
- // only add paymaster if bundler is enabled
72
- composeFiles.push("docker-compose-paymaster.yaml");
73
- }
74
- // load the no-backend compose file
75
- if (flags["no-backend"]) {
76
- composeFiles.push("docker-compose-host.yaml");
77
- }
78
- else {
79
- // snapshot volume
80
- composeFiles.push("docker-compose-snapshot-volume.yaml");
82
+ catch (error) {
83
+ if (error instanceof ExitPromptError) {
84
+ // gracefully exit
85
+ return;
86
+ }
87
+ throw error;
81
88
  }
82
- // add project env file loading
83
- if (fs.existsSync("./.cartesi.env")) {
84
- composeFiles.push("docker-compose-envfile.yaml");
89
+ }
90
+ };
91
+ const undeploy = async (options) => {
92
+ const { projectName } = options;
93
+ const progress = ora(`${chalk.cyan(projectName)} undeploying...`).start();
94
+ await removeApplication({
95
+ application: projectName,
96
+ force: true,
97
+ projectName,
98
+ });
99
+ progress.succeed(`${chalk.cyan(projectName)} undeployed`);
100
+ };
101
+ const deploy = async (options) => {
102
+ const { consensus, epochLength, hash, projectName, salt } = options;
103
+ // deploy application to node (onchain and offchain)
104
+ const progress = ora(`deploying ${chalk.cyan(hash)} as ${chalk.cyan(projectName)}`);
105
+ const application = await deployApplication({
106
+ consensus,
107
+ epochLength,
108
+ name: projectName,
109
+ projectName,
110
+ salt,
111
+ snapshotPath: "/var/lib/cartesi-rollups-node/snapshots/image",
112
+ });
113
+ progress.succeed(`${chalk.cyan(projectName)} machine hash is ${chalk.cyan(hash)}`);
114
+ progress.succeed(`${chalk.cyan(projectName)} contract deployed at ${chalk.cyan(application.address)}`);
115
+ return application;
116
+ };
117
+ export const createRunCommand = () => {
118
+ return new Command("run")
119
+ .description("Run a local cartesi node for the application.")
120
+ .addOption(new Option("--block-time <number>", "interval between blocks (in seconds)")
121
+ .argParser(Number)
122
+ .default(2))
123
+ .addOption(new Option("--cpus <number>", "number of cpu limits for the rollups-node").argParser(Number))
124
+ .addOption(new Option("--default-block <string>", "default block to be used when fetching new blocks.")
125
+ .choices(["latest", "safe", "pending", "finalized"])
126
+ .default("latest"))
127
+ .option("--dry-run", "show the docker compose configuration", false)
128
+ .addOption(new Option("--memory <number>", "memory limit for the rollups-node in MB").argParser(Number))
129
+ .addOption(new Option("--epoch-length <number>", "length of an epoch (in blocks)")
130
+ .argParser(Number)
131
+ .default(720))
132
+ .option("-p, --port <number>", "port to listen on", Number)
133
+ .addOption(new Option("--runtime-version <version>", "version for Cartesi Rollups Runtime to use")
134
+ .default(DEFAULT_SDK_VERSION)
135
+ .hideHelp())
136
+ .option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
137
+ .option("--services <string>", `optional services to start, comma separated list from [${AVAILABLE_SERVICES.join(", ")}]`, commaSeparatedList, [])
138
+ .option("-v, --verbose", "verbose output", false)
139
+ .action(async (options, program) => {
140
+ const { blockTime, cpus, defaultBlock, dryRun, epochLength, memory, runtimeVersion, services, verbose, } = options;
141
+ const progress = ora();
142
+ if (defaultBlock !== "finalized") {
143
+ console.warn(chalk.yellow(`WARNING: default block is set to '${defaultBlock}', production configuration will likely use 'finalized'`));
85
144
  }
86
- // create the "--file <file>" list
87
- const files = composeFiles
88
- .map((f) => ["--file", path.join(binPath, "node", f)])
89
- .flat();
90
- const compose_args = [
91
- "compose",
92
- ...files,
93
- "--project-directory",
94
- ".",
95
- "--project-name",
145
+ // project name explicitly defined or the current directory name
146
+ const projectName = getProjectName(options);
147
+ // resolve port number, using the first free port in a range, unless explicitly set
148
+ const port = options.port ||
149
+ (await getPort({
150
+ port: portNumbers(PREFERRED_PORT, PREFERRED_PORT + 10),
151
+ }));
152
+ // run compose environment (detached)
153
+ const { address, config } = await startEnvironment({
154
+ blockTime,
155
+ cpus,
156
+ defaultBlock,
157
+ dryRun,
158
+ memory,
159
+ port,
96
160
  projectName,
97
- ];
98
- const up_args = [];
99
- if (!flags.verbose) {
100
- compose_args.push("--progress", "quiet");
101
- up_args.push("--attach", "validator");
102
- up_args.push("--attach", "prompt");
161
+ runtimeVersion,
162
+ services,
163
+ verbose,
164
+ });
165
+ if (dryRun && config) {
166
+ // just show the docker compose configuration and quit
167
+ process.stdout.write(config);
168
+ return;
103
169
  }
104
- // XXX: need this handler, so SIGINT can still call the finally block below
105
- process.on("SIGINT", () => { });
106
- try {
107
- if (flags["dry-run"]) {
108
- // show the docker compose configuration
109
- await execa("docker", [...compose_args, "config"], {
110
- env,
111
- stdio: "inherit",
112
- });
113
- return;
170
+ progress.succeed(`${chalk.cyan(projectName)} starting at ${chalk.cyan(`${address}`)}`);
171
+ // wait for the environment to be healthy
172
+ await waitHealthyEnvironment({
173
+ name: projectName,
174
+ port,
175
+ projectName,
176
+ services,
177
+ });
178
+ const shutdown = async () => {
179
+ progress.start(`${chalk.cyan(projectName)} stopping...`);
180
+ try {
181
+ await stopEnvironment({ projectName });
182
+ progress.succeed(`${chalk.cyan(projectName)} stopped`);
114
183
  }
115
- // run compose environment
116
- await execa("docker", [...compose_args, "up", ...up_args], {
117
- env,
118
- stdio: "inherit",
119
- });
120
- }
121
- catch (e) {
122
- // 130 is a graceful shutdown, so we can swallow it
123
- if (e.exitCode !== 130) {
124
- throw e;
184
+ catch (e) {
185
+ progress.fail(e instanceof Error ? e.message : "Unknown error");
125
186
  }
126
- }
127
- finally {
128
- // shut it down, including volumes
129
- await execa("docker", [...compose_args, "down", "--volumes"], {
130
- env,
131
- stdio: "inherit",
132
- });
133
- }
134
- }
135
- }
136
- Run.summary = "Run application node.";
137
- Run.description = "Run a local cartesi node for the application.";
138
- Run.examples = ["<%= config.bin %> <%= command.id %>"];
139
- Run.flags = {
140
- "block-time": Flags.integer({
141
- description: "interval between blocks (in seconds)",
142
- default: 5,
143
- }),
144
- "disable-explorer": Flags.boolean({
145
- default: false,
146
- description: "disable local explorer service to save machine resources",
147
- summary: "disable explorer service",
148
- }),
149
- "disable-bundler": Flags.boolean({
150
- default: false,
151
- description: "disable local bundler service to save machine resources",
152
- summary: "disable bundler service",
153
- }),
154
- "disable-paymaster": Flags.boolean({
155
- default: false,
156
- description: "disable local paymaster service to save machine resources",
157
- summary: "disable paymaster service",
158
- }),
159
- "epoch-length": Flags.integer({
160
- description: "length of an epoch (in blocks)",
161
- default: 720,
162
- }),
163
- "no-backend": Flags.boolean({
164
- description: "Run a node without the application code. Application must be executed by the developer on the host machine, fetching inputs from the node running at http://localhost:5004",
165
- summary: "run a node without the application code",
166
- default: false,
167
- }),
168
- verbose: Flags.boolean({
169
- description: "verbose output",
170
- default: false,
171
- char: "v",
172
- }),
173
- "listen-port": Flags.integer({
174
- description: "port to listen for incoming connections",
175
- default: 8080,
176
- }),
177
- cpus: Flags.integer({
178
- description: "Define the number of CPUs to use (eg.: 1) for the rollups-node",
179
- summary: "number of cpu limits for the rollups-node",
180
- }),
181
- memory: Flags.integer({
182
- description: "Define the amount of memory to use for the rollups-node in MB (eg.: 1024)",
183
- summary: "memory limit for the rollups-node in MB",
184
- }),
185
- "dry-run": Flags.boolean({
186
- description: "show the docker compose configuration",
187
- default: false,
188
- hidden: true,
189
- }),
187
+ process.exit(0);
188
+ };
189
+ // inhibit SIGINT and SIGTERM, will be handled gracefully by the shell
190
+ process.on("SIGINT", () => { });
191
+ process.on("SIGTERM", () => { });
192
+ const log = program.parent?.commands.find((c) => c.name() === "logs");
193
+ const build = program.parent?.commands.find((c) => c.name() === "build");
194
+ await shell({
195
+ build,
196
+ epochLength,
197
+ log,
198
+ projectName,
199
+ });
200
+ await shutdown();
201
+ });
190
202
  };
191
- export default Run;
@@ -0,0 +1,10 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createSendCommand: () => Command<[string | undefined], {
3
+ from?: string | undefined;
4
+ application?: string | undefined;
5
+ encoding?: "string" | "hex" | "abi" | undefined;
6
+ abiParams?: string | undefined;
7
+ projectName?: string | undefined;
8
+ rpcUrl?: string | undefined;
9
+ }, {}>;
10
+ //# sourceMappingURL=send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/commands/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAmG9D,eAAO,MAAM,iBAAiB;;;;;;;MA4D7B,CAAC"}