Skip to content

Commit

Permalink
Remove FIXIE.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed Jun 27, 2018
1 parent 0903f9f commit aca9749
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
42 changes: 30 additions & 12 deletions routes/address.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);
});
}
});
Expand All @@ -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);
Expand All @@ -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);
});
}
});
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -119,6 +134,9 @@ router.get('/unconfirmed/:address', (req, res, next) => {
}
})
res.json(unconfirmed);
})
.catch((error) => {
res.send(error.response.data.error.message);
});
}
});
Expand Down
18 changes: 12 additions & 6 deletions routes/block.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);
});
}
});
Expand Down
10 changes: 6 additions & 4 deletions routes/transaction.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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) {
Expand All @@ -41,6 +40,9 @@ router.get('/details/:txid', (req, res, next) => {
});
}
res.json(parsed);
})
.catch((error) => {
res.send(error.response.data.error.message);
});
}
});
Expand Down

0 comments on commit aca9749

Please sign in to comment.