mirror of
https://github.com/fullstack-cash/bch-api.git
synced 2026-09-21 16:52:04 -07:00
Added api docs to blockchain route
This commit is contained in:
+1
-4
@@ -47,11 +47,9 @@ const utilV2 = require("./routes/v2/util")
|
||||
const slpV2 = require("./routes/v2/slp")
|
||||
|
||||
// v3
|
||||
const indexV3 = require("./routes/v3/index")
|
||||
const healthCheckV3 = require("./routes/v3/health-check")
|
||||
const blockchainV3 = require("./routes/v3/blockchain")
|
||||
const controlV3 = require("./routes/v3/control")
|
||||
const generatingV3 = require("./routes/v3/generating")
|
||||
const miningV3 = require("./routes/v3/mining")
|
||||
const networkV3 = require("./routes/v3/network")
|
||||
const rawtransactionsV3 = require("./routes/v3/rawtransactions")
|
||||
@@ -131,7 +129,6 @@ app.use(`/${v3prefix}/`, routeRateLimit)
|
||||
app.use(`/${v3prefix}/` + `health-check`, healthCheckV3)
|
||||
app.use(`/${v3prefix}/` + `blockchain`, blockchainV3.router)
|
||||
app.use(`/${v3prefix}/` + `control`, controlV3.router)
|
||||
app.use(`/${v3prefix}/` + `generating`, generatingV3)
|
||||
app.use(`/${v3prefix}/` + `mining`, miningV3.router)
|
||||
app.use(`/${v3prefix}/` + `network`, networkV3)
|
||||
app.use(`/${v3prefix}/` + `rawtransactions`, rawtransactionsV3.router)
|
||||
@@ -170,7 +167,7 @@ app.use((err, req, res, next) => {
|
||||
*/
|
||||
const port = normalizePort(process.env.PORT || "3000")
|
||||
app.set("port", port)
|
||||
console.log(`rest.bitcoin.com started on port ${port}`)
|
||||
console.log(`bch-api started on port ${port}`)
|
||||
|
||||
/**
|
||||
* Create HTTP server.
|
||||
|
||||
+108
-2
@@ -25,7 +25,6 @@ router.get("/getBlockchainInfo", getBlockchainInfo)
|
||||
router.get("/getBlockCount", getBlockCount)
|
||||
router.get("/getBlockHeader/:hash", getBlockHeaderSingle)
|
||||
router.post("/getBlockHeader", getBlockHeaderBulk)
|
||||
|
||||
router.get("/getChainTips", getChainTips)
|
||||
router.get("/getDifficulty", getDifficulty)
|
||||
router.get("/getMempoolEntry/:txid", getMempoolEntrySingle)
|
||||
@@ -42,7 +41,18 @@ function root(req, res, next) {
|
||||
return res.json({ status: "blockchain" })
|
||||
}
|
||||
|
||||
// Returns the hash of the best (tip) block in the longest block chain.
|
||||
/**
|
||||
* @api {get} /blockchain/getBestBlockHash Get best block hash
|
||||
* @apiName GetBestBlockHash
|
||||
* @apiGroup Blockchain
|
||||
* @apiDescription Returns the hash of the best (tip) block in the longest
|
||||
* block chain.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/blockchain/getBestBlockHash" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {String} bestBlockHash 000000000000000002bc884334336d99c9a9c616670a9244c6a8c1fc35aa91a1
|
||||
*/
|
||||
async function getBestBlockHash(req, res, next) {
|
||||
try {
|
||||
const {
|
||||
@@ -75,6 +85,31 @@ async function getBestBlockHash(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 "http://localhost:3000/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 function getBlockchainInfo(req, res, next) {
|
||||
try {
|
||||
const {
|
||||
@@ -108,6 +143,17 @@ async function getBlockchainInfo(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /blockchain/getBlockCount Get Block Count
|
||||
* @apiName GetBlockCount
|
||||
* @apiGroup Blockchain
|
||||
* @apiDescription Returns the number of blocks in the longest blockchain.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/blockchain/getBlockCount" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {Number} bestBlockCount 587665
|
||||
*/
|
||||
async function getBlockCount(req, res, next) {
|
||||
try {
|
||||
const {
|
||||
@@ -140,6 +186,36 @@ async function getBlockCount(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /blockchain/getBlockHeader/:hash Get single block header
|
||||
* @apiName GetSingleBlockHeader
|
||||
* @apiGroup Blockchain
|
||||
* @apiDescription If verbose is false (default), returns a string that is
|
||||
* serialized, hex-encoded data for blockheader 'hash'. If verbose is true,
|
||||
* returns an Object with information about blockheader hash.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:3000/v3/blockchain/getBlockHeader/000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201?verbose=true" -H "accept: application/json"
|
||||
*
|
||||
* @apiParam {String} hash block hash
|
||||
* @apiParam {Boolean} verbose Return verbose data
|
||||
*
|
||||
* @apiSuccess {Object} object Object containing data
|
||||
* @apiSuccess {String} object.hash "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201"
|
||||
* @apiSuccess {Number} object.confirmations 61839
|
||||
* @apiSuccess {Number} object.height 500000
|
||||
* @apiSuccess {Number} object.version 536870912
|
||||
* @apiSuccess {String} object.versionHex "20000000"
|
||||
* @apiSuccess {String} object.merkleroot "4af279645e1b337e655ae3286fc2ca09f58eb01efa6ab27adedd1e9e6ec19091"
|
||||
* @apiSuccess {Number} object.time 1509343584
|
||||
* @apiSuccess {Number} object.mediantime 1509336533
|
||||
* @apiSuccess {Number} object.nonce 3604508752
|
||||
* @apiSuccess {String} object.bits "1809b91a"
|
||||
* @apiSuccess {Number} object.difficulty 113081236211.4533
|
||||
* @apiSuccess {String} object.chainwork "0000000000000000000000000000000000000000007ae48aca46e3b449ad9714"
|
||||
* @apiSuccess {String} object.previousblockhash "0000000000000000043831d6ebb013716f0580287ee5e5687e27d0ed72e6e523"
|
||||
* @apiSuccess {String} object.nextblockhash "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
|
||||
*/
|
||||
async function getBlockHeaderSingle(req, res, next) {
|
||||
try {
|
||||
let verbose = false
|
||||
@@ -183,6 +259,36 @@ async function getBlockHeaderSingle(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /blockchain/getBlockHeader Get multiple block headers
|
||||
* @apiName GetBulkBlockHeader
|
||||
* @apiGroup Blockchain
|
||||
* @apiDescription If verbose is false (default), returns a string that is
|
||||
* serialized, hex-encoded data for blockheader 'hash'. If verbose is true,
|
||||
* returns an Object with information about blockheader hash.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X POST "https://rest.bitcoin.com/v3/blockchain/getBlockHeader" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"hashes\":[\"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201\",\"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3\"],\"verbose\":true}"
|
||||
*
|
||||
* @apiParam {String} hash block hash
|
||||
* @apiParam {Boolean} verbose Return verbose data
|
||||
*
|
||||
* @apiSuccess {Array} array array containing objects
|
||||
* @apiSuccess {String} object.hash "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201"
|
||||
* @apiSuccess {Number} object.confirmations 61839
|
||||
* @apiSuccess {Number} object.height 500000
|
||||
* @apiSuccess {Number} object.version 536870912
|
||||
* @apiSuccess {String} object.versionHex "20000000"
|
||||
* @apiSuccess {String} object.merkleroot "4af279645e1b337e655ae3286fc2ca09f58eb01efa6ab27adedd1e9e6ec19091"
|
||||
* @apiSuccess {Number} object.time 1509343584
|
||||
* @apiSuccess {Number} object.mediantime 1509336533
|
||||
* @apiSuccess {Number} object.nonce 3604508752
|
||||
* @apiSuccess {String} object.bits "1809b91a"
|
||||
* @apiSuccess {Number} object.difficulty 113081236211.4533
|
||||
* @apiSuccess {String} object.chainwork "0000000000000000000000000000000000000000007ae48aca46e3b449ad9714"
|
||||
* @apiSuccess {String} object.previousblockhash "0000000000000000043831d6ebb013716f0580287ee5e5687e27d0ed72e6e523"
|
||||
* @apiSuccess {String} object.nextblockhash "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
|
||||
*/
|
||||
async function getBlockHeaderBulk(req, res, next) {
|
||||
try {
|
||||
const hashes = req.body.hashes
|
||||
|
||||
@@ -25,7 +25,7 @@ function root(req, res, next) {
|
||||
* @apiDescription RPC call which gets basic full node information.
|
||||
*
|
||||
* @apiExample Example usage:
|
||||
* curl -X GET "http://localhost:5000/v3/control/getinfo" -H "accept: application/json"
|
||||
* curl -X GET "http://localhost:3000/v3/control/getinfo" -H "accept: application/json"
|
||||
*
|
||||
* @apiSuccess {Object} object Object containing data
|
||||
* @apiSuccess {Number} object.version Full node version
|
||||
@@ -38,7 +38,7 @@ function root(req, res, next) {
|
||||
* @apiSuccess {Boolean} object.testnet testnet = true, mainnet = false
|
||||
* @apiSuccess {Number} object.paytxfee ?
|
||||
* @apiSuccess {Number} object.relayfee ?
|
||||
* @apiSuccess {String} object.errors ?
|
||||
* @apiSuccess {String} object.errors Recent errors
|
||||
*/
|
||||
async function getInfo(req, res, next) {
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user