@cartesi/cli 2.0.0-alpha.4 → 2.0.0-alpha.5

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 (68) hide show
  1. package/dist/base.d.ts +14 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/base.js +77 -0
  4. package/dist/commands/address-book.d.ts +2 -8
  5. package/dist/commands/address-book.d.ts.map +1 -1
  6. package/dist/commands/address-book.js +15 -14
  7. package/dist/commands/build.d.ts +2 -11
  8. package/dist/commands/build.d.ts.map +1 -1
  9. package/dist/commands/build.js +16 -28
  10. package/dist/commands/clean.d.ts +2 -7
  11. package/dist/commands/clean.d.ts.map +1 -1
  12. package/dist/commands/clean.js +9 -10
  13. package/dist/commands/create.d.ts +2 -14
  14. package/dist/commands/create.d.ts.map +1 -1
  15. package/dist/commands/create.js +37 -51
  16. package/dist/commands/deploy/build.d.ts +2 -14
  17. package/dist/commands/deploy/build.d.ts.map +1 -1
  18. package/dist/commands/deploy/build.js +41 -47
  19. package/dist/commands/deploy.d.ts +3 -0
  20. package/dist/commands/deploy.d.ts.map +1 -0
  21. package/dist/commands/{deploy/index.js → deploy.js} +26 -28
  22. package/dist/commands/doctor.d.ts +2 -12
  23. package/dist/commands/doctor.d.ts.map +1 -1
  24. package/dist/commands/doctor.js +83 -90
  25. package/dist/commands/hash.d.ts +2 -9
  26. package/dist/commands/hash.d.ts.map +1 -1
  27. package/dist/commands/hash.js +14 -14
  28. package/dist/commands/run.d.ts +2 -21
  29. package/dist/commands/run.d.ts.map +1 -1
  30. package/dist/commands/run.js +46 -88
  31. package/dist/commands/send/erc20.d.ts +2 -13
  32. package/dist/commands/send/erc20.d.ts.map +1 -1
  33. package/dist/commands/send/erc20.js +55 -52
  34. package/dist/commands/send/erc721.d.ts +2 -13
  35. package/dist/commands/send/erc721.d.ts.map +1 -1
  36. package/dist/commands/send/erc721.js +49 -46
  37. package/dist/commands/send/ether.d.ts +2 -12
  38. package/dist/commands/send/ether.d.ts.map +1 -1
  39. package/dist/commands/send/ether.js +23 -21
  40. package/dist/commands/send/generic.d.ts +2 -14
  41. package/dist/commands/send/generic.d.ts.map +1 -1
  42. package/dist/commands/send/generic.js +91 -97
  43. package/dist/commands/send.d.ts +21 -0
  44. package/dist/commands/send.d.ts.map +1 -0
  45. package/dist/commands/send.js +67 -0
  46. package/dist/commands/shell.d.ts +2 -14
  47. package/dist/commands/shell.d.ts.map +1 -1
  48. package/dist/commands/shell.js +21 -43
  49. package/dist/index.d.ts +2 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +51 -1
  52. package/package.json +6 -25
  53. package/bin/dev.cmd +0 -3
  54. package/bin/dev.js +0 -25
  55. package/bin/run.cmd +0 -3
  56. package/bin/run.js +0 -8
  57. package/dist/baseCommand.d.ts +0 -22
  58. package/dist/baseCommand.d.ts.map +0 -1
  59. package/dist/baseCommand.js +0 -92
  60. package/dist/commands/deploy/index.d.ts +0 -12
  61. package/dist/commands/deploy/index.d.ts.map +0 -1
  62. package/dist/commands/send/index.d.ts +0 -28
  63. package/dist/commands/send/index.d.ts.map +0 -1
  64. package/dist/commands/send/index.js +0 -102
  65. package/dist/flags.d.ts +0 -17
  66. package/dist/flags.d.ts.map +0 -1
  67. package/dist/flags.js +0 -28
  68. package/oclif.manifest.json +0 -883
