Closed unsystemizer closed 6 years ago
@unsystemizer great questions, I think for now as I am time-limited, I will add some examples of how to query the indexes in test/
.
Thanks. Can you describe your 2-3 steps what needs to be done, e.g. install a Web server, install this module, run Web server with this module, etc? What is your configuration if I may ask? I just need a couple of high level pointers.
@unsystemizer I hope to have some examples added by tomorrow soon, but incase that doesn't happen:
node.js
server (e.g using express) /test
to initialize adapter
and listen for new Bitcoin blocks.express
routes for your desired end-points, calling adapter.*
functions to retrieve the data you need.For example, using an router = express.Router()
, typeforce-middleware
and body-parser
, the following address_transactions
route returns an { '$address': [txIds] }
object result of transactions for each address, since block 0
.
router.post('/address_transactions', bodyParser.json(), typeforceMiddleware([
bitcoin.address.toOutputScript
]), (req, res) => {
let addrs = req.body
let tasks = {}
addrs.forEach((address) => {
let script = bitcoin.address.toOutputScript(address)
let scId = bitcoin.crypto.sha256(script).toString('hex')
tasks[address] = (next) => indexd.adapter.transactionIdsByScriptId(scId, 0, next)
})
parallel(tasks, (err, resultMap2) => {
if (err) return res.status(400).end()
let tempMap = {}
for (let address in resultMap2) {
Object.assign(tempMap, resultMap2[address])
}
res.status(200).json(tempMap)
})
})
@unsystemizer please see this example using express
.
Can someone created a simple Getting Started section in README?
I assume I need to install NodeJS, NPM, then this, and create a custom https://github.com/bitcoinjs/indexd/blob/master/test/index.js-like config file? Does that config file replace the main index.js file, or is it supposed to exist in a separate directory like here?
How to execute? How to query the index?