Merge pull request #3 from davassi/master

Updating lib
This commit is contained in:
Gianluigi Davassi
2016-12-01 15:04:54 +01:00
committed by GitHub
34 changed files with 723 additions and 292 deletions
-1
View File
@@ -1,4 +1,3 @@
iota.node.protocol=http
#iota.node.host=138.68.126.141
iota.node.host=127.0.0.1
+84 -73
View File
@@ -1,86 +1,97 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.iota</groupId>
<artifactId>jota</artifactId>
<version>1.0.0-RELEASE</version>
<name>JOTA</name>
<description>JOTA library is a simple Java wrapper around IOTA Node's JSON-REST HTTP interface.</description>
<modelVersion>4.0.0</modelVersion>
<groupId>com.iota</groupId>
<artifactId>jota</artifactId>
<version>1.0.0-RELEASE</version>
<name>JOTA</name>
<description>JOTA library is a simple Java wrapper around IOTA Node's JSON-REST HTTP interface.</description>
<properties>
<java-version>1.7</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<java-version>1.7</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-gson -->
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<testSource>${java-version}</testSource>
<testTarget>${java-version}</testTarget>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<testSource>${java-version}</testSource>
<testTarget>${java-version}</testTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
+14 -14
View File
@@ -7,29 +7,29 @@ package jota;
*/
public enum IotaAPICommands {
GET_NODE_INFO("getNodeInfo", 0),
GET_NEIGHBORS("getNeighbors", 0),
ADD_NEIGHBORS("addNeighbors", 1),
REMOVE_NEIGHBORS("removeNeighbors",1),
GET_TIPS("getTips",0),
FIND_TRANSACTIONS("findTransactions", 1),
GET_TRYTES("getTrytes", 0),
GET_INCLUSIONS_STATES("getInclusionStates", 0),
GET_BALANCES("getBalances", 0),
GET_TRANSACTIONS_TO_APPROVE("getTransactionsToApprove", 0),
GET_NODE_INFO("getNodeInfo", 0),
GET_NEIGHBORS("getNeighbors", 0),
ADD_NEIGHBORS("addNeighbors", 1),
REMOVE_NEIGHBORS("removeNeighbors", 1),
GET_TIPS("getTips", 0),
FIND_TRANSACTIONS("findTransactions", 1),
GET_TRYTES("getTrytes", 0),
GET_INCLUSIONS_STATES("getInclusionStates", 0),
GET_BALANCES("getBalances", 0),
GET_TRANSACTIONS_TO_APPROVE("getTransactionsToApprove", 0),
ATTACH_TO_TANGLE("attachToTangle", 0),
INTERRUPT_ATTACHING_TO_TANGLE("interruptAttachingToTangle", 0),
BROADCAST_TRANSACTIONS("broadcastTransactions",0),
BROADCAST_TRANSACTIONS("broadcastTransactions", 0),
STORE_TRANSACTIONS("storeTransactions", 0);
private String command;
private int params;
IotaAPICommands(String command, int params) {
this.command = command;
this.params = params;
}
private String command;
private int params;
public String command() {
return command;
}
+61 -60
View File
@@ -1,36 +1,34 @@
package jota;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import jota.dto.request.*;
import jota.dto.response.*;
import jota.utils.IotaAPIUtils;
import okhttp3.OkHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collection;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
/**
* IotaAPIProxy Builder. Usage:
*
*
* IotaApiProxy api = IotaApiProxy.Builder
* .protocol("http")
* .nodeAddress("localhost")
* .port(12345)
* .build();
*
* .protocol("http")
* .nodeAddress("localhost")
* .port(12345)
* .build();
*
* GetNodeInfoResponse response = api.getNodeInfo();
*
*
* @author davassi
*/
public class IotaAPIProxy {
@@ -38,6 +36,7 @@ public class IotaAPIProxy {
private static final Logger log = LoggerFactory.getLogger(IotaAPIProxy.class);
private IotaAPIService service;
private String protocol, host, port;
private IotaAPIProxy(final Builder builder) {
protocol = builder.protocol;
@@ -46,7 +45,28 @@ public class IotaAPIProxy {
postConstruct();
}
private String protocol, host, port;
protected static <T> Response<T> wrapCheckedException(final Call<T> call) {
try {
final Response<T> res = call.execute();
if (res.code() == 400) {
throw new IllegalAccessError(res.errorBody().toString());
}
return res;
} catch (IOException e) {
log.error("Execution of the API call raised exception. IOTA Node not reachable?", e);
throw new IllegalStateException(e.getMessage());
}
}
private static final String env(String env, String def) {
final String value = System.getenv(env);
if (value == null) {
log.warn("Environment variable '{}' is not defined, and actual value has not been specified. "
+ "Rolling back to default value: '{}'", env, def);
return def;
}
return value;
}
private void postConstruct() {
@@ -78,12 +98,12 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public AddNeighborsResponse addNeighbors(String ... uris) {
public AddNeighborsResponse addNeighbors(String... uris) {
final Call<AddNeighborsResponse> res = service.addNeighbors(IotaNeighborsRequest.createAddNeighborsRequest(uris));
return wrapCheckedException(res).body();
}
public RemoveNeighborsResponse removeNeighbors(String ... uris) {
public RemoveNeighborsResponse removeNeighbors(String... uris) {
final Call<RemoveNeighborsResponse> res = service.removeNeighbors(IotaNeighborsRequest.createRemoveNeighborsRequest(uris));
return wrapCheckedException(res).body();
}
@@ -93,12 +113,12 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public FindTransactionResponse findTransactions(String [] addresses, String [] digests, String [] approvees, String [] bundles ) {
public FindTransactionResponse findTransactions(String[] addresses, String[] tags, String[] approvees, String[] bundles) {
final IotaFindTransactionsRequest findTransRequest = IotaFindTransactionsRequest
.createFindTransactionRequest()
.byAddresses(addresses)
.byDigests(digests)
.byTags(tags)
.byApprovees(approvees)
.byBundles(bundles);
@@ -106,19 +126,19 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public FindTransactionResponse findTransactionsByAddresses(final String ... addresses) {
public FindTransactionResponse findTransactionsByAddresses(final String... addresses) {
return findTransactions(addresses, null, null, null);
}
public FindTransactionResponse findTransactionsByBundles(final String ... bundles) {
public FindTransactionResponse findTransactionsByBundles(final String... bundles) {
return findTransactions(null, null, null, bundles);
}
public FindTransactionResponse findTransactionsByApprovees(final String ... approvees) {
public FindTransactionResponse findTransactionsByApprovees(final String... approvees) {
return findTransactions(null, null, approvees, null);
}
public FindTransactionResponse findTransactionsByDigests(final String ... digests) {
public FindTransactionResponse findTransactionsByDigests(final String... digests) {
return findTransactions(null, digests, null, null);
}
@@ -134,7 +154,7 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public GetTrytesResponse getTrytes(String ... hashes) {
public GetTrytesResponse getTrytes(String... hashes) {
final Call<GetTrytesResponse> res = service.getTrytes(IotaGetTrytesRequest.createGetTrytesRequest(hashes));
return wrapCheckedException(res).body();
}
@@ -144,7 +164,7 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public GetBalancesResponse getBalances(Integer threshold, String [] addresses) {
public GetBalancesResponse getBalances(Integer threshold, String[] addresses) {
final Call<GetBalancesResponse> res = service.getBalances(IotaGetBalancesRequest.createIotaGetBalancesRequest(threshold, addresses));
return wrapCheckedException(res).body();
}
@@ -154,36 +174,23 @@ public class IotaAPIProxy {
return wrapCheckedException(res).body();
}
public GetAttachToTangleResponse attachToTangle(String trunkTransaction, String branchTransaction, Integer minWeightMagnitude, String ... trytes) {
public GetAttachToTangleResponse attachToTangle(String trunkTransaction, String branchTransaction, Integer minWeightMagnitude, String... trytes) {
final Call<GetAttachToTangleResponse> res = service.attachToTangle(IotaAttachToTangleRequest.createAttachToTangleRequest(trunkTransaction, branchTransaction, minWeightMagnitude, trytes));
return wrapCheckedException(res).body();
}
public StoreTransactionsResponse storeTransactions(String ... trytes) {
public StoreTransactionsResponse storeTransactions(String... trytes) {
final Call<StoreTransactionsResponse> res = service.storeTransactions(IotaStoreTransactionsRequest.createStoreTransactionsRequest(trytes));
return wrapCheckedException(res).body();
}
public BroadcastTransactionsResponse broadcastTransactions(String ... trytes) {
// end of proxied calls.
public BroadcastTransactionsResponse broadcastTransactions(String... trytes) {
final Call<BroadcastTransactionsResponse> res = service.broadcastTransactions(IotaBroadcastTransactionRequest.createBroadcastTransactionsRequest(trytes));
return wrapCheckedException(res).body();
}
protected static <T> Response<T> wrapCheckedException(final Call<T> call) {
try {
final Response<T> res = call.execute();
if (res.code() == 400) {
throw new IllegalAccessError(res.errorBody().toString());
}
return res;
} catch (IOException e) {
log.error("Execution of the API call raised exception. IOTA Node not reachable?", e);
throw new IllegalStateException(e.getMessage());
}
}
// end of proxied calls.
public GetBundleResponse getBundle(String transaction) {
return IotaAPIUtils.getBundle(transaction);
}
@@ -192,20 +199,10 @@ public class IotaAPIProxy {
return IotaAPIUtils.getNewAddress(seed, securityLevel);
}
private static final String env(String env, String def) {
final String value = System.getenv(env);
if (value == null) {
log.warn("Environment variable '{}' is not defined, and actual value has not been specified. "
+ "Rolling back to default value: '{}'", env, def);
return def;
}
return value;
}
public static class Builder {
String protocol, host, port;
public IotaAPIProxy build() {
if (protocol == null || host == null || port == null) {
@@ -224,9 +221,13 @@ public class IotaAPIProxy {
private boolean checkPropertiesFiles() {
try (BufferedReader reader = Files.newBufferedReader(Paths.get("node_config.properties"))) {
try {
FileReader fileReader = new FileReader("node_config.properties");
BufferedReader bufferedReader = new BufferedReader(fileReader);
final Properties nodeConfig = new Properties();
nodeConfig.load(reader);
nodeConfig.load(bufferedReader);
if (nodeConfig.getProperty("iota.node.protocol") != null) {
protocol = nodeConfig.getProperty("iota.node.protocol");
@@ -251,7 +252,7 @@ public class IotaAPIProxy {
host = env("IOTA_NODE_HOST", "localhost");
port = env("IOTA_NODE_PORT", "14265");
}
public Builder host(String host) {
this.host = host;
return this;
+22 -23
View File
@@ -9,33 +9,33 @@ import retrofit2.http.POST;
/**
* IOTA API Proxy Service definition using Retrofit2
*
*
* @author davassi
*/
public interface IotaAPIService {
public static final String CONTENT_TYPE_HEADER = "Content-Type: application/json";
public static final String USER_AGENT_HEADER = "User-Agent: JOTA-API wrapper";
String CONTENT_TYPE_HEADER = "Content-Type: application/json";
String USER_AGENT_HEADER = "User-Agent: JOTA-API wrapper";
/**
* Returns information about your node.
*
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getNodeInfo"}'
*
*
* @return a {@code NodeInfoResponse} object, if succesfull.
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetNodeInfoResponse> getNodeInfo(@Body IotaCommandRequest request);
/**
* Get the list of latest tips (unconfirmed transactions).
*
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getNeighbors"}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetNeighborsResponse> getNeighbors(@Body IotaCommandRequest request);
@@ -45,7 +45,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "addNeighbors", "uris": ["udp://8.8.8.8:14265", "udp://8.8.8.5:14265"]}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<AddNeighborsResponse> addNeighbors(@Body IotaNeighborsRequest request);
@@ -55,7 +55,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "removeNeighbors", "uris": ["udp://8.8.8.8:14265", "udp://8.8.8.5:14265"]}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<RemoveNeighborsResponse> removeNeighbors(@Body IotaNeighborsRequest request);
@@ -65,17 +65,17 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTips"}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetTipsResponse> getTips(@Body IotaCommandRequest request);
/**
* Find the transactions which match the specified input and return
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type: application/json' \
*
* curl http://localhost:14265 \ -X POST \ -H 'Content-Type: application/json' \
* -d '{"command": "findTransactions", "addresses": ["RVORZ9SIIP9RCYMREUIXXVPQIPHVCNPQ9HZWYKFWYWZRE9JQKG9REPKIASHUUECPSQO9JT9XNMVKWYGVAZETAIRPTM"]}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<FindTransactionResponse> findTransactions(@Body IotaFindTransactionsRequest request);
@@ -86,7 +86,7 @@ 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 })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetInclusionStateResponse> getInclusionStates(@Body IotaGetInclusionStateRequest request);
@@ -95,9 +95,8 @@ public interface IotaAPIService {
*
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTrytes", "hashes": ["OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999"]}'
*
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetTrytesResponse> getTrytes(@Body IotaGetTrytesRequest request);
@@ -107,7 +106,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getTransactionsToApprove", "depth": 27}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetTransactionsToApproveResponse> getTransactionsToApprove(@Body IotaGetTransactionsToApproveRequest request);
@@ -117,7 +116,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "getBalances", "addresses": ["HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ"], "threshold": 100}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetBalancesResponse> getBalances(@Body IotaGetBalancesRequest request);
@@ -127,7 +126,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "attachToTangle", "trunkTransaction": "JVMTDGDPDFYHMZPMWEKKANBQSLSDTIIHAYQUMZOKHXXXGJHJDQPOMDOMNRDKYCZRUFZROZDADTHZC9999", "branchTransaction": "P9KFSJVGSPLXAEBJSHWFZLGP9GGJTIO9YITDEHATDTGAFLPLBZ9FOFWWTKMAZXZHFGQHUOXLXUALY9999", "minWeightMagnitude": 18, "trytes": ["TRYTVALUEHERE"]}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<GetAttachToTangleResponse> attachToTangle(@Body IotaAttachToTangleRequest request);
@@ -137,7 +136,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "interruptAttachingToTangle" }
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<InterruptAttachingToTangleResponse> interruptAttachingToTangle(@Body IotaCommandRequest request);
@@ -147,7 +146,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "broadcastTransactions", "trytes": ["BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYE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LGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"]}
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<BroadcastTransactionsResponse> broadcastTransactions(@Body IotaBroadcastTransactionRequest request);
@@ -157,7 +156,7 @@ public interface IotaAPIService {
* curl http://localhost:14265 -X POST -H 'Content-Type: application/json'
* -d '{"command": "storeTransactions", "trytes": ["BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWRTLFGV9XXMYWEMGQEEEDBTIJ9OJOXFAPFQX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UJ9BKYYXSV9JSPEXYMCFAIKTGNRSQGUNIYZCRT9FOWENSZQPD9ALUPYYAVICHVYELYFPUYDTWUSWNIYFXPX9MICCCOOZIWRNJIDALWGWRATGLJXNAYTNIZWQ9YTVDBOFZRKO9CFWRPAQQRXTPACOWCPRLYRYSJARRKSQPR9TCFXDVIXLP9XVL99ERRDSOHBFJDJQQGGGCZNDQ9NYCTQJWVZIAELCRBJJFDMCNZU9FIZRPGNURTXOCDSQGXTQHKHUECGWFUUYS9J9NYQ9U9P9UUP9YMZHWWWCIASCFLCMSKTELZWUGCDE9YOKVOVKTAYPHDF9ZCCQAYPJIJNGSHUIHHCOSSOOBUDOKE9CJZGYSSGNCQJVBEFTZFJ9SQUHOASKRRGBSHWKBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999"]}'
*/
@Headers({ CONTENT_TYPE_HEADER, USER_AGENT_HEADER })
@Headers({CONTENT_TYPE_HEADER, USER_AGENT_HEADER})
@POST("./")
Call<StoreTransactionsResponse> storeTransactions(@Body IotaStoreTransactionsRequest request);
}
@@ -7,9 +7,9 @@ public class IotaAttachToTangleRequest extends IotaCommandRequest {
private String trunkTransaction;
private String branchTransaction;
private Integer minWeightMagnitude;
private String [] trytes;
private String[] trytes;
private IotaAttachToTangleRequest(final String trunkTransaction, final String branchTransaction, final Integer minWeightMagnitude, final String ... trytes) {
private IotaAttachToTangleRequest(final String trunkTransaction, final String branchTransaction, final Integer minWeightMagnitude, final String... trytes) {
super(IotaAPICommands.ATTACH_TO_TANGLE);
this.trunkTransaction = trunkTransaction;
this.branchTransaction = branchTransaction;
@@ -17,7 +17,7 @@ public class IotaAttachToTangleRequest extends IotaCommandRequest {
this.trytes = trytes;
}
public static IotaAttachToTangleRequest createAttachToTangleRequest(final String trunkTransaction, final String branchTransaction, final Integer minWeightMagnitude, final String ... trytes) {
public static IotaAttachToTangleRequest createAttachToTangleRequest(final String trunkTransaction, final String branchTransaction, final Integer minWeightMagnitude, final String... trytes) {
return new IotaAttachToTangleRequest(trunkTransaction, branchTransaction, minWeightMagnitude, trytes);
}
}
@@ -4,14 +4,14 @@ import jota.IotaAPICommands;
public class IotaBroadcastTransactionRequest extends IotaCommandRequest {
private String [] trytes;
private String[] trytes;
private IotaBroadcastTransactionRequest(final String ... trytes) {
private IotaBroadcastTransactionRequest(final String... trytes) {
super(IotaAPICommands.BROADCAST_TRANSACTIONS);
this.trytes = trytes;
}
public static IotaBroadcastTransactionRequest createBroadcastTransactionsRequest(final String ... trytes) {
public static IotaBroadcastTransactionRequest createBroadcastTransactionsRequest(final String... trytes) {
return new IotaBroadcastTransactionRequest(trytes);
}
}
@@ -17,7 +17,7 @@ public class IotaCommandRequest {
public static IotaCommandRequest createGetTipsRequest() {
return new IotaCommandRequest(IotaAPICommands.GET_TIPS);
}
public static IotaCommandRequest createGetNeighborsRequest() {
return new IotaCommandRequest(IotaAPICommands.GET_NEIGHBORS);
}
@@ -4,35 +4,35 @@ import jota.IotaAPICommands;
public class IotaFindTransactionsRequest extends IotaCommandRequest {
private IotaFindTransactionsRequest() {
super(IotaAPICommands.FIND_TRANSACTIONS);
}
private String[] bundles; // List of bundle hashes. The hashes need to be extended to 81chars by padding the hash with 9's.
private String[] addresses;
private String[] tags;
private String[] approvees;
private String[] bundles; // List of bundle hashes. The hashes need to be extended to 81chars by padding the hash with 9's.
private String[] addresses;
private String[] digests;
private String[] approvees;
private IotaFindTransactionsRequest() {
super(IotaAPICommands.FIND_TRANSACTIONS);
}
public static IotaFindTransactionsRequest createFindTransactionRequest() {
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) {
this.digests = digests;
public IotaFindTransactionsRequest byTags(String... tags) {
this.tags = tags;
return this;
}
public IotaFindTransactionsRequest byApprovees(String ... approvees) {
public IotaFindTransactionsRequest byApprovees(String... approvees) {
this.approvees = approvees;
return this;
}
@@ -4,16 +4,16 @@ import jota.IotaAPICommands;
public class IotaGetBalancesRequest extends IotaCommandRequest {
private String [] addresses;
private String[] addresses;
private Integer threshold;
private IotaGetBalancesRequest(final Integer threshold, final String ... addresses) {
private IotaGetBalancesRequest(final Integer threshold, final String... addresses) {
super(IotaAPICommands.GET_BALANCES);
this.addresses = addresses;
this.threshold = threshold;
}
public static IotaGetBalancesRequest createIotaGetBalancesRequest(final Integer threshold, final String ... addresses) {
public static IotaGetBalancesRequest createIotaGetBalancesRequest(final Integer threshold, final String... addresses) {
return new IotaGetBalancesRequest(threshold, addresses);
}
@@ -3,27 +3,26 @@ package jota.dto.request;
import jota.IotaAPICommands;
import java.util.Collection;
import java.util.stream.Collectors;
public class IotaGetInclusionStateRequest extends IotaCommandRequest {
private String[] transactions;
private String[] tips;
private IotaGetInclusionStateRequest(final String[] transactions, final String[] tips) {
super(IotaAPICommands.GET_INCLUSIONS_STATES);
this.transactions = transactions;
this.tips = tips;
}
private String[] transactions;
private String[] tips;
public static IotaGetInclusionStateRequest createGetInclusionStateRequest(String[] transactions, String[] tips) {
return new IotaGetInclusionStateRequest(transactions, tips);
}
public static IotaGetInclusionStateRequest createGetInclusionStateRequest(Collection<String> transactions, Collection<String> tips) {
return createGetInclusionStateRequest(
transactions.toArray(new String[] {}),
tips.toArray(new String[] {}));
transactions.toArray(new String[]{}),
tips.toArray(new String[]{}));
}
}
@@ -4,14 +4,14 @@ import jota.IotaAPICommands;
public class IotaGetTrytesRequest extends IotaCommandRequest {
private String [] hashes;
private String[] hashes;
private IotaGetTrytesRequest(final String ... hashes) {
private IotaGetTrytesRequest(final String... hashes) {
super(IotaAPICommands.GET_TRYTES);
this.hashes = hashes;
}
public static IotaGetTrytesRequest createGetTrytesRequest(String ... hashes) {
public static IotaGetTrytesRequest createGetTrytesRequest(String... hashes) {
return new IotaGetTrytesRequest(hashes);
}
}
@@ -4,18 +4,18 @@ import jota.IotaAPICommands;
public class IotaNeighborsRequest extends IotaCommandRequest {
private String [] uris;
private String[] uris;
private IotaNeighborsRequest(IotaAPICommands type, final String ... uris) {
private IotaNeighborsRequest(IotaAPICommands type, final String... uris) {
super(type);
this.uris = uris;
}
public static IotaNeighborsRequest createAddNeighborsRequest(String ... uris) {
public static IotaNeighborsRequest createAddNeighborsRequest(String... uris) {
return new IotaNeighborsRequest(IotaAPICommands.ADD_NEIGHBORS, uris);
}
public static IotaNeighborsRequest createRemoveNeighborsRequest(String ... uris) {
public static IotaNeighborsRequest createRemoveNeighborsRequest(String... uris) {
return new IotaNeighborsRequest(IotaAPICommands.REMOVE_NEIGHBORS, uris);
}
}
@@ -4,14 +4,14 @@ import jota.IotaAPICommands;
public class IotaStoreTransactionsRequest extends IotaCommandRequest {
private String [] trytes;
private String[] trytes;
private IotaStoreTransactionsRequest(final String ... trytes) {
private IotaStoreTransactionsRequest(final String... trytes) {
super(IotaAPICommands.STORE_TRANSACTIONS);
this.trytes = trytes;
}
public static IotaStoreTransactionsRequest createStoreTransactionsRequest(final String ... trytes) {
public static IotaStoreTransactionsRequest createStoreTransactionsRequest(final String... trytes) {
return new IotaStoreTransactionsRequest(trytes);
}
}
@@ -34,39 +34,51 @@ public class AnalyzeTransactionResponse extends AbstractResponse {
public String getValue() {
return value;
}
public String getDigest() {
return digest;
}
public String getTrunkTransaction() {
return trunkTransaction;
}
public String getTimestamp() {
return timestamp;
}
public String getSignatureNonce() {
return signatureNonce;
}
public String getType() {
return type;
}
public String getAddress() {
return address;
}
public String getApprovalNonce() {
return approvalNonce;
}
public String getBranchTransaction() {
return branchTransaction;
}
public String getBundle() {
return bundle;
}
public String getHash() {
return hash;
}
public String getIndex() {
return index;
}
public String getSignatureMessageChunk() {
return signatureMessageChunk;
}
@@ -1,10 +1,10 @@
package jota.dto.response;
public class FindTransactionResponse extends AbstractResponse {
String [] addresses;
public String[] getAddresses() {
return addresses;
}
String[] hashes;
public String[] getHashes() {
return hashes;
}
}
@@ -2,7 +2,7 @@ package jota.dto.response;
public class GetAttachToTangleResponse extends AbstractResponse {
private String [] trytes;
private String[] trytes;
public String[] getTrytes() {
return trytes;
@@ -2,7 +2,7 @@ package jota.dto.response;
public class GetBalancesResponse extends AbstractResponse {
private String [] balances;
private String[] balances;
private String milestone;
private Integer milestoneIndex;
@@ -5,7 +5,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class GetBundleResponse extends AbstractResponse {
private Transactions[] transactions;
public Transactions[] transactions;
private String warning;
@@ -17,7 +17,7 @@ public class GetBundleResponse extends AbstractResponse {
return transactions;
}
static class Transactions {
public static class Transactions {
private String signatureMessageChunk;
private String index;
private String approvalNonce;
@@ -1,7 +1,8 @@
package jota.dto.response;
public class GetInclusionStateResponse extends AbstractResponse {
boolean [] states;
boolean[] states;
public boolean[] getStates() {
return states;
@@ -2,25 +2,32 @@ package jota.dto.response;
public class GetNeighborsResponse extends AbstractResponse {
private Neighbors[] neighbors;
public Neighbors[] neighbors;
public Neighbors[] getNeighbors() {
return neighbors;
}
static class Neighbors {
public static class Neighbors {
private String numberOfAllTransactions;
private String address;
private String numberOfNewTransactions;
private Integer numberOfAllTransactions;
private Integer numberOfInvalidTransactions;
private Integer numberOfNewTransactions;
public String getAddress() {
return address;
}
public String getNumberOfAllTransactions() {
public Integer getNumberOfAllTransactions() {
return numberOfAllTransactions;
}
public String getNumberOfNewTransactions() {
public Integer getNumberOfInvalidTransactions() {
return numberOfInvalidTransactions;
}
public Integer getNumberOfNewTransactions() {
return numberOfNewTransactions;
}
}
@@ -7,4 +7,10 @@ public class GetNewAddressResponse extends AbstractResponse {
public String getAddress() {
return address;
}
public static GetNewAddressResponse create(String address) {
GetNewAddressResponse res = new GetNewAddressResponse();
res.address = address;
return res;
}
}
@@ -2,65 +2,80 @@ package jota.dto.response;
public class GetNodeInfoResponse extends AbstractResponse {
private String incomingPacketsBacklog;
private String appName;
private String transactionsToRequest;
private String jreTotalMemory;
private String time;
private String neighbors;
private String milestoneIndex;
private String appVersion;
private String jreAvailableProcessors;
private String jreMaxMemory;
private String tips;
private String jreFreeMemory;
public String getIncomingPacketsBacklog() {
return incomingPacketsBacklog;
}
private Integer jreAvailableProcessors;
private Integer jreFreeMemory;
private Integer jreMaxMemory;
private Integer jreTotalMemory;
private String latestMilestone;
private Long latestMilestoneIndex;
private String latestSolidSubtangleMilestone;
private Long latestSolidSubtangleMilestoneIndex;
private Long neighbors;
private Long packetsQueueSize;
private Long time;
private Long tips;
private Long transactionsToRequest;
public String getAppName() {
return appName;
}
public String getTransactionsToRequest() {
return transactionsToRequest;
}
public String getJreTotalMemory() {
return jreTotalMemory;
}
public String getTime() {
return time;
}
public String getNeighbors() {
return neighbors;
}
public String getMilestoneIndex() {
return milestoneIndex;
}
public String getAppVersion() {
return appVersion;
}
public String getJreAvailableProcessors() {
public Integer getJreAvailableProcessors() {
return jreAvailableProcessors;
}
public String getJreMaxMemory() {
return jreMaxMemory;
}
public String getTips() {
return tips;
}
public String getJreFreeMemory() {
public Integer getJreFreeMemory() {
return jreFreeMemory;
}
}
public Integer getJreMaxMemory() {
return jreMaxMemory;
}
public Integer getJreTotalMemory() {
return jreTotalMemory;
}
public String getLatestMilestone() {
return latestMilestone;
}
public Long getLatestMilestoneIndex() {
return latestMilestoneIndex;
}
public String getLatestSolidSubtangleMilestone() {
return latestSolidSubtangleMilestone;
}
public Long getLatestSolidSubtangleMilestoneIndex() {
return latestSolidSubtangleMilestoneIndex;
}
public Long getNeighbors() {
return neighbors;
}
public Long getPacketsQueueSize() {
return packetsQueueSize;
}
public Long getTime() {
return time;
}
public Long getTips() {
return tips;
}
public Long getTransactionsToRequest() {
return transactionsToRequest;
}
}
@@ -8,6 +8,7 @@ public class GetTransactionsToApproveResponse extends AbstractResponse {
public String getBranchTransactionToApprove() {
return branchTransactionToApprove;
}
public String getTrunkTransaction() {
return trunkTransaction;
}
@@ -6,27 +6,35 @@ import org.apache.commons.lang3.builder.ToStringStyle;
public class GetTransfersResponse extends AbstractResponse {
private Transfers[] transfers;
public Transfers[] getTransfers() {
return transfers;
}
public static class Transfers {
private String timestamp;
private String address;
private String hash;
private String persistence;
private String value;
private Integer persistence;
private long value;
public String getAddress() {
return address;
}
public String getHash() {
return hash;
}
public String getPersistence() {
public Integer getPersistence() {
return persistence;
}
public String getTimestamp() {
return timestamp;
}
public String getValue() {
public long getValue() {
return value;
}
@@ -35,8 +43,4 @@ public class GetTransfersResponse extends AbstractResponse {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
public Transfers[] getTransfers() {
return transfers;
}
}
@@ -2,9 +2,9 @@ package jota.dto.response;
public class GetTrytesResponse extends AbstractResponse {
private String [] trites;
private String[] trytes;
public String[] getTrites() {
return trites;
public String[] getTrytes() {
return trytes;
}
}
+128
View File
@@ -0,0 +1,128 @@
package jota.utils;
import java.util.Arrays;
public class Converter {
public static final int RADIX = 3;
public static final int MAX_TRIT_VALUE = (RADIX - 1) / 2, MIN_TRIT_VALUE = -MAX_TRIT_VALUE;
public static final int NUMBER_OF_TRITS_IN_A_BYTE = 5;
public static final int NUMBER_OF_TRITS_IN_A_TRYTE = 3;
public static final String TRYTE_ALPHABET = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static final int[][] BYTE_TO_TRITS_MAPPINGS = new int[243][];
static final int[][] TRYTE_TO_TRITS_MAPPINGS = new int[27][];
static {
final int[] trits = new int[NUMBER_OF_TRITS_IN_A_BYTE];
for (int i = 0; i < 243; i++) {
BYTE_TO_TRITS_MAPPINGS[i] = Arrays.copyOf(trits, NUMBER_OF_TRITS_IN_A_BYTE);
increment(trits, NUMBER_OF_TRITS_IN_A_BYTE);
}
for (int i = 0; i < 27; i++) {
TRYTE_TO_TRITS_MAPPINGS[i] = Arrays.copyOf(trits, NUMBER_OF_TRITS_IN_A_TRYTE);
increment(trits, NUMBER_OF_TRITS_IN_A_TRYTE);
}
}
public static byte[] bytes(final int[] trits, final int offset, final int size) {
final byte[] bytes = new byte[(size + NUMBER_OF_TRITS_IN_A_BYTE - 1) / NUMBER_OF_TRITS_IN_A_BYTE];
for (int i = 0; i < bytes.length; i++) {
int value = 0;
for (int j = (size - i * NUMBER_OF_TRITS_IN_A_BYTE) < 5 ? (size - i * NUMBER_OF_TRITS_IN_A_BYTE) : NUMBER_OF_TRITS_IN_A_BYTE; j-- > 0; ) {
value = value * RADIX + trits[offset + i * NUMBER_OF_TRITS_IN_A_BYTE + j];
}
bytes[i] = (byte) value;
}
return bytes;
}
public static byte[] bytes(final int[] trits) {
return bytes(trits, 0, trits.length);
}
public static void getTrits(final byte[] bytes, final int[] trits) {
int offset = 0;
for (int i = 0; i < bytes.length && offset < trits.length; i++) {
System.arraycopy(BYTE_TO_TRITS_MAPPINGS[bytes[i] < 0 ? (bytes[i] + BYTE_TO_TRITS_MAPPINGS.length) : bytes[i]], 0, trits, offset, trits.length - offset < NUMBER_OF_TRITS_IN_A_BYTE ? (trits.length - offset) : NUMBER_OF_TRITS_IN_A_BYTE);
offset += NUMBER_OF_TRITS_IN_A_BYTE;
}
while (offset < trits.length) {
trits[offset++] = 0;
}
}
public static int[] trits(final String trytes) {
final int[] trits = new int[trytes.length() * NUMBER_OF_TRITS_IN_A_TRYTE];
for (int i = 0; i < trytes.length(); i++) {
System.arraycopy(TRYTE_TO_TRITS_MAPPINGS[TRYTE_ALPHABET.indexOf(trytes.charAt(i))], 0, trits, i * NUMBER_OF_TRITS_IN_A_TRYTE, NUMBER_OF_TRITS_IN_A_TRYTE);
}
return trits;
}
public static void copyTrits(final long value, final int[] destination, final int offset, final int size) {
long absoluteValue = value < 0 ? -value : value;
for (int i = 0; i < size; i++) {
int remainder = (int) (absoluteValue % RADIX);
absoluteValue /= RADIX;
if (remainder > MAX_TRIT_VALUE) {
remainder = MIN_TRIT_VALUE;
absoluteValue++;
}
destination[offset + i] = remainder;
}
if (value < 0) {
for (int i = 0; i < size; i++) {
destination[offset + i] = -destination[offset + i];
}
}
}
public static String trytes(final int[] trits, final int offset, final int size) {
StringBuilder trytes = new StringBuilder();
for (int i = 0; i < (size + NUMBER_OF_TRITS_IN_A_TRYTE - 1) / NUMBER_OF_TRITS_IN_A_TRYTE; i++) {
int j = trits[offset + i * 3] + trits[offset + i * 3 + 1] * 3 + trits[offset + i * 3 + 2] * 9;
if (j < 0) {
j += TRYTE_ALPHABET.length();
}
trytes.append(TRYTE_ALPHABET.charAt(j));
}
return trytes.toString();
}
public static String trytes(final int[] trits) {
return trytes(trits, 0, trits.length);
}
public static int tryteValue(final int[] trits, final int offset) {
return trits[offset] + trits[offset + 1] * 3 + trits[offset + 2] * 9;
}
public static void increment(final int[] trits, final int size) {
for (int i = 0; i < size; i++) {
if (++trits[i] > Converter.MAX_TRIT_VALUE) {
trits[i] = Converter.MIN_TRIT_VALUE;
} else {
break;
}
}
}
}
+59
View File
@@ -0,0 +1,59 @@
package jota.utils;
/**
* (c) 2016 Come-from-Beyond
* <p>
* Curl belongs to the sponge function family.
*/
public class Curl {
public static final int HASH_LENGTH = 243;
private static final int STATE_LENGTH = 3 * HASH_LENGTH;
private static final int NUMBER_OF_ROUNDS = 27;
private static final int[] TRUTH_TABLE = {1, 0, -1, 1, -1, 0, -1, 1, 0};
private final int[] state = new int[STATE_LENGTH];
public void absorb(final int[] trits, int offset, int length) {
do {
System.arraycopy(trits, offset, state, 0, length < HASH_LENGTH ? length : HASH_LENGTH);
transform();
offset += HASH_LENGTH;
} while ((length -= HASH_LENGTH) > 0);
}
public int[] squeeze(final int[] trits, int offset, int length) {
do {
System.arraycopy(state, 0, trits, offset, length < HASH_LENGTH ? length : HASH_LENGTH);
transform();
offset += HASH_LENGTH;
} while ((length -= HASH_LENGTH) > 0);
return state;
}
private void transform() {
final int[] scratchpad = new int[STATE_LENGTH];
int scratchpadIndex = 0;
for (int round = 0; round < NUMBER_OF_ROUNDS; round++) {
System.arraycopy(state, 0, scratchpad, 0, STATE_LENGTH);
for (int stateIndex = 0; stateIndex < STATE_LENGTH; stateIndex++) {
state[stateIndex] = TRUTH_TABLE[scratchpad[scratchpadIndex] + scratchpad[scratchpadIndex += (scratchpadIndex < 365 ? 364 : -365)] * 3 + 4];
}
}
}
public void reset() {
for (int stateIndex = 0; stateIndex < STATE_LENGTH; stateIndex++) {
state[stateIndex] = 0;
}
}
public int[] getState() {
return state;
}
}
@@ -1,4 +1,4 @@
package jota;
package jota.utils;
import jota.dto.response.GetBundleResponse;
import jota.dto.response.GetNewAddressResponse;
@@ -15,8 +15,14 @@ public class IotaAPIUtils {
private static final Logger log = LoggerFactory.getLogger(IotaAPIUtils.class);
public static GetNewAddressResponse getNewAddress(final String seed, final Integer securityLevel) {
throw new NotImplementedException("Not yet implemented");
public static GetNewAddressResponse getNewAddress(final String seed, final int index) {
final int[] key = Signing.key(Converter.trits(seed), index, 2);
final int[] digests = Signing.digests(key);
final int[] addressTrits = Signing.address(digests);
final String address = Converter.trytes(addressTrits);
return GetNewAddressResponse.create(address);
}
public static GetBundleResponse getBundle(final String transaction) {
@@ -0,0 +1,16 @@
package jota.utils;
/**
* Created by pinpong on 30.11.16.
*/
public class IotaUnitConverter {
public static long convertUnits(long amount, IotaUnits fromUnit, IotaUnits toUnit) {
long amountInSource = (long) (amount * Math.pow(10, fromUnit.getValue()));
return convertUnits(amountInSource, toUnit);
}
private static long convertUnits(long amount, IotaUnits toUnit) {
return (long) (amount / Math.pow(10, toUnit.getValue()));
}
}
+29
View File
@@ -0,0 +1,29 @@
package jota.utils;
/**
* Created by pinpong on 30.11.16.
*/
public enum IotaUnits {
IOTA("i", 0),
KILO_IOTA("Ki", 3),
MEGA_IOTA("Mi", 6),
GIGA_IOTA("Gi", 9),
TERA_IOTA("Ti", 12),
PETA_IOTA("Pi", 15);
private String unit;
private long value;
IotaUnits(String unit, long value) {
this.unit = unit;
this.value = value;
}
public String getUnit() {
return unit;
}
public long getValue() {
return value;
}
}
+94
View File
@@ -0,0 +1,94 @@
package jota.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Signing {
static int[] key(int[] seed, int index, int length) {
final int[] subseed = seed;
for (int i = 0; i < index; i++) {
for (int j = 0; j < 243; j++) {
if (++subseed[j] > 1) {
subseed[j] = -1;
} else {
break;
}
}
}
Curl curl = new Curl();
//curl.absorb(subseed, state);
//curl.squeeze(subseed, state);
curl.absorb(subseed, 0, subseed.length);
List<Integer> key = new ArrayList<>();
int[] buffer = new int[subseed.length];
int offset = 0;
while (length-- > 0) {
for (int i = 0; i < 27; i++) {
curl.squeeze(buffer, 0, buffer.length);
for (int j = 0; j < 243; j++) {
key.add(buffer[j]);
}
}
}
return to(key);
}
private static int[] to(List<Integer> key) {
int a[] = new int[key.size()];
int i = 0;
for (Integer v : key) {
a[i++] = v;
}
return a;
}
public static int[] digests(int[] key) {
final Curl curl = new Curl();
int[] digests = new int[key.length];
int[] buffer = new int[key.length];
for (int i = 0; i < Math.floor(key.length / 6561); i++) {
int[] keyFragment = Arrays.copyOfRange(key, i * 6561, (i + 1) * 6561);
for (int j = 0; j < 27; j++) {
buffer = Arrays.copyOfRange(keyFragment, j * 243, (j + 1) * 243);
for (int k = 0; k < 26; k++) {
curl.absorb(buffer, 0, buffer.length);
curl.squeeze(buffer, 0, buffer.length);
}
for (int k = 0; k < 243; k++) {
keyFragment[j * 243 + k] = buffer[k];
}
}
curl.absorb(keyFragment, 0, keyFragment.length);
curl.squeeze(buffer, 0, buffer.length);
for (int j = 0; j < 243; j++) {
digests[i * 243 + j] = buffer[j];
}
}
return digests;
}
public static int[] address(int[] digests) {
final Curl curl = new Curl();
int[] address = new int[digests.length];
curl.absorb(digests, 0, digests.length);
curl.squeeze(address, 0, address.length);
return address;
}
}
+12 -6
View File
@@ -1,18 +1,18 @@
package jota;
import static org.junit.Assert.assertThat;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jota.dto.response.*;
import jota.utils.IotaAPIUtils;
import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertThat;
/**
* Let's do some integration test coverage against a default local real node.
*
*
* @author davassi
*/
public class IotaAPIProxyTest {
@@ -122,5 +122,11 @@ public class IotaAPIProxyTest {
IotaAPIProxy proxy = new IotaAPIProxy.Builder().build();
assertThat(proxy, IsNull.notNullValue());
}
}
@Test
public void shouldCreateANewAddress() {
GetNewAddressResponse res = IotaAPIUtils.getNewAddress(TEST_SEED, 2);
System.err.println(res);
}
}
@@ -0,0 +1,38 @@
package jota;
import jota.utils.IotaUnitConverter;
import jota.utils.IotaUnits;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Created by pinpong on 30.11.16.
*/
public class IotaUnitConverterTest {
@Test
public void shouldConvertUnitItoKi() {
assertEquals(IotaUnitConverter.convertUnits(1000, IotaUnits.IOTA, IotaUnits.KILO_IOTA), 1);
}
@Test
public void shouldConvertUnitKiToMi() {
assertEquals(IotaUnitConverter.convertUnits(1000, IotaUnits.KILO_IOTA, IotaUnits.MEGA_IOTA), 1);
}
@Test
public void shouldConvertUnitMiToGi() {
assertEquals(IotaUnitConverter.convertUnits(1000, IotaUnits.MEGA_IOTA, IotaUnits.GIGA_IOTA), 1);
}
@Test
public void shouldConvertUnitGiToTi() {
assertEquals(IotaUnitConverter.convertUnits(1000, IotaUnits.GIGA_IOTA, IotaUnits.TERA_IOTA), 1);
}
@Test
public void shouldConvertUnitTiToPi() {
assertEquals(IotaUnitConverter.convertUnits(1000, IotaUnits.TERA_IOTA, IotaUnits.PETA_IOTA), 1);
}
}