Skip to content

Commit 8005f93

Browse files
committed
added xExplorer
1 parent 797aaa9 commit 8005f93

8 files changed

Lines changed: 46 additions & 59 deletions

File tree

cli/src/config/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type CLIConfig = {
44
shouldHaveRedis: boolean
55
shouldHaveRabbitMQ: boolean
66
shouldHaveApi: boolean
7+
shouldHaveXExplorer: boolean
78
numberOfShards: number
89
initialEGLDAddress?: string
910
mxOpsScenesPath?: string
@@ -16,6 +17,7 @@ export function getDefaultConfig(): CLIConfig {
1617
shouldHaveRedis: false,
1718
shouldHaveRabbitMQ: false,
1819
shouldHaveApi: false,
20+
shouldHaveXExplorer: false,
1921
numberOfShards: 1
2022
}
2123
}

cli/src/config/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ export class Constants {
5555
}
5656
}
5757

58+
static get XEXPLORER_CONTAINER(): ContainerInfos {
59+
return {
60+
name: "xexplorer",
61+
pauseBehavior: PauseBehavior.STOP
62+
}
63+
}
64+
5865
static get ELASTIC_CONTAINER(): ContainerInfos {
5966
return {
6067
name: "elastic",

cli/src/questions/features/featuresQuestion.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,47 @@ import {CLIChoice, CLIQuestion} from "../question.js";
22
import {Answers, CheckboxQuestion, Question} from "inquirer";
33
import {CLIConfig} from "../../config/config";
44
import {MxOpsScenesPathQuestion} from "./mxOpsScenesPathQuestion.js";
5+
import {CustomAddressToGiveEGLDQuestion} from "./customAddressToGiveEGLDQuestion.js";
56

6-
export abstract class FeaturesQuestion extends CLIQuestion {
7+
export class FeaturesQuestion extends CLIQuestion {
78

89
private static apiChoice = 'Enable full API (like api.multiversx.com)'
10+
private static xExplorerChoice = 'Enable xExplorer, requires the full API'
911
private static mxOpsChoice = 'Run MxOps scenes at startup'
12+
static readonly giveToCustomAddressChoice = 'Give 1,000,000 EGLD to a custom address (otherwise a new one will be generated for you)'
1013

1114
override async getQuestion(): Promise<Question> {
1215
const question: CheckboxQuestion = {
1316
type: 'checkbox',
1417
name: 'choice',
1518
message: 'Which features do you want to enable ?',
16-
choices: this.generalFeatures.concat(this.cliChoices)
19+
choices: this.generalFeatures
1720
}
1821

1922
return question
2023
}
2124

2225
private generalFeatures: CLIChoice[] = [
2326
FeaturesQuestion.apiChoice,
24-
FeaturesQuestion.mxOpsChoice
27+
FeaturesQuestion.xExplorerChoice,
28+
FeaturesQuestion.mxOpsChoice,
29+
FeaturesQuestion.giveToCustomAddressChoice
2530
]
2631

27-
abstract cliChoices: CLIChoice[]
28-
2932
override async handleAnswer(answers: Answers, config: CLIConfig): Promise<CLIQuestion[]> {
30-
if (answers.choice.includes(FeaturesQuestion.apiChoice)) {
33+
const hasAPI = answers.choice.includes(FeaturesQuestion.apiChoice)
34+
if (answers.choice.includes(FeaturesQuestion.xExplorerChoice)) {
35+
if (hasAPI) {
36+
config.shouldHaveXExplorer = true
37+
} else {
38+
const errorMessage = '\n❌ You have to opt for the full API in order to run xExplorer.\n'
39+
console.log(errorMessage)
40+
41+
return [new FeaturesQuestion()]
42+
}
43+
}
44+
45+
if (hasAPI) {
3146
config.shouldHaveElasticSearch = true
3247
config.shouldHaveMySQL = true
3348
config.shouldHaveRabbitMQ = true
@@ -41,6 +56,10 @@ export abstract class FeaturesQuestion extends CLIQuestion {
4156
questions.push(new MxOpsScenesPathQuestion())
4257
}
4358

59+
if (answers.choice.includes(FeaturesQuestion.giveToCustomAddressChoice)) {
60+
questions.push(new CustomAddressToGiveEGLDQuestion())
61+
}
62+
4463
return questions
4564
}
4665
}

cli/src/questions/features/freshLocalnetFeaturesQuestion.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

cli/src/questions/features/shadowForkFeaturesQuestion.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

cli/src/questions/fresh/numberShardsQuestion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {CLIQuestion} from "../question.js";
2-
import {FreshLocalnetFeaturesQuestion} from "../features/freshLocalnetFeaturesQuestion.js";
32
import {Answers, Question} from "inquirer";
43
import {CLIConfig} from "../../config/config.js";
4+
import {FeaturesQuestion} from "../features/featuresQuestion.js";
55

66
export class NumberShardsQuestion extends CLIQuestion {
77

@@ -31,6 +31,6 @@ export class NumberShardsQuestion extends CLIQuestion {
3131

3232
config.numberOfShards = answers.numberShards
3333

34-
return [new FreshLocalnetFeaturesQuestion()]
34+
return [new FeaturesQuestion()]
3535
}
3636
}

cli/src/questions/shadowfork/shadowForkNetworkQuestion.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

cli/src/utils/docker/createNetwork.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ export async function createNetwork(config: CLIConfig) {
6060
startingApiHealthCheckSpinner.succeed('API is ready')
6161
}
6262

63+
if (config.shouldHaveXExplorer) {
64+
const startingApiSpinner = ora('Starting xExplorer container...').start()
65+
await upContainer(Constants.XEXPLORER_CONTAINER.name)
66+
startingApiSpinner.succeed('Started xExplorer container')
67+
68+
const startingApiHealthCheckSpinner = ora('Waiting for API to be ready').start()
69+
await waitForAPIToBeReady()
70+
startingApiHealthCheckSpinner.succeed('API is ready')
71+
}
72+
6373
if (config.mxOpsScenesPath) {
6474
const copyingScenesSpinner = ora('Copying mxops scenes...').start()
6575
await execCustomInRepo(`docker-compose cp ${config.mxOpsScenesPath} localnet:/home/ubuntu/mxops`)

0 commit comments

Comments
 (0)