Skip to content

Commit 1dc89dc

Browse files
committed
feat<cli>: added filterheader
1 parent 62dfdbd commit 1dc89dc

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

bin/bcoin-cli

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ class CLI {
129129
this.log(filter);
130130
}
131131

132+
async getFilterHeader() {
133+
let hash = this.config.str(0, '');
134+
135+
if (hash.length !== 64)
136+
hash = parseInt(hash, 10);
137+
138+
const filterHeader = await this.client.getFilterHeader(hash);
139+
140+
if (!filterHeader) {
141+
this.log('Filter header not found.');
142+
return;
143+
}
144+
145+
this.log(filterHeader);
146+
}
147+
132148
async estimateFee() {
133149
const blocks = this.config.uint(0, 1);
134150

@@ -246,6 +262,9 @@ class CLI {
246262
case 'filter':
247263
await this.getFilter();
248264
break;
265+
case 'filterheader':
266+
await this.getFilterHeader();
267+
break;
249268
case 'fee':
250269
await this.estimateFee();
251270
break;
@@ -263,6 +282,7 @@ class CLI {
263282
this.log(' $ coin [hash+index/address]: View coins.');
264283
this.log(' $ fee [target]: Estimate smart fee.');
265284
this.log(' $ filter [hash/height]: View filter.');
285+
this.log(' $ filterheader [hash/height]: View filter header.');
266286
this.log(' $ header [hash/height]: View block header.');
267287
this.log(' $ info: Get server info.');
268288
this.log(' $ mempool: Get mempool snapshot.');

lib/client/node.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,14 @@ class NodeClient extends Client {
164164
* @returns {Promise}
165165
*/
166166

167-
getFilter(filter) {
168-
assert(typeof filter === 'string' || typeof filter === 'number');
169-
return this.get(`/filter/${filter}`);
167+
getFilter(block) {
168+
assert(typeof block === 'string' || typeof block === 'number');
169+
return this.get(`/filter/${block}`);
170+
}
171+
172+
getFilterHeader(block) {
173+
assert(typeof block === 'string' || typeof block === 'number');
174+
return this.get(`/filterheader/${block}`);
170175
}
171176

172177
getBlockPeer(hash) {

lib/node/http.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ class HTTP extends Server {
291291

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

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

296297
if (!filter) {
297298
res.json(404);
@@ -301,6 +302,24 @@ class HTTP extends Server {
301302
res.json(200, filter.toJSON());
302303
});
303304

305+
this.get('/filterheader/:block', async (req, res) => {
306+
const valid = Validator.fromRequest(req);
307+
const hash = valid.uintbrhash('block');
308+
309+
enforce(hash != null, 'Hash or height required.');
310+
311+
const filterName = valid.str(1, 'BASIC').toUpperCase();
312+
const filterHeader = await this.node.
313+
getBlockFilterHeader(hash, filterName);
314+
315+
if (!filterHeader) {
316+
res.json(404);
317+
return;
318+
}
319+
320+
res.json(200, filterHeader.toJSON());
321+
});
322+
304323
// Mempool snapshot
305324
this.get('/mempool', async (req, res) => {
306325
enforce(this.mempool, 'No mempool available.');

0 commit comments

Comments
 (0)