Skip to content

Commit

Permalink
Support bignumber response parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Branco committed Oct 18, 2016
1 parent 297baa2 commit 2540d58
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"bluebird": "^3.4.1",
"json-bigint": "^0.2.0",
"lodash": "^4.0.0",
"request": "^2.53.0",
"semver": "^5.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class Client {

return this.request.postAsync({
auth: _.pickBy(this.auth, _.identity),
body,
body: JSON.stringify(body),
json: false,
uri: '/'
})
.bind(this)
Expand Down
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import RpcError from './errors/rpc-error';
import _ from 'lodash';
import jsonBigInt from 'json-bigint';

/**
* Get response result and errors.
Expand Down Expand Up @@ -52,6 +53,9 @@ export default class Parser {
throw new RpcError(response.statusCode);
}

// Parsing the body with custom parser to support BigNumbers.
body = jsonBigInt({ storeAsString: true }).parse(body);

if (!Array.isArray(body)) {
return get(body, { headers: this.headers, response });
}
Expand Down
2 changes: 1 addition & 1 deletion test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('Client', () => {
it('should return the proof-of-work difficulty', async () => {
const difficulty = await new Client(config.bitcoind).getDifficulty();

difficulty.should.be.a.Number();
difficulty.should.be.a.String();
});
});

Expand Down

0 comments on commit 2540d58

Please sign in to comment.