Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobranco committed Feb 11, 2019
1 parent aad875c commit bd89a29
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 54 deletions.
16 changes: 13 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Changelog

## [2.0.0](https://github.com/ruimarinho/bitcoin-core/tree/2.0.0) (2017-11-27)
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.2.0...2.0.0)
## [2.1.0](https://github.com/ruimarinho/bitcoin-core/tree/2.1.0) (2019-02-11)
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v2.0.0...2.1.0)

**Merged pull requests:**

- Add support for json extension in rest endpoint [\#78](https://github.com/ruimarinho/bitcoin-core/pull/78) ([pedrobranco](https://github.com/pedrobranco))
- Fix response log obfuscation [\#64](https://github.com/ruimarinho/bitcoin-core/pull/64) ([pedrobranco](https://github.com/pedrobranco))
- Fix obfuscator with named parameters [\#62](https://github.com/ruimarinho/bitcoin-core/pull/62) ([pedrobranco](https://github.com/pedrobranco))
- Add support for multiwallet [\#45](https://github.com/ruimarinho/bitcoin-core/pull/45) ([ruimarinho](https://github.com/ruimarinho))

## [v2.0.0](https://github.com/ruimarinho/bitcoin-core/tree/v2.0.0) (2017-11-27)
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.2.0...v2.0.0)

**Merged pull requests:**

Expand All @@ -15,7 +25,6 @@
- Add support for [email protected] methods [\#36](https://github.com/ruimarinho/bitcoin-core/pull/36) ([joaopaulofonseca](https://github.com/joaopaulofonseca))
- Add support for bitcoin 0.13.2 [\#24](https://github.com/ruimarinho/bitcoin-core/pull/24) ([pedrobranco](https://github.com/pedrobranco))
- Fix mempool naming inconsistency in getRawMempool method name [\#22](https://github.com/ruimarinho/bitcoin-core/pull/22) ([ruimarinho](https://github.com/ruimarinho))
- Add support for bignumbers [\#17](https://github.com/ruimarinho/bitcoin-core/pull/17) ([pedrobranco](https://github.com/pedrobranco))

## [v1.2.0](https://github.com/ruimarinho/bitcoin-core/tree/v1.2.0) (2017-02-12)
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.1.0...v1.2.0)
Expand All @@ -24,6 +33,7 @@

- Pin docker image to 0.13.0 to avoid failing tests on newer versions [\#21](https://github.com/ruimarinho/bitcoin-core/pull/21) ([pedrobranco](https://github.com/pedrobranco))
- Add logging to all requests [\#19](https://github.com/ruimarinho/bitcoin-core/pull/19) ([pedrobranco](https://github.com/pedrobranco))
- Add support for bignumbers [\#17](https://github.com/ruimarinho/bitcoin-core/pull/17) ([pedrobranco](https://github.com/pedrobranco))

## [v1.1.0](https://github.com/ruimarinho/bitcoin-core/tree/v1.1.0) (2016-09-19)
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.0.0...v1.1.0)
Expand Down
74 changes: 42 additions & 32 deletions dist/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Client {
ssl = false,
timeout = 30000,
username,
version
version,
wallet
} = {}) {
if (!_lodash.default.has(networks, network)) {
throw new Error(`Invalid network name "${network}"`, {
Expand All @@ -86,13 +87,12 @@ class Client {
this.host = host;
this.password = password;
this.port = port || networks[network];
this.timeout = timeout;
this.ssl = {
enabled: _lodash.default.get(ssl, 'enabled', ssl),
strict: _lodash.default.get(ssl, 'strict', _lodash.default.get(ssl, 'enabled', ssl))
}; // Find unsupported methods according to version.

let unsupported = [];
};
this.timeout = timeout;
this.wallet = wallet; // Version handling.

if (version) {
// Capture X.Y.Z when X.Y.Z.A is passed to support oddly formatted Bitcoin Core
Expand All @@ -107,9 +107,19 @@ class Client {

[version] = result;
this.hasNamedParametersSupport = _semver.default.satisfies(version, '>=0.14.0');
unsupported = _lodash.default.chain(_methods.default).pickBy(method => !_semver.default.satisfies(version, method.version)).keys().invokeMap(String.prototype.toLowerCase).value();
}

this.version = version;
this.methods = _lodash.default.transform(_methods.default, (result, method, name) => {
result[_lodash.default.toLower(name)] = {
features: _lodash.default.transform(method.features, (result, constraint, name) => {
result[name] = {
supported: version ? _semver.default.satisfies(version, constraint) : true
};
}, {}),
supported: version ? _semver.default.satisfies(version, method.version) : true
};
}, {});
const request = (0, _requestLogger.default)(logger);
this.request = _bluebird.default.promisifyAll(request.defaults({
agentOptions: this.agentOptions,
Expand All @@ -120,7 +130,7 @@ class Client {
multiArgs: true
});
this.requester = new _requester.default({
unsupported,
methods: this.methods,
version
});
this.parser = new _parser.default({
Expand All @@ -135,40 +145,44 @@ class Client {
command(...args) {
let body;
let callback;
let multiwallet;
let [input, ...parameters] = args; // eslint-disable-line prefer-const

let parameters = _lodash.default.tail(args);
const lastArg = _lodash.default.last(parameters);

const input = _lodash.default.head(args);

const lastArg = _lodash.default.last(args);
const isBatch = Array.isArray(input);

if (_lodash.default.isFunction(lastArg)) {
callback = lastArg;
parameters = _lodash.default.dropRight(parameters);
}

if (this.hasNamedParametersSupport && parameters.length === 1 && _lodash.default.isPlainObject(parameters[0])) {
parameters = parameters[0];
if (isBatch) {
multiwallet = _lodash.default.some(input, command => {
return _lodash.default.get(this.methods[command.method], 'features.multiwallet.supported', false) === true;
});
body = input.map((method, index) => this.requester.prepare({
method: method.method,
parameters: method.parameters,
suffix: index
}));
} else {
if (this.hasNamedParametersSupport && parameters.length === 1 && _lodash.default.isPlainObject(parameters[0])) {
parameters = parameters[0];
}

multiwallet = _lodash.default.get(this.methods[input], 'features.multiwallet.supported', false) === true;
body = this.requester.prepare({
method: input,
parameters
});
}

return _bluebird.default.try(() => {
if (Array.isArray(input)) {
body = input.map((method, index) => this.requester.prepare({
method: method.method,
parameters: method.parameters,
suffix: index
}));
} else {
body = this.requester.prepare({
method: input,
parameters
});
}

return this.request.postAsync({
auth: _lodash.default.pickBy(this.auth, _lodash.default.identity),
body: JSON.stringify(body),
uri: '/'
uri: `${multiwallet && this.wallet ? `/wallet/${this.wallet}` : '/'}`
}).bind(this).then(this.parser.rpc);
}).asCallback(callback);
}
Expand Down Expand Up @@ -217,10 +231,6 @@ class Client {
extension = 'json'
} = {}], callback] = source(...args);
return _bluebird.default.try(() => {
if (!_lodash.default.includes(['bin', 'hex'], extension)) {
throw new Error(`Extension "${extension}" is not supported`);
}

return this.request.getAsync({
encoding: extension === 'bin' ? null : undefined,
url: `/rest/headers/${count}/${hash}.${extension}`
Expand Down Expand Up @@ -289,7 +299,7 @@ class Client {
*/


_lodash.default.forOwn(_methods.default, (range, method) => {
_lodash.default.forOwn(_methods.default, (options, method) => {
Client.prototype[method] = _lodash.default.partial(Client.prototype.command, method.toLowerCase());
});
/**
Expand Down
27 changes: 18 additions & 9 deletions dist/src/logging/request-obfuscator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,30 @@ function obfuscateResponse(request, instance) {
return;
}

if (!(0, _lodash.get)(request, 'response.body')) {
if (!request.body) {
return;
}

if ((0, _lodash.get)(request, `response.headers['content-type']`) === 'application/octet-stream') {
request.response.body = '******';
if ((0, _lodash.get)(request, `headers['content-type']`) === 'application/octet-stream') {
request.body = '******';
return;
}

if (!instance.body) {
return;
}

request.body = JSON.parse(request.body);
const requestBody = JSON.parse(instance.body);

if ((0, _lodash.isArray)(request.response.body)) {
if ((0, _lodash.isArray)(request.body)) {
const methodsById = (0, _lodash.mapKeys)(requestBody, method => method.id);
request.response.body = (0, _lodash.map)(request.response.body, request => obfuscateResponseBody(request, methodsById[request.id].method));
return;
request.body = (0, _lodash.map)(request.body, request => obfuscateResponseBody(request, methodsById[request.id].method));
} else {
request.body = obfuscateResponseBody(request.body, requestBody.method);
}

request.response.body = obfuscateResponseBody(request.response.body, requestBody.method);
request.body = JSON.stringify(request.body);
}
/**
* Obfuscate the request body.
Expand All @@ -79,8 +81,15 @@ function obfuscateRequestBody(body) {
return body;
}

body.params = method(body.params);
return body;
if ((0, _lodash.isPlainObject)(body.params)) {
return (0, _lodash.assign)(body, {
params: method.named(body.params)
});
}

return (0, _lodash.assign)(body, {
params: method.default(body.params)
});
}
/**
* Obfuscate the request.
Expand Down
Loading

0 comments on commit bd89a29

Please sign in to comment.