@layr-labs/ecloud-cli 0.0.1-rfc.1 → 0.1.0-dev
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 +264 -48
- package/VERSION +2 -0
- package/dist/commands/auth/generate.js +116 -10
- package/dist/commands/auth/generate.js.map +1 -1
- package/dist/commands/auth/login.js +37 -35
- package/dist/commands/auth/login.js.map +1 -1
- package/dist/commands/auth/logout.js +2 -8
- package/dist/commands/auth/logout.js.map +1 -1
- package/dist/commands/auth/migrate.js +32 -37
- package/dist/commands/auth/migrate.js.map +1 -1
- package/dist/commands/auth/whoami.js +53 -21
- package/dist/commands/auth/whoami.js.map +1 -1
- package/dist/commands/billing/cancel.js +83 -22
- package/dist/commands/billing/cancel.js.map +1 -1
- package/dist/commands/billing/status.js +92 -29
- package/dist/commands/billing/status.js.map +1 -1
- package/dist/commands/billing/subscribe.js +86 -31
- package/dist/commands/billing/subscribe.js.map +1 -1
- package/dist/commands/compute/app/configure/tls.js +150 -0
- package/dist/commands/compute/app/configure/tls.js.map +1 -0
- package/dist/commands/compute/app/create.js +134 -0
- package/dist/commands/compute/app/create.js.map +1 -0
- package/dist/commands/compute/app/deploy.js +1101 -0
- package/dist/commands/compute/app/deploy.js.map +1 -0
- package/dist/commands/compute/app/info.js +818 -0
- package/dist/commands/compute/app/info.js.map +1 -0
- package/dist/commands/compute/app/list.js +578 -0
- package/dist/commands/compute/app/list.js.map +1 -0
- package/dist/commands/compute/app/logs.js +639 -0
- package/dist/commands/compute/app/logs.js.map +1 -0
- package/dist/commands/compute/app/profile/set.js +1086 -0
- package/dist/commands/compute/app/profile/set.js.map +1 -0
- package/dist/commands/compute/app/start.js +675 -0
- package/dist/commands/compute/app/start.js.map +1 -0
- package/dist/commands/compute/app/stop.js +675 -0
- package/dist/commands/compute/app/stop.js.map +1 -0
- package/dist/commands/compute/app/terminate.js +681 -0
- package/dist/commands/compute/app/terminate.js.map +1 -0
- package/dist/commands/compute/app/upgrade.js +1072 -0
- package/dist/commands/compute/app/upgrade.js.map +1 -0
- package/dist/commands/compute/environment/list.js +89 -0
- package/dist/commands/compute/environment/list.js.map +1 -0
- package/dist/commands/compute/environment/set.js +215 -0
- package/dist/commands/compute/environment/set.js.map +1 -0
- package/dist/commands/compute/environment/show.js +96 -0
- package/dist/commands/compute/environment/show.js.map +1 -0
- package/dist/commands/compute/undelegate.js +259 -0
- package/dist/commands/compute/undelegate.js.map +1 -0
- package/dist/commands/upgrade.js +91 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/commands/version.js +65 -0
- package/dist/commands/version.js.map +1 -0
- package/package.json +30 -5
- package/dist/commands/app/create.js +0 -29
- package/dist/commands/app/create.js.map +0 -1
- package/dist/commands/app/deploy.js +0 -142
- package/dist/commands/app/deploy.js.map +0 -1
- package/dist/commands/app/logs.js +0 -108
- package/dist/commands/app/logs.js.map +0 -1
- package/dist/commands/app/start.js +0 -121
- package/dist/commands/app/start.js.map +0 -1
- package/dist/commands/app/stop.js +0 -121
- package/dist/commands/app/stop.js.map +0 -1
- package/dist/commands/app/terminate.js +0 -128
- package/dist/commands/app/terminate.js.map +0 -1
- package/dist/commands/app/upgrade.js +0 -142
- package/dist/commands/app/upgrade.js.map +0 -1
- package/dist/keys/mainnet-alpha/prod/kms-encryption-public-key.pem +0 -14
- package/dist/keys/mainnet-alpha/prod/kms-signing-public-key.pem +0 -4
- package/dist/keys/sepolia/dev/kms-encryption-public-key.pem +0 -14
- package/dist/keys/sepolia/dev/kms-signing-public-key.pem +0 -4
- package/dist/keys/sepolia/prod/kms-encryption-public-key.pem +0 -14
- package/dist/keys/sepolia/prod/kms-signing-public-key.pem +0 -4
- package/dist/templates/Dockerfile.layered.tmpl +0 -58
- package/dist/templates/compute-source-env.sh.tmpl +0 -110
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/compute/app/start.ts
|
|
4
|
+
import { Command, Args } from "@oclif/core";
|
|
5
|
+
|
|
6
|
+
// src/client.ts
|
|
7
|
+
import {
|
|
8
|
+
createAppModule,
|
|
9
|
+
createBillingModule,
|
|
10
|
+
getEnvironmentConfig as getEnvironmentConfig2,
|
|
11
|
+
requirePrivateKey,
|
|
12
|
+
getPrivateKeyWithSource
|
|
13
|
+
} from "@layr-labs/ecloud-sdk";
|
|
14
|
+
|
|
15
|
+
// src/flags.ts
|
|
16
|
+
import { Flags } from "@oclif/core";
|
|
17
|
+
|
|
18
|
+
// src/utils/prompts.ts
|
|
19
|
+
import { input, select, password, confirm as inquirerConfirm } from "@inquirer/prompts";
|
|
20
|
+
import fs3 from "fs";
|
|
21
|
+
import path3 from "path";
|
|
22
|
+
import os3 from "os";
|
|
23
|
+
import { isAddress as isAddress2 } from "viem";
|
|
24
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
25
|
+
import {
|
|
26
|
+
getEnvironmentConfig,
|
|
27
|
+
getAvailableEnvironments,
|
|
28
|
+
isEnvironmentAvailable,
|
|
29
|
+
getAllAppsByDeveloper as getAllAppsByDeveloper2,
|
|
30
|
+
getCategoryDescriptions,
|
|
31
|
+
fetchTemplateCatalog,
|
|
32
|
+
PRIMARY_LANGUAGES,
|
|
33
|
+
validateAppName,
|
|
34
|
+
validateImageReference,
|
|
35
|
+
validateFilePath,
|
|
36
|
+
validatePrivateKeyFormat,
|
|
37
|
+
extractAppNameFromImage,
|
|
38
|
+
UserApiClient as UserApiClient2
|
|
39
|
+
} from "@layr-labs/ecloud-sdk";
|
|
40
|
+
|
|
41
|
+
// src/utils/appResolver.ts
|
|
42
|
+
import { isAddress } from "viem";
|
|
43
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
44
|
+
import {
|
|
45
|
+
UserApiClient,
|
|
46
|
+
getAllAppsByDeveloper
|
|
47
|
+
} from "@layr-labs/ecloud-sdk";
|
|
48
|
+
|
|
49
|
+
// src/utils/globalConfig.ts
|
|
50
|
+
import * as fs from "fs";
|
|
51
|
+
import * as path from "path";
|
|
52
|
+
import * as os from "os";
|
|
53
|
+
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
54
|
+
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
55
|
+
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
56
|
+
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
57
|
+
function getGlobalConfigDir() {
|
|
58
|
+
const configHome = process.env.XDG_CONFIG_HOME;
|
|
59
|
+
let baseDir;
|
|
60
|
+
if (configHome && path.isAbsolute(configHome)) {
|
|
61
|
+
baseDir = configHome;
|
|
62
|
+
} else {
|
|
63
|
+
baseDir = path.join(os.homedir(), ".config");
|
|
64
|
+
}
|
|
65
|
+
const buildType = getBuildType();
|
|
66
|
+
const buildSuffix = buildType === "dev" ? "-dev" : "";
|
|
67
|
+
const configDirName = `ecloud${buildSuffix}`;
|
|
68
|
+
return path.join(baseDir, configDirName);
|
|
69
|
+
}
|
|
70
|
+
function getGlobalConfigPath() {
|
|
71
|
+
return path.join(getGlobalConfigDir(), GLOBAL_CONFIG_FILE);
|
|
72
|
+
}
|
|
73
|
+
function loadGlobalConfig() {
|
|
74
|
+
const configPath = getGlobalConfigPath();
|
|
75
|
+
if (!fs.existsSync(configPath)) {
|
|
76
|
+
return {
|
|
77
|
+
first_run: true
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
82
|
+
const config = loadYaml(content);
|
|
83
|
+
return config || { first_run: true };
|
|
84
|
+
} catch {
|
|
85
|
+
return {
|
|
86
|
+
first_run: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function saveGlobalConfig(config) {
|
|
91
|
+
const configPath = getGlobalConfigPath();
|
|
92
|
+
const configDir = path.dirname(configPath);
|
|
93
|
+
fs.mkdirSync(configDir, { recursive: true, mode: 493 });
|
|
94
|
+
const content = dumpYaml(config, { lineWidth: -1 });
|
|
95
|
+
fs.writeFileSync(configPath, content, { mode: 420 });
|
|
96
|
+
}
|
|
97
|
+
function getDefaultEnvironment() {
|
|
98
|
+
const config = loadGlobalConfig();
|
|
99
|
+
return config.default_environment;
|
|
100
|
+
}
|
|
101
|
+
function getProfileCache(environment) {
|
|
102
|
+
const config = loadGlobalConfig();
|
|
103
|
+
const cacheEntry = config.profile_cache?.[environment];
|
|
104
|
+
if (!cacheEntry) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
if (now - cacheEntry.updated_at > PROFILE_CACHE_TTL_MS) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return cacheEntry.profiles;
|
|
112
|
+
}
|
|
113
|
+
function setProfileCache(environment, profiles) {
|
|
114
|
+
const config = loadGlobalConfig();
|
|
115
|
+
if (!config.profile_cache) {
|
|
116
|
+
config.profile_cache = {};
|
|
117
|
+
}
|
|
118
|
+
config.profile_cache[environment] = {
|
|
119
|
+
updated_at: Date.now(),
|
|
120
|
+
profiles
|
|
121
|
+
};
|
|
122
|
+
saveGlobalConfig(config);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/utils/appNames.ts
|
|
126
|
+
import * as fs2 from "fs";
|
|
127
|
+
import * as path2 from "path";
|
|
128
|
+
import * as os2 from "os";
|
|
129
|
+
import { load as loadYaml2, dump as dumpYaml2 } from "js-yaml";
|
|
130
|
+
var CONFIG_DIR = path2.join(os2.homedir(), ".eigenx");
|
|
131
|
+
var APPS_DIR = path2.join(CONFIG_DIR, "apps");
|
|
132
|
+
var APP_REGISTRY_VERSION = "1.0.0";
|
|
133
|
+
function getAppRegistryPath(environment) {
|
|
134
|
+
return path2.join(APPS_DIR, `${environment}.yaml`);
|
|
135
|
+
}
|
|
136
|
+
function loadAppRegistry(environment) {
|
|
137
|
+
const filePath = getAppRegistryPath(environment);
|
|
138
|
+
if (!fs2.existsSync(filePath)) {
|
|
139
|
+
return {
|
|
140
|
+
version: APP_REGISTRY_VERSION,
|
|
141
|
+
apps: {}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const content = fs2.readFileSync(filePath, "utf-8");
|
|
146
|
+
const registry = loadYaml2(content);
|
|
147
|
+
if (!registry.apps) {
|
|
148
|
+
registry.apps = {};
|
|
149
|
+
}
|
|
150
|
+
return registry;
|
|
151
|
+
} catch {
|
|
152
|
+
return {
|
|
153
|
+
version: APP_REGISTRY_VERSION,
|
|
154
|
+
apps: {}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function listApps(environment) {
|
|
159
|
+
const registry = loadAppRegistry(environment);
|
|
160
|
+
const result = {};
|
|
161
|
+
for (const [name, app] of Object.entries(registry.apps)) {
|
|
162
|
+
if (app?.app_id) {
|
|
163
|
+
result[name] = String(app.app_id);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/utils/version.ts
|
|
170
|
+
function getCliVersion() {
|
|
171
|
+
return true ? "0.1.0-dev" : "0.0.0";
|
|
172
|
+
}
|
|
173
|
+
function getClientId() {
|
|
174
|
+
return `ecloud-cli/v${getCliVersion()}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/utils/appResolver.ts
|
|
178
|
+
var CHUNK_SIZE = 10;
|
|
179
|
+
async function getAppInfosChunked(userApiClient, appIds, addressCount) {
|
|
180
|
+
if (appIds.length === 0) {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
const chunks = [];
|
|
184
|
+
for (let i = 0; i < appIds.length; i += CHUNK_SIZE) {
|
|
185
|
+
chunks.push(appIds.slice(i, i + CHUNK_SIZE));
|
|
186
|
+
}
|
|
187
|
+
const chunkResults = await Promise.all(
|
|
188
|
+
chunks.map((chunk) => userApiClient.getInfos(chunk, addressCount))
|
|
189
|
+
);
|
|
190
|
+
return chunkResults.flat();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/utils/prompts.ts
|
|
194
|
+
function addHexPrefix(value) {
|
|
195
|
+
if (value.startsWith("0x")) {
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
198
|
+
return `0x${value}`;
|
|
199
|
+
}
|
|
200
|
+
var ContractAppStatusStarted = 1;
|
|
201
|
+
var ContractAppStatusStopped = 2;
|
|
202
|
+
var ContractAppStatusTerminated = 3;
|
|
203
|
+
var ContractAppStatusSuspended = 4;
|
|
204
|
+
function getContractStatusString(status) {
|
|
205
|
+
switch (status) {
|
|
206
|
+
case ContractAppStatusStarted:
|
|
207
|
+
return "Started";
|
|
208
|
+
case ContractAppStatusStopped:
|
|
209
|
+
return "Stopped";
|
|
210
|
+
case ContractAppStatusTerminated:
|
|
211
|
+
return "Terminated";
|
|
212
|
+
case ContractAppStatusSuspended:
|
|
213
|
+
return "Suspended";
|
|
214
|
+
default:
|
|
215
|
+
return "Unknown";
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function getStatusPriority(status, isExited) {
|
|
219
|
+
if (isExited) {
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
switch (status) {
|
|
223
|
+
case ContractAppStatusStarted:
|
|
224
|
+
return 0;
|
|
225
|
+
case ContractAppStatusStopped:
|
|
226
|
+
return 2;
|
|
227
|
+
case ContractAppStatusTerminated:
|
|
228
|
+
return 3;
|
|
229
|
+
default:
|
|
230
|
+
return 4;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function formatAppDisplay(environmentName, appID, profileName) {
|
|
234
|
+
if (profileName) {
|
|
235
|
+
return `${profileName} (${environmentName}:${appID})`;
|
|
236
|
+
}
|
|
237
|
+
return `${environmentName}:${appID}`;
|
|
238
|
+
}
|
|
239
|
+
async function getOrPromptAppID(appIDOrOptions, environment) {
|
|
240
|
+
let options;
|
|
241
|
+
if (environment !== void 0) {
|
|
242
|
+
options = {
|
|
243
|
+
appID: appIDOrOptions,
|
|
244
|
+
environment
|
|
245
|
+
};
|
|
246
|
+
} else if (appIDOrOptions && typeof appIDOrOptions === "object" && "environment" in appIDOrOptions) {
|
|
247
|
+
options = appIDOrOptions;
|
|
248
|
+
} else {
|
|
249
|
+
options = {
|
|
250
|
+
appID: appIDOrOptions,
|
|
251
|
+
environment: "sepolia"
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
if (options.appID) {
|
|
255
|
+
const normalized = typeof options.appID === "string" ? addHexPrefix(options.appID) : options.appID;
|
|
256
|
+
if (isAddress2(normalized)) {
|
|
257
|
+
return normalized;
|
|
258
|
+
}
|
|
259
|
+
const profileCache = getProfileCache(options.environment);
|
|
260
|
+
if (profileCache) {
|
|
261
|
+
const searchName = options.appID.toLowerCase();
|
|
262
|
+
for (const [appId, name] of Object.entries(profileCache)) {
|
|
263
|
+
if (name.toLowerCase() === searchName) {
|
|
264
|
+
return appId;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const apps = listApps(options.environment);
|
|
269
|
+
const foundAppID = apps[options.appID];
|
|
270
|
+
if (foundAppID) {
|
|
271
|
+
return addHexPrefix(foundAppID);
|
|
272
|
+
}
|
|
273
|
+
throw new Error(
|
|
274
|
+
`App name '${options.appID}' not found in environment '${options.environment}'`
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
return getAppIDInteractive(options);
|
|
278
|
+
}
|
|
279
|
+
async function getAppIDInteractive(options) {
|
|
280
|
+
const action = options.action || "view";
|
|
281
|
+
const environment = options.environment || "sepolia";
|
|
282
|
+
const environmentConfig = getEnvironmentConfig(environment);
|
|
283
|
+
if (!options.privateKey || !options.rpcUrl) {
|
|
284
|
+
return getAppIDInteractiveFromRegistry(environment, action);
|
|
285
|
+
}
|
|
286
|
+
console.log(`
|
|
287
|
+
Select an app to ${action}:
|
|
288
|
+
`);
|
|
289
|
+
const privateKeyHex = addHexPrefix(options.privateKey);
|
|
290
|
+
const account = privateKeyToAccount2(privateKeyHex);
|
|
291
|
+
const developerAddr = account.address;
|
|
292
|
+
const { apps, appConfigs } = await getAllAppsByDeveloper2(
|
|
293
|
+
options.rpcUrl,
|
|
294
|
+
environmentConfig,
|
|
295
|
+
developerAddr
|
|
296
|
+
);
|
|
297
|
+
if (apps.length === 0) {
|
|
298
|
+
throw new Error("no apps found for your address");
|
|
299
|
+
}
|
|
300
|
+
const profileNames = {};
|
|
301
|
+
let cachedProfiles = getProfileCache(environment);
|
|
302
|
+
if (!cachedProfiles) {
|
|
303
|
+
try {
|
|
304
|
+
const userApiClient = new UserApiClient2(
|
|
305
|
+
environmentConfig,
|
|
306
|
+
options.privateKey,
|
|
307
|
+
options.rpcUrl,
|
|
308
|
+
getClientId()
|
|
309
|
+
);
|
|
310
|
+
const appInfos = await getAppInfosChunked(userApiClient, apps);
|
|
311
|
+
const freshProfiles = {};
|
|
312
|
+
for (const info of appInfos) {
|
|
313
|
+
if (info.profile?.name) {
|
|
314
|
+
const normalizedId = String(info.address).toLowerCase();
|
|
315
|
+
freshProfiles[normalizedId] = info.profile.name;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
setProfileCache(environment, freshProfiles);
|
|
319
|
+
cachedProfiles = freshProfiles;
|
|
320
|
+
} catch {
|
|
321
|
+
cachedProfiles = {};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const [appId, name] of Object.entries(cachedProfiles)) {
|
|
325
|
+
profileNames[appId.toLowerCase()] = name;
|
|
326
|
+
}
|
|
327
|
+
const localApps = listApps(environment);
|
|
328
|
+
for (const [name, appID] of Object.entries(localApps)) {
|
|
329
|
+
const normalizedID = String(appID).toLowerCase();
|
|
330
|
+
if (!profileNames[normalizedID]) {
|
|
331
|
+
profileNames[normalizedID] = name;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const isEligible = (status) => {
|
|
335
|
+
switch (action) {
|
|
336
|
+
case "view":
|
|
337
|
+
case "view info for":
|
|
338
|
+
case "set profile for":
|
|
339
|
+
return true;
|
|
340
|
+
case "start":
|
|
341
|
+
return status === ContractAppStatusStopped || status === ContractAppStatusSuspended;
|
|
342
|
+
case "stop":
|
|
343
|
+
return status === ContractAppStatusStarted;
|
|
344
|
+
default:
|
|
345
|
+
return status !== ContractAppStatusTerminated && status !== ContractAppStatusSuspended;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const appItems = [];
|
|
349
|
+
for (let i = 0; i < apps.length; i++) {
|
|
350
|
+
const appAddr = apps[i];
|
|
351
|
+
const config = appConfigs[i];
|
|
352
|
+
const status = config.status;
|
|
353
|
+
if (!isEligible(status)) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const statusStr = getContractStatusString(status);
|
|
357
|
+
const profileName = profileNames[String(appAddr).toLowerCase()] || "";
|
|
358
|
+
const displayName = formatAppDisplay(environmentConfig.name, appAddr, profileName);
|
|
359
|
+
appItems.push({
|
|
360
|
+
addr: appAddr,
|
|
361
|
+
display: `${displayName} - ${statusStr}`,
|
|
362
|
+
status,
|
|
363
|
+
index: i
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
appItems.sort((a, b) => {
|
|
367
|
+
const aPriority = getStatusPriority(a.status, false);
|
|
368
|
+
const bPriority = getStatusPriority(b.status, false);
|
|
369
|
+
if (aPriority !== bPriority) {
|
|
370
|
+
return aPriority - bPriority;
|
|
371
|
+
}
|
|
372
|
+
return b.index - a.index;
|
|
373
|
+
});
|
|
374
|
+
if (appItems.length === 0) {
|
|
375
|
+
switch (action) {
|
|
376
|
+
case "start":
|
|
377
|
+
throw new Error("no startable apps found - only Stopped apps can be started");
|
|
378
|
+
case "stop":
|
|
379
|
+
throw new Error("no running apps found - only Running apps can be stopped");
|
|
380
|
+
default:
|
|
381
|
+
throw new Error("no active apps found");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const choices = appItems.map((item) => ({
|
|
385
|
+
name: item.display,
|
|
386
|
+
value: item.addr
|
|
387
|
+
}));
|
|
388
|
+
const selected = await select({
|
|
389
|
+
message: "Select app:",
|
|
390
|
+
choices
|
|
391
|
+
});
|
|
392
|
+
return selected;
|
|
393
|
+
}
|
|
394
|
+
async function getAppIDInteractiveFromRegistry(environment, action) {
|
|
395
|
+
const allApps = {};
|
|
396
|
+
const cachedProfiles = getProfileCache(environment);
|
|
397
|
+
if (cachedProfiles) {
|
|
398
|
+
for (const [appId, name] of Object.entries(cachedProfiles)) {
|
|
399
|
+
allApps[name] = appId;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const localApps = listApps(environment);
|
|
403
|
+
for (const [name, appId] of Object.entries(localApps)) {
|
|
404
|
+
if (!allApps[name]) {
|
|
405
|
+
allApps[name] = appId;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (Object.keys(allApps).length === 0) {
|
|
409
|
+
console.log("\nNo apps found in registry.");
|
|
410
|
+
console.log("You can enter an app ID (address) or app name.");
|
|
411
|
+
console.log();
|
|
412
|
+
const appIDInput = await input({
|
|
413
|
+
message: "Enter app ID or name:",
|
|
414
|
+
default: "",
|
|
415
|
+
validate: (value) => {
|
|
416
|
+
if (!value) {
|
|
417
|
+
return "App ID or name cannot be empty";
|
|
418
|
+
}
|
|
419
|
+
const normalized2 = addHexPrefix(value);
|
|
420
|
+
if (isAddress2(normalized2)) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
return "Invalid app ID address";
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
const normalized = addHexPrefix(appIDInput);
|
|
427
|
+
if (isAddress2(normalized)) {
|
|
428
|
+
return normalized;
|
|
429
|
+
}
|
|
430
|
+
throw new Error(`Invalid app ID address: ${appIDInput}`);
|
|
431
|
+
}
|
|
432
|
+
const choices = Object.entries(allApps).map(([name, appID]) => {
|
|
433
|
+
const displayName = `${name} (${appID})`;
|
|
434
|
+
return { name: displayName, value: appID };
|
|
435
|
+
});
|
|
436
|
+
choices.push({ name: "Enter custom app ID or name", value: "custom" });
|
|
437
|
+
console.log(`
|
|
438
|
+
Select an app to ${action}:`);
|
|
439
|
+
const selected = await select({
|
|
440
|
+
message: "Choose app:",
|
|
441
|
+
choices
|
|
442
|
+
});
|
|
443
|
+
if (selected === "custom") {
|
|
444
|
+
const appIDInput = await input({
|
|
445
|
+
message: "Enter app ID or name:",
|
|
446
|
+
default: "",
|
|
447
|
+
validate: (value) => {
|
|
448
|
+
if (!value) {
|
|
449
|
+
return "App ID or name cannot be empty";
|
|
450
|
+
}
|
|
451
|
+
const normalized2 = addHexPrefix(value);
|
|
452
|
+
if (isAddress2(normalized2)) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
if (allApps[value]) {
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
return "Invalid app ID or name not found";
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
const normalized = addHexPrefix(appIDInput);
|
|
462
|
+
if (isAddress2(normalized)) {
|
|
463
|
+
return normalized;
|
|
464
|
+
}
|
|
465
|
+
const foundAppID = allApps[appIDInput];
|
|
466
|
+
if (foundAppID) {
|
|
467
|
+
return addHexPrefix(foundAppID);
|
|
468
|
+
}
|
|
469
|
+
throw new Error(`Failed to resolve app ID from input: ${appIDInput}`);
|
|
470
|
+
}
|
|
471
|
+
return addHexPrefix(selected);
|
|
472
|
+
}
|
|
473
|
+
async function confirm(prompt) {
|
|
474
|
+
return confirmWithDefault(prompt, false);
|
|
475
|
+
}
|
|
476
|
+
async function confirmWithDefault(prompt, defaultValue = false) {
|
|
477
|
+
return await inquirerConfirm({
|
|
478
|
+
message: prompt,
|
|
479
|
+
default: defaultValue
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
async function getPrivateKeyInteractive(privateKey) {
|
|
483
|
+
if (privateKey) {
|
|
484
|
+
if (!validatePrivateKeyFormat(privateKey)) {
|
|
485
|
+
throw new Error("Invalid private key format");
|
|
486
|
+
}
|
|
487
|
+
return privateKey;
|
|
488
|
+
}
|
|
489
|
+
const { getPrivateKeyWithSource: getPrivateKeyWithSource2 } = await import("@layr-labs/ecloud-sdk");
|
|
490
|
+
const result = await getPrivateKeyWithSource2({ privateKey: void 0 });
|
|
491
|
+
if (result) {
|
|
492
|
+
return result.key;
|
|
493
|
+
}
|
|
494
|
+
const key = await password({
|
|
495
|
+
message: "Enter private key:",
|
|
496
|
+
mask: true,
|
|
497
|
+
validate: (value) => {
|
|
498
|
+
if (!value.trim()) {
|
|
499
|
+
return "Private key is required";
|
|
500
|
+
}
|
|
501
|
+
if (!validatePrivateKeyFormat(value)) {
|
|
502
|
+
return "Invalid private key format (must be 64 hex characters, optionally prefixed with 0x)";
|
|
503
|
+
}
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
return key.trim();
|
|
508
|
+
}
|
|
509
|
+
async function getEnvironmentInteractive(environment) {
|
|
510
|
+
if (environment) {
|
|
511
|
+
try {
|
|
512
|
+
getEnvironmentConfig(environment);
|
|
513
|
+
if (!isEnvironmentAvailable(environment)) {
|
|
514
|
+
throw new Error(`Environment ${environment} is not available in this build`);
|
|
515
|
+
}
|
|
516
|
+
return environment;
|
|
517
|
+
} catch {
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const availableEnvs = getAvailableEnvironments();
|
|
521
|
+
let defaultEnv;
|
|
522
|
+
const configDefaultEnv = getDefaultEnvironment();
|
|
523
|
+
if (configDefaultEnv && availableEnvs.includes(configDefaultEnv)) {
|
|
524
|
+
try {
|
|
525
|
+
getEnvironmentConfig(configDefaultEnv);
|
|
526
|
+
defaultEnv = configDefaultEnv;
|
|
527
|
+
} catch {
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
const choices = [];
|
|
531
|
+
if (availableEnvs.includes("sepolia")) {
|
|
532
|
+
choices.push({ name: "sepolia - Ethereum Sepolia testnet", value: "sepolia" });
|
|
533
|
+
}
|
|
534
|
+
if (availableEnvs.includes("sepolia-dev")) {
|
|
535
|
+
choices.push({ name: "sepolia-dev - Ethereum Sepolia testnet (dev)", value: "sepolia-dev" });
|
|
536
|
+
}
|
|
537
|
+
if (availableEnvs.includes("mainnet-alpha")) {
|
|
538
|
+
choices.push({
|
|
539
|
+
name: "mainnet-alpha - Ethereum mainnet (\u26A0\uFE0F uses real funds)",
|
|
540
|
+
value: "mainnet-alpha"
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
if (choices.length === 0) {
|
|
544
|
+
throw new Error("No environments available in this build");
|
|
545
|
+
}
|
|
546
|
+
const env = await select({
|
|
547
|
+
message: "Select environment:",
|
|
548
|
+
choices,
|
|
549
|
+
default: defaultEnv
|
|
550
|
+
});
|
|
551
|
+
return env;
|
|
552
|
+
}
|
|
553
|
+
var MAX_IMAGE_SIZE = 4 * 1024 * 1024;
|
|
554
|
+
|
|
555
|
+
// src/flags.ts
|
|
556
|
+
var commonFlags = {
|
|
557
|
+
environment: Flags.string({
|
|
558
|
+
required: false,
|
|
559
|
+
description: "Deployment environment to use",
|
|
560
|
+
env: "ECLOUD_ENV"
|
|
561
|
+
}),
|
|
562
|
+
"private-key": Flags.string({
|
|
563
|
+
required: false,
|
|
564
|
+
description: "Private key for signing transactions",
|
|
565
|
+
env: "ECLOUD_PRIVATE_KEY"
|
|
566
|
+
}),
|
|
567
|
+
"rpc-url": Flags.string({
|
|
568
|
+
required: false,
|
|
569
|
+
description: "RPC URL to connect to blockchain",
|
|
570
|
+
env: "ECLOUD_RPC_URL"
|
|
571
|
+
}),
|
|
572
|
+
verbose: Flags.boolean({
|
|
573
|
+
required: false,
|
|
574
|
+
description: "Enable verbose logging (default: false)",
|
|
575
|
+
default: false
|
|
576
|
+
})
|
|
577
|
+
};
|
|
578
|
+
async function validateCommonFlags(flags) {
|
|
579
|
+
if (!flags["environment"]) {
|
|
580
|
+
flags["environment"] = getDefaultEnvironment();
|
|
581
|
+
}
|
|
582
|
+
flags["environment"] = await getEnvironmentInteractive(flags["environment"]);
|
|
583
|
+
flags["private-key"] = await getPrivateKeyInteractive(flags["private-key"]);
|
|
584
|
+
return flags;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/client.ts
|
|
588
|
+
async function createAppClient(flags) {
|
|
589
|
+
flags = await validateCommonFlags(flags);
|
|
590
|
+
const environment = flags.environment;
|
|
591
|
+
const environmentConfig = getEnvironmentConfig2(environment);
|
|
592
|
+
const rpcUrl = flags["rpc-url"] || environmentConfig.defaultRPCURL;
|
|
593
|
+
const { key: privateKey, source } = await requirePrivateKey({
|
|
594
|
+
privateKey: flags["private-key"]
|
|
595
|
+
});
|
|
596
|
+
if (flags.verbose) {
|
|
597
|
+
console.log(`Using private key from: ${source}`);
|
|
598
|
+
}
|
|
599
|
+
return createAppModule({
|
|
600
|
+
verbose: flags.verbose,
|
|
601
|
+
privateKey,
|
|
602
|
+
rpcUrl,
|
|
603
|
+
environment,
|
|
604
|
+
clientId: getClientId()
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// src/commands/compute/app/start.ts
|
|
609
|
+
import {
|
|
610
|
+
getEnvironmentConfig as getEnvironmentConfig3,
|
|
611
|
+
estimateTransactionGas,
|
|
612
|
+
encodeStartAppData,
|
|
613
|
+
isMainnet
|
|
614
|
+
} from "@layr-labs/ecloud-sdk";
|
|
615
|
+
import chalk from "chalk";
|
|
616
|
+
var AppLifecycleStart = class _AppLifecycleStart extends Command {
|
|
617
|
+
static description = "Start stopped app (start GCP instance)";
|
|
618
|
+
static args = {
|
|
619
|
+
"app-id": Args.string({
|
|
620
|
+
description: "App ID or name to start",
|
|
621
|
+
required: false
|
|
622
|
+
})
|
|
623
|
+
};
|
|
624
|
+
static flags = {
|
|
625
|
+
...commonFlags
|
|
626
|
+
};
|
|
627
|
+
async run() {
|
|
628
|
+
const { args, flags } = await this.parse(_AppLifecycleStart);
|
|
629
|
+
const app = await createAppClient(flags);
|
|
630
|
+
const environment = flags.environment || "sepolia";
|
|
631
|
+
const environmentConfig = getEnvironmentConfig3(environment);
|
|
632
|
+
const rpcUrl = flags.rpcUrl || environmentConfig.defaultRPCURL;
|
|
633
|
+
const privateKey = flags["private-key"] || await getPrivateKeyInteractive(environment);
|
|
634
|
+
const appId = await getOrPromptAppID({
|
|
635
|
+
appID: args["app-id"],
|
|
636
|
+
environment: flags["environment"],
|
|
637
|
+
privateKey,
|
|
638
|
+
rpcUrl,
|
|
639
|
+
action: "start"
|
|
640
|
+
});
|
|
641
|
+
const callData = encodeStartAppData(appId);
|
|
642
|
+
const estimate = await estimateTransactionGas({
|
|
643
|
+
privateKey,
|
|
644
|
+
rpcUrl,
|
|
645
|
+
environmentConfig,
|
|
646
|
+
to: environmentConfig.appControllerAddress,
|
|
647
|
+
data: callData
|
|
648
|
+
});
|
|
649
|
+
if (isMainnet(environmentConfig)) {
|
|
650
|
+
const confirmed = await confirm(`This will cost up to ${estimate.maxCostEth} ETH. Continue?`);
|
|
651
|
+
if (!confirmed) {
|
|
652
|
+
this.log(`
|
|
653
|
+
${chalk.gray(`Start cancelled`)}`);
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const res = await app.start(appId, {
|
|
658
|
+
gas: {
|
|
659
|
+
maxFeePerGas: estimate.maxFeePerGas,
|
|
660
|
+
maxPriorityFeePerGas: estimate.maxPriorityFeePerGas
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
if (!res.tx) {
|
|
664
|
+
this.log(`
|
|
665
|
+
${chalk.gray(`Start failed`)}`);
|
|
666
|
+
} else {
|
|
667
|
+
this.log(`
|
|
668
|
+
\u2705 ${chalk.green(`App started successfully`)}`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
export {
|
|
673
|
+
AppLifecycleStart as default
|
|
674
|
+
};
|
|
675
|
+
//# sourceMappingURL=start.js.map
|