Skip to content

Commit 9a8e0f0

Browse files
authored
Support for header-only flag on /v2/block algod endpoint. (#557)
1 parent 71b02d5 commit 9a8e0f0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

algosdk/v2client/algod.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ def block_info(
270270
block: Optional[int] = None,
271271
response_format: str = "json",
272272
round_num: Optional[int] = None,
273+
header_only: Optional[bool] = None,
273274
**kwargs: Any,
274275
) -> AlgodResponseType:
275276
"""
@@ -280,8 +281,15 @@ def block_info(
280281
response_format (str): the format in which the response is
281282
returned: either "json" or "msgpack"
282283
round_num (int, optional): alias for block; specify one of these
284+
header_only (bool, optional): if set to true, only block header would be
285+
present in the the response
286+
283287
"""
284288
query = {"format": response_format}
289+
290+
if header_only:
291+
query["header-only"] = "true"
292+
285293
req = "/blocks/" + _specify_round_string(block, round_num)
286294
res = self.algod_request(
287295
"GET", req, query, response_format=response_format, **kwargs

tests/steps/other_v2_steps.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,19 @@ def block(context, block, response_format):
328328
)
329329

330330

331+
@when(
332+
'we make a Get Block call for round {round} with format "{response_format}" and header-only "{header_only}"'
333+
)
334+
def block(context, round, response_format, header_only):
335+
bool_opt = None
336+
if header_only == "true":
337+
bool_opt = True
338+
339+
context.response = context.acl.block_info(
340+
int(round), response_format=response_format, header_only=bool_opt
341+
)
342+
343+
331344
@when("we make any Get Block call")
332345
def block_any(context):
333346
context.response = context.acl.block_info(3, response_format="msgpack")
@@ -339,6 +352,17 @@ def parse_block(context, pool):
339352
assert context.response["block"]["rwd"] == pool
340353

341354

355+
@then(
356+
'the parsed Get Block response should have rewards pool "{pool}" and no certificate or payset'
357+
)
358+
def parse_block_header(context, pool):
359+
context.response = json.loads(context.response)
360+
assert context.response["block"]["rwd"] == pool
361+
assert (
362+
"cert" not in context.response
363+
), f"Key 'cert' unexpectedly found in dictionary"
364+
365+
342366
@then(
343367
'the parsed Get Block response should have heartbeat address "{hb_address}"'
344368
)
@@ -654,7 +678,6 @@ def parse_txns_by_addr(context, roundNum, length, idx, sender):
654678
'we make a Lookup Block call against round {block:d} and header "{headerOnly:MaybeBool}"'
655679
)
656680
def lookup_block(context, block, headerOnly):
657-
print("Header only = " + str(headerOnly))
658681
context.response = context.icl.block_info(
659682
block=block, header_only=headerOnly
660683
)

0 commit comments

Comments
 (0)