mirror of
https://github.com/gosticks/iota.lib.java.git
synced 2025-10-16 11:45:37 +00:00
refactored
This commit is contained in:
parent
3650407eb9
commit
d2b33f73bd
@ -1,135 +1,136 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.iota</groupId>
|
||||
<artifactId>jota</artifactId>
|
||||
<name>JOTA</name>
|
||||
<version>0.9.2</version>
|
||||
<description>JOTA library is a simple Java wrapper around IOTA Node's JSON-REST HTTP interface.</description>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<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>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>${skipTests}</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>build-extras</id>
|
||||
<build>
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.iota</groupId>
|
||||
<artifactId>jota</artifactId>
|
||||
<name>JOTA</name>
|
||||
<version>0.9.2</version>
|
||||
<description>JOTA library is a simple Java wrapper around IOTA Node's JSON-REST HTTP interface.</description>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<show>private</show>
|
||||
<nohelp>true</nohelp>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<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>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>${skipTests}</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<gpg.keyname>${env.GPG_KEYNAME}</gpg.keyname>
|
||||
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<skipTests>true</skipTests>
|
||||
<java-version>1.7</java-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>build-extras</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<show>private</show>
|
||||
<nohelp>true</nohelp>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<gpg.keyname>${env.GPG_KEYNAME}</gpg.keyname>
|
||||
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<skipTests>true</skipTests>
|
||||
<java-version>1.7</java-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@ -126,7 +126,7 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>${skipTests}</skipTests>
|
||||
<skipTests>${skipTests}</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@ -109,8 +109,8 @@ public class IotaAPI extends IotaAPICore {
|
||||
*/
|
||||
public GetTransferResponse getTransfers(String seed, int security, Integer start, Integer end, Boolean inclusionStates) throws ArgumentException, InvalidBundleException, InvalidSignatureException, NoNodeInfoException, NoInclusionStatesException, InvalidSecurityLevelException, InvalidAddressException {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
// validate & if needed pad seed
|
||||
if ((seed = InputValidator.validateSeed(seed)) == null) {
|
||||
// validate seed
|
||||
if ((!InputValidator.isValidSeed(seed))) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
@ -344,14 +344,15 @@ public class IotaAPI extends IotaAPICore {
|
||||
public List<String> prepareTransfers(String seed, int security, final List<Transfer> transfers, String remainder, List<Input> inputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException, InvalidTransferException {
|
||||
return prepareTransfers(seed, security, transfers, remainder, inputs, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares transfer by generating bundle, finding and signing inputs.
|
||||
*
|
||||
* @param seed 81-tryte encoded address of recipient.
|
||||
* @param security The security level of private key / seed.
|
||||
* @param transfers Array of transfer objects.
|
||||
* @param remainder If defined, this address will be used for sending the remainder value (of the inputs) to.
|
||||
* @param inputs The inputs.
|
||||
* @param seed 81-tryte encoded address of recipient.
|
||||
* @param security The security level of private key / seed.
|
||||
* @param transfers Array of transfer objects.
|
||||
* @param remainder If defined, this address will be used for sending the remainder value (of the inputs) to.
|
||||
* @param inputs The inputs.
|
||||
* @param validateInputs whether or not to validate the balances of the provided inputs
|
||||
* @return Returns bundle trytes.
|
||||
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
|
||||
@ -366,8 +367,8 @@ public class IotaAPI extends IotaAPICore {
|
||||
throw new InvalidTransferException();
|
||||
}
|
||||
|
||||
// validate & if needed pad seed
|
||||
if ((seed = InputValidator.validateSeed(seed)) == null) {
|
||||
// validate seed
|
||||
if ((!InputValidator.isValidSeed(seed))) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
@ -438,11 +439,11 @@ public class IotaAPI extends IotaAPICore {
|
||||
|
||||
// Get inputs if we are sending tokens
|
||||
if (totalValue != 0) {
|
||||
if(!validateInputs)
|
||||
if (!validateInputs)
|
||||
return addRemainder(seed, security, inputs, bundle, tag, totalValue, remainder, signatureFragments);
|
||||
// Case 1: user provided inputs
|
||||
// Validate the inputs by calling getBalances
|
||||
if(!validateInputs)
|
||||
if (!validateInputs)
|
||||
return addRemainder(seed, security, inputs, bundle, tag, totalValue, remainder, signatureFragments);
|
||||
if (inputs != null && !inputs.isEmpty()) {
|
||||
|
||||
@ -524,13 +525,9 @@ public class IotaAPI extends IotaAPICore {
|
||||
**/
|
||||
public GetBalancesAndFormatResponse getInputs(String seed, int security, int start, int end, long threshold) throws InvalidSecurityLevelException, InvalidAddressException {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
// validate the seed
|
||||
if (!InputValidator.isTrytes(seed, 0)) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
// validate & if needed pad seed
|
||||
if ((seed = InputValidator.validateSeed(seed)) == null) {
|
||||
// validate the seed
|
||||
if ((!InputValidator.isValidSeed(seed))) {
|
||||
throw new IllegalStateException("Invalid Seed");
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import jota.IotaAPICommands;
|
||||
|
||||
/**
|
||||
* This class represents the core API request 'attachToTangle'.
|
||||
*
|
||||
* <p>
|
||||
* It is used to attach trytes to the tangle.
|
||||
**/
|
||||
public class IotaAttachToTangleRequest extends IotaCommandRequest {
|
||||
|
||||
@ -4,7 +4,7 @@ import jota.IotaAPICommands;
|
||||
|
||||
/**
|
||||
* This class represents the core API request 'broadcastTransaction'.
|
||||
*
|
||||
* <p>
|
||||
* Broadcast a list of transactions to all neighbors. The input trytes for this call are provided by attachToTangle
|
||||
**/
|
||||
public class IotaBroadcastTransactionRequest extends IotaCommandRequest {
|
||||
|
||||
@ -4,7 +4,7 @@ import jota.IotaAPICommands;
|
||||
|
||||
/**
|
||||
* This class represents the core API request 'getTransactionsToApprove'.
|
||||
*
|
||||
* <p>
|
||||
* It stores transactions into the local storage. The trytes to be used for this call are returned by attachToTangle.
|
||||
**/
|
||||
public class IotaStoreTransactionsRequest extends IotaCommandRequest {
|
||||
|
||||
@ -43,6 +43,7 @@ public class JCurl implements ICurl {
|
||||
stateLow = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Absorbs the specified trits.
|
||||
*
|
||||
|
||||
@ -9,21 +9,20 @@ import java.util.List;
|
||||
*/
|
||||
public class Converter {
|
||||
|
||||
public static final int HIGH_INTEGER_BITS = 0xFFFFFFFF;
|
||||
public static final long HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFFL;
|
||||
/**
|
||||
* The radix
|
||||
*/
|
||||
private static final int RADIX = 3;
|
||||
|
||||
/**
|
||||
* The maximum trit value
|
||||
*/
|
||||
private static final int MAX_TRIT_VALUE = (RADIX - 1) / 2, MIN_TRIT_VALUE = -MAX_TRIT_VALUE;
|
||||
|
||||
/**
|
||||
* The number of trits in a byte
|
||||
*/
|
||||
private static final int NUMBER_OF_TRITS_IN_A_BYTE = 5;
|
||||
|
||||
/**
|
||||
* The number of trits in a tryte
|
||||
*/
|
||||
@ -31,9 +30,6 @@ public class Converter {
|
||||
private static final int[][] BYTE_TO_TRITS_MAPPINGS = new int[243][];
|
||||
private static final int[][] TRYTE_TO_TRITS_MAPPINGS = new int[27][];
|
||||
|
||||
public static final int HIGH_INTEGER_BITS = 0xFFFFFFFF;
|
||||
public static final long HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFFL;
|
||||
|
||||
static {
|
||||
|
||||
final int[] trits = new int[NUMBER_OF_TRITS_IN_A_BYTE];
|
||||
|
||||
@ -2,7 +2,6 @@ package jota.utils;
|
||||
|
||||
import jota.error.InvalidAddressException;
|
||||
import jota.model.Transfer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
import java.util.List;
|
||||
@ -153,18 +152,9 @@ public class InputValidator {
|
||||
* Checks if the seed is valid. If not, an exception is thrown.
|
||||
*
|
||||
* @param seed The seed to validate.
|
||||
* @return The validated seed.
|
||||
* @throws IllegalStateException Format not in trytes or Invalid Seed: Seed too long.
|
||||
* @return <code>true</code> if the specified seed is valid; otherwise, <code>false</code>.
|
||||
**/
|
||||
public static String validateSeed(String seed) {
|
||||
if (seed.length() > 81)
|
||||
throw new IllegalStateException("Invalid Seed: Seed too long");
|
||||
|
||||
if (!isTrytes(seed, seed.length()))
|
||||
throw new IllegalStateException("Invalid Seed: Format not in trytes");
|
||||
|
||||
seed = StringUtils.rightPad(seed, 81, '9');
|
||||
|
||||
return seed;
|
||||
public static boolean isValidSeed(String seed) {
|
||||
return isTrytes(seed, seed.length());
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,9 +31,9 @@ public class Multisig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred.
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred.
|
||||
* @param security Secuirty level of private key / seed.
|
||||
* @param index Key index to start search from. If the index is provided, the generation of the address is not deterministic.
|
||||
* @param index Key index to start search from. If the index is provided, the generation of the address is not deterministic.
|
||||
* @return trytes
|
||||
**/
|
||||
public String getDigest(String seed, int security, int index) {
|
||||
@ -70,7 +70,7 @@ public class Multisig {
|
||||
/**
|
||||
* Gets the key value of a seed
|
||||
*
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred
|
||||
* @param seed Tryte-encoded seed. It should be noted that this seed is not transferred
|
||||
* @param index Key index to start search from. If the index is provided, the generation of the address is not deterministic.
|
||||
* @return trytes.
|
||||
**/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user