-
Notifications
You must be signed in to change notification settings - Fork 405
Support for /block_search RPC endpoint
#810
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
Changes from 8 commits
b78f8d7
cae413f
4f4d153
871e195
409967b
732cb30
a51ad08
c85c93b
8dee1a0
c9ccea0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,47 @@ export class Tendermint34Client { | |
| return this.doCall(query, this.p.encodeBlockResults, this.r.decodeBlockResults); | ||
| } | ||
|
|
||
| /** | ||
| * Search for events that are in a block | ||
| * | ||
| * @see https://docs.tendermint.com/master/rpc/#/Info/block_search | ||
| */ | ||
| public async blockSearch(params: requests.BlockSearchParams): Promise<responses.BlockSearchResponse> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good to me (in terms of functionality). My one question is that this is only available in tendermint v0.34.9+, correct? Minimally that should be documented in the comments along with a link to the PR. However, what happens when someone tries to run this on tendermint v0.34.8 node? There should be a clearly defined error case that distinguishes "network error" from "tendermint version too old" or it will be very hard for people to debug this. Maybe @webmaster128 has some idea how to do this properly - it seems this error would be thrown in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a note regarding compatibility here would be nice. I would not get into the version checking business again, which led to a lot of trouble sttarting with Tendermint 0.34. If the backend does not support an RPC method, it will return some kind of error that explains the problem somehow. |
||
| const query: requests.BlockSearchRequest = { params: params, method: requests.Method.BlockSearch }; | ||
| const resp = await this.doCall(query, this.p.encodeBlockSearch, this.r.decodeBlockSearch); | ||
| return { | ||
| ...resp, | ||
| // make sure we sort by height, as tendermint may be sorting by string value of the height | ||
| blocks: [...resp.blocks].sort((a, b) => a.block.header.height - b.block.header.height), | ||
| }; | ||
| } | ||
|
|
||
| // this should paginate through all blockSearch options to ensure it returns all results. | ||
| // starts with page 1 or whatever was provided (eg. to start on page 7) | ||
| public async blockSearchAll(params: requests.BlockSearchParams): Promise<responses.BlockSearchResponse> { | ||
| let page = params.page || 1; | ||
| const blocks: responses.BlockResponse[] = []; | ||
| let done = false; | ||
|
|
||
| while (!done) { | ||
| const resp = await this.blockSearch({ ...params, page: page }); | ||
| blocks.push(...resp.blocks); | ||
| if (blocks.length < resp.totalCount) { | ||
| page++; | ||
| } else { | ||
| done = true; | ||
| } | ||
| } | ||
| // make sure we sort by height, as tendermint may be sorting by string value of the height | ||
| // and the earlier items may be in a higher page than the later items | ||
| blocks.sort((a, b) => a.block.header.height - b.block.header.height); | ||
|
|
||
| return { | ||
| totalCount: blocks.length, | ||
| blocks: blocks, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Queries block headers filtered by minHeight <= height <= maxHeight. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.