genlayer 0.18.1 → 0.18.2
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/CHANGELOG.md +9 -0
- package/dist/index.js +49 -29
- package/package.json +1 -1
- package/src/commands/contracts/call.ts +7 -49
- package/src/commands/contracts/deploy.ts +3 -2
- package/src/commands/contracts/index.ts +36 -11
- package/src/commands/contracts/write.ts +49 -0
- package/src/commands/general/init.ts +15 -20
- package/src/commands/general/start.ts +14 -10
- package/src/commands/keygen/create.ts +2 -2
- package/tests/actions/call.test.ts +22 -86
- package/tests/actions/create.test.ts +8 -8
- package/tests/actions/init.test.ts +173 -102
- package/tests/actions/start.test.ts +48 -24
- package/tests/actions/write.test.ts +102 -0
- package/tests/commands/write.test.ts +76 -0
- package/tests/libs/baseAction.test.ts +37 -26
- package/tests/services/simulator.test.ts +98 -102
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.2 (2025-05-29)
|
|
4
|
+
|
|
5
|
+
## 0.18.2-beta.0 (2025-05-29)
|
|
6
|
+
|
|
7
|
+
## 0.18.0-beta.0 (2025-05-09)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* separate read and write calls ([#222](https://github.com/yeagerai/genlayer-cli/issues/222)) ([fce8904](https://github.com/yeagerai/genlayer-cli/commit/fce8904f6b51587bfb9e690b0e42efe441f19b1d))
|
|
3
12
|
## 0.18.1 (2025-05-29)
|
|
4
13
|
|
|
5
14
|
## 0.18.0 (2025-05-28)
|
package/dist/index.js
CHANGED
|
@@ -17723,7 +17723,7 @@ var require_semver2 = __commonJS({
|
|
|
17723
17723
|
import { program } from "commander";
|
|
17724
17724
|
|
|
17725
17725
|
// package.json
|
|
17726
|
-
var version = "0.18.
|
|
17726
|
+
var version = "0.18.2";
|
|
17727
17727
|
var package_default = {
|
|
17728
17728
|
name: "genlayer",
|
|
17729
17729
|
version,
|
|
@@ -41979,10 +41979,7 @@ var InitAction = class extends BaseAction {
|
|
|
41979
41979
|
}
|
|
41980
41980
|
this.startSpinner("Initializing validators...");
|
|
41981
41981
|
await this.simulatorService.deleteAllValidators();
|
|
41982
|
-
await this.simulatorService.createRandomValidators(
|
|
41983
|
-
Number(options.numValidators),
|
|
41984
|
-
selectedLlmProviders
|
|
41985
|
-
);
|
|
41982
|
+
await this.simulatorService.createRandomValidators(Number(options.numValidators), selectedLlmProviders);
|
|
41986
41983
|
if (options.resetDb) {
|
|
41987
41984
|
this.setSpinnerText("Cleaning database...");
|
|
41988
41985
|
await this.simulatorService.cleanDatabase();
|
|
@@ -42064,7 +42061,10 @@ var StartAction = class extends BaseAction {
|
|
|
42064
42061
|
}
|
|
42065
42062
|
];
|
|
42066
42063
|
const llmProvidersAnswer = await inquirer3.prompt(questions);
|
|
42067
|
-
await this.simulatorService.createRandomValidators(
|
|
42064
|
+
await this.simulatorService.createRandomValidators(
|
|
42065
|
+
numValidators,
|
|
42066
|
+
llmProvidersAnswer.selectedLlmProviders
|
|
42067
|
+
);
|
|
42068
42068
|
} catch (error) {
|
|
42069
42069
|
this.failSpinner("Unable to initialize the validators", error);
|
|
42070
42070
|
return;
|
|
@@ -42253,10 +42253,11 @@ var DeployAction = class extends BaseAction {
|
|
|
42253
42253
|
this.setSpinnerText("Starting contract deployment...");
|
|
42254
42254
|
this.log("Deployment Parameters:", deployParams);
|
|
42255
42255
|
const hash2 = await client.deployContract(deployParams);
|
|
42256
|
+
this.log("Deployment Transaction Hash:", hash2);
|
|
42256
42257
|
const result = await client.waitForTransactionReceipt({
|
|
42257
42258
|
hash: hash2,
|
|
42258
|
-
retries:
|
|
42259
|
-
interval:
|
|
42259
|
+
retries: 50,
|
|
42260
|
+
interval: 5e3,
|
|
42260
42261
|
status: TransactionStatus.ACCEPTED
|
|
42261
42262
|
});
|
|
42262
42263
|
this.log("Deployment Receipt:", result);
|
|
@@ -42284,21 +42285,7 @@ var CallAction = class extends BaseAction {
|
|
|
42284
42285
|
const client = await this.getClient(rpc);
|
|
42285
42286
|
await client.initializeConsensusSmartContract();
|
|
42286
42287
|
this.startSpinner(`Calling method ${method} on contract at ${contractAddress}...`);
|
|
42287
|
-
const contractSchema = await client.getContractSchema(contractAddress);
|
|
42288
|
-
if (!contractSchema.methods.hasOwnProperty(method)) {
|
|
42289
|
-
this.failSpinner(`method ${method} not found.`);
|
|
42290
|
-
return;
|
|
42291
|
-
}
|
|
42292
|
-
const readonly = contractSchema.methods[method].readonly;
|
|
42293
|
-
if (readonly) {
|
|
42294
|
-
await this.executeRead(contractAddress, method, args);
|
|
42295
|
-
return;
|
|
42296
|
-
}
|
|
42297
|
-
await this.executeWrite(contractAddress, method, args);
|
|
42298
|
-
}
|
|
42299
|
-
async executeRead(contractAddress, method, args) {
|
|
42300
42288
|
try {
|
|
42301
|
-
const client = await this.getClient();
|
|
42302
42289
|
const result = await client.readContract({
|
|
42303
42290
|
address: contractAddress,
|
|
42304
42291
|
functionName: method,
|
|
@@ -42309,21 +42296,35 @@ var CallAction = class extends BaseAction {
|
|
|
42309
42296
|
this.failSpinner("Error during read operation", error);
|
|
42310
42297
|
}
|
|
42311
42298
|
}
|
|
42312
|
-
|
|
42299
|
+
};
|
|
42300
|
+
|
|
42301
|
+
// src/commands/contracts/write.ts
|
|
42302
|
+
var WriteAction = class extends BaseAction {
|
|
42303
|
+
constructor() {
|
|
42304
|
+
super();
|
|
42305
|
+
}
|
|
42306
|
+
async write({
|
|
42307
|
+
contractAddress,
|
|
42308
|
+
method,
|
|
42309
|
+
args,
|
|
42310
|
+
rpc
|
|
42311
|
+
}) {
|
|
42312
|
+
const client = await this.getClient(rpc);
|
|
42313
|
+
await client.initializeConsensusSmartContract();
|
|
42314
|
+
this.startSpinner(`Calling write method ${method} on contract at ${contractAddress}...`);
|
|
42313
42315
|
try {
|
|
42314
|
-
const client = await this.getClient();
|
|
42315
42316
|
const hash2 = await client.writeContract({
|
|
42316
42317
|
address: contractAddress,
|
|
42317
42318
|
functionName: method,
|
|
42318
42319
|
args,
|
|
42319
42320
|
value: 0n
|
|
42320
42321
|
});
|
|
42322
|
+
this.log("Write Transaction Hash:", hash2);
|
|
42321
42323
|
const result = await client.waitForTransactionReceipt({
|
|
42322
42324
|
hash: hash2,
|
|
42323
|
-
retries:
|
|
42324
|
-
interval:
|
|
42325
|
+
retries: 100,
|
|
42326
|
+
interval: 5e3
|
|
42325
42327
|
});
|
|
42326
|
-
this.log("Write transaction hash:", hash2);
|
|
42327
42328
|
this.succeedSpinner("Write operation successfully executed", result);
|
|
42328
42329
|
} catch (error) {
|
|
42329
42330
|
this.failSpinner("Error during write operation", error);
|
|
@@ -42339,7 +42340,12 @@ function parseArg(value, previous = []) {
|
|
|
42339
42340
|
return [...previous, value];
|
|
42340
42341
|
}
|
|
42341
42342
|
function initializeContractsCommands(program2) {
|
|
42342
|
-
program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--rpc <rpcUrl>", "RPC URL for the network").option(
|
|
42343
|
+
program2.command("deploy").description("Deploy intelligent contracts").option("--contract <contractPath>", "Path to the smart contract to deploy").option("--rpc <rpcUrl>", "RPC URL for the network").option(
|
|
42344
|
+
"--args <args...>",
|
|
42345
|
+
"Positional arguments for the contract (space-separated, use quotes for multi-word arguments)",
|
|
42346
|
+
parseArg,
|
|
42347
|
+
[]
|
|
42348
|
+
).action(async (options) => {
|
|
42343
42349
|
const deployer = new DeployAction();
|
|
42344
42350
|
if (options.contract) {
|
|
42345
42351
|
await deployer.deploy(options);
|
|
@@ -42348,10 +42354,24 @@ function initializeContractsCommands(program2) {
|
|
|
42348
42354
|
await deployer.deployScripts(deployScriptsOptions);
|
|
42349
42355
|
}
|
|
42350
42356
|
});
|
|
42351
|
-
program2.command("call <contractAddress> <method>").description("Call a contract method").option("--rpc <rpcUrl>", "RPC URL for the network").option(
|
|
42357
|
+
program2.command("call <contractAddress> <method>").description("Call a contract method without sending a transaction or changing the state").option("--rpc <rpcUrl>", "RPC URL for the network").option(
|
|
42358
|
+
"--args <args...>",
|
|
42359
|
+
"Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
|
|
42360
|
+
parseArg,
|
|
42361
|
+
[]
|
|
42362
|
+
).action(async (contractAddress, method, options) => {
|
|
42352
42363
|
const caller = new CallAction();
|
|
42353
42364
|
await caller.call({ contractAddress, method, ...options });
|
|
42354
42365
|
});
|
|
42366
|
+
program2.command("write <contractAddress> <method>").description("Sends a transaction to a contract method that modifies the state").option("--rpc <rpcUrl>", "RPC URL for the network").option(
|
|
42367
|
+
"--args <args...>",
|
|
42368
|
+
"Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
|
|
42369
|
+
parseArg,
|
|
42370
|
+
[]
|
|
42371
|
+
).action(async (contractAddress, method, options) => {
|
|
42372
|
+
const writer = new WriteAction();
|
|
42373
|
+
await writer.write({ contractAddress, method, ...options });
|
|
42374
|
+
});
|
|
42355
42375
|
return program2;
|
|
42356
42376
|
}
|
|
42357
42377
|
|
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { GenLayerClient } from "genlayer-js/types";
|
|
3
|
-
import { BaseAction } from "../../lib/actions/BaseAction";
|
|
1
|
+
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
4
2
|
|
|
5
3
|
export interface CallOptions {
|
|
6
4
|
args: any[];
|
|
7
5
|
rpc?: string;
|
|
8
6
|
}
|
|
9
7
|
|
|
10
|
-
export class CallAction extends BaseAction{
|
|
8
|
+
export class CallAction extends BaseAction {
|
|
11
9
|
constructor() {
|
|
12
10
|
super();
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
async call({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
contractAddress,
|
|
15
|
+
method,
|
|
16
|
+
args,
|
|
17
|
+
rpc,
|
|
18
|
+
}: {
|
|
21
19
|
contractAddress: string;
|
|
22
20
|
method: string;
|
|
23
21
|
args: any[];
|
|
@@ -27,26 +25,7 @@ export class CallAction extends BaseAction{
|
|
|
27
25
|
await client.initializeConsensusSmartContract();
|
|
28
26
|
this.startSpinner(`Calling method ${method} on contract at ${contractAddress}...`);
|
|
29
27
|
|
|
30
|
-
const contractSchema = await client.getContractSchema(contractAddress);
|
|
31
|
-
|
|
32
|
-
if(!contractSchema.methods.hasOwnProperty(method)){
|
|
33
|
-
this.failSpinner(`method ${method} not found.`);
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const readonly = contractSchema.methods[method as any].readonly;
|
|
38
|
-
|
|
39
|
-
if (readonly) {
|
|
40
|
-
await this.executeRead(contractAddress, method, args);
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await this.executeWrite(contractAddress, method, args);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private async executeRead(contractAddress: string, method: string, args: any[]): Promise<void> {
|
|
48
28
|
try {
|
|
49
|
-
const client = await this.getClient();
|
|
50
29
|
const result = await client.readContract({
|
|
51
30
|
address: contractAddress as any,
|
|
52
31
|
functionName: method,
|
|
@@ -57,25 +36,4 @@ export class CallAction extends BaseAction{
|
|
|
57
36
|
this.failSpinner("Error during read operation", error);
|
|
58
37
|
}
|
|
59
38
|
}
|
|
60
|
-
|
|
61
|
-
private async executeWrite(contractAddress: string, method: string, args: any[]): Promise<void> {
|
|
62
|
-
try {
|
|
63
|
-
const client = await this.getClient();
|
|
64
|
-
const hash = await client.writeContract({
|
|
65
|
-
address: contractAddress as any,
|
|
66
|
-
functionName: method,
|
|
67
|
-
args,
|
|
68
|
-
value: 0n,
|
|
69
|
-
});
|
|
70
|
-
const result = await client.waitForTransactionReceipt({
|
|
71
|
-
hash,
|
|
72
|
-
retries: 15,
|
|
73
|
-
interval: 2000,
|
|
74
|
-
});
|
|
75
|
-
this.log("Write transaction hash:", hash);
|
|
76
|
-
this.succeedSpinner("Write operation successfully executed", result);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
this.failSpinner("Error during write operation", error);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
39
|
}
|
|
@@ -136,10 +136,11 @@ export class DeployAction extends BaseAction {
|
|
|
136
136
|
this.log("Deployment Parameters:", deployParams);
|
|
137
137
|
|
|
138
138
|
const hash = (await client.deployContract(deployParams)) as any;
|
|
139
|
+
this.log("Deployment Transaction Hash:", hash);
|
|
139
140
|
const result = await client.waitForTransactionReceipt({
|
|
140
141
|
hash,
|
|
141
|
-
retries:
|
|
142
|
-
interval:
|
|
142
|
+
retries: 50,
|
|
143
|
+
interval: 5000,
|
|
143
144
|
status: TransactionStatus.ACCEPTED,
|
|
144
145
|
});
|
|
145
146
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {Command} from "commander";
|
|
2
|
+
import {DeployAction, DeployOptions, DeployScriptsOptions} from "./deploy";
|
|
3
|
+
import {CallAction, CallOptions} from "./call";
|
|
4
|
+
import {WriteAction, WriteOptions} from "./write";
|
|
4
5
|
|
|
5
6
|
function parseArg(value: string, previous: any[] = []): any[] {
|
|
6
7
|
if (value === "true") return [...previous, true];
|
|
@@ -10,31 +11,55 @@ function parseArg(value: string, previous: any[] = []): any[] {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export function initializeContractsCommands(program: Command) {
|
|
13
|
-
|
|
14
14
|
program
|
|
15
15
|
.command("deploy")
|
|
16
16
|
.description("Deploy intelligent contracts")
|
|
17
17
|
.option("--contract <contractPath>", "Path to the smart contract to deploy")
|
|
18
18
|
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
19
|
-
.option(
|
|
19
|
+
.option(
|
|
20
|
+
"--args <args...>",
|
|
21
|
+
"Positional arguments for the contract (space-separated, use quotes for multi-word arguments)",
|
|
22
|
+
parseArg,
|
|
23
|
+
[],
|
|
24
|
+
)
|
|
20
25
|
.action(async (options: DeployOptions) => {
|
|
21
26
|
const deployer = new DeployAction();
|
|
22
|
-
if(options.contract){
|
|
27
|
+
if (options.contract) {
|
|
23
28
|
await deployer.deploy(options);
|
|
24
|
-
}else {
|
|
25
|
-
const deployScriptsOptions: DeployScriptsOptions = {
|
|
29
|
+
} else {
|
|
30
|
+
const deployScriptsOptions: DeployScriptsOptions = {rpc: options.rpc};
|
|
26
31
|
await deployer.deployScripts(deployScriptsOptions);
|
|
27
32
|
}
|
|
28
33
|
});
|
|
29
34
|
|
|
30
35
|
program
|
|
31
36
|
.command("call <contractAddress> <method>")
|
|
32
|
-
.description("Call a contract method")
|
|
37
|
+
.description("Call a contract method without sending a transaction or changing the state")
|
|
33
38
|
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
34
|
-
.option(
|
|
39
|
+
.option(
|
|
40
|
+
"--args <args...>",
|
|
41
|
+
"Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
|
|
42
|
+
parseArg,
|
|
43
|
+
[],
|
|
44
|
+
)
|
|
35
45
|
.action(async (contractAddress: string, method: string, options: CallOptions) => {
|
|
36
46
|
const caller = new CallAction();
|
|
37
|
-
await caller.call({
|
|
47
|
+
await caller.call({contractAddress, method, ...options});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
program
|
|
51
|
+
.command("write <contractAddress> <method>")
|
|
52
|
+
.description("Sends a transaction to a contract method that modifies the state")
|
|
53
|
+
.option("--rpc <rpcUrl>", "RPC URL for the network")
|
|
54
|
+
.option(
|
|
55
|
+
"--args <args...>",
|
|
56
|
+
"Positional arguments for the method (space-separated, use quotes for multi-word arguments)",
|
|
57
|
+
parseArg,
|
|
58
|
+
[],
|
|
59
|
+
)
|
|
60
|
+
.action(async (contractAddress: string, method: string, options: WriteOptions) => {
|
|
61
|
+
const writer = new WriteAction();
|
|
62
|
+
await writer.write({contractAddress, method, ...options});
|
|
38
63
|
});
|
|
39
64
|
|
|
40
65
|
return program;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// import {simulator} from "genlayer-js/chains";
|
|
2
|
+
// import type {GenLayerClient} from "genlayer-js/types";
|
|
3
|
+
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
4
|
+
|
|
5
|
+
export interface WriteOptions {
|
|
6
|
+
args: any[];
|
|
7
|
+
rpc?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class WriteAction extends BaseAction {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async write({
|
|
16
|
+
contractAddress,
|
|
17
|
+
method,
|
|
18
|
+
args,
|
|
19
|
+
rpc,
|
|
20
|
+
}: {
|
|
21
|
+
contractAddress: string;
|
|
22
|
+
method: string;
|
|
23
|
+
args: any[];
|
|
24
|
+
rpc?: string;
|
|
25
|
+
}): Promise<void> {
|
|
26
|
+
const client = await this.getClient(rpc);
|
|
27
|
+
await client.initializeConsensusSmartContract();
|
|
28
|
+
this.startSpinner(`Calling write method ${method} on contract at ${contractAddress}...`);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const hash = await client.writeContract({
|
|
32
|
+
address: contractAddress as any,
|
|
33
|
+
functionName: method,
|
|
34
|
+
args,
|
|
35
|
+
value: 0n,
|
|
36
|
+
});
|
|
37
|
+
this.log("Write Transaction Hash:", hash);
|
|
38
|
+
|
|
39
|
+
const result = await client.waitForTransactionReceipt({
|
|
40
|
+
hash,
|
|
41
|
+
retries: 100,
|
|
42
|
+
interval: 5000,
|
|
43
|
+
});
|
|
44
|
+
this.succeedSpinner("Write operation successfully executed", result);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
this.failSpinner("Error during write operation", error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import {DistinctQuestion} from "inquirer";
|
|
3
|
+
import {ISimulatorService} from "../../lib/interfaces/ISimulatorService";
|
|
4
|
+
import {AI_PROVIDERS_CONFIG, AiProviders} from "../../lib/config/simulator";
|
|
5
|
+
import {OllamaAction} from "../update/ollama";
|
|
6
|
+
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
7
|
+
import {SimulatorService} from "../../lib/services/simulator";
|
|
8
8
|
|
|
9
9
|
export interface InitActionOptions {
|
|
10
10
|
numValidators: number;
|
|
@@ -14,14 +14,14 @@ export interface InitActionOptions {
|
|
|
14
14
|
ollama: boolean;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function getRequirementsErrorMessage({
|
|
17
|
+
function getRequirementsErrorMessage({docker}: Record<string, boolean>): string {
|
|
18
18
|
if (!docker) {
|
|
19
19
|
return "Docker is not installed. Please install Docker and try again.\n";
|
|
20
20
|
}
|
|
21
21
|
return "";
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function getVersionErrorMessage({
|
|
24
|
+
function getVersionErrorMessage({docker, node}: Record<string, string>): string {
|
|
25
25
|
let message = "";
|
|
26
26
|
|
|
27
27
|
if (docker) {
|
|
@@ -73,7 +73,7 @@ export class InitAction extends BaseAction {
|
|
|
73
73
|
const confirmMessage = isRunning
|
|
74
74
|
? `GenLayer Localnet is already running and this command is going to reset GenLayer docker images and containers, providers API Keys, and GenLayer database (accounts, transactions, validators and logs). Contract code (gpy files) will be kept. Do you want to continue?`
|
|
75
75
|
: `This command is going to reset GenLayer docker images and containers, providers API Keys, and GenLayer database (accounts, transactions, validators and logs). Contract code (gpy files) will be kept. Do you want to continue?`;
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
await this.confirmPrompt(confirmMessage);
|
|
78
78
|
|
|
79
79
|
this.logInfo(`Initializing GenLayer CLI with ${options.numValidators} validators`);
|
|
@@ -90,8 +90,7 @@ export class InitAction extends BaseAction {
|
|
|
90
90
|
name: "selectedLlmProviders",
|
|
91
91
|
message: "Select which LLM providers do you want to use:",
|
|
92
92
|
choices: this.simulatorService.getAiProvidersOptions(true, options.ollama ? [] : ["ollama"]),
|
|
93
|
-
validate: (answer)
|
|
94
|
-
answer.length < 1 ? "You must choose at least one option." : true,
|
|
93
|
+
validate: answer => (answer.length < 1 ? "You must choose at least one option." : true),
|
|
95
94
|
},
|
|
96
95
|
];
|
|
97
96
|
const llmProvidersAnswer = await inquirer.prompt(llmQuestions);
|
|
@@ -100,7 +99,7 @@ export class InitAction extends BaseAction {
|
|
|
100
99
|
let defaultOllamaModel = this.getConfig().defaultOllamaModel;
|
|
101
100
|
const aiProvidersEnvVars: Record<string, string> = {};
|
|
102
101
|
const configurableAiProviders = selectedLlmProviders.filter(
|
|
103
|
-
(provider: AiProviders) => AI_PROVIDERS_CONFIG[provider].envVar
|
|
102
|
+
(provider: AiProviders) => AI_PROVIDERS_CONFIG[provider].envVar,
|
|
104
103
|
);
|
|
105
104
|
for (const provider of configurableAiProviders) {
|
|
106
105
|
const providerConfig = AI_PROVIDERS_CONFIG[provider];
|
|
@@ -119,14 +118,13 @@ export class InitAction extends BaseAction {
|
|
|
119
118
|
|
|
120
119
|
this.startSpinner("Configuring GenLayer Localnet environment...");
|
|
121
120
|
this.simulatorService.addConfigToEnvFile(aiProvidersEnvVars);
|
|
122
|
-
this.simulatorService.addConfigToEnvFile({
|
|
121
|
+
this.simulatorService.addConfigToEnvFile({LOCALNETVERSION: localnetVersion});
|
|
123
122
|
|
|
124
123
|
this.setSpinnerText("Running GenLayer Localnet...");
|
|
125
124
|
await this.simulatorService.runSimulator();
|
|
126
125
|
|
|
127
126
|
this.setSpinnerText("Waiting for localnet to be ready...");
|
|
128
|
-
const {
|
|
129
|
-
await this.simulatorService.waitForSimulatorToBeReady();
|
|
127
|
+
const {initialized, errorCode, errorMessage} = await this.simulatorService.waitForSimulatorToBeReady();
|
|
130
128
|
if (!initialized) {
|
|
131
129
|
if (errorCode === "ERROR") {
|
|
132
130
|
this.failSpinner(`Unable to initialize the GenLayer Localnet: ${errorMessage}`);
|
|
@@ -134,7 +132,7 @@ export class InitAction extends BaseAction {
|
|
|
134
132
|
}
|
|
135
133
|
if (errorCode === "TIMEOUT") {
|
|
136
134
|
this.failSpinner(
|
|
137
|
-
"The localnet is taking too long to initialize. Please try again after the localnet is ready."
|
|
135
|
+
"The localnet is taking too long to initialize. Please try again after the localnet is ready.",
|
|
138
136
|
);
|
|
139
137
|
return;
|
|
140
138
|
}
|
|
@@ -153,10 +151,7 @@ export class InitAction extends BaseAction {
|
|
|
153
151
|
|
|
154
152
|
this.startSpinner("Initializing validators...");
|
|
155
153
|
await this.simulatorService.deleteAllValidators();
|
|
156
|
-
await this.simulatorService.createRandomValidators(
|
|
157
|
-
Number(options.numValidators),
|
|
158
|
-
selectedLlmProviders
|
|
159
|
-
);
|
|
154
|
+
await this.simulatorService.createRandomValidators(Number(options.numValidators), selectedLlmProviders);
|
|
160
155
|
|
|
161
156
|
if (options.resetDb) {
|
|
162
157
|
this.setSpinnerText("Cleaning database...");
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import inquirer from "inquirer";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import {ISimulatorService} from "../../lib/interfaces/ISimulatorService";
|
|
3
|
+
import {DistinctQuestion} from "inquirer";
|
|
4
|
+
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
5
|
+
import {SimulatorService} from "../../lib/services/simulator";
|
|
6
6
|
|
|
7
7
|
export interface StartActionOptions {
|
|
8
8
|
resetValidators: boolean;
|
|
@@ -21,7 +21,7 @@ export class StartAction extends BaseAction {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async execute(options: StartActionOptions) {
|
|
24
|
-
const {
|
|
24
|
+
const {resetValidators, numValidators, headless, resetDb, ollama} = options;
|
|
25
25
|
|
|
26
26
|
this.simulatorService.setComposeOptions(headless, ollama);
|
|
27
27
|
this.startSpinner("Checking CLI version...");
|
|
@@ -49,7 +49,7 @@ export class StartAction extends BaseAction {
|
|
|
49
49
|
|
|
50
50
|
try {
|
|
51
51
|
this.setSpinnerText("Waiting for the simulator to be ready...");
|
|
52
|
-
const {
|
|
52
|
+
const {initialized, errorCode, errorMessage} = await this.simulatorService.waitForSimulatorToBeReady();
|
|
53
53
|
|
|
54
54
|
if (!initialized) {
|
|
55
55
|
if (errorCode === "ERROR") {
|
|
@@ -61,7 +61,6 @@ export class StartAction extends BaseAction {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
|
|
65
64
|
} catch (error) {
|
|
66
65
|
this.failSpinner("Error waiting for the simulator to be ready", error);
|
|
67
66
|
return;
|
|
@@ -83,12 +82,15 @@ export class StartAction extends BaseAction {
|
|
|
83
82
|
name: "selectedLlmProviders",
|
|
84
83
|
message: "Select which LLM providers do you want to use:",
|
|
85
84
|
choices: this.simulatorService.getAiProvidersOptions(false, ollama ? [] : ["ollama"]),
|
|
86
|
-
validate:
|
|
85
|
+
validate: answer => (answer.length < 1 ? "You must choose at least one option." : true),
|
|
87
86
|
},
|
|
88
87
|
];
|
|
89
88
|
|
|
90
89
|
const llmProvidersAnswer = await inquirer.prompt(questions);
|
|
91
|
-
await this.simulatorService.createRandomValidators(
|
|
90
|
+
await this.simulatorService.createRandomValidators(
|
|
91
|
+
numValidators,
|
|
92
|
+
llmProvidersAnswer.selectedLlmProviders,
|
|
93
|
+
);
|
|
92
94
|
} catch (error) {
|
|
93
95
|
this.failSpinner("Unable to initialize the validators", error);
|
|
94
96
|
return;
|
|
@@ -96,7 +98,9 @@ export class StartAction extends BaseAction {
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
let successMessage = "GenLayer simulator initialized successfully! ";
|
|
99
|
-
successMessage += headless
|
|
101
|
+
successMessage += headless
|
|
102
|
+
? ""
|
|
103
|
+
: `Go to ${this.simulatorService.getFrontendUrl()} in your browser to access it.`;
|
|
100
104
|
this.succeedSpinner(successMessage);
|
|
101
105
|
|
|
102
106
|
if (!headless) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {BaseAction} from "../../lib/actions/BaseAction";
|
|
2
2
|
|
|
3
3
|
export interface CreateKeypairOptions {
|
|
4
4
|
output: string;
|
|
@@ -19,4 +19,4 @@ export class KeypairCreator extends BaseAction {
|
|
|
19
19
|
this.failSpinner("Failed to generate keypair", error);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|