Skip to content

Commit

Permalink
cleanup: more quiet mode for tools
Browse files Browse the repository at this point in the history
  • Loading branch information
BT Enterprise committed Mar 22, 2019
1 parent a2ac93e commit c405f45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
23 changes: 18 additions & 5 deletions tools/richlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function makeRichList(toBlock, blocks, updateCallback) {
fromBlock = 0;
}

console.log(`Scan accounts from ${fromBlock} to ${toBlock} ...`);
if (!('quiet' in config && config.quiet === true)) {
console.log(`Scan accounts from ${fromBlock} to ${toBlock} ...`);
}

let ended = false;
if (fromBlock == toBlock) {
Expand Down Expand Up @@ -134,7 +136,9 @@ function makeRichList(toBlock, blocks, updateCallback) {
console.info(`* ${len} / ${self.index + len} total accounts.`);
if (updateCallback && (len >= 100 || ended)) {
self.index += len;
console.log(`* update ${len} accounts ...`);
if (!('quiet' in config && config.quiet === true)) {
console.log(`* update ${len} accounts ...`);
}

// split accounts into chunks to make proper sized json-rpc batch job.
const accounts = Object.keys(self.accounts);
Expand Down Expand Up @@ -294,7 +298,9 @@ function makeParityRichList(number, offset, blockNumber, updateCallback) {
offset = lastAccount;
const j = Object.keys(accounts).length;
self.index += j;
console.log(` * ${j} / ${self.index} accounts, offset = ${offset}`);
if (!('quiet' in config && config.quiet === true)) {
console.log(` * ${j} / ${self.index} accounts, offset = ${offset}`);
}
if (updateCallback) {
updateCallback(accounts, blockNumber);
}
Expand Down Expand Up @@ -362,7 +368,9 @@ var bulkInsert = function (bulk) {
console.log(`WARN: Fail to upsert (ignore) ${err}`);

}
console.log(`* ${localbulk.length} accounts successfully updated.`);
if (!('quiet' in config && config.quiet === true)) {
console.log(`* ${localbulk.length} accounts successfully updated.`);
}
if (bulk.length > 0) {
setTimeout(() => {
bulkInsert(bulk);
Expand All @@ -374,7 +382,9 @@ var bulkInsert = function (bulk) {
process.exit(9);
}
} else {
console.log(`* ${data.insertedCount} accounts successfully inserted.`);
if (!('quiet' in config && config.quiet === true)) {
console.log(`* ${data.insertedCount} accounts successfully inserted.`);
}
if (bulk.length > 0) {
setTimeout(() => {
bulkInsert(bulk);
Expand Down Expand Up @@ -461,6 +471,9 @@ async function startSync() {
console.log('Error: Fail to load genesis address (ignore)');
}
}
if ('quiet' in config && config.quiet === true) {
console.log('Quiet mode enabled');
}
makeRichList(latestBlock, 500, updateAccounts);
}
}
Expand Down
24 changes: 16 additions & 8 deletions tools/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ try {
console.log(`Connecting ${config.nodeAddr}:${config.wsPort}...`);
// Sets address for RPC WEB3 to connect to, usually your node IP address defaults ot localhost
const web3 = new Web3(new Web3.providers.WebsocketProvider(`ws://${config.nodeAddr}:${config.wsPort.toString()}`));
if ('quiet' in config && config.quiet === true) {
console.log('Quiet mode enabled');
}

const updateStats = async (range, interval, rescan) => {
let latestBlock = await web3.eth.getBlockNumber();
Expand Down Expand Up @@ -94,27 +97,32 @@ var checkBlockDBExistsThenWrite = function (web3, blockData, nextBlock, endNumbe
'uncleCount': blockData.uncles.length,
};
new BlockStat(stat).save((err, s, count) => {
console.log(s);
if (!('quiet' in config && config.quiet === true)) {
console.log(s);
}
if (typeof err !== 'undefined' && err) {
console.log(`${'Error: Aborted due to error on ' +
'block number '}${blockData.number.toString()}: ${
console.log(`${'Error: Aborted due to error on ' + 'block number '}${blockData.number.toString()}: ${
err}`);
process.exit(9);
} else {
console.log(`DB successfully written for block number ${
blockData.number.toString()}`);
if (!('quiet' in config && config.quiet === true)) {
console.log(`DB successfully written for block number ${blockData.number.toString()}`);
}
getStats(web3, blockData.number - interval, blockData, endNumber, interval, rescan);
}
});
} else {
if (rescan || !nextBlock) {
getStats(web3, blockData.number - interval, blockData, endNumber, interval, rescan);
if (nextBlock) {
console.log(`WARN: block number: ${blockData.number.toString()} already exists in DB.`);
if (!('quiet' in config && config.quiet === true)) {
console.log(`WARN: block number: ${blockData.number.toString()} already exists in DB.`);
}
}
} else {
console.error(`Aborting because block number: ${blockData.number.toString()
} already exists in DB.`);
if (!('quiet' in config && config.quiet === true)) {
console.error(`Aborting because block number: ${blockData.number.toString()} already exists in DB.`);
}

}
}
Expand Down

0 comments on commit c405f45

Please sign in to comment.