[WIP ] added finalize to bundle

This commit is contained in:
AZ
2016-12-09 21:40:34 +01:00
parent a633a54401
commit 39c5ed4fa3
+39 -1
View File
@@ -1,5 +1,6 @@
package jota.model;
import jota.pow.Curl;
import jota.utils.Converter;
import org.apache.commons.lang3.NotImplementedException;
@@ -45,9 +46,46 @@ public class Bundle {
}
public void finalize() {
throw new NotImplementedException("");
Curl curl = new Curl();
curl.reset();
for (int i = 0; i < this.getTransactions().size(); i++) {
int[] valueTrits = Converter.trits(this.getTransactions().get(i).getValue());
while (valueTrits.length < 81) {
valueTrits[valueTrits.length] = 0;
}
int[] timestampTrits = Converter.trits(this.getTransactions().get(i).getTimestamp());
while (timestampTrits.length < 27) {
timestampTrits[timestampTrits.length] = 0;
}
int[] currentIndexTrits = Converter.trits(this.getTransactions().get(i).setCurrentIndex("" + i));
while (currentIndexTrits.length < 27) {
currentIndexTrits[currentIndexTrits.length] = 0;
}
int[] lastIndexTrits = Converter.trits(this.getTransactions().get(i).setLastIndex("" + (this.getTransactions().size() - 1)));
while (lastIndexTrits.length < 27) {
lastIndexTrits[lastIndexTrits.length] = 0;
}
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));
curl.absorb(t, 0, t.length);
}
int[] hash = new int[90];
curl.squeeze(hash, 0, hash.length);
String hashInTrytes = Converter.trytes(hash);
for (int i = 0; i < this.getTransactions().size(); i++) {
this.getTransactions().get(i).setBundle(hashInTrytes);
}
}
public void addTrytes(List<String> signatureFragments) {
throw new NotImplementedException("");
}