Skip to content

Commit bd89a29

Browse files
committed
Release 2.1.0
1 parent aad875c commit bd89a29

File tree

6 files changed

+359
-54
lines changed

6 files changed

+359
-54
lines changed

CHANGELOG.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Changelog
22

3-
## [2.0.0](https://github.com/ruimarinho/bitcoin-core/tree/2.0.0) (2017-11-27)
4-
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.2.0...2.0.0)
3+
## [2.1.0](https://github.com/ruimarinho/bitcoin-core/tree/2.1.0) (2019-02-11)
4+
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v2.0.0...2.1.0)
5+
6+
**Merged pull requests:**
7+
8+
- Add support for json extension in rest endpoint [\#78](https://github.com/ruimarinho/bitcoin-core/pull/78) ([pedrobranco](https://github.com/pedrobranco))
9+
- Fix response log obfuscation [\#64](https://github.com/ruimarinho/bitcoin-core/pull/64) ([pedrobranco](https://github.com/pedrobranco))
10+
- Fix obfuscator with named parameters [\#62](https://github.com/ruimarinho/bitcoin-core/pull/62) ([pedrobranco](https://github.com/pedrobranco))
11+
- Add support for multiwallet [\#45](https://github.com/ruimarinho/bitcoin-core/pull/45) ([ruimarinho](https://github.com/ruimarinho))
12+
13+
## [v2.0.0](https://github.com/ruimarinho/bitcoin-core/tree/v2.0.0) (2017-11-27)
14+
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.2.0...v2.0.0)
515

616
**Merged pull requests:**
717

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

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

2534
- 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))
2635
- Add logging to all requests [\#19](https://github.com/ruimarinho/bitcoin-core/pull/19) ([pedrobranco](https://github.com/pedrobranco))
36+
- Add support for bignumbers [\#17](https://github.com/ruimarinho/bitcoin-core/pull/17) ([pedrobranco](https://github.com/pedrobranco))
2737

2838
## [v1.1.0](https://github.com/ruimarinho/bitcoin-core/tree/v1.1.0) (2016-09-19)
2939
[Full Changelog](https://github.com/ruimarinho/bitcoin-core/compare/v1.0.0...v1.1.0)

dist/src/index.js

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class Client {
6868
ssl = false,
6969
timeout = 30000,
7070
username,
71-
version
71+
version,
72+
wallet
7273
} = {}) {
7374
if (!_lodash.default.has(networks, network)) {
7475
throw new Error(`Invalid network name "${network}"`, {
@@ -86,13 +87,12 @@ class Client {
8687
this.host = host;
8788
this.password = password;
8889
this.port = port || networks[network];
89-
this.timeout = timeout;
9090
this.ssl = {
9191
enabled: _lodash.default.get(ssl, 'enabled', ssl),
9292
strict: _lodash.default.get(ssl, 'strict', _lodash.default.get(ssl, 'enabled', ssl))
93-
}; // Find unsupported methods according to version.
94-
95-
let unsupported = [];
93+
};
94+
this.timeout = timeout;
95+
this.wallet = wallet; // Version handling.
9696

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

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

112+
this.version = version;
113+
this.methods = _lodash.default.transform(_methods.default, (result, method, name) => {
114+
result[_lodash.default.toLower(name)] = {
115+
features: _lodash.default.transform(method.features, (result, constraint, name) => {
116+
result[name] = {
117+
supported: version ? _semver.default.satisfies(version, constraint) : true
118+
};
119+
}, {}),
120+
supported: version ? _semver.default.satisfies(version, method.version) : true
121+
};
122+
}, {});
113123
const request = (0, _requestLogger.default)(logger);
114124
this.request = _bluebird.default.promisifyAll(request.defaults({
115125
agentOptions: this.agentOptions,
@@ -120,7 +130,7 @@ class Client {
120130
multiArgs: true
121131
});
122132
this.requester = new _requester.default({
123-
unsupported,
133+
methods: this.methods,
124134
version
125135
});
126136
this.parser = new _parser.default({
@@ -135,40 +145,44 @@ class Client {
135145
command(...args) {
136146
let body;
137147
let callback;
148+
let multiwallet;
149+
let [input, ...parameters] = args; // eslint-disable-line prefer-const
138150

139-
let parameters = _lodash.default.tail(args);
151+
const lastArg = _lodash.default.last(parameters);
140152

141-
const input = _lodash.default.head(args);
142-
143-
const lastArg = _lodash.default.last(args);
153+
const isBatch = Array.isArray(input);
144154

145155
if (_lodash.default.isFunction(lastArg)) {
146156
callback = lastArg;
147157
parameters = _lodash.default.dropRight(parameters);
148158
}
149159

150-
if (this.hasNamedParametersSupport && parameters.length === 1 && _lodash.default.isPlainObject(parameters[0])) {
151-
parameters = parameters[0];
160+
if (isBatch) {
161+
multiwallet = _lodash.default.some(input, command => {
162+
return _lodash.default.get(this.methods[command.method], 'features.multiwallet.supported', false) === true;
163+
});
164+
body = input.map((method, index) => this.requester.prepare({
165+
method: method.method,
166+
parameters: method.parameters,
167+
suffix: index
168+
}));
169+
} else {
170+
if (this.hasNamedParametersSupport && parameters.length === 1 && _lodash.default.isPlainObject(parameters[0])) {
171+
parameters = parameters[0];
172+
}
173+
174+
multiwallet = _lodash.default.get(this.methods[input], 'features.multiwallet.supported', false) === true;
175+
body = this.requester.prepare({
176+
method: input,
177+
parameters
178+
});
152179
}
153180

154181
return _bluebird.default.try(() => {
155-
if (Array.isArray(input)) {
156-
body = input.map((method, index) => this.requester.prepare({
157-
method: method.method,
158-
parameters: method.parameters,
159-
suffix: index
160-
}));
161-
} else {
162-
body = this.requester.prepare({
163-
method: input,
164-
parameters
165-
});
166-
}
167-
168182
return this.request.postAsync({
169183
auth: _lodash.default.pickBy(this.auth, _lodash.default.identity),
170184
body: JSON.stringify(body),
171-
uri: '/'
185+
uri: `${multiwallet && this.wallet ? `/wallet/${this.wallet}` : '/'}`
172186
}).bind(this).then(this.parser.rpc);
173187
}).asCallback(callback);
174188
}
@@ -217,10 +231,6 @@ class Client {
217231
extension = 'json'
218232
} = {}], callback] = source(...args);
219233
return _bluebird.default.try(() => {
220-
if (!_lodash.default.includes(['bin', 'hex'], extension)) {
221-
throw new Error(`Extension "${extension}" is not supported`);
222-
}
223-
224234
return this.request.getAsync({
225235
encoding: extension === 'bin' ? null : undefined,
226236
url: `/rest/headers/${count}/${hash}.${extension}`
@@ -289,7 +299,7 @@ class Client {
289299
*/
290300

291301

292-
_lodash.default.forOwn(_methods.default, (range, method) => {
302+
_lodash.default.forOwn(_methods.default, (options, method) => {
293303
Client.prototype[method] = _lodash.default.partial(Client.prototype.command, method.toLowerCase());
294304
});
295305
/**

dist/src/logging/request-obfuscator.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,30 @@ function obfuscateResponse(request, instance) {
4444
return;
4545
}
4646

47-
if (!(0, _lodash.get)(request, 'response.body')) {
47+
if (!request.body) {
4848
return;
4949
}
5050

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

5656
if (!instance.body) {
5757
return;
5858
}
5959

60+
request.body = JSON.parse(request.body);
6061
const requestBody = JSON.parse(instance.body);
6162

62-
if ((0, _lodash.isArray)(request.response.body)) {
63+
if ((0, _lodash.isArray)(request.body)) {
6364
const methodsById = (0, _lodash.mapKeys)(requestBody, method => method.id);
64-
request.response.body = (0, _lodash.map)(request.response.body, request => obfuscateResponseBody(request, methodsById[request.id].method));
65-
return;
65+
request.body = (0, _lodash.map)(request.body, request => obfuscateResponseBody(request, methodsById[request.id].method));
66+
} else {
67+
request.body = obfuscateResponseBody(request.body, requestBody.method);
6668
}
6769

68-
request.response.body = obfuscateResponseBody(request.response.body, requestBody.method);
70+
request.body = JSON.stringify(request.body);
6971
}
7072
/**
7173
* Obfuscate the request body.
@@ -79,8 +81,15 @@ function obfuscateRequestBody(body) {
7981
return body;
8082
}
8183

82-
body.params = method(body.params);
83-
return body;
84+
if ((0, _lodash.isPlainObject)(body.params)) {
85+
return (0, _lodash.assign)(body, {
86+
params: method.named(body.params)
87+
});
88+
}
89+
90+
return (0, _lodash.assign)(body, {
91+
params: method.default(body.params)
92+
});
8493
}
8594
/**
8695
* Obfuscate the request.

0 commit comments

Comments
 (0)