From 3be4f38fd2a74e71a10cccdf1778d29b174fe154 Mon Sep 17 00:00:00 2001 From: Algorand Generation Bot Date: Mon, 23 Dec 2024 23:25:30 +0000 Subject: [PATCH] Regenerate code from specification file --- .../v2/client/algod/AccountInformation.java | 2 +- .../v2/client/algod/GetBlockHeader.java | 66 +++++++++ .../algosdk/v2/client/common/AlgodClient.java | 11 +- .../v2/client/common/IndexerClient.java | 10 ++ .../v2/client/indexer/LookupAccountByID.java | 3 +- .../v2/client/indexer/SearchForAccounts.java | 7 +- .../client/indexer/SearchForBlockHeaders.java | 138 ++++++++++++++++++ .../v2/client/model/BlockHeaderResponse.java | 31 ++++ .../v2/client/model/BlockHeadersResponse.java | 41 ++++++ .../algosdk/v2/client/model/Enums.java | 2 + .../v2/client/model/HbProofFields.java | 92 ++++++++++++ .../algosdk/v2/client/model/Transaction.java | 10 ++ .../v2/client/model/TransactionHeartbeat.java | 75 ++++++++++ 13 files changed, 480 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/algorand/algosdk/v2/client/algod/GetBlockHeader.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForBlockHeaders.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/BlockHeaderResponse.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/BlockHeadersResponse.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/HbProofFields.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/TransactionHeartbeat.java diff --git a/src/main/java/com/algorand/algosdk/v2/client/algod/AccountInformation.java b/src/main/java/com/algorand/algosdk/v2/client/algod/AccountInformation.java index efdb465c5..77e8277b8 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/algod/AccountInformation.java +++ b/src/main/java/com/algorand/algosdk/v2/client/algod/AccountInformation.java @@ -11,7 +11,7 @@ /** - * Given a specific account public key, this call returns the accounts status, + * Given a specific account public key, this call returns the account's status, * balance and spendable amounts * /v2/accounts/{address} */ 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..37a045629 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; @@ -115,7 +116,7 @@ public GetVersion GetVersion() { } /** - * Given a specific account public key, this call returns the accounts status, + * Given a specific account public key, this call returns the account's status, * balance and spendable amounts * /v2/accounts/{address} */ @@ -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/common/IndexerClient.java b/src/main/java/com/algorand/algosdk/v2/client/common/IndexerClient.java index 3ca218bbf..b7392e4b7 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/common/IndexerClient.java +++ b/src/main/java/com/algorand/algosdk/v2/client/common/IndexerClient.java @@ -17,6 +17,7 @@ import com.algorand.algosdk.v2.client.indexer.LookupAssetByID; import com.algorand.algosdk.v2.client.indexer.LookupAssetBalances; import com.algorand.algosdk.v2.client.indexer.LookupAssetTransactions; +import com.algorand.algosdk.v2.client.indexer.SearchForBlockHeaders; import com.algorand.algosdk.v2.client.indexer.LookupBlock; import com.algorand.algosdk.v2.client.indexer.LookupTransaction; import com.algorand.algosdk.v2.client.indexer.SearchForTransactions; @@ -196,6 +197,15 @@ public LookupAssetTransactions lookupAssetTransactions(Long assetId) { return new LookupAssetTransactions((Client) this, assetId); } + /** + * Search for block headers. Block headers are returned in ascending round order. + * Transactions are not included in the output. + * /v2/block-headers + */ + public SearchForBlockHeaders searchForBlockHeaders() { + return new SearchForBlockHeaders((Client) this); + } + /** * Lookup block. * /v2/blocks/{round-number} 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/indexer/SearchForBlockHeaders.java b/src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForBlockHeaders.java new file mode 100644 index 000000000..5b677c583 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/indexer/SearchForBlockHeaders.java @@ -0,0 +1,138 @@ +package com.algorand.algosdk.v2.client.indexer; + +import java.util.Date; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + +import com.algorand.algosdk.crypto.Address; +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.common.Utils; +import com.algorand.algosdk.v2.client.model.BlockHeadersResponse; + + +/** + * Search for block headers. Block headers are returned in ascending round order. + * Transactions are not included in the output. + * /v2/block-headers + */ +public class SearchForBlockHeaders extends Query { + + public SearchForBlockHeaders(Client client) { + super(client, new HttpMethod("get")); + } + + /** + * Accounts marked as absent in the block header's participation updates. This + * parameter accepts a comma separated list of addresses. + */ + public SearchForBlockHeaders absent(List
absent) { + addQuery("absent", StringUtils.join(absent, ",")); + return this; + } + + /** + * Include results after the given time. Must be an RFC 3339 formatted string. + */ + public SearchForBlockHeaders afterTime(Date afterTime) { + addQuery("after-time", Utils.getDateString(afterTime)); + return this; + } + + /** + * Include results before the given time. Must be an RFC 3339 formatted string. + */ + public SearchForBlockHeaders beforeTime(Date beforeTime) { + addQuery("before-time", Utils.getDateString(beforeTime)); + return this; + } + + /** + * Accounts marked as expired in the block header's participation updates. This + * parameter accepts a comma separated list of addresses. + */ + public SearchForBlockHeaders expired(List
expired) { + addQuery("expired", StringUtils.join(expired, ",")); + return this; + } + + /** + * Maximum number of results to return. There could be additional pages even if the + * limit is not reached. + */ + public SearchForBlockHeaders limit(Long limit) { + addQuery("limit", String.valueOf(limit)); + return this; + } + + /** + * Include results at or before the specified max-round. + */ + public SearchForBlockHeaders maxRound(Long maxRound) { + addQuery("max-round", String.valueOf(maxRound)); + return this; + } + + /** + * Include results at or after the specified min-round. + */ + public SearchForBlockHeaders minRound(Long minRound) { + addQuery("min-round", String.valueOf(minRound)); + return this; + } + + /** + * The next page of results. Use the next token provided by the previous results. + */ + public SearchForBlockHeaders next(String next) { + addQuery("next", String.valueOf(next)); + return this; + } + + /** + * Accounts marked as proposer in the block header's participation updates. This + * parameter accepts a comma separated list of addresses. + */ + public SearchForBlockHeaders proposers(List
proposers) { + addQuery("proposers", StringUtils.join(proposers, ",")); + return this; + } + + /** + * Execute the query. + * @return the query response object. + * @throws Exception + */ + @Override + public Response execute() throws Exception { + Response resp = baseExecute(); + resp.setValueType(BlockHeadersResponse.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(BlockHeadersResponse.class); + return resp; + } + + protected QueryData getRequestString() { + addPathSegment(String.valueOf("v2")); + addPathSegment(String.valueOf("block-headers")); + + return qd; + } +} 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; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/BlockHeadersResponse.java b/src/main/java/com/algorand/algosdk/v2/client/model/BlockHeadersResponse.java new file mode 100644 index 000000000..b9ee52530 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/BlockHeadersResponse.java @@ -0,0 +1,41 @@ +package com.algorand.algosdk.v2.client.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import com.algorand.algosdk.v2.client.common.PathResponse; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class BlockHeadersResponse extends PathResponse { + + @JsonProperty("blocks") + public List blocks = new ArrayList(); + + /** + * Round at which the results were computed. + */ + @JsonProperty("current-round") + public Long currentRound; + + /** + * Used for pagination, when making another request provide this token with the + * next parameter. + */ + @JsonProperty("next-token") + public String nextToken; + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + BlockHeadersResponse other = (BlockHeadersResponse) o; + if (!Objects.deepEquals(this.blocks, other.blocks)) return false; + if (!Objects.deepEquals(this.currentRound, other.currentRound)) return false; + if (!Objects.deepEquals(this.nextToken, other.nextToken)) return false; + + return true; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/Enums.java b/src/main/java/com/algorand/algosdk/v2/client/model/Enums.java index eee96c87f..8575fa1e9 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/model/Enums.java +++ b/src/main/java/com/algorand/algosdk/v2/client/model/Enums.java @@ -191,6 +191,7 @@ public static SigType forValue(String value) { * (afrz) asset-freeze-transaction * (appl) application-transaction * (stpf) state-proof-transaction + * (hb) heartbeat-transaction */ public enum TxType { @JsonProperty("pay") PAY("pay"), @@ -200,6 +201,7 @@ public enum TxType { @JsonProperty("afrz") AFRZ("afrz"), @JsonProperty("appl") APPL("appl"), @JsonProperty("stpf") STPF("stpf"), + @JsonProperty("hb") HB("hb"), @JsonProperty("") UNKNOWN(""); final String serializedName; diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/HbProofFields.java b/src/main/java/com/algorand/algosdk/v2/client/model/HbProofFields.java new file mode 100644 index 000000000..d47675fd6 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/HbProofFields.java @@ -0,0 +1,92 @@ +package com.algorand.algosdk.v2.client.model; + +import java.util.Objects; + +import com.algorand.algosdk.util.Encoder; +import com.algorand.algosdk.v2.client.common.PathResponse; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * (hbprf) HbProof is a signature using HeartbeatAddress's partkey, thereby showing + * it is online. + */ +public class HbProofFields extends PathResponse { + + /** + * (p) Public key of the heartbeat message. + */ + @JsonProperty("hb-pk") + public void hbPk(String base64Encoded) { + this.hbPk = Encoder.decodeFromBase64(base64Encoded); + } + public String hbPk() { + return Encoder.encodeToBase64(this.hbPk); + } + public byte[] hbPk; + + /** + * (p1s) Signature of OneTimeSignatureSubkeyOffsetID(PK, Batch, Offset) under the + * key PK2. + */ + @JsonProperty("hb-pk1sig") + public void hbPk1sig(String base64Encoded) { + this.hbPk1sig = Encoder.decodeFromBase64(base64Encoded); + } + public String hbPk1sig() { + return Encoder.encodeToBase64(this.hbPk1sig); + } + public byte[] hbPk1sig; + + /** + * (p2) Key for new-style two-level ephemeral signature. + */ + @JsonProperty("hb-pk2") + public void hbPk2(String base64Encoded) { + this.hbPk2 = Encoder.decodeFromBase64(base64Encoded); + } + public String hbPk2() { + return Encoder.encodeToBase64(this.hbPk2); + } + public byte[] hbPk2; + + /** + * (p2s) Signature of OneTimeSignatureSubkeyBatchID(PK2, Batch) under the master + * key (OneTimeSignatureVerifier). + */ + @JsonProperty("hb-pk2sig") + public void hbPk2sig(String base64Encoded) { + this.hbPk2sig = Encoder.decodeFromBase64(base64Encoded); + } + public String hbPk2sig() { + return Encoder.encodeToBase64(this.hbPk2sig); + } + public byte[] hbPk2sig; + + /** + * (s) Signature of the heartbeat message. + */ + @JsonProperty("hb-sig") + public void hbSig(String base64Encoded) { + this.hbSig = Encoder.decodeFromBase64(base64Encoded); + } + public String hbSig() { + return Encoder.encodeToBase64(this.hbSig); + } + public byte[] hbSig; + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + HbProofFields other = (HbProofFields) o; + if (!Objects.deepEquals(this.hbPk, other.hbPk)) return false; + if (!Objects.deepEquals(this.hbPk1sig, other.hbPk1sig)) return false; + if (!Objects.deepEquals(this.hbPk2, other.hbPk2)) return false; + if (!Objects.deepEquals(this.hbPk2sig, other.hbPk2sig)) return false; + if (!Objects.deepEquals(this.hbSig, other.hbSig)) return false; + + return true; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/Transaction.java b/src/main/java/com/algorand/algosdk/v2/client/model/Transaction.java index 1ac8a4423..c7a89c3a7 100644 --- a/src/main/java/com/algorand/algosdk/v2/client/model/Transaction.java +++ b/src/main/java/com/algorand/algosdk/v2/client/model/Transaction.java @@ -156,6 +156,14 @@ public String group() { } public byte[] group; + /** + * Fields for a heartbeat transaction. + * Definition: + * data/transactions/heartbeat.go : HeartbeatTxnFields + */ + @JsonProperty("heartbeat-transaction") + public TransactionHeartbeat heartbeatTransaction; + /** * Transaction ID */ @@ -321,6 +329,7 @@ public String rekeyTo() throws NoSuchAlgorithmException { * (afrz) asset-freeze-transaction * (appl) application-transaction * (stpf) state-proof-transaction + * (hb) heartbeat-transaction */ @JsonProperty("tx-type") public Enums.TxType txType; @@ -348,6 +357,7 @@ public boolean equals(Object o) { if (!Objects.deepEquals(this.genesisId, other.genesisId)) return false; if (!Objects.deepEquals(this.globalStateDelta, other.globalStateDelta)) return false; if (!Objects.deepEquals(this.group, other.group)) return false; + if (!Objects.deepEquals(this.heartbeatTransaction, other.heartbeatTransaction)) return false; if (!Objects.deepEquals(this.id, other.id)) return false; if (!Objects.deepEquals(this.innerTxns, other.innerTxns)) return false; if (!Objects.deepEquals(this.intraRoundOffset, other.intraRoundOffset)) return false; diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/TransactionHeartbeat.java b/src/main/java/com/algorand/algosdk/v2/client/model/TransactionHeartbeat.java new file mode 100644 index 000000000..dff70bad2 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/TransactionHeartbeat.java @@ -0,0 +1,75 @@ +package com.algorand.algosdk.v2.client.model; + +import java.util.Objects; + +import com.algorand.algosdk.util.Encoder; +import com.algorand.algosdk.v2.client.common.PathResponse; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Fields for a heartbeat transaction. + * Definition: + * data/transactions/heartbeat.go : HeartbeatTxnFields + */ +public class TransactionHeartbeat extends PathResponse { + + /** + * (hbad) HbAddress is the account this txn is proving onlineness for. + */ + @JsonProperty("hb-address") + public String hbAddress; + + /** + * (hbkd) HbKeyDilution must match HbAddress account's current KeyDilution. + */ + @JsonProperty("hb-key-dilution") + public java.math.BigInteger hbKeyDilution; + + /** + * (hbprf) HbProof is a signature using HeartbeatAddress's partkey, thereby showing + * it is online. + */ + @JsonProperty("hb-proof") + public HbProofFields hbProof; + + /** + * (hbsd) HbSeed must be the block seed for the this transaction's firstValid + * block. + */ + @JsonProperty("hb-seed") + public void hbSeed(String base64Encoded) { + this.hbSeed = Encoder.decodeFromBase64(base64Encoded); + } + public String hbSeed() { + return Encoder.encodeToBase64(this.hbSeed); + } + public byte[] hbSeed; + + /** + * (hbvid) HbVoteID must match the HbAddress account's current VoteID. + */ + @JsonProperty("hb-vote-id") + public void hbVoteId(String base64Encoded) { + this.hbVoteId = Encoder.decodeFromBase64(base64Encoded); + } + public String hbVoteId() { + return Encoder.encodeToBase64(this.hbVoteId); + } + public byte[] hbVoteId; + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + TransactionHeartbeat other = (TransactionHeartbeat) o; + if (!Objects.deepEquals(this.hbAddress, other.hbAddress)) return false; + if (!Objects.deepEquals(this.hbKeyDilution, other.hbKeyDilution)) return false; + if (!Objects.deepEquals(this.hbProof, other.hbProof)) return false; + if (!Objects.deepEquals(this.hbSeed, other.hbSeed)) return false; + if (!Objects.deepEquals(this.hbVoteId, other.hbVoteId)) return false; + + return true; + } +}