Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cartesi Rollups v2 #116

Merged
merged 3 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-clowns-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

DEPRECATED: cartesi deploy build
5 changes: 5 additions & 0 deletions .changeset/flat-ears-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": minor
---

improve doctor command
5 changes: 5 additions & 0 deletions .changeset/floppy-eggs-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

new: cartesi rollups deploy
5 changes: 5 additions & 0 deletions .changeset/huge-jeans-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

DEPRECATED: cartesi run
5 changes: 5 additions & 0 deletions .changeset/kind-mice-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

new: cartesi rollups stop
5 changes: 5 additions & 0 deletions .changeset/soft-bats-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

new: cartesi rollups start
5 changes: 5 additions & 0 deletions .changeset/solid-owls-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

new: cartesi rollups status
5 changes: 5 additions & 0 deletions .changeset/upset-news-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": major
---

DEPRECATED: cartesi deploy
40 changes: 20 additions & 20 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,50 @@
],
"dependencies": {
"@commander-js/extra-typings": "^13.1.0",
"@inquirer/confirm": "^5.0.0",
"@inquirer/core": "^10.0.0",
"@inquirer/input": "^4.0.0",
"@inquirer/select": "^4.0.0",
"@inquirer/type": "^3.0.0",
"@inquirer/confirm": "^5.1.6",
"@inquirer/core": "^10.1.7",
"@inquirer/input": "^4.1.6",
"@inquirer/select": "^4.0.9",
"@inquirer/type": "^3.0.4",
"bytes": "^3.1.2",
"chalk": "^5.3.0",
"chalk": "^5.4.1",
"cli-table3": "^0.6.5",
"commander": "^13.1.0",
"execa": "^9.4.1",
"fs-extra": "^11.2.0",
"giget": "^1.2.3",
"lookpath": "^1.2.2",
"execa": "^9.5.2",
"fs-extra": "^11.3.0",
"giget": "^2.0.0",
"lookpath": "^1.2.3",
"open": "^10.1.0",
"ora": "^8.1.0",
"ora": "^8.2.0",
"progress-stream": "^2.0.0",
"semver": "^7.6.3",
"smol-toml": "^1.3.0",
"semver": "^7.7.1",
"smol-toml": "^1.3.1",
"tmp": "^0.2.3",
"viem": "^2.21.27"
"viem": "^2.23.6"
},
"devDependencies": {
"@cartesi/devnet": "workspace:*",
"@cartesi/eslint-config": "workspace:*",
"@sunodo/wagmi-plugin-hardhat-deploy": "^0.3.0",
"@types/bytes": "^3.1.4",
"@types/bytes": "^3.1.5",
"@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.7",
"@types/node": "^22.7.6",
"@types/node-fetch": "^2.6.11",
"@types/node": "^22.13.9",
"@types/node-fetch": "^2.6.12",
"@types/progress-stream": "^2.0.5",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.5.8",
"@types/tmp": "^0.2.6",
"@vitest/coverage-istanbul": "^2.1.3",
"@wagmi/cli": "^2.1.16",
"@wagmi/cli": "^2.2.0",
"copyfiles": "^2.4.1",
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"tsconfig": "workspace:*",
"tslib": "^2.8.0",
"typescript": "^5.6.3",
"tslib": "^2.8.1",
"typescript": "^5.8.2",
"vitest": "^2.1.3"
},
"scripts": {
Expand Down
39 changes: 32 additions & 7 deletions apps/cli/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { InvalidArgumentError } from "@commander-js/extra-typings";
import chalk from "chalk";
import { execa } from "execa";
import fs from "fs";
import path from "path";
import { Address, getAddress, Hash, isHash } from "viem";
import { Address, getAddress, Hash, isAddress, isHash, zeroHash } from "viem";
import { Config, parse } from "./config.js";
import {
applicationFactoryAddress,
Expand All @@ -18,6 +19,7 @@
testNftAddress,
testTokenAddress,
} from "./contracts.js";
import { getApplicationAddress } from "./exec/rollups.js";
import { PsResponse } from "./types/docker.js";

export const getContextPath = (...paths: string[]): string => {
Expand All @@ -42,19 +44,13 @@
: parse("");
};

export const getApplicationAddress = async (): Promise<Address> => {
// fixed value, as we do deterministic deployment with a zero hash
return getAddress("0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e");
};

export type AddressBook = Record<string, Address>;

export const getAddressBook = async (): Promise<AddressBook> => {
const applicationAddress = await getApplicationAddress();

// build rollups contracts address book
const contracts: AddressBook = {
Application: applicationAddress,
ApplicationFactory: applicationFactoryAddress,
AuthorityFactory: authorityFactoryAddress,
EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
Expand All @@ -79,6 +75,10 @@
VerifyingPaymasterV07: "0xc5c97885C67F7361aBAfD2B95067a5bBdA603608",
};

if (applicationAddress) {
contracts.Application = applicationAddress;
}

return contracts;
};

Expand Down Expand Up @@ -109,3 +109,28 @@
const ps = stdout ? (JSON.parse(stdout) as PsResponse) : undefined;
return ps?.State;
};

