Skip to content

Commit 5c131dd

Browse files
author
Pedro Branco
committed
Add support for JSON RPC named parameters
1 parent 44e77c7 commit 5c131dd

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sut:
1010
- bitcoind-username-only
1111

1212
bitcoind:
13-
image: seegno/bitcoind:0.13.2-alpine
13+
image: seegno/bitcoind:0.14.2-alpine
1414
command:
1515
-printtoconsole
1616
-regtest=1
@@ -26,7 +26,7 @@ bitcoind:
2626
- 18333:18333
2727

2828
bitcoind-ssl:
29-
image: seegno/bitcoind:0.11-alpine
29+
image: seegno/bitcoind:0.14.2-alpine
3030
command:
3131
-printtoconsole
3232
-regtest=1
@@ -47,7 +47,7 @@ bitcoind-ssl:
4747
- 18334:18334
4848

4949
bitcoind-username-only:
50-
image: seegno/bitcoind:0.11-alpine
50+
image: seegno/bitcoind:0.14.2-alpine
5151
command:
5252
-printtoconsole
5353
-regtest=1

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ class Client {
113113
parameters = _.dropRight(parameters);
114114
}
115115

116+
// Support named parameters.
117+
if (parameters.length === 1 && _.isPlainObject(parameters[0])) {
118+
parameters = parameters[0];
119+
}
120+
116121
return Promise.try(() => {
117122
if (Array.isArray(input)) {
118123
body = input.map((method, index) => this.requester.prepare({ method: method.method, parameters: method.parameters, suffix: index }));

test/index_test.js

+19
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ describe('Client', () => {
193193

194194
balance.should.be.a.Number();
195195
});
196+
197+
it('should support named parameters', async () => {
198+
const balance = await new Client(config.bitcoind).getBalance({
199+
account: '*',
200+
minconf: 0
201+
});
202+
203+
balance.should.be.a.Number();
204+
});
196205
});
197206

198207
describe('getDifficulty()', () => {
@@ -242,6 +251,16 @@ describe('Client', () => {
242251

243252
transactions.should.be.an.Array().and.empty();
244253
});
254+
255+
it('should support named parameters', async () => {
256+
let transactions = await new Client(config.bitcoind).listTransactions({ account: 'test' });
257+
258+
transactions.should.be.an.Array().and.empty();
259+
260+
transactions = await new Client(config.bitcoind).listTransactions({ account: 'test', count: 15 });
261+
262+
transactions.should.be.an.Array().and.empty();
263+
});
245264
});
246265
});
247266

0 commit comments

Comments
 (0)