From 81e8a09f946c6dde8152b379f6166d6c7fc3d47d Mon Sep 17 00:00:00 2001 From: "Andreas C. Osowski" Date: Sat, 21 Oct 2017 20:41:42 +0200 Subject: [PATCH] bugfix --- src/main/java/jota/model/Bundle.java | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/jota/model/Bundle.java b/src/main/java/jota/model/Bundle.java index 9155821..40c0e42 100644 --- a/src/main/java/jota/model/Bundle.java +++ b/src/main/java/jota/model/Bundle.java @@ -89,11 +89,17 @@ public class Bundle implements Comparable { * @param customCurl The custom curl. */ public void finalize(ICurl 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(); - ICurl curl = customCurl == null ? SpongeFactory.create(SpongeFactory.Mode.KERL) : customCurl; - curl.reset(); - - for (int i = 0; i < this.getTransactions().size(); i++) { + for (int i = 0; i < this.getTransactions().size(); i++) { int[] valueTrits = Converter.trits(this.getTransactions().get(i).getValue(), 81); @@ -110,11 +116,24 @@ public class Bundle implements Comparable { 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)); curl.absorb(t, 0, t.length); - } + } - int[] hash = new int[243]; - curl.squeeze(hash, 0, hash.length); - String hashInTrytes = Converter.trytes(hash); + curl.squeeze(hash, 0, hash.length); + 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); @@ -210,4 +229,4 @@ public class Bundle implements Comparable { public int compareTo(Bundle o) { return Long.compare(this.getTransactions().get(0).getAttachmentTimestamp(), o.getTransactions().get(0).getAttachmentTimestamp()); } -} \ No newline at end of file +}