From 4a271face5786ec15cc289715b9bf420bb22078a Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 13:21:06 -0700 Subject: [PATCH 1/9] Removed block and transaction endpoints --- src/app.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index 73e5318..6e9e076 100644 --- a/src/app.js +++ b/src/app.js @@ -49,14 +49,12 @@ const slpV2 = require("./routes/v2/slp") // v3 const indexV3 = require("./routes/v3/index") const healthCheckV3 = require("./routes/v3/health-check") -const blockV3 = require("./routes/v3/block") 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") -const transactionV3 = require("./routes/v3/transaction") const utilV3 = require("./routes/v3/util") const slpV3 = require("./routes/v3/slp") const xpubV3 = require("./routes/v3/xpub") @@ -126,17 +124,15 @@ app.use(`/${v2prefix}/` + `transaction`, transactionV2.router) app.use(`/${v2prefix}/` + `util`, utilV2.router) app.use(`/${v2prefix}/` + `slp`, slpV2.router) -// Rate limit on all v2 routes +// Rate limit on all v3 routes app.use(`/${v3prefix}/`, routeRateLimit) app.use(`/${v3prefix}/` + `health-check`, healthCheckV3) app.use(`/${v3prefix}/` + `blockchain`, blockchainV3.router) -app.use(`/${v3prefix}/` + `block`, blockV3.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) -app.use(`/${v3prefix}/` + `transaction`, transactionV3.router) app.use(`/${v3prefix}/` + `util`, utilV3.router) app.use(`/${v3prefix}/` + `slp`, slpV3.router) app.use(`/${v3prefix}/` + `xpub`, xpubV3.router) From 57a99722984b8a4fb2963ed2b4aa7192792bb651 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 13:22:16 -0700 Subject: [PATCH 2/9] Ran npm audit --- package-lock.json | 110 ++++++++++++++++++++++++++++++++++++++++++++-- package.json | 1 + 2 files changed, 108 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 952cebd..5f2c5fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -765,6 +765,69 @@ "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=", "dev": true }, + "apidoc": { + "version": "0.17.7", + "resolved": "https://registry.npmjs.org/apidoc/-/apidoc-0.17.7.tgz", + "integrity": "sha512-9Wf4bRPwCuWOIOxR42dDnsXnFw+rhJg5VrMQK+KmNxJwyIh30UqX6gvjjXSG6YO74MqE87F18bbQXUENK9dPGg==", + "requires": { + "apidoc-core": "~0.8.2", + "commander": "^2.19.0", + "fs-extra": "^7.0.0", + "lodash": "^4.17.10", + "markdown-it": "^8.3.1", + "winston": "^3.0.0" + }, + "dependencies": { + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, + "apidoc-core": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/apidoc-core/-/apidoc-core-0.8.3.tgz", + "integrity": "sha1-2dY1RYKd8lDSzKBJaDqH53U2S5Y=", + "requires": { + "fs-extra": "^3.0.1", + "glob": "^7.1.1", + "iconv-lite": "^0.4.17", + "klaw-sync": "^2.1.0", + "lodash": "~4.17.4", + "semver": "~5.3.0" + }, + "dependencies": { + "fs-extra": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-3.0.1.tgz", + "integrity": "sha1-N5TzeMWLNC6n27sjCVEJxLO2IpE=", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^3.0.0", + "universalify": "^0.1.0" + } + }, + "jsonfile": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.1.tgz", + "integrity": "sha1-pezG9l9T9mLEQVx2daAzHQmS7GY=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "semver": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", + "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=" + } + } + }, "append-transform": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-1.0.0.tgz", @@ -3590,6 +3653,11 @@ "has-binary2": "~1.0.2" } }, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" + }, "env-ci": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/env-ci/-/env-ci-4.1.1.tgz", @@ -6959,7 +7027,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -7024,6 +7091,14 @@ "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true }, + "klaw-sync": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/klaw-sync/-/klaw-sync-2.1.0.tgz", + "integrity": "sha1-PTvNhgDnv971MjHHOf8FOu1WDkQ=", + "requires": { + "graceful-fs": "^4.1.11" + } + }, "kuler": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz", @@ -7186,6 +7261,14 @@ "type-check": "~0.3.2" } }, + "linkify-it": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.1.0.tgz", + "integrity": "sha512-4REs8/062kV2DSHxNfq5183zrqXMl7WP0WzABH9IeJI+NLm429FgE1PDecltYfnOoFDFlZGh2T8PfZn0r+GTRg==", + "requires": { + "uc.micro": "^1.0.1" + } + }, "load-json-file": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", @@ -7395,6 +7478,18 @@ "object-visit": "^1.0.0" } }, + "markdown-it": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz", + "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==", + "requires": { + "argparse": "^1.0.7", + "entities": "~1.1.1", + "linkify-it": "^2.0.0", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + } + }, "marked": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/marked/-/marked-0.6.2.tgz", @@ -7425,6 +7520,11 @@ "safe-buffer": "^5.1.2" } }, + "mdurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -15694,6 +15794,11 @@ "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", "dev": true }, + "uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==" + }, "uglify-js": { "version": "3.5.15", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.5.15.tgz", @@ -15852,8 +15957,7 @@ "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "unorm": { "version": "1.5.0", diff --git a/package.json b/package.json index 2659ed5..cbeaf53 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "dependencies": { "@chris.troutner/bitbox-js": "^7.0.2", + "apidoc": "^0.17.7", "axios": "^0.19.0", "bitcoincash-zmq-decoder": "0.1.5", "body-parser": "^1.18.3", From 2f26b39fea05d804a3984d8d27652400e5807dd9 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 13:25:19 -0700 Subject: [PATCH 3/9] Adding docs dir --- docs/README.md | 1 + package.json | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..dcaa432 --- /dev/null +++ b/docs/README.md @@ -0,0 +1 @@ +This directory holds api docs generated by apidoc. diff --git a/package.json b/package.json index cbeaf53..c54a260 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "test-v3": "export NETWORK=testnet && nyc --reporter=text mocha --timeout 25000 test/v3/", "test:integration": "mocha test/v3/integration", "coverage": "nyc report --reporter=text-lcov | coveralls", - "coverage:report": "export NETWORK=testnet && nyc --reporter=html mocha test/v2/" + "coverage:report": "export NETWORK=testnet && nyc --reporter=html mocha test/v2/", + "docs": "./node_modules/.bin/apidoc -i src/ -o docs" }, "engines": { "node": ">=10.15.1" @@ -83,5 +84,9 @@ "npmPublish": false } ] + }, + "apidoc": { + "title": "bch-api", + "url": "localhost:3000" } } From 07e415f307a9dba1362310a977cf602ac293e66f Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 13:26:10 -0700 Subject: [PATCH 4/9] Adding docs dir to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1ab1b59..c6880e3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ test-v1 nohup.out slp-tx-db/ logs/ +docs/* From c915aff436f229a8b4989f9e500fdd67c16a6bea Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 17:26:27 -0700 Subject: [PATCH 5/9] fix(api docs): Added api docs and first docs --- package.json | 2 +- src/app.js | 4 +++- src/public/index.html | 21 ++++++++++++++------- src/routes/v3/bitcore.js | 10 ++++++++++ src/routes/v3/control.js | 25 +++++++++++++++++++++++-- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index c54a260..389d39d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test:integration": "mocha test/v3/integration", "coverage": "nyc report --reporter=text-lcov | coveralls", "coverage:report": "export NETWORK=testnet && nyc --reporter=html mocha test/v2/", - "docs": "./node_modules/.bin/apidoc -i src/ -o docs" + "docs": "./node_modules/.bin/apidoc -i src/routes/v3 -o docs" }, "engines": { "node": ">=10.15.1" diff --git a/src/app.js b/src/app.js index 6e9e076..d7fe624 100644 --- a/src/app.js +++ b/src/app.js @@ -76,7 +76,9 @@ app.enable("trust proxy") app.set("views", path.join(__dirname, "views")) app.set("view engine", "jade") -app.use("/public", express.static(`${__dirname}/public`)) +// Mount the docs +app.use("/docs", express.static(`${__dirname}/../docs`)) + app.use(logger("dev")) app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: false })) diff --git a/src/public/index.html b/src/public/index.html index d2cc81d..28ed44e 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -4,9 +4,9 @@ - The HTML5 Herald - - + BCH API + + @@ -18,10 +18,17 @@ This web server is based on rest.bitcoin.com. Go there to view an interactive UI of the REST API endpoints.

