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

Commit b2b49f4

Browse files
authored
Merge pull request #131 from iotaledger/dev
1.0.0-beta2 pre-release
2 parents a7165b2 + f2eccc8 commit b2b49f4

30 files changed

+1028
-336
lines changed

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![IOTA Logo][iota-logo]
22

33
# IOTA Java Library
4-
4+
[![Codacy Badge][codacy-badge]][codacy]
55
[![JitPack][jitpack-badge]][jitpack]
66
[![Build Status][travis-badge]][travis]
77
[![License][license-badge]][license]
@@ -36,7 +36,7 @@ All the boilerplate code for connecting to the node REST interface has been hidd
3636
1. [Disclaimer](#disclaimer)
3737
1. [Supporting the project](#supporting-the-project)
3838
1. [Join the Discussion](#join-the-discussion)
39-
1. [License](#license)
39+
1. [License](codacity#license)
4040

4141
## Installation
4242

@@ -56,7 +56,7 @@ allprojects {
5656
Add this in your module `build.gradle` file:
5757
```gradle
5858
dependencies {
59-
compile 'com.github.iotaledger:iota-java:1.0.0-beta1'
59+
compile 'com.github.iotaledger:iota-java:1.0.0-beta2'
6060
}
6161
```
6262

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

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

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

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

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

@@ -279,17 +279,19 @@ See the License for the specific language governing permissions and
279279
limitations under the License.
280280
```
281281

282-
[iota-logo]: https://raw.githubusercontent.com/iotaledger/documentation/master/source/images/iota-logo.png
282+
[iota-logo]: https://avatars0.githubusercontent.com/u/20126597?s=200&v=4
283+
[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
284+
[codacy-badge]: https://api.codacy.com/project/badge/Grade/92feea51a15c4e589386c269475b8761
283285
[jitpack]: https://jitpack.io/#iotaledger/iota-java
284286
[jitpack-badge]: https://jitpack.io/v/iotaledger/iota-java.svg
285287
[travis]: https://travis-ci.org/iotaledger/iota-java
286288
[travis-badge]: https://travis-ci.org/iotaledger/iota-java.svg?branch=master
287289
[license]: https://github.com/iotaledger/iota-java/blob/master/LICENSE
288290
[license-badge]: https://img.shields.io/github/license/iotaledger/iota-java.svg
289-
[iota-iri]: https://github.com/iotaledger/iri/tree/v1.5.0
290-
[iota-iri-badge]: https://img.shields.io/badge/IOTA%20IRI%20compatibility-v1.5.0-blue.svg
291+
[iota-iri]: https://github.com/iotaledger/iri/tree/v1.5.5
292+
[iota-iri-badge]: https://img.shields.io/badge/IOTA%20IRI%20compatibility-v1.5.5-blue.svg
291293
[iota-api]: https://iota.readme.io/reference
292-
[iota-api-badge]: https://img.shields.io/badge/IOTA%20API%20coverage-14/15%20commands-red.svg
294+
[iota-api-badge]: https://img.shields.io/badge/IOTA%20API%20coverage-15/15%20commands-green.svg
293295
[javadoc]: https://iotaledger.github.io/iota-java/javadoc/
294296
[issues]: https://github.com/iotaledger/iota-java/issues
295297
[new-issue]: https://github.com/iotaledger/iota-java/issues/new

jota/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.iota</groupId>
77
<artifactId>jota-parent</artifactId>
8-
<version>1.0.0-beta1</version>
8+
<version>1.0.0-beta2</version>
99
</parent>
1010

1111
<name>JOTA : Library</name>

jota/src/main/java/jota/IotaAPI.java

+214-139
Large diffs are not rendered by default.

jota/src/main/java/jota/dto/response/GetNewAddressResponse.java

+8
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ public static GetNewAddressResponse create(List<String> addresses, long duration
2727
public List<String> getAddresses() {
2828
return addresses;
2929
}
30+
31+
/**
32+
* Gets the first address, for quick access
33+
* @return The address
34+
*/
35+
public String first() {
36+
return addresses.get(0);
37+
}
3038
}

jota/src/main/java/jota/dto/response/GetNodeInfoResponse.java

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class GetNodeInfoResponse extends AbstractResponse {
2121
private long time;
2222
private int tips;
2323
private int transactionsToRequest;
24+
25+
private String[] features;
2426

2527
/**
2628
* The name of the IOTA software the node currently running (IRI stands for Initial Reference Implementation).
@@ -167,4 +169,12 @@ public int getTips() {
167169
public int getTransactionsToRequest() {
168170
return transactionsToRequest;
169171
}
172+
173+
/**
174+
*
175+
* @return
176+
*/
177+
public String[] getFeatures() {
178+
return features;
179+
}
170180
}

jota/src/main/java/jota/error/BaseException.java

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import java.util.Arrays;
55
import java.util.Collection;
66

7-
/**
8-
* @author Adrian
9-
*/
107
public class BaseException extends Exception {
118

129
/**

jota/src/main/java/jota/model/Bundle.java

+4-37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import jota.pow.ICurl;
44
import jota.pow.SpongeFactory;
55
import jota.utils.Converter;
6+
import jota.utils.Signing;
7+
68
import org.apache.commons.lang3.StringUtils;
79

810
import java.util.ArrayList;
@@ -12,7 +14,6 @@
1214
/**
1315
* This class represents a Bundle, a set of transactions.
1416
*
15-
* @author pinpong
1617
**/
1718
public class Bundle implements Comparable<Bundle> {
1819

@@ -25,7 +26,7 @@ public class Bundle implements Comparable<Bundle> {
2526
* Initializes a new instance of the Bundle class without transactions.
2627
*/
2728
public Bundle() {
28-
this(new ArrayList<Transaction>(), 0);
29+
this(new ArrayList<>(), 0);
2930
}
3031

3132
/**
@@ -181,41 +182,7 @@ public void addTrytes(List<String> signatureFragments) {
181182
* @return normalizedBundle A normalized bundle hash.
182183
*/
183184
public int[] normalizedBundle(String bundleHash) {
184-
int[] normalizedBundle = new int[81];
185-
186-
for (int i = 0; i < 3; i++) {
187-
188-
long sum = 0;
189-
for (int j = 0; j < 27; j++) {
190-
191-
sum += (normalizedBundle[i * 27 + j] = Converter.value(Converter.tritsString("" + bundleHash.charAt(i * 27 + j))));
192-
}
193-
194-
if (sum >= 0) {
195-
while (sum-- > 0) {
196-
for (int j = 0; j < 27; j++) {
197-
if (normalizedBundle[i * 27 + j] > -13) {
198-
normalizedBundle[i * 27 + j]--;
199-
break;
200-
}
201-
}
202-
}
203-
} else {
204-
205-
while (sum++ < 0) {
206-
207-
for (int j = 0; j < 27; j++) {
208-
209-
if (normalizedBundle[i * 27 + j] < 13) {
210-
normalizedBundle[i * 27 + j]++;
211-
break;
212-
}
213-
}
214-
}
215-
}
216-
}
217-
218-
return normalizedBundle;
185+
return new Signing().normalizedBundle(bundleHash);
219186
}
220187

221188

jota/src/main/java/jota/model/Input.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
/**
77
* This class represents an Input.
88
*
9-
* @author Adrian
109
**/
1110
public class Input {
1211

jota/src/main/java/jota/model/Inputs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public List<Input> getInputsList() {
4747
* @param inputsList The input list.
4848
*/
4949
public void setInputsList(List<Input> inputsList) {
50-
inputsList = inputsList;
50+
this.inputsList = inputsList;
5151
}
5252

5353
/**

jota/src/main/java/jota/model/Neighbor.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/**
44
* This class represents an Neighbor.
55
*
6-
* @author pinpong
76
**/
87
public class Neighbor {
98

jota/src/main/java/jota/model/Signature.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
/**
77
* This class represents an Signature.
88
*
9-
* @author Adrian
109
**/
1110
public class Signature {
1211

jota/src/main/java/jota/model/Transaction.java

+53-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import jota.pow.ICurl;
44
import jota.pow.SpongeFactory;
5+
import jota.utils.Constants;
56
import jota.utils.Converter;
7+
import jota.utils.InputValidator;
8+
69
import org.apache.commons.lang3.StringUtils;
710
import org.apache.commons.lang3.builder.ToStringBuilder;
811
import org.apache.commons.lang3.builder.ToStringStyle;
@@ -14,7 +17,6 @@
1417
/**
1518
* This class represents an iota transaction.
1619
*
17-
* @author pinpong
1820
*/
1921
public class Transaction {
2022

@@ -39,6 +41,28 @@ public class Transaction {
3941
private String tag;
4042
private long attachmentTimestampLowerBound;
4143
private long attachmentTimestampUpperBound;
44+
45+
/**
46+
* Converts an array of transaction trytes into an array of transaction objects.
47+
* @param trytes the array of transactions trytes
48+
* @return the transaction objects
49+
*/
50+
public static Transaction[] asTransactionObjects(String... trytes) {
51+
Transaction[] transactions = new Transaction[trytes.length];
52+
for (int i = 0; i < trytes.length; i++) {
53+
transactions[i] = asTransactionObject(trytes[i]);
54+
}
55+
return transactions;
56+
}
57+
58+
/**
59+
* Converts transaction trytes into a transaction object.
60+
* @param trytes the transaction trytes
61+
* @return the transaction object
62+
*/
63+
public static Transaction asTransactionObject(String trytes) {
64+
return new Transaction(trytes);
65+
}
4266

4367
/**
4468
* Initializes a new instance of the Signature class.
@@ -73,15 +97,7 @@ public Transaction(String address, long value, String tag, long timestamp) {
7397
this.obsoleteTag = tag;
7498
this.timestamp = timestamp;
7599
}
76-
77-
public long getAttachmentTimestampLowerBound() {
78-
return attachmentTimestampLowerBound;
79-
}
80-
81-
public void setAttachmentTimestampLowerBound(long attachmentTimestampLowerBound) {
82-
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
83-
}
84-
100+
85101
/**
86102
* Initializes a new instance of the Signature class.
87103
*/
@@ -110,6 +126,14 @@ public Transaction(String trytes, ICurl customCurl) {
110126
transactionObject(trytes);
111127
this.customCurl = customCurl;
112128
}
129+
130+
public long getAttachmentTimestampLowerBound() {
131+
return attachmentTimestampLowerBound;
132+
}
133+
134+
public void setAttachmentTimestampLowerBound(long attachmentTimestampLowerBound) {
135+
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
136+
}
113137

114138
public long getAttachmentTimestampUpperBound() {
115139
return attachmentTimestampUpperBound;
@@ -452,15 +476,13 @@ public void transactionObject(final String trytes) {
452476
}
453477

454478
// validity check
455-
for (int i = 2279; i < 2295; i++) {
456-
if (trytes.charAt(i) != '9') {
457-
log.warn("Trytes {} does not seem a valid tryte", trytes);
458-
return;
459-
}
479+
if (!InputValidator.isNinesTrytes(trytes.substring(2279, 2295), 16)) {
480+
log.warn("Trytes {} does not seem a valid tryte", trytes);
481+
return;
460482
}
461483

462484
int[] transactionTrits = Converter.trits(trytes);
463-
int[] hash = new int[243];
485+
int[] hash = new int[Constants.HASH_LENGTH_TRITS];
464486

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

471493
this.setHash(Converter.trytes(hash));
472-
this.setSignatureFragments(trytes.substring(0, 2187));
473-
this.setAddress(trytes.substring(2187, 2268));
494+
this.setSignatureFragments(trytes.substring(0, Constants.MESSAGE_LENGTH));
495+
this.setAddress(trytes.substring(Constants.MESSAGE_LENGTH, Constants.MESSAGE_LENGTH + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
474496
this.setValue(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6804, 6837)));
475-
this.setObsoleteTag(trytes.substring(2295, 2322));
497+
this.setObsoleteTag(trytes.substring(2295, 2295 + Constants.TAG_LENGTH));
476498
this.setTimestamp(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6966, 6993)));
477499
this.setCurrentIndex(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6993, 7020)));
478500
this.setLastIndex(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7020, 7047)));
479-
this.setBundle(trytes.substring(2349, 2430));
480-
this.setTrunkTransaction(trytes.substring(2430, 2511));
481-
this.setBranchTransaction(trytes.substring(2511, 2592));
482-
this.setTag(trytes.substring(2592, 2619));
501+
this.setBundle(trytes.substring(2349, 2349 + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
502+
this.setTrunkTransaction(trytes.substring(2430, 2430 + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
503+
this.setBranchTransaction(trytes.substring(2511, 2511 + Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM));
504+
this.setTag(trytes.substring(2592, 2592 + Constants.TAG_LENGTH));
483505
this.setAttachmentTimestamp(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7857, 7884)));
484506
this.setAttachmentTimestampLowerBound(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7884, 7911)));
485507
this.setAttachmentTimestampUpperBound(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7911, 7938)));
486508
this.setNonce(trytes.substring(2646, 2673));
487509
}
510+
511+
/**
512+
* Checks if the current index is 0
513+
* @return if this is a tail transaction
514+
*/
515+
public boolean isTailTransaction() {
516+
return getCurrentIndex() == 0;
517+
}
488518
}

jota/src/main/java/jota/model/Transfer.java

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/**
66
* This class represents a Transfer.
77
*
8-
* @author pinpong
98
*/
109
public class Transfer {
1110

jota/src/main/java/cfb/pearldiver/PearlDiver.java renamed to jota/src/main/java/jota/pow/pearldiver/PearlDiver.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package cfb.pearldiver;
1+
package jota.pow.pearldiver;
22

3-
import static cfb.pearldiver.PearlDiver.State.CANCELLED;
4-
import static cfb.pearldiver.PearlDiver.State.COMPLETED;
5-
import static cfb.pearldiver.PearlDiver.State.RUNNING;
63
import static jota.pow.JCurl.NUMBER_OF_ROUNDSP81;
4+
import static jota.pow.pearldiver.PearlDiver.State.CANCELLED;
5+
import static jota.pow.pearldiver.PearlDiver.State.COMPLETED;
6+
import static jota.pow.pearldiver.PearlDiver.State.RUNNING;
77

88

99
/**

jota/src/main/java/cfb/pearldiver/PearlDiverLocalPoW.java renamed to jota/src/main/java/jota/pow/pearldiver/PearlDiverLocalPoW.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cfb.pearldiver;
1+
package jota.pow.pearldiver;
22

33
import jota.IotaLocalPoW;
44
import jota.utils.Converter;

0 commit comments

Comments
 (0)