export const parseAddress = (
value: string,
_previous: Address | undefined,

Check warning on line 115 in apps/cli/src/base.ts

View workflow job for this annotation

GitHub Actions / lint

'_previous' is defined but never used

Check warning on line 115 in apps/cli/src/base.ts

View workflow job for this annotation

GitHub Actions / build

'_previous' is defined but never used
): Address | undefined => {
if (isAddress(value)) {
return getAddress(value);
} else {
if (value !== "") {
throw new InvalidArgumentError(`Invalid address: ${value}`);
}
return undefined;
}
};

export const parseHash = (value: string, _previous: Hash): Hash => {

Check warning on line 127 in apps/cli/src/base.ts

View workflow job for this annotation

GitHub Actions / lint

'_previous' is defined but never used

Check warning on line 127 in apps/cli/src/base.ts

View workflow job for this annotation

GitHub Actions / build

'_previous' is defined but never used
if (isHash(value)) {
return value;
} else {
if (value !== "") {
throw new InvalidArgumentError(`Invalid hash: ${value}`);
}
return zeroHash;
}
};
5 changes: 2 additions & 3 deletions apps/cli/src/commands/address-book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Command } from "@commander-js/extra-typings";
import Table from "cli-table3";
import { getAddressBook } from "../base.js";

export const registerAddressBookCommand = (program: Command) => {
program
.command("address-book")
export const createAddressBookCommand = () => {
return new Command("address-book")
.description(
"Prints the addresses of all smart contracts deployed to the runtime environment of the application.",
)
Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ const buildDrive = async (
}
};

export const registerBuildCommand = (program: Command) => {
program
.command("build")
export const createBuildCommand = () => {
return new Command("build")
.description(
"Build application by building Cartesi machine drives, configuring a machine and booting it.",
)
Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Command } from "@commander-js/extra-typings";
import fs from "fs-extra";
import { getContextPath } from "../base.js";

export const registerCleanCommand = (program: Command) => {
program
.command("clean")
export const createCleanCommand = () => {
return new Command("clean")
.description("Deletes all cached build artifacts of application.")
.action(async () => {
await fs.emptyDir(getContextPath());
Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ const download = async (
});
};

export const registerCreateCommand = (program: Command) => {
program
.command("create")
export const createCreateCommand = () => {
return new Command("create")
.argument("<name>", "application and directory name")
.addOption(
new Option("-t, --template <template>", "template name to use")
Expand Down
104 changes: 13 additions & 91 deletions apps/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,19 @@
import { Command, Option } from "@commander-js/extra-typings";
import confirm from "@inquirer/confirm";
import select from "@inquirer/select";
import { Command } from "@commander-js/extra-typings";
import chalk from "chalk";
import open, { apps } from "open";
import { getMachineHash, logPrompt } from "../base.js";
import { registerBuildCommand } from "./deploy/build.js";
import { createBuildCommand } from "./deploy/build.js";

export const registerDeployCommand = (program: Command) => {
const deployCommand = program
.command("deploy")
export const createDeployCommand = () => {
const command = new Command("deploy")
.description(
"Package and deploy the application to a supported live network.",
"DEPRECATED: Package and deploy the application to a supported live network.",
)
.addOption(
new Option("--hosting <hosting>", "hosting type").choices([
"self-hosted",
"third-party",
]),
)
.addOption(
new Option(
"--webapp <webapp>",
"webapp address",
).makeOptionMandatory(),
)
.action(async (options, command) => {
// print machine hash
const templateHash = getMachineHash();
if (!templateHash) {
command.error(
`Cartesi machine snapshot not found, run 'build'`,
);
return;
}
logPrompt({
title: "Cartesi machine templateHash",
value: templateHash,
});

// ask for deployment type
const hosting =
options.hosting ||
(await select<"self-hosted" | "third-party">({
message: "Select hosting type",
choices: [
{
name: "Self-hosting",
description: `Select this option if you want to run the node for your application.
You will need the following infrastructure:

- a cloud server for the application node
- a postgres database
- a web3 node provider
- a funded wallet
`,
value: "self-hosted",
},
{
name: "Use third-party provider",
description:
"Select this option to use a third-party service provider to run a node for your application.",
value: "third-party",
disabled: "(coming soon)",
},
],
}));

let queryString = "";
switch (hosting) {
case "self-hosted": {
// build docker image
// Execute the build subcommand
program.commands
.find((cmd) => cmd.name() === "build")
?.parseAsync(program.args);

queryString = `?templateHash=${templateHash}`;
break;
}
case "third-party": {
command.error(
"Third-party provider deployment not supported yet",
);
}
}

// prompt user to open webapp for onchain deployment
const deployUrl = `${options.webapp}${queryString}`;
if (await confirm({ message: `Open ${chalk.cyan(deployUrl)}?` })) {
open(deployUrl, { app: { name: apps.chrome } });
}

return;
.action(async () => {
console.warn(
chalk.yellow(
"deploy command is deprecated, use 'rollups deploy' instead",
),
);
});
registerBuildCommand(deployCommand);
command.addCommand(createBuildCommand(), { hidden: true });
return command;
};
Loading
Loading