Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #131 from iotaledger/dev
Browse files Browse the repository at this point in the history
1.0.0-beta2 pre-release
  • Loading branch information
kwek20 authored Nov 2, 2018
2 parents a7165b2 + f2eccc8 commit b2b49f4
Show file tree
Hide file tree
Showing 30 changed files with 1,028 additions and 336 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![IOTA Logo][iota-logo]

# IOTA Java Library

[![Codacy Badge][codacy-badge]][codacy]
[![JitPack][jitpack-badge]][jitpack]
[![Build Status][travis-badge]][travis]
[![License][license-badge]][license]
Expand Down Expand Up @@ -36,7 +36,7 @@ All the boilerplate code for connecting to the node REST interface has been hidd
1. [Disclaimer](#disclaimer)
1. [Supporting the project](#supporting-the-project)
1. [Join the Discussion](#join-the-discussion)
1. [License](#license)
1. [License](codacity#license)

## Installation

Expand All @@ -56,7 +56,7 @@ allprojects {
Add this in your module `build.gradle` file:
```gradle
dependencies {
compile 'com.github.iotaledger:iota-java:1.0.0-beta1'
compile 'com.github.iotaledger:iota-java:1.0.0-beta2'
}
```

Expand All @@ -82,7 +82,7 @@ Add this in your module `pom.xml` file:
</dependency>
```
For the [VERSION_INFORMATION], you can choose to set it to a release number, or the first 10 characters of a commit hash.
`<version>17e0de8ed5</version>` or `<version>1.0.0-beta1</version>`
`<version>f3200c8380</version>` or `<version>1.0.0-beta2</version>`

Or check it out at [Jitpack](https://jitpack.io/#iotaledger/iota-java) for more specific information

Expand All @@ -96,7 +96,7 @@ Reference your new project to the "jota" project.

##### Linking jar
In order to build the jar; the following command should be run on the "jota" project:
'mvn clean install -Prelease -DprofileIdEnabled=true'
'mvn clean install'

This will generate a jar with the following format: `jota-[VERSION]-jar-with-dependencies.jar`

Expand Down Expand Up @@ -279,17 +279,19 @@ See the License for the specific language governing permissions and
limitations under the License.
```

[iota-logo]: https://raw.githubusercontent.com/iotaledger/documentation/master/source/images/iota-logo.png
[iota-logo]: https://avatars0.githubusercontent.com/u/20126597?s=200&v=4
[codacy]: https://www.codacy.com/app/kwek20/iota-java?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=iotaledger/iota-java&amp;utm_campaign=Badge_Grade
[codacy-badge]: https://api.codacy.com/project/badge/Grade/92feea51a15c4e589386c269475b8761
[jitpack]: https://jitpack.io/#iotaledger/iota-java
[jitpack-badge]: https://jitpack.io/v/iotaledger/iota-java.svg
[travis]: https://travis-ci.org/iotaledger/iota-java
[travis-badge]: https://travis-ci.org/iotaledger/iota-java.svg?branch=master
[license]: https://github.com/iotaledger/iota-java/blob/master/LICENSE
[license-badge]: https://img.shields.io/github/license/iotaledger/iota-java.svg
[iota-iri]: https://github.com/iotaledger/iri/tree/v1.5.0
[iota-iri-badge]: https://img.shields.io/badge/IOTA%20IRI%20compatibility-v1.5.0-blue.svg
[iota-iri]: https://github.com/iotaledger/iri/tree/v1.5.5
[iota-iri-badge]: https://img.shields.io/badge/IOTA%20IRI%20compatibility-v1.5.5-blue.svg
[iota-api]: https://iota.readme.io/reference
[iota-api-badge]: https://img.shields.io/badge/IOTA%20API%20coverage-14/15%20commands-red.svg
[iota-api-badge]: https://img.shields.io/badge/IOTA%20API%20coverage-15/15%20commands-green.svg
[javadoc]: https://iotaledger.github.io/iota-java/javadoc/
[issues]: https://github.com/iotaledger/iota-java/issues
[new-issue]: https://github.com/iotaledger/iota-java/issues/new
Expand Down
2 changes: 1 addition & 1 deletion jota/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.iota</groupId>
<artifactId>jota-parent</artifactId>
<version>1.0.0-beta1</version>
<version>1.0.0-beta2</version>
</parent>

<name>JOTA : Library</name>
Expand Down
353 changes: 214 additions & 139 deletions jota/src/main/java/jota/IotaAPI.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public static GetNewAddressResponse create(List<String> addresses, long duration
public List<String> getAddresses() {
return addresses;
}

/**
* Gets the first address, for quick access
* @return The address
*/
public String first() {
return addresses.get(0);
}
}
10 changes: 10 additions & 0 deletions jota/src/main/java/jota/dto/response/GetNodeInfoResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class GetNodeInfoResponse extends AbstractResponse {
private long time;
private int tips;
private int transactionsToRequest;

private String[] features;

/**
* The name of the IOTA software the node currently running (IRI stands for Initial Reference Implementation).
Expand Down Expand Up @@ -167,4 +169,12 @@ public int getTips() {
public int getTransactionsToRequest() {
return transactionsToRequest;
}

/**
*
* @return
*/
public String[] getFeatures() {
return features;
}
}
3 changes: 0 additions & 3 deletions jota/src/main/java/jota/error/BaseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.util.Arrays;
import java.util.Collection;

/**
* @author Adrian
*/
public class BaseException extends Exception {

/**
Expand Down
41 changes: 4 additions & 37 deletions jota/src/main/java/jota/model/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jota.pow.ICurl;
import jota.pow.SpongeFactory;
import jota.utils.Converter;
import jota.utils.Signing;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
Expand All @@ -12,7 +14,6 @@
/**
* This class represents a Bundle, a set of transactions.
*
* @author pinpong
**/
public class Bundle implements Comparable<Bundle> {

Expand All @@ -25,7 +26,7 @@ public class Bundle implements Comparable<Bundle> {
* Initializes a new instance of the Bundle class without transactions.
*/
public Bundle() {
this(new ArrayList<Transaction>(), 0);
this(new ArrayList<>(), 0);
}

/**
Expand Down Expand Up @@ -181,41 +182,7 @@ public void addTrytes(List<String> signatureFragments) {
* @return normalizedBundle A normalized bundle hash.
*/
public int[] normalizedBundle(String bundleHash) {
int[] normalizedBundle = new int[81];

for (int i = 0; i < 3; i++) {

long sum = 0;
for (int j = 0; j < 27; j++) {

sum += (normalizedBundle[i * 27 + j] = Converter.value(Converter.tritsString("" + bundleHash.charAt(i * 27 + j))));
}

if (sum >= 0) {
while (sum-- > 0) {
for (int j = 0; j < 27; j++) {
if (normalizedBundle[i * 27 + j] > -13) {
normalizedBundle[i * 27 + j]--;
break;
}
}
}
} else {

while (sum++ < 0) {

for (int j = 0; j < 27; j++) {

if (normalizedBundle[i * 27 + j] < 13) {
normalizedBundle[i * 27 + j]++;
break;
}
}
}
}
}

return normalizedBundle;
return new Signing().normalizedBundle(bundleHash);
}


Expand Down
1 change: 0 additions & 1 deletion jota/src/main/java/jota/model/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/**
* This class represents an Input.
*
* @author Adrian
**/
public class Input {

Expand Down
2 changes: 1 addition & 1 deletion jota/src/main/java/jota/model/Inputs.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<Input> getInputsList() {
* @param inputsList The input list.
*/
public void setInputsList(List<Input> inputsList) {
inputsList = inputsList;
this.inputsList = inputsList;
}

/**
Expand Down
1 change: 0 additions & 1 deletion jota/src/main/java/jota/model/Neighbor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/**
* This class represents an Neighbor.
*
* @author pinpong
**/
public class Neighbor {

Expand Down
1 change: 0 additions & 1 deletion jota/src/main/java/jota/model/Signature.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
/**
* This class represents an Signature.
*
* @author Adrian
**/
public class Signature {

Expand Down
76 changes: 53 additions & 23 deletions jota/src/main/java/jota/model/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import jota.pow.ICurl;
import jota.pow.SpongeFactory;
import jota.utils.Constants;
import jota.utils.Converter;
import jota.utils.InputValidator;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
Expand All @@ -14,7 +17,6 @@
/**
* This class represents an iota transaction.
*
* @author pinpong
*/
public class Transaction {

Expand All @@ -39,6 +41,28 @@ public class Transaction {
private String tag;
private long attachmentTimestampLowerBound;
private long attachmentTimestampUpperBound;

/**
* Converts an array of transaction trytes into an array of transaction objects.
* @param trytes the array of transactions trytes
* @return the transaction objects
*/
public static Transaction[] asTransactionObjects(String... trytes) {
Transaction[] transactions = new Transaction[trytes.length];
for (int i = 0; i < trytes.length; i++) {
transactions[i] = asTransactionObject(trytes[i]);
}
return transactions;
}

/**
* Converts transaction trytes into a transaction object.
* @param trytes the transaction trytes
* @return the transaction object
*/
public static Transaction asTransactionObject(String trytes) {
return new Transaction(trytes);
}

/**
* Initializes a new instance of the Signature class.
Expand Down Expand Up @@ -73,15 +97,7 @@ public Transaction(String address, long value, String tag, long timestamp) {
this.obsoleteTag = tag;
this.timestamp = timestamp;
}

public long getAttachmentTimestampLowerBound() {
return attachmentTimestampLowerBound;
}

public void setAttachmentTimestampLowerBound(long attachmentTimestampLowerBound) {
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
}


/**
* Initializes a new instance of the Signature class.
*/
Expand Down Expand Up @@ -110,6 +126,14 @@ public Transaction(String trytes, ICurl customCurl) {
transactionObject(trytes);
this.customCurl = customCurl;
}

public long getAttachmentTimestampLowerBound() {
return attachmentTimestampLowerBound;
}

public void setAttachmentTimestampLowerBound(long attachmentTimestampLowerBound) {
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
}

public long getAttachmentTimestampUpperBound() {
return attachmentTimestampUpperBound;
Expand Down Expand Up @@ -452,15 +476,13 @@ public void transactionObject(final String trytes) {
}

// validity check
for (int i = 2279; i < 2295; i++) {
if (trytes.charAt(i) != '9') {
log.warn("Trytes {} does not seem a valid tryte", trytes);
return;
}
if (!InputValidator.isNinesTrytes(trytes.substring(2279, 2295), 16)) {
log.warn("Trytes {} does not seem a valid tryte", trytes);
return;
}

int[] transactionTrits = Converter.trits(trytes);
int[] hash = new int[243];
int[] hash = new int[Constants.HASH_LENGTH_TRITS];

ICurl curl = SpongeFactory.create(SpongeFactory.Mode.CURLP81);
// generate the correct transaction hash
Expand All @@ -469,20 +491,28 @@ public void transactionObject(final String trytes) {
curl.squeeze(hash, 0, hash.length);

this.setHash(Converter.trytes(hash));
this.setSignatureFragments(trytes.substring(0, 2187));
this.setAddress(trytes.substring(2187, 2268));
this.setSignatureFragments(trytes.substring(0, Constants.MESSAGE_LENGTH));
this.setAddress(trytes.substring(Constants.MESSAGE_LENGTH, Constants.MESSAGE_LENGTH + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
this.setValue(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6804, 6837)));
this.setObsoleteTag(trytes.substring(2295, 2322));
this.setObsoleteTag(trytes.substring(2295, 2295 + Constants.TAG_LENGTH));
this.setTimestamp(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6966, 6993)));
this.setCurrentIndex(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6993, 7020)));
this.setLastIndex(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7020, 7047)));
this.setBundle(trytes.substring(2349, 2430));
this.setTrunkTransaction(trytes.substring(2430, 2511));
this.setBranchTransaction(trytes.substring(2511, 2592));
this.setTag(trytes.substring(2592, 2619));
this.setBundle(trytes.substring(2349, 2349 + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
this.setTrunkTransaction(trytes.substring(2430, 2430 + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
this.setBranchTransaction(trytes.substring(2511, 2511 + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
this.setTag(trytes.substring(2592, 2592 + Constants.TAG_LENGTH));
this.setAttachmentTimestamp(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7857, 7884)));
this.setAttachmentTimestampLowerBound(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7884, 7911)));
this.setAttachmentTimestampUpperBound(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7911, 7938)));
this.setNonce(trytes.substring(2646, 2673));
}

/**
* Checks if the current index is 0
* @return if this is a tail transaction
*/
public boolean isTailTransaction() {
return getCurrentIndex() == 0;
}
}
1 change: 0 additions & 1 deletion jota/src/main/java/jota/model/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* This class represents a Transfer.
*
* @author pinpong
*/
public class Transfer {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cfb.pearldiver;
package jota.pow.pearldiver;

import static cfb.pearldiver.PearlDiver.State.CANCELLED;
import static cfb.pearldiver.PearlDiver.State.COMPLETED;
import static cfb.pearldiver.PearlDiver.State.RUNNING;
import static jota.pow.JCurl.NUMBER_OF_ROUNDSP81;
import static jota.pow.pearldiver.PearlDiver.State.CANCELLED;
import static jota.pow.pearldiver.PearlDiver.State.COMPLETED;
import static jota.pow.pearldiver.PearlDiver.State.RUNNING;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cfb.pearldiver;
package jota.pow.pearldiver;

import jota.IotaLocalPoW;
import jota.utils.Converter;
Expand Down
Loading

0 comments on commit b2b49f4

Please sign in to comment.