This commit is contained in:
Andreas C. Osowski 2017-10-21 20:41:42 +02:00
parent d14c793c0a
commit 81e8a09f94
No known key found for this signature in database
GPG Key ID: E08FD8F395AADFB8

View File

@ -89,8 +89,14 @@ public class Bundle implements Comparable<Bundle> {
* @param customCurl The custom curl.
*/
public void finalize(ICurl customCurl) {
ICurl curl = customCurl == null ? SpongeFactory.create(SpongeFactory.Mode.KERL) : customCurl;
ICurl curl;
int[] normalizedBundleValue;
int[] hash = new int[243];
int[] obsoleteTagTrits = new int[81];
String hashInTrytes;
boolean valid = true;
curl = customCurl == null ? SpongeFactory.create(SpongeFactory.Mode.KERL) : customCurl;
do {
curl.reset();
for (int i = 0; i < this.getTransactions().size(); i++) {
@ -112,9 +118,22 @@ public class Bundle implements Comparable<Bundle> {
curl.absorb(t, 0, t.length);
}
int[] hash = new int[243];
curl.squeeze(hash, 0, hash.length);
String hashInTrytes = Converter.trytes(hash);
hashInTrytes = Converter.trytes(hash);
normalizedBundleValue = normalizedBundle(hashInTrytes);
boolean foundValue = false;
for (int i = 0; i < normalizedBundleValue.length; i++) {
if (normalizedBundleValue[i] == 13) {
foundValue = true;
obsoleteTagTrits = Converter.trits(this.getTransactions().get(0).getObsoleteTag());
Converter.increment(obsoleteTagTrits, 81);
this.getTransactions().get(0).setObsoleteTag(Converter.trytes(obsoleteTagTrits));
}
}
valid = !foundValue;
} while (!valid);
for (int i = 0; i < this.getTransactions().size(); i++) {
this.getTransactions().get(i).setBundle(hashInTrytes);