-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boxes: Support GetApplicationBoxes (#347)
- Loading branch information
1 parent
c478da8
commit 5a9d077
Showing
10 changed files
with
259 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/algorand/algosdk/v2/client/algod/GetApplicationBoxes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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, it returns the box names of that application. No | ||
* particular ordering is guaranteed. | ||
* /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<BoxesResponse> execute() throws Exception { | ||
Response<BoxesResponse> 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<BoxesResponse> execute(String[] headers, String[] values) throws Exception { | ||
Response<BoxesResponse> 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/algorand/algosdk/v2/client/model/BoxDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/algorand/algosdk/v2/client/model/BoxesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BoxDescriptor> boxes = new ArrayList<BoxDescriptor>(); | ||
|
||
@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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.