@cartesi/cli 2.0.0-alpha.21 → 2.0.0-alpha.23
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.
- package/dist/index.js +685 -50
- package/dist/index.js.map +785 -0
- package/package.json +80 -84
- package/LICENSE +0 -202
- package/dist/base.d.ts +0 -28
- package/dist/base.d.ts.map +0 -1
- package/dist/base.js +0 -109
- package/dist/builder/directory.d.ts +0 -3
- package/dist/builder/directory.d.ts.map +0 -1
- package/dist/builder/directory.js +0 -39
- package/dist/builder/docker.d.ts +0 -10
- package/dist/builder/docker.d.ts.map +0 -1
- package/dist/builder/docker.js +0 -114
- package/dist/builder/empty.d.ts +0 -3
- package/dist/builder/empty.d.ts.map +0 -1
- package/dist/builder/empty.js +0 -21
- package/dist/builder/index.d.ts +0 -6
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/index.js +0 -5
- package/dist/builder/none.d.ts +0 -3
- package/dist/builder/none.d.ts.map +0 -1
- package/dist/builder/none.js +0 -11
- package/dist/builder/tar.d.ts +0 -3
- package/dist/builder/tar.d.ts.map +0 -1
- package/dist/builder/tar.js +0 -30
- package/dist/commands/address-book.d.ts +0 -6
- package/dist/commands/address-book.d.ts.map +0 -1
- package/dist/commands/address-book.js +0 -44
- package/dist/commands/build.d.ts +0 -8
- package/dist/commands/build.d.ts.map +0 -1
- package/dist/commands/build.js +0 -97
- package/dist/commands/clean.d.ts +0 -3
- package/dist/commands/clean.d.ts.map +0 -1
- package/dist/commands/clean.js +0 -10
- package/dist/commands/create.d.ts +0 -7
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -37
- package/dist/commands/deploy/build.d.ts +0 -3
- package/dist/commands/deploy/build.d.ts.map +0 -1
- package/dist/commands/deploy/build.js +0 -9
- package/dist/commands/deploy.d.ts +0 -3
- package/dist/commands/deploy.d.ts.map +0 -1
- package/dist/commands/deploy.js +0 -12
- package/dist/commands/deposit/erc1155.d.ts +0 -18
- package/dist/commands/deposit/erc1155.d.ts.map +0 -1
- package/dist/commands/deposit/erc1155.js +0 -254
- package/dist/commands/deposit/erc20.d.ts +0 -10
- package/dist/commands/deposit/erc20.d.ts.map +0 -1
- package/dist/commands/deposit/erc20.js +0 -125
- package/dist/commands/deposit/erc721.d.ts +0 -10
- package/dist/commands/deposit/erc721.d.ts.map +0 -1
- package/dist/commands/deposit/erc721.js +0 -143
- package/dist/commands/deposit/ether.d.ts +0 -10
- package/dist/commands/deposit/ether.d.ts.map +0 -1
- package/dist/commands/deposit/ether.js +0 -65
- package/dist/commands/deposit.d.ts +0 -9
- package/dist/commands/deposit.d.ts.map +0 -1
- package/dist/commands/deposit.js +0 -37
- package/dist/commands/doctor.d.ts +0 -3
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -105
- package/dist/commands/hash.d.ts +0 -5
- package/dist/commands/hash.d.ts.map +0 -1
- package/dist/commands/hash.js +0 -22
- package/dist/commands/logs.d.ts +0 -9
- package/dist/commands/logs.d.ts.map +0 -1
- package/dist/commands/logs.js +0 -34
- package/dist/commands/run.d.ts +0 -15
- package/dist/commands/run.d.ts.map +0 -1
- package/dist/commands/run.js +0 -202
- package/dist/commands/send.d.ts +0 -10
- package/dist/commands/send.d.ts.map +0 -1
- package/dist/commands/send.js +0 -130
- package/dist/commands/shell.d.ts +0 -7
- package/dist/commands/shell.d.ts.map +0 -1
- package/dist/commands/shell.js +0 -48
- package/dist/commands/status.d.ts +0 -6
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -50
- package/dist/compose/default.env +0 -36
- package/dist/compose/docker-compose-anvil.yaml +0 -39
- package/dist/compose/docker-compose-bundler.yaml +0 -71
- package/dist/compose/docker-compose-database.yaml +0 -12
- package/dist/compose/docker-compose-explorer.yaml +0 -96
- package/dist/compose/docker-compose-node-cpus.yaml +0 -6
- package/dist/compose/docker-compose-node-memory.yaml +0 -6
- package/dist/compose/docker-compose-node.yaml +0 -50
- package/dist/compose/docker-compose-passkey-server.yaml +0 -37
- package/dist/compose/docker-compose-paymaster.yaml +0 -40
- package/dist/compose/docker-compose-proxy.yaml +0 -24
- package/dist/config.d.ts +0 -124
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -418
- package/dist/contracts.d.ts +0 -4376
- package/dist/contracts.d.ts.map +0 -1
- package/dist/contracts.js +0 -1839
- package/dist/exec/cartesi-machine.d.ts +0 -9
- package/dist/exec/cartesi-machine.d.ts.map +0 -1
- package/dist/exec/cartesi-machine.js +0 -18
- package/dist/exec/genext2fs.d.ts +0 -31
- package/dist/exec/genext2fs.d.ts.map +0 -1
- package/dist/exec/genext2fs.js +0 -44
- package/dist/exec/index.d.ts +0 -4
- package/dist/exec/index.d.ts.map +0 -1
- package/dist/exec/index.js +0 -3
- package/dist/exec/mksquashfs.d.ts +0 -21
- package/dist/exec/mksquashfs.d.ts.map +0 -1
- package/dist/exec/mksquashfs.js +0 -47
- package/dist/exec/rollups.d.ts +0 -105
- package/dist/exec/rollups.d.ts.map +0 -1
- package/dist/exec/rollups.js +0 -375
- package/dist/exec/util.d.ts +0 -21
- package/dist/exec/util.d.ts.map +0 -1
- package/dist/exec/util.js +0 -31
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/machine.d.ts +0 -12
- package/dist/machine.d.ts.map +0 -1
- package/dist/machine.js +0 -90
- package/dist/prompts.d.ts +0 -73
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -192
- package/dist/template.d.ts +0 -3
- package/dist/template.d.ts.map +0 -1
- package/dist/template.js +0 -16
- package/dist/types/docker.d.ts +0 -22
- package/dist/types/docker.d.ts.map +0 -1
- package/dist/types/docker.js +0 -1
- package/dist/wallet.d.ts +0 -9225
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -41
package/dist/commands/deposit.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Command } from "@commander-js/extra-typings";
|
|
2
|
-
import select from "@inquirer/select";
|
|
3
|
-
import { createErc1155BatchCommand, createErc1155SingleCommand, } from "./deposit/erc1155.js";
|
|
4
|
-
import { createErc20Command } from "./deposit/erc20.js";
|
|
5
|
-
import { createErc721Command } from "./deposit/erc721.js";
|
|
6
|
-
import { createEtherCommand } from "./deposit/ether.js";
|
|
7
|
-
export const createDepositCommand = () => {
|
|
8
|
-
const command = new Command("deposit")
|
|
9
|
-
.description("Deposits an asset to the application")
|
|
10
|
-
.configureHelp({ showGlobalOptions: true })
|
|
11
|
-
.option("--from <address>", "input sender address")
|
|
12
|
-
.option("--application <address>", "application address")
|
|
13
|
-
.option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
|
|
14
|
-
.option("--rpc-url <url>", "RPC URL of the Cartesi Devnet")
|
|
15
|
-
.action(async (_options, command) => {
|
|
16
|
-
// get registered subcommands
|
|
17
|
-
const commands = command.commands;
|
|
18
|
-
// create choices for the selected prompt based on registered subcommands
|
|
19
|
-
const choices = commands.map((cmd) => ({
|
|
20
|
-
name: cmd.name(),
|
|
21
|
-
value: cmd,
|
|
22
|
-
description: cmd.description(),
|
|
23
|
-
}));
|
|
24
|
-
const subcommand = await select({
|
|
25
|
-
choices,
|
|
26
|
-
message: "Select type of asset to deposit",
|
|
27
|
-
});
|
|
28
|
-
// execute selected subcommand
|
|
29
|
-
subcommand.parseAsync(command.args);
|
|
30
|
-
});
|
|
31
|
-
command.addCommand(createEtherCommand());
|
|
32
|
-
command.addCommand(createErc20Command());
|
|
33
|
-
command.addCommand(createErc721Command());
|
|
34
|
-
command.addCommand(createErc1155SingleCommand());
|
|
35
|
-
command.addCommand(createErc1155BatchCommand());
|
|
36
|
-
return command;
|
|
37
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAyHtD,eAAO,MAAM,mBAAmB,2BAa/B,CAAC"}
|
package/dist/commands/doctor.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Command } from "@commander-js/extra-typings";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { execa } from "execa";
|
|
4
|
-
import ora from "ora";
|
|
5
|
-
import semver from "semver";
|
|
6
|
-
const MINIMUM_DOCKER_VERSION = "23.0.0"; // Replace with our minimum required Docker version
|
|
7
|
-
const MINIMUM_DOCKER_COMPOSE_VERSION = "2.21.0"; // Replace with our minimum required Docker Compose version
|
|
8
|
-
const MINIMUM_BUILDX_VERSION = "0.13.0"; // Replace with our minimum required Buildx version
|
|
9
|
-
const checkDocker = async (progress) => {
|
|
10
|
-
try {
|
|
11
|
-
progress.start("Checking Docker Engine version...");
|
|
12
|
-
const { stdout: dockerVersion } = await execa("docker", [
|
|
13
|
-
"version",
|
|
14
|
-
"--format",
|
|
15
|
-
"{{json .Client.Version}}",
|
|
16
|
-
]);
|
|
17
|
-
const v = semver.coerce(dockerVersion);
|
|
18
|
-
if (v !== null && !semver.gte(v, MINIMUM_DOCKER_VERSION)) {
|
|
19
|
-
throw new Error(`Unsupported Docker version. Minimum required version is ${MINIMUM_DOCKER_VERSION}. Installed version is ${v}.`);
|
|
20
|
-
}
|
|
21
|
-
progress.succeed(`Docker Engine ${chalk.cyan(v)}`);
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
if (e instanceof Error &&
|
|
25
|
-
e.code === "ENOENT") {
|
|
26
|
-
throw new Error("Docker not found");
|
|
27
|
-
}
|
|
28
|
-
throw e;
|
|
29
|
-
}
|
|
30
|
-
return true;
|
|
31
|
-
};
|
|
32
|
-
const checkCompose = async (progress) => {
|
|
33
|
-
try {
|
|
34
|
-
progress.start("Checking Docker Compose version...");
|
|
35
|
-
const { stdout: dockerComposeVersion } = await execa("docker", [
|
|
36
|
-
"compose",
|
|
37
|
-
"version",
|
|
38
|
-
"--short",
|
|
39
|
-
]);
|
|
40
|
-
const v = semver.coerce(dockerComposeVersion);
|
|
41
|
-
if (v !== null && !semver.gte(v, MINIMUM_DOCKER_COMPOSE_VERSION)) {
|
|
42
|
-
throw new Error(`Unsupported Docker Compose version. Minimum required version is ${MINIMUM_DOCKER_COMPOSE_VERSION}. Installed version is ${v}.`);
|
|
43
|
-
}
|
|
44
|
-
progress.succeed(`Docker Compose ${chalk.cyan(dockerComposeVersion)}`);
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
if (e instanceof Error &&
|
|
48
|
-
e.exitCode === 125) {
|
|
49
|
-
throw new Error("Docker Compose is required but not installed or the command execution failed. Please refer to the Docker Compose documentation for installation instructions: https://docs.docker.com/compose/install/");
|
|
50
|
-
}
|
|
51
|
-
throw e;
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
};
|
|
55
|
-
const checkBuildx = async (progress) => {
|
|
56
|
-
try {
|
|
57
|
-
progress.start("Checking Docker Buildx version...");
|
|
58
|
-
const { stdout: buildxOutput } = await execa("docker", [
|
|
59
|
-
"buildx",
|
|
60
|
-
"version",
|
|
61
|
-
]);
|
|
62
|
-
const v = semver.coerce(buildxOutput);
|
|
63
|
-
if (v !== null && !semver.gte(v, MINIMUM_BUILDX_VERSION)) {
|
|
64
|
-
throw new Error(`Unsupported Docker Buildx version. Minimum required version is ${MINIMUM_BUILDX_VERSION}. Installed version is ${v}.`);
|
|
65
|
-
}
|
|
66
|
-
progress.succeed(`Docker Buildx ${chalk.cyan(v)}`);
|
|
67
|
-
progress.start("Checking Docker RISC-V support...");
|
|
68
|
-
const { stdout: platformsOutput } = await execa("docker", [
|
|
69
|
-
"buildx",
|
|
70
|
-
"ls",
|
|
71
|
-
"--format",
|
|
72
|
-
"{{.Platforms}}",
|
|
73
|
-
]);
|
|
74
|
-
const buildxPlatforms = platformsOutput
|
|
75
|
-
.split(",")
|
|
76
|
-
.map((platform) => platform.trim());
|
|
77
|
-
if (!buildxPlatforms.includes("linux/riscv64")) {
|
|
78
|
-
throw new Error("Your system does not support riscv64 architecture. Run `docker run --privileged --rm tonistiigi/binfmt:riscv` to enable riscv64 support.");
|
|
79
|
-
}
|
|
80
|
-
progress.succeed(`Docker RISC-V support ${chalk.cyan("linux/riscv64")}`);
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
if (e instanceof Error &&
|
|
84
|
-
e.exitCode === 125) {
|
|
85
|
-
throw new Error("Docker Buildx is required but not installed. Please refer to the Docker Desktop documentation for installation instructions: https://docs.docker.com/desktop/");
|
|
86
|
-
}
|
|
87
|
-
throw e;
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
};
|
|
91
|
-
export const createDoctorCommand = () => {
|
|
92
|
-
return new Command("doctor").action(async () => {
|
|
93
|
-
const progress = ora();
|
|
94
|
-
try {
|
|
95
|
-
await checkDocker(progress);
|
|
96
|
-
await checkCompose(progress);
|
|
97
|
-
await checkBuildx(progress);
|
|
98
|
-
progress.succeed("Your system is ready.");
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
progress.fail(e.message);
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
};
|
package/dist/commands/hash.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/commands/hash.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Command } from "@commander-js/extra-typings";
|
|
2
|
-
import chalk from "chalk";
|
|
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();
|
|
10
|
-
if (hash) {
|
|
11
|
-
if (!json) {
|
|
12
|
-
console.log(`${chalk.green("?")} Cartesi machine templateHash ${chalk.cyan(hash)}\n`);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
process.stdout.write(JSON.stringify({ hash }));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
command.error(`Cartesi machine snapshot not found, run 'build'`);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
package/dist/commands/logs.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/commands/logs.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/commands/run.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}, {}>;
|
|
15
|
-
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/commands/run.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
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
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
if (error instanceof ExitPromptError) {
|
|
84
|
-
// gracefully exit
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
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'`));
|
|
144
|
-
}
|
|
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,
|
|
160
|
-
projectName,
|
|
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;
|
|
169
|
-
}
|
|
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`);
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
progress.fail(e instanceof Error ? e.message : "Unknown error");
|
|
186
|
-
}
|
|
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
|
-
});
|
|
202
|
-
};
|
package/dist/commands/send.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/commands/send.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Command, Option } from "@commander-js/extra-typings";
|
|
2
|
-
import ora from "ora";
|
|
3
|
-
import { encodeAbiParameters, getAddress, isAddress, isHex, parseAbiParameters, stringToHex, } from "viem";
|
|
4
|
-
import { getProjectName } from "../base.js";
|
|
5
|
-
import { inputBoxAbi, inputBoxAddress } from "../contracts.js";
|
|
6
|
-
import { bytesInput, getInputApplicationAddress } from "../prompts.js";
|
|
7
|
-
import { connect } from "../wallet.js";
|
|
8
|
-
const getInput = async (input, options) => {
|
|
9
|
-
const { encoding } = options;
|
|
10
|
-
if (input) {
|
|
11
|
-
if (encoding === "hex") {
|
|
12
|
-
// validate if is a hex value
|
|
13
|
-
if (!isHex(input)) {
|
|
14
|
-
throw new Error("input encoded as hex must start with 0x");
|
|
15
|
-
}
|
|
16
|
-
return input;
|
|
17
|
-
}
|
|
18
|
-
if (encoding === "string") {
|
|
19
|
-
// encode UTF-8 string as hex
|
|
20
|
-
return stringToHex(input);
|
|
21
|
-
}
|
|
22
|
-
if (encoding === "abi") {
|
|
23
|
-
const abiParams = options.abiParams;
|
|
24
|
-
if (!abiParams) {
|
|
25
|
-
throw new Error("Undefined input-abi-params");
|
|
26
|
-
}
|
|
27
|
-
const abiParameters = parseAbiParameters(abiParams);
|
|
28
|
-
// TODO: decode values
|
|
29
|
-
const values = input.split(",").map((v, index) => {
|
|
30
|
-
if (index >= abiParameters.length) {
|
|
31
|
-
throw new Error(`Too many values, expected ${abiParameters.length} values based on --input-abi-params '${abiParams}', parsing value at index ${index} from input '${input}'`);
|
|
32
|
-
}
|
|
33
|
-
const param = abiParameters[index];
|
|
34
|
-
switch (param.type) {
|
|
35
|
-
case "string":
|
|
36
|
-
return v;
|
|
37
|
-
case "bool":
|
|
38
|
-
if (v === "true")
|
|
39
|
-
return true;
|
|
40
|
-
if (v === "false")
|
|
41
|
-
return false;
|
|
42
|
-
throw new Error(`Invalid boolean value: ${v}`);
|
|
43
|
-
case "uint":
|
|
44
|
-
case "uint8":
|
|
45
|
-
case "uint16":
|
|
46
|
-
case "uint32":
|
|
47
|
-
case "uint64":
|
|
48
|
-
case "uint128":
|
|
49
|
-
case "uint256":
|
|
50
|
-
try {
|
|
51
|
-
return BigInt(v);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
throw new Error(`Invalid uint value: ${v}`);
|
|
55
|
-
}
|
|
56
|
-
case "bytes":
|
|
57
|
-
if (isHex(v)) {
|
|
58
|
-
return v;
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`Invalid bytes value: ${v}`);
|
|
61
|
-
case "address":
|
|
62
|
-
if (isAddress(v)) {
|
|
63
|
-
return getAddress(v);
|
|
64
|
-
}
|
|
65
|
-
throw new Error(`Invalid address value: ${v}`);
|
|
66
|
-
default:
|
|
67
|
-
throw new Error(`Unsupported type ${param.type}`);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
if (values.length !== abiParameters.length) {
|
|
71
|
-
throw new Error(`Not enough values, expected ${abiParameters.length} values based on --input-abi-params '${abiParams}', parsed ${values.length} values from input '${input}'`);
|
|
72
|
-
}
|
|
73
|
-
return encodeAbiParameters(abiParameters, values);
|
|
74
|
-
}
|
|
75
|
-
if (isHex(input)) {
|
|
76
|
-
// encoding not specified, if starts with 0x, assume hex
|
|
77
|
-
return input;
|
|
78
|
-
}
|
|
79
|
-
// encode UTF-8 string as hex
|
|
80
|
-
return stringToHex(input);
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
};
|
|
84
|
-
export const createSendCommand = () => {
|
|
85
|
-
const command = new Command("send")
|
|
86
|
-
.description("Send input to the application")
|
|
87
|
-
.argument("[input]", "input payload")
|
|
88
|
-
.option("--from <address>", "input sender address")
|
|
89
|
-
.option("--application <address>", "application address")
|
|
90
|
-
.addOption(new Option("--encoding <encoding>", "input encoding").choices([
|
|
91
|
-
"hex",
|
|
92
|
-
"string",
|
|
93
|
-
"abi",
|
|
94
|
-
]))
|
|
95
|
-
.option("--abi-params <abi-params>", "input abi params")
|
|
96
|
-
.option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
|
|
97
|
-
.option("--rpc-url <url>", "RPC URL of the Cartesi Devnet")
|
|
98
|
-
.action(async (input, options) => {
|
|
99
|
-
const { application, from } = options;
|
|
100
|
-
const projectName = getProjectName(options);
|
|
101
|
-
// connect to anvil
|
|
102
|
-
const testClient = await connect(options);
|
|
103
|
-
// the input sender, impersonated
|
|
104
|
-
const account = from && isAddress(from)
|
|
105
|
-
? getAddress(from)
|
|
106
|
-
: (await testClient.getAddresses())[0];
|
|
107
|
-
// get dapp address from local node, or ask
|
|
108
|
-
const applicationAddress = await getInputApplicationAddress({
|
|
109
|
-
application,
|
|
110
|
-
projectName,
|
|
111
|
-
});
|
|
112
|
-
const payload = (await getInput(input, options)) ||
|
|
113
|
-
(await bytesInput({
|
|
114
|
-
encoding: options.encoding,
|
|
115
|
-
message: "Input",
|
|
116
|
-
}));
|
|
117
|
-
const { request } = await testClient.simulateContract({
|
|
118
|
-
address: inputBoxAddress,
|
|
119
|
-
abi: inputBoxAbi,
|
|
120
|
-
account,
|
|
121
|
-
args: [applicationAddress, payload],
|
|
122
|
-
functionName: "addInput",
|
|
123
|
-
});
|
|
124
|
-
const hash = await testClient.writeContract(request);
|
|
125
|
-
const progress = ora("Sending input...").start();
|
|
126
|
-
await testClient.waitForTransactionReceipt({ hash });
|
|
127
|
-
progress.succeed(`Input sent: ${hash}`);
|
|
128
|
-
});
|
|
129
|
-
return command;
|
|
130
|
-
};
|
package/dist/commands/shell.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,kBAAkB;;;;MAuD9B,CAAC"}
|
package/dist/commands/shell.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Command } from "@commander-js/extra-typings";
|
|
2
|
-
import { ExecaError } from "execa";
|
|
3
|
-
import fs from "fs-extra";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { getApplicationConfig, getContextPath } from "../base.js";
|
|
6
|
-
import { bootMachine } from "../machine.js";
|
|
7
|
-
export const createShellCommand = () => {
|
|
8
|
-
return new Command("shell")
|
|
9
|
-
.option("--command <command>", "shell command to run", "/bin/sh")
|
|
10
|
-
.option("-c, --config <config>", "path to the configuration file", (value, prev) => prev.concat([value]), ["cartesi.toml"])
|
|
11
|
-
.option("--run-as-root", "run as root user", false)
|
|
12
|
-
.action(async (options) => {
|
|
13
|
-
const { command, runAsRoot } = options;
|
|
14
|
-
// get application configuration from 'cartesi.toml'
|
|
15
|
-
const config = getApplicationConfig(options.config);
|
|
16
|
-
// destination directory for image and intermediate files
|
|
17
|
-
const destination = path.resolve(getContextPath());
|
|
18
|
-
// check if all drives are built
|
|
19
|
-
for (const [name, drive] of Object.entries(config.drives)) {
|
|
20
|
-
const filename = `${name}.${drive.format}`;
|
|
21
|
-
const pathname = getContextPath(filename);
|
|
22
|
-
if (!fs.existsSync(pathname)) {
|
|
23
|
-
throw new Error(`drive '${name}' not built, run 'build'`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
// create shell entrypoint
|
|
27
|
-
config.machine.entrypoint = command;
|
|
28
|
-
// run as root if flag is set
|
|
29
|
-
config.machine.user = runAsRoot ? "root" : undefined;
|
|
30
|
-
// boot machine
|
|
31
|
-
try {
|
|
32
|
-
await bootMachine(config, undefined, { interactive: true }, // start with interactive mode on
|
|
33
|
-
{
|
|
34
|
-
cwd: destination,
|
|
35
|
-
stdio: "inherit",
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
if (error instanceof ExecaError) {
|
|
40
|
-
// just continue gracefully
|
|
41
|
-
if (error.exitCode === 130) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
};
|