mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-22 09:12:05 -07:00
Ported getBestBlockHash()
This commit is contained in:
@@ -29,12 +29,27 @@ class Blockchain {
|
||||
|
||||
this.router = router
|
||||
this.router.get("/", this.root)
|
||||
this.router.get("/getBestBlockHash", this.getBestBlockHash)
|
||||
this.router.get("/getBlockchainInfo", this.getBlockchainInfo)
|
||||
}
|
||||
|
||||
root(req, res, next) {
|
||||
return res.json({ status: "blockchain" })
|
||||
}
|
||||
|
||||
// DRY error handler.
|
||||
errorHandler(err, res) {
|
||||
// Attempt to decode the error message.
|
||||
const { msg, status } = routeUtils.decodeError(err)
|
||||
if (msg) {
|
||||
res.status(status)
|
||||
return res.json({ error: msg })
|
||||
}
|
||||
|
||||
res.status(500)
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /blockchain/getBestBlockHash Get best block hash
|
||||
* @apiName GetBestBlockHash
|
||||
@@ -60,19 +75,54 @@ class Blockchain {
|
||||
|
||||
return res.json(response.data.result)
|
||||
} catch (err) {
|
||||
// Attempt to decode the error message.
|
||||
const { msg, status } = routeUtils.decodeError(err)
|
||||
if (msg) {
|
||||
res.status(status)
|
||||
return res.json({ error: msg })
|
||||
}
|
||||
|
||||
// Write out error to error log.
|
||||
//logger.error(`Error in rawtransactions/decodeRawTransaction: `, err)
|
||||
wlogger.error(`Error in blockchain.ts/getBestBlockHash().`, err)
|
||||
|
||||
res.status(500)
|
||||
return res.json({ error: util.inspect(err) })
|
||||
return this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /blockchain/getBlockchainInfo Get blockchain info
|
||||
* @apiName GetBlockchainInfo
|
||||
* @apiGroup Blockchain
|
||||
* @apiDescription Returns an object containing various state info regarding blockchain processing.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "https://mainnet.bchjs.cash/v3/blockchain/getBlockchainInfo" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {Object} object Object containing data
|
||||
* @apiSuccess {String} object.chain "main"
|
||||
* @apiSuccess {Number} object.blocks 561838
|
||||
* @apiSuccess {Number} object.headers 561838
|
||||
* @apiSuccess {String} object.bestblockhash "000000000000000002307dd38cd01c7308b8febfcdf5772cf087b5bb023d55bc"
|
||||
* @apiSuccess {Number} object.difficulty 246585566638.1496
|
||||
* @apiSuccess {String} object.mediantime 1545402693
|
||||
* @apiSuccess {Number} object.verificationprogress 0.999998831622689
|
||||
* @apiSuccess {Boolean} object.chainwork "000000000000000000000000000000000000000000d8c09a8ab7262080266b3e"
|
||||
* @apiSuccess {Number} object.pruned false
|
||||
* @apiSuccess {Array} object.softforks Array of objects
|
||||
* @apiSuccess {String} object.softforks.id "bip34"
|
||||
* @apiSuccess {String} object.softforks.version 2
|
||||
* @apiSuccess {Object} object.softforks.reject
|
||||
* @apiSuccess {String} object.softforks.reject.status true
|
||||
*/
|
||||
async getBlockchainInfo(req, res, next) {
|
||||
try {
|
||||
// Axios options
|
||||
const options = routeUtils.getAxiosOptions()
|
||||
options.data.id = "getblockchaininfo"
|
||||
options.data.method = "getblockchaininfo"
|
||||
options.data.params = []
|
||||
|
||||
const response = await this.axios.request(options)
|
||||
|
||||
return res.json(response.data.result)
|
||||
} catch (err) {
|
||||
// Write out error to error log.
|
||||
wlogger.error(`Error in blockchain.ts/getBlockchainInfo().`, err)
|
||||
|
||||
return this.errorHandler(err, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user