Skip to content

Commit

Permalink
Add support for bignumbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Branco committed Aug 24, 2016
1 parent e7489c6 commit 37adb4c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Client {
this.request = _bluebird2.default.promisifyAll(_request2.default.defaults({
agentOptions: this.agentOptions,
baseUrl: `${ this.ssl.enabled ? 'https' : 'http' }://${ this.host }:${ this.port }`,
json: true,
json: false,
strictSSL: this.ssl.strict,
timeout: this.timeout
}), { multiArgs: true });
Expand Down Expand Up @@ -158,7 +158,7 @@ class Client {

return this.request.postAsync({
auth: _lodash2.default.pickBy(this.auth, _lodash2.default.identity),
body,
body: JSON.stringify(body),
uri: '/'
}).bind(this).then(this.parser.rpc);
}).asCallback(callback);
Expand Down
10 changes: 10 additions & 0 deletions dist/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _jsonBigintString = require('json-bigint-string');

var _jsonBigintString2 = _interopRequireDefault(_jsonBigintString);

var _rpcError = require('./errors/rpc-error');

var _rpcError2 = _interopRequireDefault(_rpcError);
Expand Down Expand Up @@ -77,6 +81,9 @@ class Parser {
throw new _rpcError2.default(response.statusCode);
}

// Parsing the body with custom parser to support BigNumbers.
body = _jsonBigintString2.default.parse(body);

if (!Array.isArray(body)) {
return get(body, { headers: this.headers, response });
}
Expand All @@ -103,6 +110,9 @@ class Parser {
let response = _ref6[0];
let body = _ref6[1];

// Parsing the body with custom parser to support BigNumbers.
body = _jsonBigintString2.default.parse(body);

if (body.error) {
throw new _rpcError2.default(body.error.code, body.error.message);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"bluebird": "^3.1.1",
"json-bigint-string": "^1.0.0",
"lodash": "^4.0.0",
"request": "^2.53.0",
"semver": "^5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Client {
this.request = Promise.promisifyAll(request.defaults({
agentOptions: this.agentOptions,
baseUrl: `${this.ssl.enabled ? 'https' : 'http'}://${this.host}:${this.port}`,
json: true,
json: false,
strictSSL: this.ssl.strict,
timeout: this.timeout
}), { multiArgs: true });
Expand Down Expand Up @@ -118,7 +118,7 @@ class Client {

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

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

/**
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.parse(body);

if (!Array.isArray(body)) {
return get(body, { headers: this.headers, response });
}
Expand All @@ -73,6 +77,9 @@ export default class Parser {
}

rest([response, body]) {
// Parsing the body with custom parser to support BigNumbers.
body = JSONBigInt.parse(body);

if (body.error) {
throw new RpcError(body.error.code, body.error.message);
}
Expand Down

0 comments on commit 37adb4c

Please sign in to comment.