<commit_before># indexd
An external [bitcoind](https://github.com/bitcoin/bitcoin) index management service.


## Example
Uses [`yajrpc`](https://github.com/dcousens/yajrpc) for the bitcoind RPC;
[`leveldown`](https://github.com/level/leveldown) for the database;
and [`zmq`](https://www.npmjs.com/package/zmq) for bitcoind notifications.

``` javascript
require('dotenv').load()

let debug = require('debug')('index')
let debugZmq = require('debug')('zmq')
let indexd = require('indexd')
let leveldown = require('leveldown')
let qup = require('qup')
let rpc = require('yajrpc/qup')({
  url: process.env.RPC,
  user: process.env.RPCUSER,
  pass: <PASSWORD>,
  batch: process.env.RPCBATCHSIZE,
  concurrent: process.env.RPCCONCURRENT
})
let zmq = require('zmq')

function debugIfErr (err) {
  if (err) debug(err)
}

let db = leveldown(process.env.LEVELDB)
db.open({
  writeBufferSize: 1 * 1024 * 1024 * 1024
}, (err) => {
  if (err) return debugIfErr(err)
  debug(`Opened leveldb @ ${process.env.LEVELDB}`)

  let adapter = indexd.makeAdapter(db, rpc)
  let syncQueue = qup((_, next) => indexd.resync(rpc, adapter, next), 1)

  function syncAndReset (callback) {
    // maximum 2 waiting
    if (syncQueue.running > 1) return callback()

    syncQueue.push(null, (err) => {
      if (err) return callback(err)

      adapter.reset(callback)
    })
  }

  let zmqSock = zmq.socket('sub')
  zmqSock.connect(process.env.ZMQ)
  zmqSock.subscribe('hashblock')
  zmqSock.subscribe('hashtx')
  zmqSock.on('message', (topic, message) => {
    topic = topic.toString('utf8')
    debugZmq(topic)

    if (topic === 'hashblock') return syncAndReset(debugIfErr)
    if (topic !== 'hashtx') return

    let txId = message.toString('hex')
    adapter.see(txId, debugIfErr)
  })

  syncAndReset(debugIfErr)
})
```


## License [ISC](LICENSE)<commit_msg>README: just link to active example<commit_after># indexd
An external [bitcoind](https://github.com/bitcoin/bitcoin) index management service.


## Example
Uses [`yajrpc`](https://github.com/dcousens/yajrpc) for the bitcoind RPC;
[`leveldown`](https://github.com/level/leveldown) for the database;
and [`zmq`](https://www.npmjs.com/package/zmq) for bitcoind notifications.

See [`test/index.js`](test/index.js) for a functioning example.


## License [ISC](LICENSE)
{'fraction_non_alphanumeric': 0.16463944396177238, 'fraction_numerical': 0.007384882710686359, 'mean_word_length': 4.56280193236715, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2780094', 'n_tokens_mistral': 845, 'n_tokens_neox': 798, 'n_words': 175}