From 94c6b4e2f21f512e1cda0f04ba45750146bbee89 Mon Sep 17 00:00:00 2001 From: AZ Date: Fri, 9 Dec 2016 20:21:37 +0100 Subject: [PATCH] updated trx object and normalizedBundle added --- src/main/java/jota/model/Bundle.java | 42 ++++++++- src/main/java/jota/model/Transaction.java | 100 ++++++++++------------ src/main/java/jota/utils/Converter.java | 8 ++ 3 files changed, 91 insertions(+), 59 deletions(-) diff --git a/src/main/java/jota/model/Bundle.java b/src/main/java/jota/model/Bundle.java index 00aed02..f6c7d7a 100644 --- a/src/main/java/jota/model/Bundle.java +++ b/src/main/java/jota/model/Bundle.java @@ -1,5 +1,6 @@ package jota.model; +import jota.utils.Converter; import org.apache.commons.lang3.NotImplementedException; import java.util.ArrayList; @@ -51,9 +52,44 @@ public class Bundle { throw new NotImplementedException(""); } - public String normalizedBundle(String bundleHash) { - throw new NotImplementedException(""); + public int[] normalizedBundle(String bundleHash) { + int[] normalizedBundle = new int[33 * 27 + 27]; + + for (int i = 0; i < 3; i++) { + + long sum = 0; + for (int j = 0; j < 27; j++) { + + sum += (normalizedBundle[i * 27 + j] = Converter.value(Converter.trits("" + bundleHash.charAt(i * 27 + j)))); + } + + if (sum >= 0) { + while (sum-- > 0) { + for (int j = 0; j < 27; j++) { + if (normalizedBundle[i * 27 + j] > -13) { + normalizedBundle[i * 27 + j]--; + break; + } + } + } + } else { + + while (sum++ < 0) { + + for (int j = 0; j < 27; j++) { + + if (normalizedBundle[i * 27 + j] < 13) { + + normalizedBundle[i * 27 + j]++; + break; + } + } + } + } + } + + return normalizedBundle; } - } + diff --git a/src/main/java/jota/model/Transaction.java b/src/main/java/jota/model/Transaction.java index 90e7231..f8f45fa 100644 --- a/src/main/java/jota/model/Transaction.java +++ b/src/main/java/jota/model/Transaction.java @@ -7,36 +7,33 @@ import org.apache.commons.lang3.builder.ToStringStyle; * Created by pinpong on 02.12.16. */ public class Transaction { - - private String signatureMessageChunk; - private String index; - private String approvalNonce; private String hash; - private String digest; - private String type; - private String timestamp; - private String trunkTransaction; - private String branchTransaction; - private String signatureNonce; + private String signatureMessageChunk; private String address; private String value; + private String tag; + private String timestamp; + private String currentIndex; + private String lastIndex; private String bundle; + private String trunkTransaction; + private String branchTransaction; + private String nonce; - public Transaction(String signatureMessageChunk, String index, String approvalNonce, String hash, String digest, String type, String timestamp, String trunkTransaction, String branchTransaction, String signatureNonce, String address, String value, String bundle) { + public Transaction(String signatureMessageChunk, String currentIndex, String lastIndex, String nonce, String hash, String tag, String timestamp, String trunkTransaction, String branchTransaction, String address, String value, String bundle) { this.hash = hash; - this.type = type; + this.tag = tag; this.signatureMessageChunk = signatureMessageChunk; - this.digest = digest; this.address = address; this.value = value; this.timestamp = timestamp; - this.index = index; + this.currentIndex = currentIndex; + this.lastIndex = lastIndex; this.bundle = bundle; - this.signatureNonce = signatureNonce; - this.approvalNonce = approvalNonce; this.trunkTransaction = trunkTransaction; this.branchTransaction = branchTransaction; + this.nonce = nonce; } @Override @@ -49,26 +46,10 @@ public class Transaction { this.signatureMessageChunk = signatureMessageChunk; } - public void setIndex(String index) { - this.index = index; - } - - public void setApprovalNonce(String approvalNonce) { - this.approvalNonce = approvalNonce; - } - public void setHash(String hash) { this.hash = hash; } - public void setDigest(String digest) { - this.digest = digest; - } - - public void setType(String type) { - this.type = type; - } - public void setTimestamp(String timestamp) { this.timestamp = timestamp; } @@ -81,10 +62,6 @@ public class Transaction { this.branchTransaction = branchTransaction; } - public void setSignatureNonce(String signatureNonce) { - this.signatureNonce = signatureNonce; - } - public void setAddress(String address) { this.address = address; } @@ -101,10 +78,6 @@ public class Transaction { return value; } - public String getDigest() { - return digest; - } - public String getTrunkTransaction() { return trunkTransaction; } @@ -113,22 +86,10 @@ public class Transaction { return timestamp; } - public String getSignatureNonce() { - return signatureNonce; - } - - public String getType() { - return type; - } - public String getAddress() { return address; } - public String getApprovalNonce() { - return approvalNonce; - } - public String getBranchTransaction() { return branchTransaction; } @@ -141,12 +102,39 @@ public class Transaction { return hash; } - public String getIndex() { - return index; - } - public String getSignatureMessageChunk() { return signatureMessageChunk; } + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public String getCurrentIndex() { + return currentIndex; + } + + public void setCurrentIndex(String currentIndex) { + this.currentIndex = currentIndex; + } + + public String getLastIndex() { + return lastIndex; + } + + public void setLastIndex(String lastIndex) { + this.lastIndex = lastIndex; + } + + public String getNonce() { + return nonce; + } + + public void setNonce(String nonce) { + this.nonce = nonce; + } } diff --git a/src/main/java/jota/utils/Converter.java b/src/main/java/jota/utils/Converter.java index a43388f..c10792b 100644 --- a/src/main/java/jota/utils/Converter.java +++ b/src/main/java/jota/utils/Converter.java @@ -124,6 +124,14 @@ public class Converter { return trits[offset] + trits[offset + 1] * 3 + trits[offset + 2] * 9; } + public static int value(final int[] trits) { + int value = 0; + + for (int i = trits.length; i-- > 0; ) { + value = value * 3 + trits[i]; + } + return value; } + public static void increment(final int[] trits, final int size) { for (int i = 0; i < size; i++) {