@cartesi/cli 2.0.0-alpha.1 → 2.0.0-alpha.11
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/base.d.ts +18 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +103 -0
- package/dist/builder/directory.d.ts.map +1 -1
- package/dist/builder/docker.d.ts.map +1 -1
- package/dist/builder/empty.d.ts.map +1 -1
- package/dist/builder/none.d.ts.map +1 -1
- package/dist/builder/tar.d.ts.map +1 -1
- package/dist/commands/address-book.d.ts +4 -8
- package/dist/commands/address-book.d.ts.map +1 -1
- package/dist/commands/address-book.js +15 -14
- package/dist/commands/build.d.ts +5 -11
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +16 -28
- package/dist/commands/clean.d.ts +2 -7
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +9 -10
- package/dist/commands/create.d.ts +2 -15
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +7 -64
- package/dist/commands/deploy/build.d.ts +2 -14
- package/dist/commands/deploy/build.d.ts.map +1 -1
- package/dist/commands/deploy/build.js +8 -61
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +12 -0
- package/dist/commands/doctor.d.ts +2 -12
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +96 -91
- package/dist/commands/hash.d.ts +4 -9
- package/dist/commands/hash.d.ts.map +1 -1
- package/dist/commands/hash.js +14 -14
- package/dist/commands/rollups/create.d.ts +7 -0
- package/dist/commands/rollups/create.d.ts.map +1 -0
- package/dist/commands/rollups/create.js +36 -0
- package/dist/commands/rollups/deploy.d.ts +16 -0
- package/dist/commands/rollups/deploy.d.ts.map +1 -0
- package/dist/commands/rollups/deploy.js +237 -0
- package/dist/commands/rollups/logs.d.ts +11 -0
- package/dist/commands/rollups/logs.d.ts.map +1 -0
- package/dist/commands/rollups/logs.js +32 -0
- package/dist/commands/rollups/start.d.ts +14 -0
- package/dist/commands/rollups/start.d.ts.map +1 -0
- package/dist/commands/rollups/start.js +211 -0
- package/dist/commands/rollups/status.d.ts +7 -0
- package/dist/commands/rollups/status.d.ts.map +1 -0
- package/dist/commands/rollups/status.js +46 -0
- package/dist/commands/rollups/stop.d.ts +5 -0
- package/dist/commands/rollups/stop.d.ts.map +1 -0
- package/dist/commands/rollups/stop.js +26 -0
- package/dist/commands/rollups.d.ts +6 -0
- package/dist/commands/rollups.d.ts.map +1 -0
- package/dist/commands/rollups.js +21 -0
- package/dist/commands/run.d.ts +2 -20
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +9 -190
- package/dist/commands/send/erc20.d.ts +11 -13
- package/dist/commands/send/erc20.d.ts.map +1 -1
- package/dist/commands/send/erc20.js +57 -52
- package/dist/commands/send/erc721.d.ts +11 -13
- package/dist/commands/send/erc721.d.ts.map +1 -1
- package/dist/commands/send/erc721.js +51 -46
- package/dist/commands/send/ether.d.ts +11 -12
- package/dist/commands/send/ether.d.ts.map +1 -1
- package/dist/commands/send/ether.js +25 -21
- package/dist/commands/send/generic.d.ts +12 -14
- package/dist/commands/send/generic.d.ts.map +1 -1
- package/dist/commands/send/generic.js +92 -97
- package/dist/commands/send.d.ts +21 -0
- package/dist/commands/send.d.ts.map +1 -0
- package/dist/commands/send.js +67 -0
- package/dist/commands/shell.d.ts +6 -14
- package/dist/commands/shell.d.ts.map +1 -1
- package/dist/commands/shell.js +21 -43
- package/dist/compose/rollups/default.env +34 -0
- package/dist/compose/rollups/docker-compose-anvil.yaml +17 -0
- package/dist/{node → compose/rollups}/docker-compose-bundler.yaml +12 -26
- package/dist/{node → compose/rollups}/docker-compose-database.yaml +4 -2
- package/dist/compose/rollups/docker-compose-espresso.yaml +68 -0
- package/dist/compose/rollups/docker-compose-explorer.yaml +57 -0
- package/dist/compose/rollups/docker-compose-graphql.yaml +23 -0
- package/dist/compose/rollups/docker-compose-node-cpus.yaml +6 -0
- package/dist/compose/rollups/docker-compose-node-memory.yaml +6 -0
- package/dist/compose/rollups/docker-compose-node.yaml +26 -0
- package/dist/compose/rollups/docker-compose-paymaster.yaml +18 -0
- package/dist/compose/rollups/docker-compose-proxy.yaml +24 -0
- package/dist/compose/rollups/proxy/anvil.yaml +17 -0
- package/dist/compose/rollups/proxy/bundler.yaml +17 -0
- package/dist/compose/rollups/proxy/espresso.yaml +17 -0
- package/dist/compose/rollups/proxy/explorer-api.yaml +17 -0
- package/dist/compose/rollups/proxy/explorer.yaml +10 -0
- package/dist/compose/rollups/proxy/graphql.yaml +10 -0
- package/dist/compose/rollups/proxy/paymaster.yaml +17 -0
- package/dist/compose/rollups/proxy/rollups-node.yaml +17 -0
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -17
- package/dist/contracts.d.ts +1695 -1636
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +632 -592
- package/dist/exec/cartesi-machine.d.ts.map +1 -1
- package/dist/exec/crane.d.ts +1 -1
- package/dist/exec/crane.d.ts.map +1 -1
- package/dist/exec/genext2fs.d.ts.map +1 -1
- package/dist/exec/mksquashfs.d.ts.map +1 -1
- package/dist/exec/rollups.d.ts +16 -0
- package/dist/exec/rollups.d.ts.map +1 -0
- package/dist/exec/rollups.js +39 -0
- package/dist/exec/util.d.ts +1 -1
- package/dist/exec/util.d.ts.map +1 -1
- package/dist/exec/util.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -1
- package/dist/machine.d.ts.map +1 -1
- package/dist/prompts.d.ts.map +1 -1
- package/dist/template.d.ts +3 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +16 -0
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +47 -6
- package/package.json +30 -47
- package/bin/dev.cmd +0 -3
- package/bin/dev.js +0 -25
- package/bin/run.cmd +0 -3
- package/bin/run.js +0 -8
- package/dist/baseCommand.d.ts +0 -22
- package/dist/baseCommand.d.ts.map +0 -1
- package/dist/baseCommand.js +0 -92
- package/dist/commands/deploy/index.d.ts +0 -12
- package/dist/commands/deploy/index.d.ts.map +0 -1
- package/dist/commands/deploy/index.js +0 -78
- package/dist/commands/send/index.d.ts +0 -28
- package/dist/commands/send/index.d.ts.map +0 -1
- package/dist/commands/send/index.js +0 -102
- package/dist/flags.d.ts +0 -17
- package/dist/flags.d.ts.map +0 -1
- package/dist/flags.js +0 -28
- package/dist/node/DockerfileDeploy.txt +0 -4
- package/dist/node/default.env +0 -27
- package/dist/node/docker-compose-anvil.yaml +0 -50
- package/dist/node/docker-compose-envfile.yaml +0 -4
- package/dist/node/docker-compose-explorer.yaml +0 -88
- package/dist/node/docker-compose-host.yaml +0 -30
- package/dist/node/docker-compose-paymaster.yaml +0 -33
- package/dist/node/docker-compose-prompt.yaml +0 -17
- package/dist/node/docker-compose-proxy.yaml +0 -48
- package/dist/node/docker-compose-snapshot-volume.yaml +0 -8
- package/dist/node/docker-compose-validator-cpus.yaml +0 -6
- package/dist/node/docker-compose-validator-memory.yaml +0 -6
- package/dist/node/docker-compose-validator.yaml +0 -59
- package/oclif.manifest.json +0 -876
package/dist/commands/doctor.js
CHANGED
|
@@ -1,106 +1,111 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
1
3
|
import { execa } from "execa";
|
|
4
|
+
import ora from "ora";
|
|
2
5
|
import semver from "semver";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
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}.`);
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
else {
|
|
29
|
+
throw e;
|
|
26
30
|
}
|
|
27
|
-
return true;
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
const checkCompose = async (progress) => {
|
|
35
|
+
try {
|
|
36
|
+
progress.start("Checking Docker Compose version...");
|
|
37
|
+
const { stdout: dockerComposeVersion } = await execa("docker", [
|
|
38
|
+
"compose",
|
|
39
|
+
"version",
|
|
40
|
+
"--short",
|
|
41
|
+
]);
|
|
42
|
+
const v = semver.coerce(dockerComposeVersion);
|
|
43
|
+
if (v !== null && !semver.gte(v, MINIMUM_DOCKER_COMPOSE_VERSION)) {
|
|
44
|
+
throw new Error(`Unsupported Docker Compose version. Minimum required version is ${MINIMUM_DOCKER_COMPOSE_VERSION}. Installed version is ${v}.`);
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
progress.succeed(`Docker Compose ${chalk.cyan(dockerComposeVersion)}`);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
if (e instanceof Error &&
|
|
50
|
+
e.exitCode === 125) {
|
|
51
|
+
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/");
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throw e;
|
|
50
55
|
}
|
|
51
|
-
return true;
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"buildx",
|
|
66
|
-
"ls",
|
|
67
|
-
"--format",
|
|
68
|
-
"{{.Platforms}}",
|
|
69
|
-
]);
|
|
70
|
-
const buildxPlatforms = platformsOutput
|
|
71
|
-
.split(",")
|
|
72
|
-
.map((platform) => platform.trim());
|
|
73
|
-
if (!buildxPlatforms.includes("linux/riscv64")) {
|
|
74
|
-
throw new Error("Your system does not support riscv64 architecture. Run `docker run --privileged --rm tonistiigi/binfmt:riscv` to enable riscv64 support.");
|
|
75
|
-
}
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
const checkBuildx = async (progress) => {
|
|
60
|
+
try {
|
|
61
|
+
progress.start("Checking Docker Buildx version...");
|
|
62
|
+
const { stdout: buildxOutput } = await execa("docker", [
|
|
63
|
+
"buildx",
|
|
64
|
+
"version",
|
|
65
|
+
]);
|
|
66
|
+
const v = semver.coerce(buildxOutput);
|
|
67
|
+
if (v !== null && !semver.gte(v, MINIMUM_BUILDX_VERSION)) {
|
|
68
|
+
throw new Error(`Unsupported Docker Buildx version. Minimum required version is ${MINIMUM_BUILDX_VERSION}. Installed version is ${v}.`);
|
|
76
69
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
progress.succeed(`Docker Buildx ${chalk.cyan(v)}`);
|
|
71
|
+
progress.start("Checking Docker RISC-V support...");
|
|
72
|
+
const { stdout: platformsOutput } = await execa("docker", [
|
|
73
|
+
"buildx",
|
|
74
|
+
"ls",
|
|
75
|
+
"--format",
|
|
76
|
+
"{{.Platforms}}",
|
|
77
|
+
]);
|
|
78
|
+
const buildxPlatforms = platformsOutput
|
|
79
|
+
.split(",")
|
|
80
|
+
.map((platform) => platform.trim());
|
|
81
|
+
if (!buildxPlatforms.includes("linux/riscv64")) {
|
|
82
|
+
throw new Error("Your system does not support riscv64 architecture. Run `docker run --privileged --rm tonistiigi/binfmt:riscv` to enable riscv64 support.");
|
|
85
83
|
}
|
|
86
|
-
|
|
84
|
+
progress.succeed(`Docker RISC-V support ${chalk.cyan("linux/riscv64")}`);
|
|
87
85
|
}
|
|
88
|
-
|
|
86
|
+
catch (e) {
|
|
87
|
+
if (e instanceof Error &&
|
|
88
|
+
e.exitCode === 125) {
|
|
89
|
+
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/");
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
export const createDoctorCommand = () => {
|
|
98
|
+
return new Command("doctor").action(async () => {
|
|
99
|
+
const progress = ora();
|
|
89
100
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
await checkDocker(progress);
|
|
102
|
+
await checkCompose(progress);
|
|
103
|
+
await checkBuildx(progress);
|
|
104
|
+
progress.succeed("Your system is ready.");
|
|
94
105
|
}
|
|
95
106
|
catch (e) {
|
|
96
|
-
|
|
107
|
+
progress.fail(e.message);
|
|
108
|
+
process.exit(1);
|
|
97
109
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
DoctorCommand.description = "Verify the minimal sytem requirements";
|
|
102
|
-
DoctorCommand.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
103
|
-
DoctorCommand.MINIMUM_DOCKER_VERSION = "23.0.0"; // Replace with our minimum required Docker version
|
|
104
|
-
DoctorCommand.MINIMUM_DOCKER_COMPOSE_VERSION = "2.21.0"; // Replace with our minimum required Docker Compose version
|
|
105
|
-
DoctorCommand.MINIMUM_BUILDX_VERSION = "0.13.0"; // Replace with our minimum required Buildx version
|
|
106
|
-
export default DoctorCommand;
|
|
110
|
+
});
|
|
111
|
+
};
|
package/dist/commands/hash.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
static enableJsonFlag: boolean;
|
|
6
|
-
run(): Promise<{
|
|
7
|
-
hash: `0x${string}`;
|
|
8
|
-
} | undefined>;
|
|
9
|
-
}
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createHashCommand: () => Command<[], {
|
|
3
|
+
json?: true | undefined;
|
|
4
|
+
}, {}>;
|
|
10
5
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/commands/hash.ts"],"names":[],"mappings":"
|
|
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
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
1
2
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 (!
|
|
8
|
-
|
|
11
|
+
if (!json) {
|
|
12
|
+
console.log(`${chalk.green("?")} Cartesi machine templateHash ${chalk.cyan(hash)}\n`);
|
|
9
13
|
}
|
|
10
14
|
else {
|
|
11
|
-
|
|
15
|
+
process.stdout.write(JSON.stringify({ hash }));
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
else {
|
|
15
|
-
|
|
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,7 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const DEFAULT_TEMPLATES_BRANCH = "prerelease/sdk-12";
|
|
3
|
+
export declare const createCreateCommand: () => Command<[string], {
|
|
4
|
+
template: "cpp" | "cpp-low-level" | "go" | "javascript" | "lua" | "python" | "ruby" | "rust" | "typescript";
|
|
5
|
+
branch: string;
|
|
6
|
+
}, {}>;
|
|
7
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/rollups/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAK9D,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAc5D,eAAO,MAAM,mBAAmB;;;MA+B/B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Command, Option } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { download } from "../../template.js";
|
|
5
|
+
export const DEFAULT_TEMPLATES_BRANCH = "prerelease/sdk-12";
|
|
6
|
+
const TEMPLATES = [
|
|
7
|
+
"cpp",
|
|
8
|
+
"cpp-low-level",
|
|
9
|
+
"go",
|
|
10
|
+
"javascript",
|
|
11
|
+
"lua",
|
|
12
|
+
"python",
|
|
13
|
+
"ruby",
|
|
14
|
+
"rust",
|
|
15
|
+
"typescript",
|
|
16
|
+
];
|
|
17
|
+
export const createCreateCommand = () => {
|
|
18
|
+
return new Command("create")
|
|
19
|
+
.argument("<name>", "application and directory name")
|
|
20
|
+
.addOption(new Option("-t, --template <template>", "template name to use")
|
|
21
|
+
.choices(TEMPLATES)
|
|
22
|
+
.makeOptionMandatory())
|
|
23
|
+
.option("-b, --branch <branch>", "cartesi/application-templates repository branch name to use", DEFAULT_TEMPLATES_BRANCH)
|
|
24
|
+
.action(async (name, { branch, template }) => {
|
|
25
|
+
const spinner = ora("Creating application...").start();
|
|
26
|
+
try {
|
|
27
|
+
const { dir } = await download("rollups", template, branch, name);
|
|
28
|
+
spinner.succeed(`Application created at ${chalk.cyan(dir)}`);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
spinner.fail(e instanceof Error
|
|
32
|
+
? `Error creating application: ${chalk.red(e.message)}`
|
|
33
|
+
: String(e));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createDeployCommand: () => Command<[], {
|
|
3
|
+
chainId: number;
|
|
4
|
+
rpcUrl?: string | undefined;
|
|
5
|
+
mnemonic?: string | undefined;
|
|
6
|
+
mnemonicIndex: number;
|
|
7
|
+
name?: string | undefined;
|
|
8
|
+
authorityOwner?: `0x${string}` | undefined;
|
|
9
|
+
applicationOwner?: `0x${string}` | undefined;
|
|
10
|
+
epochLength: number;
|
|
11
|
+
salt: `0x${string}`;
|
|
12
|
+
json?: true | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
environmentName: string;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/commands/rollups/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAoP9D,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;EAqG/B,CAAC"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Command, Option } from "@commander-js/extra-typings";
|
|
2
|
+
import input from "@inquirer/input";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { execa } from "execa";
|
|
5
|
+
import ora from "ora";
|
|
6
|
+
import { encodeFunctionData, zeroHash, } from "viem";
|
|
7
|
+
import { cannon } from "viem/chains";
|
|
8
|
+
import { getContextPath, getMachineHash, parseAddress, parseHash, } from "../../base.js";
|
|
9
|
+
import { applicationFactoryAbi, applicationFactoryAddress, authorityFactoryAbi, authorityFactoryAddress, dataAvailabilityAbi, inputBoxAddress, } from "../../contracts.js";
|
|
10
|
+
import { addressInput } from "../../prompts.js";
|
|
11
|
+
import { connect } from "../send.js";
|
|
12
|
+
/**
|
|
13
|
+
* Deploy authority contract (if not already deployed)
|
|
14
|
+
* @param options
|
|
15
|
+
* @returns address of the authority
|
|
16
|
+
*/
|
|
17
|
+
const deployAuthority = async (publicClient, walletClient, options) => {
|
|
18
|
+
const { epochLength, progress, salt } = options;
|
|
19
|
+
// deploy authority contract (if not already deployed)
|
|
20
|
+
const authorityOwner = options.authorityOwner ||
|
|
21
|
+
(await addressInput({
|
|
22
|
+
message: "Authority Owner",
|
|
23
|
+
default: walletClient.account?.address,
|
|
24
|
+
}));
|
|
25
|
+
const authorityAddress = await publicClient.readContract({
|
|
26
|
+
abi: authorityFactoryAbi,
|
|
27
|
+
address: authorityFactoryAddress,
|
|
28
|
+
functionName: "calculateAuthorityAddress",
|
|
29
|
+
args: [authorityOwner, BigInt(epochLength), salt],
|
|
30
|
+
});
|
|
31
|
+
// check if authority is already deployed
|
|
32
|
+
const authorityCode = await publicClient.getCode({
|
|
33
|
+
address: authorityAddress,
|
|
34
|
+
});
|
|
35
|
+
if (authorityCode === undefined) {
|
|
36
|
+
// deploy authority
|
|
37
|
+
const { request } = await publicClient.simulateContract({
|
|
38
|
+
abi: authorityFactoryAbi,
|
|
39
|
+
address: authorityFactoryAddress,
|
|
40
|
+
account: walletClient.account,
|
|
41
|
+
functionName: "newAuthority",
|
|
42
|
+
args: [authorityOwner, BigInt(epochLength), salt],
|
|
43
|
+
});
|
|
44
|
+
progress.start("Deploying authority...");
|
|
45
|
+
const hash = await walletClient.writeContract(request);
|
|
46
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
47
|
+
progress.succeed(`Authority ${chalk.cyan(authorityAddress)}`);
|
|
48
|
+
}
|
|
49
|
+
return authorityAddress;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Deploy application contract
|
|
53
|
+
* @param options
|
|
54
|
+
* @returns address of the application
|
|
55
|
+
*/
|
|
56
|
+
const deployApplication = async (publicClient, walletClient, options) => {
|
|
57
|
+
const { authorityAddress, progress, salt, templateHash } = options;
|
|
58
|
+
const applicationOwner = options.applicationOwner ||
|
|
59
|
+
(await addressInput({
|
|
60
|
+
message: "Application Owner",
|
|
61
|
+
default: walletClient.account?.address,
|
|
62
|
+
}));
|
|
63
|
+
// create data availability descriptor for InputBox only
|
|
64
|
+
const dataAvailability = encodeFunctionData({
|
|
65
|
+
abi: dataAvailabilityAbi,
|
|
66
|
+
functionName: "InputBox",
|
|
67
|
+
args: [inputBoxAddress],
|
|
68
|
+
});
|
|
69
|
+
const applicationAddress = await publicClient.readContract({
|
|
70
|
+
abi: applicationFactoryAbi,
|
|
71
|
+
address: applicationFactoryAddress,
|
|
72
|
+
functionName: "calculateApplicationAddress",
|
|
73
|
+
args: [
|
|
74
|
+
authorityAddress,
|
|
75
|
+
applicationOwner,
|
|
76
|
+
templateHash,
|
|
77
|
+
dataAvailability,
|
|
78
|
+
salt,
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
// check if application is already deployed
|
|
82
|
+
const applicationCode = await publicClient.getCode({
|
|
83
|
+
address: applicationAddress,
|
|
84
|
+
});
|
|
85
|
+
if (applicationCode === undefined) {
|
|
86
|
+
// deploy application
|
|
87
|
+
const { request } = await publicClient.simulateContract({
|
|
88
|
+
abi: applicationFactoryAbi,
|
|
89
|
+
address: applicationFactoryAddress,
|
|
90
|
+
account: walletClient.account,
|
|
91
|
+
functionName: "newApplication",
|
|
92
|
+
args: [
|
|
93
|
+
authorityAddress,
|
|
94
|
+
applicationOwner,
|
|
95
|
+
templateHash,
|
|
96
|
+
dataAvailability,
|
|
97
|
+
salt,
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
progress.start("Deploying application...");
|
|
101
|
+
const hash = await walletClient.writeContract(request);
|
|
102
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
103
|
+
progress.succeed(`Application ${chalk.cyan(applicationAddress)}`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// abort, because application is already deployed
|
|
107
|
+
throw new Error(`Application ${chalk.cyan(templateHash)} already deployed to ${chalk.cyan(applicationAddress)}`);
|
|
108
|
+
}
|
|
109
|
+
return applicationAddress;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Publish machine snapshot to rollups node by copying it to the rollups node container
|
|
113
|
+
* @param options
|
|
114
|
+
* @returns path to the snapshot in the rollups node
|
|
115
|
+
*/
|
|
116
|
+
const publishMachine = async (options) => {
|
|
117
|
+
const { progress, environmentName, templateHash } = options;
|
|
118
|
+
const snapshotPath = getContextPath("image");
|
|
119
|
+
const containerSnapshotPath = `/var/lib/cartesi-rollups-node/snapshots/${templateHash}/`;
|
|
120
|
+
progress.start("Publishing machine snapshot...");
|
|
121
|
+
await execa("docker", [
|
|
122
|
+
"compose",
|
|
123
|
+
"--project-name",
|
|
124
|
+
environmentName,
|
|
125
|
+
"cp",
|
|
126
|
+
snapshotPath,
|
|
127
|
+
`rollups-node:${containerSnapshotPath}`,
|
|
128
|
+
]);
|
|
129
|
+
progress.succeed(`Machine snapshot ${chalk.cyan(containerSnapshotPath)}`);
|
|
130
|
+
return containerSnapshotPath;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Register application in rollups node
|
|
134
|
+
* @param options
|
|
135
|
+
* @returns name of the application
|
|
136
|
+
*/
|
|
137
|
+
const registerApplication = async (options) => {
|
|
138
|
+
const { applicationAddress, progress, environmentName, snapshotPath } = options;
|
|
139
|
+
// use template hash as the name of the deployment
|
|
140
|
+
const name = options.name ??
|
|
141
|
+
(await input({
|
|
142
|
+
message: "Application Name",
|
|
143
|
+
default: applicationAddress.toLowerCase(),
|
|
144
|
+
}));
|
|
145
|
+
// deploy application
|
|
146
|
+
progress.start("Registering application...");
|
|
147
|
+
const { stdout } = await execa("docker", [
|
|
148
|
+
"compose",
|
|
149
|
+
"--project-name",
|
|
150
|
+
environmentName,
|
|
151
|
+
"exec",
|
|
152
|
+
"rollups-node",
|
|
153
|
+
"cartesi-rollups-cli",
|
|
154
|
+
"app",
|
|
155
|
+
"register",
|
|
156
|
+
"--name",
|
|
157
|
+
name,
|
|
158
|
+
"--address",
|
|
159
|
+
applicationAddress,
|
|
160
|
+
"--template-path",
|
|
161
|
+
snapshotPath,
|
|
162
|
+
"--print-json",
|
|
163
|
+
]);
|
|
164
|
+
const registration = stdout ? JSON.parse(stdout) : undefined;
|
|
165
|
+
if (registration) {
|
|
166
|
+
if (registration.state !== "ENABLED") {
|
|
167
|
+
throw new Error(registration.reason);
|
|
168
|
+
}
|
|
169
|
+
progress.succeed(`Registration ${chalk.cyan(name)}`);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw new Error("Failed to deploy application");
|
|
173
|
+
}
|
|
174
|
+
return name;
|
|
175
|
+
};
|
|
176
|
+
export const createDeployCommand = () => {
|
|
177
|
+
return new Command("deploy")
|
|
178
|
+
.description("Deploy a rollups application to a rollups node.")
|
|
179
|
+
.configureHelp({ showGlobalOptions: true })
|
|
180
|
+
.option("--chain-id <id>", "Chain ID", parseInt, 13370)
|
|
181
|
+
.option("--rpc-url <url>", "RPC URL")
|
|
182
|
+
.option("--mnemonic <phrase>", "Mnemonic passphrase")
|
|
183
|
+
.option("--mnemonic-index <index>", "Mnemonic account index", parseInt, 0)
|
|
184
|
+
.option("--name <string>", "application name")
|
|
185
|
+
.option("--authority-owner <address>", "authority owner", parseAddress, undefined)
|
|
186
|
+
.option("--application-owner <address>", "application owner", parseAddress, undefined)
|
|
187
|
+
.addOption(new Option("--epoch-length <number>", "length of an epoch (in blocks)")
|
|
188
|
+
.argParser(Number)
|
|
189
|
+
.default(720))
|
|
190
|
+
.option("--salt <hash>", "salt for deployment", parseHash, zeroHash)
|
|
191
|
+
.option("--json", "output in JSON format")
|
|
192
|
+
.action(async (options, command) => {
|
|
193
|
+
const rollupsOptions = command.optsWithGlobals();
|
|
194
|
+
const { environmentName } = rollupsOptions;
|
|
195
|
+
const { json } = options;
|
|
196
|
+
// XXX: json support is not implemented yet
|
|
197
|
+
// if case of json maybe we should not support interactive mode
|
|
198
|
+
const progress = ora();
|
|
199
|
+
// get cartesi machine snapshot hash, produced by 'build'
|
|
200
|
+
const templateHash = getMachineHash();
|
|
201
|
+
if (!templateHash) {
|
|
202
|
+
progress.fail(`Cartesi machine snapshot not found, run 'build'`);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
progress.succeed(`Cartesi machine template hash ${chalk.cyan(templateHash)}`);
|
|
206
|
+
// connect to some chain
|
|
207
|
+
const { publicClient, walletClient } = await connect(options);
|
|
208
|
+
try {
|
|
209
|
+
// deploy authority contract (if not already deployed)
|
|
210
|
+
const authorityAddress = await deployAuthority(publicClient, walletClient, { progress, ...options });
|
|
211
|
+
// deploy application contract
|
|
212
|
+
const applicationAddress = await deployApplication(publicClient, walletClient, { authorityAddress, progress, templateHash, ...options });
|
|
213
|
+
if (publicClient.chain?.id === cannon.id) {
|
|
214
|
+
// copy machine snapshot to rollups node container
|
|
215
|
+
const containerSnapshotPath = await publishMachine({
|
|
216
|
+
progress,
|
|
217
|
+
templateHash,
|
|
218
|
+
environmentName,
|
|
219
|
+
});
|
|
220
|
+
const name = await registerApplication({
|
|
221
|
+
applicationAddress,
|
|
222
|
+
progress,
|
|
223
|
+
snapshotPath: containerSnapshotPath,
|
|
224
|
+
...options,
|
|
225
|
+
...rollupsOptions,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const snapshotPath = getContextPath("image");
|
|
230
|
+
progress.succeed(`Done. Manually copy machine to rollups node ${chalk.cyan(snapshotPath)}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
progress.fail(e instanceof Error ? e.message : "Unknown error");
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createLogsCommand: () => Command<[], {
|
|
3
|
+
follow?: true | undefined;
|
|
4
|
+
color: boolean;
|
|
5
|
+
since?: string | undefined;
|
|
6
|
+
tail: string;
|
|
7
|
+
until?: string | undefined;
|
|
8
|
+
}, {
|
|
9
|
+
environmentName: string;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=logs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../../src/commands/rollups/logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,iBAAiB;;;;;;;;EAuC7B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
export const createLogsCommand = () => {
|
|
4
|
+
return new Command("logs")
|
|
5
|
+
.description("Show logs of a local rollups node environment.")
|
|
6
|
+
.option("-f, --follow", "Follow log output")
|
|
7
|
+
.option("--no-color", "Produce monochrome output")
|
|
8
|
+
.option("--since <string>", "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)")
|
|
9
|
+
.option("-n, --tail <string>", "Number of lines to show from the end of the logs", "all")
|
|
10
|
+
.option("--until <string>", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)")
|
|
11
|
+
.configureHelp({ showGlobalOptions: true })
|
|
12
|
+
.action(async ({ follow, color, since, tail, until }, command) => {
|
|
13
|
+
const { environmentName } = command.optsWithGlobals();
|
|
14
|
+
const logOptions = ["--no-log-prefix"];
|
|
15
|
+
if (follow)
|
|
16
|
+
logOptions.push("--follow");
|
|
17
|
+
if (color === false)
|
|
18
|
+
logOptions.push("--no-color");
|
|
19
|
+
if (since)
|
|
20
|
+
logOptions.push("--since", since);
|
|
21
|
+
if (tail)
|
|
22
|
+
logOptions.push("--tail", tail);
|
|
23
|
+
await execa("docker", [
|
|
24
|
+
"compose",
|
|
25
|
+
"--project-name",
|
|
26
|
+
environmentName,
|
|
27
|
+
"logs",
|
|
28
|
+
...logOptions,
|
|
29
|
+
"rollups-node",
|
|
30
|
+
], { stdio: "inherit" });
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createStartCommand: () => Command<[], {
|
|
3
|
+
blockTime: number;
|
|
4
|
+
defaultBlock: "latest" | "pending" | "safe" | "finalized";
|
|
5
|
+
cpus?: number | undefined;
|
|
6
|
+
memory?: number | undefined;
|
|
7
|
+
services: string[];
|
|
8
|
+
port: number;
|
|
9
|
+
dryRun: boolean;
|
|
10
|
+
verbose: boolean;
|
|
11
|
+
}, {
|
|
12
|
+
environmentName: string;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/commands/rollups/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AA4I9D,eAAO,MAAM,kBAAkB;;;;;;;;;;;EAkK9B,CAAC"}
|