Skip to content

Commit

Permalink
Merge pull request #108 from Bitcoin-com/stage
Browse files Browse the repository at this point in the history
1.10.6
  • Loading branch information
cgcardona authored Nov 7, 2018
2 parents fe117d8 + c304dcf commit b7cd751
Show file tree
Hide file tree
Showing 14 changed files with 1,184 additions and 149 deletions.
4 changes: 2 additions & 2 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ app.use("/", indexV2);
app.use("/" + v2prefix + "/" + "health-check", healthCheckV2);
app.use("/" + v2prefix + "/" + "address", addressV2.router);
app.use("/" + v2prefix + "/" + "blockchain", blockchainV2);
app.use("/" + v2prefix + "/" + "block", blockV2);
app.use("/" + v2prefix + "/" + "control", controlV2);
app.use("/" + v2prefix + "/" + "block", blockV2.router);
app.use("/" + v2prefix + "/" + "control", controlV2.router);
app.use("/" + v2prefix + "/" + "generating", generatingV2);
app.use("/" + v2prefix + "/" + "mining", miningV2);
app.use("/" + v2prefix + "/" + "network", networkV2);
Expand Down
59 changes: 33 additions & 26 deletions dist/routes/v2/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,33 @@ while (i < 4) {
});
i++;
}
router.get("/", config.blockRateLimit1, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
res.json({ status: "block" });
return [2 /*return*/];
});
}); });
router.get("/detailsByHash/:hash", config.blockRateLimit2, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
var response, parsed, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, axios_1.default.get(process.env.BITCOINCOM_BASEURL + "block/" + req.params.hash)];
case 1:
response = _a.sent();
parsed = response.data;
res.json(parsed);
return [3 /*break*/, 3];
case 2:
error_1 = _a.sent();
res.status(500);
return [2 /*return*/, res.send(error_1)];
case 3: return [2 /*return*/];
}
router.get("/", config.blockRateLimit1, root);
router.get("/detailsByHash/:hash", config.blockRateLimit2, detailsByHash);
function root(req, res, next) {
return res.json({ status: "block" });
}
function detailsByHash(req, res, next) {
return __awaiter(this, void 0, void 0, function () {
var response, parsed, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, axios_1.default.get(process.env.BITCOINCOM_BASEURL + "block/" + req.params.hash)];
case 1:
response = _a.sent();
parsed = response.data;
res.json(parsed);
return [3 /*break*/, 3];
case 2:
error_1 = _a.sent();
res.status(500);
return [2 /*return*/, res.send(error_1)];
case 3: return [2 /*return*/];
}
});
});
}); });
}
router.get("/detailsByHeight/:height", config.blockRateLimit2, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
var requestConfig;
var _this = this;
Expand Down Expand Up @@ -127,4 +128,10 @@ router.get("/detailsByHeight/:height", config.blockRateLimit2, function (req, re
return [2 /*return*/];
});
}); });
module.exports = router;
module.exports = {
router: router,
testableComponents: {
root: root,
detailsByHash: detailsByHash
}
};
81 changes: 50 additions & 31 deletions dist/routes/v2/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var express = require("express");
var router = express.Router();
var axios_1 = require("axios");
var RateLimit = require("express-rate-limit");
var logger = require("./logging.js");
// Used for processing error messages before sending them to the user.
var util = require("util");
util.inspect.defaultOptions = { depth: 3 };
console.log("process.env.RPC_BASEURL: " + process.env.RPC_BASEURL);
var BitboxHTTP = axios_1.default.create({
baseURL: process.env.RPC_BASEURL
});
Expand Down Expand Up @@ -77,36 +81,45 @@ var requestConfig = {
jsonrpc: "1.0"
}
};
router.get("/", config.controlRateLimit1, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
res.json({ status: "control" });
return [2 /*return*/];
});
}); });
router.get("/getInfo", config.controlRateLimit2, function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
var response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
requestConfig.data.id = "getinfo";
requestConfig.data.method = "getinfo";
requestConfig.data.params = [];
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, BitboxHTTP(requestConfig)];
case 2:
response = _a.sent();
res.json(response.data.result);
return [3 /*break*/, 4];
case 3:
error_1 = _a.sent();
res.status(500).send(error_1.response.data.error);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
router.get("/", config.controlRateLimit1, root);
router.get("/getInfo", config.controlRateLimit2, getInfo);
function root(req, res, next) {
return res.json({ status: "control" });
}
function getInfo(req, res, next) {
return __awaiter(this, void 0, void 0, function () {
var response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
requestConfig.data.id = "getinfo";
requestConfig.data.method = "getinfo";
requestConfig.data.params = [];
//console.log(`requestConfig: ${util.inspect(requestConfig)}`)
//console.log(`requestConfig.data.params: ${util.inspect(requestConfig.data.params)}`)
//console.log(`BitboxHTTP: ${util.inspect(BitboxHTTP)}`)
console.log("BitboxHTTP.defaults.baseURL: " + BitboxHTTP.defaults.baseURL);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, BitboxHTTP(requestConfig)];
case 2:
response = _a.sent();
res.json(response.data.result);
return [3 /*break*/, 4];
case 3:
error_1 = _a.sent();
// Write out error to error log.
logger.error("Error in address/details: ", error_1);
res.status(500);
if (error_1.response && error_1.response.data && error_1.response.data.error)
return [2 /*return*/, res.json({ error: error_1.response.data.error })];
return [2 /*return*/, res.json({ error: util.inspect(error_1) })];
case 4: return [2 /*return*/];
}
});
});
}); });
}
// router.get('/getMemoryInfo', (req, res, next) => {
// BitboxHTTP({
// method: 'post',
Expand Down Expand Up @@ -143,4 +156,10 @@ router.get("/getInfo", config.controlRateLimit2, function (req, res, next) { ret
// }, (err) => { console.log(err);
// });
// });
module.exports = router;
module.exports = {
router: router,
testableComponents: {
root: root,
getInfo: getInfo
}
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "rest.bitcoin.com",
"version": "1.10.5",
"version": "1.10.6",
"description": "REST API for Bitcoin.com's Cloud",
"author": "Gabriel Cardona @ Bitcoin.com",
"license": "MIT",
"scripts": {
"start": "node ./dist/app.js",
"build": "node ./node_modules/gulp/bin/gulp.js build && ./node_modules/typescript/bin/tsc",
"dev": "nodemon ./dist/app.js",
"test": "npm run build && nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/",
"test-v1": "nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/",
"test-v2": "nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v2/",
"test": "npm run test-v1",
"test-v1": "npm run build && nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/",
"test-v2": "export NETWORK=testnet && npm run build && nyc --reporter=text mocha --require babel-core/register test/v2/",
"test-v2:blockchain": "nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v2/blockchain",
"test-all": "TEST=integration nyc --reporter=text mocha --require babel-core/register --timeout 15000 test/v1/ test/v2/",
"coverage": "nyc report --reporter=text-lcov | coveralls",
Expand Down Expand Up @@ -63,7 +63,7 @@
"node-mocks-http": "^1.7.0",
"nodemon": "^1.18.1",
"nyc": "^11.6.0",
"pandacash-cli": "^0.4.0",
"pandacash-core": "^0.1.0",
"prettier": "^1.14.2",
"sinon": "^6.3.4",
"typescript": "^3.1.4"
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ app.use("/", indexV2)
app.use(`/${v2prefix}/` + `health-check`, healthCheckV2)
app.use(`/${v2prefix}/` + `address`, addressV2.router)
app.use(`/${v2prefix}/` + `blockchain`, blockchainV2)
app.use(`/${v2prefix}/` + `block`, blockV2)
app.use(`/${v2prefix}/` + `control`, controlV2)
app.use(`/${v2prefix}/` + `block`, blockV2.router)
app.use(`/${v2prefix}/` + `control`, controlV2.router)
app.use(`/${v2prefix}/` + `generating`, generatingV2)
app.use(`/${v2prefix}/` + `mining`, miningV2)
app.use(`/${v2prefix}/` + `network`, networkV2)
Expand Down
8 changes: 4 additions & 4 deletions src/public/bitcoin-com-rest-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@
"in": "path",
"description": "The identifier of the managed tokens to lookup",
"required": true,
"example": 3,
"example": 220,
"schema": {
"type": "number"
}
Expand Down Expand Up @@ -1655,7 +1655,7 @@
"in": "path",
"description": "The hash of the transaction to retrieve payload",
"required": true,
"example": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
"example": "d7dbbd16350ca13a1ce7fc67eb7fb411debca23ce01c3ae0e3e44498f1f6c3d0",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -1787,7 +1787,7 @@
"in": "path",
"description": "The hash of the transaction to lookup",
"required": true,
"example": "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
"example": "d7dbbd16350ca13a1ce7fc67eb7fb411debca23ce01c3ae0e3e44498f1f6c3d0",
"schema": {
"type": "string"
}
Expand Down Expand Up @@ -2106,7 +2106,7 @@
"in": "path",
"description": "The identifier of the tokens to grant",
"required": true,
"example": 51,
"example": 220,
"schema": {
"type": "number"
}
Expand Down
51 changes: 32 additions & 19 deletions src/routes/v2/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,33 @@ while (i < 4) {
i++
}

router.get("/", config.blockRateLimit1, async (req, res, next) => {
res.json({ status: "block" })
})
router.get("/", config.blockRateLimit1, root)
router.get("/detailsByHash/:hash", config.blockRateLimit2, detailsByHash)

router.get(
"/detailsByHash/:hash",
config.blockRateLimit2,
async (req, res, next) => {
try {
const response = await axios.get(
`${process.env.BITCOINCOM_BASEURL}block/${req.params.hash}`
)
const parsed = response.data
res.json(parsed)
} catch (error) {
res.status(500)
return res.send(error)
}
function root(
req: express.Request,
res: express.Response,
next: express.NextFunction
) {
return res.json({ status: "block" })
}

async function detailsByHash(
req: express.Request,
res: express.Response,
next: express.NextFunction
) {
try {
const response = await axios.get(
`${process.env.BITCOINCOM_BASEURL}block/${req.params.hash}`
)
const parsed = response.data
res.json(parsed)
} catch (error) {
res.status(500)
return res.send(error)
}
)
}

router.get(
"/detailsByHeight/:height",
Expand Down Expand Up @@ -91,4 +98,10 @@ router.get(
}
)

module.exports = router
module.exports = {
router,
testableComponents: {
root,
detailsByHash
}
}
Loading

0 comments on commit b7cd751

Please sign in to comment.