Skip to content

Commit

Permalink
feat<cli>: added filterheader
Browse files Browse the repository at this point in the history
  • Loading branch information
manavdesai27 committed Jul 17, 2023
1 parent aabe613 commit a8bb572
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
20 changes: 20 additions & 0 deletions bin/bcoin-cli
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ class CLI {
this.log(filter);
}

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

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

const filterHeader = await this.client.getFilterHeader(hash);

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

this.log(filterHeader);
}

async estimateFee() {
const blocks = this.config.uint(0, 1);

Expand Down Expand Up @@ -246,6 +262,9 @@ class CLI {
case 'filter':
await this.getFilter();
break;
case 'filterheader':
await this.getFilterHeader();
break;
case 'fee':
await this.estimateFee();
break;
Expand All @@ -263,6 +282,7 @@ class CLI {
this.log(' $ coin [hash+index/address]: View coins.');
this.log(' $ fee [target]: Estimate smart fee.');
this.log(' $ filter [hash/height]: View filter.');
this.log(' $ filterheader [hash/height]: View filter header.');
this.log(' $ header [hash/height]: View block header.');
this.log(' $ info: Get server info.');
this.log(' $ mempool: Get mempool snapshot.');
Expand Down
11 changes: 8 additions & 3 deletions lib/client/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,14 @@ class NodeClient extends Client {
* @returns {Promise}
*/

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

Check warning on line 169 in lib/client/node.js

View check run for this annotation

Codecov / codecov/patch

lib/client/node.js#L168-L169

Added lines #L168 - L169 were not covered by tests
}

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

Check warning on line 174 in lib/client/node.js

View check run for this annotation

Codecov / codecov/patch

lib/client/node.js#L173-L174

Added lines #L173 - L174 were not covered by tests
}

getBlockPeer(hash) {
Expand Down
21 changes: 20 additions & 1 deletion lib/node/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class HTTP extends Server {

enforce(hash != null, 'Hash or height required.');

const filter = await this.node.getBlockFilter(hash);
const filterName = valid.str(1, 'BASIC').toUpperCase();
const filter = await this.node.getBlockFilter(hash, filterName);

Check warning on line 295 in lib/node/http.js

View check run for this annotation

Codecov / codecov/patch

lib/node/http.js#L294-L295

Added lines #L294 - L295 were not covered by tests

if (!filter) {
res.json(404);
Expand All @@ -301,6 +302,24 @@ class HTTP extends Server {
res.json(200, filter.toJSON());
});

this.get('/filterheader/:block', async (req, res) => {
const valid = Validator.fromRequest(req);
const hash = valid.uintbrhash('block');

Check warning on line 307 in lib/node/http.js

View check run for this annotation

Codecov / codecov/patch

lib/node/http.js#L306-L307

Added lines #L306 - L307 were not covered by tests

enforce(hash != null, 'Hash or height required.');

Check warning on line 309 in lib/node/http.js

View check run for this annotation

Codecov / codecov/patch

lib/node/http.js#L309

Added line #L309 was not covered by tests

const filterName = valid.str(1, 'BASIC').toUpperCase();
const filterHeader = await this.node.

Check warning on line 312 in lib/node/http.js

View check run for this annotation

Codecov / codecov/patch

lib/node/http.js#L311-L312

Added lines #L311 - L312 were not covered by tests
getBlockFilterHeader(hash, filterName);

if (!filterHeader) {
res.json(404);
return;

Check warning on line 317 in lib/node/http.js

View check run for this annotation

Codecov / codecov/patch

lib/node/http.js#L315-L317

Added lines #L315 - L317 were not covered by tests
}

res.json(200, filterHeader.toJSON());

Check warning on line 320 in lib/node/http.js

View check run for this annotation

Codecov / codecov/patch

lib/node/http.js#L320

Added line #L320 was not covered by tests
});

// Mempool snapshot
this.get('/mempool', async (req, res) => {
enforce(this.mempool, 'No mempool available.');
Expand Down

0 comments on commit a8bb572

Please sign in to comment.