Skip to content

Commit 4fb86ec

Browse files
authored
Support for header-only flag on /v2/block algod endpoint. (#774)
1 parent 26166b7 commit 4fb86ec

File tree

6 files changed

+29
-111
lines changed

6 files changed

+29
-111
lines changed

src/main/java/com/algorand/algosdk/v2/client/algod/GetBlock.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public GetBlock(Client client, Long round) {
2525
this.round = round;
2626
}
2727

28+
/**
29+
* If true, only the block header (exclusive of payset or certificate) may be
30+
* included in response.
31+
*/
32+
public GetBlock headerOnly(Boolean headerOnly) {
33+
addQuery("header-only", String.valueOf(headerOnly));
34+
return this;
35+
}
36+
2837
/**
2938
* Execute the query.
3039
* @return the query response object.

src/main/java/com/algorand/algosdk/v2/client/algod/GetBlockHeader.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/main/java/com/algorand/algosdk/v2/client/common/AlgodClient.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.algorand.algosdk.v2.client.algod.GetBlock;
1414
import com.algorand.algosdk.v2.client.algod.GetBlockTxids;
1515
import com.algorand.algosdk.v2.client.algod.GetBlockHash;
16-
import com.algorand.algosdk.v2.client.algod.GetBlockHeader;
1716
import com.algorand.algosdk.v2.client.algod.GetTransactionProof;
1817
import com.algorand.algosdk.v2.client.algod.GetBlockLogs;
1918
import com.algorand.algosdk.v2.client.algod.GetSupply;
@@ -181,14 +180,6 @@ public GetBlockHash GetBlockHash(Long round) {
181180
return new GetBlockHash((Client) this, round);
182181
}
183182

184-
/**
185-
* Get the block header for the block on the given round.
186-
* /v2/blocks/{round}/header
187-
*/
188-
public GetBlockHeader GetBlockHeader(Long round) {
189-
return new GetBlockHeader((Client) this, round);
190-
}
191-
192183
/**
193184
* Get a proof for a transaction in a block.
194185
* /v2/blocks/{round}/transactions/{txid}/proof

src/main/java/com/algorand/algosdk/v2/client/model/BlockHeaderResponse.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/test/java/com/algorand/algosdk/unit/AlgodPaths.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
import com.algorand.algosdk.crypto.Address;
44
import com.algorand.algosdk.unit.utils.TestingUtils;
5-
import com.algorand.algosdk.v2.client.algod.AccountInformation;
6-
import com.algorand.algosdk.v2.client.algod.GetApplicationBoxes;
7-
import com.algorand.algosdk.v2.client.algod.GetPendingTransactions;
8-
import com.algorand.algosdk.v2.client.algod.GetPendingTransactionsByAddress;
9-
import com.algorand.algosdk.v2.client.algod.GetTransactionProof;
5+
import com.algorand.algosdk.v2.client.algod.*;
106
import com.algorand.algosdk.v2.client.common.AlgodClient;
117
import com.algorand.algosdk.v2.client.model.Enums;
128
import io.cucumber.java.en.When;
@@ -59,6 +55,19 @@ public void getBlock(Long round, String format) {
5955
ps.q = algodClient.GetBlock(round);
6056
}
6157

58+
@When("we make a Get Block call for round {int} with format {string} and header-only {string}")
59+
public void getBlockHeaderOnly(Integer round, String format, String headerOnly) {
60+
GetBlock gb = algodClient.GetBlock(Long.valueOf(round));
61+
62+
boolean headerOnlyBool = Boolean.parseBoolean(headerOnly);
63+
64+
if (headerOnlyBool) {
65+
gb.headerOnly(true);
66+
}
67+
68+
ps.q = gb;
69+
}
70+
6271
@When("we make a GetAssetByID call for assetID {long}")
6372
public void getAssetByID(Long id) {
6473
ps.q = algodClient.GetAssetByID(id);

src/test/java/com/algorand/algosdk/unit/AlgodResponses.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ public void the_parsed_Get_Block_response_should_have_rewards_pool(String string
139139
verifyResponse(blockResponse, shared.bodyFile);
140140
}
141141

142+
@Then("the parsed Get Block response should have rewards pool {string} and no certificate or payset")
143+
public void the_parsed_get_block_response_should_have_rewards_pool_and_no_certificate_or_payset(String string) throws IOException {
144+
verifyResponse(blockResponse, shared.bodyFile);
145+
}
146+
147+
142148
@Then("the parsed Get Block response should have heartbeat address {string}")
143149
public void the_parsed_Get_Block_response_should_have_heartbeat_address(String string) throws IOException {
144150
verifyResponse(blockResponse, shared.bodyFile);

0 commit comments

Comments
 (0)