Skip to content

Commit 9e283aa

Browse files
authored
Merge pull request #18 from seegno/support/bitcoind-0-13
Add support for bitcoind 0.13
2 parents e7489c6 + 05def6b commit 9e283aa

12 files changed

+93
-64
lines changed

.babelrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
["transform-async-to-module-method", {
77
"module": "bluebird",
88
"method": "coroutine"
9-
}]
9+
}],
10+
"istanbul"
1011
]
1112
}
1213
},

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.nyc_output
12
coverage
23
node_modules

.jscsrc

-4
This file was deleted.

.npmignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.babelrc
2+
.dockerignore
3+
.eslintrc.yml
4+
.gitattributes
5+
.gitignore
6+
.nyc_output
7+
.travis.yml
8+
/src
9+
/test
10+
docker-compose.yml

docker-compose.yml

+1-1
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.12-alpine
13+
image: seegno/bitcoind:0.13-alpine
1414
command:
1515
-printtoconsole
1616
-regtest=1

package.json

+39-33
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22
"name": "bitcoin-core",
33
"version": "1.0.0",
44
"description": "A modern Bitcoin Core REST and RPC client.",
5-
"author": {
6-
"name": "Rui Marinho",
7-
"email": "[email protected]",
8-
"url": "http://seegno.com"
9-
},
10-
"license": "MIT",
11-
"homepage": "https://github.com/seegno/bitcoin-core",
12-
"bugs": "https://github.com/seegno/bitcoin-core/issues",
13-
"repository": {
14-
"type": "git",
15-
"url": "https://github.com/seegno/bitcoin-core.git"
16-
},
17-
"main": "dist/src/index.js",
185
"keywords": [
196
"bitcoin",
207
"bitcoind",
@@ -23,22 +10,32 @@
2310
"rest",
2411
"rpc"
2512
],
26-
"options": {
27-
"mocha": "--compilers js:babel-register --timeout 20000 --recursive --require should test"
13+
"homepage": "https://github.com/seegno/bitcoin-core",
14+
"bugs": "https://github.com/seegno/bitcoin-core/issues",
15+
"license": "MIT",
16+
"author": {
17+
"name": "Rui Marinho",
18+
"email": "[email protected]",
19+
"url": "http://seegno.com"
20+
},
21+
"main": "dist/src/index.js",
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/seegno/bitcoin-core.git"
2825
},
2926
"scripts": {
3027
"changelog": "github_changelog_generator --no-issues --header-label='# Changelog' --future-release=$npm_config_future_release && sed -i '' -e :a -e '$d;N;2,4ba' -e 'P;D' CHANGELOG.md",
31-
"cover": "babel-node node_modules/.bin/isparta cover --report html _mocha -- $npm_package_options_mocha",
28+
"cover": "nyc --reporter=html --reporter=text npm test",
3229
"dependencies": "docker-compose up -d bitcoind bitcoind-ssl bitcoind-username-only",
33-
"lint": "eslint src test && jscs src test",
30+
"lint": "eslint src test",
3431
"prepublish": "npm run transpile",
35-
"testdocker": "docker-compose run --rm sut",
3632
"test": "NODE_ENV=test mocha $npm_package_options_mocha",
33+
"testdocker": "docker-compose run --rm sut",
3734
"transpile": "rm -rf dist/* && babel src --out-dir dist/src",
3835
"version": "npm run changelog --future-release=$npm_package_version && npm run transpile && git add -A CHANGELOG.md dist"
3936
},
4037
"dependencies": {
41-
"bluebird": "^3.1.1",
38+
"bluebird": "^3.4.1",
4239
"lodash": "^4.0.0",
4340
"request": "^2.53.0",
4441
"semver": "^5.1.0",
@@ -47,26 +44,35 @@
4744
"devDependencies": {
4845
"babel-cli": "^6.4.0",
4946
"babel-eslint": "^6.0.0",
50-
"babel-plugin-add-module-exports": "^0.1.2",
47+
"babel-plugin-add-module-exports": "^0.2.1",
48+
"babel-plugin-istanbul": "^2.0.0",
5149
"babel-plugin-transform-async-to-module-method": "^6.5.2",
5250
"babel-preset-es2015-node4": "^2.0.2",
5351
"babel-register": "^6.3.13",
54-
"eslint": "^2.3.0",
55-
"eslint-config-seegno": "^3.0.0",
56-
"eslint-plugin-babel": "^3.0.0",
52+
"eslint": "^3.3.1",
53+
"eslint-config-seegno": "^6.0.0",
5754
"isparta": "^4.0.0",
58-
"jscs": "^2.7.0",
59-
"jscs-config-seegno": "^1.0.0",
60-
"mocha": "^2.3.4",
61-
"nock": "^7.2.2",
55+
"mocha": "^3.0.2",
56+
"nock": "^8.0.0",
57+
"nyc": "^8.1.0",
6258
"pre-commit": "^1.1.2",
63-
"should": "^8.0.0",
64-
"sinon": "^1.17.2"
59+
"should": "^11.1.0"
6560
},
66-
"pre-commit": [
67-
"lint"
68-
],
6961
"engines": {
7062
"node": ">=4"
71-
}
63+
},
64+
"nyc": {
65+
"include": [
66+
"src/"
67+
],
68+
"instrument": false,
69+
"report-dir": "./coverage",
70+
"sourceMap": false
71+
},
72+
"options": {
73+
"mocha": "--compilers js:babel-register --timeout 20000 --recursive --require should"
74+
},
75+
"pre-commit": [
76+
"lint"
77+
]
7278
}

