Skip to content

Commit

Permalink
enhancement: add fiat exchange for addresses and tx
Browse files Browse the repository at this point in the history
cherry picked from EthereumCommonwealth/clo-explorer@c4502a0 by @yograteol

 * configurable fiat conversion
 * hide fiat value when it is not used.
 * use cryptocompare instead of coinmarketcap
  • Loading branch information
BT Enterprise committed Mar 19, 2019
1 parent c54a642 commit dc55f99
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 35 deletions.
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Basic settings:
"poweredbyCustom": false,
"poweredbyEtcImage": "/img/powered-by-etcexplorer-w.png",
"poweredbyEtc": true,
"useFiat": false,
"miners": {
"0xdf7d7e053933b5cc24372f878c90e62dadad5d42": "EtherMine",
"0xc91716199ccde49dc4fafaeb68925127ac80443f": "F2Pool",
Expand Down Expand Up @@ -91,23 +92,17 @@ Basic settings:

```

```nodeAddr``` Your node API RPC address.

```rpcPort``` Your node API RPC port.

```startBlock``` This is the start block of the blockchain, should always be 0 if you want to sync the whole ETC blockchain.

```endBlock``` This is usually the 'latest'/'newest' block in the blockchain, this value gets updated automatically, and will be used to patch missing blocks if the whole app goes down.

```quiet``` Suppress some messages. (admittedly still not quiet)

```syncAll``` If this is set to true at the start of the app, the sync will start syncing all blocks from lastSync, and if lastSync is 0 it will start from whatever the endBlock or latest block in the blockchain is.

```patch``` If set to true and below value is set, sync will iterated through the # of blocks specified.

```patchBlocks``` If `patch` is set to true, the amount of block specified will be check from the latest one.

```useRichList``` If `useRichList` is set to true, explorer will update account balance for richlist page.
| Name | Explanation |
|-------------|-----|
| `nodeAddr` | Your node API RPC address. |
| `wsPort` | Your node API WS (Websocket) port. (RPC HTTP port is deprecated on Web3 1.0 see https://web3js.readthedocs.io/en/1.0/web3.html#value) |
| `startBlock` | This is the start block of the blockchain, should always be 0 if you want to sync the whole ETC blockchain. |
| `endBlock` | This is usually the 'latest'/'newest' block in the blockchain, this value gets updated automatically, and will be used to patch missing blocks if the whole app goes down. |
| `quiet` | Suppress some messages. (admittedly still not quiet) |
| `syncAll` | If this is set to true at the start of the app, the sync will start syncing all blocks from lastSync, and if lastSync is 0 it will start from whatever the endBlock or latest block in the blockchain is. |
| `patch` | If set to true and below value is set, sync will iterated through the # of blocks specified. |
| `patchBlocks` | If `patch` is set to true, the amount of block specified will be check from the latest one. |
| `useRichList` | If `useRichList` is set to true, explorer will update account balance for richlist page. |

### Mongodb Auth setting.

Expand Down Expand Up @@ -177,13 +172,20 @@ The below will start both the web-gui and sync.js (which populates MongoDB with
`npm start`

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

`npm run sync`

Enabling stats requires running a separate process:
`node ./tools/stats.js`

`npm run stats`

Enabling richlist requires running a separate process:
`node ./tools/richlist.js`

`npm run rich`

Enabling price conversion requires running a separate process:

`npm run price`

You can configure intervals (how often a new data point is pulled) and range (how many blocks to go back) with the following:
`RESCAN=100:7700000 node tools/stats.js` (New data point every 100 blocks. Go back 7,700,000 blocks).
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"poweredbyCustom": false,
"poweredbyEtcImage": "/img/powered-by-etcexplorer-w.png",
"poweredbyEtc": true,
"useFiat": false,
"miners": {
"0xdf7d7e053933b5cc24372f878c90e62dadad5d42": "EtherMine",
"0xc91716199ccde49dc4fafaeb68925127ac80443f": "F2Pool",
Expand Down
11 changes: 11 additions & 0 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ var BlockStat = new Schema(
"uncleCount": Number
}, {collection: "BlockStat"});

var Market = new Schema(
{
"symbol": String,
"timestamp": Number,
"quoteBTC": Number,
"quoteUSD": Number
}, {collection: "Market"});

// create indices
Transaction.index({blockNumber:-1});
Transaction.index({from:1, blockNumber:-1});
Expand All @@ -88,17 +96,20 @@ Account.index({type:-1, balance:-1});
Block.index({miner:1});
Block.index({miner:1, blockNumber:-1});
Block.index({hash:1, number:-1});
Market.index({timestamp: -1});

mongoose.model('BlockStat', BlockStat);
mongoose.model('Block', Block);
mongoose.model('Account', Account);
mongoose.model('Contract', Contract);
mongoose.model('Transaction', Transaction);
mongoose.model('Market', Market);
module.exports.BlockStat = mongoose.model('BlockStat');
module.exports.Block = mongoose.model('Block');
module.exports.Contract = mongoose.model('Contract');
module.exports.Transaction = mongoose.model('Transaction');
module.exports.Account = mongoose.model('Account');
module.exports.Market = mongoose.model('Market');

mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/explorerDB', {
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"license": "MIT",
"scripts": {
"start": "concurrently \"node tools/sync.js \" \"node app.js\" ",
"app": "node app.js",
"sync": "node tools/sync.js",
"stats": "node tools/stats.js",
"rich": "node tools/richlist.js",
"price": "node tools/price.js",
"pretest": "copyfiles app.js app/ ",
"test": "mocha --exit"
},
Expand All @@ -17,6 +22,7 @@
"express": "^4.16.0",
"mongoose": "^4.10.8",
"morgan": "^1.9.0",
"node-fetch": "^2.3.0",
"rlp": "^2.0.0",
"serve-favicon": "~2.4.5",
"socket.io": "^2.0.4",
Expand Down
3 changes: 3 additions & 0 deletions public/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ li.ng-scope {
.search-form.open{width:100%!important;}
}
.page-spinner-bar{margin-top:-84px;margin-left:-98px;top:50%;left:50%;}
.mini-logo {
height: 1.2em;
}
Loading

0 comments on commit dc55f99

Please sign in to comment.