Browse Source

Blockheight and Block hash get params

master
nolim1t 5 years ago
parent
commit
dd4b6e0e9b
No known key found for this signature in database GPG Key ID: F6287B82CC84BCBD
  1. 9
      logic/bitcoind.js
  2. 11
      routes/v1/bitcoind/info.js
  3. 5
      services/bitcoind.js

9
logic/bitcoind.js

@ -130,7 +130,16 @@ async function getTransaction(txid) {
}
}
async function getBlockHash(height) {
const getBlockHashObj = await bitcoindService.getBlockHash(height);
return {
height: getBlockHashObj.result
}
}
module.exports = {
getBlockHash,
getTransaction,
getBlock,
getBlockCount,

11
routes/v1/bitcoind/info.js

@ -35,6 +35,17 @@ router.get('/version', auth.jwt, safeHandler((req, res) =>
.then(version => res.json(version))
));
router.get('/block', auth.jwt, safeHandler((req, res) => {
if (req.query.hash !== undefined && req.query.hash !== null) {
bitcoind.getBlock(req.query.hash)
.then(blockhash => res.json(blockhash))
} else if (req.query.height !== undefined && req.query.height !== null) {
bitcoind.getBlockHash(req.query.height)
.then(blockhash => res.json(blockhash))
}
}
));
// /v1/bitcoind/info/block/<hash>
router.get('/block/:id', auth.jwt, safeHandler((req, res) =>
bitcoind.getBlock(req.params.id)

5
services/bitcoind.js

@ -64,6 +64,10 @@ function promiseifyParamTwo(rpcObj, rpcFn, param1, param2, what) {
});
}
function getBlockHash(height) {
return promiseifyParam(rpcClient, rpcClient.getBlockHash, height, 'block height');
}
function getBlock(hash) {
return promiseifyParam(rpcClient, rpcClient.getBlock, hash, 'block info');
}
@ -105,6 +109,7 @@ function help() {
}
module.exports = {
getBlockHash,
getBlock,
getTransaction,
getBlockChainInfo,

Loading…
Cancel
Save