@cartesi/cli 0.14.0
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/LICENSE +202 -0
- package/README.md +19 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +25 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +8 -0
- package/dist/baseCommand.d.ts +26 -0
- package/dist/baseCommand.d.ts.map +1 -0
- package/dist/baseCommand.js +80 -0
- package/dist/commands/address-book.d.ts +9 -0
- package/dist/commands/address-book.d.ts.map +1 -0
- package/dist/commands/address-book.js +21 -0
- package/dist/commands/build.d.ts +24 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +219 -0
- package/dist/commands/clean.d.ts +8 -0
- package/dist/commands/clean.d.ts.map +1 -0
- package/dist/commands/clean.js +11 -0
- package/dist/commands/create.d.ts +16 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +66 -0
- package/dist/commands/deploy/build.d.ts +12 -0
- package/dist/commands/deploy/build.d.ts.map +1 -0
- package/dist/commands/deploy/build.js +61 -0
- package/dist/commands/deploy/index.d.ts +13 -0
- package/dist/commands/deploy/index.d.ts.map +1 -0
- package/dist/commands/deploy/index.js +78 -0
- package/dist/commands/doctor.d.ts +13 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +106 -0
- package/dist/commands/hash.d.ts +10 -0
- package/dist/commands/hash.d.ts.map +1 -0
- package/dist/commands/hash.js +22 -0
- package/dist/commands/run.d.ts +15 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +137 -0
- package/dist/commands/send/dapp-address.d.ts +9 -0
- package/dist/commands/send/dapp-address.d.ts.map +1 -0
- package/dist/commands/send/dapp-address.js +20 -0
- package/dist/commands/send/erc20.d.ts +14 -0
- package/dist/commands/send/erc20.d.ts.map +1 -0
- package/dist/commands/send/erc20.js +70 -0
- package/dist/commands/send/erc721.d.ts +14 -0
- package/dist/commands/send/erc721.d.ts.map +1 -0
- package/dist/commands/send/erc721.js +73 -0
- package/dist/commands/send/ether.d.ts +13 -0
- package/dist/commands/send/ether.d.ts.map +1 -0
- package/dist/commands/send/ether.js +32 -0
- package/dist/commands/send/generic.d.ts +15 -0
- package/dist/commands/send/generic.d.ts.map +1 -0
- package/dist/commands/send/generic.js +119 -0
- package/dist/commands/send/index.d.ts +28 -0
- package/dist/commands/send/index.d.ts.map +1 -0
- package/dist/commands/send/index.js +102 -0
- package/dist/commands/shell.d.ts +14 -0
- package/dist/commands/shell.d.ts.map +1 -0
- package/dist/commands/shell.js +65 -0
- package/dist/contracts.d.ts +4863 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +2074 -0
- package/dist/flags.d.ts +17 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.js +28 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/node/DockerfileDeploy.txt +4 -0
- package/dist/node/default.env +28 -0
- package/dist/node/docker-compose-anvil.yaml +49 -0
- package/dist/node/docker-compose-database.yaml +15 -0
- package/dist/node/docker-compose-envfile.yaml +4 -0
- package/dist/node/docker-compose-explorer.yaml +84 -0
- package/dist/node/docker-compose-host.yaml +30 -0
- package/dist/node/docker-compose-prompt.yaml +17 -0
- package/dist/node/docker-compose-proxy.yaml +48 -0
- package/dist/node/docker-compose-snapshot-volume.yaml +8 -0
- package/dist/node/docker-compose-validator.yaml +59 -0
- package/dist/prompts.d.ts +62 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +159 -0
- package/dist/types/docker.d.ts +22 -0
- package/dist/types/docker.d.ts.map +1 -0
- package/dist/types/docker.js +1 -0
- package/dist/wallet.d.ts +24 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +204 -0
- package/oclif.manifest.json +887 -0
- package/package.json +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2024 Cartesi and individual contributors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Cartesi CLI
|
|
2
|
+
|
|
3
|
+
Cartesi CLI provides a tool to help developers to:
|
|
4
|
+
|
|
5
|
+
- `create` applications from templates
|
|
6
|
+
- `build` applications from source to a cartesi machine
|
|
7
|
+
- `run` applications in a local development environment
|
|
8
|
+
- `deploy` applications to a live network
|
|
9
|
+
|
|
10
|
+
It's distributed through several channels including `npm` and `homebrew`.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
brew install cartesi/tap/cartesi
|
|
16
|
+
cartesi --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
More documentation at [https://docs.cartesi.io](https://docs.cartesi.io).
|
package/bin/dev.cmd
ADDED
package/bin/dev.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node --no-warnings=ExperimentalWarning --loader ts-node/esm
|
|
2
|
+
|
|
3
|
+
import oclif from "@oclif/core";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import url from "node:url";
|
|
6
|
+
import { register } from "ts-node";
|
|
7
|
+
|
|
8
|
+
// In dev mode -> use ts-node and dev plugins
|
|
9
|
+
process.env.NODE_ENV = "development";
|
|
10
|
+
|
|
11
|
+
const project = path.join(
|
|
12
|
+
path.dirname(url.fileURLToPath(import.meta.url)),
|
|
13
|
+
"..",
|
|
14
|
+
"tsconfig.json"
|
|
15
|
+
);
|
|
16
|
+
register({ project });
|
|
17
|
+
|
|
18
|
+
// In dev mode, always show stack traces
|
|
19
|
+
oclif.settings.debug = true;
|
|
20
|
+
|
|
21
|
+
// Start the CLI
|
|
22
|
+
oclif
|
|
23
|
+
.run(process.argv.slice(2), import.meta.url)
|
|
24
|
+
.then(oclif.flush)
|
|
25
|
+
.catch(oclif.Errors.handle);
|
package/bin/run.cmd
ADDED
package/bin/run.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Command, Interfaces } from "@oclif/core";
|
|
2
|
+
import { Address, Hash } from "viem";
|
|
3
|
+
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof BaseCommand)["baseFlags"] & T["flags"]>;
|
|
4
|
+
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T["args"]>;
|
|
5
|
+
export type AddressBook = Record<string, Address>;
|
|
6
|
+
export interface DApp {
|
|
7
|
+
address: Address;
|
|
8
|
+
blockHash: Address;
|
|
9
|
+
blockNumber: number;
|
|
10
|
+
transactionHash: Address;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class BaseCommand<T extends typeof Command> extends Command {
|
|
13
|
+
protected flags: Flags<T>;
|
|
14
|
+
protected args: Args<T>;
|
|
15
|
+
protected getServiceState(projectName: string, serviceName: string): Promise<string | undefined>;
|
|
16
|
+
protected getContextPath(...paths: string[]): string;
|
|
17
|
+
protected getMachineHash(): Hash | undefined;
|
|
18
|
+
protected logPrompt({ title, value }: {
|
|
19
|
+
title: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}): void;
|
|
22
|
+
protected getApplicationAddress(): Promise<Address | undefined>;
|
|
23
|
+
protected getAddressBook(): Promise<AddressBook>;
|
|
24
|
+
init(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=baseCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseCommand.d.ts","sourceRoot":"","sources":["../src/baseCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKlD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,MAAM,CAAC;AAmB7C,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,OAAO,IAAI,UAAU,CAAC,aAAa,CAClE,CAAC,OAAO,WAAW,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CACjD,CAAC;AACF,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,OAAO,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAClD,MAAM,WAAW,IAAI;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;CAC5B;AAED,8BAAsB,WAAW,CAAC,CAAC,SAAS,OAAO,OAAO,CAAE,SAAQ,OAAO;IACvE,SAAS,CAAC,KAAK,EAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,IAAI,EAAG,IAAI,CAAC,CAAC,CAAC,CAAC;cAET,eAAe,CAC3B,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAe9B,SAAS,CAAC,cAAc,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAIpD,SAAS,CAAC,cAAc,IAAI,IAAI,GAAG,SAAS;IAY5C,SAAS,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;cAItD,qBAAqB,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;cAKrD,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IA0BzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAYrC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { execa } from "execa";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { isHash } from "viem";
|
|
7
|
+
import { authorityHistoryPairFactoryAddress, cartesiDAppFactoryAddress, dAppAddressRelayAddress, erc1155BatchPortalAddress, erc1155SinglePortalAddress, erc20PortalAddress, erc721PortalAddress, etherPortalAddress, inputBoxAddress, selfHostedApplicationFactoryAddress, testMultiTokenAddress, testNftAddress, testTokenAddress, } from "./contracts.js";
|
|
8
|
+
export class BaseCommand extends Command {
|
|
9
|
+
async getServiceState(projectName, serviceName) {
|
|
10
|
+
// get service information
|
|
11
|
+
const { stdout } = await execa("docker", [
|
|
12
|
+
"compose",
|
|
13
|
+
"--project-name",
|
|
14
|
+
projectName,
|
|
15
|
+
"ps",
|
|
16
|
+
serviceName,
|
|
17
|
+
"--format",
|
|
18
|
+
"json",
|
|
19
|
+
]);
|
|
20
|
+
const ps = stdout ? JSON.parse(stdout) : undefined;
|
|
21
|
+
return ps?.State;
|
|
22
|
+
}
|
|
23
|
+
getContextPath(...paths) {
|
|
24
|
+
return path.join(".cartesi", ...paths);
|
|
25
|
+
}
|
|
26
|
+
getMachineHash() {
|
|
27
|
+
// read hash of the cartesi machine snapshot, if one exists
|
|
28
|
+
const hashPath = this.getContextPath("image", "hash");
|
|
29
|
+
if (fs.existsSync(hashPath)) {
|
|
30
|
+
const hash = fs.readFileSync(hashPath).toString("hex");
|
|
31
|
+
if (isHash(`0x${hash}`)) {
|
|
32
|
+
return `0x${hash}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
logPrompt({ title, value }) {
|
|
38
|
+
this.log(`${chalk.green("?")} ${title} ${chalk.cyan(value)}`);
|
|
39
|
+
}
|
|
40
|
+
async getApplicationAddress() {
|
|
41
|
+
// fixed value, as we do deterministic deployment with a zero hash
|
|
42
|
+
return "0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e";
|
|
43
|
+
}
|
|
44
|
+
async getAddressBook() {
|
|
45
|
+
// build rollups contracts address book
|
|
46
|
+
const contracts = {
|
|
47
|
+
AuthorityHistoryPairFactory: authorityHistoryPairFactoryAddress,
|
|
48
|
+
CartesiDAppFactory: cartesiDAppFactoryAddress,
|
|
49
|
+
DAppAddressRelay: dAppAddressRelayAddress,
|
|
50
|
+
ERC1155BatchPortal: erc1155BatchPortalAddress,
|
|
51
|
+
ERC1155SinglePortal: erc1155SinglePortalAddress,
|
|
52
|
+
ERC20Portal: erc20PortalAddress,
|
|
53
|
+
ERC721Portal: erc721PortalAddress,
|
|
54
|
+
EtherPortal: etherPortalAddress,
|
|
55
|
+
InputBox: inputBoxAddress,
|
|
56
|
+
SelfHostedApplicationFactory: selfHostedApplicationFactoryAddress,
|
|
57
|
+
TestToken: testTokenAddress,
|
|
58
|
+
TestNFT: testNftAddress,
|
|
59
|
+
TestMultiToken: testMultiTokenAddress,
|
|
60
|
+
};
|
|
61
|
+
// get dapp address
|
|
62
|
+
const applicationAddress = await this.getApplicationAddress();
|
|
63
|
+
if (applicationAddress) {
|
|
64
|
+
contracts["CartesiDApp"] = applicationAddress;
|
|
65
|
+
}
|
|
66
|
+
return contracts;
|
|
67
|
+
}
|
|
68
|
+
async init() {
|
|
69
|
+
await super.init();
|
|
70
|
+
const { args, flags } = await this.parse({
|
|
71
|
+
flags: this.ctor.flags,
|
|
72
|
+
baseFlags: super.ctor.baseFlags,
|
|
73
|
+
args: this.ctor.args,
|
|
74
|
+
enableJsonFlag: this.ctor.enableJsonFlag,
|
|
75
|
+
strict: this.ctor.strict,
|
|
76
|
+
});
|
|
77
|
+
this.flags = flags;
|
|
78
|
+
this.args = args;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AddressBook as AddressBookType, BaseCommand } from "../baseCommand.js";
|
|
2
|
+
export default class AddressBook extends BaseCommand<typeof AddressBook> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static enableJsonFlag: boolean;
|
|
7
|
+
run(): Promise<AddressBookType>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=address-book.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/commands/address-book.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhF,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW,CAAC,OAAO,WAAW,CAAC;IACpE,MAAM,CAAC,OAAO,SAAmD;IAEjE,MAAM,CAAC,WAAW,SACwF;IAE1G,MAAM,CAAC,QAAQ,WAA2C;IAE1D,OAAc,cAAc,UAAQ;IAEvB,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC;CAe/C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ux } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../baseCommand.js";
|
|
3
|
+
class AddressBook extends BaseCommand {
|
|
4
|
+
async run() {
|
|
5
|
+
const addressBook = await super.getAddressBook();
|
|
6
|
+
if (!this.jsonEnabled()) {
|
|
7
|
+
// print as a table
|
|
8
|
+
ux.table(Object.entries(addressBook).map(([name, address]) => ({
|
|
9
|
+
name,
|
|
10
|
+
address,
|
|
11
|
+
})), { name: { header: "Contract" }, address: {} });
|
|
12
|
+
}
|
|
13
|
+
// return (as json)
|
|
14
|
+
return addressBook;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
AddressBook.summary = "Prints addresses of smart contracts deployed.";
|
|
18
|
+
AddressBook.description = "Prints the addresses of all smart contracts deployed to the runtime environment of the application.";
|
|
19
|
+
AddressBook.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
20
|
+
AddressBook.enableJsonFlag = true;
|
|
21
|
+
export default AddressBook;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseCommand } from "../baseCommand.js";
|
|
2
|
+
export default class BuildApplication extends BaseCommand<typeof BuildApplication> {
|
|
3
|
+
static summary: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static args: {};
|
|
7
|
+
static flags: {
|
|
8
|
+
"from-image": import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
target: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Build DApp image (linux/riscv64). Returns image id.
|
|
13
|
+
* @param directory path of context containing Dockerfile
|
|
14
|
+
*/
|
|
15
|
+
private buildImage;
|
|
16
|
+
private getImageInfo;
|
|
17
|
+
private createTarball;
|
|
18
|
+
private sdkRun;
|
|
19
|
+
private static createRootfsTarCommand;
|
|
20
|
+
private static createExt2Command;
|
|
21
|
+
private static createMachineSnapshotCommand;
|
|
22
|
+
run(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAyBhD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,WAAW,CACrD,OAAO,gBAAgB,CAC1B;IACG,MAAM,CAAC,OAAO,SAAwB;IAEtC,MAAM,CAAC,WAAW,SAC8V;IAEhX,MAAM,CAAC,QAAQ,WAGb;IAEF,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,KAAK;;;MAWV;IAEF;;;OAGG;YACW,UAAU;YAcV,YAAY;YAkEZ,aAAa;YAgBb,MAAM;IA+BpB,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAoBrC,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAkBhC,OAAO,CAAC,MAAM,CAAC,4BAA4B;IA4B9B,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA0DpC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import bytes from "bytes";
|
|
3
|
+
import { execa } from "execa";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import semver from "semver";
|
|
6
|
+
import tmp from "tmp";
|
|
7
|
+
import { BaseCommand } from "../baseCommand.js";
|
|
8
|
+
import { DEFAULT_TEMPLATES_BRANCH } from "./create.js";
|
|
9
|
+
const CARTESI_LABEL_PREFIX = "io.cartesi.rollups";
|
|
10
|
+
const CARTESI_LABEL_RAM_SIZE = `${CARTESI_LABEL_PREFIX}.ram_size`;
|
|
11
|
+
const CARTESI_LABEL_DATA_SIZE = `${CARTESI_LABEL_PREFIX}.data_size`;
|
|
12
|
+
const CARTESI_DEFAULT_RAM_SIZE = "128Mi";
|
|
13
|
+
const CARTESI_LABEL_SDK_VERSION = `${CARTESI_LABEL_PREFIX}.sdk_version`;
|
|
14
|
+
const CARTESI_DEFAULT_SDK_VERSION = "0.6.0";
|
|
15
|
+
class BuildApplication extends BaseCommand {
|
|
16
|
+
/**
|
|
17
|
+
* Build DApp image (linux/riscv64). Returns image id.
|
|
18
|
+
* @param directory path of context containing Dockerfile
|
|
19
|
+
*/
|
|
20
|
+
async buildImage(options) {
|
|
21
|
+
const buildResult = tmp.tmpNameSync();
|
|
22
|
+
this.debug(`building docker image and writing result to ${buildResult}`);
|
|
23
|
+
const args = ["buildx", "build", "--load", "--iidfile", buildResult];
|
|
24
|
+
if (options.target) {
|
|
25
|
+
args.push("--target", options.target);
|
|
26
|
+
}
|
|
27
|
+
await execa("docker", [...args, process.cwd()], { stdio: "inherit" });
|
|
28
|
+
return fs.readFileSync(buildResult, "utf8");
|
|
29
|
+
}
|
|
30
|
+
async getImageInfo(image) {
|
|
31
|
+
const { stdout: jsonStr } = await execa("docker", [
|
|
32
|
+
"image",
|
|
33
|
+
"inspect",
|
|
34
|
+
image,
|
|
35
|
+
]);
|
|
36
|
+
// parse image info from docker inspect output
|
|
37
|
+
const [imageInfo] = JSON.parse(jsonStr);
|
|
38
|
+
// validate image architecture (must be riscv64)
|
|
39
|
+
if (imageInfo["Architecture"] !== "riscv64") {
|
|
40
|
+
throw new Error(`Invalid image Architecture: ${imageInfo["Architecture"]}. Expected riscv64`);
|
|
41
|
+
}
|
|
42
|
+
const labels = imageInfo["Config"]["Labels"] || {};
|
|
43
|
+
const info = {
|
|
44
|
+
cmd: imageInfo["Config"]["Cmd"] ?? [],
|
|
45
|
+
dataSize: labels[CARTESI_LABEL_DATA_SIZE] ?? "10Mb",
|
|
46
|
+
entrypoint: imageInfo["Config"]["Entrypoint"] ?? [],
|
|
47
|
+
env: imageInfo["Config"]["Env"] || [],
|
|
48
|
+
ramSize: labels[CARTESI_LABEL_RAM_SIZE] ?? CARTESI_DEFAULT_RAM_SIZE,
|
|
49
|
+
sdkVersion: labels[CARTESI_LABEL_SDK_VERSION] ??
|
|
50
|
+
CARTESI_DEFAULT_SDK_VERSION,
|
|
51
|
+
workdir: imageInfo["Config"]["WorkingDir"],
|
|
52
|
+
};
|
|
53
|
+
if (!info.entrypoint && !info.cmd) {
|
|
54
|
+
throw new Error("Undefined image ENTRYPOINT or CMD");
|
|
55
|
+
}
|
|
56
|
+
// fail if using unsupported sdk version
|
|
57
|
+
if (!semver.valid(info.sdkVersion)) {
|
|
58
|
+
this.warn("sdk version is not a valid semver");
|
|
59
|
+
}
|
|
60
|
+
else if (semver.lt(info.sdkVersion, CARTESI_DEFAULT_SDK_VERSION)) {
|
|
61
|
+
throw new Error(`Unsupported sdk version: ${info.sdkVersion} (used) < ${CARTESI_DEFAULT_SDK_VERSION} (minimum).
|
|
62
|
+
Update your application Dockerfile using one of the templates at https://github.com/cartesi/application-templates/tree/${DEFAULT_TEMPLATES_BRANCH}
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
// warn for using default values
|
|
66
|
+
info.sdkVersion ||
|
|
67
|
+
this.warn(`Undefined ${CARTESI_LABEL_SDK_VERSION} label, defaulting to ${CARTESI_DEFAULT_SDK_VERSION}`);
|
|
68
|
+
info.ramSize ||
|
|
69
|
+
this.warn(`Undefined ${CARTESI_LABEL_RAM_SIZE} label, defaulting to ${CARTESI_DEFAULT_RAM_SIZE}`);
|
|
70
|
+
// validate data size value
|
|
71
|
+
if (bytes(info.dataSize) === null) {
|
|
72
|
+
throw new Error(`Invalid ${CARTESI_LABEL_DATA_SIZE} value: ${info.dataSize}`);
|
|
73
|
+
}
|
|
74
|
+
// XXX: validate other values
|
|
75
|
+
return info;
|
|
76
|
+
}
|
|
77
|
+
// saves the OCI Image to a tarball
|
|
78
|
+
async createTarball(image, outputFilePath) {
|
|
79
|
+
// create docker tarball from app image
|
|
80
|
+
const { stdout: appCid } = await execa("docker", [
|
|
81
|
+
"image",
|
|
82
|
+
"save",
|
|
83
|
+
image,
|
|
84
|
+
"-o",
|
|
85
|
+
outputFilePath,
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
// this wraps the call to the sdk image with a one-shot approach
|
|
89
|
+
// the (inputPath, outputPath) signature will mount the input as a volume and copy the output with docker cp
|
|
90
|
+
async sdkRun(sdkImage, cmd, inputPath, outputPath) {
|
|
91
|
+
const { stdout: cid } = await execa("docker", [
|
|
92
|
+
"container",
|
|
93
|
+
"create",
|
|
94
|
+
"--volume",
|
|
95
|
+
`./${inputPath}:/tmp/input`,
|
|
96
|
+
sdkImage,
|
|
97
|
+
...cmd,
|
|
98
|
+
]);
|
|
99
|
+
await execa("docker", ["container", "start", "-a", cid], {
|
|
100
|
+
stdio: "inherit",
|
|
101
|
+
});
|
|
102
|
+
await execa("docker", [
|
|
103
|
+
"container",
|
|
104
|
+
"cp",
|
|
105
|
+
`${cid}:/tmp/output`,
|
|
106
|
+
outputPath,
|
|
107
|
+
]);
|
|
108
|
+
await execa("docker", ["container", "stop", cid]);
|
|
109
|
+
await execa("docker", ["container", "rm", cid]);
|
|
110
|
+
}
|
|
111
|
+
// returns the command to create rootfs tarball from an OCI Image tarball
|
|
112
|
+
static createRootfsTarCommand() {
|
|
113
|
+
const cmd = [
|
|
114
|
+
"cat",
|
|
115
|
+
"/tmp/input",
|
|
116
|
+
"|",
|
|
117
|
+
"crane",
|
|
118
|
+
"export",
|
|
119
|
+
"-", // OCI Image from stdin
|
|
120
|
+
"-", // rootfs tarball to stdout
|
|
121
|
+
"|",
|
|
122
|
+
"bsdtar",
|
|
123
|
+
"-cf",
|
|
124
|
+
"/tmp/output",
|
|
125
|
+
"--format=gnutar",
|
|
126
|
+
"@/dev/stdin", // rootfs tarball from stdin
|
|
127
|
+
];
|
|
128
|
+
return ["/usr/bin/env", "bash", "-c", cmd.join(" ")];
|
|
129
|
+
}
|
|
130
|
+
// returns the command to create ext2 from a rootfs
|
|
131
|
+
static createExt2Command(extraBytes) {
|
|
132
|
+
const blockSize = 4096;
|
|
133
|
+
const extraBlocks = Math.ceil(extraBytes / blockSize);
|
|
134
|
+
const extraSize = `+${extraBlocks}`;
|
|
135
|
+
return [
|
|
136
|
+
"xgenext2fs",
|
|
137
|
+
"--tarball",
|
|
138
|
+
"/tmp/input",
|
|
139
|
+
"--block-size",
|
|
140
|
+
blockSize.toString(),
|
|
141
|
+
"--faketime",
|
|
142
|
+
"-r",
|
|
143
|
+
extraSize,
|
|
144
|
+
"/tmp/output",
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
static createMachineSnapshotCommand(info) {
|
|
148
|
+
const ramSize = info.ramSize;
|
|
149
|
+
const driveLabel = "root"; // XXX: does this need to be customizable?
|
|
150
|
+
// list of environment variables of docker image
|
|
151
|
+
const envs = info.env.map((variable) => `--append-entrypoint=export ${variable}`);
|
|
152
|
+
// ENTRYPOINT and CMD as a space separated string
|
|
153
|
+
const entrypoint = [...info.entrypoint, ...info.cmd].join(" ");
|
|
154
|
+
// command to change working directory if WORKDIR is defined
|
|
155
|
+
const cwd = info.workdir ? `--append-init=WORKDIR=${info.workdir}` : "";
|
|
156
|
+
return [
|
|
157
|
+
"cartesi-machine",
|
|
158
|
+
"--assert-rolling-template",
|
|
159
|
+
`--ram-length=${ramSize}`,
|
|
160
|
+
`--flash-drive=label:${driveLabel},filename:/tmp/input`,
|
|
161
|
+
"--final-hash",
|
|
162
|
+
`--store=/tmp/output`,
|
|
163
|
+
"--append-bootargs=no4lvl",
|
|
164
|
+
cwd,
|
|
165
|
+
...envs,
|
|
166
|
+
`--append-entrypoint=${entrypoint}`,
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
async run() {
|
|
170
|
+
const { flags } = await this.parse(BuildApplication);
|
|
171
|
+
const snapshotPath = this.getContextPath("image");
|
|
172
|
+
const tarPath = this.getContextPath("image.tar");
|
|
173
|
+
const gnuTarPath = this.getContextPath("image.gnutar");
|
|
174
|
+
const ext2Path = this.getContextPath("image.ext2");
|
|
175
|
+
// clean up temp files we create along the process
|
|
176
|
+
tmp.setGracefulCleanup();
|
|
177
|
+
// use pre-existing image or build dapp image
|
|
178
|
+
const appImage = flags["from-image"] || (await this.buildImage(flags));
|
|
179
|
+
// prepare context directory
|
|
180
|
+
await fs.emptyDir(this.getContextPath()); // XXX: make it less error prone
|
|
181
|
+
// get and validate image info
|
|
182
|
+
const imageInfo = await this.getImageInfo(appImage);
|
|
183
|
+
// resolve sdk version
|
|
184
|
+
const sdkImage = `cartesi/sdk:${imageInfo.sdkVersion}`;
|
|
185
|
+
try {
|
|
186
|
+
// create docker tarball for image specified
|
|
187
|
+
await this.createTarball(appImage, tarPath);
|
|
188
|
+
// create rootfs tar
|
|
189
|
+
await this.sdkRun(sdkImage, BuildApplication.createRootfsTarCommand(), tarPath, gnuTarPath);
|
|
190
|
+
// create ext2
|
|
191
|
+
await this.sdkRun(sdkImage, BuildApplication.createExt2Command(bytes.parse(imageInfo.dataSize)), gnuTarPath, ext2Path);
|
|
192
|
+
// create machine snapshot
|
|
193
|
+
await this.sdkRun(sdkImage, BuildApplication.createMachineSnapshotCommand(imageInfo), ext2Path, snapshotPath);
|
|
194
|
+
await fs.chmod(snapshotPath, 0o755);
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
await fs.remove(gnuTarPath);
|
|
198
|
+
await fs.remove(tarPath);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
BuildApplication.summary = "Build application.";
|
|
203
|
+
BuildApplication.description = "Build application starting from a Dockerfile and ending with a snapshot of the corresponding Cartesi Machine already booted and yielded for the first time. This snapshot can be used to start a Cartesi node for the application using `run`. The process can also start from a Docker image built by the developer using `docker build` using the option `--from-image`";
|
|
204
|
+
BuildApplication.examples = [
|
|
205
|
+
"<%= config.bin %> <%= command.id %>",
|
|
206
|
+
"<%= config.bin %> <%= command.id %> --from-image my-app",
|
|
207
|
+
];
|
|
208
|
+
BuildApplication.args = {};
|
|
209
|
+
BuildApplication.flags = {
|
|
210
|
+
"from-image": Flags.string({
|
|
211
|
+
summary: "skip docker build and start from this image.",
|
|
212
|
+
description: "if the build process of the application Dockerfile needs more control the developer can build the image using the `docker build` command, and then start the build process of the Cartesi machine starting from that image.",
|
|
213
|
+
}),
|
|
214
|
+
target: Flags.string({
|
|
215
|
+
summary: "target of docker multi-stage build.",
|
|
216
|
+
description: "if the application Dockerfile uses a multi-stage strategy, and stage of the image to be exported as a Cartesi machine is not the last stage, use this parameter to specify the target stage.",
|
|
217
|
+
}),
|
|
218
|
+
};
|
|
219
|
+
export default BuildApplication;
|