Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for json extension in rest endpoint #78

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ class Client {
const [[hash, count, { extension = 'json' } = {}], callback] = source(...args);

return Promise.try(() => {
if (!_.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
2 changes: 1 addition & 1 deletion test/parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Module dependencies.
*/

import { defaults } from 'lodash';
import Client from '../src/index';
import RpcError from '../src/errors/rpc-error';
import config from './config';
import { defaults } from 'lodash';
import nock from 'nock';
import should from 'should';

Expand Down
2 changes: 1 addition & 1 deletion test/requester_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Module dependencies.
*/

import { defaults } from 'lodash';
import Client from '../src/index';
import config from './config';
import { defaults } from 'lodash';
import should from 'should';

/**
Expand Down
12 changes: 4 additions & 8 deletions test/rest_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('REST', () => {
before(async () => {
const [tip] = await client.getChainTips();


if (tip.height >= 200) {
return null;
}
Expand Down Expand Up @@ -113,14 +112,11 @@ describe('REST', () => {

describe('getBlockHeadersByHash()', () => {
it('should return a block json-encoded by default', async () => {
try {
await client.getBlockHeadersByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', 1, { extension: 'json' });
const headers = await client.getBlockHeadersByHash('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', 1, { extension: 'json' });

should.fail();
} catch (e) {
e.should.be.an.instanceOf(Error);
e.message.should.equal('Extension "json" is not supported');
}
headers.should.have.length(1);
headers[0].should.have.keys('bits', 'chainwork', 'confirmations', 'difficulty', 'hash', 'height', 'mediantime', 'merkleroot', 'nextblockhash', 'nonce', 'time', 'version', 'versionHex');
headers[0].hash.should.equal('0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206');
});

it('should return block headers hex-encoded if extension is `hex`', async () => {
Expand Down
Loading