From aca97495258a8b66054b3f7d1a983175d556128f Mon Sep 17 00:00:00 2001 From: Gabriel Cardona Date: Thu, 28 Jun 2018 06:53:25 +0900 Subject: [PATCH] Remove FIXIE. --- routes/address.js | 42 ++++++++++++++++++++++++++++++------------ routes/block.js | 18 ++++++++++++------ routes/transaction.js | 10 ++++++---- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/routes/address.js b/routes/address.js index f4908a3e..ae4e4bdc 100644 --- a/routes/address.js +++ b/routes/address.js @@ -1,8 +1,6 @@ let express = require('express'); let router = express.Router(); let axios = require('axios'); -const request = require('request') -const fixieRequest = request.defaults({'proxy': process.env.FIXIE_URL}); let BITBOXCli = require('bitbox-cli/lib/bitbox-cli').default; let BITBOX = new BITBOXCli(); @@ -30,12 +28,16 @@ router.get('/details/:address', (req, res, next) => { path = `${path}?from=${req.query.from}&to=${req.query.to}`; } - fixieRequest(path, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(path) + .then((response) => { + let parsed = response.data; delete parsed.addrStr; parsed.legacyAddress = BITBOX.Address.toLegacyAddress(req.params.address); parsed.cashAddress = BITBOX.Address.toCashAddress(req.params.address); res.json(parsed); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } }); @@ -51,8 +53,9 @@ router.get('/utxo/:address', (req, res, next) => { final.push([]) }); - fixieRequest(`http://194.14.246.69/api/addrs/${addresses}/utxo`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/addrs/${addresses}/utxo`) + .then((response) => { + let parsed = response.data; parsed.forEach((data) => { data.legacyAddress = BITBOX.Address.toLegacyAddress(data.address); data.cashAddress = BITBOX.Address.toCashAddress(data.address); @@ -64,17 +67,24 @@ router.get('/utxo/:address', (req, res, next) => { }); }); res.json(final); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } catch(error) { - fixieRequest(`http://194.14.246.69/api/addr/${BITBOX.Address.toLegacyAddress(req.params.address)}/utxo`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/addr/${BITBOX.Address.toLegacyAddress(req.params.address)}/utxo`) + .then((response) => { + let parsed = response.data; parsed.forEach((data) => { delete data.address; data.legacyAddress = BITBOX.Address.toLegacyAddress(req.params.address); data.cashAddress = BITBOX.Address.toCashAddress(req.params.address); }); res.json(parsed); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } }); @@ -89,8 +99,9 @@ router.get('/unconfirmed/:address', (req, res, next) => { addresses.forEach((address) => { final.push([]) }); - fixieRequest(`http://194.14.246.69/api/addrs/${addresses}/utxo`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/addrs/${addresses}/utxo`) + .then((response) => { + let parsed = response.data; parsed.forEach((data) => { data.legacyAddress = BITBOX.Address.toLegacyAddress(data.address); data.cashAddress = BITBOX.Address.toCashAddress(data.address); @@ -104,11 +115,15 @@ router.get('/unconfirmed/:address', (req, res, next) => { } }); res.json(final); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } catch(error) { - fixieRequest(`http://194.14.246.69/api/addr/${BITBOX.Address.toLegacyAddress(req.params.address)}/utxo`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/addr/${BITBOX.Address.toLegacyAddress(req.params.address)}/utxo`) + .then((response) => { + let parsed = response.data; let unconfirmed = []; parsed.forEach((data) => { delete parsed.address; @@ -119,6 +134,9 @@ router.get('/unconfirmed/:address', (req, res, next) => { } }) res.json(unconfirmed); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } }); diff --git a/routes/block.js b/routes/block.js index c681b217..659e53f1 100644 --- a/routes/block.js +++ b/routes/block.js @@ -1,8 +1,6 @@ let express = require('express'); let router = express.Router(); let axios = require('axios'); -const request = require('request') -const fixieRequest = request.defaults({'proxy': process.env.FIXIE_URL}); let BITBOXCli = require('bitbox-cli/lib/bitbox-cli').default; let BITBOX = new BITBOXCli(); @@ -43,18 +41,26 @@ router.get('/details/:id', (req, res, next) => { } }) .then((response) => { - fixieRequest(`http://194.14.246.69/api/block/${response.data.result}`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/block/${response.data.result}`) + .then((response) => { + let parsed = response.data; res.json(parsed); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); }) .catch((error) => { res.send(error.response.data.error.message); }); } else { - fixieRequest(`http://194.14.246.69/api/block/${req.params.id}`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/block/${req.params.id}`) + .then((response) => { + let parsed = response.data; res.json(parsed); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } }); diff --git a/routes/transaction.js b/routes/transaction.js index d83cd056..00c2971f 100644 --- a/routes/transaction.js +++ b/routes/transaction.js @@ -1,8 +1,6 @@ let express = require('express'); let router = express.Router(); let axios = require('axios'); -const request = require('request') -const fixieRequest = request.defaults({'proxy': process.env.FIXIE_URL}); let BITBOXCli = require('bitbox-cli/lib/bitbox-cli').default; let BITBOX = new BITBOXCli(); @@ -25,8 +23,9 @@ router.get('/details/:txid', (req, res, next) => { })); } catch(error) { - fixieRequest(`http://194.14.246.69/api/tx/${req.params.txid}`, (err, result, body) => { - let parsed = JSON.parse(body); + axios.get(`http://194.14.246.69/api/tx/${req.params.txid}`) + .then((response) => { + let parsed = response.data; if(parsed && parsed.vin) { parsed.vin.forEach((vin) => { if(!vin.coinbase) { @@ -41,6 +40,9 @@ router.get('/details/:txid', (req, res, next) => { }); } res.json(parsed); + }) + .catch((error) => { + res.send(error.response.data.error.message); }); } });