Skip to content

Commit 6eaec99

Browse files
authored
BlockHeaders: Support for /v2/blockheaders against Indexer API (v2.x line) (#928)
* Support for /v2/blockheaders against Indexer API. * Update CircleCI browsertools.
1 parent 62645cf commit 6eaec99

File tree

6 files changed

+299
-2
lines changed

6 files changed

+299
-2
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
orbs:
44
node: circleci/node@5.0.0
55
slack: circleci/slack@4.4.2
6-
browser-tools: circleci/browser-tools@1.4.8
6+
browser-tools: circleci/browser-tools@1.5.1
77
gh-pages: sugarshin/gh-pages@1.0.0
88

99
parameters:

src/client/v2/indexer/indexer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import LookupApplications from './lookupApplications';
1515
import LookupApplicationLogs from './lookupApplicationLogs';
1616
import LookupApplicationBoxByIDandName from './lookupApplicationBoxByIDandName';
1717
import SearchAccounts from './searchAccounts';
18+
import SearchForBlockHeaders from './searchForBlockHeaders';
1819
import SearchForTransactions from './searchForTransactions';
1920
import SearchForAssets from './searchForAssets';
2021
import SearchForApplications from './searchForApplications';
@@ -345,6 +346,21 @@ export default class IndexerClient extends ServiceClient {
345346
return new SearchForTransactions(this.c, this.intDecoding);
346347
}
347348

349+
/**
350+
* Returns information about indexed block headers.
351+
*
352+
* #### Example
353+
* ```typescript
354+
* const txns = await indexerClient.searchForBlockHeaders().do();
355+
* ```
356+
*
357+
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/indexer/#get-v2block-headers)
358+
* @category GET
359+
*/
360+
searchForBlockHeaders() {
361+
return new SearchForBlockHeaders(this.c, this.intDecoding);
362+
}
363+
348364
/**
349365
* Returns information about indexed assets.
350366
*
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import JSONRequest from '../jsonrequest';
2+
3+
/**
4+
* Returns information about indexed block headers.
5+
*
6+
* #### Example
7+
* ```typescript
8+
* const bhs = await indexerClient.searchForBlockHeaders().do();
9+
* ```
10+
*
11+
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/indexer/#get-v2block-headers)
12+
* @category GET
13+
*/
14+
export default class SearchForBlockHeaders extends JSONRequest {
15+
/**
16+
* @returns `/v2/block-headers`
17+
*/
18+
// eslint-disable-next-line class-methods-use-this
19+
path() {
20+
return '/v2/block-headers';
21+
}
22+
23+
/**
24+
* Accounts marked as absent in the block header's participation updates.
25+
*
26+
* #### Example
27+
* ```typescript
28+
* const address1 = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
29+
* const address2 = "4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4";
30+
* const bhs = await indexerClient
31+
* .searchForBlockHeaders()
32+
* .absent([address1,address2])
33+
* .do();
34+
* ```
35+
*
36+
* @param absent - a comma separated list of addresses
37+
* @category query
38+
*/
39+
absent(absent: string[]) {
40+
this.query.absent = absent;
41+
return this;
42+
}
43+
44+
/**
45+
* Include results after the given time.
46+
*
47+
* #### Example
48+
* ```typescript
49+
* const afterTime = "2022-10-21T00:00:11.55Z";
50+
* const bhs = await indexerClient
51+
* .searchForBlockHeaders()
52+
* .afterTime(afterTime)
53+
* .do();
54+
* ```
55+
*
56+
* @param after - rfc3339 string
57+
* @category query
58+
*/
59+
afterTime(after: string) {
60+
this.query['after-time'] = after;
61+
return this;
62+
}
63+
64+
/**
65+
* Include results before the given time.
66+
*
67+
* #### Example
68+
* ```typescript
69+
* const beforeTime = "2022-02-02T20:20:22.02Z";
70+
* const bhs = await indexerClient
71+
* .searchForBlockHeaders()
72+
* .beforeTime(beforeTime)
73+
* .do();
74+
* ```
75+
*
76+
* @param before - rfc3339 string
77+
* @category query
78+
*/
79+
beforeTime(before: string) {
80+
this.query['before-time'] = before;
81+
return this;
82+
}
83+
84+
/**
85+
* Accounts marked as expired in the block header's participation updates.
86+
*
87+
* #### Example
88+
* ```typescript
89+
* const address1 = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
90+
* const address2 = "4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4";
91+
* const bhs = await indexerClient
92+
* .searchForBlockHeaders()
93+
* .expired([address1,address2])
94+
* .do();
95+
* ```
96+
*
97+
* @param expired - - a comma separated list of addresses
98+
* @category query
99+
*/
100+
expired(expired: string[]) {
101+
this.query.expired = expired;
102+
return this;
103+
}
104+
105+
/**
106+
* Maximum number of results to return.
107+
*
108+
* #### Example
109+
* ```typescript
110+
* const maxResults = 25;
111+
* const bhs = await indexerClient
112+
* .searchForBlockHeaders()
113+
* .limit(maxResults)
114+
* .do();
115+
* ```
116+
*
117+
* @param limit
118+
* @category query
119+
*/
120+
limit(limit: number) {
121+
this.query.limit = limit;
122+
return this;
123+
}
124+
125+
/**
126+
* Include results at or before the specified max-round.
127+
*
128+
* #### Example
129+
* ```typescript
130+
* const maxRound = 18309917;
131+
* const bhs = await indexerClient
132+
* .searchForBlockHeaders()
133+
* .maxRound(maxRound)
134+
* .do();
135+
* ```
136+
*
137+
* @param round
138+
* @category query
139+
*/
140+
maxRound(round: number) {
141+
this.query['max-round'] = round;
142+
return this;
143+
}
144+
145+
/**
146+
* Include results at or after the specified min-round.
147+
*
148+
* #### Example
149+
* ```typescript
150+
* const minRound = 18309917;
151+
* const bhs = await indexerClient
152+
* .searchForBlockHeaders()
153+
* .minRound(minRound)
154+
* .do();
155+
* ```
156+
*
157+
* @param round
158+
* @category query
159+
*/
160+
minRound(round: number) {
161+
this.query['min-round'] = round;
162+
return this;
163+
}
164+
165+
/**
166+
* The next page of results.
167+
*
168+
* #### Example
169+
* ```typescript
170+
* const maxResults = 25;
171+
*
172+
* const bh1 = await indexerClient
173+
* .searchForBlockHeaders()
174+
* .limit(maxResults)
175+
* .do();
176+
*
177+
* const bh2 = await indexerClient
178+
* .searchForBlockHeaders()
179+
* .limit(maxResults)
180+
* .nextToken(bh1["next-token"])
181+
* .do();
182+
* ```
183+
*
184+
* @param nextToken - provided by the previous results
185+
* @category query
186+
*/
187+
nextToken(nextToken: string) {
188+
this.query.next = nextToken;
189+
return this;
190+
}
191+
192+
/**
193+
* Accounts marked as proposer in the block header's participation updates.
194+
*
195+
* #### Example
196+
* ```typescript
197+
* const address1 = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
198+
* const address2 = "4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4";
199+
* const bhs = await indexerClient
200+
* .searchForBlockHeaders()
201+
* .proposers([address1,address2])
202+
* .do();
203+
* ```
204+
*
205+
* @param proposers - a comma separated list of addresses
206+
* @category query
207+
*/
208+
proposers(proposers: string[]) {
209+
this.query.proposers = proposers;
210+
return this;
211+
}
212+
}

tests/9.Client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ describe('client', () => {
4343
format: 'json',
4444
abc: 'xyz',
4545
l: '2',
46+
adds: [
47+
'XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA',
48+
'4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4',
49+
],
4650
});
47-
const expected = 'http://localhost:3000/relative?format=json&abc=xyz&l=2';
51+
const expected =
52+
'http://localhost:3000/relative?format=json&abc=xyz&l=2&adds=XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA%2C4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4';
4853

4954
assert.strictEqual(actual, expected);
5055
});

