Skip to content

Commit

Permalink
Refactor to use async/await.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cardona committed Aug 24, 2018
1 parent 342d671 commit 839657c
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 465 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let clone = require('git-clone');
let cmd = require('node-cmd');

program
.version('1.5.12');
.version('1.6.0');

program
.command('new <name>')
Expand All @@ -34,7 +34,7 @@ program

let config;
let environment = fetchOption('environment=development', config, options);
let restURL = fetchOption('restURL=https://rest.bitcoin.com/v1/', config, options);
let restURL = fetchOption('restURL=https://trest.bitcoin.com/v1/', config, options);

if(options && options.scaffold) {
let scaffold = options.scaffold.toLowerCase();
Expand Down
30 changes: 18 additions & 12 deletions lib/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,39 +145,45 @@ var Address = function () {
}
}, {
key: 'details',
value: function details(address) {
value: async function details(address) {
if (typeof address !== 'string') {
address = JSON.stringify(address);
}
return _axios2.default.get(this.restURL + 'address/details/' + address).then(function (response) {

try {
var response = await _axios2.default.get(this.restURL + 'address/details/' + address);
return response.data;
}).catch(function (error) {
} catch (error) {
return JSON.stringify(error.response.data.error.message);
});
}
}
}, {
key: 'utxo',
value: function utxo(address) {
value: async function utxo(address) {
if (typeof address !== 'string') {
address = JSON.stringify(address);
}
return _axios2.default.get(this.restURL + 'address/utxo/' + address).then(function (response) {

try {
var response = await _axios2.default.get(this.restURL + 'address/utxo/' + address);
return response.data;
}).catch(function (error) {
} catch (error) {
return JSON.stringify(error.response.data.error.message);
});
}
}
}, {
key: 'unconfirmed',
value: function unconfirmed(address) {
value: async function unconfirmed(address) {
if (typeof address !== 'string') {
address = JSON.stringify(address);
}
return _axios2.default.get(this.restURL + 'address/unconfirmed/' + address).then(function (response) {

try {
var response = await _axios2.default.get(this.restURL + 'address/unconfirmed/' + address);
return response.data;
}).catch(function (error) {
} catch (error) {
return JSON.stringify(error.response.data.error.message);
});
}
}
}]);

Expand Down
9 changes: 5 additions & 4 deletions lib/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ var Block = function () {

_createClass(Block, [{
key: 'details',
value: function details(id) {
return _axios2.default.get(this.restURL + 'block/details/' + id).then(function (response) {
value: async function details(id) {
try {
var response = await _axios2.default.get(this.restURL + 'block/details/' + id);
return response.data;
}).catch(function (error) {
} catch (error) {
return JSON.stringify(error.response.data.error.message);
});
}
}
}]);

Expand Down
Loading

0 comments on commit 839657c

Please sign in to comment.