-
-
Save pinheadmz/791a86f0782f12a2e08f54201bae8848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const {NodeClient} = require('hs-client'); | |
const {Network, Output} = require('hsd'); | |
const AirdropProof = require('hsd/lib/primitives/airdropproof'); | |
const {OwnershipProof} = require('hsd/lib/covenants/ownership'); | |
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(); | |
map.set('unspendable', 0); | |
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]; | |
const O = Output.fromJSON(output); | |
if (O.isUnspendable()) | |
map.set('unspendable', map.get('unspendable') + 1); | |
let action = output.covenant.action; | |
let value = output.value; | |
if (i === 0 && j > 0) { | |
const blob = Buffer.from(tx.inputs[j].witness[0], 'hex'); | |
// console.dir(tx, {depth:null}); | |
if (action === 'CLAIM') { | |
const claim = OwnershipProof.decode(blob); | |
const data = claim.getData(network); | |
value = data.value; | |
} else { | |
if (blob.length > 900) { | |
action = 'AIRDROP'; | |
const proof = AirdropProof.decode(blob); | |
value = proof.getValue(); | |
} else { | |
action = 'FAUCET'; | |
const proof = AirdropProof.decode(blob); | |
value = proof.getValue(); | |
} | |
} | |
} | |
if (i === 0 && j === 0) { | |
action = 'COINBASE'; | |
value = 2000000000; | |
} | |
const curr = map.get(action); | |
if (!curr) { | |
const det = new Map(); | |
det.set('count', 1); | |
det.set('value', value); | |
map.set(action, det); | |
} else { | |
curr.set('count', curr.get('count') + 1); | |
curr.set('value', curr.get('value') + value); | |
} | |
} | |
} | |
console.log(block.height, map); | |
height++; | |
} | |
process.exit(0); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment