mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Added Block and Mining Routes
This commit is contained in:
@@ -24,7 +24,18 @@ router.post("/detailsByHeight", detailsByHeightBulk)
|
||||
function root(req, res, next) {
|
||||
return res.json({ status: "block" })
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /block/detailsByHash/{hash} Get Block details single.
|
||||
* @apiName Block details single
|
||||
* @apiGroup Block
|
||||
* @apiDescription Returns details about a single block by hash.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/insight/block/detailsByHash/000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
// Call the insight server to get block details based on the hash.
|
||||
async function detailsByHashSingle(req, res, next) {
|
||||
try {
|
||||
@@ -66,7 +77,18 @@ async function detailsByHashSingle(req, res, next) {
|
||||
return res.json({ error: util.inspect(error) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /block/detailsByHash Get Block details bulk.
|
||||
* @apiName Block details bulk
|
||||
* @apiGroup Block
|
||||
* @apiDescription Returns retails about multiple blocks by hashes.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -d '{"hashes":["0000000000000000040e83398a79a16390897f0d18c92bada6350a19a32ec984","000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201"]}' -H "Content-Type: application/json" "http://localhost:3000/v3/insight/block/detailsByHash"
|
||||
* curl -d '{"hashes":["0000000000000000040e83398a79a16390897f0d18c92bada6350a19a32ec984","000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201"], "from": 1, "to": 5}' -H "Content-Type: application/json" "http://localhost:3000/v3/insight/block/detailsByHash"
|
||||
*
|
||||
*/
|
||||
async function detailsByHashBulk(req, res, next) {
|
||||
try {
|
||||
const hashes = req.body.hashes
|
||||
@@ -135,7 +157,18 @@ async function detailsByHashBulk(req, res, next) {
|
||||
return res.json({ error: util.inspect(error) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /block/detailsByHeight/{hash} Get Block details single by height.
|
||||
* @apiName Block details single by height
|
||||
* @apiGroup Block
|
||||
* @apiDescription Returns Details about a single block by height.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/insight/block/block/detailsByHeight/500000" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
// Call the Full Node to get block hash based on height, then call the Insight
|
||||
// server to get details from that hash.
|
||||
async function detailsByHeightSingle(req, res, next) {
|
||||
@@ -183,7 +216,18 @@ async function detailsByHeightSingle(req, res, next) {
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /block/detailsByHash Get Block details bulk by height.
|
||||
* @apiName Block details bulk by height
|
||||
* @apiGroup Block
|
||||
* @apiDescription Returns Bulk details about blocks by heights.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -d '{"heights":[499000,500000]}' -H "Content-Type: application/json" "http://localhost:3000/v3/insight/block/detailsByHeight"
|
||||
* curl -d '{"heights":[499000,500000], "from": 1, "to": 5}' -H "Content-Type: application/json" "http://localhost:3000/v3/insight/block/detailsByHeight"
|
||||
*
|
||||
*/
|
||||
async function detailsByHeightBulk(req, res, next) {
|
||||
try {
|
||||
const heights = req.body.heights
|
||||
|
||||
+24
-2
@@ -60,7 +60,18 @@ function root(req, res, next) {
|
||||
// res.send(error.response.data.error.message);
|
||||
// });
|
||||
// });
|
||||
|
||||
/**
|
||||
* @api {get} /mining/getMiningInfo Get Mining Info.
|
||||
* @apiName Mining info.
|
||||
* @apiGroup Mining
|
||||
* @apiDescription Returns a json object containing mining-related information.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/mining/getMiningInfo" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
async function getMiningInfo(req, res, next) {
|
||||
try {
|
||||
const {
|
||||
@@ -91,7 +102,18 @@ async function getMiningInfo(req, res, next) {
|
||||
return res.json({ error: util.inspect(err) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /mining/getNetworkHashps?nblocks=&height= Get Estimated network hashes per second.
|
||||
* @apiName Estimated network hashes per second.
|
||||
* @apiGroup Mining
|
||||
* @apiDescription Returns the estimated network hashes per second based on the last n blocks. Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change. Pass in [height] to estimate the network speed at the time when a certain block was found.
|
||||
*
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/mining/getNetworkHashps?nblocks=120&height=-1" -H "accept: application/json"
|
||||
*
|
||||
*
|
||||
*/
|
||||
async function getNetworkHashPS(req, res, next) {
|
||||
try {
|
||||
let nblocks = 120 // Default
|
||||
|
||||
Reference in New Issue
Block a user