Skip to content

Commit

Permalink
Merge pull request #715 from near/validators-fix
Browse files Browse the repository at this point in the history
epoch converted to number in 'near validators <epoch>'
  • Loading branch information
vgrichina authored Apr 21, 2021
2 parents d621481 + 6ef4b05 commit d8f5a99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion commands/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
desc: 'lookup validators for given epoch (or current / next)',
builder: (yargs) => yargs
.option('epoch', {
desc: 'epoch defined by block number or current / next',
desc: 'epoch defined by block number, block hash or current / next keyword',
type: 'string',
required: true
}),
Expand Down
12 changes: 8 additions & 4 deletions utils/validators-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ const { validators, utils } = require('near-api-js');
const BN = require('bn.js');
const AsciiTable = require('ascii-table');

async function validatorsInfo(near, epochId) {
async function validatorsInfo(near, blockNumberOrHash) {
// converts block number to integer
if (blockNumberOrHash && !isNaN(parseInt(blockNumberOrHash))) {
blockNumberOrHash = parseInt(blockNumberOrHash);
}
const genesisConfig = await near.connection.provider.sendJsonRpc('EXPERIMENTAL_genesis_config', {});
const result = await near.connection.provider.sendJsonRpc('validators', [epochId]);
const result = await near.connection.provider.sendJsonRpc('validators', [blockNumberOrHash]);
result.genesisConfig = genesisConfig;
result.numSeats = genesisConfig.num_block_producer_seats + genesisConfig.avg_hidden_validator_seats_per_shard.reduce((a, b) => a + b);
return result;
}

async function showValidatorsTable(near, epochId) {
const result = await validatorsInfo(near, epochId);
async function showValidatorsTable(near, blockNumberOrHash) {
const result = await validatorsInfo(near, blockNumberOrHash);
const seatPrice = validators.findSeatPrice(result.current_validators, result.numSeats);
result.current_validators = result.current_validators.sort((a, b) => -new BN(a.stake).cmp(new BN(b.stake)));
var validatorsTable = new AsciiTable();
Expand Down

0 comments on commit d8f5a99

Please sign in to comment.