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

nodeclient: getblockheader #28

Merged
merged 2 commits into from
May 8, 2020
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
20 changes: 20 additions & 0 deletions bin/hsd-cli
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ class CLI {
this.log(block);
}

async getBlockHeader() {
let hash = this.config.str(0, '');

if (hash.length !== 64)
hash = parseInt(hash, 10);

const header = await this.client.getBlockHeader(hash);

if (!header) {
this.log('Block header not found.');
return;
}

this.log(header);
}

async getCoin() {
const hash = this.config.str(0, '');
const index = this.config.uint(1);
Expand Down Expand Up @@ -189,6 +205,9 @@ class CLI {
case 'block':
await this.getBlock();
break;
case 'header':
await this.getBlockHeader();
break;
case 'reset':
await this.reset();
break;
Expand All @@ -204,6 +223,7 @@ class CLI {
this.log(' $ tx [hash/address]: View transactions.');
this.log(' $ coin [hash+index/address]: View coins.');
this.log(' $ block [hash/height]: View block.');
this.log(' $ header [hash/height]: View block header.');
this.log(' $ reset [height/hash]: Reset chain to desired block.');
this.log(' $ rpc [command] [args]: Execute RPC command.');
break;
Expand Down
11 changes: 11 additions & 0 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ class NodeClient extends Client {
return this.get(`/block/${block}`);
}

/**
* Retrieve a block header.
* @param {Hash|Number} block
* @returns {Promise}
*/

getBlockHeader(block) {
assert(typeof block === 'string' || typeof block === 'number');
return this.get(`/header/${block}`);
}

/**
* Add a transaction to the mempool and broadcast it.
* @param {TX} tx
Expand Down