src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Module dependencies.
44
*/
55

6-
import _ from 'lodash';
76
import Parser from './parser';
8-
import Requester from './requester';
97
import Promise from 'bluebird';
8+
import Requester from './requester';
9+
import _ from 'lodash';
1010
import methods from './methods';
1111
import request from 'request';
1212
import semver from 'semver';
@@ -76,7 +76,7 @@ class Client {
7676

7777
if (version) {
7878
unsupported = _.chain(methods)
79-
.pickBy((range) => !semver.satisfies(version, range))
79+
.pickBy(range => !semver.satisfies(version, range))
8080
.keys()
8181
.invokeMap(String.prototype.toLowerCase)
8282
.value();
@@ -198,7 +198,7 @@ class Client {
198198
getUnspentTransactionOutputs(...args) {
199199
const [[outpoints, { extension = 'json' } = {}], callback] = source(...args);
200200

201-
const sets = _.flatten([outpoints]).map((outpoint) => {
201+
const sets = _.flatten([outpoints]).map(outpoint => {
202202
return `${outpoint.id}-${outpoint.index}`;
203203
}).join('/');
204204

src/methods.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export default {
88
abandonTransaction: '>=0.12.0',
99
addMultiSigAddress: '>=0.1.0',
1010
addNode: '>=0.8.0',
11+
addWitnessAddress: '>=0.13.0',
1112
backupWallet: '>=0.3.12',
1213
clearBanned: '>=0.12.0',
1314
createMultiSig: '>=0.1.0',
1415
createRawTransaction: '>=0.7.0',
16+
createWitnessAddress: '>=0.13.0',
1517
decodeRawTransaction: '>=0.7.0',
1618
decodeScript: '>=0.9.0',
1719
disconnectNode: '>=0.12.0',
@@ -24,6 +26,7 @@ export default {
2426
estimateSmartPriority: '>=0.12.0',
2527
fundRawTransaction: '>=0.12.0',
2628
generate: '>=0.11.0',
29+
generateToAddress: '>=0.13.0',
2730
getAccount: '>=0.1.0',
2831
getAccountAddress: '>=0.3.18',
2932
getAddedNodeInfo: '>=0.8.0',
@@ -39,9 +42,12 @@ export default {
3942
getChainTips: '>=0.10.0',
4043
getConnectionCount: '>=0.1.0',
4144
getDifficulty: '>=0.1.0',
42-
getGenerate: '>=0.1.0',
45+
getGenerate: '<0.13.0',
4346
getHashesPerSec: '<0.10.0',
4447
getInfo: '>=0.1.0',
48+
getMempoolAncestors: '>=0.13.0',
49+
getMempoolDescendants: '>=0.13.0',
50+
getMempoolEntry: '>=0.13.0',
4551
getMempoolInfo: '>=0.10.0',
4652
getMiningInfo: '>=0.6.0',
4753
getNetTotals: '>=0.1.0',
@@ -64,6 +70,7 @@ export default {
6470
help: '>=0.1.0',
6571
importAddress: '>=0.10.0',
6672
importPrivKey: '>=0.6.0',
73+
importPrunedFunds: '>=0.13.0',
6774
importPubKey: '>=0.12.0',
6875
importWallet: '>=0.9.0',
6976
keypoolRefill: '>=0.1.0',
@@ -80,15 +87,17 @@ export default {
8087
move: '>=0.3.18',
8188
ping: '>=0.9.0',
8289
prioritiseTransaction: '>=0.10.0',
90+
removePrunedFunds: '>=0.13.0',
8391
sendFrom: '>=0.3.18',
8492
sendMany: '>=0.3.21',
8593
sendRawTransaction: '>=0.7.0',
8694
sendToAddress: '>=0.1.0',
8795
setAccount: '>=0.1.0',
8896
setBan: '>=0.12.0',
89-
setGenerate: '>=0.1.0',
97+
setGenerate: '<0.13.0',
9098
setTxFee: '>=0.3.22',
9199
signMessage: '>=0.5.0',
100+
signMessageWithPrivKey: '>=0.13.0',
92101
signRawTransaction: '>=0.7.0',
93102
stop: '>=0.1.0',
94103
submitBlock: '>=0.7.0',

src/parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* Module dependencies.
44
*/
55

6-
import _ from 'lodash';
76
import RpcError from './errors/rpc-error';
7+
import _ from 'lodash';
88

99
/**
1010
* Get response result and errors.
@@ -57,7 +57,7 @@ export default class Parser {
5757
}
5858

5959
// Batch response parsing where each response may or may not be successful.
60-
const batch = body.map((response) => {
60+
const batch = body.map(response => {
6161
try {
6262
return get(response, { headers: false, response });
6363
} catch (e) {

test/config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
function getHost(name) {
11-
return process.env.CI === 'true' ? name : 'docker.local';
11+
return process.env.CI === 'true' ? name : '127.0.0.1';
1212
}
1313

1414
/**

test/index_test.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Module dependencies.
44
*/
55

6-
import _ from 'lodash';
76
import Client from '../src/index';
87
import RpcError from '../src/errors/rpc-error';
8+
import _ from 'lodash';
99
import config from './config';
1010
import fs from 'fs';
1111
import methods from '../src/methods';
@@ -137,7 +137,7 @@ describe('Client', () => {
137137
headers.should.have.keys('date', 'connection', 'content-length', 'content-type');
138138
});
139139

140-
it('should return the response headers if `headers` is enabled using callbacks', (done) => {
140+
it('should return the response headers if `headers` is enabled using callbacks', done => {
141141
new Client(_.defaults({ headers: true }, config.bitcoind)).getInfo((err, [info, headers]) => {
142142
should.not.exist(err);
143143

@@ -160,7 +160,7 @@ describe('Client', () => {
160160
headers.should.have.keys('date', 'connection', 'content-length', 'content-type');
161161
});
162162

163-
it('should return the response headers if `headers` is enabled and batching is used with callbacks', (done) => {
163+
it('should return the response headers if `headers` is enabled and batching is used with callbacks', done => {
164164
const batch = [];
165165

166166
_.times(5, () => batch.push({ method: 'getnewaddress' }));
@@ -269,7 +269,7 @@ describe('Client', () => {
269269
it('should establish a connection if certificate is self signed but `ca` agent option is passed', async () => {
270270
const sslClient = new Client(_.defaults({
271271
agentOptions: {
272-
/*eslint-disable no-sync */
272+
/* eslint-disable no-sync */
273273
ca: fs.readFileSync(path.join(__dirname, '/config/ssl/cert.pem')),
274274
checkServerIdentity() {
275275
// Skip server identity checks otherwise the certificate would be immediately rejected
@@ -301,7 +301,7 @@ describe('Client', () => {
301301
_.difference(parse(help), _.invokeMap(Object.keys(methods), String.prototype.toLowerCase)).should.be.empty();
302302
});
303303

304-
it('should support callbacks', (done) => {
304+
it('should support callbacks', done => {
305305
new Client(config.bitcoind).help((err, help) => {
306306
should.not.exist(err);
307307

@@ -406,7 +406,7 @@ describe('Client', () => {
406406
const [transaction] = await client.listUnspent();
407407
const hex = await client.getTransactionByHash(transaction.txid);
408408

409-
hex.should.have.keys('blockhash', 'blocktime', 'confirmations', 'locktime', 'size', 'time', 'txid', 'version', 'vin', 'vout');
409+
hex.should.have.keys('blockhash', 'blocktime', 'confirmations', 'locktime', 'hash', 'size', 'time', 'txid', 'version', 'vin', 'vout', 'vsize');
410410
});
411411
});
412412

@@ -426,15 +426,15 @@ describe('Client', () => {
426426
it('should return a block json-encoded by default', async () => {
427427
const block = await client.getBlockByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', { extension: 'json' });
428428

429-
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'time', 'tx', 'version');
430-
block.tx.should.matchEach((value) => value.should.be.an.Object());
429+
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
430+
block.tx.should.matchEach(value => value.should.be.an.Object());
431431
});
432432

433433
it('should return a block summary json-encoded if `summary` is enabled', async () => {
434434
const block = await client.getBlockByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', { extension: 'json', summary: true });
435435

436-
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'time', 'tx', 'version');
437-
block.tx.should.matchEach((value) => value.should.be.a.String());
436+
block.should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'size', 'strippedsize', 'time', 'tx', 'version', 'versionHex', 'weight');
437+
block.tx.should.matchEach(value => value.should.be.a.String());
438438
});
439439
});
440440

@@ -506,7 +506,7 @@ describe('Client', () => {
506506
}]);
507507

508508
result.should.have.keys('bitmap', 'chainHeight', 'chaintipHash', 'utxos');
509-
result.chainHeight.should.equal(200);
509+
result.chainHeight.should.be.a.Number();
510510
});
511511
});
512512

@@ -520,9 +520,15 @@ describe('Client', () => {
520520

521521
describe('getMemoryPoolInformation()', () => {
522522
it('should return memory pool information json-encoded by default', async () => {
523-
const information = await new Client(config.bitcoind).getMemoryPoolContent();
524-
525-
information.should.eql({});
523+
const information = await new Client(config.bitcoind).getMemoryPoolInformation();
524+
525+
information.should.eql({
526+
bytes: 0,
527+
maxmempool: 300000000,
528+
mempoolminfee: 0,
529+
size: 0,
530+
usage: 0
531+
});
526532
});
527533
});
528534
});

test/utils/help-parser-util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import _ from 'lodash';
1111

1212
export default function parse(help) {
1313
return _.chain(help.split('\n'))
14-
.reject((line) => line.startsWith('==') || !_.identity(line))
15-
.map((line) => (/^([a-z]+)/).exec(line)[1])
14+
.reject(line => line.startsWith('==') || !_.identity(line))
15+
.map(line => (/^([a-z]+)/).exec(line)[1])
1616
.value();
1717
}

0 commit comments

Comments
 (0)