Skip to content

Commit 4b4c484

Browse files
authored
Merge pull request #21
Added xExplorer
2 parents 0100921 + 8005f93 commit 4b4c484

14 files changed

Lines changed: 394 additions & 59 deletions

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`)

containers/xexplorer/Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ubuntu:22.04 AS environment
2+
3+
SHELL ["/bin/bash", "-c"]
4+
5+
RUN apt update -y
6+
RUN apt install sudo -y
7+
RUN apt install curl -y
8+
9+
RUN adduser --disabled-password --gecos '' ubuntu
10+
RUN adduser ubuntu sudo
11+
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
12+
USER ubuntu
13+
WORKDIR /home/ubuntu
14+
15+
#Python3 setup
16+
RUN sudo DEBIAN_FRONTEND=noninteractive apt install python3-pip -y
17+
RUN sudo pip3 install requests
18+
19+
#NodeJS setup
20+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt install nodejs -y
21+
RUN sudo npm i -g yarn
22+
23+
#mx-explorer-dapp setup (nodejs)
24+
RUN sudo apt install git -y
25+
RUN git clone https://github.com/multiversx/mx-explorer-dapp.git -b main
26+
RUN cd mx-explorer-dapp && git checkout 6b9560d83cfa9b2197f1efde651450c9d25508e4
27+
RUN cd mx-explorer-dapp && yarn
28+
COPY config.localnet.ts mx-explorer-dapp/src/config/index.ts
29+
COPY vite.config.ts mx-explorer-dapp/vite.config.ts
30+
31+
COPY wait-for-it.sh .
32+
RUN sudo chmod +x wait-for-it.sh
33+
34+
COPY run.sh .
35+
RUN sudo chmod +x run.sh
36+
CMD ./run.sh
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { NetworkType } from 'types/network.types';
2+
import { allApps, schema } from './sharedConfig';
3+
export * from './sharedConfig';
4+
5+
export const networks: NetworkType[] = [
6+
{
7+
default: true,
8+
id: 'localnet',
9+
name: 'Localnet',
10+
chainId: 'localnet',
11+
adapter: 'api',
12+
theme: 'testnet',
13+
egldLabel: 'tEGLD',
14+
walletAddress: 'https://devnet-wallet.multiversx.com',
15+
explorerAddress: 'http://localhost:3002',
16+
nftExplorerAddress: 'https://devnet.xspotlight.com',
17+
apiAddress: 'http://localhost:3001'
18+
}
19+
];
20+
21+
export const multiversxApps = allApps([
22+
{
23+
id: 'wallet',
24+
url: 'https://devnet-wallet.multiversx.com'
25+
},
26+
{
27+
id: 'explorer',
28+
url: 'http://localhost:3002'
29+
},
30+
{
31+
id: 'xexchange',
32+
url: 'http://devnet.xexchange.com'
33+
},
34+
{
35+
id: 'xspotlight',
36+
url: 'https://devnet.xspotlight.com/'
37+
}
38+
]);
39+
40+
networks.forEach((network) => {
41+
schema.validate(network, { strict: true }).catch(({ errors }) => {
42+
console.error(`Config invalid format for ${network.id}`, errors);
43+
});
44+
});

0 commit comments

Comments
 (0)