From a5da1e5c011e66de8dd6f325490353705aa7a4cf Mon Sep 17 00:00:00 2001 From: Algorand Generation Bot Date: Mon, 31 Oct 2022 23:31:13 +0000 Subject: [PATCH] Regenerate code from specification file --- .../client/algod/GetApplicationBoxByName.java | 82 +++++++++++++++++++ .../v2/client/algod/GetApplicationBoxes.java | 76 +++++++++++++++++ .../algosdk/v2/client/common/AlgodClient.java | 24 ++++++ .../algorand/algosdk/v2/client/model/Box.java | 50 +++++++++++ .../v2/client/model/BoxDescriptor.java | 37 +++++++++ .../v2/client/model/BoxesResponse.java | 29 +++++++ 6 files changed, 298 insertions(+) create mode 100644 src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxByName.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxes.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/Box.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/BoxDescriptor.java create mode 100644 src/main/java/com/algorand/algosdk/v2/client/model/BoxesResponse.java diff --git a/src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxByName.java b/src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxByName.java new file mode 100644 index 000000000..2eab16704 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxByName.java @@ -0,0 +1,82 @@ +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.Box; + + +/** + * Given an application ID and box name, it returns the box name and value (each + * base64 encoded). Box names must be in the goal app call arg encoding form + * 'encoding:value'. For ints, use the form 'int:1234'. For raw bytes, use the form + * 'b64:A=='. For printable strings, use the form 'str:hello'. For addresses, use + * the form 'addr:XYZ...'. + * /v2/applications/{application-id}/box + */ +public class GetApplicationBoxByName extends Query { + + private Long applicationId; + + /** + * @param applicationId An application identifier + */ + public GetApplicationBoxByName(Client client, Long applicationId) { + super(client, new HttpMethod("get")); + this.applicationId = applicationId; + } + + /** + * A box name, in the goal app call arg form 'encoding:value'. For ints, use the + * form 'int:1234'. For raw bytes, use the form 'b64:A=='. For printable strings, + * use the form 'str:hello'. For addresses, use the form 'addr:XYZ...'. + */ + public GetApplicationBoxByName name(String name) { + addQuery("name", String.valueOf(name)); + return this; + } + + /** + * Execute the query. + * @return the query response object. + * @throws Exception + */ + @Override + public Response execute() throws Exception { + Response resp = baseExecute(); + resp.setValueType(Box.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(Box.class); + return resp; + } + + protected QueryData getRequestString() { + if (this.applicationId == null) { + throw new RuntimeException("application-id is not set. It is a required parameter."); + } + if (!qd.queries.containsKey("name")) { + throw new RuntimeException("name is not set. It is a required parameter."); + } + addPathSegment(String.valueOf("v2")); + addPathSegment(String.valueOf("applications")); + addPathSegment(String.valueOf(applicationId)); + addPathSegment(String.valueOf("box")); + + return qd; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxes.java b/src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxes.java new file mode 100644 index 000000000..f8a734254 --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxes.java @@ -0,0 +1,76 @@ +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.BoxesResponse; + + +/** + * Given an application ID, return all Box names. No particular ordering is + * guaranteed. Request fails when client or server-side configured limits prevent + * returning all Box names. + * /v2/applications/{application-id}/boxes + */ +public class GetApplicationBoxes extends Query { + + private Long applicationId; + + /** + * @param applicationId An application identifier + */ + public GetApplicationBoxes(Client client, Long applicationId) { + super(client, new HttpMethod("get")); + this.applicationId = applicationId; + } + + /** + * Max number of box names to return. If max is not set, or max == 0, returns all + * box-names. + */ + public GetApplicationBoxes max(Long max) { + addQuery("max", String.valueOf(max)); + return this; + } + + /** + * Execute the query. + * @return the query response object. + * @throws Exception + */ + @Override + public Response execute() throws Exception { + Response resp = baseExecute(); + resp.setValueType(BoxesResponse.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(BoxesResponse.class); + return resp; + } + + protected QueryData getRequestString() { + if (this.applicationId == null) { + throw new RuntimeException("application-id is not set. It is a required parameter."); + } + addPathSegment(String.valueOf("v2")); + addPathSegment(String.valueOf("applications")); + addPathSegment(String.valueOf(applicationId)); + addPathSegment(String.valueOf("boxes")); + + 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 f37482abf..6211aefa2 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 @@ -22,6 +22,8 @@ import com.algorand.algosdk.v2.client.algod.GetStateProof; import com.algorand.algosdk.v2.client.algod.GetLightBlockHeaderProof; import com.algorand.algosdk.v2.client.algod.GetApplicationByID; +import com.algorand.algosdk.v2.client.algod.GetApplicationBoxes; +import com.algorand.algosdk.v2.client.algod.GetApplicationBoxByName; import com.algorand.algosdk.v2.client.algod.GetAssetByID; import com.algorand.algosdk.v2.client.algod.TealCompile; import com.algorand.algosdk.v2.client.algod.TealDisassemble; @@ -249,6 +251,28 @@ public GetApplicationByID GetApplicationByID(Long applicationId) { return new GetApplicationByID((Client) this, applicationId); } + /** + * Given an application ID, return all Box names. No particular ordering is + * guaranteed. Request fails when client or server-side configured limits prevent + * returning all Box names. + * /v2/applications/{application-id}/boxes + */ + public GetApplicationBoxes GetApplicationBoxes(Long applicationId) { + return new GetApplicationBoxes((Client) this, applicationId); + } + + /** + * Given an application ID and box name, it returns the box name and value (each + * base64 encoded). Box names must be in the goal app call arg encoding form + * 'encoding:value'. For ints, use the form 'int:1234'. For raw bytes, use the form + * 'b64:A=='. For printable strings, use the form 'str:hello'. For addresses, use + * the form 'addr:XYZ...'. + * /v2/applications/{application-id}/box + */ + public GetApplicationBoxByName GetApplicationBoxByName(Long applicationId) { + return new GetApplicationBoxByName((Client) this, applicationId); + } + /** * Given a asset ID, it returns asset information including creator, name, total * supply and special addresses. diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/Box.java b/src/main/java/com/algorand/algosdk/v2/client/model/Box.java new file mode 100644 index 000000000..326593c4a --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/Box.java @@ -0,0 +1,50 @@ +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; + +/** + * Box name and its content. + */ +public class Box extends PathResponse { + + /** + * (name) box name, base64 encoded + */ + @JsonProperty("name") + public void name(String base64Encoded) { + this.name = Encoder.decodeFromBase64(base64Encoded); + } + public String name() { + return Encoder.encodeToBase64(this.name); + } + public byte[] name; + + /** + * (value) box value, base64 encoded. + */ + @JsonProperty("value") + public void value(String base64Encoded) { + this.value = Encoder.decodeFromBase64(base64Encoded); + } + public String value() { + return Encoder.encodeToBase64(this.value); + } + public byte[] value; + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + Box other = (Box) o; + if (!Objects.deepEquals(this.name, other.name)) return false; + if (!Objects.deepEquals(this.value, other.value)) return false; + + return true; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/BoxDescriptor.java b/src/main/java/com/algorand/algosdk/v2/client/model/BoxDescriptor.java new file mode 100644 index 000000000..9a4a4335b --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/BoxDescriptor.java @@ -0,0 +1,37 @@ +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; + +/** + * Box descriptor describes a Box. + */ +public class BoxDescriptor extends PathResponse { + + /** + * Base64 encoded box name + */ + @JsonProperty("name") + public void name(String base64Encoded) { + this.name = Encoder.decodeFromBase64(base64Encoded); + } + public String name() { + return Encoder.encodeToBase64(this.name); + } + public byte[] name; + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + BoxDescriptor other = (BoxDescriptor) o; + if (!Objects.deepEquals(this.name, other.name)) return false; + + return true; + } +} diff --git a/src/main/java/com/algorand/algosdk/v2/client/model/BoxesResponse.java b/src/main/java/com/algorand/algosdk/v2/client/model/BoxesResponse.java new file mode 100644 index 000000000..3b8740b4b --- /dev/null +++ b/src/main/java/com/algorand/algosdk/v2/client/model/BoxesResponse.java @@ -0,0 +1,29 @@ +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; + +/** + * Box names of an application + */ +public class BoxesResponse extends PathResponse { + + @JsonProperty("boxes") + public List boxes = new ArrayList(); + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null) return false; + + BoxesResponse other = (BoxesResponse) o; + if (!Objects.deepEquals(this.boxes, other.boxes)) return false; + + return true; + } +}