implemented getTrytes command request

This commit is contained in:
davassi
2016-10-07 15:24:27 +02:00
parent 117694cdc2
commit 53067530f8
9 changed files with 109 additions and 28 deletions
+2 -4
View File
@@ -8,7 +8,7 @@ It allows to connect easily using java directly to a local or a remote [[IOTA]](
* **Compatibility:** IOTA IRI v1.0.6
* **API coverage:** 20 of 20 commands fully implemented
* **License:** Apache License 2.0
* **Readme updated:** 2016-02-17 10:16:43 (UTC)
* **Readme updated:** 2016-10-07 14:23:43 (UTC)
A list of all *IOTA* JSON-REST API commands currently supported by jota wrapper can be found in the `Commands` enum (see [here](IotaAPICommands.java) for more details).
@@ -21,9 +21,7 @@ The JOTA library has been designed to be used exclusively with Java 8+.
Core dependencies:
* Retrofit Client 2.1.0 [[link]](https://square.github.io/retrofit/)
* Gson JSON Processor :
* Annotations 2.5.0 (`jackson-annotations`) [[link]](https://github.com/FasterXML/jackson-annotations)
* Databind 2.5.0 (`jackson-databind`) [[link]](https://github.com/FasterXML/jackson-databind)
* Gson JSON Processor : [[link]](https://github.com/google/gson)
* Lombok 1.16.2 [[link]](https://github.com/rzwitserloot/lombok)
Other dependencies:
+17 -5
View File
@@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
@@ -81,7 +82,8 @@ public class IotaAPIProxy {
}
public GetTransfersResponse getTransfers(String seed, Integer securityLevel) {
final Call<GetTransfersResponse> res = service.getTransfers(IotaGetTransferRequest.createGetTransferRequest(seed, securityLevel));
final IotaGetTransferRequest tr = IotaGetTransferRequest.createGetTransferRequest(seed, securityLevel);
final Call<GetTransfersResponse> res = service.getTransfers(tr);
return wrapCheckedException(res).body();
}
@@ -98,19 +100,19 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public FindTransactionResponse findTransactionsByAddresses(String [] addresses) {
public FindTransactionResponse findTransactionsByAddresses(final String ... addresses) {
return findTransactions(addresses, null, null, null);
}
public FindTransactionResponse findTransactionsByBundles(String [] bundles) {
public FindTransactionResponse findTransactionsByBundles(final String ... bundles) {
return findTransactions(null, null, null, bundles);
}
public FindTransactionResponse findTransactionsByApprovees(String [] approvees) {
public FindTransactionResponse findTransactionsByApprovees(final String ... approvees) {
return findTransactions(null, null, approvees, null);
}
public FindTransactionResponse findTransactionsByDigests(String [] digests) {
public FindTransactionResponse findTransactionsByDigests(final String ... digests) {
return findTransactions(null, digests, null, null);
}
@@ -126,6 +128,16 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public GetBundleResponse getBundle(String transaction) {
final Call<GetBundleResponse> res = service.getBundle(IotaGetBundleRequest.createIotaGetBundleRequest(transaction));
return wrapCheckedException(res).body();
}
public GetTrytesResponse getTrytes(String ... hashes) {
final Call<GetTrytesResponse> res = service.getTrytes(IotaGetTrytesRequest.createGetTrytesRequest(hashes));
return wrapCheckedException(res).body();
}
protected static <T> Response<T> wrapCheckedException(final Call<T> call) {
try {
final Response<T> res = call.execute();
+21 -9
View File
@@ -53,19 +53,19 @@ public interface IotaAPIService {
/**
* Get the list of latest tips (unconfirmed transactions).
*
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type:
* application/json' \ -d '{"command": "getTips"}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetTipsResponse> getTips(@Body IotaCommandRequest request);
/**
* Get the list of latest tips (unconfirmed transactions).
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type:
* application/json' \ -d '{"command": "getTips"}'
* Get the list of transfers from a specified seed (account).
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTransfers", "seed": "AAA999999999999999999999999999999999999999999999999999999999999999999999999999999", "securityLevel": 1}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
@@ -88,22 +88,34 @@ public interface IotaAPIService {
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getInclusionStates", "transactions"Q9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVAZETAIRPTM"], "tips" : []}'
*
*
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetInclusionStateResponse> getInclusionStates(@Body IotaGetInclusionStateRequest request);
/**
* Get the list of transactions which were bundled with the specified tail transaction. This call returns the full value of all individual transactions, not just the hashes.
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getBundle", "transaction": "ZJVYUGTDRPDYFGFXMKOTV9ZWSGFK9CFPXTITQLQNLPPG9YNAARMKNKYQO9GSCSBIOTGMLJUFLZWSY9999"}'
*
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetBundleResponse> getBundle(@Body IotaGetBundleRequest request);
/*
/**
* Returns the raw trytes data of a transaction.
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTrytes", "hashes": ["OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999"]}'
*
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<GetTrytesResponse> getTrytes(@Body IotaGetTrytesRequest request);
/*
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@POST("./")
Call<AnalyzeTransactionResponse> analyzeTransactions(@Body IotaAnalyzeTransactionRequest request);
@@ -17,22 +17,22 @@ public class IotaFindTransactionsRequest extends IotaCommandRequest {
return new IotaFindTransactionsRequest();
}
public IotaFindTransactionsRequest byBundles(String [] bundles) {
public IotaFindTransactionsRequest byBundles(String ... bundles) {
this.bundles = bundles;
return this;
}
public IotaFindTransactionsRequest byAddresses(String [] addresses) {
public IotaFindTransactionsRequest byAddresses(String ... addresses) {
this.addresses = addresses;
return this;
}
public IotaFindTransactionsRequest byDigests(String [] digests) {
public IotaFindTransactionsRequest byDigests(String ... digests) {
this.digests = digests;
return this;
}
public IotaFindTransactionsRequest byApprovees(String [] approvees) {
public IotaFindTransactionsRequest byApprovees(String ... approvees) {
this.approvees = approvees;
return this;
}
@@ -1,19 +1,20 @@
package jota.dto.request;
import com.google.gson.Gson;
import jota.IotaAPICommands;
public class IotaGetTransferRequest extends IotaCommandRequest {
private String seed;
private String securityLevel;
private Integer securityLevel;
private IotaGetTransferRequest(final String seed, final String securityLevel) {
private IotaGetTransferRequest(final String seed, final Integer securityLevel) {
super(IotaAPICommands.GET_TRANSFER);
this.seed = seed;
this.securityLevel = securityLevel;
}
public static IotaGetTransferRequest createGetTransferRequest(String seed, Integer securityLevel) {
return new IotaGetTransferRequest(seed, String.valueOf(securityLevel));
return new IotaGetTransferRequest(seed, securityLevel);
}
}
@@ -0,0 +1,17 @@
package jota.dto.request;
import jota.IotaAPICommands;
public class IotaGetTrytesRequest extends IotaCommandRequest {
private String [] hashes;
private IotaGetTrytesRequest(final String ... hashes) {
super(IotaAPICommands.GET_TRYTES);
this.hashes = hashes;
}
public static IotaGetTrytesRequest createGetTrytesRequest(String ... hashes) {
return new IotaGetTrytesRequest(hashes);
}
}
@@ -1,5 +1,8 @@
package jota.dto.response;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class GetTransfersResponse extends AbstractResponse {
private Transfers[] transfers;
@@ -26,6 +29,11 @@ public class GetTransfersResponse extends AbstractResponse {
public String getValue() {
return value;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
public Transfers[] getTransfers() {
@@ -0,0 +1,10 @@
package jota.dto.response;
public class GetTrytesResponse extends AbstractResponse {
private String [] trites;
public String[] getTrites() {
return trites;
}
}
+26 -3
View File
@@ -14,6 +14,11 @@ import org.junit.Test;
*/
public class IotaAPIProxyTest {
private static final String TEST_SEED = "AAA999999999999999999999999999999999999999999999999999999999999999999999999999999";
private static final String TEST_TRANSACTION = "ZJVYUGTDRPDYFGFXMKOTV9ZWSGFK9CFPXTITQLQNLPPG9YNAARMKNKYQO9GSCSBIOTGMLJUFLZWSY9999";
private static final String TEST_HASH = "OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999";
private static final Integer TEST_MILESTONE_INDEX = 8059;
private IotaAPIProxy proxy;
@Before
@@ -40,7 +45,7 @@ public class IotaAPIProxyTest {
@Test
public void shouldGetMilestone() {
GetMilestoneResponse milestone = proxy.getMilestone(1000);
GetMilestoneResponse milestone = proxy.getMilestone(TEST_MILESTONE_INDEX);
assertThat(milestone, IsNull.notNullValue());
}
@@ -58,7 +63,7 @@ public class IotaAPIProxyTest {
@Test
public void shouldFindTransactionsByAddresses() {
FindTransactionResponse trans = proxy.findTransactionsByAddresses(new String[]{"123ABC"});
FindTransactionResponse trans = proxy.findTransactionsByAddresses(TEST_TRANSACTION);
assertThat(trans, IsNull.notNullValue());
}
@@ -80,10 +85,28 @@ public class IotaAPIProxyTest {
assertThat(trans, IsNull.notNullValue());
}
@Test
public void shouldGetTransactions() {
GetTransfersResponse res = proxy.getTransfers(TEST_SEED, 1);
assertThat(res, IsNull.notNullValue());
}
@Test
public void shouldGetInclusionStates() {
GetInclusionStateResponse res = proxy.getInclusionStates(new String[]{"123ABC"},
GetInclusionStateResponse res = proxy.getInclusionStates(new String[]{TEST_TRANSACTION},
new String[]{"123"});
assertThat(res, IsNull.notNullValue());
}
@Test
public void shouldGetBundle() {
GetBundleResponse res = proxy.getBundle(TEST_TRANSACTION);
assertThat(res, IsNull.notNullValue());
}
@Test
public void shouldGetTrytes() {
GetTrytesResponse res = proxy.getTrytes(TEST_HASH);
assertThat(res, IsNull.notNullValue());
}
}