@cartesi/cli 2.0.0-alpha.13 → 2.0.0-alpha.14
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 +8 -3
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +7 -4
- package/dist/commands/address-book.d.ts +1 -0
- package/dist/commands/address-book.d.ts.map +1 -1
- package/dist/commands/address-book.js +6 -3
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +1 -0
- package/dist/commands/deploy.d.ts +1 -16
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +8 -267
- package/dist/commands/deposit/erc20.d.ts +11 -0
- package/dist/commands/deposit/erc20.d.ts.map +1 -0
- package/dist/commands/deposit/erc20.js +126 -0
- package/dist/commands/deposit/erc721.d.ts +12 -0
- package/dist/commands/deposit/erc721.d.ts.map +1 -0
- package/dist/commands/deposit/erc721.js +144 -0
- package/dist/commands/deposit/ether.d.ts +10 -0
- package/dist/commands/deposit/ether.d.ts.map +1 -0
- package/dist/commands/deposit/ether.js +66 -0
- package/dist/commands/deposit.d.ts +9 -0
- package/dist/commands/deposit.d.ts.map +1 -0
- package/dist/commands/deposit.js +36 -0
- package/dist/commands/logs.d.ts +1 -1
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +6 -4
- package/dist/commands/run.d.ts +13 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +196 -4
- package/dist/commands/send.d.ts +6 -17
- package/dist/commands/send.d.ts.map +1 -1
- package/dist/commands/send.js +122 -59
- package/dist/commands/status.d.ts +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +10 -7
- package/dist/compose/default.env +1 -1
- package/dist/compose/docker-compose-anvil.yaml +1 -1
- package/dist/compose/docker-compose-node.yaml +1 -4
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -2
- package/dist/exec/cartesi-machine.js +1 -1
- package/dist/exec/rollups.d.ts +94 -5
- package/dist/exec/rollups.d.ts.map +1 -1
- package/dist/exec/rollups.js +356 -12
- package/dist/index.js +5 -7
- package/dist/prompts.d.ts +12 -1
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +58 -23
- package/dist/wallet.d.ts +15948 -21
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +33 -221
- package/package.json +24 -23
- package/dist/commands/send/eip712.d.ts +0 -34
- package/dist/commands/send/eip712.d.ts.map +0 -1
- package/dist/commands/send/eip712.js +0 -81
- package/dist/commands/send/erc20.d.ts +0 -12
- package/dist/commands/send/erc20.d.ts.map +0 -1
- package/dist/commands/send/erc20.js +0 -75
- package/dist/commands/send/erc721.d.ts +0 -12
- package/dist/commands/send/erc721.d.ts.map +0 -1
- package/dist/commands/send/erc721.js +0 -78
- package/dist/commands/send/ether.d.ts +0 -12
- package/dist/commands/send/ether.d.ts.map +0 -1
- package/dist/commands/send/ether.js +0 -36
- package/dist/commands/send/generic.d.ts +0 -15
- package/dist/commands/send/generic.d.ts.map +0 -1
- package/dist/commands/send/generic.js +0 -122
- package/dist/commands/start.d.ts +0 -14
- package/dist/commands/start.d.ts.map +0 -1
- package/dist/commands/start.js +0 -220
- package/dist/commands/stop.d.ts +0 -5
- package/dist/commands/stop.d.ts.map +0 -1
- package/dist/commands/stop.js +0 -27
- package/dist/compose/docker-compose-espresso.yaml +0 -81
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { BaseError, ContractFunctionRevertedError, erc721Abi, getAddress, isAddress, isHex, } from "viem";
|
|
5
|
+
import { getProjectName } from "../../base.js";
|
|
6
|
+
import { erc721PortalAbi, erc721PortalAddress, testNftAbi, testNftAddress, } from "../../contracts.js";
|
|
7
|
+
import { addressInput, bigintInput, getInputApplicationAddress, } from "../../prompts.js";
|
|
8
|
+
import { connect } from "../../wallet.js";
|
|
9
|
+
const readToken = async (publicClient, address) => {
|
|
10
|
+
const args = { abi: erc721Abi, address };
|
|
11
|
+
const symbol = await publicClient.readContract({
|
|
12
|
+
...args,
|
|
13
|
+
functionName: "symbol",
|
|
14
|
+
});
|
|
15
|
+
const name = await publicClient.readContract({
|
|
16
|
+
...args,
|
|
17
|
+
functionName: "name",
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
address,
|
|
21
|
+
name,
|
|
22
|
+
symbol,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const parseToken = async (options) => {
|
|
26
|
+
const { testClient } = options;
|
|
27
|
+
const address = options.token && isAddress(options.token)
|
|
28
|
+
? getAddress(options.token)
|
|
29
|
+
: await addressInput({
|
|
30
|
+
message: "Token address",
|
|
31
|
+
default: testNftAddress,
|
|
32
|
+
});
|
|
33
|
+
return readToken(testClient, address);
|
|
34
|
+
};
|
|
35
|
+
export const createErc721Command = () => {
|
|
36
|
+
// biome-ignore lint/complexity/noBannedTypes: commander pattern
|
|
37
|
+
return new Command("erc721")
|
|
38
|
+
.description("Deposit ERC-721 to the application")
|
|
39
|
+
.configureHelp({ showGlobalOptions: true })
|
|
40
|
+
.argument("[token-id]", "token ID")
|
|
41
|
+
.option("--token <address>", "token address")
|
|
42
|
+
.option("--base-layer-data <hex>", "base layer data", "0x")
|
|
43
|
+
.option("--exec-layer-data <hex>", "exec layer data", "0x")
|
|
44
|
+
.action(async (tokenIdStr, options, command) => {
|
|
45
|
+
const { from } = command.optsWithGlobals();
|
|
46
|
+
const tokenId = tokenIdStr
|
|
47
|
+
? BigInt(tokenIdStr)
|
|
48
|
+
: await bigintInput({ decimals: 0, message: "Token ID" });
|
|
49
|
+
const projectName = getProjectName(command.optsWithGlobals());
|
|
50
|
+
// connect to anvil
|
|
51
|
+
const testClient = await connect(command.optsWithGlobals());
|
|
52
|
+
// the input sender, impersonated
|
|
53
|
+
const account = from && isAddress(from)
|
|
54
|
+
? getAddress(from)
|
|
55
|
+
: (await testClient.getAddresses())[0];
|
|
56
|
+
const token = await parseToken({
|
|
57
|
+
testClient,
|
|
58
|
+
token: options.token,
|
|
59
|
+
});
|
|
60
|
+
const tokenAbi = token.address === testNftAddress ? testNftAbi : erc721Abi;
|
|
61
|
+
// get dapp address from local node, or ask
|
|
62
|
+
const application = await getInputApplicationAddress({
|
|
63
|
+
...command.optsWithGlobals(),
|
|
64
|
+
projectName,
|
|
65
|
+
});
|
|
66
|
+
const { symbol } = token;
|
|
67
|
+
const baseLayerData = isHex(options.baseLayerData)
|
|
68
|
+
? options.baseLayerData
|
|
69
|
+
: "0x";
|
|
70
|
+
const execLayerData = isHex(options.execLayerData)
|
|
71
|
+
? options.execLayerData
|
|
72
|
+
: "0x";
|
|
73
|
+
// progress spinner
|
|
74
|
+
const progress = ora();
|
|
75
|
+
// check balance
|
|
76
|
+
try {
|
|
77
|
+
const currentOwner = await testClient.readContract({
|
|
78
|
+
abi: tokenAbi,
|
|
79
|
+
address: token.address,
|
|
80
|
+
args: [tokenId],
|
|
81
|
+
functionName: "ownerOf",
|
|
82
|
+
});
|
|
83
|
+
if (currentOwner !== account) {
|
|
84
|
+
progress.fail("Insufficient balance");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
if (e instanceof BaseError) {
|
|
90
|
+
const revertError = e.walk((err) => err instanceof ContractFunctionRevertedError);
|
|
91
|
+
if (revertError instanceof ContractFunctionRevertedError) {
|
|
92
|
+
const errorName = revertError.data?.errorName ?? "";
|
|
93
|
+
if (errorName === "ERC721NonexistentToken") {
|
|
94
|
+
progress.fail(`Token ${tokenIdStr} does not exist`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
progress.fail("Failed to check ownership");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// check allowance
|
|
102
|
+
const operator = await testClient.readContract({
|
|
103
|
+
abi: tokenAbi,
|
|
104
|
+
address: token.address,
|
|
105
|
+
args: [tokenId],
|
|
106
|
+
functionName: "getApproved",
|
|
107
|
+
});
|
|
108
|
+
// for messages
|
|
109
|
+
const amountStr = `${chalk.cyan(tokenIdStr)} ${symbol}`;
|
|
110
|
+
// approve if needed
|
|
111
|
+
if (operator !== erc721PortalAddress) {
|
|
112
|
+
progress.start(`Approving ${amountStr}...`);
|
|
113
|
+
const { request } = await testClient.simulateContract({
|
|
114
|
+
abi: tokenAbi,
|
|
115
|
+
account,
|
|
116
|
+
address: token.address,
|
|
117
|
+
functionName: "approve",
|
|
118
|
+
args: [erc721PortalAddress, tokenId],
|
|
119
|
+
});
|
|
120
|
+
const hash = await testClient.writeContract(request);
|
|
121
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
122
|
+
progress.succeed(`Approved ${amountStr}`);
|
|
123
|
+
}
|
|
124
|
+
// simulate deposit call
|
|
125
|
+
const { request } = await testClient.simulateContract({
|
|
126
|
+
abi: erc721PortalAbi,
|
|
127
|
+
account,
|
|
128
|
+
address: erc721PortalAddress,
|
|
129
|
+
functionName: "depositERC721Token",
|
|
130
|
+
args: [
|
|
131
|
+
token.address,
|
|
132
|
+
application,
|
|
133
|
+
tokenId,
|
|
134
|
+
baseLayerData,
|
|
135
|
+
execLayerData,
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
// send deposit
|
|
139
|
+
progress.start(`Depositing ${amountStr} to ${chalk.cyan(application)}...`);
|
|
140
|
+
const hash = await testClient.writeContract(request);
|
|
141
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
142
|
+
progress.succeed(`Deposited ${amountStr} to ${chalk.cyan(application)}`);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createEtherCommand: () => Command<[string | undefined], {
|
|
3
|
+
execLayerData: string;
|
|
4
|
+
}, {
|
|
5
|
+
from?: string | undefined;
|
|
6
|
+
application?: string | undefined;
|
|
7
|
+
projectName?: string | undefined;
|
|
8
|
+
rpcUrl?: string | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=ether.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ether.d.ts","sourceRoot":"","sources":["../../../src/commands/deposit/ether.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAUtD,eAAO,MAAM,kBAAkB;;;;;;;EAyE9B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import ora from "ora";
|
|
4
|
+
import { formatUnits, getAddress, isAddress, isHex, parseUnits } from "viem";
|
|
5
|
+
import { getProjectName } from "../../base.js";
|
|
6
|
+
import { etherPortalAbi, etherPortalAddress } from "../../contracts.js";
|
|
7
|
+
import { bigintInput, getInputApplicationAddress } from "../../prompts.js";
|
|
8
|
+
import { connect } from "../../wallet.js";
|
|
9
|
+
export const createEtherCommand = () => {
|
|
10
|
+
// biome-ignore lint/complexity/noBannedTypes: commander pattern
|
|
11
|
+
return new Command("ether")
|
|
12
|
+
.description("Deposit ether to the application")
|
|
13
|
+
.configureHelp({ showGlobalOptions: true })
|
|
14
|
+
.argument("[amount]", "amount, in ETH units")
|
|
15
|
+
.option("--exec-layer-data <hex>", "exec layer data", "0x")
|
|
16
|
+
.action(async (amountStr, options, command) => {
|
|
17
|
+
const { from } = command.optsWithGlobals();
|
|
18
|
+
const projectName = getProjectName(command.optsWithGlobals());
|
|
19
|
+
// connect to anvil
|
|
20
|
+
const testClient = await connect(command.optsWithGlobals());
|
|
21
|
+
// the input sender, impersonated
|
|
22
|
+
const account = from && isAddress(from)
|
|
23
|
+
? getAddress(from)
|
|
24
|
+
: (await testClient.getAddresses())[0];
|
|
25
|
+
// get dapp address from local node, or ask
|
|
26
|
+
const application = await getInputApplicationAddress({
|
|
27
|
+
...command.optsWithGlobals(),
|
|
28
|
+
projectName,
|
|
29
|
+
});
|
|
30
|
+
const { decimals, symbol } = testClient.chain.nativeCurrency;
|
|
31
|
+
const amount = amountStr
|
|
32
|
+
? parseUnits(amountStr, decimals)
|
|
33
|
+
: await bigintInput({
|
|
34
|
+
message: `Amount (${symbol})`,
|
|
35
|
+
decimals,
|
|
36
|
+
});
|
|
37
|
+
const execLayerData = isHex(options.execLayerData)
|
|
38
|
+
? options.execLayerData
|
|
39
|
+
: "0x";
|
|
40
|
+
// progress spinner
|
|
41
|
+
const progress = ora();
|
|
42
|
+
// for messages
|
|
43
|
+
const amountLabel = `${chalk.cyan(formatUnits(amount, decimals))} ${symbol}`;
|
|
44
|
+
// check balance
|
|
45
|
+
const balance = await testClient.getBalance({
|
|
46
|
+
address: account,
|
|
47
|
+
});
|
|
48
|
+
if (balance < amount) {
|
|
49
|
+
progress.fail("Insufficient balance");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const { request } = await testClient.simulateContract({
|
|
53
|
+
abi: etherPortalAbi,
|
|
54
|
+
account,
|
|
55
|
+
address: etherPortalAddress,
|
|
56
|
+
args: [application, execLayerData],
|
|
57
|
+
functionName: "depositEther",
|
|
58
|
+
value: amount,
|
|
59
|
+
});
|
|
60
|
+
// send deposit
|
|
61
|
+
progress.start(`Depositing ${amountLabel} to ${chalk.cyan(application)}...`);
|
|
62
|
+
const hash = await testClient.writeContract(request);
|
|
63
|
+
await testClient.waitForTransactionReceipt({ hash });
|
|
64
|
+
progress.succeed(`Deposited ${amountLabel} to ${chalk.cyan(application)}`);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const createDepositCommand: () => Command<[], {
|
|
3
|
+
from?: string | undefined;
|
|
4
|
+
application?: string | undefined;
|
|
5
|
+
projectName?: string | undefined;
|
|
6
|
+
rpcUrl?: string | undefined;
|
|
7
|
+
}, {}>;
|
|
8
|
+
export type DepositCommandOpts = ReturnType<ReturnType<typeof createDepositCommand>["opts"]>;
|
|
9
|
+
//# sourceMappingURL=deposit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../src/commands/deposit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAMtD,eAAO,MAAM,oBAAoB;;;;;MAsChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,UAAU,CACvC,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAClD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import select from "@inquirer/select";
|
|
3
|
+
import { createErc20Command } from "./deposit/erc20.js";
|
|
4
|
+
import { createErc721Command } from "./deposit/erc721.js";
|
|
5
|
+
import { createEtherCommand } from "./deposit/ether.js";
|
|
6
|
+
export const createDepositCommand = () => {
|
|
7
|
+
const command = new Command("deposit")
|
|
8
|
+
.description("Deposits an asset to the application")
|
|
9
|
+
.configureHelp({ showGlobalOptions: true })
|
|
10
|
+
.option("--from <address>", "input sender address")
|
|
11
|
+
.option("--application <address>", "application address")
|
|
12
|
+
.option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
|
|
13
|
+
.option("--rpc-url <url>", "RPC URL of the Cartesi Devnet")
|
|
14
|
+
.action(async (options, command) => {
|
|
15
|
+
// get registered subcommands
|
|
16
|
+
const commands = command.commands;
|
|
17
|
+
// create choices for the selected prompt based on registered subcommands
|
|
18
|
+
const choices = commands.map((cmd) => ({
|
|
19
|
+
name: cmd.name(),
|
|
20
|
+
value: cmd,
|
|
21
|
+
description: cmd.description(),
|
|
22
|
+
}));
|
|
23
|
+
const subcommand = await select({
|
|
24
|
+
choices,
|
|
25
|
+
message: "Select type of asset to deposit",
|
|
26
|
+
});
|
|
27
|
+
// execute selected subcommand
|
|
28
|
+
subcommand.parseAsync(command.args);
|
|
29
|
+
});
|
|
30
|
+
command.addCommand(createEtherCommand());
|
|
31
|
+
command.addCommand(createErc20Command());
|
|
32
|
+
command.addCommand(createErc721Command());
|
|
33
|
+
// command.addCommand(createErc1155BatchCommand());
|
|
34
|
+
// command.addCommand(createErc1155SingleCommand());
|
|
35
|
+
return command;
|
|
36
|
+
};
|
package/dist/commands/logs.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;;;;;
|
|
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;;;;;;;MA4C7B,CAAC"}
|
package/dist/commands/logs.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { Command } from "@commander-js/extra-typings";
|
|
2
2
|
import { execa } from "execa";
|
|
3
|
-
import {
|
|
3
|
+
import { getProjectName } from "../base.js";
|
|
4
4
|
export const createLogsCommand = () => {
|
|
5
5
|
return new Command("logs")
|
|
6
6
|
.description("Show logs of a local environment.")
|
|
7
|
-
.option("--
|
|
7
|
+
.option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
|
|
8
8
|
.option("-f, --follow", "Follow log output")
|
|
9
9
|
.option("--no-color", "Produce monochrome output")
|
|
10
10
|
.option("--since <string>", "Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)")
|
|
11
11
|
.option("-n, --tail <string>", "Number of lines to show from the end of the logs", "all")
|
|
12
12
|
.option("--until <string>", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)")
|
|
13
13
|
.configureHelp({ showGlobalOptions: true })
|
|
14
|
-
.action(async (
|
|
14
|
+
.action(async (options, command) => {
|
|
15
|
+
const { follow, color, since, tail, until } = options;
|
|
16
|
+
const projectName = getProjectName(options);
|
|
15
17
|
const logOptions = ["--no-log-prefix"];
|
|
16
18
|
if (follow)
|
|
17
19
|
logOptions.push("--follow");
|
|
@@ -24,7 +26,7 @@ export const createLogsCommand = () => {
|
|
|
24
26
|
await execa("docker", [
|
|
25
27
|
"compose",
|
|
26
28
|
"--project-name",
|
|
27
|
-
|
|
29
|
+
projectName,
|
|
28
30
|
"logs",
|
|
29
31
|
...logOptions,
|
|
30
32
|
"rollups-node",
|
package/dist/commands/run.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { Command } from "@commander-js/extra-typings";
|
|
2
|
-
export declare const createRunCommand: () => Command<[], {
|
|
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
|
+
}, {}>;
|
|
3
15
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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
CHANGED
|
@@ -1,10 +1,202 @@
|
|
|
1
|
-
import { Command } from "@commander-js/extra-typings";
|
|
1
|
+
import { Command, Option, } from "@commander-js/extra-typings";
|
|
2
|
+
import { ExitPromptError } from "@inquirer/core";
|
|
2
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 = undefined;
|
|
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
|
+
};
|
|
3
117
|
export const createRunCommand = () => {
|
|
4
118
|
return new Command("run")
|
|
5
119
|
.description("Run a local cartesi node for the application.")
|
|
6
|
-
.
|
|
7
|
-
.
|
|
8
|
-
|
|
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();
|
|
9
201
|
});
|
|
10
202
|
};
|
package/dist/commands/send.d.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import { Command } from "@commander-js/extra-typings";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}) => Promise<{
|
|
9
|
-
publicClient: PublicClient;
|
|
10
|
-
walletClient: WalletClient;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const getInputApplicationAddress: (dapp?: string) => Promise<Address>;
|
|
13
|
-
export declare const createSendCommand: () => Command<[], {
|
|
14
|
-
chainId: number;
|
|
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;
|
|
15
8
|
rpcUrl?: string | undefined;
|
|
16
|
-
mnemonic?: string | undefined;
|
|
17
|
-
mnemonicIndex: number;
|
|
18
|
-
dapp?: `0x${string}` | undefined;
|
|
19
9
|
}, {}>;
|
|
20
|
-
export type SendCommandOpts = ReturnType<ReturnType<typeof createSendCommand>["opts"]>;
|
|
21
10
|
//# sourceMappingURL=send.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/commands/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
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"}
|