Skip to content

Commit 4f17900

Browse files
authored
api: Sync client object with latest spec. (#648)
1 parent 92cbfeb commit 4f17900

26 files changed

+870
-4
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.BlockTxidsResponse;
9+
10+
11+
/**
12+
* Get the top level transaction IDs for the block on the given round.
13+
* /v2/blocks/{round}/txids
14+
*/
15+
public class GetBlockTxids extends Query {
16+
17+
private Long round;
18+
19+
/**
20+
* @param round The round from which to fetch block transaction IDs.
21+
*/
22+
public GetBlockTxids(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<BlockTxidsResponse> execute() throws Exception {
34+
Response<BlockTxidsResponse> resp = baseExecute();
35+
resp.setValueType(BlockTxidsResponse.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<BlockTxidsResponse> execute(String[] headers, String[] values) throws Exception {
49+
Response<BlockTxidsResponse> resp = baseExecute(headers, values);
50+
resp.setValueType(BlockTxidsResponse.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("txids"));
62+
63+
return qd;
64+
}
65+
}

src/main/java/com/algorand/algosdk/v2/client/algod/WaitForBlock.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
/**
1212
* Waits for a block to appear after round {round} and returns the node's status at
13-
* the time.
13+
* the time. There is a 1 minute timeout, when reached the current status is
14+
* returned regardless of whether or not it is the round after the given round.
1415
* /v2/status/wait-for-block-after/{round}
1516
*/
1617
public class WaitForBlock extends Query {

src/main/java/com/algorand/algosdk/v2/client/common/AlgodClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.algorand.algosdk.v2.client.algod.AccountApplicationInformation;
1212
import com.algorand.algosdk.v2.client.algod.GetPendingTransactionsByAddress;
1313
import com.algorand.algosdk.v2.client.algod.GetBlock;
14+
import com.algorand.algosdk.v2.client.algod.GetBlockTxids;
1415
import com.algorand.algosdk.v2.client.algod.GetBlockHash;
1516
import com.algorand.algosdk.v2.client.algod.GetTransactionProof;
1617
import com.algorand.algosdk.v2.client.algod.GetSupply;
@@ -162,6 +163,14 @@ public GetBlock GetBlock(Long round) {
162163
return new GetBlock((Client) this, round);
163164
}
164165

166+
/**
167+
* Get the top level transaction IDs for the block on the given round.
168+
* /v2/blocks/{round}/txids
169+
*/
170+
public GetBlockTxids GetBlockTxids(Long round) {
171+
return new GetBlockTxids((Client) this, round);
172+
}
173+
165174
/**
166175
* Get the block hash for the block on the given round.
167176
* /v2/blocks/{round}/hash
@@ -197,7 +206,8 @@ public GetStatus GetStatus() {
197206

198207
/**
199208
* Waits for a block to appear after round {round} and returns the node's status at
200-
* the time.
209+
* the time. There is a 1 minute timeout, when reached the current status is
210+
* returned regardless of whether or not it is the round after the given round.
201211
* /v2/status/wait-for-block-after/{round}
202212
*/
203213
public WaitForBlock WaitForBlock(Long round) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.algorand.algosdk.v2.client.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Objects;
6+
7+
import com.algorand.algosdk.v2.client.common.PathResponse;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
/**
11+
* An application's initial global/local/box states that were accessed during
12+
* simulation.
13+
*/
14+
public class ApplicationInitialStates extends PathResponse {
15+
16+
/**
17+
* An application's global/local/box state.
18+
*/
19+
@JsonProperty("app-boxes")
20+
public ApplicationKVStorage appBoxes;
21+
22+
/**
23+
* An application's global/local/box state.
24+
*/
25+
@JsonProperty("app-globals")
26+
public ApplicationKVStorage appGlobals;
27+
28+
/**
29+
* An application's initial local states tied to different accounts.
30+
*/
31+
@JsonProperty("app-locals")
32+
public List<ApplicationKVStorage> appLocals = new ArrayList<ApplicationKVStorage>();
33+
34+
/**
35+
* Application index.
36+
*/
37+
@JsonProperty("id")
38+
public java.math.BigInteger id;
39+
40+
@Override
41+
public boolean equals(Object o) {
42+
43+
if (this == o) return true;
44+
if (o == null) return false;
45+
46+
ApplicationInitialStates other = (ApplicationInitialStates) o;
47+
if (!Objects.deepEquals(this.appBoxes, other.appBoxes)) return false;
48+
if (!Objects.deepEquals(this.appGlobals, other.appGlobals)) return false;
49+
if (!Objects.deepEquals(this.appLocals, other.appLocals)) return false;
50+
if (!Objects.deepEquals(this.id, other.id)) return false;
51+
52+
return true;
53+
}
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.algorand.algosdk.v2.client.model;
2+
3+
import java.security.NoSuchAlgorithmException;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Objects;
7+
8+
import com.algorand.algosdk.crypto.Address;
9+
import com.algorand.algosdk.v2.client.common.PathResponse;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
12+
/**
13+
* An application's global/local/box state.
14+
*/
15+
public class ApplicationKVStorage extends PathResponse {
16+
17+
/**
18+
* The address of the account associated with the local state.
19+
*/
20+
@JsonProperty("account")
21+
public void account(String account) throws NoSuchAlgorithmException {
22+
this.account = new Address(account);
23+
}
24+
@JsonProperty("account")
25+
public String account() throws NoSuchAlgorithmException {
26+
if (this.account != null) {
27+
return this.account.encodeAsString();
28+
} else {
29+
return null;
30+
}
31+
}
32+
public Address account;
33+
34+
/**
35+
* Key-Value pairs representing application states.
36+
*/
37+
@JsonProperty("kvs")
38+
public List<AvmKeyValue> kvs = new ArrayList<AvmKeyValue>();
39+
40+
@Override
41+
public boolean equals(Object o) {
42+
43+
if (this == o) return true;
44+
if (o == null) return false;
45+
46+
ApplicationKVStorage other = (ApplicationKVStorage) o;
47+
if (!Objects.deepEquals(this.account, other.account)) return false;
48+
if (!Objects.deepEquals(this.kvs, other.kvs)) return false;
49+
50+
return true;
51+
}
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.algorand.algosdk.v2.client.model;
2+
3+
import java.security.NoSuchAlgorithmException;
4+
import java.util.Objects;
5+
6+
import com.algorand.algosdk.crypto.Address;
7+
import com.algorand.algosdk.v2.client.common.PathResponse;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
/**
11+
* References an account's local state for an application.
12+
*/
13+
public class ApplicationLocalReference extends PathResponse {
14+
15+
/**
16+
* Address of the account with the local state.
17+
*/
18+
@JsonProperty("account")
19+
public void account(String account) throws NoSuchAlgorithmException {
20+
this.account = new Address(account);
21+
}
22+
@JsonProperty("account")
23+
public String account() throws NoSuchAlgorithmException {
24+
if (this.account != null) {
25+
return this.account.encodeAsString();
26+
} else {
27+
return null;
28+
}
29+
}
30+
public Address account;
31+
32+
/**
33+
* Application ID of the local state application.
34+
*/
35+
@JsonProperty("app")
36+
public java.math.BigInteger app;
37+
38+
@Override
39+
public boolean equals(Object o) {
40+
41+
if (this == o) return true;
42+
if (o == null) return false;
43+
44+
ApplicationLocalReference other = (ApplicationLocalReference) o;
45+
if (!Objects.deepEquals(this.account, other.account)) return false;
46+
if (!Objects.deepEquals(this.app, other.app)) return false;
47+
48+
return true;
49+
}
50+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.algorand.algosdk.v2.client.model;
2+
3+
import java.security.NoSuchAlgorithmException;
4+
import java.util.Objects;
5+
6+
import com.algorand.algosdk.crypto.Address;
7+
import com.algorand.algosdk.util.Encoder;
8+
import com.algorand.algosdk.v2.client.common.PathResponse;
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
11+
/**
12+
* An operation against an application's global/local/box state.
13+
*/
14+
public class ApplicationStateOperation extends PathResponse {
15+
16+
/**
17+
* For local state changes, the address of the account associated with the local
18+
* state.
19+
*/
20+
@JsonProperty("account")
21+
public void account(String account) throws NoSuchAlgorithmException {
22+
this.account = new Address(account);
23+
}
24+
@JsonProperty("account")
25+
public String account() throws NoSuchAlgorithmException {
26+
if (this.account != null) {
27+
return this.account.encodeAsString();
28+
} else {
29+
return null;
30+
}
31+
}
32+
public Address account;
33+
34+
/**
35+
* Type of application state. Value `g` is global state , `l` is local
36+
* state , `b` is boxes .
37+
*/
38+
@JsonProperty("app-state-type")
39+
public String appStateType;
40+
41+
/**
42+
* The key (name) of the global/local/box state.
43+
*/
44+
@JsonProperty("key")
45+
public void key(String base64Encoded) {
46+
this.key = Encoder.decodeFromBase64(base64Encoded);
47+
}
48+
public String key() {
49+
return Encoder.encodeToBase64(this.key);
50+
}
51+
public byte[] key;
52+
53+
/**
54+
* Represents an AVM value.
55+
*/
56+
@JsonProperty("new-value")
57+
public AvmValue newValue;
58+
59+
/**
60+
* Operation type. Value `w` is write , `d` is delete .
61+
*/
62+
@JsonProperty("operation")
63+
public String operation;
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
68+
if (this == o) return true;
69+
if (o == null) return false;
70+
71+
ApplicationStateOperation other = (ApplicationStateOperation) o;
72+
if (!Objects.deepEquals(this.account, other.account)) return false;
73+
if (!Objects.deepEquals(this.appStateType, other.appStateType)) return false;
74+
if (!Objects.deepEquals(this.key, other.key)) return false;
75+
if (!Objects.deepEquals(this.newValue, other.newValue)) return false;
76+
if (!Objects.deepEquals(this.operation, other.operation)) return false;
77+
78+
return true;
79+
}
80+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.algorand.algosdk.v2.client.model;
2+
3+
import java.security.NoSuchAlgorithmException;
4+
import java.util.Objects;
5+
6+
import com.algorand.algosdk.crypto.Address;
7+
import com.algorand.algosdk.v2.client.common.PathResponse;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
10+
/**
11+
* References an asset held by an account.
12+
*/
13+
public class AssetHoldingReference extends PathResponse {
14+
15+
/**
16+
* Address of the account holding the asset.
17+
*/
18+
@JsonProperty("account")
19+
public void account(String account) throws NoSuchAlgorithmException {
20+
this.account = new Address(account);
21+
}
22+
@JsonProperty("account")
23+
public String account() throws NoSuchAlgorithmException {
24+
if (this.account != null) {
25+
return this.account.encodeAsString();
26+
} else {
27+
return null;
28+
}
29+
}
30+
public Address account;
31+
32+
/**
33+
* Asset ID of the holding.
34+
*/
35+
@JsonProperty("asset")
36+
public java.math.BigInteger asset;
37+
38+
@Override
39+
public boolean equals(Object o) {
40+
41+
if (this == o) return true;
42+
if (o == null) return false;
43+
44+
AssetHoldingReference other = (AssetHoldingReference) o;
45+
if (!Objects.deepEquals(this.account, other.account)) return false;
46+
if (!Objects.deepEquals(this.asset, other.asset)) return false;
47+
48+
return true;
49+
}
50+
}

0 commit comments

Comments
 (0)