diff --git a/src/main/java/com/algorand/algosdk/v2/client/algod/GetBlockHeader.java b/src/main/java/com/algorand/algosdk/v2/client/algod/GetBlockHeader.java new file mode 100644 index 000000000..db072ead8 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/algod/GetBlockHeader.java @@ -0,0 +1,66 @@ +package com.algorand.algosdk.v2.client.algod; + +import com.algorand.algosdk.v2.client.common.Client; +import com.algorand.algosdk.v2.client.common.HttpMethod; +import com.algorand.algosdk.v2.client.common.Query; +import com.algorand.algosdk.v2.client.common.QueryData; +import com.algorand.algosdk.v2.client.common.Response; +import com.algorand.algosdk.v2.client.model.BlockHeaderResponse; + + +/** + * Get the block header for the block on the given round. + * /v2/blocks/{round}/header + */ +public class GetBlockHeader extends Query { + + private Long round; + + /** + * @param round The round from which to fetch block header information. + */ + public GetBlockHeader(Client client, Long round) { + super(client, new HttpMethod("get")); + addQuery("format", "msgpack"); + this.round = round; + } + + /** + * Execute the query. + * @return the query response object. + * @throws Exception + */ + @Override + public Response execute() throws Exception { + Response resp = baseExecute(); + resp.setValueType(BlockHeaderResponse.class); + return resp; + } + + /** + * Execute the query with custom headers, there must be an equal number of keys and values + * or else an error will be generated. + * @param headers an array of header keys + * @param values an array of header values + * @return the query response object. + * @throws Exception + */ + @Override + public Response execute(String[] headers, String[] values) throws Exception { + Response resp = baseExecute(headers, values); + resp.setValueType(BlockHeaderResponse.class); + return resp; + } + + protected QueryData getRequestString() { + if (this.round == null) { + throw new RuntimeException("round is not set. It is a required parameter."); + } + addPathSegment(String.valueOf("v2")); + addPathSegment(String.valueOf("blocks")); + addPathSegment(String.valueOf(round)); + addPathSegment(String.valueOf("header")); + + return qd; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/common/AlgodClient.java b/src/main/java/com/algorand/algosdk/v2/client/common/AlgodClient.java index 813479cf0..94a22dfd9 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/common/AlgodClient.java +++ b/src/main/java/com/algorand/algosdk/v2/client/common/AlgodClient.java @@ -13,6 +13,7 @@ import com.algorand.algosdk.v2.client.algod.GetBlock; import com.algorand.algosdk.v2.client.algod.GetBlockTxids; import com.algorand.algosdk.v2.client.algod.GetBlockHash; +import com.algorand.algosdk.v2.client.algod.GetBlockHeader; import com.algorand.algosdk.v2.client.algod.GetTransactionProof; import com.algorand.algosdk.v2.client.algod.GetBlockLogs; import com.algorand.algosdk.v2.client.algod.GetSupply; @@ -180,6 +181,14 @@ public GetBlockHash GetBlockHash(Long round) { return new GetBlockHash((Client) this, round); } + /** + * Get the block header for the block on the given round. + * /v2/blocks/{round}/header + */ + public GetBlockHeader GetBlockHeader(Long round) { + return new GetBlockHeader((Client) this, round); + } + /** * Get a proof for a transaction in a block. * /v2/blocks/{round}/transactions/{txid}/proof diff --git a/src/main/java/com/algorand/algosdk/v2/client/indexer/LookupAccountByID.java b/src/main/java/com/algorand/algosdk/v2/client/indexer/LookupAccountByID.java index fc760b3ce..375b8dd5d 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/indexer/LookupAccountByID.java +++ b/src/main/java/com/algorand/algosdk/v2/client/indexer/LookupAccountByID.java @@ -50,7 +50,8 @@ public LookupAccountByID includeAll(Boolean includeAll) { } /** - * Include results for the specified round. + * Deprecated and disallowed. This parameter used to include results for a + * specified round. Requests with this parameter set are now rejected. */ public LookupAccountByID round(Long round) { addQuery("round", String.valueOf(round)); diff --git a/src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForAccounts.java b/src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForAccounts.java index d67db48a1..93efd9e3d 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForAccounts.java +++ b/src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForAccounts.java @@ -104,11 +104,8 @@ public SearchForAccounts next(String next) { } /** - * Include results for the specified round. For performance reasons, this parameter - * may be disabled on some configurations. Using application-id or asset-id filters - * will return both creator and opt-in accounts. Filtering by include-all will - * return creator and opt-in accounts for deleted assets and accounts. Non-opt-in - * managers are not included in the results when asset-id is used. + * Deprecated and disallowed. This parameter used to include results for a + * specified round. Requests with this parameter set are now rejected. */ public SearchForAccounts round(Long round) { addQuery("round", String.valueOf(round)); diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/BlockHeaderResponse.java b/src/main/java/com/algorand/algosdk/v2/client/model/BlockHeaderResponse.java new file mode 100644 index 000000000..3576edece --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/BlockHeaderResponse.java @@ -0,0 +1,31 @@ +package com.algorand.algosdk.v2.client.model; + +import java.util.HashMap; +import java.util.Objects; + +import com.algorand.algosdk.v2.client.common.PathResponse; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Block header. + */ +public class BlockHeaderResponse extends PathResponse { + + /** + * Block header data. + */ + @JsonProperty("blockHeader") + public HashMap blockHeader; + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + BlockHeaderResponse other = (BlockHeaderResponse) o; + if (!Objects.deepEquals(this.blockHeader, other.blockHeader)) return false; + + return true; + } +}