@@ -0,0 +1,67 @@
1
+ import input from "@inquirer/input";
2
+ import select from "@inquirer/select";
3
+ import { isAddress } from "viem";
4
+ import { getApplicationAddress } from "../base.js";
5
+ import createClients, { supportedChains } from "../wallet.js";
6
+ import { registerErc20Command } from "./send/erc20.js";
7
+ import { registerErc721Command } from "./send/erc721.js";
8
+ import { registerEtherCommand } from "./send/ether.js";
9
+ import { registerGenericCommand } from "./send/generic.js";
10
+ export const connect = (options) => {
11
+ const { chainId, rpcUrl, mnemonic, mnemonicIndex } = options;
12
+ // create viem clients
13
+ return createClients({
14
+ chain: supportedChains({ includeDevnet: true }).find((c) => c.id == chainId),
15
+ rpcUrl,
16
+ mnemonicPassphrase: mnemonic,
17
+ mnemonicIndex,
18
+ });
19
+ };
20
+ export const getInputApplicationAddress = async (dapp) => {
21
+ if (dapp && isAddress(dapp)) {
22
+ // honor the flag
23
+ return dapp;
24
+ }
25
+ // get the running container dapp address
26
+ const nodeAddress = await getApplicationAddress();
27
+ // query for the address
28
+ const applicationAddress = await input({
29
+ message: "Application address",
30
+ validate: (value) => isAddress(value) || "Invalid address",
31
+ default: nodeAddress,
32
+ });
33
+ return applicationAddress;
34
+ };
35
+ export const addCommonOptions = (command) => {
36
+ return command
37
+ .option("--dapp <address>", "Application address")
38
+ .option("--chain-id <id>", "Chain ID", parseInt)
39
+ .option("--rpc-url <url>", "RPC URL")
40
+ .option("--mnemonic <phrase>", "Mnemonic passphrase")
41
+ .option("--mnemonic-index <index>", "Mnemonic account index", parseInt, 0);
42
+ };
43
+ export const registerSendCommand = (program) => {
44
+ const sendCommand = addCommonOptions(program
45
+ .command("send")
46
+ .description("Sends different kinds of input to the application in interactive mode.")).action(async (options, program) => {
47
+ // Get the registered subcommands from the program
48
+ const commands = program.commands;
49
+ // Create choices for the select prompt based on registered commands
50
+ const choices = commands.map((cmd) => ({
51
+ name: cmd.name(),
52
+ value: cmd,
53
+ description: cmd.description(),
54
+ }));
55
+ // Present the list of subcommands using @inquirer/select
56
+ const subcommand = await select({
57
+ message: "Select the type of input to send",
58
+ choices,
59
+ });
60
+ // Execute the selected subcommand
61
+ subcommand.parseAsync(program.args);
62
+ });
63
+ registerErc20Command(sendCommand);
64
+ registerErc721Command(sendCommand);
65
+ registerEtherCommand(sendCommand);
66
+ registerGenericCommand(sendCommand);
67
+ };
@@ -1,15 +1,3 @@
1
- import { BaseCommand } from "../baseCommand.js";
2
- export default class Shell extends BaseCommand<typeof Shell> {
3
- static description: string;
4
- static examples: string[];
5
- static args: {
6
- image: import("@oclif/core/lib/interfaces/parser.js").Arg<string | undefined, Record<string, unknown>>;
7
- };
8
- static flags: {
9
- command: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- config: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
- "run-as-root": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
12
- };
13
- run(): Promise<void>;
14
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const registerShellCommand: (program: Command) => void;
15
3
  //# sourceMappingURL=shell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/commands/shell.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,WAAW,CAAC,OAAO,KAAK,CAAC;IACxD,MAAM,CAAC,WAAW,SAAqD;IAEvE,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,IAAI;;MAKT;IAEF,MAAM,CAAC,KAAK;;;;MAgBV;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA2CpC"}
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/commands/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAOtD,eAAO,MAAM,oBAAoB,YAAa,OAAO,SAkDpD,CAAC"}
@@ -1,65 +1,43 @@
1
- import { Args, Flags } from "@oclif/core";
2
1
  import fs from "fs-extra";
3
2
  import path from "path";
4
- import { BaseCommand } from "../baseCommand.js";
3
+ import { getApplicationConfig, getContextPath } from "../base.js";
5
4
  import { bootMachine } from "../machine.js";
6
- class Shell extends BaseCommand {
7
- async run() {
8
- const { flags } = await this.parse(Shell);
5
+ export const registerShellCommand = (program) => {
6
+ program
7
+ .command("shell")
8
+ .argument("[image]", "image ID|name")
9
+ .option("--command <command>", "shell command to run", "/bin/sh")
10
+ .option("-c, --config <config>", "path to the configuration file", "cartesi.toml")
11
+ .option("--run-as-root", "run as root user", false)
12
+ .action(async (image, { command, config, runAsRoot }) => {
9
13
  // get application configuration from 'cartesi.toml'
10
- const config = this.getApplicationConfig(flags.config);
14
+ const c = getApplicationConfig(config);
11
15
  // destination directory for image and intermediate files
12
- const destination = path.resolve(this.getContextPath());
16
+ const destination = path.resolve(getContextPath());
13
17
  // check if all drives are built
14
- for (const [name, drive] of Object.entries(config.drives)) {
18
+ for (const [name, drive] of Object.entries(c.drives)) {
15
19
  const filename = `${name}.${drive.format}`;
16
- const pathname = this.getContextPath(filename);
20
+ const pathname = getContextPath(filename);
17
21
  if (!fs.existsSync(pathname)) {
18
- throw new Error(`drive '${name}' not built, run '${this.config.bin} build'`);
22
+ throw new Error(`drive '${name}' not built, run 'build'`);
19
23
  }
20
24
  }
21
25
  // create shell entrypoint
22
26
  const info = {
23
27
  cmd: [],
24
- entrypoint: [this.flags.command],
28
+ entrypoint: [command],
25
29
  env: [],
26
30
  workdir: "/",
27
31
  };
28
32
  // start with interactive mode on
29
- config.machine.interactive = true;
33
+ c.machine.interactive = true;
30
34
  // interactive mode can't have final hash
31
- config.machine.finalHash = false;
35
+ c.machine.finalHash = false;
32
36
  // do not store machine in interactive mode
33
- config.machine.store = undefined;
37
+ c.machine.store = undefined;
34
38
  // run as root if flag is set
35
- config.machine.user = flags["run-as-root"] ? "root" : undefined;
39
+ c.machine.user = runAsRoot ? "root" : undefined;
36
40
  // boot machine
37
- await bootMachine(config, info, destination);
38
- }
39
- }
40
- Shell.description = "Start a shell in cartesi machine of application";
41
- Shell.examples = ["<%= config.bin %> <%= command.id %>"];
42
- Shell.args = {
43
- image: Args.string({
44
- description: "image ID|name",
45
- required: false,
46
- }),
41
+ await bootMachine(c, info, destination);
42
+ });
47
43
  };
48
- Shell.flags = {
49
- command: Flags.string({
50
- default: "/bin/sh",
51
- description: "shell command to run",
52
- summary: "shell to run",
53
- }),
54
- config: Flags.file({
55
- char: "c",
56
- default: "cartesi.toml",
57
- summary: "path to the configuration file",
58
- }),
59
- "run-as-root": Flags.boolean({
60
- default: false,
61
- description: "run as root user",
62
- summary: "run the cartesi machine as the root user",
63
- }),
64
- };
65
- export default Shell;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { run } from "@oclif/core";
1
+ #!/usr/bin/env node
2
+ export {};
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js CHANGED
@@ -1 +1,51 @@
1
- export { run } from "@oclif/core";
1
+ #!/usr/bin/env node
2
+ import { Command } from "@commander-js/extra-typings";
3
+ import { createRequire } from "node:module";
4
+ import { registerAddressBookCommand } from "./commands/address-book.js";
5
+ import { registerBuildCommand } from "./commands/build.js";
6
+ import { registerCleanCommand } from "./commands/clean.js";
7
+ import { registerCreateCommand } from "./commands/create.js";
8
+ import { registerDeployCommand } from "./commands/deploy.js";
9
+ import { registerDoctorCommand } from "./commands/doctor.js";
10
+ import { registerHashCommand } from "./commands/hash.js";
11
+ import { registerRunCommand } from "./commands/run.js";
12
+ import { registerSendCommand } from "./commands/send.js";
13
+ import { registerShellCommand } from "./commands/shell.js";
14
+ // Use `createRequire` to import JSON in ESM
15
+ const require = createRequire(import.meta.url);
16
+ const pkg = require("../package.json");
17
+ const splash = String.raw ` .
18
+ / \
19
+ / \
20
+ \---/---\ /----\
21
+ \ X \
22
+ \----/ \---/---\
23
+ \ / CARTESI
24
+ \ / CLI
25
+ '`;
26
+ const program = new Command()
27
+ .name("cartesi")
28
+ .version(pkg.version)
29
+ .addHelpText("before", splash);
30
+ registerAddressBookCommand(program);
31
+ registerBuildCommand(program);
32
+ registerCleanCommand(program);
33
+ registerCreateCommand(program);
34
+ registerDeployCommand(program);
35
+ registerDoctorCommand(program);
36
+ registerHashCommand(program);
37
+ registerRunCommand(program);
38
+ registerSendCommand(program);
39
+ registerShellCommand(program);
40
+ // Global error handling
41
+ process.on("uncaughtException", (err) => {
42
+ if (process.env.NODE_ENV === "development") {
43
+ console.error(err);
44
+ }
45
+ else {
46
+ // in production, only print the error message, not the stack trace
47
+ console.error(err.message);
48
+ }
49
+ process.exit(1);
50
+ });
51
+ program.parse();
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@cartesi/cli",
3
- "version": "2.0.0-alpha.4",
3
+ "version": "2.0.0-alpha.5",
4
4
  "description": "Cartesi CLI",
5
5
  "author": "Danilo Tuler <tuler@pobox.com>",
6
6
  "bin": {
7
- "cartesi": "./bin/run.js"
7
+ "cartesi": "./dist/index.js"
8
8
  },
9
9
  "type": "module",
10
10
  "homepage": "https://github.com/cartesi/cli",
@@ -14,21 +14,19 @@
14
14
  "files": [
15
15
  "/bin",
16
16
  "/dist",
17
- "/npm-shrinkwrap.json",
18
- "/oclif.manifest.json"
17
+ "/npm-shrinkwrap.json"
19
18
  ],
20
19
  "dependencies": {
20
+ "@commander-js/extra-typings": "^13.1.0",
21
21
  "@inquirer/confirm": "^5.0.0",
22
22
  "@inquirer/core": "^10.0.0",
23
23
  "@inquirer/input": "^4.0.0",
24
24
  "@inquirer/select": "^4.0.0",
25
25
  "@inquirer/type": "^3.0.0",
26
- "@oclif/core": "^4.0.29",
27
- "@oclif/plugin-help": "^6.2.15",
28
- "@oclif/plugin-plugins": "^5.4.15",
29
26
  "bytes": "^3.1.2",
30
27
  "chalk": "^5.3.0",
31
28
  "cli-table3": "^0.6.5",
29
+ "commander": "^13.1.0",
32
30
  "execa": "^9.4.1",
33
31
  "fs-extra": "^11.2.0",
34
32
  "giget": "^1.2.3",
@@ -56,10 +54,7 @@
56
54
  "@wagmi/cli": "^2.1.16",
57
55
  "copyfiles": "^2.4.1",
58
56
  "eslint": "^8.57.0",
59
- "eslint-config-oclif": "^5.2.1",
60
- "eslint-config-oclif-typescript": "^3.1.12",
61
57
  "npm-run-all": "^4.1.5",
62
- "oclif": "^4.15.9",
63
58
  "rimraf": "^6.0.1",
64
59
  "ts-node": "^10.9.2",
65
60
  "tslib": "^2.8.0",
@@ -69,25 +64,10 @@
69
64
  "@cartesi/eslint-config": "0.0.0",
70
65
  "tsconfig": "0.0.0"
71
66
  },
72
- "oclif": {
73
- "bin": "cartesi",
74
- "dirname": "cartesi",
75
- "commands": "./dist/commands",
76
- "plugins": [
77
- "@oclif/plugin-help"
78
- ],
79
- "topicSeparator": " ",
80
- "macos": {
81
- "identifier": "io.cartesi.cli"
82
- }
83
- },
84
67
  "engines": {
85
68
  "node": ">=18.0.0"
86
69
  },
87
70
  "bugs": "https://github.com/cartesi/cli/issues",
88
- "keywords": [
89
- "oclif"
90
- ],
91
71
  "types": "dist/index.d.ts",
92
72
  "scripts": {
93
73
  "build": "run-s clean codegen compile copy-files",
@@ -95,6 +75,7 @@
95
75
  "codegen": "run-p codegen:wagmi",
96
76
  "codegen:wagmi": "wagmi generate",
97
77
  "compile": "tsc -p tsconfig.build.json",
78
+ "postcompile": "chmod +x dist/index.js",
98
79
  "copy-files": "copyfiles -u 1 \"src/**/*.yaml\" \"src/**/*.env\" \"src/**/*.txt\" dist",
99
80
  "lint": "eslint \"src/**/*.ts*\"",
100
81
  "posttest": "pnpm lint",
package/bin/dev.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\dev" %*
package/bin/dev.js DELETED
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node --no-warnings=ExperimentalWarning --loader ts-node/esm
2
-
3
- import oclif from "@oclif/core";
4
- import path from "node:path";
5
- import url from "node:url";
6
- import { register } from "ts-node";
7
-
8
- // In dev mode -> use ts-node and dev plugins
9
- process.env.NODE_ENV = "development";
10
-
11
- const project = path.join(
12
- path.dirname(url.fileURLToPath(import.meta.url)),
13
- "..",
14
- "tsconfig.json"
15
- );
16
- register({ project });
17
-
18
- // In dev mode, always show stack traces
19
- oclif.settings.debug = true;
20
-
21
- // Start the CLI
22
- oclif
23
- .run(process.argv.slice(2), import.meta.url)
24
- .then(oclif.flush)
25
- .catch(oclif.Errors.handle);
package/bin/run.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\run" %*
package/bin/run.js DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import oclif from "@oclif/core";
4
-
5
- oclif
6
- .run(process.argv.slice(2), import.meta.url)
7
- .then(oclif.flush)
8
- .catch(oclif.Errors.handle);
@@ -1,22 +0,0 @@
1
- import { Command, Interfaces } from "@oclif/core";
2
- import { Address, Hash } from "viem";
3
- import { Config } from "./config.js";
4
- export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)["baseFlags"] & T["flags"]>;
5
- export type Args<T extends typeof Command> = Interfaces.InferredArgs<T["args"]>;
6
- export type AddressBook = Record<string, Address>;
7
- export declare abstract class BaseCommand<T extends typeof Command> extends Command {
8
- protected flags: Flags<T>;
9
- protected args: Args<T>;
10
- protected getServiceState(projectName: string, serviceName: string): Promise<string | undefined>;
11
- protected getContextPath(...paths: string[]): string;
12
- protected getApplicationConfig(configPath: string): Config;
13
- protected getMachineHash(): Hash | undefined;
14
- protected logPrompt({ title, value }: {
15
- title: string;
16
- value: string;
17
- }): void;
18
- protected getApplicationAddress(): Promise<Address>;
19
- protected getAddressBook(): Promise<AddressBook>;
20
- init(): Promise<void>;
21
- }
22
- //# sourceMappingURL=baseCommand.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"baseCommand.d.ts","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKlD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAsB,MAAM,MAAM,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAS,MAAM,aAAa,CAAC;AAiB5C,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,OAAO,IAAI,UAAU,CAAC,aAAa,CAClE,CAAC,OAAO,WAAW,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CACjD,CAAC;AACF,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,OAAO,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAChF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,8BAAsB,WAAW,CAAC,CAAC,SAAS,OAAO,OAAO,CAAE,SAAQ,OAAO;IACvE,SAAS,CAAC,KAAK,EAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,IAAI,EAAG,IAAI,CAAC,CAAC,CAAC,CAAC;cAET,eAAe,CAC3B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAe9B,SAAS,CAAC,cAAc,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAIpD,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAM1D,SAAS,CAAC,cAAc,IAAI,IAAI,GAAG,SAAS;IAY5C,SAAS,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;cAItD,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;cAKzC,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAiCzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAYrC"}
@@ -1,92 +0,0 @@
1
- import { Command } from "@oclif/core";
2
- import chalk from "chalk";
3
- import { execa } from "execa";
4
- import fs from "fs";
5
- import path from "path";
6
- import { getAddress, isHash } from "viem";
7
- import { parse } from "./config.js";
8
- import { applicationFactoryAddress, authorityFactoryAddress, erc1155BatchPortalAddress, erc1155SinglePortalAddress, erc20PortalAddress, erc721PortalAddress, etherPortalAddress, inputBoxAddress, selfHostedApplicationFactoryAddress, testMultiTokenAddress, testNftAddress, testTokenAddress, } from "./contracts.js";
9
- export class BaseCommand extends Command {
10
- async getServiceState(projectName, serviceName) {
11
- // get service information
12
- const { stdout } = await execa("docker", [
13
- "compose",
14
- "--project-name",
15
- projectName,
16
- "ps",
17
- serviceName,
18
- "--format",
19
- "json",
20
- ]);
21
- const ps = stdout ? JSON.parse(stdout) : undefined;
22
- return ps?.State;
23
- }
24
- getContextPath(...paths) {
25
- return path.join(".cartesi", ...paths);
26
- }
27
- getApplicationConfig(configPath) {
28
- return fs.existsSync(configPath)
29
- ? parse(fs.readFileSync(configPath).toString())
30
- : parse("");
31
- }
32
- getMachineHash() {
33
- // read hash of the cartesi machine snapshot, if one exists
34
- const hashPath = this.getContextPath("image", "hash");
35
- if (fs.existsSync(hashPath)) {
36
- const hash = fs.readFileSync(hashPath).toString("hex");
37
- if (isHash(`0x${hash}`)) {
38
- return `0x${hash}`;
39
- }
40
- }
41
- return undefined;
42
- }
43
- logPrompt({ title, value }) {
44
- this.log(`${chalk.green("?")} ${title} ${chalk.cyan(value)}`);
45
- }
46
- async getApplicationAddress() {
47
- // fixed value, as we do deterministic deployment with a zero hash
48
- return getAddress("0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e");
49
- }
50
- async getAddressBook() {
51
- const applicationAddress = await this.getApplicationAddress();
52
- // build rollups contracts address book
53
- const contracts = {
54
- Application: applicationAddress,
55
- ApplicationFactory: applicationFactoryAddress,
56
- AuthorityFactory: authorityFactoryAddress,
57
- EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
58
- EntryPointV07: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
59
- ERC1155BatchPortal: erc1155BatchPortalAddress,
60
- ERC1155SinglePortal: erc1155SinglePortalAddress,
61
- ERC20Portal: erc20PortalAddress,
62
- ERC721Portal: erc721PortalAddress,
63
- EtherPortal: etherPortalAddress,
64
- InputBox: inputBoxAddress,
65
- LightAccountFactory: "0x00004EC70002a32400f8ae005A26081065620D20",
66
- SelfHostedApplicationFactory: selfHostedApplicationFactoryAddress,
67
- SimpleAccountFactory: "0x9406Cc6185a346906296840746125a0E44976454",
68
- SmartAccountFactory: "0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5",
69
- KernelFactoryV2: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3",
70
- KernelFactoryV3: "0x6723b44Abeec4E71eBE3232BD5B455805baDD22f",
71
- KernelFactoryV3_1: "0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419",
72
- TestToken: testTokenAddress,
73
- TestNFT: testNftAddress,
74
- TestMultiToken: testMultiTokenAddress,
75
- VerifyingPaymasterV06: "0x28ec0633192d0cBd9E1156CE05D5FdACAcB93947",
76
- VerifyingPaymasterV07: "0xc5c97885C67F7361aBAfD2B95067a5bBdA603608",
77
- };
78
- return contracts;
79
- }
80
- async init() {
81
- await super.init();
82
- const { args, flags } = await this.parse({
83
- flags: this.ctor.flags,
84
- baseFlags: super.ctor.baseFlags,
85
- args: this.ctor.args,
86
- enableJsonFlag: this.ctor.enableJsonFlag,
87
- strict: this.ctor.strict,
88
- });
89
- this.flags = flags;
90
- this.args = args;
91
- }
92
- }
@@ -1,12 +0,0 @@
1
- import { BaseCommand } from "../../baseCommand.js";
2
- export default class Deploy extends BaseCommand<typeof Deploy> {
3
- static summary: string;
4
- static description: string;
5
- static examples: string[];
6
- static flags: {
7
- hosting: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- webapp: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<import("url").URL, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- };
10
- run(): Promise<void>;
11
- }
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,WAAW,CAAC,OAAO,MAAM,CAAC;IAC1D,MAAM,CAAC,OAAO,SAA2C;IAEzD,MAAM,CAAC,WAAW,SACoD;IAEtE,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,KAAK;;;MAWV;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAiEpC"}
@@ -1,28 +0,0 @@
1
- import { Command, Interfaces } from "@oclif/core";
2
- import { Address, PublicClient, WalletClient } from "viem";
3
- import { BaseCommand } from "../../baseCommand.js";
4
- export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof SendBaseCommand)["baseFlags"] & T["flags"]>;
5
- export type Args<T extends typeof Command> = Interfaces.InferredArgs<T["args"]>;
6
- export declare abstract class SendBaseCommand<T extends typeof Command> extends BaseCommand<typeof SendBaseCommand> {
7
- static baseFlags: {
8
- dapp: Interfaces.OptionFlag<`0x${string}` | undefined, Interfaces.CustomOptions>;
9
- "chain-id": Interfaces.OptionFlag<number | undefined, Interfaces.CustomOptions>;
10
- "rpc-url": Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
11
- "mnemonic-passphrase": Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
12
- "mnemonic-index": Interfaces.OptionFlag<number, Interfaces.CustomOptions>;
13
- };
14
- protected flags: Flags<T>;
15
- protected args: Args<T>;
16
- private connect;
17
- protected getApplicationAddress(): Promise<Address>;
18
- init(): Promise<void>;
19
- protected abstract send(publicClient: PublicClient, walletClient: WalletClient): Promise<Address>;
20
- run(): Promise<void>;
21
- }
22
- export default class Send extends Command {
23
- static summary: string;
24
- static description: string;
25
- static examples: string[];
26
- run(): Promise<void>;
27
- }
28
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/send/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAA0B,MAAM,aAAa,CAAC;AAE1E,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAa,MAAM,MAAM,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,OAAO,IAAI,UAAU,CAAC,aAAa,CAClE,CAAC,OAAO,eAAe,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CACrD,CAAC;AACF,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,OAAO,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAGhF,8BAAsB,eAAe,CACjC,CAAC,SAAS,OAAO,OAAO,CAC1B,SAAQ,WAAW,CAAC,OAAO,eAAe,CAAC;IACzC,MAAM,CAAC,SAAS;;;;;;MA8Bd;IAEF,SAAS,CAAC,KAAK,EAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,IAAI,EAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAEX,OAAO;cAeL,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;IAmB5C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAYlC,SAAS,CAAC,QAAQ,CAAC,IAAI,CACnB,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,OAAO,CAAC;IAEN,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAOpC;AAED,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,OAAO;IACrC,MAAM,CAAC,OAAO,SAAoC;IAElD,MAAM,CAAC,WAAW,SAC2D;IAE7E,MAAM,CAAC,QAAQ,WAA2C;IAE7C,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAmBpC"}
@@ -1,102 +0,0 @@
1
- import input from "@inquirer/input";
2
- import select from "@inquirer/select";
3
- import { Command, Flags as StandardFlags } from "@oclif/core";
4
- import ora from "ora";
5
- import { isAddress } from "viem";
6
- import { BaseCommand } from "../../baseCommand.js";
7
- import * as CustomFlags from "../../flags.js";
8
- import createClients, { supportedChains } from "../../wallet.js";
9
- // base command for sending input to the application
10
- export class SendBaseCommand extends BaseCommand {
11
- async connect() {
12
- // create viem clients
13
- return createClients({
14
- chain: supportedChains({ includeDevnet: true }).find((c) => c.id == this.flags["chain-id"]),
15
- rpcUrl: this.flags["rpc-url"],
16
- mnemonicPassphrase: this.flags["mnemonic-passphrase"],
17
- mnemonicIndex: this.flags["mnemonic-index"],
18
- });
19
- }
20
- async getApplicationAddress() {
21
- if (this.flags.dapp) {
22
- // honor the flag
23
- return this.flags.dapp;
24
- }
25
- // get the running container dapp address
26
- const nodeAddress = await super.getApplicationAddress();
27
- // query for the address
28
- const applicationAddress = await input({
29
- message: "Application address",
30
- validate: (value) => isAddress(value) || "Invalid address",
31
- default: nodeAddress,
32
- });
33
- return applicationAddress;
34
- }
35
- async init() {
36
- await super.init();
37
- const { args, flags } = await this.parse({
38
- flags: this.ctor.flags,
39
- baseFlags: super.ctor.baseFlags,
40
- args: this.ctor.args,
41
- strict: this.ctor.strict,
42
- });
43
- this.flags = flags;
44
- this.args = args;
45
- }
46
- async run() {
47
- const { publicClient, walletClient } = await this.connect();
48
- const hash = await this.send(publicClient, walletClient);
49
- const progress = ora("Sending input...").start();
50
- await publicClient.waitForTransactionReceipt({ hash });
51
- progress.succeed(`Input sent: ${hash}`);
52
- }
53
- }
54
- SendBaseCommand.baseFlags = {
55
- dapp: CustomFlags.address({
56
- summary: "dapp address.",
57
- description: "the address of the DApp, defaults to the deployed DApp address if application is running.",
58
- }),
59
- "chain-id": StandardFlags.integer({
60
- description: "The EIP-155 chain ID.",
61
- char: "c",
62
- env: "CHAIN",
63
- helpGroup: "Ethereum",
64
- options: supportedChains({ includeDevnet: true }).map((c) => c.id.toString()),
65
- }),
66
- "rpc-url": StandardFlags.string({
67
- description: "The RPC endpoint.",
68
- char: "r",
69
- env: "ETH_RPC_URL",
70
- helpGroup: "Ethereum",
71
- }),
72
- "mnemonic-passphrase": StandardFlags.string({
73
- description: "Use a BIP39 passphrase for the mnemonic.",
74
- helpGroup: "Wallet",
75
- }),
76
- "mnemonic-index": StandardFlags.integer({
77
- description: "Use the private key from the given mnemonic index.",
78
- helpGroup: "Wallet",
79
- default: 0,
80
- }),
81
- };
82
- class Send extends Command {
83
- async run() {
84
- // get all send sub-commands
85
- const sendCommands = this.config.commands.filter((command) => command.id.startsWith("send:"));
86
- // select the send sub-command
87
- const commandId = await select({
88
- message: "Select send sub-command",
89
- choices: sendCommands.map((command) => ({
90
- value: command.id,
91
- name: command.summary,
92
- description: command.description,
93
- })),
94
- });
95
- // invoke the sub-command
96
- await this.config.runCommand(commandId, this.argv);
97
- }
98
- }
99
- Send.summary = "Send input to the application.";
100
- Send.description = "Sends different kinds of input to the application in interactive mode.";
101
- Send.examples = ["<%= config.bin %> <%= command.id %>"];
102
- export default Send;