-- Leo's gemini proxy

-- Connecting to karelbilek.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; charset=utf-8

// 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))
    }
  }
})

-- Response ended

-- Page fetched on Mon May 20 16:03:18 2024