SteemJs: How Many Witnesses are Running on 23.1?

  • 时间:2020-09-09 13:08:38
  • 分类:网络文摘
  • 阅读:160 次

How many witnesses are running on 23.1 and how many of them are active? It turns out answering this question does not require preprocess blocks on steem blockchain e.g. SteemSQL. Rather, we can get the answer by pure SteemJS.

Get All Witnesses

First, we can use the steemp.api.getWitnessCount to return the list of all registered witnesses – which is a lot more than we thought, currently more than 1400 witnesses but of course many of them have been disabled or never produced a block.

1
2
3
4
5
6
7
8
9
10
11
function getTotalWitnesses() {
    return new Promise((resolve, reject) => {
      steem.api.getWitnessCount(function(err, result) {
          if (!err) {
              resolve(result);
          } else {
              reject(err);
          }
      });
    });
}
function getTotalWitnesses() {
    return new Promise((resolve, reject) => {
      steem.api.getWitnessCount(function(err, result) {
          if (!err) {
              resolve(result);
          } else {
              reject(err);
          }
      });
    });
}

Get All Witnesses Accounts

Then, we can use steem.api.getWitnesses to retreive the witnesses information for multiple accounts at the same time.

1
2
3
4
5
6
7
8
9
10
11
function getAllWitnessAccounts(total) {
    return new Promise((resolve, reject) => {
          steem.api.getWitnesses([...Array(total).keys()], function(err, result) {
            if (!err) {
                resolve(result);
            } else {
                reject(err);
           }
        });
    });
}   
function getAllWitnessAccounts(total) {
    return new Promise((resolve, reject) => {
          steem.api.getWitnesses([...Array(total).keys()], function(err, result) {
            if (!err) {
                resolve(result);
            } else {
                reject(err);
           }
        });
    });
}   

Filtering and Count the Results

Then, we can chain those two functions to filter out those witnesses that are running 23.1 and are active.

1
2
3
4
5
6
7
(async function () {
    const totalWitnesses = await getTotalWitnesses();
    let data = await getAllWitnessAccounts(totalWitnesses);
    log(data.filter(x => {
        return x.running_version === "0.23.1" && (x.signing_key !== "STM1111111111111111111111111111111114T1Anm");
    }).length);
})();
(async function () {
    const totalWitnesses = await getTotalWitnesses();
    let data = await getAllWitnessAccounts(totalWitnesses);
    log(data.filter(x => {
        return x.running_version === "0.23.1" && (x.signing_key !== "STM1111111111111111111111111111111114T1Anm");
    }).length);
})();

The answer is 46 witnesses are running on 23.1 and all of them are active. If we point the RPC node to HIVE chain, we get 107 active HIVE witnesses running on 23.0.

Run the code using SteemJs.

Slightly changing the query, we know:
There are 24 Witnesses running at 0.23.0 but they are disabled.
And there are 9 witnesses running at 0.23.0 and they are ‘active’ which may be those HIVE witnesses who didn’t take offline they witnesses.

BTW, i have added the dSteem into the SteemJs tool

steem-js-witnesses SteemJs: How Many Witnesses are Running on 23.1? blockchain javascript

SteemJs Editor

–EOF (The Ultimate Computing & Technology Blog) —

推荐阅读:
数学题:9个队员进行单循环制猜丁壳比赛  数学题:有三位登山者要攀登一座荒无人烟的大山。出发时每人只能携带够6天的食物  数学题:一个多位数四舍五入后是1亿,这个数最小是多少?  新网站优化对于一个企业来说到底有多重要  大学生如何在渗透测试行业立足  网站渗透测试中的历程经验记录分析  百度推出的“鸿雁计划”到底有什么用?对站长有哪些影响?  如何构建高质量的网站?  2020年SEO优化应该注意哪些细节?新手必看  运营笔记:花5分钟看完这篇文章,保证让你立马学会写运营方案 
评论列表
添加评论