@cartesi/cli 2.0.0-alpha.21 → 2.0.0-alpha.22
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/exec/rollups.js
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { execa } from "execa";
|
|
3
|
-
import { Listr } from "listr2";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import pRetry from "p-retry";
|
|
6
|
-
import { getAddress, hexToNumber, } from "viem";
|
|
7
|
-
import { getContextPath, getMachineHash, getProjectName, getServiceHealth, } from "../base.js";
|
|
8
|
-
import { DEFAULT_SDK_IMAGE } from "../config.js";
|
|
9
|
-
const parseDeployment = (deployment) => ({
|
|
10
|
-
address: deployment.iapplication_address,
|
|
11
|
-
consensus: deployment.iconsensus_address,
|
|
12
|
-
epochLength: hexToNumber(deployment.epoch_length),
|
|
13
|
-
name: deployment.name,
|
|
14
|
-
state: deployment.state,
|
|
15
|
-
templateHash: deployment.template_hash,
|
|
16
|
-
});
|
|
17
|
-
export const getDeployments = async (options) => {
|
|
18
|
-
try {
|
|
19
|
-
const { stdout } = await execa("docker", [
|
|
20
|
-
"compose",
|
|
21
|
-
"--project-name",
|
|
22
|
-
options.projectName,
|
|
23
|
-
"exec",
|
|
24
|
-
"rollups-node",
|
|
25
|
-
"cartesi-rollups-cli",
|
|
26
|
-
"app",
|
|
27
|
-
"list",
|
|
28
|
-
]);
|
|
29
|
-
return JSON.parse(stdout).map(parseDeployment);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
export const getApplicationDeployment = async (options) => {
|
|
36
|
-
const machineHash = getMachineHash();
|
|
37
|
-
if (!machineHash) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
const deployments = await getDeployments(options);
|
|
41
|
-
return deployments.find((deployment) => deployment.templateHash === machineHash);
|
|
42
|
-
};
|
|
43
|
-
export const getApplicationAddress = async (options) => {
|
|
44
|
-
const projectName = getProjectName(options ?? {});
|
|
45
|
-
const deployment = await getApplicationDeployment({ projectName });
|
|
46
|
-
return deployment?.address;
|
|
47
|
-
};
|
|
48
|
-
const host = "http://127.0.0.1";
|
|
49
|
-
// services configuration
|
|
50
|
-
const baseServices = [
|
|
51
|
-
{
|
|
52
|
-
name: "anvil",
|
|
53
|
-
file: "docker-compose-anvil.yaml",
|
|
54
|
-
healthySemaphore: "anvil",
|
|
55
|
-
healthyTitle: (port) => `${chalk.cyan("anvil")} service ready at ${chalk.cyan(`${host}:${port}/anvil`)}`,
|
|
56
|
-
waitTitle: `${chalk.cyan("anvil")} service starting...`,
|
|
57
|
-
errorTitle: `${chalk.red("anvil")} service failed`,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: "proxy",
|
|
61
|
-
file: "docker-compose-proxy.yaml",
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: "database",
|
|
65
|
-
file: "docker-compose-database.yaml",
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: "rpc",
|
|
69
|
-
file: "docker-compose-node.yaml",
|
|
70
|
-
healthySemaphore: "rollups-node",
|
|
71
|
-
healthyTitle: (port) => `${chalk.cyan("rpc")} service ready at ${chalk.cyan(`${host}:${port}/rpc`)}`,
|
|
72
|
-
waitTitle: `${chalk.cyan("rpc")} service starting...`,
|
|
73
|
-
errorTitle: `${chalk.red("rpc")} service failed`,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "inspect",
|
|
77
|
-
file: "docker-compose-node.yaml",
|
|
78
|
-
healthySemaphore: "rollups-node",
|
|
79
|
-
healthyTitle: (port, name) => `${chalk.cyan("inspect")} service ready at ${chalk.cyan(`${host}:${port}/inspect/${name ?? "<application_address>"}`)}`,
|
|
80
|
-
waitTitle: `${chalk.cyan("inspect")} service starting...`,
|
|
81
|
-
errorTitle: `${chalk.red("inspect")} service failed`,
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
const availableServices = [
|
|
85
|
-
{
|
|
86
|
-
name: "bundler",
|
|
87
|
-
file: "docker-compose-bundler.yaml",
|
|
88
|
-
healthySemaphore: "bundler",
|
|
89
|
-
healthyTitle: (port) => `${chalk.cyan("bundler")} service ready at ${chalk.cyan(`${host}:${port}/bundler/rpc`)}`,
|
|
90
|
-
waitTitle: `${chalk.cyan("bundler")} service starting...`,
|
|
91
|
-
errorTitle: `${chalk.red("bundler")} service failed`,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: "explorer",
|
|
95
|
-
file: "docker-compose-explorer.yaml",
|
|
96
|
-
healthySemaphore: "explorer_api",
|
|
97
|
-
healthyTitle: (port) => `${chalk.cyan("explorer")} service ready at ${chalk.cyan(`${host}:${port}/explorer`)}`,
|
|
98
|
-
waitTitle: `${chalk.cyan("explorer")} service starting...`,
|
|
99
|
-
errorTitle: `${chalk.red("explorer")} service failed`,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: "paymaster",
|
|
103
|
-
file: "docker-compose-paymaster.yaml",
|
|
104
|
-
healthySemaphore: "paymaster",
|
|
105
|
-
healthyTitle: (port) => `${chalk.cyan("paymaster")} service ready at ${chalk.cyan(`${host}:${port}/paymaster`)}`,
|
|
106
|
-
waitTitle: `${chalk.cyan("paymaster")} service starting...`,
|
|
107
|
-
errorTitle: `${chalk.red("paymaster")} service failed`,
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "passkey",
|
|
111
|
-
file: "docker-compose-passkey-server.yaml",
|
|
112
|
-
healthySemaphore: "passkey-server",
|
|
113
|
-
healthyTitle: (port) => `${chalk.cyan("passkey")} service ready at ${chalk.cyan(`${host}:${port}/passkey`)}`,
|
|
114
|
-
waitTitle: `${chalk.cyan("passkey")} service starting...`,
|
|
115
|
-
errorTitle: `${chalk.red("passkey")} service failed`,
|
|
116
|
-
},
|
|
117
|
-
];
|
|
118
|
-
export const AVAILABLE_SERVICES = availableServices.map(({ name }) => name);
|
|
119
|
-
const serviceMonitorTask = (options) => {
|
|
120
|
-
const { errorTitle, healthyTitle, service, waitTitle } = options;
|
|
121
|
-
return {
|
|
122
|
-
task: async (_ctx, task) => {
|
|
123
|
-
await pRetry(async () => {
|
|
124
|
-
const health = await getServiceHealth(options);
|
|
125
|
-
if (health !== "healthy") {
|
|
126
|
-
throw new Error(errorTitle ??
|
|
127
|
-
`Service ${chalk.cyan(service)} is not healthy`);
|
|
128
|
-
}
|
|
129
|
-
}, { retries: 100, minTimeout: 500, factor: 1.1 });
|
|
130
|
-
task.title =
|
|
131
|
-
healthyTitle ?? `Service ${chalk.cyan(service)} is ready`;
|
|
132
|
-
},
|
|
133
|
-
title: waitTitle ?? `Starting ${chalk.cyan(service)}...`,
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
export const startEnvironment = async (options) => {
|
|
137
|
-
const { blockTime, cpus, defaultBlock, dryRun, memory, port, projectName, runtimeVersion, services, verbose, } = options;
|
|
138
|
-
const address = `${host}:${port}`;
|
|
139
|
-
// path of the tool instalation
|
|
140
|
-
const binPath = path.join(path.dirname(new URL(import.meta.url).pathname), "..");
|
|
141
|
-
// setup the environment variable used in docker compose
|
|
142
|
-
const env = {
|
|
143
|
-
CARTESI_BIN_PATH: binPath,
|
|
144
|
-
CARTESI_BLOCK_TIME: blockTime.toString(),
|
|
145
|
-
CARTESI_BLOCKCHAIN_DEFAULT_BLOCK: defaultBlock,
|
|
146
|
-
CARTESI_LISTEN_PORT: port.toString(),
|
|
147
|
-
CARTESI_LOG_LEVEL: verbose ? "debug" : "info",
|
|
148
|
-
CARTESI_ROLLUPS_NODE_CPUS: cpus?.toString(),
|
|
149
|
-
CARTESI_ROLLUPS_NODE_MEMORY: memory?.toString(),
|
|
150
|
-
CARTESI_SDK_IMAGE: `${DEFAULT_SDK_IMAGE}:${runtimeVersion}`,
|
|
151
|
-
CARTESI_SDK_VERSION: runtimeVersion,
|
|
152
|
-
};
|
|
153
|
-
// build a list of unique compose files
|
|
154
|
-
const composeFiles = [...new Set(baseServices.map(({ file }) => file))];
|
|
155
|
-
// cpu and memory limits, mostly for testing and debuggingpurposes
|
|
156
|
-
if (cpus) {
|
|
157
|
-
composeFiles.push("docker-compose-node-cpus.yaml");
|
|
158
|
-
}
|
|
159
|
-
if (memory) {
|
|
160
|
-
composeFiles.push("docker-compose-node-memory.yaml");
|
|
161
|
-
}
|
|
162
|
-
// select subset of optional services
|
|
163
|
-
const optionalServices = services.length === 1 && services[0] === "all"
|
|
164
|
-
? availableServices
|
|
165
|
-
: availableServices.filter(({ name }) => services.includes(name));
|
|
166
|
-
// add to compose files list
|
|
167
|
-
composeFiles.push(...optionalServices.map(({ file }) => file));
|
|
168
|
-
// create the "--file <file>" list
|
|
169
|
-
const files = composeFiles.flatMap((f) => [
|
|
170
|
-
"--file",
|
|
171
|
-
path.join(binPath, "compose", f),
|
|
172
|
-
]);
|
|
173
|
-
const composeArgs = [
|
|
174
|
-
"compose",
|
|
175
|
-
...files,
|
|
176
|
-
"--project-directory",
|
|
177
|
-
".",
|
|
178
|
-
"--project-name",
|
|
179
|
-
projectName,
|
|
180
|
-
];
|
|
181
|
-
// run in detached mode (background)
|
|
182
|
-
const upArgs = ["--detach"];
|
|
183
|
-
// if only dry run, just return the config
|
|
184
|
-
if (dryRun) {
|
|
185
|
-
// parse, resolve and render compose file in canonical format
|
|
186
|
-
const { stdout: config } = await execa("docker", [...composeArgs, "config", "--format", "yaml"], { env });
|
|
187
|
-
return { address, config };
|
|
188
|
-
}
|
|
189
|
-
// pull images first
|
|
190
|
-
const pullArgs = ["--policy", "missing"];
|
|
191
|
-
await execa("docker", [...composeArgs, "pull", ...pullArgs], {
|
|
192
|
-
env,
|
|
193
|
-
stdio: "inherit",
|
|
194
|
-
});
|
|
195
|
-
// run compose
|
|
196
|
-
await execa("docker", [...composeArgs, "up", ...upArgs], {
|
|
197
|
-
env,
|
|
198
|
-
});
|
|
199
|
-
return { address };
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* Wait for the environment to be healthy
|
|
203
|
-
* @param options
|
|
204
|
-
*/
|
|
205
|
-
export const waitHealthyEnvironment = async (options) => {
|
|
206
|
-
const { name, port, projectName, services } = options;
|
|
207
|
-
// select subset of optional services
|
|
208
|
-
const optionalServices = services.length === 1 && services[0] === "all"
|
|
209
|
-
? availableServices
|
|
210
|
-
: availableServices.filter(({ name }) => services.includes(name));
|
|
211
|
-
// create tasks to monitor services startup
|
|
212
|
-
const monitorTasks = [...baseServices, ...optionalServices]
|
|
213
|
-
.filter(({ healthySemaphore }) => !!healthySemaphore) // only services with a healthy semaphore
|
|
214
|
-
.map((service) => {
|
|
215
|
-
const healthyTitle = typeof service.healthyTitle === "function"
|
|
216
|
-
? service.healthyTitle(port, name)
|
|
217
|
-
: service.healthyTitle;
|
|
218
|
-
return serviceMonitorTask({
|
|
219
|
-
projectName,
|
|
220
|
-
service: service.healthySemaphore,
|
|
221
|
-
errorTitle: service.errorTitle,
|
|
222
|
-
waitTitle: service.waitTitle,
|
|
223
|
-
healthyTitle,
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
const tasks = new Listr(monitorTasks, { concurrent: true });
|
|
227
|
-
await tasks.run();
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Publish machine snapshot to rollups node by copying it to the rollups node container
|
|
231
|
-
* @param options
|
|
232
|
-
* @returns path to the snapshot in the rollups node
|
|
233
|
-
*/
|
|
234
|
-
export const publishMachine = async (options) => {
|
|
235
|
-
const { projectName, templateHash } = options;
|
|
236
|
-
const snapshotPath = getContextPath("image");
|
|
237
|
-
const containerSnapshotPath = `/var/lib/cartesi-rollups-node/snapshots/${templateHash}/`;
|
|
238
|
-
await execa("docker", [
|
|
239
|
-
"compose",
|
|
240
|
-
"--project-name",
|
|
241
|
-
projectName,
|
|
242
|
-
"cp",
|
|
243
|
-
snapshotPath,
|
|
244
|
-
`rollups-node:${containerSnapshotPath}`,
|
|
245
|
-
]);
|
|
246
|
-
return containerSnapshotPath;
|
|
247
|
-
};
|
|
248
|
-
/**
|
|
249
|
-
* Stop an environment by removing the containers and volumes
|
|
250
|
-
* @param options
|
|
251
|
-
* @returns
|
|
252
|
-
*/
|
|
253
|
-
export const stopEnvironment = async (options) => {
|
|
254
|
-
const { projectName } = options;
|
|
255
|
-
return execa("docker", [
|
|
256
|
-
"compose",
|
|
257
|
-
"--project-name",
|
|
258
|
-
projectName,
|
|
259
|
-
"down",
|
|
260
|
-
"--volumes",
|
|
261
|
-
]);
|
|
262
|
-
};
|
|
263
|
-
/**
|
|
264
|
-
* Deploy application to rollups node
|
|
265
|
-
* @param options
|
|
266
|
-
* @returns address of the application
|
|
267
|
-
*/
|
|
268
|
-
export const deployAuthority = async (options) => {
|
|
269
|
-
const { epochLength, projectName } = options;
|
|
270
|
-
// deploy application
|
|
271
|
-
const { stdout } = await execa("docker", [
|
|
272
|
-
"compose",
|
|
273
|
-
"--project-name",
|
|
274
|
-
projectName,
|
|
275
|
-
"exec",
|
|
276
|
-
"rollups-node",
|
|
277
|
-
"cartesi-rollups-cli",
|
|
278
|
-
"deploy",
|
|
279
|
-
"authority",
|
|
280
|
-
"--epoch-length",
|
|
281
|
-
epochLength.toString(),
|
|
282
|
-
"--json",
|
|
283
|
-
]);
|
|
284
|
-
return getAddress(JSON.parse(stdout).address);
|
|
285
|
-
};
|
|
286
|
-
/**
|
|
287
|
-
* Deploy application to rollups node
|
|
288
|
-
* @param options
|
|
289
|
-
* @returns address of the application
|
|
290
|
-
*/
|
|
291
|
-
export const deployApplication = async (options) => {
|
|
292
|
-
const { consensus, epochLength, name, projectName, salt, snapshotPath } = options;
|
|
293
|
-
// app deploy args
|
|
294
|
-
const deployArgs = [name, snapshotPath];
|
|
295
|
-
if (consensus) {
|
|
296
|
-
deployArgs.push("--consensus", consensus);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
deployArgs.push("--epoch-length", epochLength.toString());
|
|
300
|
-
}
|
|
301
|
-
if (salt) {
|
|
302
|
-
deployArgs.push("--salt", salt);
|
|
303
|
-
}
|
|
304
|
-
deployArgs.push("--json");
|
|
305
|
-
// deploy application
|
|
306
|
-
const { stdout } = await execa("docker", [
|
|
307
|
-
"compose",
|
|
308
|
-
"--project-name",
|
|
309
|
-
projectName,
|
|
310
|
-
"exec",
|
|
311
|
-
"rollups-node",
|
|
312
|
-
"cartesi-rollups-cli",
|
|
313
|
-
"deploy",
|
|
314
|
-
"application",
|
|
315
|
-
...deployArgs,
|
|
316
|
-
]);
|
|
317
|
-
const deployment = stdout ? parseDeployment(JSON.parse(stdout)) : undefined;
|
|
318
|
-
if (deployment) {
|
|
319
|
-
return deployment;
|
|
320
|
-
}
|
|
321
|
-
throw new Error("Failed to deploy application");
|
|
322
|
-
};
|
|
323
|
-
/**
|
|
324
|
-
* Remove application from rollups node
|
|
325
|
-
* @param options
|
|
326
|
-
* @returns
|
|
327
|
-
*/
|
|
328
|
-
export const removeApplication = async (options) => {
|
|
329
|
-
const { application, force, projectName } = options;
|
|
330
|
-
// disable application first so we can remove it
|
|
331
|
-
await execa("docker", [
|
|
332
|
-
"compose",
|
|
333
|
-
"--project-name",
|
|
334
|
-
projectName,
|
|
335
|
-
"exec",
|
|
336
|
-
"rollups-node",
|
|
337
|
-
"cartesi-rollups-cli",
|
|
338
|
-
"app",
|
|
339
|
-
"status",
|
|
340
|
-
application,
|
|
341
|
-
"disabled",
|
|
342
|
-
]);
|
|
343
|
-
const removeArgs = [application];
|
|
344
|
-
if (force) {
|
|
345
|
-
removeArgs.push("--force");
|
|
346
|
-
}
|
|
347
|
-
return execa("docker", [
|
|
348
|
-
"compose",
|
|
349
|
-
"--project-name",
|
|
350
|
-
projectName,
|
|
351
|
-
"exec",
|
|
352
|
-
"rollups-node",
|
|
353
|
-
"cartesi-rollups-cli",
|
|
354
|
-
"app",
|
|
355
|
-
"remove",
|
|
356
|
-
...removeArgs,
|
|
357
|
-
]);
|
|
358
|
-
};
|
|
359
|
-
/**
|
|
360
|
-
* Get the host and port of the docker compose project entrypoint
|
|
361
|
-
* @param options
|
|
362
|
-
* @returns port of the proxy service
|
|
363
|
-
*/
|
|
364
|
-
export const getProjectPort = async (options) => {
|
|
365
|
-
const { projectName } = options;
|
|
366
|
-
const { stdout } = await execa("docker", [
|
|
367
|
-
"compose",
|
|
368
|
-
"--project-name",
|
|
369
|
-
projectName,
|
|
370
|
-
"port",
|
|
371
|
-
"proxy",
|
|
372
|
-
"8088",
|
|
373
|
-
]);
|
|
374
|
-
return stdout;
|
|
375
|
-
};
|
package/dist/exec/util.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type Options } from "execa";
|
|
2
|
-
export type DockerFallbackOptions = {
|
|
3
|
-
image: string;
|
|
4
|
-
forceDocker: true;
|
|
5
|
-
} | {
|
|
6
|
-
image?: string;
|
|
7
|
-
forceDocker?: false;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Calls execa and falls back to docker run if command (on the host) fails
|
|
11
|
-
* @param command command to be executed
|
|
12
|
-
* @param args arguments to be passed to the command
|
|
13
|
-
* @param options execution options
|
|
14
|
-
* @returns return of execa
|
|
15
|
-
*/
|
|
16
|
-
export type ExecaOptionsDockerFallback = Options & DockerFallbackOptions;
|
|
17
|
-
export declare const execaDockerFallback: (command: string, args: readonly string[], options: ExecaOptionsDockerFallback) => Promise<import("execa").Result<Options & {
|
|
18
|
-
image?: string;
|
|
19
|
-
forceDocker?: false;
|
|
20
|
-
}>>;
|
|
21
|
-
//# sourceMappingURL=util.d.ts.map
|
package/dist/exec/util.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/exec/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,OAAO,EAAE,MAAM,OAAO,CAAC;AAGxD,MAAM,MAAM,qBAAqB,GAC3B;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,IAAI,CAAA;CAAE,GACpC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,MAAM,0BAA0B,GAAG,OAAO,GAAG,qBAAqB,CAAC;AACzE,eAAO,MAAM,mBAAmB,GAC5B,SAAS,MAAM,EACf,MAAM,SAAS,MAAM,EAAE,EACvB,SAAS,0BAA0B;YAbvB,MAAM;kBAAgB,KAAK;GA6C1C,CAAC"}
|
package/dist/exec/util.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ExecaError, execa } from "execa";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
export const execaDockerFallback = async (command, args, options) => {
|
|
4
|
-
try {
|
|
5
|
-
if (options.forceDocker) {
|
|
6
|
-
const error = new ExecaError();
|
|
7
|
-
error.code = "ENOENT";
|
|
8
|
-
throw error;
|
|
9
|
-
}
|
|
10
|
-
return await execa(command, args, options);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
if (error instanceof ExecaError) {
|
|
14
|
-
if (error.code === "ENOENT" && options.image) {
|
|
15
|
-
const userInfo = os.userInfo();
|
|
16
|
-
const dockerOpts = [
|
|
17
|
-
"--volume",
|
|
18
|
-
`${options.cwd}:/work`,
|
|
19
|
-
"--workdir",
|
|
20
|
-
"/work",
|
|
21
|
-
"--interactive",
|
|
22
|
-
"--rm",
|
|
23
|
-
"--user",
|
|
24
|
-
`${userInfo.uid}:${userInfo.gid}`,
|
|
25
|
-
];
|
|
26
|
-
return await execa("docker", ["run", ...dockerOpts, options.image, command, ...args], options);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
};
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/machine.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Config, ImageInfo } from "./config.js";
|
|
2
|
-
import type { ExecaOptionsDockerFallback } from "./exec/util.js";
|
|
3
|
-
export type BootMachineOptions = {
|
|
4
|
-
finalHash?: boolean;
|
|
5
|
-
interactive?: boolean;
|
|
6
|
-
store?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const bootMachine: (config: Config, info: ImageInfo | undefined, bootOptions: BootMachineOptions, options?: ExecaOptionsDockerFallback) => Promise<import("execa").Result<import("execa").Options & {
|
|
9
|
-
image?: string;
|
|
10
|
-
forceDocker?: false;
|
|
11
|
-
}>>;
|
|
12
|
-
//# sourceMappingURL=machine.d.ts.map
|
package/dist/machine.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../src/machine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAe,SAAS,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAmBjE,MAAM,MAAM,kBAAkB,GAAG;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,WAAW,GACpB,QAAQ,MAAM,EACd,MAAM,SAAS,GAAG,SAAS,EAC3B,aAAa,kBAAkB,EAC/B,UAAU,0BAA0B;;;GAkGvC,CAAC"}
|
package/dist/machine.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { cartesiMachine } from "./exec/index.js";
|
|
2
|
-
const flashDrive = (label, drive) => {
|
|
3
|
-
const { format, mount, shared, user } = drive;
|
|
4
|
-
const filename = `${label}.${format}`;
|
|
5
|
-
const vars = [`label:${label}`, `filename:${filename}`];
|
|
6
|
-
if (mount !== undefined) {
|
|
7
|
-
vars.push(`mount:${mount}`);
|
|
8
|
-
}
|
|
9
|
-
if (user) {
|
|
10
|
-
vars.push(`user:${user}`);
|
|
11
|
-
}
|
|
12
|
-
if (shared) {
|
|
13
|
-
vars.push("shared");
|
|
14
|
-
}
|
|
15
|
-
// don't specify start and length
|
|
16
|
-
return `--flash-drive=${vars.join(",")}`;
|
|
17
|
-
};
|
|
18
|
-
export const bootMachine = (config, info, bootOptions, options) => {
|
|
19
|
-
const { machine } = config;
|
|
20
|
-
const { assertRollingTemplate, maxMCycle, noRollup, ramLength, ramImage, useDockerEnv, useDockerWorkdir, user, } = machine;
|
|
21
|
-
// list of environment variables of docker image
|
|
22
|
-
const env = useDockerEnv ? (info?.env ?? []) : [];
|
|
23
|
-
const envs = env.map((variable) => {
|
|
24
|
-
const [key, value] = variable.split("=");
|
|
25
|
-
return `--env=${key}="${value}"`;
|
|
26
|
-
});
|
|
27
|
-
// check if we need a rootfstype boot arg
|
|
28
|
-
const root = config.drives.root;
|
|
29
|
-
if (root?.format === "sqfs") {
|
|
30
|
-
const definedRootfsType = config.machine.bootargs.find((arg) => arg.startsWith("rootfstype="));
|
|
31
|
-
// not checking here if user intentionally defined wrong type
|
|
32
|
-
if (!definedRootfsType) {
|
|
33
|
-
config.machine.bootargs.push("rootfstype=squashfs");
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// bootargs from config string array
|
|
37
|
-
const bootargs = machine.bootargs.map((arg) => `--append-bootargs="${arg}"`);
|
|
38
|
-
// entrypoint from config or image info (Docker ENTRYPOINT + CMD)
|
|
39
|
-
let entrypoint;
|
|
40
|
-
if (machine.entrypoint) {
|
|
41
|
-
entrypoint = machine.entrypoint;
|
|
42
|
-
}
|
|
43
|
-
else if (info && (info.entrypoint.length > 0 || info.cmd.length > 0)) {
|
|
44
|
-
entrypoint = [...info.entrypoint, ...info.cmd].join(" ");
|
|
45
|
-
}
|
|
46
|
-
if (!entrypoint) {
|
|
47
|
-
throw new Error("Undefined machine entrypoint. Please define an entrypoint in your cartesi.toml config or in your Dockerfile.");
|
|
48
|
-
}
|
|
49
|
-
const flashDrives = Object.entries(config.drives).map(([label, drive]) => flashDrive(label, drive));
|
|
50
|
-
// command to change working directory if WORKDIR is defined
|
|
51
|
-
const args = [
|
|
52
|
-
...bootargs,
|
|
53
|
-
...envs,
|
|
54
|
-
...flashDrives,
|
|
55
|
-
`--ram-length=${ramLength}`,
|
|
56
|
-
];
|
|
57
|
-
if (ramImage) {
|
|
58
|
-
args.push(`--ram-image=${ramImage}`);
|
|
59
|
-
}
|
|
60
|
-
if (assertRollingTemplate) {
|
|
61
|
-
args.push("--assert-rolling-template");
|
|
62
|
-
}
|
|
63
|
-
if (bootOptions.finalHash) {
|
|
64
|
-
args.push("--final-hash");
|
|
65
|
-
}
|
|
66
|
-
if (useDockerWorkdir && info?.workdir) {
|
|
67
|
-
args.push(`--workdir="${info.workdir}"`);
|
|
68
|
-
}
|
|
69
|
-
if (bootOptions.interactive) {
|
|
70
|
-
args.push("-it");
|
|
71
|
-
}
|
|
72
|
-
if (noRollup) {
|
|
73
|
-
args.push("--no-rollup");
|
|
74
|
-
}
|
|
75
|
-
if (maxMCycle) {
|
|
76
|
-
args.push(`--max-mcycle=${maxMCycle.toString()}`);
|
|
77
|
-
}
|
|
78
|
-
if (bootOptions.store) {
|
|
79
|
-
args.push(`--store=${bootOptions.store}`);
|
|
80
|
-
}
|
|
81
|
-
if (user) {
|
|
82
|
-
args.push(`--user=${user}`);
|
|
83
|
-
}
|
|
84
|
-
args.push("--");
|
|
85
|
-
args.push(entrypoint);
|
|
86
|
-
return cartesiMachine.boot(args, {
|
|
87
|
-
image: config.sdk,
|
|
88
|
-
...options,
|
|
89
|
-
});
|
|
90
|
-
};
|
package/dist/prompts.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Separator } from "@inquirer/core";
|
|
2
|
-
import input from "@inquirer/input";
|
|
3
|
-
import select from "@inquirer/select";
|
|
4
|
-
import type { Context } from "@inquirer/type";
|
|
5
|
-
import { type Address, type Hex } from "viem";
|
|
6
|
-
type InputConfig = Parameters<typeof input>[0];
|
|
7
|
-
type SelectConfig<ValueType> = Parameters<typeof select<ValueType>>[0];
|
|
8
|
-
/**
|
|
9
|
-
* Prompt for an address value.
|
|
10
|
-
* @param config inquirer config
|
|
11
|
-
* @returns address
|
|
12
|
-
*/
|
|
13
|
-
export type AddressPromptConfig = InputConfig & {
|
|
14
|
-
default?: Address;
|
|
15
|
-
};
|
|
16
|
-
export declare const addressInput: (config: AddressPromptConfig) => Promise<Address>;
|
|
17
|
-
/**
|
|
18
|
-
* Prompt for a hex value.
|
|
19
|
-
* @param config inquirer config
|
|
20
|
-
* @returns hex
|
|
21
|
-
*/
|
|
22
|
-
export type HexPromptConfig = InputConfig & {
|
|
23
|
-
default?: Hex;
|
|
24
|
-
};
|
|
25
|
-
export declare const hexInput: (config: HexPromptConfig) => Promise<Hex>;
|
|
26
|
-
export type BigintPromptConfig = InputConfig & {
|
|
27
|
-
decimals: number;
|
|
28
|
-
default?: bigint;
|
|
29
|
-
};
|
|
30
|
-
export declare const bigintInput: (config: BigintPromptConfig) => Promise<bigint>;
|
|
31
|
-
/**
|
|
32
|
-
* Prompt for a bytes input, by choosing from different encoding options.
|
|
33
|
-
* @param config inquirer config
|
|
34
|
-
* @returns bytes as hex string
|
|
35
|
-
*/
|
|
36
|
-
export declare const bytesInput: (config: InputConfig & {
|
|
37
|
-
encoding?: "string" | "hex" | "abi";
|
|
38
|
-
message: string;
|
|
39
|
-
}) => Promise<Hex>;
|
|
40
|
-
/**
|
|
41
|
-
* Prompt for ABI encoded parameters.
|
|
42
|
-
* @param config inquirer config
|
|
43
|
-
* @returns ABI encoded parameters as hex string
|
|
44
|
-
*/
|
|
45
|
-
export declare const abiParamsInput: (config: InputConfig & {
|
|
46
|
-
message: string;
|
|
47
|
-
}) => Promise<`0x${string}`>;
|
|
48
|
-
export type Choice<ValueType> = {
|
|
49
|
-
value: ValueType;
|
|
50
|
-
name?: string;
|
|
51
|
-
description?: string;
|
|
52
|
-
disabled?: boolean | string;
|
|
53
|
-
type?: never;
|
|
54
|
-
};
|
|
55
|
-
export type SelectAutoConfig<ValueType> = SelectConfig<ValueType> & {
|
|
56
|
-
choices: ReadonlyArray<Choice<ValueType> | Separator>;
|
|
57
|
-
pageSize?: number;
|
|
58
|
-
};
|
|
59
|
-
export declare const selectAuto: <ValueType>(config: SelectAutoConfig<ValueType> & {
|
|
60
|
-
discardDisabled?: boolean;
|
|
61
|
-
}, context?: Context | undefined) => Promise<ValueType>;
|
|
62
|
-
export declare const keySelect: <Value>(config: {
|
|
63
|
-
choices: readonly Choice<Value>[];
|
|
64
|
-
separator?: string | undefined;
|
|
65
|
-
}, context?: Context) => Promise<Value> & {
|
|
66
|
-
cancel: () => void;
|
|
67
|
-
};
|
|
68
|
-
export declare const getInputApplicationAddress: (options: {
|
|
69
|
-
application?: string;
|
|
70
|
-
projectName?: string;
|
|
71
|
-
}) => Promise<Address>;
|
|
72
|
-
export {};
|
|
73
|
-
//# sourceMappingURL=prompts.d.ts.map
|
package/dist/prompts.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA6B,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,GAAG,EASX,MAAM,MAAM,CAAC;AAGd,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,KAAK,YAAY,CAAC,SAAS,IAAI,UAAU,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AACtE,eAAO,MAAM,YAAY,GACrB,QAAQ,mBAAmB,KAC5B,OAAO,CAAC,OAAO,CAMjB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG;IAAE,OAAO,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC;AAC9D,eAAO,MAAM,QAAQ,GAAU,QAAQ,eAAe,KAAG,OAAO,CAAC,GAAG,CAMnE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,eAAO,MAAM,WAAW,GACpB,QAAQ,kBAAkB,KAC3B,OAAO,CAAC,MAAM,CAUhB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACnB,QAAQ,WAAW,GAAG;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;CACnB,KACF,OAAO,CAAC,GAAG,CAkDb,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACvB,QAAQ,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,KAC1C,OAAO,CAAC,KAAK,MAAM,EAAE,CA+DvB,CAAC;AAGF,MAAM,MAAM,MAAM,CAAC,SAAS,IAAI;IAC5B,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,SAAS,IAAI,YAAY,CAAC,SAAS,CAAC,GAAG;IAChE,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,SAAS,EAChC,QAAQ,gBAAgB,CAAC,SAAS,CAAC,GAAG;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,EACnE,UAAU,OAAO,GAAG,SAAS,KAC9B,OAAO,CAAC,SAAS,CAsBnB,CAAC;AAOF,eAAO,MAAM,SAAS,GACjB,KAAK;;gBAJM,MAAM;;;CAoBrB,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAU,SAAS;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,KAAG,OAAO,CAAC,OAAO,CAoBlB,CAAC"}
|