-

- View the API documentation - on developer.bitcoin.com. -

+ diff --git a/src/routes/v3/bitcore.js b/src/routes/v3/bitcore.js index 70722d6..8867af8 100644 --- a/src/routes/v3/bitcore.js +++ b/src/routes/v3/bitcore.js @@ -61,6 +61,16 @@ async function balanceFromBitcore(thisAddress) { } } +/** + * @api {get} /bitcore/balance/:address Get BCH balance for an address + * @apiName GetBalance + * @apiGroup Bitcore + * + * @apiParam {String} address Bitcoin Cash address. + * + * @apiSuccess {String} firstname Firstname of the User. + * @apiSuccess {String} lastname Lastname of the User. + */ // GET handler for single balance async function balanceSingle(req, res, next) { try { diff --git a/src/routes/v3/control.js b/src/routes/v3/control.js index fabc233..a7994c8 100644 --- a/src/routes/v3/control.js +++ b/src/routes/v3/control.js @@ -13,13 +13,34 @@ const util = require("util") util.inspect.defaultOptions = { depth: 1 } router.get("/", root) -router.get("/getInfo", getInfo) +router.get("/getinfo", getInfo) function root(req, res, next) { return res.json({ status: "control" }) } -// Execute the RPC getinfo call. +/** + * @api {get} /control/getinfo Get full node info + * @apiName GetInfo + * @apiGroup Control + * @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" + * + * @apiSuccess {Object} object Object containing data + * @apiSuccess {Number} object.version Full node version + * @apiSuccess {Number} object.protocolversion Protocol version + * @apiSuccess {Number} object.blocks Current block + * @apiSuccess {Number} object.timeoffset ? + * @apiSuccess {Number} object.connections Number of connected peers + * @apiSuccess {String} object.proxy ? + * @apiSuccess {Number} object.difficulty Current difficulty setting + * @apiSuccess {Boolean} object.testnet testnet = true, mainnet = false + * @apiSuccess {Number} object.paytxfee ? + * @apiSuccess {Number} object.relayfee ? + * @apiSuccess {String} object.errors ? + */ async function getInfo(req, res, next) { const { BitboxHTTP, From b8f96bf90c28d6185278f0da9bf1c2db9ba8ecd0 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 17:30:30 -0700 Subject: [PATCH 6/9] Removing generating library --- src/routes/v3/generating.js | 51 ------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/routes/v3/generating.js diff --git a/src/routes/v3/generating.js b/src/routes/v3/generating.js deleted file mode 100644 index ec0c601..0000000 --- a/src/routes/v3/generating.js +++ /dev/null @@ -1,51 +0,0 @@ -"use strict" - -const express = require("express") -const router = express.Router() -//const axios = require("axios"); - -//const BITBOXCli = require("bitbox-sdk/lib/bitbox-sdk").default; -//const BITBOX = new BITBOXCli(); - -//const BitboxHTTP = axios.create({ -// baseURL: process.env.RPC_BASEURL, -//}); -//const username = process.env.RPC_USERNAME; -//const password = process.env.RPC_PASSWORD; - -router.get("/", (req, res, next) => { - res.json({ status: "generating" }) -}) -// -// router.post('/generateToAddress/:nblocks/:address', (req, res, next) => { -// let maxtries = 1000000; -// if(req.query.maxtries) { -// maxtries = parseInt(req.query.maxtries); -// } -// -// BitboxHTTP({ -// method: 'post', -// auth: { -// username: username, -// password: password -// }, -// data: { -// jsonrpc: "1.0", -// id:"generatetoaddress", -// method: "generatetoaddress", -// params: [ -// req.params.nblocks, -// req.params.address, -// maxtries -// ] -// } -// }) -// .then((response) => { -// res.json(response.data.result); -// }) -// .catch((error) => { -// res.send(error.response.data.error.message); -// }); -// }); - -module.exports = router From 45f430bc7e250a48b3d7bb7a895550dd62056828 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Tue, 18 Jun 2019 20:27:11 -0700 Subject: [PATCH 7/9] Removed old logging library --- src/routes/v3/blockchain.js | 12 ++++---- src/routes/v3/control.js | 1 - src/routes/v3/health-check.js | 7 ++++- src/routes/v3/index.js | 15 ---------- src/routes/v3/logging.js | 51 -------------------------------- src/routes/v3/mining.js | 1 - src/routes/v3/rawtransactions.js | 1 - src/routes/v3/slp.js | 5 ++-- src/routes/v3/util.js | 3 +- src/routes/v3/xpub.js | 3 -- 10 files changed, 16 insertions(+), 83 deletions(-) delete mode 100644 src/routes/v3/index.js delete mode 100644 src/routes/v3/logging.js diff --git a/src/routes/v3/blockchain.js b/src/routes/v3/blockchain.js index 65d772d..57ef71b 100644 --- a/src/routes/v3/blockchain.js +++ b/src/routes/v3/blockchain.js @@ -10,7 +10,6 @@ const router = express.Router() const axios = require("axios") const routeUtils = require("./route-utils") -const logger = require("./logging.js") const wlogger = require("../../util/winston-logging") // Used to convert error messages to strings, to safely pass to users. @@ -204,7 +203,7 @@ async function getBlockHeaderBulk(req, res, next) { }) } - logger.debug( + wlogger.debug( `Executing blockchain/getBlockHeaderBulk with these hashes: `, hashes ) @@ -385,7 +384,7 @@ async function getMempoolEntryBulk(req, res, next) { }) } - logger.debug( + wlogger.debug( `Executing blockchain/getMempoolEntry with these txids: `, txids ) @@ -641,7 +640,10 @@ async function getTxOutProofBulk(req, res, next) { } } - logger.debug(`Executing blockchain/getTxOutProof with these txids: `, txids) + wlogger.debug( + `Executing blockchain/getTxOutProof with these txids: `, + txids + ) // Loop through each txid and creates an array of requests to call in parallel const promises = txids.map(async txid => { @@ -826,7 +828,7 @@ async function verifyTxOutProofBulk(req, res, next) { } } - logger.debug( + wlogger.debug( `Executing blockchain/verifyTxOutProof with these proofs: `, proofs ) diff --git a/src/routes/v3/control.js b/src/routes/v3/control.js index a7994c8..a2e97ce 100644 --- a/src/routes/v3/control.js +++ b/src/routes/v3/control.js @@ -4,7 +4,6 @@ const express = require("express") const router = express.Router() const axios = require("axios") -const logger = require("./logging.js") const routeUtils = require("./route-utils") const wlogger = require("../../util/winston-logging") diff --git a/src/routes/v3/health-check.js b/src/routes/v3/health-check.js index 8c05030..45bb1e7 100644 --- a/src/routes/v3/health-check.js +++ b/src/routes/v3/health-check.js @@ -1,3 +1,8 @@ +/* + This health-check API can be used to test the server for aliveness and + readiness. +*/ + "use strict" const express = require("express") @@ -5,7 +10,7 @@ const router = express.Router() /* GET home page. */ router.get("/", (req, res, next) => { - res.json({ status: "winning v2" }) + res.json({ status: true }) }) module.exports = router diff --git a/src/routes/v3/index.js b/src/routes/v3/index.js deleted file mode 100644 index 33c175f..0000000 --- a/src/routes/v3/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict" - -const express = require("express") -const router = express.Router() - -/* GET home page. */ -router.get("/", (req, res, next) => { - res.render("swagger-v2") -}) - -router.get("/v2", (req, res, next) => { - res.render("swagger-v2") -}) - -module.exports = router diff --git a/src/routes/v3/logging.js b/src/routes/v3/logging.js deleted file mode 100644 index 07fd9be..0000000 --- a/src/routes/v3/logging.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - A utility library for setting up greylog2 logging. -*/ - -"use strict" - -// This will be uncommented and correct once we have our logging server functioning. -/* -var graylog2 = require("graylog2"); -var logger = new graylog2.graylog({ - servers: [ - { 'host': '127.0.0.1', port: 12201 }, - { 'host': '127.0.0.2', port: 12201 } - ], - hostname: 'server.name', // the name of this host - // (optional, default: os.hostname()) - facility: 'Node.js', // the facility for these log messages - // (optional, default: "Node.js") - bufferSize: 1350 // max UDP packet size, should never exceed the - // MTU of your system (optional, default: 1400) -}); - -logger.on('error', function (error) { - console.error('Error while trying to write to graylog2:', error); -}); -*/ - -// This is just a placeholder function that will be replaced once we get the -// greylog server working. -function log(msg, obj) { - //console.log(msg, obj) -} - -// This is just a placeholder function that will be replaced once we get the -// greylog server working. -function error(msg, obj) { - if (!obj) console.error(msg) - else console.error(msg, obj) -} - -// This is just a placeholder function that will be replaced once we get the -// greylog server working. -function debug(msg, obj) { - //console.log(msg, obj) -} - -module.exports = { - log, - error, - debug -} diff --git a/src/routes/v3/mining.js b/src/routes/v3/mining.js index 243b75a..54398af 100644 --- a/src/routes/v3/mining.js +++ b/src/routes/v3/mining.js @@ -5,7 +5,6 @@ const router = express.Router() const axios = require("axios") const routeUtils = require("./route-utils") -const logger = require("./logging.js") const wlogger = require("../../util/winston-logging") // Used to convert error messages to strings, to safely pass to users. diff --git a/src/routes/v3/rawtransactions.js b/src/routes/v3/rawtransactions.js index 99104c7..7ffed0c 100644 --- a/src/routes/v3/rawtransactions.js +++ b/src/routes/v3/rawtransactions.js @@ -5,7 +5,6 @@ const router = express.Router() const axios = require("axios") const routeUtils = require("./route-utils") -const logger = require("./logging.js") const wlogger = require("../../util/winston-logging") // Used to convert error messages to strings, to safely pass to users. diff --git a/src/routes/v3/slp.js b/src/routes/v3/slp.js index 19483d1..fb13532 100644 --- a/src/routes/v3/slp.js +++ b/src/routes/v3/slp.js @@ -5,7 +5,6 @@ const router = express.Router() const axios = require("axios") const routeUtils = require("./route-utils") -const logger = require("./logging.js") const strftime = require("strftime") const wlogger = require("../../util/winston-logging") @@ -812,7 +811,7 @@ async function validateBulk(req, res, next) { }) } - logger.debug(`Executing slp/validate with these txids: `, txids) + wlogger.debug(`Executing slp/validate with these txids: `, txids) // Validate each txid const validatePromises = txids.map(async txid => { @@ -865,7 +864,7 @@ async function validateSingle(req, res, next) { return res.json({ error: "txid can not be empty" }) } - logger.debug(`Executing slp/validate/:txid with this txid: `, txid) + wlogger.debug(`Executing slp/validate/:txid with this txid: `, txid) // Validate txid // Dev note: must call module.exports to allow stubs in unit tests. diff --git a/src/routes/v3/util.js b/src/routes/v3/util.js index e222d24..892e538 100644 --- a/src/routes/v3/util.js +++ b/src/routes/v3/util.js @@ -5,7 +5,6 @@ const router = express.Router() const axios = require("axios") const routeUtils = require("./route-utils") -const logger = require("./logging.js") const wlogger = require("../../util/winston-logging") const BITBOXJS = require("@chris.troutner/bitbox-js") @@ -122,7 +121,7 @@ async function validateAddressBulk(req, res, next) { } } - logger.debug(`Executing util/validate with these addresses: `, addresses) + wlogger.debug(`Executing util/validate with these addresses: `, addresses) const { BitboxHTTP, diff --git a/src/routes/v3/xpub.js b/src/routes/v3/xpub.js index bd3256e..60d36e9 100644 --- a/src/routes/v3/xpub.js +++ b/src/routes/v3/xpub.js @@ -7,7 +7,6 @@ const express = require("express") const requestUtils = require("./services/requestUtils") const axios = require("axios") -const logger = require("./logging.js") const routeUtils = require("./route-utils") const wlogger = require("../../util/winston-logging") @@ -48,7 +47,6 @@ async function fromXPubSingle(req, res, next) { }) } - logger.debug(`Executing address/fromXPub with this xpub: `, xpub) wlogger.debug(`Executing address/fromXPub with this xpub: `, xpub) const cashAddr = BITBOX.Address.fromXPub(xpub, hdPath) @@ -67,7 +65,6 @@ async function fromXPubSingle(req, res, next) { } // Write out error to error log. - //logger.error(`Error in rawtransactions/decodeRawTransaction: `, err) wlogger.error(`Error in address.ts/fromXPubSingle().`, err) res.status(500) From ab97850f7d433086b86c029ce86ad5235199b601 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 19 Jun 2019 20:57:07 -0700 Subject: [PATCH 8/9] Added api docs to blockchain route --- src/app.js | 5 +- src/routes/v3/blockchain.js | 110 +++++++++++++++++++++++++++++++++++- src/routes/v3/control.js | 4 +- 3 files changed, 111 insertions(+), 8 deletions(-) diff --git a/src/app.js b/src/app.js index d7fe624..751ed53 100644 --- a/src/app.js +++ b/src/app.js @@ -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. diff --git a/src/routes/v3/blockchain.js b/src/routes/v3/blockchain.js index 57ef71b..753ac06 100644 --- a/src/routes/v3/blockchain.js +++ b/src/routes/v3/blockchain.js @@ -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 diff --git a/src/routes/v3/control.js b/src/routes/v3/control.js index a2e97ce..270ca37 100644 --- a/src/routes/v3/control.js +++ b/src/routes/v3/control.js @@ -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 { From f04d01517f481ae76c6e9546ab3a936aeb366b00 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 19 Jun 2019 21:50:55 -0700 Subject: [PATCH 9/9] More api docs for the blockchain route --- src/routes/v3/blockchain.js | 104 ++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/src/routes/v3/blockchain.js b/src/routes/v3/blockchain.js index 753ac06..44f2b91 100644 --- a/src/routes/v3/blockchain.js +++ b/src/routes/v3/blockchain.js @@ -364,6 +364,17 @@ async function getBlockHeaderBulk(req, res, next) { } } +/** + * @api {get} /blockchain/getChainTips Get Chain Tips + * @apiName getChainTips + * @apiGroup Blockchain + * @apiDescription Return information about all known tips in the block tree, + * including the main chain as well as orphaned branches. + * + * @apiExample Example usage: + * curl -X GET "http://localhost:3000/v3/blockchain/getChainTips" -H "accept: application/json" + * + */ async function getChainTips(req, res, next) { try { const { @@ -396,7 +407,17 @@ async function getChainTips(req, res, next) { } } -// Get the current difficulty value, used to regulate mining power on the network. +/** + * @api {get} /blockchain/getDifficulty Get difficulty + * @apiName getDifficulty + * @apiGroup Blockchain + * @apiDescription Get the current difficulty value, used to regulate mining + * power on the network. + * + * @apiExample Example usage: + * curl -X GET "http://localhost:3000/v3/blockchain/getDifficulty" -H "accept: application/json" + * + */ async function getDifficulty(req, res, next) { try { const { @@ -430,7 +451,17 @@ async function getDifficulty(req, res, next) { } } -// Returns mempool data for given transaction. TXID must be in mempool (unconfirmed) +/** + * @api {get} /blockchain/getMempoolEntry/:txid Get single mempool entry + * @apiName getMempoolEntry + * @apiGroup Blockchain + * @apiDescription Returns mempool data for given transaction. TXID must be in + * mempool (unconfirmed) + * + * @apiExample Example usage: + * curl -X GET "http://localhost:3000/v3/blockchain/getMempoolEntry/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json" + * + */ async function getMempoolEntrySingle(req, res, next) { try { // Validate input parameter @@ -471,6 +502,15 @@ async function getMempoolEntrySingle(req, res, next) { } } +/** + * @api {post} /blockchain/getMempoolEntry Get bulk mempool entry + * @apiName getMempoolEntryBulk + * @apiGroup Blockchain + * @apiDescription Returns mempool data for multiple transactions + * + * @apiExample Example usage: + * curl -X POST http://localhost:3000/v3/blockchain/getMempoolEntry -H "Content-Type: application/json" -d "{\"txids\":[\"a5f972572ee1753e2fd2457dd61ce5f40fa2f8a30173d417e49feef7542c96a1\",\"5165dc531aad05d1149bb0f0d9b7bda99c73e2f05e314bcfb5b4bb9ca5e1af5e\"]}" + */ async function getMempoolEntryBulk(req, res, next) { try { const txids = req.body.txids @@ -545,6 +585,16 @@ async function getMempoolEntryBulk(req, res, next) { } } +/** + * @api {get} /blockchain/getMempoolInfo Get mempool info + * @apiName getMempoolInfo + * @apiGroup Blockchain + * @apiDescription Returns details on the active state of the TX memory pool. + * + * @apiExample Example usage: + * curl -X GET http://localhost:3000/v3/getMempoolInfo -H "accept: application/json" + * + */ async function getMempoolInfo(req, res, next) { try { const { @@ -577,6 +627,29 @@ async function getMempoolInfo(req, res, next) { } } +/** + * @api {get} /blockchain/getRawMempool Get mempool info + * @apiName getMempoolInfo + * @apiGroup Blockchain + * @apiDescription Returns details on the active state of the TX memory pool. + * + * @apiExample Example usage: + * curl -X GET http://localhost:3000/v3/getMempoolInfo -H "accept: application/json" + * + */ +/** + * @api {get} /blockchain/getRawMempool/?verbose= Get raw mempool + * @apiName getRawMempool + * @apiGroup Blockchain + * @apiDescription Returns all transaction ids in memory pool as a json array + * of string transaction ids. + * + * @apiExample Example usage: + * curl -X GET "http://localhost:3000/v3/getRawMempool/?verbose=true" -H "accept: application/json" + * + * @apiParam {Boolean} verbose Return verbose data + * + */ async function getRawMempool(req, res, next) { try { const { @@ -613,6 +686,20 @@ async function getRawMempool(req, res, next) { } } +/** + * @api {get} /blockchain/getTxOut/:txid/:n?mempool= Get Tx Out + * @apiName getTxOut + * @apiGroup Blockchain + * @apiDescription Returns details about an unspent transaction output. + * + * @apiExample Example usage: + * curl -X GET "http://localhost:3000/v3/blockchain/getTxOut/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33/0?mempool=false" -H "accept: application/json" + * + * @apiParam {String} txid Transaction id (required) + * @apiParam {Number} n Output number (required) + * @apiParam {Boolean} mempool Check mempool or not (optional) + * + */ // Returns details about an unspent transaction output. async function getTxOut(req, res, next) { try { @@ -665,7 +752,18 @@ async function getTxOut(req, res, next) { } } -// Returns a hex-encoded proof that 'txid' was included in a block. +/** + * @api {get} /blockchain/getTxOutProofSingle/:txid Get Tx Out Proof + * @apiName getTxOutProofSingle + * @apiGroup Blockchain + * @apiDescription Returns a hex-encoded proof that 'txid' was included in a block. + * + * @apiExample Example usage: + * curl -X GET "http://localhost:3000/v3/blockchain/getTxOutProofSingle/fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33" -H "accept: application/json" + * + * @apiParam {String} txid Transaction id (required) + * + */ async function getTxOutProofSingle(req, res, next) { try { // Validate input parameter