Skip to content

Commit

Permalink
Merge pull request #28 from tynes/getblockheader
Browse files Browse the repository at this point in the history
nodeclient: getblockheader
  • Loading branch information
boymanjor authored May 8, 2020
2 parents 1de5165 + 2a9c1f2 commit fa31898
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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

0 comments on commit fa31898

Please sign in to comment.