tests/cucumber/steps/steps.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,47 @@ module.exports = function getSteps(options) {
23592359
}
23602360
);
23612361

2362+
When(
2363+
'we make a Search For BlockHeaders call with minRound {int} maxRound {int} limit {int} nextToken {string} beforeTime {string} afterTime {string} proposers {string} expired {string} absent {string}',
2364+
async function (
2365+
minRound,
2366+
maxRound,
2367+
limit,
2368+
nextToken,
2369+
beforeTime,
2370+
afterTime,
2371+
proposers,
2372+
expired,
2373+
absent
2374+
) {
2375+
const builder = this.indexerClient
2376+
.searchForBlockHeaders()
2377+
.afterTime(afterTime)
2378+
.beforeTime(beforeTime)
2379+
.limit(limit)
2380+
.maxRound(maxRound)
2381+
.minRound(minRound)
2382+
.nextToken(nextToken);
2383+
2384+
if (proposers !== null && proposers.trim().length > 0) {
2385+
const proposersArray = proposers.split(',');
2386+
builder.proposers(proposersArray);
2387+
}
2388+
2389+
if (expired !== null && expired.trim().length > 0) {
2390+
const expiredArray = expired.split(',');
2391+
builder.expired(expiredArray);
2392+
}
2393+
2394+
if (absent !== null && absent.trim().length > 0) {
2395+
const absentArray = absent.split(',');
2396+
builder.absent(absentArray);
2397+
}
2398+
2399+
await builder.do();
2400+
}
2401+
);
2402+
23622403
When(
23632404
'we make a Search For Transactions call with account {string} NotePrefix {string} TxType {string} SigType {string} txid {string} round {int} minRound {int} maxRound {int} limit {int} beforeTime {string} afterTime {string} currencyGreaterThan {int} currencyLessThan {int} assetIndex {int} addressRole {string} ExcluseCloseTo {string} rekeyTo {string}',
23642405
async function (
@@ -2738,6 +2779,28 @@ module.exports = function getSteps(options) {
27382779
}
27392780
);
27402781

2782+
let anySearchForBlockHeadersResponse;
2783+
2784+
When('we make any SearchForBlockHeaders call', async function () {
2785+
anySearchForBlockHeadersResponse = await this.indexerClient
2786+
.searchForBlockHeaders()
2787+
.do();
2788+
});
2789+
2790+
Then(
2791+
'the parsed SearchForBlockHeaders response should have a block array of len {int} and the element at index {int} should have round {string}',
2792+
(length, idx, roundStr) => {
2793+
assert.strictEqual(
2794+
anySearchForBlockHeadersResponse.blocks.length,
2795+
length
2796+
);
2797+
assert.strictEqual(
2798+
anySearchForBlockHeadersResponse.blocks[idx].round,
2799+
parseInt(roundStr)
2800+
);
2801+
}
2802+
);
2803+
27412804
let anySearchForAssetsResponse;
27422805

27432806
When('we make any SearchForAssets call', async function () {

tests/cucumber/unit.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@unit.dryrun.trace.application
1313
@unit.feetest
1414
@unit.indexer
15+
@unit.indexer.blockheaders
1516
@unit.indexer.ledger_refactoring
1617
@unit.indexer.logs
1718
@unit.indexer.heartbeat

0 commit comments

Comments
 (0)