💾 Archived View for karelbilek.com › btcinputs › experiment2.gmi captured on 2024-05-12 at 15:18:05. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

// run cat /path/to/blocks/blk* | node experiment.js > out
// note: it appends stats for sanity checking every 10k blocks, see below

var BlockStream = require('blkdat-stream')
var blockStream = new BlockStream() // for testnet3: new BlockStream(0x0709110b)
var bitcoin = require('bitcoinjs-lib')

var i = 0
var res = {}
process.stdin.pipe(new BlockStream()).on('data', function (blockBuffer) {
  i++
  const block = bitcoin.Block.fromBuffer(blockBuffer)
  const ydiff = (new Date() - new Date(block.timestamp*1000)) / (1000 * 60 * 60 * 24 * 365)

  if (ydiff <= 2) {

    block.transactions.forEach(tx => {
      if (!tx.isCoinbase()) {
        tx.ins.forEach(inp => {
          const type = bitcoin.script.classifyInput(inp.script);
          if (type === "scripthash") {
              var decoded = bitcoin.script.scriptHash.input.decode(inp.script)
              var redeemS = decoded.redeemScript
              var redeemSS = decoded.redeemScriptSig
              var stype = bitcoin.script.classifyOutput(redeemS)
              if (stype === 'multisig') {
                  var decodedRedeem = bitcoin.script.multisig.output.decode(redeemS)
                  var m = decodedRedeem.m
                  var n = decodedRedeem.pubKeys.length
                  var sstype = m + "-of-" + n
                  stype = stype + sstype
              } else if (stype === 'nonstandard') {
                  // maybe classify input will work?
                  stype = bitcoin.script.classifyInput(redeemSS)
              }
              var scr = stype + "," + inp.script.length
              res[scr] = (res[scr] || 0) + 1
            }
        })
      }
    })

    if (i%10000 === 0) {
      console.log("---------------------")
      var types = Object.keys(res).sort((a, b) => (res[b] - res[a]))
      types.map(typ => typ + "," + res[typ]).forEach(k => console.log(k))
    }
  }
})