Skip to content

Commit

Permalink
Merge pull request #305 from btenterprise2020/dev
Browse files Browse the repository at this point in the history
Explorer patch ( mongoose + gulpify + small cleanup )
  • Loading branch information
phyro authored Apr 15, 2019
2 parents c1eda06 + 37794e2 commit 6429d74
Show file tree
Hide file tree
Showing 189 changed files with 2,341 additions and 33,815 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ data/
config.json
.node-xmlhttprequest-*
/nbproject/private/
dist/*
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ matrix:
- docker build -t ethereumclassic/explorer .
- docker run -d --network="container:$varA" ethereumclassic/explorer app.js
script:
- npm run dist
- npm run test

# This builder only tests code linters
Expand All @@ -25,7 +26,7 @@ matrix:
node_js: '8'
env: lint
script:
- npm run lint:check
- npm run lint

# Temporary allow failures for eslint until the code is done.
allow_failures:
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM node:latest
COPY . /

RUN npm i
RUN npm run dist

EXPOSE 3000

Expand Down
105 changes: 22 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@

Follow the project progress at: [ETC Block Explorer Development](https://github.com/ethereumclassic/explorer)

## Local installation
## Requirements

Clone the repo
| Dependency | Mac | Linux |
|-------------|-----|-------|
| [Node.js 8.x](https://nodejs.org/en/) | `brew install node` | [Node.js Install Example](https://nodejs.org/en/download/package-manager/) |
| [MongoDB 4.x](https://www.mongodb.com) | `brew install mongodb` | [MongoDB Install Example](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/) |

`git clone https://github.com/ethereumclassic/explorer`
## Build and Run

Download [Nodejs and npm](https://docs.npmjs.com/getting-started/installing-node "Nodejs install") if you don't have them
1. Clone the repository.
`git clone https://github.com/ethereumclassic/explorer`

Install dependencies:
2. Go to the explorer subdirectory.
`cd explorer`

`npm install`
3. Set up default configurations.
`cp config.example.json config.json`

Install mongodb:
4. Install Node.js dependencies.
`npm install`

MacOS: `brew install mongodb`
5. Build frontend.
`npm run dist`

Ubuntu: `sudo apt-get install -y mongodb-org`
6. Start Express Server.
`npm start`

## Populate the DB

This will fetch and parse the entire blockchain.

Setup your configuration file: `cp config.example.json config.json`

Edit `config.json` as you wish

Basic settings:
## Basic settings
```json
{
"nodeAddr": "localhost",
Expand All @@ -48,12 +49,12 @@ Basic settings:
"symbol": "ETC",
"name": "Ethereum Classic",
"title": "Ethereum Classic Block Explorer",
"author": "Elaine",
"rss": "https://ethereumclassic.org",
"reddit": "https://www.reddit.com/r/EthereumClassic",
"twitter": "https://twitter.com/eth_classic",
"linkedin": "https://www.linkedin.com/company/ethereum-classic",
"github": "https://github.com/ethereumclassic",
"github-repo": "https://github.com/ethereumclassic/explorer",
"logo": "/img/explorer-logo.png",
"copyright": "2019 © Ethereum Classic.",
"poweredbyCustom": false,
Expand Down Expand Up @@ -107,75 +108,13 @@ Basic settings:
| `useRichList` | If `useRichList` is set to true, explorer will update account balance for richlist page. |
| `useFiat` | If `useFiat` is set to true, explorer will show price for account & tx page. ( Disable for testnets )|

### Mongodb Auth setting.

#### Configure MongoDB

In view of system security, most of mongoDB Admin has setup security options, So, You need to setup mongodb auth informations.
Switch to the built-in admin database:

```
$ mongo
$ > use admin
```

1. Create an administrative user (if you have already admin or root of mongodb account, then skip it)

```
# make admin auth and role setup
$ > db.createUser( { user: "admin", pwd: "<Enter a secure password>", roles: ["root"] } )
```

And, You can make Explorer's "explorerDB" database with db user accounts "explorer" and password "some_pass_code".

```
$ > use explorerDB
$ > db.createUser( { user: "explorer", pwd: "<Enter a secure password>", roles: ["dbOwner"] } )
$ > quit()
```

Above dbuser explorer will full access explorerDB and clustor setting will be well used on monitoring the multiple sharding and replication of multiple mongodb instances.
Enable database authorization in the MongoDB configuration file /etc/mongodb.conf by appending the following lines:

```
auth=true
```

Restart MongoDB and verify the administrative user created earlier can connect:

```
$ sudo service mongodb restart
$ mongo -u admin -p your_password --authenticationDatabase=admin
```

If everything is configured correctly the Mongo Shell will connect and

```
$ > show dbs
```

will show db informations.
and You can add modified from ./db.js:103 lines, add auth information and mongodb connect options.

```
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/explorerDB', {
useMongoClient: true
// poolSize: 5,
// rs_name: 'myReplicaSetName',
// user: 'explorer',
// pass: 'yourdbpasscode'
});
```

And explore it.

### Run
## Run

The below will start both the web-gui and sync.js (which populates MongoDB with blocks/transactions).

`npm start`

You can leave sync.js running without app.js and it will sync and grab blocks based on config.json parameters
You can leave sync.js running without app.js and it will sync and grab blocks based on config.json parameters.

`npm run sync`

Expand Down
14 changes: 12 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(favicon(`${__dirname}/public/favicon.ico`));
const distdir = 'dist';

if (process.env.DIST && ['dist', 'public'].indexOf(process.env.DIST) > 0) {
distdir = process.env.DIST;
console.log('distdir = ' + distdir);
}

// setup settings.development = process.env.NODE_ENV
config.settings["development"] = app.get('env');

app.use(favicon(`${__dirname}/${distdir}/favicon.ico`));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, distdir)));

// app libraries
global.__lib = `${__dirname}/lib/`;
Expand Down
2 changes: 1 addition & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"symbol": "ETC",
"name": "Ethereum Classic",
"title": "Ethereum Classic Block Explorer",
"author": "Elaine, Cody, Hackmod, Bakon",
"contact": "mailto:ethereumclassicanthony@gmail.com",
"about": "This is an open source Blockchain Explorer.",
"rss": "https://ethereumclassic.org",
"reddit": "https://www.reddit.com/r/EthereumClassic",
"twitter": "https://twitter.com/eth_classic",
"linkedin": "https://www.linkedin.com/company/ethereum-classic",
"github": "https://github.com/ethereumclassic",
"github-repo": "https://github.com/ethereumclassic/explorer",
"logo": "/img/explorer-logo.png",
"copyright": "2019 &copy; Ethereum Classic.",
"poweredbyCustom": false,
Expand Down
39 changes: 0 additions & 39 deletions db-internal.js

This file was deleted.

9 changes: 2 additions & 7 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ module.exports.Market = mongoose.model('Market');
module.exports.TokenTransfer = mongoose.model('TokenTransfer');

mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/explorerDB', {
useMongoClient: true
// poolSize: 5,
// rs_name: 'myReplicaSetName',
// user: 'explorer',
// pass: 'yourdbpasscode'
});
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost:27017/explorerDB', {useNewUrlParser: true});

mongoose.set('useCreateIndex', true);
// mongoose.set('debug', true);
16 changes: 0 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,5 @@ services:
MONGO_URI: 'mongodb://db/explorerDB'
depends_on:
- db
price:
build: .
command: ./tools/price.js
restart: always
environment:
MONGO_URI: 'mongodb://db/explorerDB'
depends_on:
- db
richlist:
build: .
command: ./tools/richlist.js
restart: "no"
environment:
MONGO_URI: 'mongodb://db/explorerDB'
depends_on:
- db
db:
image: mongo
Loading

0 comments on commit 6429d74

Please sign in to comment.