Skip to content

Commit

Permalink
Call bitcoin.com insight api directly to avoid rate limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed Jul 19, 2018
1 parent 0d10ee3 commit 7d3f67a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rest-cloud",
"version": "1.2.0",
"version": "1.2.1",
"private": true,
"scripts": {
"start": "node ./bin/www",
Expand Down
17 changes: 13 additions & 4 deletions routes/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ let router = express.Router();
let axios = require('axios');

let BITBOXCli = require('bitbox-cli/lib/bitbox-cli').default;
let BITBOX = new BITBOXCli();
let BITBOX = new BITBOXCli({
restURL: "http://localhost:3000/v1/"
});

router.get('/', (req, res, next) => {
res.json({ status: 'address' });
Expand All @@ -14,11 +16,18 @@ router.get('/details/:address', (req, res, next) => {
let addresses = JSON.parse(req.params.address);
let result = [];
addresses = addresses.map((address) => {
return BITBOX.Address.details(address)
let path = `${process.env.BITCOINCOM_BASEURL}addr/${BITBOX.Address.toLegacyAddress(address)}`;
return axios.get(path)
})
axios.all(addresses)
.then(axios.spread((...spread) => {
result.push(...spread);
.then(axios.spread((...args) => {
for (let i = 0; i < args.length; i++) {
let parsed = args[i].data;
parsed.legacyAddress = BITBOX.Address.toLegacyAddress(parsed.addrStr);
parsed.cashAddress = BITBOX.Address.toCashAddress(parsed.addrStr);
delete parsed.addrStr;
result.push(parsed);
}
res.json(result);
}));
}
Expand Down

0 comments on commit 7d3f67a

Please sign in to comment.