GithubHelp home page GithubHelp logo

gridcoin-community / blockexplorer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imharrywu/explorer

5.0 7.0 4.0 3.21 MB

Open source GRC block explorer.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 74.95% CSS 0.57% HTML 24.48%

blockexplorer's Introduction

An open-source block explorer written in node.js.

Tested on Ubuntu Xenial/Bionic.

Requires

  • node.js >= 0.10.28
  • npm >= 1.4.9
  • mongodb >= 2.6.x
  • gridcoinresearchd

Installing node.js/npm:

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

You can quickly install gridcoinresearchd, including the latest snapshot, using the handy Autonode script located here:

https://github.com/gridcoin-community/Autonode

Wallet

The wallet must be running with the following flags:

-daemon -txindex

Or set the following in your gridcoinresearch.conf file:

daemon=1
txindex=1

Create Database

Enter MongoDB cli:

$ mongo

Create database:

use explorerdb

Create user with read/write access:

db.createUser( { user: "gridcoin", pwd: "u9WdcVgMVqvHcDz7", roles: [ "readWrite" ] } )

Get The Source

git clone https://github.com/gridcoin-community/BlockExplorer.git explorer

Install Node Modules

cd explorer && sudo npm install --production

Edit settings.json

vi settings.json

Set the RPC ID and password for your gridcoinresearchd instance (found in your gridcoinresearch.conf file) on lines 46-47.

Start Explorer

sudo npm start

Note: mongod must be running to start the explorer.

The explorer defaults to cluster mode, forking an instance of its process to each CPU core. This results in increased performance and stability. Load balancing is automatic, and any instances that die will be restarted automatically. For testing/development a single instance can be launched with:

node --stack-size=10000 bin/instance

To stop the cluster you can use:

sudo npm stop

Syncing Databases With The Blockchain

sync.js (located in scripts/) is used for updating the local databases. This script must be called from the explorer's root directory.

Usage: node scripts/sync.js [database] [mode]
Example: node scripts/sync.js index update

database: (required)
index [mode] Main index: coin info/stats, transactions & addresses
market       Market data: summaries, orderbooks, trade history & chartdata

mode: (required for index database only)
update       Updates index from last sync to current block
check        checks index for (and adds) any missing transactions/addresses
reindex      Clears index then resyncs from genesis to current block

notes:
* 'current block' is the latest created block when script is executed.
* The market database only supports (& defaults to) reindex mode.
* If check mode finds missing data (ignoring new data since last sync),
  index_timeout in settings.json is set too low.

It is recommended to have this script launched via a cronjob at 1+ min intervals.

crontab

Example crontab; update index every minute and market data every 2 minutes

*/1 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js index update > /dev/null 2>&1
*/2 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/sync.js market > /dev/null 2>&1
*/5 * * * * cd /path/to/explorer && /usr/bin/nodejs scripts/peers.js > /dev/null 2>&1

Known Issues

script is already running.

If you receive this message when launching the sync script either a) a sync is currently in progress, or b) a previous sync was killed before it completed. If you are certain a sync is not in progress, remove the index.pid from the tmp folder in the explorer root directory.

rm tmp/index.pid

exceeding stack size

RangeError: Maximum call stack size exceeded

Node's default stack size may be too small to index addresses with many tx's. If you experience the above error while running sync.js, the stack size needs to be increased.

To determine the default setting run:

node --v8-options | grep -B0 -A1 stack_size

To run sync.js with a larger stack size launch with:

node --stack-size=[SIZE] scripts/sync.js index update

Where [SIZE] is an integer higher than the default.

blockexplorer's People

Contributors

bitbaba avatar chey avatar iquidus avatar ksynb avatar lyoshenka avatar mudjello avatar neuralminer avatar patrykwegrzyn avatar rudy4682 avatar snyk-community avatar udjinm6 avatar xcoredev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockexplorer's Issues

Clean up views/layout.jade

Since this explorer is GRC specific, we can remove this extra code.

if settings.nethash_units == 'K'
strong #{settings.locale.network} (KH/s)
else if settings.nethash_units == 'M'
strong #{settings.locale.network} (MH/s)
else if settings.nethash_units == 'G'
strong #{settings.locale.network} (GH/s)
else if settings.nethash_units == 'T'
strong #{settings.locale.network} (TH/s)
else if settings.nethash_units == 'P'
strong #{settings.locale.network} (PH/s)
else if settings.nethash_units == 'H'
strong #{settings.locale.network} (H/s)

Remove nonexistent RPC calls

var uri = base_url + 'getmaxmoney';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},
get_maxvote: function(cb) {
var uri = base_url + 'getmaxvote';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},
get_vote: function(cb) {
var uri = base_url + 'getvote';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},
get_phase: function(cb) {
var uri = base_url + 'getphase';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},
get_reward: function(cb) {
var uri = base_url + 'getreward';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},
get_estnext: function(cb) {
var uri = base_url + 'getnextrewardestimate';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},
get_nextin: function(cb) {
var uri = base_url + 'getnextrewardwhenstr';
request({uri: uri, json: true}, function (error, response, body) {
return cb(body);
});
},

