Skip to content

Instantly share code, notes, and snippets.

@pinheadmz

pinheadmz/hsd-cov-stats.js

Last active May 15, 2020
Embed
What would you like to do?
'use strict';
const {NodeClient} = require('hs-client');
const {Network} = require('hsd');
const network = Network.get('main');
const nodeOptions = {
network: network.type,
port: network.rpcPort
};
const nodeClient = new NodeClient(nodeOptions);
(async () => {
await nodeClient.open();
let height = 0;
const map = new Map();
for(;;) {
const block = await nodeClient.getBlock(height);
if (!block)
break;
for (let i = 0; i < block.txs.length; i++) {
const tx = block.txs[i];
for (let j = 0; j < tx.outputs.length; j++) {
const output = tx.outputs[j];
let action = output.covenant.action;
if (i === 0 && j > 0 && action !== 'CLAIM') {
if (tx.inputs[j].witness[0].length > 900)
action = 'AIRDROP';
else
action = 'FAUCET';
}
if (i === 0 && j === 0)
action = 'COINBASE';
const curr = map.get(action)
if (!curr){
const det = new Map();
det.set('count', 1);
det.set('value', output.value);
map.set(action, det);
} else {
curr.set('count', curr.get('count') + 1);
curr.set('value', curr.get('value') + output.value);
}
}
}
console.log(block.height, map);
height++;
}
process.exit(0);
})();
@pinheadmz

This comment has been minimized.

Copy link
Owner Author

@pinheadmz pinheadmz commented Apr 23, 2020

11967 Map {
  'COINBASE' => Map { 'count' => 11968, 'value' => 24119992145291 },
  'FAUCET' => Map { 'count' => 1358, 'value' => 237238786158270 },
  'AIRDROP' => Map { 'count' => 4545, 'value' => 19301544016930 },
  'NONE' => Map { 'count' => 511160, 'value' => 9396965767064992 },
  'OPEN' => Map { 'count' => 28320, 'value' => 0 },
  'BID' => Map { 'count' => 88268, 'value' => 22703560015542 },
  'CLAIM' => Map { 'count' => 796, 'value' => 3936696577620 },
  'REVEAL' => Map { 'count' => 84760, 'value' => 14059980980609 },
  'REDEEM' => Map { 'count' => 47812, 'value' => 5741502797953 },
  'REGISTER' => Map { 'count' => 19863, 'value' => 2511477255414 },
  'UPDATE' => Map { 'count' => 80813, 'value' => 11549987178129 },
  'TRANSFER' => Map { 'count' => 10, 'value' => 3700100000 },
  'FINALIZE' => Map { 'count' => 10, 'value' => 3700100000 },
  'RENEW' => Map { 'count' => 1, 'value' => 400000000 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.