@twin.org/move-to-json 0.0.3-next.1 → 0.0.3-next.10
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/README.md +8 -374
- package/dist/es/cli.js +1 -1
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/deploy.js +80 -9
- package/dist/es/commands/deploy.js.map +1 -1
- package/dist/locales/en.json +49 -7
- package/docs/changelog.md +219 -68
- package/docs/reference/classes/CLI.md +2 -2
- package/docs/reference/interfaces/INetworkConfig.md +9 -9
- package/docs/usage.md +170 -0
- package/locales/en.json +7 -3
- package/package.json +11 -7
- package/docs/examples.md +0 -98
package/README.md
CHANGED
|
@@ -1,387 +1,21 @@
|
|
|
1
1
|
# TWIN Move to JSON
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
### IOTA CLI Installation
|
|
8
|
-
|
|
9
|
-
Before using this tool, you need to install the IOTA CLI. The simplest way is using Homebrew:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
# Install IOTA CLI using Homebrew (macOS/Linux/WSL)
|
|
13
|
-
brew install iotaledger/tap/iota
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
**Alternative installation methods:**
|
|
17
|
-
|
|
18
|
-
For other platforms or installation from source, see the [official IOTA installation guide](https://docs.iota.org/developer/getting-started/install-iota).
|
|
19
|
-
|
|
20
|
-
**Verify installation:**
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
iota --version
|
|
24
|
-
```
|
|
3
|
+
This app provides a command line workflow for compiling Move contracts and producing deployment-ready JSON for IOTA networks. It is intended for development teams that want predictable build and deployment inputs across test and production environments.
|
|
25
4
|
|
|
26
5
|
## Installation
|
|
27
6
|
|
|
28
7
|
```shell
|
|
29
|
-
npm install -
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Quick Start
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# Build contracts for mainnet using environment variables (recommended)
|
|
36
|
-
npx move-to-json build "src/**/*.move" --load-env configs/mainnet.env --output smart-contract-deployments.json
|
|
37
|
-
|
|
38
|
-
# Deploy to mainnet using environment variables (recommended)
|
|
39
|
-
npx move-to-json deploy --load-env configs/mainnet.env --contracts smart-contract-deployments.json
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Environment Setup for Production Deployments
|
|
43
|
-
|
|
44
|
-
### Required Environment Variables
|
|
45
|
-
|
|
46
|
-
For production deployments, you need to set up environment variables containing your deployment credentials. The tool uses network-specific configuration files located in the `configs/` directory.
|
|
47
|
-
|
|
48
|
-
#### 1. Create Environment Files
|
|
49
|
-
|
|
50
|
-
Copy the environment templates for each network you plan to use:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
# Copy environment templates for each network
|
|
54
|
-
cp configs/testnet.env.example configs/testnet.env
|
|
55
|
-
cp configs/devnet.env.example configs/devnet.env
|
|
56
|
-
cp configs/mainnet.env.example configs/mainnet.env
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**Note:** Only copy the environment files for the networks you actually plan to deploy to. For development, you typically only need `testnet.env` and `devnet.env`.
|
|
60
|
-
|
|
61
|
-
#### 2. Generate Deployment Mnemonics
|
|
62
|
-
|
|
63
|
-
Use the wallet CLI to generate secure mnemonics and then manually update the appropriate network configuration files with the generated mnemonic.
|
|
64
|
-
|
|
65
|
-
### Environment Variable Reference
|
|
66
|
-
|
|
67
|
-
Each network has its own configuration file in the `configs/` directory with the required deployment mnemonic:
|
|
68
|
-
|
|
69
|
-
| Network | File | Required Variable |
|
|
70
|
-
| ------- | --------------------- | ------------------- |
|
|
71
|
-
| Testnet | `configs/testnet.env` | `DEPLOYER_MNEMONIC` |
|
|
72
|
-
| Devnet | `configs/devnet.env` | `DEPLOYER_MNEMONIC` |
|
|
73
|
-
| Mainnet | `configs/mainnet.env` | `DEPLOYER_MNEMONIC` |
|
|
74
|
-
|
|
75
|
-
### Security Best Practices
|
|
76
|
-
|
|
77
|
-
#### Local Development
|
|
78
|
-
|
|
79
|
-
- Store credentials in `configs/*.env` files (never commit to git - only commit `.example` files)
|
|
80
|
-
- Use test mnemonics with faucet funds for testnet/devnet
|
|
81
|
-
- Use dedicated deployment wallets separate from personal wallets
|
|
82
|
-
|
|
83
|
-
#### CI/CD and Production
|
|
84
|
-
|
|
85
|
-
- Store credentials in GitHub Secrets or your CI/CD secrets manager
|
|
86
|
-
- Use hardware wallets or HSM for mainnet deployment keys
|
|
87
|
-
- Implement approval workflows for mainnet deployments
|
|
88
|
-
- Monitor wallet balances and deployment costs
|
|
89
|
-
|
|
90
|
-
### Generating Credentials
|
|
91
|
-
|
|
92
|
-
#### 1. Generate Mnemonic and Seed
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
# Generate a new 24-word mnemonic and save to wallet.env
|
|
96
|
-
npx "@twin.org/wallet-cli" mnemonic --env wallet.env
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
#### 2. Generate Addresses from Seed
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# Generate 5 addresses and save to address.env
|
|
103
|
-
npx "@twin.org/wallet-cli" address --load-env wallet.env --seed '!SEED' --count 5 --env address.env
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Commands
|
|
107
|
-
|
|
108
|
-
### build
|
|
109
|
-
|
|
110
|
-
Compile Move contracts for a specific network:
|
|
111
|
-
|
|
112
|
-
```bash
|
|
113
|
-
# Using environment variables (recommended)
|
|
114
|
-
npx move-to-json build "src/**/*.move" --load-env configs/<network>.env [--output <file>]
|
|
115
|
-
|
|
116
|
-
# Using explicit network flag
|
|
117
|
-
npx move-to-json build "src/**/*.move" --network <network> [--output <file>]
|
|
118
|
-
|
|
119
|
-
# If installed globally
|
|
120
|
-
move-to-json build "src/**/*.move" --load-env configs/<network>.env [--output <file>]
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
**Options:**
|
|
124
|
-
|
|
125
|
-
- `--network <network>` - Target network (testnet/devnet/mainnet) **[Optional if using --load-env]**
|
|
126
|
-
- `--load-env <file>` - Load environment variables from file (must contain NETWORK variable)
|
|
127
|
-
- `--output <file>` - Output JSON file (default: smart-contract-deployments.json)
|
|
128
|
-
|
|
129
|
-
**What it does:**
|
|
130
|
-
|
|
131
|
-
1. Reads network from `--network` flag or `NETWORK` environment variable
|
|
132
|
-
2. Validates environment variables for the target network
|
|
133
|
-
3. Cleans build artifacts and Move.lock files
|
|
134
|
-
4. Compiles contracts using unified Move.toml (same bytecode for all networks)
|
|
135
|
-
5. Generates network-aware JSON with package IDs and base64 modules
|
|
136
|
-
|
|
137
|
-
**Key Changes:**
|
|
138
|
-
|
|
139
|
-
- **Unified Move.toml**: Uses single Move.toml file with `framework/testnet` for consistent builds
|
|
140
|
-
- **Network-agnostic compilation**: Same bytecode works across all networks
|
|
141
|
-
- **Environment-aware**: Network targeting handled by IOTA CLI environments, not Move.toml
|
|
142
|
-
|
|
143
|
-
**Example:**
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
# Build for testnet using environment variables (recommended)
|
|
147
|
-
npx move-to-json build "tests/fixtures/sources/**/*.move" --load-env configs/testnet.env --output tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
148
|
-
|
|
149
|
-
# Build for mainnet using environment variables (recommended)
|
|
150
|
-
npx move-to-json build "src/contracts/**/*.move" --load-env configs/mainnet.env --output smart-contract-deployments.json
|
|
151
|
-
|
|
152
|
-
# Alternative: using explicit network flag
|
|
153
|
-
npx move-to-json build "tests/fixtures/sources/**/*.move" --network testnet --output tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### deploy
|
|
157
|
-
|
|
158
|
-
Deploy compiled contracts to the specified network:
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
# Using environment variables (recommended)
|
|
162
|
-
npx move-to-json deploy --load-env configs/<network>.env [--contracts <file>] [options]
|
|
163
|
-
|
|
164
|
-
# Using explicit network flag
|
|
165
|
-
npx move-to-json deploy --network <network> [--load-env configs/<network>.env] [options]
|
|
166
|
-
|
|
167
|
-
# If installed globally
|
|
168
|
-
move-to-json deploy --load-env configs/<network>.env [--contracts <file>] [options]
|
|
8
|
+
npm install -D @twin.org/move-to-json
|
|
169
9
|
```
|
|
170
10
|
|
|
171
|
-
|
|
11
|
+
## Usage
|
|
172
12
|
|
|
173
|
-
|
|
174
|
-
- `--load-env <file>` - Load environment variables from file (must contain NETWORK variable)
|
|
175
|
-
- `--contracts <file>` - Compiled modules JSON file (default: smart-contract-deployments.json)
|
|
176
|
-
- `--dry-run` - Simulate deployment without executing
|
|
177
|
-
- `--force` - Force redeployment of existing packages
|
|
13
|
+
Usage of the CLI is shown in the examples [docs/usage.md](docs/usage.md)
|
|
178
14
|
|
|
179
|
-
|
|
15
|
+
## Reference
|
|
180
16
|
|
|
181
|
-
|
|
182
|
-
2. Loads environment variables from the file specified via `--load-env` flag
|
|
183
|
-
3. Validates deployment credentials are available
|
|
184
|
-
4. Checks wallet balance against gas requirements
|
|
185
|
-
5. Loads compiled contracts from JSON
|
|
186
|
-
6. Deploys using IOTA CLI with active network environment
|
|
187
|
-
7. Extracts and saves both Package ID and UpgradeCap ID
|
|
188
|
-
8. Updates JSON with deployed package information
|
|
17
|
+
Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
|
|
189
18
|
|
|
190
|
-
|
|
19
|
+
## Changelog
|
|
191
20
|
|
|
192
|
-
|
|
193
|
-
- **Network targeting**: Uses IOTA CLI environments instead of Move.toml configuration
|
|
194
|
-
- **Consistent deployment**: Same compiled bytecode deployed to all networks
|
|
195
|
-
- **UpgradeCap tracking**: Captures and stores UpgradeCap object ID for future package upgrades
|
|
196
|
-
|
|
197
|
-
**Prerequisites:**
|
|
198
|
-
Ensure IOTA CLI environments are configured:
|
|
199
|
-
|
|
200
|
-
```bash
|
|
201
|
-
# Check available environments
|
|
202
|
-
iota client envs
|
|
203
|
-
|
|
204
|
-
# Configure networks if missing
|
|
205
|
-
iota client new-env --alias testnet --rpc https://fullnode.testnet.iota.cafe:443
|
|
206
|
-
iota client new-env --alias mainnet --rpc https://api.mainnet.iota.cafe
|
|
207
|
-
iota client new-env --alias devnet --rpc https://api.devnet.iota.cafe
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
**Example:**
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
# Deploy to testnet using environment variables (recommended)
|
|
214
|
-
npx move-to-json deploy --load-env configs/testnet.env --contracts tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
215
|
-
|
|
216
|
-
# Deploy to mainnet using environment variables (recommended)
|
|
217
|
-
npx move-to-json deploy --load-env configs/mainnet.env --contracts tests/fixtures/smart-contract-deployments/smart-contract-deployments.json
|
|
218
|
-
|
|
219
|
-
# Dry run (simulation)
|
|
220
|
-
npx move-to-json deploy --load-env configs/testnet.env --contracts tests/fixtures/smart-contract-deployments/smart-contract-deployments.json --dry-run
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
**Output:**
|
|
224
|
-
The deployment saves both Package ID and UpgradeCap ID:
|
|
225
|
-
|
|
226
|
-
```json
|
|
227
|
-
{
|
|
228
|
-
"testnet": {
|
|
229
|
-
"packageId": "0x...",
|
|
230
|
-
"package": "base64data...",
|
|
231
|
-
"deployedPackageId": "0x239ad3ea39f0910a4dc4c98161bcde948fb5ed0d7d7ae6d9a593239c43af748e",
|
|
232
|
-
"upgradeCap": "0xfd6269c28e3931e41aa9d9e08ffabb8162cf1fd0baaef14094b4442e6c743edf"
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
**Important Note on UpgradeCap:**
|
|
238
|
-
The UpgradeCap ID is crucial for package upgrades. Keep this secure - it's required to upgrade your deployed packages in the future.
|
|
239
|
-
|
|
240
|
-
## Unified Move.toml Approach
|
|
241
|
-
|
|
242
|
-
The tool now uses a **unified Move.toml approach** that eliminates the need for network-specific Move.toml files. This provides better consistency and reduces complexity.
|
|
243
|
-
|
|
244
|
-
### Single Move.toml Configuration
|
|
245
|
-
|
|
246
|
-
Instead of multiple `Move.toml.{network}` files, use a single `Move.toml` file:
|
|
247
|
-
|
|
248
|
-
```toml
|
|
249
|
-
[package]
|
|
250
|
-
name = "my_contract"
|
|
251
|
-
version = "0.0.1"
|
|
252
|
-
edition = "2024.beta"
|
|
253
|
-
|
|
254
|
-
[dependencies]
|
|
255
|
-
Iota = {
|
|
256
|
-
git = "https://github.com/iotaledger/iota.git",
|
|
257
|
-
subdir = "crates/iota-framework/packages/iota-framework",
|
|
258
|
-
rev = "framework/testnet"
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
[addresses]
|
|
262
|
-
my_contract = "0x0"
|
|
263
|
-
|
|
264
|
-
[dev-dependencies]
|
|
265
|
-
# Optional: Override dependencies for testing
|
|
266
|
-
# Iota = { git = "https://github.com/iotaledger/iota.git", subdir = "crates/iota-framework/packages/iota-framework", rev = "framework/devnet", override = true }
|
|
267
|
-
|
|
268
|
-
[dev-addresses]
|
|
269
|
-
# Optional: Override addresses for development
|
|
270
|
-
# my_contract = "0x1234"
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Framework Version Strategy
|
|
274
|
-
|
|
275
|
-
- **Development/Testing**: Use `framework/testnet` for all networks
|
|
276
|
-
- **Production**: Same `framework/testnet` works for mainnet deployment
|
|
277
|
-
- **Consistency**: Same bytecode compiles for all target networks
|
|
278
|
-
|
|
279
|
-
### Network Targeting
|
|
280
|
-
|
|
281
|
-
Network targeting is handled through **IOTA CLI environments**, not Move.toml:
|
|
282
|
-
|
|
283
|
-
```bash
|
|
284
|
-
# Build once - same bytecode for all networks
|
|
285
|
-
iota move build
|
|
286
|
-
|
|
287
|
-
# Deploy to different networks by switching environments
|
|
288
|
-
iota client switch --env testnet && iota client publish
|
|
289
|
-
iota client switch --env mainnet && iota client publish
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### Benefits
|
|
293
|
-
|
|
294
|
-
- ✅ **Consistent builds** across all networks
|
|
295
|
-
- ✅ **Reduced complexity** - no file copying
|
|
296
|
-
- ✅ **Industry standard** approach
|
|
297
|
-
- ✅ **Better maintainability** - single source of truth
|
|
298
|
-
- ✅ **Eliminated build conflicts** between networks
|
|
299
|
-
|
|
300
|
-
## Package Upgrades and UpgradeCap Management
|
|
301
|
-
|
|
302
|
-
When you deploy a Move package on IOTA, the network creates an **UpgradeCap** (Upgrade Capability) object that controls the ability to upgrade that package. This tool automatically captures and stores the UpgradeCap ID for future use.
|
|
303
|
-
|
|
304
|
-
### What is an UpgradeCap?
|
|
305
|
-
|
|
306
|
-
The UpgradeCap is a special object that:
|
|
307
|
-
|
|
308
|
-
- **Controls package upgrades**: Only the holder can upgrade the package
|
|
309
|
-
- **Is created once**: Generated during initial package deployment
|
|
310
|
-
- **Must be preserved**: Lost UpgradeCap = no future upgrades possible
|
|
311
|
-
- **Is network-specific**: Each network deployment gets its own UpgradeCap
|
|
312
|
-
|
|
313
|
-
### UpgradeCap Storage
|
|
314
|
-
|
|
315
|
-
The tool stores UpgradeCap IDs in the smart-contract-deployments.json file:
|
|
316
|
-
|
|
317
|
-
```json
|
|
318
|
-
{
|
|
319
|
-
"testnet": {
|
|
320
|
-
"packageId": "0xabc123...",
|
|
321
|
-
"package": "base64data...",
|
|
322
|
-
"deployedPackageId": "0x239ad3ea39f0910a4dc4c98161bcde948fb5ed0d7d7ae6d9a593239c43af748e",
|
|
323
|
-
"upgradeCap": "0xfd6269c28e3931e41aa9d9e08ffabb8162cf1fd0baaef14094b4442e6c743edf"
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Using UpgradeCap for Package Upgrades
|
|
329
|
-
|
|
330
|
-
To upgrade a deployed package, you'll need the UpgradeCap ID:
|
|
331
|
-
|
|
332
|
-
```bash
|
|
333
|
-
# Example upgrade command (using IOTA CLI)
|
|
334
|
-
iota client call --package 0x2 --module package --function upgrade \
|
|
335
|
-
--args 0xfd6269c28e3931e41aa9d9e08ffabb8162cf1fd0baaef14094b4442e6c743edf \
|
|
336
|
-
--gas-budget 50000000
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
## Known Issues
|
|
340
|
-
|
|
341
|
-
### Windows
|
|
342
|
-
|
|
343
|
-
#### Long Path Limitation Error
|
|
344
|
-
|
|
345
|
-
**Error Symptoms:**
|
|
346
|
-
|
|
347
|
-
- Build commands fail with `Failed to reset to latest Git state 'mainnet'`
|
|
348
|
-
- Tests timeout during Move compilation
|
|
349
|
-
- Git dependency resolution failures
|
|
350
|
-
|
|
351
|
-
**Root Cause:**
|
|
352
|
-
Windows has a default file path length limitation of 260 characters. The IOTA framework repository contains files with very long paths (especially in test directories) that exceed this limit, causing Git operations to fail during dependency resolution.
|
|
353
|
-
|
|
354
|
-
**Solution:**
|
|
355
|
-
Enable long path support in both Git and Windows:
|
|
356
|
-
|
|
357
|
-
1. **Enable Git Long Paths:**
|
|
358
|
-
|
|
359
|
-
```bash
|
|
360
|
-
git config --global core.longpaths true
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
2. **Enable Windows Long Path Support (requires Administrator privileges):**
|
|
364
|
-
|
|
365
|
-
```powershell
|
|
366
|
-
# Run PowerShell as Administrator
|
|
367
|
-
Set-ItemProperty -Path 'HKLM:SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
3. **Restart your computer** for Windows registry changes to take effect.
|
|
371
|
-
|
|
372
|
-
**Verification:**
|
|
373
|
-
After applying the fix, you should see successful Git dependency updates:
|
|
374
|
-
|
|
375
|
-
```bash
|
|
376
|
-
UPDATING GIT DEPENDENCY https://github.com/iotaledger/iota.git
|
|
377
|
-
INCLUDING DEPENDENCY Iota
|
|
378
|
-
INCLUDING DEPENDENCY MoveStdlib
|
|
379
|
-
BUILDING nft
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
**Alternative Workaround:**
|
|
383
|
-
If you cannot enable long path support system-wide, you can use the `--skip-fetch-latest-git-deps` flag as a workaround, though this will use cached dependencies instead of the latest versions:
|
|
384
|
-
|
|
385
|
-
```bash
|
|
386
|
-
iota move build --skip-fetch-latest-git-deps
|
|
387
|
-
```
|
|
21
|
+
The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
|
package/dist/es/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ export class CLI extends CLIBase {
|
|
|
21
21
|
return this.execute({
|
|
22
22
|
title: "TWIN Move to JSON",
|
|
23
23
|
appName: "move-to-json",
|
|
24
|
-
version: "0.0.3-next.
|
|
24
|
+
version: "0.0.3-next.10", // x-release-please-version
|
|
25
25
|
icon: "⚙️ ",
|
|
26
26
|
supportsEnvFiles: true,
|
|
27
27
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/dist/es/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAEC;QAED,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,mBAAmB;YAC1B,OAAO,EAAE,cAAc;YACvB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAEC;QAED,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,mBAAmB;YAC1B,OAAO,EAAE,cAAc;YACvB,OAAO,EAAE,eAAe,EAAE,2BAA2B;YACrD,IAAI,EAAE,KAAK;YACX,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,OAAO,EAAE,mBAAmB;SACjD,EACD,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,EACzF,IAAI,CACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACO,aAAa,CAAC,OAAgB;QACvC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3B,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { CLIBase } from \"@twin.org/cli-core\";\nimport type { Command } from \"commander\";\nimport { buildCommandBuild } from \"./commands/build.js\";\nimport { buildCommandDeploy } from \"./commands/deploy.js\";\n\n/**\n * The main entry point for the Move to JSON CLI.\n */\nexport class CLI extends CLIBase {\n\t/**\n\t * Run the app.\n\t * @param argv The process arguments.\n\t * @param localesDirectory The directory for the locales, default to relative to the script.\n\t * @param options Additional options.\n\t * @param options.overrideOutputWidth Override the output width.\n\t * @returns The exit code.\n\t */\n\tpublic async run(\n\t\targv: string[],\n\t\tlocalesDirectory?: string,\n\t\toptions?: {\n\t\t\toverrideOutputWidth?: number;\n\t\t}\n\t): Promise<number> {\n\t\treturn this.execute(\n\t\t\t{\n\t\t\t\ttitle: \"TWIN Move to JSON\",\n\t\t\t\tappName: \"move-to-json\",\n\t\t\t\tversion: \"0.0.3-next.10\", // x-release-please-version\n\t\t\t\ticon: \"⚙️ \",\n\t\t\t\tsupportsEnvFiles: true,\n\t\t\t\toverrideOutputWidth: options?.overrideOutputWidth\n\t\t\t},\n\t\t\tlocalesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), \"../locales\"),\n\t\t\targv\n\t\t);\n\t}\n\n\t/**\n\t * Configure any options or actions at the root program level.\n\t * @param program The root program command.\n\t */\n\tprotected configureRoot(program: Command): void {\n\t\tbuildCommandBuild(program);\n\t\tbuildCommandDeploy(program);\n\t}\n}\n"]}
|
|
@@ -5,9 +5,12 @@ import path from "node:path";
|
|
|
5
5
|
import { IotaClient } from "@iota/iota-sdk/client";
|
|
6
6
|
import { requestIotaFromFaucetV0 } from "@iota/iota-sdk/faucet";
|
|
7
7
|
import { CLIDisplay, CLIParam, CLIUtils } from "@twin.org/cli-core";
|
|
8
|
-
import { Converter, GeneralError, Guards, I18n, Is, RandomHelper } from "@twin.org/core";
|
|
8
|
+
import { Coerce, Converter, GeneralError, Guards, I18n, Is, RandomHelper } from "@twin.org/core";
|
|
9
9
|
import { Bip39, Bip44 } from "@twin.org/crypto";
|
|
10
10
|
import { Iota, NetworkTypes } from "@twin.org/dlt-iota";
|
|
11
|
+
import { MemoryEntityStorageConnector } from "@twin.org/entity-storage-connector-memory";
|
|
12
|
+
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
13
|
+
import { EntityStorageVaultConnector, initSchema } from "@twin.org/vault-connector-entity-storage";
|
|
11
14
|
import { cleanBuildArtifactsInPath } from "../utils/buildArtifactUtils.js";
|
|
12
15
|
import { ensureEnvironment, execAsyncWithError } from "../utils/environmentUtils.js";
|
|
13
16
|
import { getDeploymentMnemonic, getDeploymentSeed, validateDeploymentEnvironment } from "../utils/envSetup.js";
|
|
@@ -398,6 +401,39 @@ async function determineDeploymentStrategy(contractData) {
|
|
|
398
401
|
}
|
|
399
402
|
return "initial-deploy";
|
|
400
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Query the on-chain UpgradeCap object to get the actual latest package ID.
|
|
406
|
+
* This is used to validate/correct the `published-at` value before upgrades,
|
|
407
|
+
* preventing failures when the deployment JSON is stale.
|
|
408
|
+
* @param rpcUrl RPC endpoint URL for the network.
|
|
409
|
+
* @param upgradeCapabilityId The UpgradeCap object ID on-chain.
|
|
410
|
+
* @returns The on-chain package ID and version, or undefined if query fails.
|
|
411
|
+
*/
|
|
412
|
+
async function queryUpgradeCapPackage(rpcUrl, upgradeCapabilityId) {
|
|
413
|
+
try {
|
|
414
|
+
const client = new IotaClient({ url: rpcUrl });
|
|
415
|
+
const response = await client.getObject({
|
|
416
|
+
id: upgradeCapabilityId,
|
|
417
|
+
options: { showContent: true }
|
|
418
|
+
});
|
|
419
|
+
if (response.data?.content?.dataType === "moveObject") {
|
|
420
|
+
const fields = response.data.content.fields;
|
|
421
|
+
const fieldPackage = Coerce.string(fields.package);
|
|
422
|
+
const fieldVersion = Coerce.number(fields.version);
|
|
423
|
+
if (Is.stringValue(fieldPackage) && Is.number(fieldVersion)) {
|
|
424
|
+
return {
|
|
425
|
+
package: fieldPackage,
|
|
426
|
+
version: fieldVersion
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
// If query fails (e.g. network issue), return undefined to fall back to JSON value
|
|
434
|
+
return undefined;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
401
437
|
/**
|
|
402
438
|
* Execute contract upgrade using iota client upgrade command.
|
|
403
439
|
* @param contractData Contract data containing upgrade capability.
|
|
@@ -405,10 +441,27 @@ async function determineDeploymentStrategy(contractData) {
|
|
|
405
441
|
* @returns Upgrade result with package ID and upgrade capability.
|
|
406
442
|
*/
|
|
407
443
|
async function executeContractUpgrade(contractData, config) {
|
|
408
|
-
//
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
444
|
+
// Start with lastDeployedPackageId from JSON as the candidate for "published-at"
|
|
445
|
+
let publishedAtPackageId = contractData.lastDeployedPackageId;
|
|
446
|
+
// Query the on-chain UpgradeCap to get the actual latest package ID.
|
|
447
|
+
// This prevents failures when the JSON is stale
|
|
448
|
+
if (Is.stringValue(contractData.upgradeCapabilityId)) {
|
|
449
|
+
CLIDisplay.task(I18n.formatMessage("commands.deploy.progress.queryingUpgradeCap"));
|
|
450
|
+
const onChainCap = await queryUpgradeCapPackage(config.rpc.url, contractData.upgradeCapabilityId);
|
|
451
|
+
if (onChainCap) {
|
|
452
|
+
CLIDisplay.value(I18n.formatMessage("commands.deploy.labels.onChainPackageId"), onChainCap.package, 1);
|
|
453
|
+
CLIDisplay.value(I18n.formatMessage("commands.deploy.labels.onChainVersion"), String(onChainCap.version), 1);
|
|
454
|
+
if (publishedAtPackageId !== onChainCap.package) {
|
|
455
|
+
CLIDisplay.value(I18n.formatMessage("commands.deploy.labels.warning"), I18n.formatMessage("commands.deploy.messages.staleJsonDetected", {
|
|
456
|
+
jsonPackageId: publishedAtPackageId ?? "none",
|
|
457
|
+
onChainPackageId: onChainCap.package
|
|
458
|
+
}), 2);
|
|
459
|
+
publishedAtPackageId = onChainCap.package;
|
|
460
|
+
contractData.lastDeployedPackageId = onChainCap.package;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!publishedAtPackageId) {
|
|
412
465
|
throw new GeneralError("commands", "commands.deploy.noPreviousDeploymentForUpgrade");
|
|
413
466
|
}
|
|
414
467
|
const moveTomlPaths = [];
|
|
@@ -424,8 +477,8 @@ async function executeContractUpgrade(contractData, config) {
|
|
|
424
477
|
const projectRoot = path.dirname(moveTomlPath);
|
|
425
478
|
const backupPath = await backupMoveToml(moveTomlPath);
|
|
426
479
|
try {
|
|
427
|
-
// Update Move.toml with "published-at" =
|
|
428
|
-
await updateMoveTomlPublishedAt(moveTomlPath,
|
|
480
|
+
// Update Move.toml with "published-at" = validated package ID (from chain or JSON)
|
|
481
|
+
await updateMoveTomlPublishedAt(moveTomlPath, publishedAtPackageId);
|
|
429
482
|
await validateContractIsBuilt(contractData, projectRoot);
|
|
430
483
|
// Execute upgrade command
|
|
431
484
|
const upgradeCapabilityId = contractData.upgradeCapabilityId;
|
|
@@ -624,6 +677,7 @@ async function deployContract(contractName, contractData, config, network, dryRu
|
|
|
624
677
|
* @returns The wallet address.
|
|
625
678
|
*/
|
|
626
679
|
async function getDeploymentWalletAddress(network, addressIndex, deployerMnemonic, deployerSeed) {
|
|
680
|
+
const vault = setupVault();
|
|
627
681
|
// Try to use seed first if available
|
|
628
682
|
const hexSeed = await getDeploymentSeed(network, deployerSeed);
|
|
629
683
|
let seed;
|
|
@@ -632,10 +686,27 @@ async function getDeploymentWalletAddress(network, addressIndex, deployerMnemoni
|
|
|
632
686
|
}
|
|
633
687
|
else {
|
|
634
688
|
const mnemonic = await getDeploymentMnemonic(network, deployerMnemonic);
|
|
689
|
+
await vault.setSecret("deployment/mnemonic", mnemonic);
|
|
635
690
|
seed = Bip39.mnemonicToSeed(mnemonic);
|
|
636
691
|
}
|
|
637
|
-
|
|
638
|
-
return
|
|
692
|
+
await vault.setSecret("deployment/seed", seed);
|
|
693
|
+
return Iota.getAddress(vault, {}, "deployment", 0, addressIndex);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Setup vault connectors for storing deployment keys and secrets.
|
|
697
|
+
* @returns An instance of IVaultConnector for use in deployment.
|
|
698
|
+
*/
|
|
699
|
+
function setupVault() {
|
|
700
|
+
initSchema();
|
|
701
|
+
const keyEntityStorage = new MemoryEntityStorageConnector({
|
|
702
|
+
entitySchema: "VaultKey"
|
|
703
|
+
});
|
|
704
|
+
const secretEntityStorage = new MemoryEntityStorageConnector({
|
|
705
|
+
entitySchema: "VaultSecret"
|
|
706
|
+
});
|
|
707
|
+
EntityStorageConnectorFactory.register("vault-key", () => keyEntityStorage);
|
|
708
|
+
EntityStorageConnectorFactory.register("vault-secret", () => secretEntityStorage);
|
|
709
|
+
return new EntityStorageVaultConnector();
|
|
639
710
|
}
|
|
640
711
|
/**
|
|
641
712
|
* Convert nanos to IOTA (1 IOTA = 1,000,000,000 nanos).
|