Skip to content

Commit 26f0553

Browse files
committed
Merge branch 'release/1.6.0'
2 parents 7d046d9 + dc8ffb3 commit 26f0553

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1054
-109
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# java-algorand-sdk stuff
2+
test-harness/
3+
src/test/resources/generated_responses/
4+
*.feature
5+
src/test/resources/**/*.json
6+
src/test/resources/**/*.base64
7+
src/test/resources/**/*.teal
8+
src/test/resources/**/*.tok
9+
110
# OS X
211
.DS_Store
312

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ dist: bionic
22
language: java
33

44
script:
5+
- if [ -n "$DOCKER_PASSWORD" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin ; fi
56
- make docker-test
7+
env:
8+
global:
9+
- secure: Qr2fZRtZke1S8l9nElsCxfa99KA+1xkIbG8Qlltndp6m9FaH1bSeLbjqzwRFn3BhdQlHRLH+Dn9hmJPjPkWFCUrQ1WH6iZOKqN8nekzlcgQAKz6f201Rw3O3HSMu3HGrnAyJW7XLQNNtUpunBLhwvGoHCQG3jf3J0J0vJ88w/gRPyBzD11SF7OjBhNNabqF5/TpJbSXaFzntJXbaFGDkf2ZenK3dpVrObUiCJCnud9QDupwVx36/8PP+dx259+UIKtMZfWSutqCF0IPRjyEl+J+VKTAriyayNtSmmWR4qJYER3eG84Hx8YfF1O+l8yED4KlUE8Plg0OV6TPcNyD8kxW9LK259BFMNlTsSwxdvYFLEBDkz/iHfwRqdrt6B09ftawDBhy0g9+opq31KJkvMLzPhw7nTzlG3ZwN2gyTZ5+daGSeh/mbQ1o2n2sTR/uxRnmbpzmuOBTpkk7IlDsm9bfkaLubx+ATTFcjlBKWCXJexdX9y00wWXy+j60qoe9LeSK6I1TzBvjYpPE5YZj1qfuFxvwnMwwGAqHT3o6w1LVU4Mb/7GZXqugrR8Xtt1YHUUD4kTWCMpp+ZWbOTHT7pVyFUgltpJmOuNxYeaQxsXyFyqhByhFQeVJHcNrbF6/S0o5RbqHpPOZaJUxEizqyIVSFJ/LG/3ig6dOwWTDf5ts=
10+
- secure: ZmuRqWki11IkNQDqCCuaqTVF/YPJiPLInUVsExz1n5L8IzH8ltGjGaSNbFzvp/9k3VfGRdQhwHC2rO1xjadGR1Py1MPjeo2GFCilsd/AXDPyneoO8WKxUKVaA7yogGM2pKEEZNnp+psT92uQUERXLRc0obS+kYANwq5EbTK/FhNmPrWKoMshqpSYx4AsIyqcJCAX45rbw3+87SlcQaqIHEFnBNZ39c5R8WWkuJLK6GKliAYelh0bZ3dEYtfwIMNrpXlmEI8SEQbtRJziH7pOuOuuSFSspd6VvQscU/aSV7G99Fi7Bu7+aD27J0qAQQBcLAQI+/CFY+Tmqr5QT/4TFy7envfea7AVm585rN1+t07V2L+H7NBBKYpdagiJve2XOetPXwJKXt/Ak0CwVchvYuTCfl2+Gx1Ca4WZm0i2LBOF7tNaiiXg4vnepobQgnRIuUMDZR1ysNdXis+oyExrHb9aS/yThhgUIKO+O9/0IQauYGMMhbiL6NLA61VG5OY0QQYr76R68gb24+MPPe8Bu8MrFeuPsA5Q5UdBPNP1D6NX7cja3mphNjxmrjC3Splndcr1qfa+6lheqTNFHpB6MUg+1iU3buOkUrQ7wZvPihvbwGdRYnLfn5rJdPA7yg9WIX0/SJE5/8k1N/7zXDGAuAJPr9+BqcbgKCOEe5IY3mU=

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# 1.6.0
2+
- Add static qualifiers to json creators for onCompletion enum serialization.
3+
- Bump guava from 28.2-android to 29.0-android in /generator.
4+
- Bump guava from 28.2-android to 29.0-android.
5+
- Corrected Exception message for Keccak-256 hash function.
6+
- Add TEAL 3 support.
7+
- Regenerated comment.
8+
- Fix custom token key comment.
9+
- Update .gitignore.
10+
- Regenerate Indexer Client.
11+
- Regenerate client code, implement new cucumber tests.
12+
- Fix base32 decode bug.
13+
- Add secure vars and docker login.
14+
- Don't override values with lookupParams/suggestedParams.
15+
- New constructors for v2 and Indexer that also accepts tokenKey.
16+
- Updated README example.
17+
118
# 1.5.1
219
- Add custom header option to v2 client, new 'execute' method on each endpoint request.
320

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
unit:
2-
mvn test -Dcucumber.filter.tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.indexer.rekey or @unit.transactions or @unit.responses or @unit.applications or @unit.dryrun or @unit.tealsign or @unit.responses.messagepack"
2+
mvn test -Dcucumber.filter.tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.indexer.rekey or @unit.transactions or @unit.responses or @unit.applications or @unit.dryrun or @unit.tealsign or @unit.responses.messagepack or @unit.responses.231 or @unit.responses.messagepack.231"
33

44
integration:
5-
mvn test -Dcucumber.filter.tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @rekey or @applications.verified or @applications or @compile or @dryrun or @indexer.applications or @applications.evaldelta"
5+
mvn test -Dcucumber.filter.tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @rekey or @applications.verified or @applications or @compile or @dryrun or @indexer.applications or @applications.evaldelta or @indexer.231"
6+
67
docker-test:
78
./run_integration_tests.sh

README.md

Lines changed: 133 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,152 @@ Maven:
2323
<dependency>
2424
<groupId>com.algorand</groupId>
2525
<artifactId>algosdk</artifactId>
26-
<version>1.5.1</version>
26+
<version>1.6.0</version>
2727
</dependency>
2828
```
2929

3030
# Quickstart
3131

32+
This program connects to a running [sandbox](https://github.com/algorand/sandbox) private network, creates a payment transaction between two of the accounts, signs it with kmd, and reads result from Indexer.
3233
```java
33-
package com.algorand.algosdk.example;
34+
import com.algorand.algosdk.account.Account;
35+
import com.algorand.algosdk.crypto.Address;
36+
import com.algorand.algosdk.kmd.client.ApiException;
37+
import com.algorand.algosdk.kmd.client.KmdClient;
38+
import com.algorand.algosdk.kmd.client.api.KmdApi;
39+
import com.algorand.algosdk.kmd.client.model.*;
40+
import com.algorand.algosdk.transaction.SignedTransaction;
41+
import com.algorand.algosdk.transaction.Transaction;
42+
import com.algorand.algosdk.util.Encoder;
43+
import com.algorand.algosdk.v2.client.common.AlgodClient;
44+
import com.algorand.algosdk.v2.client.common.IndexerClient;
45+
import com.algorand.algosdk.v2.client.common.Response;
46+
import com.algorand.algosdk.v2.client.model.PendingTransactionResponse;
47+
import com.algorand.algosdk.v2.client.model.PostTransactionsResponse;
48+
import com.algorand.algosdk.v2.client.model.TransactionsResponse;
49+
50+
import java.io.IOException;
51+
import java.security.NoSuchAlgorithmException;
52+
import java.util.ArrayList;
53+
import java.util.Arrays;
54+
import java.util.List;
3455

35-
import com.algorand.algosdk.algod.client.AlgodClient;
36-
import com.algorand.algosdk.algod.client.ApiException;
37-
import com.algorand.algosdk.algod.client.api.AlgodApi;
38-
import com.algorand.algosdk.algod.client.auth.ApiKeyAuth;
39-
import com.algorand.algosdk.algod.client.model.NodeStatus;
56+
public class Main {
57+
private static String token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
58+
private static KmdApi kmd = null;
59+
60+
public static void main(String[] args) throws Exception {
61+
// Initialize algod/indexer v2 clients.
62+
AlgodClient algod = new AlgodClient("http://localhost", 4001, token);
63+
IndexerClient indexer = new IndexerClient("http://localhost", 8980);
64+
65+
// Initialize KMD v1 client
66+
KmdClient kmdClient = new KmdClient();
67+
kmdClient.setBasePath("http://localhost:4002");
68+
kmdClient.setApiKey(token);
69+
kmd = new KmdApi(kmdClient);
70+
71+
// Get accounts from sandbox.
72+
String walletHandle = getDefaultWalletHandle();
73+
List<Address> accounts = getWalletAccounts(walletHandle);
74+
75+
// Create a payment transaction
76+
Transaction tx1 = Transaction.PaymentTransactionBuilder()
77+
.lookupParams(algod) // lookup fee, firstValid, lastValid
78+
.sender(accounts.get(0))
79+
.receiver(accounts.get(1))
80+
.amount(1000000)
81+
.noteUTF8("test transaction!")
82+
.build();
83+
84+
// Sign with KMD
85+
SignedTransaction stx1a = signTransactionWithKMD(tx1, walletHandle);
86+
byte[] stx1aBytes = Encoder.encodeToMsgPack(stx1a);
87+
88+
// Sign with private key
89+
byte[] privateKey = lookupPrivateKey(accounts.get(0), walletHandle);
90+
Account account = new Account(privateKey);
91+
SignedTransaction stx1b = account.signTransaction(tx1);
92+
byte[] stx1bBytes = Encoder.encodeToMsgPack(stx1b);
93+
94+
// KMD and signing directly should both be the same.
95+
if (!Arrays.equals(stx1aBytes, stx1bBytes)) {
96+
throw new RuntimeException("KMD disagrees with the manual signature!");
97+
}
98+
99+
// Send transaction
100+
Response<PostTransactionsResponse> post = algod.RawTransaction().rawtxn(stx1aBytes).execute();
101+
if (!post.isSuccessful()) {
102+
throw new RuntimeException("Failed to post transaction");
103+
}
40104

105+
// Wait for confirmation
106+
boolean done = false;
107+
while (!done) {
108+
Response<PendingTransactionResponse> txInfo = algod.PendingTransactionInformation(post.body().txId).execute();
109+
if (!txInfo.isSuccessful()) {
110+
throw new RuntimeException("Failed to check on tx progress");
111+
}
112+
if (txInfo.body().confirmedRound != null) {
113+
done = true;
114+
}
115+
}
41116

42-
public class Main {
117+
// Wait for indexer to index the round.
118+
Thread.sleep(5000);
43119

44-
public static void main(String args[]) throws Exception {
45-
final String ALGOD_API_ADDR = "http://localhost:8080";
46-
final String ALGOD_API_TOKEN = "d6f33a522f465ff12f0d263f2c3b707ac2f560bacad4d859914ada7e827902b3";
47-
48-
AlgodClient client = new AlgodClient();
49-
client.setBasePath(ALGOD_API_ADDR);
50-
ApiKeyAuth api_key = (ApiKeyAuth) client.getAuthentication("api_key");
51-
api_key.setApiKey(ALGOD_API_TOKEN);
52-
53-
AlgodApi algodApiInstance = new AlgodApi(client);
54-
try {
55-
NodeStatus status = algodApiInstance.getStatus();
56-
System.out.println("Algorand network status: " + status);
57-
} catch (ApiException e) {
58-
System.err.println("Exception when calling algod#getStatus");
59-
e.printStackTrace();
120+
// Query indexer for the transaction
121+
Response<TransactionsResponse> transactions = indexer.searchForTransactions()
122+
.txid(post.body().txId)
123+
.execute();
124+
125+
if (!transactions.isSuccessful()) {
126+
throw new RuntimeException("Failed to lookup transaction");
60127
}
128+
129+
System.out.println("Transaction received! \n" + transactions.toString());
61130
}
62131

63-
}
64-
```
65-
This prints:
66-
```
67-
Algorand network status: class NodeStatus {
68-
catchupTime: 0
69-
lastConsensusVersion: v4
70-
lastRound: 260318
71-
nextConsensusVersion: v4
72-
nextConsensusVersionRound: 260319
73-
nextConsensusVersionSupported: true
74-
timeSinceLastRound: 3620331759
132+
public static SignedTransaction signTransactionWithKMD(Transaction tx, String walletHandle) throws IOException, ApiException {
133+
SignTransactionRequest req = new SignTransactionRequest();
134+
req.transaction(Encoder.encodeToMsgPack(tx));
135+
req.setWalletHandleToken(walletHandle);
136+
req.setWalletPassword("");
137+
byte[] stxBytes = kmd.signTransaction(req).getSignedTransaction();
138+
return Encoder.decodeFromMsgPack(stxBytes, SignedTransaction.class);
139+
}
140+
141+
public static byte[] lookupPrivateKey(Address addr, String walletHandle) throws ApiException {
142+
ExportKeyRequest req = new ExportKeyRequest();
143+
req.setAddress(addr.toString());
144+
req.setWalletHandleToken(walletHandle);
145+
req.setWalletPassword("");
146+
return kmd.exportKey(req).getPrivateKey();
147+
}
148+
149+
public static String getDefaultWalletHandle() throws ApiException {
150+
for (APIV1Wallet w : kmd.listWallets().getWallets()) {
151+
if (w.getName().equals("unencrypted-default-wallet")) {
152+
InitWalletHandleTokenRequest tokenreq = new InitWalletHandleTokenRequest();
153+
tokenreq.setWalletId(w.getId());
154+
tokenreq.setWalletPassword("");
155+
return kmd.initWalletHandleToken(tokenreq).getWalletHandleToken();
156+
}
157+
}
158+
throw new RuntimeException("Default wallet not found.");
159+
}
160+
161+
public static List<Address> getWalletAccounts(String walletHandle) throws ApiException, NoSuchAlgorithmException {
162+
List<Address> accounts = new ArrayList<>();
163+
164+
ListKeysRequest keysRequest = new ListKeysRequest();
165+
keysRequest.setWalletHandleToken(walletHandle);
166+
for (String addr : kmd.listKeysInWallet(keysRequest).getAddresses()) {
167+
accounts.add(new Address(addr));
168+
}
169+
170+
return accounts;
171+
}
75172
}
76173
```
77174

generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
<dependency>
169169
<groupId>com.algorand</groupId>
170170
<artifactId>algosdk</artifactId>
171-
<version>1.5.1</version>
171+
<version>1.6.0</version>
172172
</dependency>
173173

174174
<!-- testing -->

generator/src/main/java/com/algorand/sdkutils/listeners/JavaGenerator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ private static void generateClientFile(
207207
" super(host, port, token, \"" + tokenName + "\");\n" +
208208
" }\n");
209209

210+
sb.append("\n /**\n");
211+
sb.append(" * Construct an " + clientName + " for communicating with the REST API.\n");
212+
sb.append(" * @param host using a URI format. If the scheme is not supplied the client will use HTTP.\n");
213+
sb.append(" * @param port REST server port.\n");
214+
sb.append(" * @param token authentication token.\n");
215+
sb.append(" * @param tokenKey authentication token key.\n");
216+
sb.append(" */\n");
217+
sb.append(" public " + clientName + "(String host, int port, String token String tokenKey) {\n" +
218+
" super(host, port, token, tokenKey);\n" +
219+
" }\n");
220+
210221
if (tokenOptional) {
211222
sb.append("\n /**\n");
212223
sb.append(" * Construct an " + clientName + " for communicating with the REST API.\n");

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.algorand</groupId>
66
<artifactId>algosdk</artifactId>
7-
<version>1.5.1</version>
7+
<version>1.6.0</version>
88
<packaging>jar</packaging>
99

1010
<name>${project.groupId}:${project.artifactId}</name>

run_generator.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3+
# Note: This script currently assumes that you are in a java sdk source
4+
# directory named 'java-algorand-sdk' and that the generator is checked
5+
# out at '../generator'.
36
#
47
# Regenerates the client code from the spec files.
58
#
@@ -17,7 +20,7 @@
1720
set -e
1821

1922
rootdir=`dirname $0`
20-
pushd $rootdir/generator > /dev/null
23+
pushd $rootdir/../generator > /dev/null
2124

2225
function help {
2326
echo "Options:"
@@ -64,16 +67,16 @@ if [[ ! -f "$ALGOD_SPEC" ]]; then
6467
my_exit 1
6568
fi
6669

67-
mvn clean package
70+
mvn clean package -DskipTests
6871

6972
java -jar target/generator-*-jar-with-dependencies.jar \
7073
java \
71-
-c "../src/main/java/com/algorand/algosdk/v2/client/common" \
74+
-c "../java-algorand-sdk/src/main/java/com/algorand/algosdk/v2/client/common" \
7275
-cp "com.algorand.algosdk.v2.client.common" \
73-
-m "../src/main/java/com/algorand/algosdk/v2/client/model" \
76+
-m "../java-algorand-sdk/src/main/java/com/algorand/algosdk/v2/client/model" \
7477
-mp "com.algorand.algosdk.v2.client.model" \
7578
-n "AlgodClient" \
76-
-p "../src/main/java/com/algorand/algosdk/v2/client/algod" \
79+
-p "../java-algorand-sdk/src/main/java/com/algorand/algosdk/v2/client/algod" \
7780
-pp "com.algorand.algosdk.v2.client.algod" \
7881
-t "X-Algo-API-Token" \
7982
-tr \
@@ -83,12 +86,12 @@ java -jar target/generator-*-jar-with-dependencies.jar \
8386
# overwriting the second one.
8487
java -jar target/generator-*-jar-with-dependencies.jar \
8588
java \
86-
-c "../src/main/java/com/algorand/algosdk/v2/client/common" \
89+
-c "../java-algorand-sdk/src/main/java/com/algorand/algosdk/v2/client/common" \
8790
-cp "com.algorand.algosdk.v2.client.common" \
88-
-m "../src/main/java/com/algorand/algosdk/v2/client/model" \
91+
-m "../java-algorand-sdk/src/main/java/com/algorand/algosdk/v2/client/model" \
8992
-mp "com.algorand.algosdk.v2.client.model" \
9093
-n "IndexerClient" \
91-
-p "../src/main/java/com/algorand/algosdk/v2/client/indexer" \
94+
-p "../java-algorand-sdk/src/main/java/com/algorand/algosdk/v2/client/indexer" \
9295
-pp "com.algorand.algosdk.v2.client.indexer" \
9396
-t "X-Indexer-API-Token" \
9497
-s "$INDEXER_SPEC"

0 commit comments

Comments
 (0)