From 398d8090e90bd8b0be8b021709b0b932d9c4725f Mon Sep 17 00:00:00 2001 From: Gabriel Cardona Date: Mon, 21 May 2018 09:36:31 -0700 Subject: [PATCH 1/4] `BlockCount`, `BlockHash`, `BlockHeader` --- public/bitbox-rest-v1.json | 75 +++++++++++++++++++++++++++++++++----- routes/blockchain.js | 2 +- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/public/bitbox-rest-v1.json b/public/bitbox-rest-v1.json index c22c5678..4f3db4ae 100644 --- a/public/bitbox-rest-v1.json +++ b/public/bitbox-rest-v1.json @@ -360,10 +360,10 @@ ], "responses": { "200": { - "description": "successful operation" - }, - "400": { - "description": "Invalid tag value" + "description": "successful operation", + "schema": { + "$ref": "#/definitions/BlockCount" + } } } } @@ -390,10 +390,10 @@ ], "responses": { "200": { - "description": "successful operation" - }, - "400": { - "description": "Invalid tag value" + "description": "successful operation", + "schema": { + "$ref": "#/definitions/BlockHash" + } } } } @@ -428,7 +428,10 @@ ], "responses": { "200": { - "description": "successful operation" + "description": "successful operation", + "schema": { + "$ref": "#/definitions/BlockHeader" + } }, "400": { "description": "Invalid tag value" @@ -1761,6 +1764,60 @@ } } } + }, + "BlockCount": { + "type": "number" + }, + "BlockHash": { + "type": "string" + }, + "BlockHeader": { + "type": "object", + "properties": { + "hash": { + "type": "string" + }, + "confirmations": { + "type": "number" + }, + "height": { + "type": "number" + }, + "version": { + "type": "number" + }, + "versionHex": { + "type": "string" + }, + "merkleroot": { + "type": "string" + }, + "time": { + "type": "number" + }, + "mediantime": { + "type": "number" + }, + "nonce": { + "type": "number" + }, + "bits": { + "type": "string" + }, + "difficulty": { + "type": "number", + "format": "float" + }, + "chainwork": { + "type": "string" + }, + "previousblockhash": { + "type": "string" + }, + "nextblockhash": { + "type": "string" + } + } } } } diff --git a/routes/blockchain.js b/routes/blockchain.js index 3b39d94c..1716f013 100644 --- a/routes/blockchain.js +++ b/routes/blockchain.js @@ -65,7 +65,7 @@ router.get('/getBlockHeader/:hash', function(req, res, next) { } BITBOX.Blockchain.getBlockHeader(req.params.hash, verbose) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); From f7696aabaec0499497599e57b66c24df78d98bb9 Mon Sep 17 00:00:00 2001 From: Gabriel Cardona Date: Mon, 21 May 2018 09:37:30 -0700 Subject: [PATCH 2/4] v --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc25062a..17436375 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rest-cloud", - "version": "0.1.6", + "version": "0.1.7", "private": true, "scripts": { "start": "node ./bin/www" From d0286d5659c466b355c2f6b8968db92d69369910 Mon Sep 17 00:00:00 2001 From: Gabriel Cardona Date: Mon, 21 May 2018 09:44:17 -0700 Subject: [PATCH 3/4] error handling --- public/bitbox-rest-v1.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public/bitbox-rest-v1.json b/public/bitbox-rest-v1.json index 4f3db4ae..142900bb 100644 --- a/public/bitbox-rest-v1.json +++ b/public/bitbox-rest-v1.json @@ -394,6 +394,13 @@ "schema": { "$ref": "#/definitions/BlockHash" } + }, + "400": { + "description": "Block not found", + "schema": { + "status": 500, + "message": "Block not found" + } } } } @@ -434,7 +441,11 @@ } }, "400": { - "description": "Invalid tag value" + "description": "Block not found", + "schema": { + "status": 500, + "message": "Block not found" + } } } } From 507b57a52401e21c673da587a3a701c0ad808b3b Mon Sep 17 00:00:00 2001 From: Gabriel Cardona Date: Mon, 21 May 2018 10:31:34 -0700 Subject: [PATCH 4/4] Difficulty and MempoolInfo --- package.json | 2 +- public/bitbox-rest-v1.json | 39 ++++++++++++++++++++++++++++++++------ routes/blockchain.js | 24 +++++++++++------------ 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 17436375..74a8ed73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rest-cloud", - "version": "0.1.7", + "version": "0.1.8", "private": true, "scripts": { "start": "node ./bin/www" diff --git a/public/bitbox-rest-v1.json b/public/bitbox-rest-v1.json index 142900bb..a6b70a74 100644 --- a/public/bitbox-rest-v1.json +++ b/public/bitbox-rest-v1.json @@ -481,7 +481,10 @@ ], "responses": { "200": { - "description": "successful operation" + "description": "successful operation", + "schema": { + "$ref": "#/definitions/Difficulty" + } } } } @@ -605,10 +608,10 @@ ], "responses": { "200": { - "description": "successful operation" - }, - "400": { - "description": "Invalid tag value" + "description": "successful operation", + "schema": { + "$ref": "#/definitions/MempoolInfo" + } } } } @@ -1829,6 +1832,30 @@ "type": "string" } } - } + }, + "Difficulty": { + "type": "number", + "format": "float" + }, + "MempoolInfo": { + "type": "object", + "properties": { + "size": { + "type": "number" + }, + "bytes": { + "type": "number" + }, + "usage": { + "type": "number" + }, + "maxmempool": { + "type": "number" + }, + "mempoolminfee": { + "type": "number" + }, + } + }, } } diff --git a/routes/blockchain.js b/routes/blockchain.js index 1716f013..8a4250c3 100644 --- a/routes/blockchain.js +++ b/routes/blockchain.js @@ -73,7 +73,7 @@ router.get('/getBlockHeader/:hash', function(req, res, next) { router.get('/getChainTips', function(req, res, next) { BITBOX.Blockchain.getChainTips() .then((result) => { - res.json({result: result}); + res.json(result); }, (err) => { console.log(err); }); }); @@ -93,7 +93,7 @@ router.get('/getMempoolAncestors/:txid', function(req, res, next) { } BITBOX.Blockchain.getMempoolAncestors(req.params.txid, verbose) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -105,7 +105,7 @@ router.get('/getMempoolDescendants/:txid', function(req, res, next) { } BITBOX.Blockchain.getMempoolDescendants(req.params.txid, verbose) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -113,7 +113,7 @@ router.get('/getMempoolDescendants/:txid', function(req, res, next) { router.get('/getMempoolEntry/:txid', function(req, res, next) { BITBOX.Blockchain.getMempoolEntry(req.params.txid) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -121,7 +121,7 @@ router.get('/getMempoolEntry/:txid', function(req, res, next) { router.get('/getMempoolInfo', function(req, res, next) { BITBOX.Blockchain.getMempoolInfo() .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -133,7 +133,7 @@ router.get('/getRawMempool', function(req, res, next) { } BITBOX.Blockchain.getRawMempool(verbose) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -145,7 +145,7 @@ router.get('/getTxOut/:txid/:n', function(req, res, next) { } BITBOX.Blockchain.getTxOut(req.params.txid, parseInt(req.params.n), include_mempool) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -154,7 +154,7 @@ router.get('/getTxOutProof/:txids', function(req, res, next) { // TODO finish this BITBOX.Blockchain.getTxOutProof(req.params.txids) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -162,7 +162,7 @@ router.get('/getTxOutProof/:txids', function(req, res, next) { router.get('/getTxOutSetInfo', function(req, res, next) { BITBOX.Blockchain.getTxOutSetInfo() .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -170,7 +170,7 @@ router.get('/getTxOutSetInfo', function(req, res, next) { router.get('/preciousBlock/:hash', function(req, res, next) { BITBOX.Blockchain.preciousBlock(req.params.hash) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -178,7 +178,7 @@ router.get('/preciousBlock/:hash', function(req, res, next) { router.post('/pruneBlockchain/:height', function(req, res, next) { BITBOX.Blockchain.pruneBlockchain(req.params.height) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); }); @@ -195,7 +195,7 @@ router.get('/verifyChain', function(req, res, next) { router.get('/verifyTxOutProof/:proof', function(req, res, next) { BITBOX.Blockchain.verifyTxOutProof(req.params.proof) .then((result) => { - res.json({ result: result }); + res.json(result); }, (err) => { console.log(err); }); });