exports.api_getmaxmoney = 'Returns the maximum possible money supply.',
exports.api_getmaxvote = 'Returns the maximum allowed vote for the current phase of voting.',
exports.api_getvote = 'Returns the current block reward vote setting.',
exports.api_getphase = 'Returns the current voting phase (\'Mint\', \'Limit\' or \'Sustain\').',
exports.api_getreward = 'Returns the current block reward, which has been decided democratically in the previous round of block reward voting.',
exports.api_getsupply = 'Returns the current money supply.',
exports.api_getnextrewardestimate = 'Returns an estimate for the next block reward based on the current state of decentralized voting.',
exports.api_getnextrewardwhenstr = 'Returns string describing how long until the votes are tallied and the next block reward is computed.',

Error on Markets tab

/home/user/explorer/views/markets/bittrex.jade:26 24| tbody 25| tr > 26| td #{marketdata.data.summary.High.toFixed(8)} 27| td #{marketdata.data.summary.Low.toFixed(8)} 28| td #{marketdata.data.summary.Volume.toFixed(8)} 29| td.hidden-xs #{marketdata.data.summary.Bid.toFixed(8)} Cannot read property 'toFixed' of undefined

Remove code for calculating hash rate

Since this will be GRC specific, hash rate calculations/display can be removed.

get_hashrate: function(cb) {
if (settings.index.show_hashrate == false) return cb('-');
if (settings.nethash == 'netmhashps') {
var uri = base_url + 'getmininginfo';
request({uri: uri, json: true}, function (error, response, body) { //returned in mhash
if (body.netmhashps) {
if (settings.nethash_units == 'K') {
return cb((body.netmhashps * 1000).toFixed(4));
} else if (settings.nethash_units == 'G') {
return cb((body.netmhashps / 1000).toFixed(4));
} else if (settings.nethash_units == 'H') {
return cb((body.netmhashps * 1000000).toFixed(4));
} else if (settings.nethash_units == 'T') {
return cb((body.netmhashps / 1000000).toFixed(4));
} else if (settings.nethash_units == 'P') {
return cb((body.netmhashps / 1000000000).toFixed(4));
} else {
return cb(body.netmhashps.toFixed(4));
}
} else {
return cb('-');
}
});
} else {
var uri = base_url + 'getnetworkhashps';
request({uri: uri, json: true}, function (error, response, body) {
if (body == 'There was an error. Check your console.') {
return cb('-');
} else {
if (settings.nethash_units == 'K') {
return cb((body / 1000).toFixed(4));
} else if (settings.nethash_units == 'M'){
return cb((body / 1000000).toFixed(4));
} else if (settings.nethash_units == 'G') {
return cb((body / 1000000000).toFixed(4));
} else if (settings.nethash_units == 'T') {
return cb((body / 1000000000000).toFixed(4));
} else if (settings.nethash_units == 'P') {
return cb((body / 1000000000000000).toFixed(4));
} else {
return cb((body).toFixed(4));
}
}
});
}
},

BlockExplorer/settings.json

Lines 138 to 145 in eb2f005

// how to acquire network hashrate
// getnetworkhashps: uses getnetworkhashps api call, returns in GH/s
// netmhashps: uses getmininginfo.netmhashpsm returns in MH/s
"nethash": "getnetworkhashps",
// nethash unitd: sets nethash API return units
// valid options: "P" (PH/s), "T" (TH/s), "G" (GH/s), "M" (MH/s), "K" (KH/s)
"nethash_units": "G",

if settings.nethash_units == 'K'
strong #{settings.locale.network} (KH/s)
else if settings.nethash_units == 'M'
strong #{settings.locale.network} (MH/s)
else if settings.nethash_units == 'G'
strong #{settings.locale.network} (GH/s)
else if settings.nethash_units == 'T'
strong #{settings.locale.network} (TH/s)
else if settings.nethash_units == 'P'
strong #{settings.locale.network} (PH/s)
else if settings.nethash_units == 'H'
strong #{settings.locale.network} (H/s)

Replace hash rate with block height on web front end

.col-md-12
.row.text-center
.col-md-2.col-md-offset-1
.panel.panel-default.hidden-sm.hidden-xs
.panel-heading
if settings.nethash_units == 'K'
strong #{settings.locale.network} (KH/s)
else if settings.nethash_units == 'M'
strong #{settings.locale.network} (MH/s)
else if settings.nethash_units == 'G'
strong #{settings.locale.network} (GH/s)
else if settings.nethash_units == 'T'
strong #{settings.locale.network} (TH/s)
else if settings.nethash_units == 'P'
strong #{settings.locale.network} (PH/s)
else if settings.nethash_units == 'H'
strong #{settings.locale.network} (H/s)
.panel-body
if settings.index.difficulty == 'Hybrid'
label#hashrate -
<br>
label#lblX1
else
label#hashrate -

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.