|
| 1 | +package com.algorand.algosdk.v2.client.algod; |
| 2 | + |
| 3 | +import com.algorand.algosdk.v2.client.common.Client; |
| 4 | +import com.algorand.algosdk.v2.client.common.HttpMethod; |
| 5 | +import com.algorand.algosdk.v2.client.common.Query; |
| 6 | +import com.algorand.algosdk.v2.client.common.QueryData; |
| 7 | +import com.algorand.algosdk.v2.client.common.Response; |
| 8 | +import com.algorand.algosdk.v2.client.model.BlockHashResponse; |
| 9 | + |
| 10 | + |
| 11 | +/** |
| 12 | + * Get the block hash for the block on the given round. |
| 13 | + * /v2/blocks/{round}/hash |
| 14 | + */ |
| 15 | +public class GetBlockHash extends Query { |
| 16 | + |
| 17 | + private Long round; |
| 18 | + |
| 19 | + /** |
| 20 | + * @param round The round from which to fetch block hash information. |
| 21 | + */ |
| 22 | + public GetBlockHash(Client client, Long round) { |
| 23 | + super(client, new HttpMethod("get")); |
| 24 | + this.round = round; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Execute the query. |
| 29 | + * @return the query response object. |
| 30 | + * @throws Exception |
| 31 | + */ |
| 32 | + @Override |
| 33 | + public Response<BlockHashResponse> execute() throws Exception { |
| 34 | + Response<BlockHashResponse> resp = baseExecute(); |
| 35 | + resp.setValueType(BlockHashResponse.class); |
| 36 | + return resp; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Execute the query with custom headers, there must be an equal number of keys and values |
| 41 | + * or else an error will be generated. |
| 42 | + * @param headers an array of header keys |
| 43 | + * @param values an array of header values |
| 44 | + * @return the query response object. |
| 45 | + * @throws Exception |
| 46 | + */ |
| 47 | + @Override |
| 48 | + public Response<BlockHashResponse> execute(String[] headers, String[] values) throws Exception { |
| 49 | + Response<BlockHashResponse> resp = baseExecute(headers, values); |
| 50 | + resp.setValueType(BlockHashResponse.class); |
| 51 | + return resp; |
| 52 | + } |
| 53 | + |
| 54 | + protected QueryData getRequestString() { |
| 55 | + if (this.round == null) { |
| 56 | + throw new RuntimeException("round is not set. It is a required parameter."); |
| 57 | + } |
| 58 | + addPathSegment(String.valueOf("v2")); |
| 59 | + addPathSegment(String.valueOf("blocks")); |
| 60 | + addPathSegment(String.valueOf(round)); |
| 61 | + addPathSegment(String.valueOf("hash")); |
| 62 | + |
| 63 | + return qd; |
| 64 | + } |
| 65 | +} |
0 commit comments