This repository was archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 366
replace all trit representations from int[] to byte[] #879
Merged
GalRogozinski
merged 3 commits into
iotaledger-archive:dev
from
alon-e:feat/tritsAsBytes
Jul 22, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ public class TransactionViewModel { | |
| public final static int PREFILLED_SLOT = 1; // means that we know only hash of the tx, the rest is unknown yet: only another tx references that hash | ||
| public final static int FILLED_SLOT = -1; // knows the hash only coz another tx references that hash | ||
|
|
||
| private int[] trits; | ||
| private byte[] trits; | ||
| public int weightMagnitude; | ||
|
|
||
| public static void fillMetadata(Tangle tangle, TransactionViewModel transactionViewModel) throws Exception { | ||
|
|
@@ -85,29 +85,29 @@ public TransactionViewModel(final Transaction transaction, final Hash hash) { | |
| weightMagnitude = this.hash.trailingZeros(); | ||
| } | ||
|
|
||
| public TransactionViewModel(final int[] trits, Hash hash) { | ||
| transaction = new com.iota.iri.model.Transaction(); | ||
| this.trits = new int[trits.length]; | ||
| System.arraycopy(trits, 0, this.trits, 0, trits.length); | ||
| transaction.bytes = Converter.allocateBytesForTrits(trits.length); | ||
| Converter.bytes(trits, 0, transaction.bytes, 0, trits.length); | ||
| this.hash = hash; | ||
| public TransactionViewModel(final byte[] trits, Hash hash) { | ||
| if(trits.length == 8019) { | ||
| transaction = new com.iota.iri.model.Transaction(); | ||
| this.trits = new byte[trits.length]; | ||
| System.arraycopy(trits, 0, this.trits, 0, trits.length); | ||
| transaction.bytes = Converter.allocateBytesForTrits(trits.length); | ||
| Converter.bytes(trits, 0, transaction.bytes, 0, trits.length); | ||
| this.hash = hash; | ||
|
|
||
| transaction.type = FILLED_SLOT; | ||
| transaction.type = FILLED_SLOT; | ||
|
|
||
| weightMagnitude = this.hash.trailingZeros(); | ||
| transaction.validity = 0; | ||
| transaction.arrivalTime = 0; | ||
| } | ||
|
|
||
|
|
||
| public TransactionViewModel(final byte[] bytes, Hash hash) throws RuntimeException { | ||
| transaction = new Transaction(); | ||
| transaction.bytes = new byte[SIZE]; | ||
| System.arraycopy(bytes, 0, transaction.bytes, 0, SIZE); | ||
| this.hash = hash; | ||
| weightMagnitude = this.hash.trailingZeros(); | ||
| transaction.type = FILLED_SLOT; | ||
| weightMagnitude = this.hash.trailingZeros(); | ||
| transaction.validity = 0; | ||
| transaction.arrivalTime = 0; | ||
| } | ||
| else { | ||
| transaction = new Transaction(); | ||
| transaction.bytes = new byte[SIZE]; | ||
| System.arraycopy(trits, 0, transaction.bytes, 0, SIZE); | ||
| this.hash = hash; | ||
| weightMagnitude = this.hash.trailingZeros(); | ||
| transaction.type = FILLED_SLOT; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would create two static factory methods:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open an issue on this. but it shouldn't block the goodness from this PR imo. |
||
| } | ||
|
|
||
| public static int getNumberOfStoredTransactions(Tangle tangle) throws Exception { | ||
|
|
@@ -143,16 +143,16 @@ public TransactionViewModel getTrunkTransaction(Tangle tangle) throws Exception | |
| return trunk; | ||
| } | ||
|
|
||
| public static int[] trits(byte[] transactionBytes) { | ||
| int[] trits; | ||
| trits = new int[TRINARY_SIZE]; | ||
| public static byte[] trits(byte[] transactionBytes) { | ||
| byte[] trits; | ||
| trits = new byte[TRINARY_SIZE]; | ||
| if(transactionBytes != null) { | ||
| Converter.getTrits(transactionBytes, trits); | ||
| } | ||
| return trits; | ||
| } | ||
|
|
||
| public synchronized int[] trits() { | ||
| public synchronized byte[] trits() { | ||
| return (trits == null) ? (trits = trits(transaction.bytes)) : trits; | ||
| } | ||
|
|
||
|
|
@@ -329,7 +329,7 @@ public long getCurrentIndex() { | |
| return transaction.currentIndex; | ||
| } | ||
|
|
||
| public int[] getSignature() { | ||
| public byte[] getSignature() { | ||
| return Arrays.copyOfRange(trits(), SIGNATURE_MESSAGE_FRAGMENT_TRINARY_OFFSET, SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this hack, perhaphs create two methods:
validateTritsandvalidateBytes.The above change is just confusing (even though it works)...