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

Commit c891d41

Browse files
committed
* switched from Curl-P27 -> Curl-P81
* new Transaction format
1 parent a8ca265 commit c891d41

14 files changed

+221
-87
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ deploy:
1313
file_glob: true
1414
file:
1515
- "/home/travis/build/iotaledger/iota.lib.java/target/jota*.jar"
16+
- "/home/travis/build/iotaledger/iota.lib.java/target/jota*.jar-with-dependencies"
1617
- "/home/travis/build/iotaledger/iota.lib.java/target/jota*.jar.asc"
1718
- "/home/travis/build/iotaledger/iota.lib.java/target/jota*-sources.jar"
1819
- "/home/travis/build/iotaledger/iota.lib.java/target/jota*-sources.jar.asc"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ The JOTA library is a simple Java wrapper around [[IOTA]](http://www.iotatoken.c
77

88
It allows to connect easily using java directly to a local or a remote [[IOTA node]](https://iota.readme.io/docs/syncing-to-the-network).
99

10-
* **Latest release:** 0.9.1
11-
* **Compatibility:** fully compatible with IOTA IRI v1.2.6
10+
* **Latest release:** 0.9.3
11+
* **Compatibility:** fully compatible with IOTA IRI v1.4.0
1212
* **API coverage:** 14 of 14 commands fully implemented
1313
* **License:** Apache License 2.0
14-
* **Readme updated:** 2016-01-19 21:05:02 (UTC)
14+
* **Readme updated:** 2017-09-23 21:05:02 (UTC)
1515

1616
A list of all *IOTA* JSON-REST API commands currently supported by jota wrapper can be found in the `Commands` enum (see [here](https://github.com/davassi/JOTA/blob/master/src/main/java/jota/IotaAPICommands.java) for more details).
1717

pom.xml

+22
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@
115115
</properties>
116116
<build>
117117
<plugins>
118+
<plugin>
119+
<artifactId>maven-assembly-plugin</artifactId>
120+
<configuration>
121+
<archive>
122+
<manifest>
123+
<mainClass></mainClass>
124+
</manifest>
125+
</archive>
126+
<descriptorRefs>
127+
<descriptorRef>jar-with-dependencies</descriptorRef>
128+
</descriptorRefs>
129+
</configuration>
130+
<executions>
131+
<execution>
132+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
133+
<phase>package</phase> <!-- bind to the packaging phase -->
134+
<goals>
135+
<goal>single</goal>
136+
</goals>
137+
</execution>
138+
</executions>
139+
</plugin>
118140
<plugin>
119141
<groupId>org.apache.maven.plugins</groupId>
120142
<artifactId>maven-source-plugin</artifactId>

src/main/java/jota/IotaAPI.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -805,24 +805,24 @@ public GetInclusionStateResponse getLatestInclusion(String[] hashes) throws NoNo
805805
* @param minWeightMagnitude The minimum weight magnitude.
806806
* @param transfers Array of transfer objects.
807807
* @param inputs List of inputs used for funding the transfer.
808-
* @param address If defined, this address will be used for sending the remainder value (of the inputs) to.
808+
* @param remainderAddress If defined, this remainderAddress will be used for sending the remainder value (of the inputs) to.
809809
* @return Array of Transaction objects.
810-
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
810+
* @throws InvalidAddressException is thrown when the specified remainderAddress is not an valid remainderAddress.
811811
* @throws NotEnoughBalanceException is thrown when a transfer fails because their is not enough balance to perform the transfer.
812812
* @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
813813
* @throws InvalidTrytesException is thrown when invalid trytes is provided.
814-
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
814+
* @throws InvalidAddressException is thrown when the specified remainderAddress is not an valid remainderAddress.
815815
* @throws InvalidTransferException is thrown when an invalid transfer is provided.
816816
*/
817-
public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List<Transfer> transfers, Input[] inputs, String address) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
817+
public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List<Transfer> transfers, Input[] inputs, String remainderAddress) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
818818

819819
if (security < 1 || security > 3) {
820820
throw new InvalidSecurityLevelException();
821821
}
822822

823823
StopWatch stopWatch = new StopWatch();
824824

825-
List<String> trytes = prepareTransfers(seed, security, transfers, address, inputs == null ? null : Arrays.asList(inputs));
825+
List<String> trytes = prepareTransfers(seed, security, transfers, remainderAddress, inputs == null ? null : Arrays.asList(inputs));
826826
List<Transaction> trxs = sendTrytes(trytes.toArray(new String[trytes.size()]), depth, minWeightMagnitude);
827827

828828
Boolean[] successful = new Boolean[trxs.size()];
@@ -1044,7 +1044,7 @@ public List<Transaction> initiateTransfer(int securitySum, final String inputAdd
10441044
bundle.addEntry(1, remainderAddress, remainder, tag, timestamp);
10451045
}
10461046

1047-
bundle.finalize(customCurl.clone());
1047+
bundle.finalize(SpongeFactory.create(SpongeFactory.Mode.CURLP81));
10481048
bundle.addTrytes(signatureFragments);
10491049

10501050
return bundle.getTransactions();

src/main/java/jota/IotaAPICore.java

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import retrofit2.converter.gson.GsonConverterFactory;
1515

1616
import java.io.BufferedReader;
17-
import java.io.FileNotFoundException;
1817
import java.io.FileReader;
1918
import java.io.IOException;
2019
import java.util.List;

src/main/java/jota/IotaLocalPoW.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* Interface for an implementation to perform local PoW.
55
*/
66
public interface IotaLocalPoW {
7-
public String performPoW(String trytes, int minWeightMagnitude);
7+
String performPoW(String trytes, int minWeightMagnitude);
88
}

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public void finalize(ICurl customCurl) {
107107

108108
int[] lastIndexTrits = Converter.trits(this.getTransactions().get(i).getLastIndex(), 27);
109109

110-
int[] t = Converter.trits(this.getTransactions().get(i).getAddress() + Converter.trytes(valueTrits) + this.getTransactions().get(i).getTag() + Converter.trytes(timestampTrits) + Converter.trytes(currentIndexTrits) + Converter.trytes(lastIndexTrits));
110+
int[] t = Converter.trits(this.getTransactions().get(i).getAddress() + Converter.trytes(valueTrits) + this.getTransactions().get(i).getObsoleteTag() + Converter.trytes(timestampTrits) + Converter.trytes(currentIndexTrits) + Converter.trytes(lastIndexTrits));
111+
111112
curl.absorb(t, 0, t.length);
112113
}
113114

@@ -128,6 +129,7 @@ public void finalize(ICurl customCurl) {
128129
public void addTrytes(List<String> signatureFragments) {
129130
String emptySignatureFragment = "";
130131
String emptyHash = EMPTY_HASH;
132+
long emptyTimestamp = 999999999l;
131133

132134
emptySignatureFragment = StringUtils.rightPad(emptySignatureFragment, 2187, '9');
133135

@@ -141,8 +143,14 @@ public void addTrytes(List<String> signatureFragments) {
141143
// Fill empty branchTransaction
142144
this.getTransactions().get(i).setBranchTransaction(emptyHash);
143145

146+
147+
this.getTransactions().get(i).setAttachmentTimestamp(emptyTimestamp);
148+
this.getTransactions().get(i).setAttachmentTimestampLowerBound(emptyTimestamp);
149+
this.getTransactions().get(i).setAttachmentTimestampUpperBound(emptyTimestamp);
150+
144151
// Fill empty nonce
145-
this.getTransactions().get(i).setNonce(emptyHash);
152+
this.getTransactions().get(i).setNonce(StringUtils.rightPad("", 27, "9"));
153+
146154
}
147155
}
148156

@@ -200,6 +208,6 @@ public int[] normalizedBundle(String bundleHash) {
200208
*/
201209
@Override
202210
public int compareTo(Bundle o) {
203-
return Long.compare(this.getTransactions().get(0).getTimestamp(), o.getTransactions().get(0).getTimestamp());
211+
return Long.compare(this.getTransactions().get(0).getAttachmentTimestamp(), o.getTransactions().get(0).getAttachmentTimestamp());
204212
}
205213
}

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

+107-33
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Transaction {
2626
private String signatureFragments;
2727
private String address;
2828
private long value;
29-
private String tag;
29+
private String obsoleteTag;
3030
private long timestamp;
3131
private long currentIndex;
3232
private long lastIndex;
@@ -35,6 +35,51 @@ public class Transaction {
3535
private String branchTransaction;
3636
private String nonce;
3737
private Boolean persistence;
38+
private long attachmentTimestamp;
39+
private String tag;
40+
private long attachmentTimestampLowerBound;
41+
private long attachmentTimestampUpperBound;
42+
43+
/**
44+
* Initializes a new instance of the Signature class.
45+
*/
46+
public Transaction(String signatureFragments, long currentIndex, long lastIndex, String nonce, String hash, String obsoleteTag, long timestamp, String trunkTransaction, String branchTransaction, String address, long value, String bundle, String tag, long attachmentTimestamp, long attachmentTimestampLowerBound, long attachmentTimestampUpperBound) {
47+
48+
this.hash = hash;
49+
this.obsoleteTag = obsoleteTag;
50+
this.signatureFragments = signatureFragments;
51+
this.address = address;
52+
this.value = value;
53+
this.timestamp = timestamp;
54+
this.currentIndex = currentIndex;
55+
this.lastIndex = lastIndex;
56+
this.bundle = bundle;
57+
this.trunkTransaction = trunkTransaction;
58+
this.branchTransaction = branchTransaction;
59+
this.tag = tag;
60+
this.attachmentTimestamp = attachmentTimestamp;
61+
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
62+
this.attachmentTimestampUpperBound = attachmentTimestampUpperBound;
63+
this.nonce = nonce;
64+
}
65+
66+
/**
67+
* Initializes a new instance of the Signature class.
68+
*/
69+
public Transaction(String address, long value, String tag, long timestamp) {
70+
this.address = address;
71+
this.value = value;
72+
this.obsoleteTag = tag;
73+
this.timestamp = timestamp;
74+
}
75+
76+
public long getAttachmentTimestampLowerBound() {
77+
return attachmentTimestampLowerBound;
78+
}
79+
80+
public void setAttachmentTimestampLowerBound(long attachmentTimestampLowerBound) {
81+
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
82+
}
3883

3984
/**
4085
* Initializes a new instance of the Signature class.
@@ -65,33 +110,12 @@ public Transaction(String trytes, ICurl customCurl) {
65110
this.customCurl = customCurl;
66111
}
67112

68-
/**
69-
* Initializes a new instance of the Signature class.
70-
*/
71-
public Transaction(String signatureFragments, long currentIndex, long lastIndex, String nonce, String hash, String tag, long timestamp, String trunkTransaction, String branchTransaction, String address, long value, String bundle) {
72-
73-
this.hash = hash;
74-
this.tag = tag;
75-
this.signatureFragments = signatureFragments;
76-
this.address = address;
77-
this.value = value;
78-
this.timestamp = timestamp;
79-
this.currentIndex = currentIndex;
80-
this.lastIndex = lastIndex;
81-
this.bundle = bundle;
82-
this.trunkTransaction = trunkTransaction;
83-
this.branchTransaction = branchTransaction;
84-
this.nonce = nonce;
113+
public long getAttachmentTimestampUpperBound() {
114+
return attachmentTimestampUpperBound;
85115
}
86116

87-
/**
88-
* Initializes a new instance of the Signature class.
89-
*/
90-
public Transaction(String address, long value, String tag, long timestamp) {
91-
this.address = address;
92-
this.value = value;
93-
this.tag = tag;
94-
this.timestamp = timestamp;
117+
public void setAttachmentTimestampUpperBound(long attachmentTimestampUpperBound) {
118+
this.attachmentTimestampUpperBound = attachmentTimestampUpperBound;
95119
}
96120

97121
/**
@@ -338,6 +362,42 @@ public void setPersistence(Boolean persistence) {
338362
this.persistence = persistence;
339363
}
340364

365+
/**
366+
* Get the obsoleteTag.
367+
*
368+
* @return The obsoleteTag.
369+
*/
370+
public String getObsoleteTag() {
371+
return obsoleteTag;
372+
}
373+
374+
/**
375+
* Set the obsoleteTag.
376+
*
377+
* @param obsoleteTag The persistence.
378+
*/
379+
public void setObsoleteTag(String obsoleteTag) {
380+
this.obsoleteTag = obsoleteTag;
381+
}
382+
383+
/**
384+
* Get the attachmentTimestamp.
385+
*
386+
* @return The attachmentTimestamp.
387+
*/
388+
public long getAttachmentTimestamp() {
389+
return attachmentTimestamp;
390+
}
391+
392+
/**
393+
* Set the attachmentTimestamp.
394+
*
395+
* @param attachmentTimestamp The persistence.
396+
*/
397+
public void setAttachmentTimestamp(long attachmentTimestamp) {
398+
this.attachmentTimestamp = attachmentTimestamp;
399+
}
400+
341401
public boolean equals(Object obj) {
342402
return obj != null && ((Transaction) obj).getHash().equals(this.getHash());
343403
}
@@ -351,24 +411,34 @@ public String toTrytes() {
351411

352412
int[] timestampTrits = Converter.trits(this.getTimestamp(), 27);
353413

354-
355414
int[] currentIndexTrits = Converter.trits(this.getCurrentIndex(), 27);
356415

357-
358416
int[] lastIndexTrits = Converter.trits(this.getLastIndex(), 27);
359417

418+
int[] attachmentTimestampTrits = Converter.trits(this.getAttachmentTimestamp(), 27);
360419

361-
return this.getSignatureFragments()
420+
int[] attachmentTimestampLowerBoundTrits = Converter.trits(this.getAttachmentTimestampLowerBound(), 27);
421+
422+
int[] attachmentTimestampUpperBoundTrits = Converter.trits(this.getAttachmentTimestampUpperBound(), 27);
423+
424+
this.tag = this.tag != null && !this.tag.isEmpty() ? this.tag : this.obsoleteTag;
425+
426+
String trx = this.getSignatureFragments()
362427
+ this.getAddress()
363428
+ Converter.trytes(valueTrits)
364-
+ this.getTag()
429+
+ this.getObsoleteTag()
365430
+ Converter.trytes(timestampTrits)
366431
+ Converter.trytes(currentIndexTrits)
367432
+ Converter.trytes(lastIndexTrits)
368433
+ this.getBundle()
369434
+ this.getTrunkTransaction()
370435
+ this.getBranchTransaction()
436+
+ this.getTag()
437+
+ Converter.trytes(attachmentTimestampTrits)
438+
+ Converter.trytes(attachmentTimestampLowerBoundTrits)
439+
+ Converter.trytes(attachmentTimestampUpperBoundTrits)
371440
+ this.getNonce();
441+
return trx;
372442
}
373443

374444
/**
@@ -392,7 +462,7 @@ public void transactionObject(final String trytes) {
392462
int[] transactionTrits = Converter.trits(trytes);
393463
int[] hash = new int[243];
394464

395-
ICurl curl = SpongeFactory.create(SpongeFactory.Mode.CURL);
465+
ICurl curl = SpongeFactory.create(SpongeFactory.Mode.CURLP81);
396466
// generate the correct transaction hash
397467
curl.reset();
398468
curl.absorb(transactionTrits, 0, transactionTrits.length);
@@ -402,13 +472,17 @@ public void transactionObject(final String trytes) {
402472
this.setSignatureFragments(trytes.substring(0, 2187));
403473
this.setAddress(trytes.substring(2187, 2268));
404474
this.setValue(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6804, 6837)));
405-
this.setTag(trytes.substring(2295, 2322));
475+
this.setObsoleteTag(trytes.substring(2295, 2322));
406476
this.setTimestamp(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6966, 6993)));
407477
this.setCurrentIndex(Converter.longValue(Arrays.copyOfRange(transactionTrits, 6993, 7020)));
408478
this.setLastIndex(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7020, 7047)));
409479
this.setBundle(trytes.substring(2349, 2430));
410480
this.setTrunkTransaction(trytes.substring(2430, 2511));
411481
this.setBranchTransaction(trytes.substring(2511, 2592));
412-
this.setNonce(trytes.substring(2592, 2673));
482+
this.setTag(trytes.substring(2592, 2619));
483+
this.setAttachmentTimestamp(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7857, 7884)) / 1000);
484+
this.setAttachmentTimestampLowerBound(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7884, 7911)));
485+
this.setAttachmentTimestampUpperBound(Converter.longValue(Arrays.copyOfRange(transactionTrits, 7911, 7938)));
486+
this.setNonce(trytes.substring(2646, 2673));
413487
}
414488
}

0 commit comments

Comments
 (0)